KIO
kfiledialog.cpp
Go to the documentation of this file.
00001 // -*- c++ -*- 00002 /* This file is part of the KDE libraries 00003 Copyright (C) 1997, 1998 Richard Moore <rich@kde.org> 00004 1998 Stephan Kulow <coolo@kde.org> 00005 1998 Daniel Grana <grana@ie.iwi.unibe.ch> 00006 1999,2000,2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org> 00007 2003 Clarence Dang <dang@kde.org> 00008 2008 Jarosław Staniek <staniek@kde.org> 00009 2009 David Jarvie <djarvie@kde.org> 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Library General Public 00013 License as published by the Free Software Foundation; either 00014 version 2 of the License, or (at your option) any later version. 00015 00016 This library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Library General Public License for more details. 00020 00021 You should have received a copy of the GNU Library General Public License 00022 along with this library; see the file COPYING.LIB. If not, write to 00023 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00024 Boston, MA 02110-1301, USA. 00025 */ 00026 00027 #include "kfiledialog.h" 00028 00029 #include <QtGui/QCheckBox> 00030 #include <QtGui/QKeyEvent> 00031 #include <QtGui/QFileDialog> 00032 #include <QtGui/QApplication> 00033 #include <QtGui/QDesktopWidget> 00034 00035 #include <kimageio.h> 00036 #include <klocale.h> 00037 #include <kpushbutton.h> 00038 #include <config-kfile.h> 00039 #include <krecentdocument.h> 00040 #include <kimagefilepreview.h> 00041 #include <kpluginloader.h> 00042 #include <kpluginfactory.h> 00043 #include <kdebug.h> 00044 #include <kwindowsystem.h> 00045 #include "kabstractfilewidget.h" 00046 #include "kabstractfilemodule.h" 00047 #include "krecentdirs.h" 00048 #include "kservice.h" 00049 00051 #if defined(Q_WS_WIN) || defined(Q_WS_MAEMO_5) 00052 const bool NATIVE_FILEDIALOGS_BY_DEFAULT = true; 00053 #else 00054 const bool NATIVE_FILEDIALOGS_BY_DEFAULT = false; 00055 #endif 00056 00057 static QStringList mime2KdeFilter( const QStringList &mimeTypes, QString *allExtensions = 0 ) 00058 { 00059 const KUrl emptyUrl; 00060 QStringList kdeFilter; 00061 QStringList allExt; 00062 foreach( const QString& mimeType, mimeTypes ) { 00063 KMimeType::Ptr mime( KMimeType::mimeType(mimeType) ); 00064 if (mime) { 00065 allExt += mime->patterns(); 00066 kdeFilter.append(mime->patterns().join(QLatin1String(" ")) + 00067 QLatin1Char('|') + 00068 mime->comment(emptyUrl)); 00069 } 00070 } 00071 if (allExtensions) { 00072 allExt.sort(); 00073 *allExtensions = allExt.join(QLatin1String(" ")); 00074 } 00075 return kdeFilter; 00076 } 00080 static QString qtFilter(const QStringList& _filters) 00081 { 00082 QString converted; 00083 const QStringList filters = _filters; 00084 00085 foreach (const QString& current, filters) { 00086 QString new_f; //filter part 00087 QString new_name; //filter name part 00088 int p = current.indexOf('|'); 00089 if (p==-1) { 00090 new_f = current; 00091 new_name = current; // nothing better found 00092 } 00093 else { 00094 new_f = current.left(p); 00095 new_name = current.mid(p+1); 00096 } 00097 //Qt filters assume anything in () is the file extension list 00098 new_name = new_name.replace('(', '[').replace(')',']').trimmed(); 00099 00100 //convert everything to lower case and remove dupes (doesn't matter on win32) 00101 QStringList allfiltersUnique; 00102 const QStringList origList( new_f.split(' ', QString::SkipEmptyParts) ); 00103 foreach (const QString& origFilter, origList) { 00104 if (!allfiltersUnique.contains(origFilter, Qt::CaseInsensitive)) 00105 allfiltersUnique += origFilter.toLower(); 00106 } 00107 00108 if (!converted.isEmpty()) 00109 converted += ";;"; 00110 00111 converted += (new_name + " (" + allfiltersUnique.join(" ") + QLatin1Char(')')); 00112 } 00113 00114 // Strip escape characters from escaped '/' characters. 00115 converted.replace("\\/","/"); 00116 00117 return converted; 00118 } 00119 00123 static QString qtFilter(const QString& filter) 00124 { 00125 // Qt format: "some text (*.first *.second)" or "All files (*)" separated by ;; 00126 // KDE format: "*.first *.second|Description" or "*|Description", separated by \n (Description is optional) 00127 QStringList filters; 00128 if (filter.isEmpty()) 00129 filters += i18n("*|All files"); 00130 else { 00131 // check if it's a mimefilter 00132 int pos = filter.indexOf('/'); 00133 if (pos > 0 && filter[pos - 1] != '\\') 00134 filters = mime2KdeFilter(filter.split(QLatin1Char(' '), QString::SkipEmptyParts)); 00135 else 00136 filters = filter.split('\n', QString::SkipEmptyParts); 00137 } 00138 return qtFilter(filters); 00139 } 00140 00141 static KAbstractFileModule* s_module = 0; 00142 static KAbstractFileModule* loadFileModule( const QString& moduleName ) 00143 { 00144 KService::Ptr fileModuleService = KService::serviceByDesktopName(moduleName); 00145 if(fileModuleService) 00146 return fileModuleService->createInstance<KAbstractFileModule>(); 00147 else 00148 return 0; 00149 } 00150 00151 static const char s_defaultFileModuleName[] = "kfilemodule"; 00152 static KAbstractFileModule* fileModule() 00153 { 00154 if(!s_module) { 00155 QString moduleName = KConfigGroup(KGlobal::config(), ConfigGroup).readEntry("file module", s_defaultFileModuleName); 00156 if(!(s_module = loadFileModule(moduleName))) { 00157 kDebug() << "Failed to load configured file module" << moduleName; 00158 if(moduleName != s_defaultFileModuleName) { 00159 kDebug() << "Falling back to default file module."; 00160 s_module = loadFileModule(s_defaultFileModuleName); 00161 } 00162 } 00163 } 00164 return s_module; 00165 } 00166 00167 class KFileDialogPrivate 00168 { 00169 public: 00171 class Native { 00172 public: 00173 Native() 00174 : mode(KFile::File), 00175 operationMode(KAbstractFileWidget::Opening) 00176 { 00177 } 00180 KUrl startDir() const 00181 { 00182 if (!s_startDir.isEmpty()) 00183 return s_startDir; 00184 if (!selectedUrls.isEmpty()) 00185 return selectedUrls.first(); 00186 return KUrl(); 00187 } 00190 static KUrl staticStartDir( const KUrl& defaultDir ) 00191 { 00192 if ( s_startDir.isEmpty() ) 00193 return defaultDir; 00194 return s_startDir; 00195 } 00196 static KUrl s_startDir; 00197 static bool s_allowNative; // as fallback when we can't use native dialog 00198 QString filter; 00199 QString selectedFilter; 00200 QStringList mimeTypes; 00201 KUrl::List selectedUrls; 00202 KFile::Modes mode; 00203 KAbstractFileWidget::OperationMode operationMode; 00204 }; 00205 00206 KFileDialogPrivate() 00207 : native(0), 00208 w(0), 00209 cfgGroup(KGlobal::config(), ConfigGroup) 00210 { 00211 if (cfgGroup.readEntry("Native", NATIVE_FILEDIALOGS_BY_DEFAULT) && 00212 KFileDialogPrivate::Native::s_allowNative) 00213 native = new Native; 00214 } 00215 00216 static bool isNative() 00217 { 00218 if(!KFileDialogPrivate::Native::s_allowNative) 00219 return false; 00220 KConfigGroup cfgGroup(KGlobal::config(), ConfigGroup); 00221 return cfgGroup.readEntry("Native", NATIVE_FILEDIALOGS_BY_DEFAULT); 00222 } 00223 00224 static QString getOpenFileName(const KUrl& startDir, const QString& filter, 00225 QWidget *parent, const QString& caption, 00226 QString *selectedFilter); 00227 static KUrl getOpenUrl(const KUrl& startDir, const QString& filter, 00228 QWidget *parent, const QString& caption, 00229 QString *selectedFilter); 00230 static QStringList getOpenFileNames(const KUrl& startDir, const QString& filter, 00231 QWidget *parent, const QString& caption, 00232 QString *selectedFilter); 00233 static KUrl::List getOpenUrls(const KUrl& startDir, const QString& filter, 00234 QWidget *parent, const QString& caption, 00235 QString *selectedFilter); 00236 static QString getSaveFileName(const KUrl& dir, const QString& filter, 00237 QWidget *parent, const QString& caption, 00238 KFileDialog::Options options, QString *selectedFilter); 00239 static KUrl getSaveUrl(const KUrl& dir, const QString& filter, 00240 QWidget *parent, const QString& caption, 00241 KFileDialog::Options options, QString *selectedFilter); 00242 00243 ~KFileDialogPrivate() 00244 { 00245 delete native; 00246 } 00247 00248 Native* native; 00249 KAbstractFileWidget* w; 00250 KConfigGroup cfgGroup; 00251 }; 00252 00253 KUrl KFileDialogPrivate::Native::s_startDir; 00254 bool KFileDialogPrivate::Native::s_allowNative = true; 00255 00256 KFileDialog::KFileDialog( const KUrl& startDir, const QString& filter, 00257 QWidget *parent, QWidget* customWidget) 00258 #ifdef Q_WS_WIN 00259 : KDialog( parent , Qt::WindowMinMaxButtonsHint), 00260 #else 00261 : KDialog( parent ), 00262 #endif 00263 d( new KFileDialogPrivate ) 00264 00265 { 00266 // It would be nice to have this behind d->native but it doesn't work 00267 // because of derived classes like KEncodingDialog... 00268 // Dlopen the file widget from libkfilemodule 00269 QWidget* fileQWidget = fileModule()->createFileWidget(startDir, this); 00270 d->w = ::qobject_cast<KAbstractFileWidget *>(fileQWidget); 00271 00272 if (d->native) { 00273 KFileDialogPrivate::Native::s_startDir = startDir; 00274 // check if it's a mimefilter 00275 int pos = filter.indexOf('/'); 00276 if (pos > 0 && filter[pos - 1] != '\\') 00277 setMimeFilter(filter.split(QLatin1Char(' '), QString::SkipEmptyParts)); 00278 else 00279 setFilter(filter); 00280 return; 00281 } 00282 00283 setButtons( KDialog::None ); 00284 restoreDialogSize(d->cfgGroup); // call this before the fileQWidget is set as the main widget. 00285 // otherwise the sizes for the components are not obeyed (ereslibre) 00286 00287 d->w->setFilter(filter); 00288 setMainWidget(fileQWidget); 00289 00290 d->w->okButton()->show(); 00291 connect(d->w->okButton(), SIGNAL(clicked()), SLOT(slotOk())); 00292 d->w->cancelButton()->show(); 00293 connect(d->w->cancelButton(), SIGNAL( clicked() ), SLOT( slotCancel() )); 00294 00295 // Publish signals 00296 // TODO: Move the relevant signal declarations from KFileWidget to the 00297 // KAbstractFileWidget interface? 00298 // Else, all of these connects (including "accepted") are not typesafe. 00299 // Answer: you cannot define signals in a non-qobject base class (DF). 00300 // I simply documentde them in kabstractfilewidget.h now. 00301 kDebug (kfile_area) << "KFileDialog connecting signals"; 00302 connect(fileQWidget, SIGNAL(fileSelected(KUrl)), 00303 SIGNAL(fileSelected(KUrl))); 00304 connect(fileQWidget, SIGNAL(fileHighlighted(KUrl)), 00305 SIGNAL(fileHighlighted(KUrl))); 00306 connect(fileQWidget, SIGNAL(fileSelected(QString)), 00307 SIGNAL(fileSelected(QString))); 00308 connect(fileQWidget, SIGNAL(fileHighlighted(QString)), 00309 SIGNAL(fileHighlighted(QString))); 00310 connect(fileQWidget, SIGNAL(selectionChanged()), 00311 SIGNAL(selectionChanged())); 00312 connect(fileQWidget, SIGNAL(filterChanged(QString)), 00313 SIGNAL(filterChanged(QString))); 00314 00315 connect(fileQWidget, SIGNAL(accepted()), SLOT(accept())); 00316 //connect(fileQWidget, SIGNAL(canceled()), SLOT(slotCancel())); 00317 00318 if (customWidget) 00319 d->w->setCustomWidget(QString(), customWidget); 00320 } 00321 00322 00323 KFileDialog::~KFileDialog() 00324 { 00325 delete d; 00326 } 00327 00328 void KFileDialog::setLocationLabel(const QString& text) 00329 { 00330 if (d->native) 00331 return; // not available 00332 d->w->setLocationLabel(text); 00333 } 00334 00335 void KFileDialog::setFilter(const QString& filter) 00336 { 00337 if (d->native) { 00338 d->native->filter = filter; 00339 return; 00340 } 00341 d->w->setFilter(filter); 00342 } 00343 00344 QString KFileDialog::currentFilter() const 00345 { 00346 if (d->native) 00347 return QString(); // not available 00348 return d->w->currentFilter(); 00349 } 00350 00351 void KFileDialog::setMimeFilter( const QStringList& mimeTypes, 00352 const QString& defaultType ) 00353 { 00354 d->w->setMimeFilter(mimeTypes, defaultType); 00355 00356 if (d->native) { 00357 QString allExtensions; 00358 QStringList filters = mime2KdeFilter(mimeTypes, &allExtensions); 00359 if (defaultType.isEmpty() && (mimeTypes.count() > 1)) { 00360 filters.prepend(allExtensions + QLatin1Char('|') + i18n("All Supported Files")); 00361 } 00362 d->native->filter = filters.join(QLatin1String("\n")); 00363 } 00364 } 00365 00366 void KFileDialog::clearFilter() 00367 { 00368 if (d->native) { 00369 d->native->filter.clear(); 00370 return; 00371 } 00372 d->w->clearFilter(); 00373 } 00374 00375 QString KFileDialog::currentMimeFilter() const 00376 { 00377 if (d->native) { 00378 // adapted from qt2KdeFilter 00379 QString filter = d->native->selectedFilter.split(";;").replaceInStrings("/", "\\/")[0]; 00380 filter = filter.mid(filter.indexOf('(') + 1, filter.indexOf(')') - filter.indexOf('(') - 1); 00381 QString mimetype = KMimeType::findByPath("test" + filter.mid(1).split(' ')[0])->name(); 00382 return mimetype; 00383 } 00384 return d->w->currentMimeFilter(); 00385 } 00386 00387 KMimeType::Ptr KFileDialog::currentFilterMimeType() 00388 { 00389 return KMimeType::mimeType( currentMimeFilter() ); 00390 } 00391 00392 void KFileDialog::setPreviewWidget(KPreviewWidgetBase *w) 00393 { 00394 if (d->native) 00395 return; 00396 d->w->setPreviewWidget(w); 00397 } 00398 00399 void KFileDialog::setInlinePreviewShown(bool show) 00400 { 00401 if (d->native) { 00402 return; 00403 } 00404 d->w->setInlinePreviewShown(show); 00405 } 00406 00407 // This is only used for the initial size when no configuration has been saved 00408 QSize KFileDialog::sizeHint() const 00409 { 00410 int fontSize = fontMetrics().height(); 00411 QSize goodSize(48 * fontSize, 30 * fontSize); 00412 QSize screenSize = QApplication::desktop()->availableGeometry(this).size(); 00413 QSize minSize(screenSize / 2); 00414 QSize maxSize(screenSize * qreal(0.9)); 00415 return (goodSize.expandedTo(minSize).boundedTo(maxSize)); 00416 } 00417 00418 // This slot still exists mostly for compat purposes; for subclasses which reimplement slotOk 00419 void KFileDialog::slotOk() 00420 { 00421 if (d->native) 00422 return; 00423 d->w->slotOk(); 00424 } 00425 00426 // This slot still exists mostly for compat purposes; for subclasses which reimplement accept 00427 void KFileDialog::accept() 00428 { 00429 if (d->native) 00430 return; 00431 setResult( QDialog::Accepted ); // keep old behavior; probably not needed though 00432 d->w->accept(); 00433 KConfigGroup cfgGroup(KGlobal::config(), ConfigGroup); 00434 KDialog::accept(); 00435 emit okClicked(); 00436 } 00437 00438 // This slot still exists mostly for compat purposes; for subclasses which reimplement slotCancel 00439 void KFileDialog::slotCancel() 00440 { 00441 if (d->native) 00442 return; 00443 d->w->slotCancel(); 00444 reject(); 00445 } 00446 00447 void KFileDialog::setUrl(const KUrl& url, bool clearforward) 00448 { 00449 if (d->native) { 00450 d->native->selectedUrls.clear(); 00451 d->native->selectedUrls.append(url); 00452 return; 00453 } 00454 d->w->setUrl(url, clearforward); 00455 } 00456 00457 void KFileDialog::setSelection(const QString& name) 00458 { 00459 if (d->native) { 00460 d->native->selectedUrls.clear(); 00461 d->native->selectedUrls.append( KUrl(name) ); 00462 return; 00463 } 00464 d->w->setSelection(name); 00465 } 00466 00467 QString KFileDialog::getOpenFileName(const KUrl& startDir, 00468 const QString& filter, 00469 QWidget *parent, const QString& caption) 00470 { 00471 return KFileDialogPrivate::getOpenFileName(startDir, filter, parent, caption, 0); 00472 } 00473 00474 QString KFileDialogPrivate::getOpenFileName(const KUrl& startDir, 00475 const QString& filter, 00476 QWidget *parent, 00477 const QString& caption, 00478 QString *selectedFilter) 00479 { 00480 if (KFileDialogPrivate::isNative() && (!startDir.isValid() || startDir.isLocalFile())) { 00481 return QFileDialog::getOpenFileName( 00482 parent, 00483 caption.isEmpty() ? i18n("Open") : caption, 00484 KFileDialogPrivate::Native::staticStartDir( startDir ).toLocalFile(), 00485 qtFilter(filter), 00486 selectedFilter ); 00487 // TODO use extra args? QString * selectedFilter = 0, Options options = 0 00488 } 00489 KFileDialog dlg(startDir, filter, parent); 00490 00491 dlg.setOperationMode( KFileDialog::Opening ); 00492 dlg.setMode( KFile::File | KFile::LocalOnly | KFile::ExistingOnly ); 00493 dlg.setCaption(caption.isEmpty() ? i18n("Open") : caption); 00494 00495 dlg.exec(); 00496 if(selectedFilter) *selectedFilter = dlg.currentMimeFilter(); 00497 return dlg.selectedFile(); 00498 } 00499 00500 QString KFileDialog::getOpenFileNameWId(const KUrl& startDir, 00501 const QString& filter, 00502 WId parent_id, const QString& caption) 00503 { 00504 if (KFileDialogPrivate::isNative() && (!startDir.isValid() || startDir.isLocalFile())) 00505 return KFileDialog::getOpenFileName(startDir, filter, 0, caption); // everything we can do... 00506 QWidget* parent = QWidget::find( parent_id ); 00507 KFileDialogPrivate::Native::s_allowNative = false; 00508 KFileDialog dlg(startDir, filter, parent); 00509 if( parent == NULL && parent_id != 0 ) 00510 KWindowSystem::setMainWindow( &dlg, parent_id ); 00511 00512 dlg.setOperationMode( KFileDialog::Opening ); 00513 dlg.setMode( KFile::File | KFile::LocalOnly | KFile::ExistingOnly ); 00514 dlg.setCaption(caption.isEmpty() ? i18n("Open") : caption); 00515 00516 dlg.exec(); 00517 00518 return dlg.selectedFile(); 00519 } 00520 00521 QStringList KFileDialog::getOpenFileNames(const KUrl& startDir, 00522 const QString& filter, 00523 QWidget *parent, 00524 const QString& caption) 00525 { 00526 return KFileDialogPrivate::getOpenFileNames(startDir, filter, parent, caption, 0); 00527 } 00528 00529 QStringList KFileDialogPrivate::getOpenFileNames(const KUrl& startDir, 00530 const QString& filter, 00531 QWidget *parent, 00532 const QString& caption, 00533 QString *selectedFilter) 00534 { 00535 if (KFileDialogPrivate::isNative() && (!startDir.isValid() || startDir.isLocalFile())) { 00536 return QFileDialog::getOpenFileNames( 00537 parent, 00538 caption.isEmpty() ? i18n("Open") : caption, 00539 KFileDialogPrivate::Native::staticStartDir( startDir ).toLocalFile(), 00540 qtFilter( filter ), selectedFilter ); 00541 // TODO use extra args? QString * selectedFilter = 0, Options options = 0 00542 } 00543 KFileDialogPrivate::Native::s_allowNative = false; 00544 KFileDialog dlg(startDir, filter, parent); 00545 00546 dlg.setOperationMode( KFileDialog::Opening ); 00547 dlg.setMode(KFile::Files | KFile::LocalOnly | KFile::ExistingOnly); 00548 dlg.setCaption(caption.isEmpty() ? i18n("Open") : caption); 00549 00550 dlg.exec(); 00551 if(selectedFilter) *selectedFilter = dlg.currentMimeFilter(); 00552 return dlg.selectedFiles(); 00553 } 00554 00555 KUrl KFileDialog::getOpenUrl(const KUrl& startDir, const QString& filter, 00556 QWidget *parent, const QString& caption) 00557 { 00558 return KFileDialogPrivate::getOpenUrl(startDir, filter, parent, caption, 0); 00559 } 00560 KUrl KFileDialogPrivate::getOpenUrl(const KUrl& startDir, const QString& filter, 00561 QWidget *parent, const QString& caption, 00562 QString *selectedFilter) 00563 { 00564 if (KFileDialogPrivate::isNative() && (!startDir.isValid() || startDir.isLocalFile())) { 00565 const QString fileName( KFileDialogPrivate::getOpenFileName( 00566 startDir, filter, parent, caption, selectedFilter) ); 00567 return fileName.isEmpty() ? KUrl() : KUrl::fromPath(fileName); 00568 } 00569 KFileDialogPrivate::Native::s_allowNative = false; 00570 KFileDialog dlg(startDir, filter, parent); 00571 00572 dlg.setOperationMode( KFileDialog::Opening ); 00573 dlg.setMode( KFile::File | KFile::ExistingOnly ); 00574 dlg.setCaption(caption.isEmpty() ? i18n("Open") : caption); 00575 00576 dlg.exec(); 00577 if(selectedFilter) *selectedFilter = dlg.currentMimeFilter(); 00578 return dlg.selectedUrl(); 00579 } 00580 00581 KUrl::List KFileDialog::getOpenUrls(const KUrl& startDir, 00582 const QString& filter, 00583 QWidget *parent, 00584 const QString& caption) 00585 { 00586 return KFileDialogPrivate::getOpenUrls(startDir, filter, parent, caption, 0); 00587 } 00588 00589 KUrl::List KFileDialogPrivate::getOpenUrls(const KUrl& startDir, 00590 const QString& filter, 00591 QWidget *parent, 00592 const QString& caption, 00593 QString *selectedFilter) 00594 { 00595 if (KFileDialogPrivate::isNative() && (!startDir.isValid() || startDir.isLocalFile())) { 00596 const QStringList fileNames( KFileDialogPrivate::getOpenFileNames( 00597 startDir, filter, parent, caption, selectedFilter) ); 00598 return KUrl::List(fileNames); 00599 } 00600 KFileDialogPrivate::Native::s_allowNative = false; 00601 00602 KFileDialog dlg(startDir, filter, parent); 00603 00604 dlg.setOperationMode( KFileDialog::Opening ); 00605 dlg.setMode( KFile::Files | KFile::ExistingOnly ); 00606 dlg.setCaption(caption.isEmpty() ? i18n("Open") : caption); 00607 00608 dlg.exec(); 00609 if(selectedFilter) *selectedFilter = dlg.currentMimeFilter(); 00610 return dlg.selectedUrls(); 00611 } 00612 00613 void KFileDialog::setConfirmOverwrite(bool enable) 00614 { 00615 if (operationMode() == KFileDialog::Saving) { 00616 d->w->setConfirmOverwrite(enable); 00617 } 00618 } 00619 00620 KUrl KFileDialog::getExistingDirectoryUrl(const KUrl& startDir, 00621 QWidget *parent, 00622 const QString& caption) 00623 { 00624 if (KFileDialogPrivate::isNative() && (!startDir.isValid() || startDir.isLocalFile())) { 00625 QString result( QFileDialog::getExistingDirectory(parent, caption, 00626 KFileDialogPrivate::Native::staticStartDir( startDir ).toLocalFile(), 00627 QFileDialog::ShowDirsOnly) ); 00628 return result.isEmpty() ? KUrl() : KUrl::fromPath(result); 00629 } 00630 return fileModule()->selectDirectory(startDir, false, parent, caption); 00631 } 00632 00633 QString KFileDialog::getExistingDirectory(const KUrl& startDir, 00634 QWidget *parent, 00635 const QString& caption) 00636 { 00637 if (KFileDialogPrivate::isNative() && (!startDir.isValid() || startDir.isLocalFile())) { 00638 return QFileDialog::getExistingDirectory(parent, caption, 00639 KFileDialogPrivate::Native::staticStartDir( startDir ).toLocalFile(), 00640 QFileDialog::ShowDirsOnly); 00641 } 00642 KUrl url = fileModule()->selectDirectory(startDir, true, parent, caption); 00643 if ( url.isValid() ) 00644 return url.path(); 00645 return QString(); 00646 } 00647 00648 KUrl KFileDialog::getImageOpenUrl( const KUrl& startDir, QWidget *parent, 00649 const QString& caption) 00650 { 00651 if (KFileDialogPrivate::isNative() && (!startDir.isValid() || startDir.isLocalFile())) { // everything we can do... 00652 const QStringList mimetypes( KImageIO::mimeTypes( KImageIO::Reading ) ); 00653 return KFileDialog::getOpenUrl(startDir, mimetypes.join(" "), parent, caption); 00654 } 00655 const QStringList mimetypes = KImageIO::mimeTypes( KImageIO::Reading ); 00656 KFileDialogPrivate::Native::s_allowNative = false; 00657 KFileDialog dlg(startDir, mimetypes.join(" "), parent); 00658 00659 dlg.setOperationMode( KFileDialog::Opening ); 00660 dlg.setMode( KFile::File | KFile::ExistingOnly ); 00661 dlg.setCaption( caption.isEmpty() ? i18n("Open") : caption ); 00662 dlg.setInlinePreviewShown( true ); 00663 00664 dlg.exec(); 00665 00666 return dlg.selectedUrl(); 00667 } 00668 00669 KUrl KFileDialog::selectedUrl() const 00670 { 00671 if (d->native) 00672 return d->native->selectedUrls.isEmpty() ? KUrl() : d->native->selectedUrls.first(); 00673 return d->w->selectedUrl(); 00674 } 00675 00676 KUrl::List KFileDialog::selectedUrls() const 00677 { 00678 if (d->native) 00679 return d->native->selectedUrls; 00680 return d->w->selectedUrls(); 00681 } 00682 00683 QString KFileDialog::selectedFile() const 00684 { 00685 if (d->native) 00686 return selectedUrl().toLocalFile(); 00687 return d->w->selectedFile(); 00688 } 00689 00690 QStringList KFileDialog::selectedFiles() const 00691 { 00692 if (d->native) 00693 return selectedUrls().toStringList(); 00694 return d->w->selectedFiles(); 00695 } 00696 00697 KUrl KFileDialog::baseUrl() const 00698 { 00699 if (d->native) 00700 return selectedUrl().isEmpty() ? KUrl() : KUrl::fromPath(selectedUrl().path()); 00701 return d->w->baseUrl(); 00702 } 00703 00704 QString KFileDialog::getSaveFileName(const KUrl& dir, const QString& filter, 00705 QWidget *parent, 00706 const QString& caption) 00707 { 00708 //TODO KDE5: replace this method by the method below (with default parameter values in declaration) 00709 // Set no confirm-overwrite mode for backwards compatibility 00710 return KFileDialogPrivate::getSaveFileName(dir, filter, parent, caption, Options(0), 0); 00711 } 00712 00713 QString KFileDialog::getSaveFileName(const KUrl& dir, const QString& filter, 00714 QWidget *parent, 00715 const QString& caption, Options options) 00716 { 00717 return KFileDialogPrivate::getSaveFileName(dir, filter, parent, caption, options, 0); 00718 } 00719 00720 QString KFileDialogPrivate::getSaveFileName(const KUrl& dir, const QString& filter, 00721 QWidget *parent, const QString& caption, 00722 KFileDialog::Options options, QString *selectedFilter) 00723 { 00724 if (KFileDialogPrivate::isNative()) { 00725 bool defaultDir = dir.isEmpty(); 00726 bool specialDir = !defaultDir && dir.protocol() == "kfiledialog"; 00727 KUrl startDir; 00728 QString recentDirClass; 00729 if (specialDir) { 00730 startDir = KFileDialog::getStartUrl(dir, recentDirClass); 00731 } 00732 else if ( !specialDir && !defaultDir ) { 00733 if (!dir.isLocalFile()) 00734 kWarning() << "non-local start dir " << dir; 00735 startDir = dir; 00736 } 00737 00738 QFileDialog::Options opts = (options & KFileDialog::ConfirmOverwrite) ? QFileDialog::Options(0) : QFileDialog::DontConfirmOverwrite; 00739 const QString result = QFileDialog::getSaveFileName( 00740 parent, 00741 caption.isEmpty() ? i18n("Save As") : caption, 00742 KFileDialogPrivate::Native::staticStartDir( startDir ).toLocalFile(), 00743 qtFilter(filter), 00744 // TODO use extra args? QString * selectedFilter = 0, Options opts = 0 00745 selectedFilter, opts ); 00746 if (!result.isEmpty()) { 00747 if (!recentDirClass.isEmpty()) 00748 KRecentDirs::add(recentDirClass, KUrl::fromPath(result).url()); 00749 KRecentDocument::add(result); 00750 } 00751 return result; 00752 } 00753 00754 KFileDialog dlg(dir, filter, parent); 00755 00756 dlg.setOperationMode( KFileDialog::Saving ); 00757 dlg.setMode( KFile::File | KFile::LocalOnly ); 00758 dlg.setConfirmOverwrite(options & KFileDialog::ConfirmOverwrite); 00759 dlg.setInlinePreviewShown(options & KFileDialog::ShowInlinePreview); 00760 dlg.setCaption(caption.isEmpty() ? i18n("Save As") : caption); 00761 00762 dlg.exec(); 00763 00764 QString filename = dlg.selectedFile(); 00765 if (!filename.isEmpty()) 00766 KRecentDocument::add(filename); 00767 00768 return filename; 00769 } 00770 00771 QString KFileDialog::getSaveFileNameWId(const KUrl& dir, const QString& filter, 00772 WId parent_id, 00773 const QString& caption) 00774 { 00775 //TODO KDE5: replace this method by the method below (with default parameter values in declaration) 00776 // Set no confirm-overwrite mode for backwards compatibility 00777 return getSaveFileNameWId(dir, filter, parent_id, caption, Options(0)); 00778 } 00779 00780 QString KFileDialog::getSaveFileNameWId(const KUrl& dir, const QString& filter, 00781 WId parent_id, 00782 const QString& caption, Options options) 00783 { 00784 if (KFileDialogPrivate::isNative()) { 00785 return KFileDialog::getSaveFileName(dir, filter, 0, caption, options); // everything we can do... 00786 } 00787 00788 QWidget* parent = QWidget::find( parent_id ); 00789 KFileDialog dlg(dir, filter, parent); 00790 if( parent == NULL && parent_id != 0 ) 00791 KWindowSystem::setMainWindow( &dlg, parent_id); 00792 00793 dlg.setOperationMode( KFileDialog::Saving ); 00794 dlg.setMode( KFile::File | KFile::LocalOnly ); 00795 dlg.setConfirmOverwrite(options & ConfirmOverwrite); 00796 dlg.setInlinePreviewShown(options & ShowInlinePreview); 00797 dlg.setCaption(caption.isEmpty() ? i18n("Save As") : caption); 00798 00799 dlg.exec(); 00800 00801 QString filename = dlg.selectedFile(); 00802 if (!filename.isEmpty()) 00803 KRecentDocument::add(filename); 00804 00805 return filename; 00806 } 00807 00808 KUrl KFileDialog::getSaveUrl(const KUrl& dir, const QString& filter, 00809 QWidget *parent, const QString& caption) 00810 { 00811 //TODO KDE5: replace this method by the method below (with default parameter values in declaration) 00812 // Set no confirm-overwrite mode for backwards compatibility 00813 return KFileDialogPrivate::getSaveUrl(dir, filter, parent, caption, Options(0), 0); 00814 } 00815 00816 KUrl KFileDialog::getSaveUrl(const KUrl& dir, const QString& filter, 00817 QWidget *parent, const QString& caption, Options options) 00818 { 00819 return KFileDialogPrivate::getSaveUrl(dir, filter, parent, caption, options, 0); 00820 } 00821 KUrl KFileDialogPrivate::getSaveUrl(const KUrl& dir, const QString& filter, 00822 QWidget *parent, const QString& caption, 00823 KFileDialog::Options options, QString *selectedFilter) 00824 { 00825 if (KFileDialogPrivate::isNative() && (!dir.isValid() || dir.isLocalFile())) { 00826 const QString fileName( KFileDialogPrivate::getSaveFileName( 00827 dir, filter, parent, caption, options, selectedFilter) ); 00828 return fileName.isEmpty() ? KUrl() : KUrl::fromPath(fileName); 00829 } 00830 00831 KFileDialogPrivate::Native::s_allowNative = false; 00832 00833 KFileDialog dlg(dir, filter, parent); 00834 00835 dlg.setOperationMode( KFileDialog::Saving ); 00836 dlg.setMode( KFile::File ); 00837 dlg.setConfirmOverwrite(options & KFileDialog::ConfirmOverwrite); 00838 dlg.setInlinePreviewShown(options & KFileDialog::ShowInlinePreview); 00839 dlg.setCaption(caption.isEmpty() ? i18n("Save As") : caption); 00840 00841 dlg.exec(); 00842 if(selectedFilter) *selectedFilter = dlg.currentMimeFilter(); 00843 KUrl url = dlg.selectedUrl(); 00844 if (url.isValid()) 00845 KRecentDocument::add( url ); 00846 00847 return url; 00848 } 00849 00850 void KFileDialog::setMode( KFile::Modes m ) 00851 { 00852 if (d->native) 00853 d->native->mode = m; 00854 else 00855 d->w->setMode(m); 00856 } 00857 00858 KFile::Modes KFileDialog::mode() const 00859 { 00860 if (d->native) 00861 return d->native->mode; 00862 return d->w->mode(); 00863 } 00864 00865 KPushButton * KFileDialog::okButton() const 00866 { 00867 return d->w->okButton(); 00868 } 00869 00870 KPushButton * KFileDialog::cancelButton() const 00871 { 00872 return d->w->cancelButton(); 00873 } 00874 00875 KUrlComboBox* KFileDialog::locationEdit() const 00876 { 00877 return d->w->locationEdit(); 00878 } 00879 00880 KFileFilterCombo* KFileDialog::filterWidget() const 00881 { 00882 return d->w->filterWidget(); 00883 } 00884 00885 KActionCollection * KFileDialog::actionCollection() const 00886 { 00887 return d->w->actionCollection(); 00888 } 00889 00890 void KFileDialog::setKeepLocation( bool keep ) 00891 { 00892 if (d->native) 00893 return; 00894 d->w->setKeepLocation(keep); 00895 } 00896 00897 bool KFileDialog::keepsLocation() const 00898 { 00899 if (d->native) 00900 return false; 00901 return d->w->keepsLocation(); 00902 } 00903 00904 void KFileDialog::setOperationMode( OperationMode mode ) 00905 { 00906 if (d->native) 00907 d->native->operationMode = static_cast<KAbstractFileWidget::OperationMode>(mode); 00908 else 00909 d->w->setOperationMode(static_cast<KAbstractFileWidget::OperationMode>(mode)); 00910 } 00911 00912 KFileDialog::OperationMode KFileDialog::operationMode() const 00913 { 00914 if (d->native) 00915 return static_cast<KFileDialog::OperationMode>(d->native->operationMode); 00916 return static_cast<KFileDialog::OperationMode>(d->w->operationMode()); 00917 } 00918 00919 void KFileDialog::keyPressEvent( QKeyEvent *e ) 00920 { 00921 if (d->native) 00922 return; 00923 00924 if ( e->key() == Qt::Key_Escape ) 00925 { 00926 e->accept(); 00927 d->w->cancelButton()->animateClick(); 00928 } 00929 else 00930 KDialog::keyPressEvent( e ); 00931 } 00932 00933 void KFileDialog::hideEvent( QHideEvent *e ) 00934 { 00935 if (d->native) 00936 return; 00937 00938 saveDialogSize(d->cfgGroup, KConfigBase::Persistent); 00939 00940 KDialog::hideEvent( e ); 00941 } 00942 00943 // static 00944 KUrl KFileDialog::getStartUrl( const KUrl& startDir, 00945 QString& recentDirClass ) 00946 { 00947 return fileModule()->getStartUrl(startDir, recentDirClass); 00948 } 00949 00950 void KFileDialog::setStartDir( const KUrl& directory ) 00951 { 00952 if (KFileDialogPrivate::isNative()) 00953 KFileDialogPrivate::Native::s_startDir = directory; 00954 fileModule()->setStartDir(directory); 00955 } 00956 00957 KToolBar * KFileDialog::toolBar() const 00958 { 00959 return d->w->toolBar(); 00960 } 00961 00962 KAbstractFileWidget* KFileDialog::fileWidget() 00963 { 00964 return d->w; 00965 } 00966 00967 #ifdef Q_WS_WIN 00968 int KFileDialog::exec() 00969 { 00970 if (!d->native || !KFileDialogPrivate::Native::s_allowNative) { 00971 KFileDialogPrivate::Native::s_allowNative = true; 00972 return KDialog::exec(); 00973 } 00974 00975 // not clear here to let KFileDialogPrivate::Native::startDir() return a useful value 00976 // d->native->selectedUrls.clear(); 00977 int res = QDialog::Rejected; 00978 switch (d->native->operationMode) { 00979 case KAbstractFileWidget::Opening: 00980 case KAbstractFileWidget::Other: 00981 if (d->native->mode & KFile::File) { 00982 KUrl url( KFileDialogPrivate::getOpenUrl( 00983 d->native->startDir(), d->native->filter, parentWidget(), windowTitle(), &d->native->selectedFilter ) ); 00984 if (url.isEmpty() || !url.isValid()) { 00985 res = QDialog::Rejected; 00986 break; 00987 } 00988 d->native->selectedUrls.clear(); 00989 d->native->selectedUrls.append(url); 00990 res = QDialog::Accepted; 00991 break; 00992 } 00993 else if (d->native->mode & KFile::Files) { 00994 KUrl::List urls( KFileDialogPrivate::getOpenUrls( 00995 d->native->startDir(), d->native->filter, parentWidget(), windowTitle(), &d->native->selectedFilter ) ); 00996 if (urls.isEmpty()) { 00997 res = QDialog::Rejected; 00998 break; 00999 } 01000 d->native->selectedUrls = urls; 01001 res = QDialog::Accepted; 01002 break; 01003 } 01004 else if (d->native->mode & KFile::Directory) { 01005 KUrl url( KFileDialog::getExistingDirectoryUrl( 01006 d->native->startDir(), parentWidget(), windowTitle()) ); 01007 if (url.isEmpty() || !url.isValid()) { 01008 res = QDialog::Rejected; 01009 } 01010 d->native->selectedUrls.clear(); 01011 d->native->selectedUrls.append(url); 01012 res = QDialog::Accepted; 01013 break; 01014 } 01015 break; 01016 case KAbstractFileWidget::Saving: 01017 if (d->native->mode & KFile::File) { 01018 KUrl url( KFileDialogPrivate::getSaveUrl( 01019 d->native->startDir(), d->native->filter, parentWidget(), windowTitle(), Options(0), &d->native->selectedFilter ) ); 01020 if (url.isEmpty() || !url.isValid()) { 01021 res = QDialog::Rejected; 01022 break; 01023 } 01024 d->native->selectedUrls.clear(); 01025 d->native->selectedUrls.append(url); 01026 res = QDialog::Accepted; 01027 break; 01028 } 01029 else if (d->native->mode & KFile::Directory) { 01030 KUrl url( KFileDialog::getExistingDirectoryUrl( 01031 d->native->startDir(), parentWidget(), windowTitle()) ); 01032 if (url.isEmpty() || !url.isValid()) { 01033 res = QDialog::Rejected; 01034 break; 01035 } 01036 d->native->selectedUrls.clear(); 01037 d->native->selectedUrls.append(url); 01038 res = QDialog::Accepted; 01039 break; 01040 } 01041 break; 01042 default:; 01043 } 01044 01045 setResult(res); 01046 emit finished(); 01047 01048 if (res == QDialog::Accepted) { 01049 emit accepted(); 01050 } else { 01051 emit rejected(); 01052 } 01053 01054 return res; 01055 } 01056 #endif // Q_WS_WIN 01057 01058 #ifdef Q_WS_WIN 01059 #define KF_EXTERN extern __declspec(dllimport) 01060 #else 01061 #define KF_EXTERN extern 01062 #endif 01063 01064 typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, 01065 const QString &dir, 01066 QFileDialog::Options options); 01067 KF_EXTERN _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook; 01068 01069 typedef QString (*_qt_filedialog_open_filename_hook)(QWidget * parent, const QString &caption, 01070 const QString &dir, const QString &filter, 01071 QString *selectedFilter, 01072 QFileDialog::Options options); 01073 KF_EXTERN _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook; 01074 01075 typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, 01076 const QString &dir, const QString &filter, 01077 QString *selectedFilter, 01078 QFileDialog::Options options); 01079 KF_EXTERN _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook; 01080 01081 typedef QString (*_qt_filedialog_save_filename_hook)(QWidget * parent, const QString &caption, 01082 const QString &dir, const QString &filter, 01083 QString *selectedFilter, 01084 QFileDialog::Options options); 01085 KF_EXTERN _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook; 01086 01087 /* 01088 * This class is used to override Qt's QFileDialog calls with KFileDialog ones. 01089 * This is necessary because QPrintDialog calls QFileDialog::getSaveFileName() for 01090 * the print to file function. 01091 */ 01092 class KFileDialogQtOverride 01093 { 01094 public: 01095 KFileDialogQtOverride() 01096 { 01097 if(!qt_filedialog_existing_directory_hook) 01098 qt_filedialog_existing_directory_hook=&getExistingDirectory; 01099 if(!qt_filedialog_open_filename_hook) 01100 qt_filedialog_open_filename_hook=&getOpenFileName; 01101 if(!qt_filedialog_open_filenames_hook) 01102 qt_filedialog_open_filenames_hook=&getOpenFileNames; 01103 if(!qt_filedialog_save_filename_hook) 01104 qt_filedialog_save_filename_hook=&getSaveFileName; 01105 } 01106 01107 ~KFileDialogQtOverride() { 01108 if(qt_filedialog_existing_directory_hook == &getExistingDirectory) 01109 qt_filedialog_existing_directory_hook = 0; 01110 if(qt_filedialog_open_filename_hook == &getOpenFileName) 01111 qt_filedialog_open_filename_hook = 0; 01112 if(qt_filedialog_open_filenames_hook == &getOpenFileNames) 01113 qt_filedialog_open_filenames_hook=0; 01114 if(qt_filedialog_save_filename_hook == &getSaveFileName) 01115 qt_filedialog_save_filename_hook=0; 01116 } 01117 01118 /* 01119 * Map a Qt filter string into a KDE one. 01120 */ 01121 static QString qt2KdeFilter(const QString &f) 01122 { 01123 QString filter; 01124 QTextStream str(&filter, QIODevice::WriteOnly); 01125 QStringList list(f.split(";;").replaceInStrings("/", "\\/")); 01126 QStringList::const_iterator it(list.begin()), 01127 end(list.end()); 01128 bool first=true; 01129 01130 for(; it!=end; ++it) 01131 { 01132 int ob=(*it).lastIndexOf('('), 01133 cb=(*it).lastIndexOf(')'); 01134 01135 if(-1!=cb && ob<cb) 01136 { 01137 if(first) 01138 first=false; 01139 else 01140 str << '\n'; 01141 str << (*it).mid(ob+1, (cb-ob)-1) << '|' << (*it).mid(0, ob); 01142 } 01143 } 01144 01145 return filter; 01146 } 01147 01148 /* 01149 * Map a KDE filter string into a Qt one. 01150 */ 01151 static void kde2QtFilter(const QString &orig, const QString &kde, QString *sel) 01152 { 01153 if(sel) 01154 { 01155 QStringList list(orig.split(";;")); 01156 QStringList::const_iterator it(list.begin()), 01157 end(list.end()); 01158 int pos; 01159 01160 for(; it!=end; ++it) 01161 if(-1!=(pos=(*it).indexOf(kde)) && pos>0 && 01162 ('('==(*it)[pos-1] || ' '==(*it)[pos-1]) && 01163 (*it).length()>=kde.length()+pos && 01164 (')'==(*it)[pos+kde.length()] || ' '==(*it)[pos+kde.length()])) 01165 { 01166 *sel=*it; 01167 return; 01168 } 01169 } 01170 } 01171 01172 static QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, 01173 QFileDialog::Options options) 01174 { 01175 if (KFileDialogPrivate::isNative()) { 01176 if(qt_filedialog_existing_directory_hook) 01177 qt_filedialog_existing_directory_hook=0; // do not override 01178 return QFileDialog::getExistingDirectory(parent, caption, dir, options); 01179 } 01180 01181 KUrl url(KFileDialog::getExistingDirectory(KUrl(dir), parent, caption)); 01182 01183 if(url.isLocalFile()) 01184 return url.pathOrUrl(); 01185 else 01186 return QString(); 01187 } 01188 01189 static QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, 01190 const QString &filter, QString *selectedFilter, 01191 QFileDialog::Options options) 01192 { 01193 if (KFileDialogPrivate::isNative()) { 01194 if(qt_filedialog_open_filename_hook) 01195 qt_filedialog_open_filename_hook=0; // do not override 01196 return QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options); 01197 } 01198 01199 KFileDialog dlg(KUrl(dir), qt2KdeFilter(filter), parent); 01200 01201 dlg.setOperationMode(KFileDialog::Opening); 01202 dlg.setMode(KFile::File|KFile::LocalOnly); 01203 dlg.setCaption(caption); 01204 dlg.exec(); 01205 01206 QString rv(dlg.selectedFile()); 01207 01208 if(!rv.isEmpty()) 01209 kde2QtFilter(filter, dlg.currentFilter(), selectedFilter); 01210 01211 return rv; 01212 } 01213 01214 static QStringList getOpenFileNames(QWidget *parent, const QString &caption, const QString &dir, 01215 const QString &filter, QString *selectedFilter, 01216 QFileDialog::Options options) 01217 { 01218 if (KFileDialogPrivate::isNative()) { 01219 if(qt_filedialog_open_filenames_hook) 01220 qt_filedialog_open_filenames_hook=0; // do not override 01221 return QFileDialog::getOpenFileNames(parent, caption, dir, filter, selectedFilter, options); 01222 } 01223 01224 KFileDialog dlg(KUrl(dir), qt2KdeFilter(filter), parent); 01225 01226 dlg.setOperationMode(KFileDialog::Opening); 01227 dlg.setMode(KFile::Files|KFile::LocalOnly); 01228 dlg.setCaption(caption); 01229 dlg.exec(); 01230 01231 QStringList rv(dlg.selectedFiles()); 01232 01233 if(rv.count()) 01234 kde2QtFilter(filter, dlg.currentFilter(), selectedFilter); 01235 01236 return rv; 01237 } 01238 01239 static QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, 01240 const QString &filter, QString *selectedFilter, 01241 QFileDialog::Options options) 01242 { 01243 if (KFileDialogPrivate::isNative()) { 01244 if(qt_filedialog_save_filename_hook) 01245 qt_filedialog_save_filename_hook=0; // do not override 01246 return QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options); 01247 } 01248 01249 KFileDialog dlg(KUrl(dir), qt2KdeFilter(filter), parent); 01250 01251 dlg.setOperationMode(KFileDialog::Saving); 01252 dlg.setMode(KFile::File|KFile::LocalOnly); 01253 dlg.setCaption(caption); 01254 dlg.setConfirmOverwrite(!(options & QFileDialog::DontConfirmOverwrite)); 01255 dlg.exec(); 01256 01257 QString rv(dlg.selectedFile()); 01258 01259 if(!rv.isEmpty()) 01260 kde2QtFilter(filter, dlg.currentFilter(), selectedFilter); 01261 01262 return rv; 01263 } 01264 01265 }; 01266 01267 static KFileDialogQtOverride qtOverride; 01268 01269 #include "kfiledialog.moc"
KDE 4.6 API Reference