File indexing completed on 2024-09-15 13:03:51
0001 /* 0002 * SPDX-FileCopyrightText: 2016-2018 Red Hat Inc 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 * 0006 * SPDX-FileCopyrightText: 2016-2018 Jan Grulich <jgrulich@redhat.com> 0007 */ 0008 0009 #ifndef XDG_DESKTOP_PORTAL_KDE_FILECHOOSER_H 0010 #define XDG_DESKTOP_PORTAL_KDE_FILECHOOSER_H 0011 0012 #include <QCheckBox> 0013 #include <QComboBox> 0014 #include <QDBusAbstractAdaptor> 0015 #include <QDBusObjectPath> 0016 #include <QDialog> 0017 0018 #include <KConfigGroup> 0019 0020 class KFileWidget; 0021 class QDialogButtonBox; 0022 class MobileFileDialog; 0023 0024 class FileDialog : public QDialog 0025 { 0026 Q_OBJECT 0027 public: 0028 friend class FileChooserPortal; 0029 0030 explicit FileDialog(QDialog *parent = nullptr, Qt::WindowFlags flags = {}); 0031 ~FileDialog() override; 0032 0033 private: 0034 QDialogButtonBox *m_buttons; 0035 0036 protected: 0037 KFileWidget *const m_fileWidget; 0038 KConfigGroup m_configGroup; 0039 }; 0040 0041 class FileChooserPortal : public QDBusAbstractAdaptor 0042 { 0043 Q_OBJECT 0044 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.FileChooser") 0045 public: 0046 // Keep in sync with qflatpakfiledialog from flatpak-platform-plugin 0047 typedef struct { 0048 uint type; 0049 QString filterString; 0050 } Filter; 0051 typedef QList<Filter> Filters; 0052 0053 typedef struct { 0054 QString userVisibleName; 0055 Filters filters; 0056 } FilterList; 0057 typedef QList<FilterList> FilterListList; 0058 0059 typedef struct { 0060 QString id; 0061 QString value; 0062 } Choice; 0063 typedef QList<Choice> Choices; 0064 0065 typedef struct { 0066 QString id; 0067 QString label; 0068 Choices choices; 0069 QString initialChoiceId; 0070 } Option; 0071 typedef QList<Option> OptionList; 0072 0073 explicit FileChooserPortal(QObject *parent); 0074 ~FileChooserPortal() override; 0075 0076 public Q_SLOTS: 0077 uint OpenFile(const QDBusObjectPath &handle, 0078 const QString &app_id, 0079 const QString &parent_window, 0080 const QString &title, 0081 const QVariantMap &options, 0082 QVariantMap &results); 0083 0084 uint SaveFile(const QDBusObjectPath &handle, 0085 const QString &app_id, 0086 const QString &parent_window, 0087 const QString &title, 0088 const QVariantMap &options, 0089 QVariantMap &results); 0090 0091 private: 0092 static QWidget *CreateChoiceControls(const OptionList &optionList, QMap<QString, QCheckBox *> &checkboxes, QMap<QString, QComboBox *> &comboboxes); 0093 0094 static QVariant EvaluateSelectedChoices(const QMap<QString, QCheckBox *> &checkboxes, const QMap<QString, QComboBox *> &comboboxes); 0095 0096 static QString ExtractAcceptLabel(const QVariantMap &options); 0097 0098 static void ExtractFilters(const QVariantMap &options, 0099 QStringList &nameFilters, 0100 QStringList &mimeTypeFilters, 0101 QMap<QString, FilterList> &allFilters, 0102 QString &selectedMimeTypeFilter); 0103 0104 static bool isMobile(); 0105 0106 MobileFileDialog *m_mobileFileDialog = nullptr; 0107 }; 0108 0109 #endif // XDG_DESKTOP_PORTAL_KDE_FILECHOOSER_H