File indexing completed on 2024-11-17 05:01:38
0001 /* 0002 SPDX-FileCopyrightText: 2001 Michael Jarrett <michaelj@corel.com> 0003 SPDX-FileCopyrightText: 2001 Carsten Pfeiffer <pfeiffer@kde.org> 0004 SPDX-FileCopyrightText: 2009 Shaun Reich <shaun.reich@kdemail.net> 0005 0006 SPDX-License-Identifier: LGPL-2.0-only 0007 */ 0008 0009 #ifndef KDIRSELECTDIALOG_H 0010 #define KDIRSELECTDIALOG_H 0011 0012 #include "kdeplatformfiledialogbase_p.h" 0013 #include <QUrl> 0014 0015 class QAbstractItemView; 0016 0017 /** 0018 * A pretty dialog for a KDirSelect control for selecting directories. 0019 * @author Michael Jarrett <michaelj@corel.com> 0020 */ 0021 class KDirSelectDialog : public KDEPlatformFileDialogBase 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 /** 0027 * Creates a new directory selection dialog. 0028 * @internal use the static selectDirectory function 0029 * @param startDir the directory, initially shown 0030 * @param localOnly unused. You can only select paths below the startDir 0031 * @param parent the parent for the dialog, usually 0L 0032 */ 0033 explicit KDirSelectDialog(const QUrl &startDir = QUrl(), bool localOnly = false, QWidget *parent = nullptr); 0034 0035 /** 0036 * Destroys the directory selection dialog. 0037 */ 0038 ~KDirSelectDialog() override; 0039 0040 /** 0041 * Returns the currently selected URL, or an empty one if no item is selected. 0042 * 0043 * If the URL entered in the combobox is valid and exists, it is returned. 0044 * Otherwise, the URL selected in the treeview is returned instead. 0045 */ 0046 QUrl url() const; 0047 0048 /** 0049 * Returns the root url 0050 */ 0051 QUrl rootUrl() const; 0052 0053 /** 0054 * Returns a pointer to the view which is used for displaying the directories. 0055 */ 0056 QAbstractItemView *view() const; 0057 0058 /** 0059 * Returns whether only local directories can be selected. 0060 */ 0061 bool localOnly() const; 0062 0063 /** 0064 * Creates a KDirSelectDialog, and returns the result. 0065 * @param startDir the directory, initially shown 0066 * The tree will display this directory and subdirectories of it. 0067 * @param localOnly unused. You can only select paths below the startDir 0068 * @param parent the parent widget to use for the dialog, or NULL to create a parent-less dialog 0069 * @param caption the caption to use for the dialog, or QString() for the default caption 0070 * @return The URL selected, or an empty URL if the user canceled 0071 * or no URL was selected. 0072 * 0073 * @deprecated since 5.0, use QFileDialog::getExistingDirectory (if localOnly was true) 0074 * or QFileDialog::getExistingDirectoryUrl (if localOnly was false) instead. 0075 */ 0076 static QUrl selectDirectory(const QUrl &startDir = QUrl(), bool localOnly = false, QWidget *parent = nullptr, const QString &caption = QString()); 0077 0078 /** 0079 * @return The path for the root node 0080 */ 0081 QUrl startDir() const; 0082 0083 QUrl directory() override; 0084 void selectMimeTypeFilter(const QString &filter) override; 0085 void selectNameFilter(const QString &filter) override; 0086 void setDirectory(const QUrl &directory) override; 0087 void selectFile(const QUrl &filename) override; 0088 QString selectedMimeTypeFilter() override; 0089 QString selectedNameFilter() override; 0090 QString currentFilterText() override; 0091 QList<QUrl> selectedFiles() override; 0092 0093 void setOkButtonText(const QString &text); 0094 void setCancelButtonText(const QString &text); 0095 public Q_SLOTS: 0096 /** 0097 * Sets the current @p url in the dialog. 0098 */ 0099 void setCurrentUrl(const QUrl &url); 0100 0101 protected: 0102 void accept() override; 0103 0104 /** 0105 * Reimplemented for saving the dialog geometry. 0106 */ 0107 void hideEvent(QHideEvent *event) override; 0108 0109 private: 0110 class Private; 0111 Private *const d; 0112 }; 0113 0114 #endif