File indexing completed on 2024-11-24 05:00:54

0001 /*  This file is part of the KDE libraries
0002     SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef KDEPLATFORMFILEDIALOGHELPER_H
0008 #define KDEPLATFORMFILEDIALOGHELPER_H
0009 
0010 #include "kdeplatformfiledialogbase_p.h"
0011 #include <qpa/qplatformdialoghelper.h>
0012 
0013 class KFileWidget;
0014 class KDEPlatformFileDialog : public KDEPlatformFileDialogBase
0015 {
0016     Q_OBJECT
0017 public:
0018     friend class KDEPlatformFileDialogHelper;
0019 
0020     explicit KDEPlatformFileDialog();
0021     QUrl directory() override;
0022     void selectMimeTypeFilter(const QString &filter) override;
0023     void selectNameFilter(const QString &filter) override;
0024     void setDirectory(const QUrl &directory) override;
0025     void selectFile(const QUrl &filename) override;
0026     void setViewMode(QFileDialogOptions::ViewMode view);
0027     void setFileMode(QFileDialogOptions::FileMode mode);
0028     void setCustomLabel(QFileDialogOptions::DialogLabel label, const QString &text);
0029     QString selectedMimeTypeFilter() override;
0030     QString selectedNameFilter() override;
0031     QString currentFilterText() override;
0032     QList<QUrl> selectedFiles() override;
0033 
0034 protected:
0035     KFileWidget *const m_fileWidget;
0036 };
0037 
0038 class KDEPlatformFileDialogHelper : public QPlatformFileDialogHelper
0039 {
0040     Q_OBJECT
0041 public:
0042     KDEPlatformFileDialogHelper();
0043     ~KDEPlatformFileDialogHelper() override;
0044 
0045     void initializeDialog();
0046 
0047     bool defaultNameFilterDisables() const override;
0048     QUrl directory() const override;
0049     QList<QUrl> selectedFiles() const override;
0050     QString selectedMimeTypeFilter() const override;
0051     void selectMimeTypeFilter(const QString &filter) override;
0052     QString selectedNameFilter() const override;
0053     void selectNameFilter(const QString &filter) override;
0054     void selectFile(const QUrl &filename) override;
0055     void setFilter() override;
0056     void setDirectory(const QUrl &directory) override;
0057     bool isSupportedUrl(const QUrl &url) const override;
0058 
0059     void exec() override;
0060     void hide() override;
0061     bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) override;
0062 
0063     QVariant styleHint(StyleHint hint) const override;
0064 
0065 private Q_SLOTS:
0066     void saveSize();
0067 
0068 private:
0069     QString qt2KdeFilter(const QStringList &f);
0070     void restoreSize();
0071     KDEPlatformFileDialogBase *m_dialog = nullptr;
0072     bool m_directorySet = false;
0073     bool m_fileSelected = false;
0074     bool m_dialogInitialized = false;
0075 };
0076 
0077 #endif // KDEPLATFORMFILEDIALOGHELPER_H