1// Copyright (C) 2017-2018 Red Hat, Inc
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QXDGDESKTOPPORTALFILEDIALOG_P_H
4#define QXDGDESKTOPPORTALFILEDIALOG_P_H
5
6#include <qpa/qplatformdialoghelper.h>
7#include <QList>
8
9QT_BEGIN_NAMESPACE
10
11class QXdgDesktopPortalFileDialogPrivate;
12
13class QXdgDesktopPortalFileDialog : public QPlatformFileDialogHelper
14{
15 Q_OBJECT
16 Q_DECLARE_PRIVATE(QXdgDesktopPortalFileDialog)
17public:
18 enum FallbackType {
19 GenericFallback,
20 OpenFallback
21 };
22
23 enum ConditionType : uint {
24 GlobalPattern = 0,
25 MimeType = 1
26 };
27 // Filters a(sa(us))
28 // Example: [('Images', [(0, '*.ico'), (1, 'image/png')]), ('Text', [(0, '*.txt')])]
29 struct FilterCondition {
30 ConditionType type;
31 QString pattern; // E.g. '*ico' or 'image/png'
32 };
33 typedef QList<FilterCondition> FilterConditionList;
34
35 struct Filter {
36 QString name; // E.g. 'Images' or 'Text
37 FilterConditionList filterConditions;; // E.g. [(0, '*.ico'), (1, 'image/png')] or [(0, '*.txt')]
38 };
39 typedef QList<Filter> FilterList;
40
41 QXdgDesktopPortalFileDialog(QPlatformFileDialogHelper *nativeFileDialog = nullptr, uint fileChooserPortalVersion = 0);
42 ~QXdgDesktopPortalFileDialog();
43
44 bool defaultNameFilterDisables() const override;
45 QUrl directory() const override;
46 void setDirectory(const QUrl &directory) override;
47 void selectFile(const QUrl &filename) override;
48 QList<QUrl> selectedFiles() const override;
49 void setFilter() override;
50 void selectNameFilter(const QString &filter) override;
51 QString selectedNameFilter() const override;
52 void selectMimeTypeFilter(const QString &filter) override;
53 QString selectedMimeTypeFilter() const override;
54
55 void exec() override;
56 bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) override;
57 void hide() override;
58
59private Q_SLOTS:
60 void gotResponse(uint response, const QVariantMap &results);
61
62private:
63 void initializeDialog();
64 void openPortal(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent);
65 bool useNativeFileDialog(FallbackType fallbackType = GenericFallback) const;
66
67 QScopedPointer<QXdgDesktopPortalFileDialogPrivate> d_ptr;
68};
69
70QT_END_NAMESPACE
71
72Q_DECLARE_METATYPE(QXdgDesktopPortalFileDialog::FilterCondition);
73Q_DECLARE_METATYPE(QXdgDesktopPortalFileDialog::FilterConditionList);
74Q_DECLARE_METATYPE(QXdgDesktopPortalFileDialog::Filter);
75Q_DECLARE_METATYPE(QXdgDesktopPortalFileDialog::FilterList);
76
77#endif // QXDGDESKTOPPORTALFILEDIALOG_P_H
78
79

source code of qtbase/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog_p.h