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