File indexing completed on 2024-11-17 05:01:39

0001 /*
0002 
0003     SPDX-FileCopyrightText: 2017-2018 Red Hat Inc
0004     Contact: https://www.qt.io/licensing/
0005 
0006     This file is part of the plugins of the Qt Toolkit.
0007 
0008     SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KFQF-Accepted-GPL OR LicenseRef-Qt-Commercial
0009 
0010 */
0011 #ifndef QXDGDESKTOPPORTALFILEDIALOG_P_H
0012 #define QXDGDESKTOPPORTALFILEDIALOG_P_H
0013 
0014 #include <QVector>
0015 #include <qpa/qplatformdialoghelper.h>
0016 
0017 QT_BEGIN_NAMESPACE
0018 
0019 class QXdgDesktopPortalFileDialogPrivate;
0020 
0021 class QXdgDesktopPortalFileDialog : public QPlatformFileDialogHelper
0022 {
0023     Q_OBJECT
0024     Q_DECLARE_PRIVATE(QXdgDesktopPortalFileDialog)
0025 public:
0026     enum ConditionType : uint {
0027         GlobalPattern = 0,
0028         MimeType = 1,
0029     };
0030     // Filters a(sa(us))
0031     // Example: [('Images', [(0, '*.ico'), (1, 'image/png')]), ('Text', [(0, '*.txt')])]
0032     struct FilterCondition {
0033         ConditionType type;
0034         QString pattern; // E.g. '*ico' or 'image/png'
0035     };
0036     typedef QVector<FilterCondition> FilterConditionList;
0037 
0038     struct Filter {
0039         QString name; // E.g. 'Images' or 'Text
0040         FilterConditionList filterConditions; // E.g. [(0, '*.ico'), (1, 'image/png')] or [(0, '*.txt')]
0041     };
0042     typedef QVector<Filter> FilterList;
0043 
0044     QXdgDesktopPortalFileDialog(QPlatformFileDialogHelper *nativeFileDialog = nullptr);
0045     ~QXdgDesktopPortalFileDialog();
0046 
0047     bool defaultNameFilterDisables() const override;
0048     QUrl directory() const override;
0049     void setDirectory(const QUrl &directory) override;
0050     void selectFile(const QUrl &filename) override;
0051     QList<QUrl> selectedFiles() const override;
0052     void setFilter() override;
0053     void selectNameFilter(const QString &filter) override;
0054     QString selectedNameFilter() const override;
0055 
0056     void exec() override;
0057     bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) override;
0058     void hide() override;
0059 
0060 private Q_SLOTS:
0061     void gotResponse(uint response, const QVariantMap &results);
0062 
0063 private:
0064     void initializeDialog();
0065     void openPortal();
0066 
0067     QScopedPointer<QXdgDesktopPortalFileDialogPrivate> d_ptr;
0068 };
0069 
0070 QT_END_NAMESPACE
0071 
0072 Q_DECLARE_METATYPE(QXdgDesktopPortalFileDialog::FilterCondition)
0073 Q_DECLARE_METATYPE(QXdgDesktopPortalFileDialog::FilterConditionList)
0074 Q_DECLARE_METATYPE(QXdgDesktopPortalFileDialog::Filter)
0075 Q_DECLARE_METATYPE(QXdgDesktopPortalFileDialog::FilterList)
0076 
0077 #endif // QXDGDESKTOPPORTALFILEDIALOG_P_H