File indexing completed on 2025-01-12 12:26:24
0001 // -*- c++ -*- 0002 /* This file is part of the KDE libraries 0003 Copyright (C) 1997, 1998 Richard Moore <rich@kde.org> 0004 1998 Stephan Kulow <coolo@kde.org> 0005 1998 Daniel Grana <grana@ie.iwi.unibe.ch> 0006 2000,2001 Carsten Pfeiffer <pfeiffer@kde.org> 0007 2001 Frerich Raabe <raabe@kde.org> 0008 2007 David Faure <faure@kde.org> 0009 2009 David Jarvie <djarvie@kde.org> 0010 0011 This library is free software; you can redistribute it and/or 0012 modify it under the terms of the GNU Library General Public 0013 License as published by the Free Software Foundation; either 0014 version 2 of the License, or (at your option) any later version. 0015 0016 This library is distributed in the hope that it will be useful, 0017 but WITHOUT ANY WARRANTY; without even the implied warranty of 0018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0019 Library General Public License for more details. 0020 0021 You should have received a copy of the GNU Library General Public License 0022 along with this library; see the file COPYING.LIB. If not, write to 0023 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0024 Boston, MA 02110-1301, USA. 0025 */ 0026 0027 #ifndef KFILEDIALOG_H 0028 #define KFILEDIALOG_H 0029 0030 #include <kdelibs4support_export.h> 0031 #include <QDialog> 0032 #include <kfile.h> 0033 #include <qmimetype.h> 0034 #include <QUrl> 0035 0036 class KFileWidget; 0037 0038 class KActionCollection; 0039 class KUrlComboBox; 0040 class KFileFilterCombo; 0041 class QPushButton; 0042 class KToolBar; 0043 class KPreviewWidgetBase; 0044 0045 class KFileDialogPrivate; 0046 0047 /** 0048 * @warning This class should be avoided in new code. 0049 * QFileDialog should be used instead. 0050 * @see QFileDialog 0051 * 0052 * Provides a user (and developer) friendly way to 0053 * select files and directories. 0054 * 0055 * The widget can be used as a drop in replacement for the 0056 * QFileDialog widget, but has greater functionality and a nicer GUI. 0057 * 0058 * You will usually want to use one of the static methods 0059 * getOpenFileName(), getSaveFileName(), getOpenUrl() 0060 * or for multiple files getOpenFileNames() or getOpenUrls(). 0061 * 0062 * The dialog has been designed to allow applications to customize it 0063 * by subclassing. It uses geometry management to ensure that subclasses 0064 * can easily add children that will be incorporated into the layout. 0065 * 0066 * \image html kfiledialog.png "KDE File Dialog" 0067 * 0068 * @short A file selection dialog. 0069 * 0070 * @deprecated since 5.0, use the QFileDialog API instead. 0071 * Note that when the KDE QPA theme plugin is installed, the KFileWidget will then 0072 * be used automatically. 0073 */ 0074 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KFileDialog : public QDialog 0075 { 0076 Q_OBJECT 0077 0078 public: 0079 0080 /** 0081 * Defines some default behavior of the filedialog. 0082 * E.g. in mode @p Opening and @p Saving, the selected files/urls will 0083 * be added to the "recent documents" list. The Saving mode also implies 0084 * setKeepLocation() being set. 0085 * 0086 * @p Other means that no default actions are performed. 0087 * 0088 * @see setOperationMode 0089 * @see operationMode 0090 */ 0091 enum OperationMode { Other = 0, Opening, Saving }; 0092 0093 /** 0094 * Defines the options to use when calling getSave* functions. 0095 * @since 4.4 0096 */ 0097 enum Option { 0098 ConfirmOverwrite = 0x01, /**< Confirm whether to overwrite file to save. */ 0099 ShowInlinePreview = 0x02 /**< Always show an inline preview. */ 0100 }; 0101 Q_DECLARE_FLAGS(Options, Option) 0102 0103 /** 0104 * Constructs a file dialog. 0105 * 0106 * @param startDir Specifies the starting directory and/or initially selected 0107 * file name, or a last used directory and optional file name 0108 * using the @c kfiledialog:/// syntax. 0109 * Refer to the KFileWidget documentation for more information 0110 * on this parameter. 0111 * 0112 * @param filter A shell glob or a mimetype filter that specifies 0113 * which files to display. For better consistency across applications, 0114 * it is recommended to use a mimetype filter. 0115 * See setFilter() and setMimeFilter() for details on how to use this argument. 0116 * 0117 * @param parent The parent widget of this dialog 0118 * 0119 * @param widget A widget, or a widget of widgets, for displaying custom 0120 * data in the dialog. This can be used, for example, to 0121 * display a check box with the caption "Open as read-only". 0122 * When creating this widget, you don't need to specify a parent, 0123 * since the widget's parent will be set automatically by KFileDialog. 0124 * 0125 * @see KFileWidget::KFileWidget() 0126 */ 0127 KFileDialog(const QUrl &startDir, const QString &filter, 0128 QWidget *parent, QWidget *widget = nullptr); 0129 0130 /** 0131 * Destructs the file dialog. 0132 */ 0133 ~KFileDialog() override; 0134 0135 /** 0136 * @returns The selected fully qualified filename. 0137 */ 0138 QUrl selectedUrl() const; 0139 0140 /** 0141 * @returns The list of selected URLs. 0142 */ 0143 QList<QUrl> selectedUrls() const; 0144 0145 /** 0146 * @returns the currently shown directory. 0147 */ 0148 QUrl baseUrl() const; 0149 0150 /** 0151 * Returns the full path of the selected file in the local filesystem. 0152 * (Local files only) 0153 */ 0154 QString selectedFile() const; 0155 0156 /** 0157 * Returns a list of all selected local files. 0158 */ 0159 QStringList selectedFiles() const; 0160 0161 /** 0162 * Sets the directory to view. 0163 * 0164 * @param url URL to show. 0165 * @param clearforward Indicates whether the forward queue 0166 * should be cleared. 0167 */ 0168 void setUrl(const QUrl &url, bool clearforward = true); 0169 0170 /** 0171 * Sets the file name to preselect to @p name 0172 * 0173 * This takes absolute URLs and relative file names. 0174 */ 0175 void setSelection(const QString &name); 0176 0177 /** 0178 * Sets the operational mode of the filedialog to @p Saving, @p Opening 0179 * or @p Other. This will set some flags that are specific to loading 0180 * or saving files. E.g. setKeepLocation() makes mostly sense for 0181 * a save-as dialog. So setOperationMode( KFileDialog::Saving ); sets 0182 * setKeepLocation for example. 0183 * 0184 * The mode @p Saving, together with a default filter set via 0185 * setMimeFilter() will make the filter combobox read-only. 0186 * 0187 * The default mode is @p Opening. 0188 * 0189 * Call this method right after instantiating KFileDialog. 0190 * 0191 * @see operationMode 0192 * @see KFileDialog::OperationMode 0193 */ 0194 void setOperationMode(KFileDialog::OperationMode); 0195 0196 /** 0197 * @returns the current operation mode, Opening, Saving or Other. Default 0198 * is Other. 0199 * 0200 * @see operationMode 0201 * @see KFileDialog::OperationMode 0202 */ 0203 OperationMode operationMode() const; 0204 0205 /** 0206 * Sets whether the filename/url should be kept when changing directories. 0207 * This is for example useful when having a predefined filename where 0208 * the full path for that file is searched. 0209 * 0210 * This is implicitly set when operationMode() is KFileDialog::Saving 0211 * 0212 * getSaveFileName() and getSaveUrl() set this to true by default, so that 0213 * you can type in the filename and change the directory without having 0214 * to type the name again. 0215 */ 0216 void setKeepLocation(bool keep); 0217 0218 /** 0219 * @returns whether the contents of the location edit are kept when 0220 * changing directories. 0221 */ 0222 bool keepsLocation() const; 0223 0224 /** 0225 * Sets the filter to be used to @p filter. 0226 * 0227 * The filter can be either set as a space-separated list of 0228 * mimetypes, which is recommended, or as a list of shell globs 0229 * separated by @c '\\n'. 0230 * 0231 * If the filter contains an unescaped @c '/', a mimetype filter is assumed. 0232 * If you would like a @c '/' visible in your filter it can be escaped with 0233 * a @c '\'. You can specify multiple mimetypes like this (separated with 0234 * space): 0235 * 0236 * \code 0237 * kfile->setFilter( "image/png text/html text/plain" ); 0238 * \endcode 0239 * 0240 * When showing the filter to the user, the mimetypes will be automatically 0241 * translated into their description like `PNG image'. Multiple mimetypes 0242 * will be automatically summarized to a filter item `All supported files'. 0243 * To add a filter item for all files matching @c '*', add @c application/octet-stream 0244 * as mimetype. 0245 * 0246 * If the filter contains no unescaped @c '/', it is assumed that 0247 * the filter contains conventional shell globs. Several filter items 0248 * to select from can be separated by @c '\\n'. Every 0249 * filter entry is defined through @c namefilter|text to display. 0250 * If no @c '|' is found in the expression, just the namefilter is 0251 * shown. Examples: 0252 * 0253 * \code 0254 * kfile->setFilter("*.cpp|C++ Source Files\n*.h|Header files"); 0255 * kfile->setFilter("*.cpp"); 0256 * kfile->setFilter("*.cpp|Sources (*.cpp)"); 0257 * kfile->setFilter("*.cpp|" + i18n("Sources (*.cpp)")); 0258 * kfile->setFilter("*.cpp *.cc *.C|C++ Source Files\n*.h *.H|Header files"); 0259 * \endcode 0260 * 0261 * Note: The text to display is not parsed in any way. So, if you 0262 * want to show the suffix to select by a specific filter, you must 0263 * repeat it. 0264 * 0265 * For better consistency across applications, it is recommended to use a 0266 * mimetype filter. 0267 * 0268 * @see filterChanged 0269 * @see setMimeFilter 0270 */ 0271 void setFilter(const QString &filter); 0272 0273 /** 0274 * Returns the current filter as entered by the user or one of the 0275 * predefined set via setFilter(). 0276 * 0277 * @see setFilter() 0278 * @see filterChanged() 0279 */ 0280 QString currentFilter() const; 0281 0282 /** 0283 * Returns the mimetype for the desired output format. 0284 * 0285 * This is only valid if setMimeFilter() has been called 0286 * previously. 0287 * 0288 * @see setFilterMimeType() 0289 */ 0290 QMimeType currentFilterMimeType(); 0291 0292 /** 0293 * Sets the filter up to specify the output type. 0294 * 0295 * @param types a list of mimetypes that can be used as output format 0296 * @param defaultType the default mimetype to use as output format, if any. 0297 * If @p defaultType is set, it will be set as the current item. 0298 * Otherwise, a first item showing all the mimetypes will be created. 0299 * Typically, @p defaultType should be empty for loading and set for saving. 0300 * 0301 * Do not use in conjunction with setFilter() 0302 */ 0303 void setMimeFilter(const QStringList &types, 0304 const QString &defaultType = QString()); 0305 0306 /** 0307 * The mimetype for the desired output format. 0308 * 0309 * This is only valid if setMimeFilter() has been called 0310 * previously. 0311 * 0312 * @see setMimeFilter() 0313 */ 0314 QString currentMimeFilter() const; 0315 0316 /** 0317 * Clears any mime- or namefilter. Does not reload the directory. 0318 */ 0319 void clearFilter(); 0320 0321 /** 0322 * Adds a preview widget and enters the preview mode. 0323 * 0324 * In this mode the dialog is split and the right part contains your 0325 * preview widget. 0326 * 0327 * Ownership is transferred to KFileDialog. You need to create the 0328 * preview-widget with "new", i.e. on the heap. 0329 * 0330 * @param w The widget to be used for the preview. 0331 */ 0332 void setPreviewWidget(KPreviewWidgetBase *w); 0333 0334 /** 0335 * Forces the inline previews to be shown or hidden, depending on @p show. 0336 * 0337 * @param show Whether to show inline previews or not. 0338 * @since 4.2 0339 */ 0340 void setInlinePreviewShown(bool show); 0341 0342 /** 0343 * Sets whether the dialog should ask before accepting the selected file 0344 * when KFileDialog::OperationMode is set to Saving. 0345 * 0346 * In this case a KMessageBox appears for confirmation. 0347 * 0348 * @param enable Set this to true to enable checking. 0349 * @since 4.2 0350 */ 0351 void setConfirmOverwrite(bool enable); 0352 0353 /** @see QWidget::sizeHint() */ 0354 QSize sizeHint() const override; 0355 0356 /** 0357 * Creates a modal file dialog and return the selected 0358 * filename or an empty string if none was chosen. 0359 * 0360 * Note that with 0361 * this method the user must select an existing filename. 0362 * 0363 * @param startDir Starting directory or @c kfiledialog:/// URL. 0364 * Refer to the KFileWidget documentation for more information 0365 * on this parameter. 0366 * @param filter A shell glob or a mimetype filter that specifies which files to display. 0367 * The preferred option is to set a list of mimetype names, see setMimeFilter() for details. 0368 * Otherwise you can set the text to be displayed for the each glob, and 0369 * provide multiple globs, see setFilter() for details. 0370 * @param parent The widget the dialog will be centered on initially. 0371 * @param caption The name of the dialog widget. 0372 * 0373 * @see KFileWidget::KFileWidget() 0374 * @deprecated use QFileDialog::getOpenFileName(parent, caption, startDir, filter) 0375 */ 0376 static QString getOpenFileName(const QUrl &startDir = QUrl(), 0377 const QString &filter = QString(), 0378 QWidget *parent = nullptr, 0379 const QString &caption = QString()); 0380 0381 /** 0382 * Use this version only if you have no QWidget available as 0383 * parent widget. This can be the case if the parent widget is 0384 * a widget in another process or if the parent widget is a 0385 * non-Qt widget. For example, in a GTK program. 0386 */ 0387 static QString getOpenFileNameWId(const QUrl &startDir, 0388 const QString &filter, 0389 WId parent_id, const QString &caption); 0390 0391 /** 0392 * Creates a modal file dialog and returns the selected 0393 * filenames or an empty list if none was chosen. 0394 * 0395 * Note that with 0396 * this method the user must select an existing filename. 0397 * 0398 * @param startDir Starting directory or @c kfiledialog:/// URL. 0399 * Refer to the KFileWidget documentation for more information 0400 * on this parameter. 0401 * @param filter A shell glob or a mimetype filter that specifies which files to display. 0402 * The preferred option is to set a list of mimetype names, see setMimeFilter() for details. 0403 * Otherwise you can set the text to be displayed for the each glob, and 0404 * provide multiple globs, see setFilter() for details. 0405 * @param parent The widget the dialog will be centered on initially. 0406 * @param caption The name of the dialog widget. 0407 * 0408 * @see KFileWidget::KFileWidget() 0409 * @deprecated use QFileDialog::getOpenFileNames(parent, caption, startDir, filter) 0410 */ 0411 static QStringList getOpenFileNames(const QUrl &startDir = QUrl(), 0412 const QString &filter = QString(), 0413 QWidget *parent = nullptr, 0414 const QString &caption = QString()); 0415 0416 /** 0417 * Creates a modal file dialog and returns the selected 0418 * URL or an empty string if none was chosen. 0419 * 0420 * Note that with 0421 * this method the user must select an existing URL. 0422 * 0423 * @param startDir Starting directory or @c kfiledialog:/// URL. 0424 * Refer to the KFileWidget documentation for more information 0425 * on this parameter. 0426 * @param filter A shell glob or a mimetype filter that specifies which files to display. 0427 * The preferred option is to set a list of mimetype names, see setMimeFilter() for details. 0428 * Otherwise you can set the text to be displayed for the each glob, and 0429 * provide multiple globs, see setFilter() for details. 0430 * @param parent The widget the dialog will be centered on initially. 0431 * @param caption The name of the dialog widget. 0432 * 0433 * @see KFileWidget::KFileWidget() 0434 * @deprecated use QFileDialog::getOpenFileUrl(parent, caption, startDir, filter) 0435 */ 0436 static QUrl getOpenUrl(const QUrl &startDir = QUrl(), 0437 const QString &filter = QString(), 0438 QWidget *parent = nullptr, 0439 const QString &caption = QString()); 0440 0441 /** 0442 * Creates a modal file dialog and returns the selected 0443 * URLs or an empty list if none was chosen. 0444 * 0445 * Note that with 0446 * this method the user must select an existing filename. 0447 * 0448 * @param startDir Starting directory or @c kfiledialog:/// URL. 0449 * Refer to the KFileWidget documentation for more information 0450 * on this parameter. 0451 * @param filter A shell glob or a mimetype filter that specifies which files to display. 0452 * The preferred option is to set a list of mimetype names, see setMimeFilter() for details. 0453 * Otherwise you can set the text to be displayed for the each glob, and 0454 * provide multiple globs, see setFilter() for details. 0455 * @param parent The widget the dialog will be centered on initially. 0456 * @param caption The name of the dialog widget. 0457 * 0458 * @see KFileWidget::KFileWidget() 0459 * @deprecated use QFileDialog::getOpenFileUrls(parent, caption, startDir, filter) 0460 */ 0461 static QList<QUrl> getOpenUrls(const QUrl &startDir = QUrl(), 0462 const QString &filter = QString(), 0463 QWidget *parent = nullptr, 0464 const QString &caption = QString()); 0465 0466 /** 0467 * Creates a modal file dialog and returns the selected 0468 * filename or an empty string if none was chosen. 0469 * 0470 * Note that with this 0471 * method the user need not select an existing filename. 0472 * 0473 * @param startDir Starting directory or @c kfiledialog:/// URL. 0474 * Refer to the KFileWidget documentation for more information 0475 * on this parameter. 0476 * @param filter A shell glob or a mimetype filter that specifies which files to display. 0477 * The preferred option is to set a list of mimetype names, see setMimeFilter() for details. 0478 * Otherwise you can set the text to be displayed for the each glob, and 0479 * provide multiple globs, see setFilter() for details. 0480 * @param parent The widget the dialog will be centered on initially. 0481 * @param caption The name of the dialog widget. 0482 * 0483 * @see KFileWidget::KFileWidget() 0484 * @deprecated use QFileDialog::getSaveFileName(parent, caption, startDir, filter) 0485 */ 0486 static QString getSaveFileName(const QUrl &startDir = QUrl(), 0487 const QString &filter = QString(), 0488 QWidget *parent = nullptr, 0489 const QString &caption = QString()); 0490 0491 /** 0492 * Creates a modal file dialog and returns the selected 0493 * filename or an empty string if none was chosen. 0494 * 0495 * Note that with this 0496 * method the user need not select an existing filename. 0497 * 0498 * @param startDir Starting directory or @c kfiledialog:/// URL. 0499 * Refer to the KFileWidget documentation for more information 0500 * on this parameter. 0501 * @param filter A shell glob or a mimetype filter that specifies which files to display. 0502 * The preferred option is to set a list of mimetype names, see setMimeFilter() for details. 0503 * Otherwise you can set the text to be displayed for the each glob, and 0504 * provide multiple globs, see setFilter() for details. 0505 * @param parent The widget the dialog will be centered on initially. 0506 * @param caption The name of the dialog widget. 0507 * @param options Dialog options. 0508 * 0509 * @see KFileWidget::KFileWidget() 0510 * 0511 * @since 4.4 0512 * @deprecated use QFileDialog::getSaveFileName(parent, caption, startDir, filter, [selectedFilter], options) 0513 */ 0514 static QString getSaveFileName(const QUrl &startDir, 0515 const QString &filter, 0516 QWidget *parent, 0517 const QString &caption, 0518 Options options); 0519 0520 /** 0521 * This function accepts the window id of the parent window, instead 0522 * of QWidget*. It should be used only when necessary. 0523 */ 0524 static QString getSaveFileNameWId(const QUrl &startDir, const QString &filter, 0525 WId parent_id, 0526 const QString &caption); 0527 0528 /** 0529 * This function accepts the window id of the parent window, instead 0530 * of QWidget*. It should be used only when necessary. 0531 * 0532 * @since 4.4 0533 */ 0534 static QString getSaveFileNameWId(const QUrl &startDir, const QString &filter, 0535 WId parent_id, 0536 const QString &caption, 0537 Options options); 0538 0539 /** 0540 * Creates a modal file dialog and returns the selected 0541 * filename or an empty string if none was chosen. 0542 * 0543 * Note that with this 0544 * method the user need not select an existing filename. 0545 * 0546 * @param startDir Starting directory or @c kfiledialog:/// URL. 0547 * Refer to the KFileWidget documentation for more information 0548 * on this parameter. 0549 * @param filter A shell glob or a mimetype filter that specifies which files to display. 0550 * The preferred option is to set a list of mimetype names, see setMimeFilter() for details. 0551 * Otherwise you can set the text to be displayed for the each glob, and 0552 * provide multiple globs, see setFilter() for details. 0553 * @param parent The widget the dialog will be centered on initially. 0554 * @param caption The name of the dialog widget. 0555 * 0556 * @see KFileWidget::KFileWidget() 0557 * @deprecated use QFileDialog::getSaveFileUrl(parent, caption, startDir, filter) 0558 */ 0559 static QUrl getSaveUrl(const QUrl &startDir = QUrl(), 0560 const QString &filter = QString(), 0561 QWidget *parent = nullptr, 0562 const QString &caption = QString()); 0563 0564 /** 0565 * Creates a modal file dialog and returns the selected 0566 * filename or an empty string if none was chosen. 0567 * 0568 * Note that with this 0569 * method the user need not select an existing filename. 0570 * 0571 * @param startDir Starting directory or @c kfiledialog:/// URL. 0572 * Refer to the KFileWidget documentation for more information 0573 * on this parameter. 0574 * @param filter A shell glob or a mimetype filter that specifies which files to display. 0575 * The preferred option is to set a list of mimetype names, see setMimeFilter() for details. 0576 * Otherwise you can set the text to be displayed for the each glob, and 0577 * provide multiple globs, see setFilter() for details. 0578 * @param parent The widget the dialog will be centered on initially. 0579 * @param caption The name of the dialog widget. 0580 * @param options Dialog options. 0581 * 0582 * @see KFileWidget::KFileWidget() 0583 * 0584 * @since 4.4 0585 * @deprecated use QFileDialog::getSaveFileUrl(parent, caption, startDir, filter, [selectedFilter], options) 0586 */ 0587 static QUrl getSaveUrl(const QUrl &startDir, 0588 const QString &filter, 0589 QWidget *parent, 0590 const QString &caption, 0591 Options options); 0592 0593 /** 0594 * Creates a modal directory-selection dialog and returns the selected 0595 * directory (local only) or an empty string if none was chosen. 0596 * 0597 * @param startDir Starting directory or @c kfiledialog:/// URL. 0598 * Refer to the KFileWidget documentation for more information 0599 * on this parameter. 0600 * @param parent The widget the dialog will be centered on initially. 0601 * @param caption The name of the dialog widget. 0602 * @return the path to an existing local directory. 0603 * 0604 * @see KFileWidget::KFileWidget() 0605 * @deprecated use QFileDialog::getExistingDirectory(parent, caption, startDir) 0606 */ 0607 static QString getExistingDirectory(const QUrl &startDir = QUrl(), 0608 QWidget *parent = nullptr, 0609 const QString &caption = QString()); 0610 0611 /** 0612 * Creates a modal directory-selection dialog and returns the selected 0613 * directory or an empty string if none was chosen. 0614 * This version supports remote urls. 0615 * 0616 * @param startDir Starting directory or @c kfiledialog:/// URL. 0617 * Refer to the KFileWidget documentation for more information 0618 * on this parameter. 0619 * @param parent The widget the dialog will be centered on initially. 0620 * @param caption The name of the dialog widget. 0621 * @return the url to an existing directory (local or remote). 0622 * 0623 * @see KFileWidget::KFileWidget() 0624 * @deprecated use QFileDialog::getExistingDirectoryUrl(parent, caption, startDir) 0625 */ 0626 static QUrl getExistingDirectoryUrl(const QUrl &startDir = QUrl(), 0627 QWidget *parent = nullptr, 0628 const QString &caption = QString()); 0629 0630 /** 0631 * Creates a modal file dialog with an image previewer and returns the 0632 * selected url or an empty string if none was chosen. 0633 * 0634 * @param startDir Starting directory or @c kfiledialog:/// URL. 0635 * Refer to the KFileWidget documentation for more information 0636 * on this parameter. 0637 * @param parent The widget the dialog will be centered on initially. 0638 * @param caption The name of the dialog widget. 0639 * 0640 * @see KFileWidget::KFileWidget() 0641 */ 0642 static QUrl getImageOpenUrl(const QUrl &startDir = QUrl(), 0643 QWidget *parent = nullptr, 0644 const QString &caption = QString()); 0645 0646 /** 0647 * Sets the mode of the dialog. 0648 * 0649 * The mode is defined as (in kfile.h): 0650 * \code 0651 * enum Mode { 0652 * File = 1, 0653 * Directory = 2, 0654 * Files = 4, 0655 * ExistingOnly = 8, 0656 * LocalOnly = 16 0657 * }; 0658 * \endcode 0659 * You can OR the values, e.g. 0660 * \code 0661 * KFile::Modes mode = KFile::Files | 0662 * KFile::ExistingOnly | 0663 * KFile::LocalOnly ); 0664 * setMode( mode ); 0665 * \endcode 0666 */ 0667 void setMode(KFile::Modes m); 0668 0669 /** 0670 * Returns the mode of the filedialog. 0671 * @see setMode() 0672 */ 0673 KFile::Modes mode() const; 0674 0675 /** 0676 * Sets the text to be displayed in front of the selection. 0677 * 0678 * The default is "Location". 0679 * Most useful if you want to make clear what 0680 * the location is used for. 0681 */ 0682 void setLocationLabel(const QString &text); 0683 0684 /** 0685 * Returns the KFileWidget that implements most of this file dialog. 0686 * If you link to libkfile you can cast this to a KFileWidget*. 0687 */ 0688 KFileWidget *fileWidget(); 0689 0690 /** 0691 * Returns a pointer to the toolbar. 0692 * 0693 * You can use this to insert custom 0694 * items into it, e.g.: 0695 * \code 0696 * yourAction = new KAction( i18n("Your Action"), 0, 0697 * this, SLOT( yourSlot() ), 0698 * this, "action name" ); 0699 * yourAction->plug( kfileDialog->toolBar() ); 0700 * \endcode 0701 */ 0702 KToolBar *toolBar() const; 0703 0704 /** 0705 * @returns a pointer to the OK-Button in the filedialog. You may use it 0706 * e.g. to set a custom text to it. 0707 */ 0708 QPushButton *okButton() const; 0709 0710 /** 0711 * @returns a pointer to the Cancel-Button in the filedialog. You may use 0712 * it e.g. to set a custom text to it. 0713 */ 0714 QPushButton *cancelButton() const; 0715 0716 /** 0717 * @returns the combobox used to type the filename or full location of the file. 0718 * You need to link to libkfile to use this widget. 0719 */ 0720 KUrlComboBox *locationEdit() const; 0721 0722 /** 0723 * @returns the combobox that contains the filters 0724 * You need to link to libkfile to use this widget. 0725 */ 0726 KFileFilterCombo *filterWidget() const; 0727 0728 /** 0729 * @returns a pointer to the action collection, holding all the used KActions. 0730 */ 0731 KActionCollection *actionCollection() const; 0732 0733 /** 0734 * This method implements the logic to determine the user's default directory 0735 * to be listed. E.g. the documents directory, home directory or a recently 0736 * used directory. 0737 * 0738 * @param startDir Starting directory or @c kfiledialog:/// URL. 0739 * Refer to the KFileWidget documentation for more information 0740 * on this parameter. 0741 * @param recentDirClass If the @c kfiledialog:/// syntax is used, this 0742 * will return the string to be passed to KRecentDirs::dir() and 0743 * KRecentDirs::add(). 0744 * @return The URL that should be listed by default (e.g. by KFileDialog or 0745 * KDirSelectDialog). 0746 * 0747 * @see KFileWidget::KFileWidget() 0748 * @see KFileWidget::getStartUrl(const QUrl& startDir, QString& recentDirClass); 0749 */ 0750 static QUrl getStartUrl(const QUrl &startDir, QString &recentDirClass); 0751 0752 /** 0753 * @internal 0754 * Used by KDirSelectDialog to share the dialog's start directory. 0755 */ 0756 static void setStartDir(const QUrl &directory); 0757 0758 #ifdef Q_OS_WIN 0759 public Q_SLOTS: 0760 int exec(); 0761 #endif 0762 0763 Q_SIGNALS: 0764 /** 0765 * Emitted when the user selects a file. It is only emitted in single- 0766 * selection mode. The best way to get notified about selected file(s) 0767 * is to connect to the accepted() signal inherited from QDialog 0768 * and call selectedFile(), selectedFiles(), 0769 * selectedUrl() or selectedUrls(). 0770 * 0771 * \since 4.4 0772 */ 0773 void fileSelected(const QUrl &); 0774 0775 /** 0776 * Emitted when the user highlights a file. 0777 * 0778 * \since 4.4 0779 */ 0780 void fileHighlighted(const QUrl &); 0781 0782 /** 0783 * Emitted when the user hilights one or more files in multiselection mode. 0784 * 0785 * Note: fileHighlighted() or fileSelected() are @em not 0786 * emitted in multiselection mode. You may use selectedItems() to 0787 * ask for the current highlighted items. 0788 * @see fileSelected 0789 */ 0790 void selectionChanged(); 0791 0792 /** 0793 * Emitted when the filter changed, i.e. the user entered an own filter 0794 * or chose one of the predefined set via setFilter(). 0795 * 0796 * @param filter contains the new filter (only the extension part, 0797 * not the explanation), i.e. "*.cpp" or "*.cpp *.cc". 0798 * 0799 * @see setFilter() 0800 * @see currentFilter() 0801 */ 0802 void filterChanged(const QString &filter); 0803 0804 protected: 0805 /** 0806 * Reimplemented to animate the cancel button. 0807 */ 0808 void keyPressEvent(QKeyEvent *e) override; 0809 0810 /** 0811 * Reimplemented for saving the dialog geometry. 0812 */ 0813 void hideEvent(QHideEvent *event) override; 0814 0815 protected Q_SLOTS: 0816 virtual void slotOk(); 0817 void accept() override; 0818 virtual void slotCancel(); 0819 0820 private: 0821 Q_DISABLE_COPY(KFileDialog) 0822 0823 KFileDialogPrivate *const d; 0824 }; 0825 0826 #endif