| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Labs Platform module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #ifndef QQUICKPLATFORMFILEDIALOG_P_H |
| 38 | #define QQUICKPLATFORMFILEDIALOG_P_H |
| 39 | |
| 40 | // |
| 41 | // W A R N I N G |
| 42 | // ------------- |
| 43 | // |
| 44 | // This file is not part of the Qt API. It exists purely as an |
| 45 | // implementation detail. This header file may change from version to |
| 46 | // version without notice, or even be removed. |
| 47 | // |
| 48 | // We mean it. |
| 49 | // |
| 50 | |
| 51 | #include "qquickplatformdialog_p.h" |
| 52 | #include <QtCore/qurl.h> |
| 53 | #include <QtQml/qqml.h> |
| 54 | |
| 55 | QT_BEGIN_NAMESPACE |
| 56 | |
| 57 | class QQuickPlatformFileNameFilter; |
| 58 | |
| 59 | class QQuickPlatformFileDialog : public QQuickPlatformDialog |
| 60 | { |
| 61 | Q_OBJECT |
| 62 | Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode NOTIFY fileModeChanged FINAL) |
| 63 | Q_PROPERTY(QUrl file READ file WRITE setFile NOTIFY fileChanged FINAL) |
| 64 | Q_PROPERTY(QList<QUrl> files READ files WRITE setFiles NOTIFY filesChanged FINAL) |
| 65 | Q_PROPERTY(QUrl currentFile READ currentFile WRITE setCurrentFile NOTIFY currentFileChanged FINAL) |
| 66 | Q_PROPERTY(QList<QUrl> currentFiles READ currentFiles WRITE setCurrentFiles NOTIFY currentFilesChanged FINAL) |
| 67 | Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged FINAL) |
| 68 | Q_PROPERTY(QFileDialogOptions::FileDialogOptions options READ options WRITE setOptions RESET resetOptions NOTIFY optionsChanged FINAL) |
| 69 | Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters RESET resetNameFilters NOTIFY nameFiltersChanged FINAL) |
| 70 | Q_PROPERTY(QQuickPlatformFileNameFilter *selectedNameFilter READ selectedNameFilter CONSTANT) |
| 71 | Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix RESET resetDefaultSuffix NOTIFY defaultSuffixChanged FINAL) |
| 72 | Q_PROPERTY(QString acceptLabel READ acceptLabel WRITE setAcceptLabel RESET resetAcceptLabel NOTIFY acceptLabelChanged FINAL) |
| 73 | Q_PROPERTY(QString rejectLabel READ rejectLabel WRITE setRejectLabel RESET resetRejectLabel NOTIFY rejectLabelChanged FINAL) |
| 74 | Q_FLAGS(QFileDialogOptions::FileDialogOptions) |
| 75 | |
| 76 | public: |
| 77 | explicit QQuickPlatformFileDialog(QObject *parent = nullptr); |
| 78 | |
| 79 | enum FileMode { |
| 80 | OpenFile, |
| 81 | OpenFiles, |
| 82 | SaveFile |
| 83 | }; |
| 84 | Q_ENUM(FileMode) |
| 85 | |
| 86 | FileMode fileMode() const; |
| 87 | void setFileMode(FileMode fileMode); |
| 88 | |
| 89 | QUrl file() const; |
| 90 | void setFile(const QUrl &file); |
| 91 | |
| 92 | QList<QUrl> files() const; |
| 93 | void setFiles(const QList<QUrl> &files); |
| 94 | |
| 95 | QUrl currentFile() const; |
| 96 | void setCurrentFile(const QUrl &file); |
| 97 | |
| 98 | QList<QUrl> currentFiles() const; |
| 99 | void setCurrentFiles(const QList<QUrl> &files); |
| 100 | |
| 101 | QUrl folder() const; |
| 102 | void setFolder(const QUrl &folder); |
| 103 | |
| 104 | QFileDialogOptions::FileDialogOptions options() const; |
| 105 | void setOptions(QFileDialogOptions::FileDialogOptions options); |
| 106 | void resetOptions(); |
| 107 | |
| 108 | QStringList nameFilters() const; |
| 109 | void setNameFilters(const QStringList &filters); |
| 110 | void resetNameFilters(); |
| 111 | |
| 112 | QQuickPlatformFileNameFilter *selectedNameFilter() const; |
| 113 | |
| 114 | QString defaultSuffix() const; |
| 115 | void setDefaultSuffix(const QString &suffix); |
| 116 | void resetDefaultSuffix(); |
| 117 | |
| 118 | QString acceptLabel() const; |
| 119 | void setAcceptLabel(const QString &label); |
| 120 | void resetAcceptLabel(); |
| 121 | |
| 122 | QString rejectLabel() const; |
| 123 | void setRejectLabel(const QString &label); |
| 124 | void resetRejectLabel(); |
| 125 | |
| 126 | Q_SIGNALS: |
| 127 | void fileModeChanged(); |
| 128 | void fileChanged(); |
| 129 | void filesChanged(); |
| 130 | void currentFileChanged(); |
| 131 | void currentFilesChanged(); |
| 132 | void folderChanged(); |
| 133 | void optionsChanged(); |
| 134 | void nameFiltersChanged(); |
| 135 | void defaultSuffixChanged(); |
| 136 | void acceptLabelChanged(); |
| 137 | void rejectLabelChanged(); |
| 138 | |
| 139 | protected: |
| 140 | bool useNativeDialog() const override; |
| 141 | void onCreate(QPlatformDialogHelper *dialog) override; |
| 142 | void onShow(QPlatformDialogHelper *dialog) override; |
| 143 | void onHide(QPlatformDialogHelper *dialog) override; |
| 144 | void accept() override; |
| 145 | |
| 146 | private: |
| 147 | QUrl addDefaultSuffix(const QUrl &file) const; |
| 148 | QList<QUrl> addDefaultSuffixes(const QList<QUrl> &files) const; |
| 149 | |
| 150 | FileMode m_fileMode; |
| 151 | QList<QUrl> m_files; |
| 152 | bool m_firstShow = true; |
| 153 | QSharedPointer<QFileDialogOptions> m_options; |
| 154 | mutable QQuickPlatformFileNameFilter *m_selectedNameFilter; |
| 155 | }; |
| 156 | |
| 157 | class QQuickPlatformFileNameFilter : public QObject |
| 158 | { |
| 159 | Q_OBJECT |
| 160 | Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged FINAL) |
| 161 | Q_PROPERTY(QString name READ name NOTIFY nameChanged FINAL) |
| 162 | Q_PROPERTY(QStringList extensions READ extensions NOTIFY extensionsChanged FINAL) |
| 163 | |
| 164 | public: |
| 165 | explicit QQuickPlatformFileNameFilter(QObject *parent = nullptr); |
| 166 | |
| 167 | int index() const; |
| 168 | void setIndex(int index); |
| 169 | |
| 170 | QString name() const; |
| 171 | QStringList extensions() const; |
| 172 | |
| 173 | QSharedPointer<QFileDialogOptions> options() const; |
| 174 | void setOptions(const QSharedPointer<QFileDialogOptions> &options); |
| 175 | |
| 176 | void update(const QString &filter); |
| 177 | |
| 178 | Q_SIGNALS: |
| 179 | void indexChanged(int index); |
| 180 | void nameChanged(const QString &name); |
| 181 | void extensionsChanged(const QStringList &extensions); |
| 182 | |
| 183 | private: |
| 184 | QStringList nameFilters() const; |
| 185 | QString nameFilter(int index) const; |
| 186 | |
| 187 | int m_index; |
| 188 | QString m_name; |
| 189 | QStringList m_extensions; |
| 190 | QSharedPointer<QFileDialogOptions> m_options; |
| 191 | }; |
| 192 | |
| 193 | QT_END_NAMESPACE |
| 194 | |
| 195 | QML_DECLARE_TYPE(QQuickPlatformFileDialog) |
| 196 | |
| 197 | #endif // QQUICKPLATFORMFILEDIALOG_P_H |
| 198 |
