本文整理汇总了C++中KFileDialog::selectedUrl方法的典型用法代码示例。如果您正苦于以下问题:C++ KFileDialog::selectedUrl方法的具体用法?C++ KFileDialog::selectedUrl怎么用?C++ KFileDialog::selectedUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KFileDialog
的用法示例。
在下文中一共展示了KFileDialog::selectedUrl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveResults
void KFindTreeView::saveResults()
{
KFileDialog *dlg = new KFileDialog(QUrl(), QString(), this);
dlg->setOperationMode (KFileDialog::Saving);
dlg->setWindowTitle( i18nc("@title:window", "Save Results As") );
dlg->setFilter( QString::fromLatin1("*.html|%1\n*.txt|%2").arg( i18n("HTML page"), i18n("Text file") ) );
dlg->setConfirmOverwrite(true);
dlg->exec();
QUrl u = dlg->selectedUrl();
QString filter = dlg->currentFilter();
delete dlg;
if (!u.isValid() || !u.isLocalFile())
return;
QString filename = u.toLocalFile();
QFile file(filename);
if ( !file.open(QIODevice::WriteOnly) )
{
KMessageBox::error(parentWidget(),
i18n("Unable to save results."));
}
else
{
QTextStream stream( &file );
stream.setCodec( QTextCodec::codecForLocale() );
QList<KFindItem> itemList = m_model->getItemList();
if ( filter == QLatin1String("*.html") )
{
stream << QString::fromLatin1("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
"<head>\n"
"<title>%2</title></head>\n"
"<meta charset=\"%1\">\n"
"<body>\n<h1>%2</h1>\n"
"<dl>\n")
.arg(QString::fromLatin1(QTextCodec::codecForLocale()->name()))
.arg(i18n("KFind Results File"));
Q_FOREACH( const KFindItem & item, itemList )
{
const KFileItem fileItem = item.getFileItem();
stream << QString::fromLatin1("<dt><a href=\"%1\">%2</a></dt>\n").arg(
fileItem.url().url(), fileItem.url().toDisplayString() );
}
stream << QString::fromLatin1("</dl>\n</body>\n</html>\n");
}
else
{
示例2: importDocument
void KoPAView::importDocument()
{
KFileDialog *dialog = new KFileDialog( KUrl("kfiledialog:///OpenDialog"),QString(), this );
dialog->setObjectName( "file dialog" );
dialog->setMode( KFile::File );
if ( d->doc->pageType() == KoPageApp::Slide ) {
dialog->setCaption(i18n("Import Slideshow"));
}
else {
dialog->setCaption(i18n("Import Document"));
}
// TODO make it possible to select also other supported types (then the default format) here.
// this needs to go via the filters to get the file in the correct format.
// For now we only support the native mime types
QStringList mimeFilter;
#if 1
mimeFilter << KoOdf::mimeType( d->doc->documentType() ) << KoOdf::templateMimeType( d->doc->documentType() );
#else
mimeFilter = KoFilterManager::mimeFilter( KoDocument::readNativeFormatMimeType(d->doc->componentData()), KoFilterManager::Import,
KoDocument::readExtraNativeMimeTypes() );
#endif
dialog->setMimeFilter( mimeFilter );
if (dialog->exec() == QDialog::Accepted) {
KUrl url(dialog->selectedUrl());
QString tmpFile;
if ( KIO::NetAccess::download( url, tmpFile, 0 ) ) {
QFile file( tmpFile );
file.open( QIODevice::ReadOnly );
QByteArray ba;
ba = file.readAll();
// set the correct mime type as otherwise it does not find the correct tag when loading
QMimeData data;
data.setData( KoOdf::mimeType( d->doc->documentType() ), ba);
KoPAPastePage paste( d->doc,d->activePage );
if ( ! paste.paste( d->doc->documentType(), &data ) ) {
KMessageBox::error(0, i18n("Could not import\n%1", url.pathOrUrl()));
}
}
else {
KMessageBox::error(0, i18n("Could not import\n%1", url.pathOrUrl()));
}
}
delete dialog;
}
示例3: main
int main(int argc, char **argv)
{
KCmdLineOptions options;
options.add("+[cmd]");
options.add("+[url]");
KCmdLineArgs::init(argc, argv, "kfstest", 0, ki18n("kfstest"), "0", ki18n("test app"));
KCmdLineArgs::addCmdLineOptions(options);
KApplication a;
a.setQuitOnLastWindowClosed(false);
QString name1;
QStringList names;
QString argv1;
KUrl startDir;
if (argc > 1)
argv1 = QLatin1String(argv[1]);
if ( argc > 2 )
startDir = KUrl( argv[2] );
#if 0 // SPLIT-TODO
if (argv1 == QLatin1String("diroperator")) {
KDirOperator *op = new KDirOperator(startDir, 0);
KConfigGroup grp(KGlobal::config(), "TestGroup" );
op->setViewConfig(grp);
op->setView(KFile::Simple);
op->show();
a.exec();
} else
#endif
if (argv1 == QLatin1String("localonly")) {
QString name = KFileDialog::getOpenFileName(startDir);
qDebug("filename=%s",name.toLatin1().constData());
}
else if (argv1 == QLatin1String("oneurl")) {
KUrl url = KFileDialog::getOpenUrl(startDir);
qDebug() << "url=" << url;
}
else if (argv1 == QLatin1String("existingDirectoryUrl")) {
KUrl url = KFileDialog::getExistingDirectoryUrl();
qDebug("URL=%s",url.url().toLatin1().constData());
name1 = url.url();
}
else if (argv1 == QLatin1String("preview")) {
KUrl u = KFileDialog::getImageOpenUrl();
qDebug("filename=%s", u.url().toLatin1().constData());
}
else if (argv1 == QLatin1String("preselect")) {
names = KFileDialog::getOpenFileNames(KUrl("/etc/passwd"));
QStringList::Iterator it = names.begin();
while ( it != names.end() ) {
qDebug("selected file: %s", (*it).toLatin1().constData());
++it;
}
}
else if (argv1 == QLatin1String("dirs"))
name1 = KFileDialog::getExistingDirectory();
else if (argv1 == QLatin1String("heap")) {
KFileDialog *dlg = new KFileDialog( startDir, QString(), 0L);
dlg->setMode( KFile::File);
dlg->setOperationMode( KFileDialog::Saving );
QStringList filter;
filter << "all/allfiles" << "text/plain";
dlg->setMimeFilter( filter, "all/allfiles" );
#if 0 // SPLIT-TODO
KUrlBar *urlBar = dlg->speedBar();
if ( urlBar )
{
urlBar->insertDynamicItem( KUrl("ftp://ftp.kde.org"),
QLatin1String("KDE FTP Server") );
}
#endif
if ( dlg->exec() == KDialog::Accepted )
name1 = dlg->selectedUrl().url();
}
else if ( argv1 == QLatin1String("eventloop") )
{
new KFDTest( startDir );
return a.exec();
}
else if (argv1 == QLatin1String("save")) {
KUrl u = KFileDialog::getSaveUrl(startDir);
// QString(QDir::homePath() + QLatin1String("/testfile")),
// QString(), 0L);
name1 = u.url();
}
else if (argv1 == QLatin1String("icon")) {
KIconDialog dlg;
QString icon = dlg.getIcon();
kDebug() << icon;
}
//.........这里部分代码省略.........