File indexing completed on 2024-05-19 05:38:04

0001 /*
0002     SPDX-FileCopyrightText: 2003-2007 Fredrik Höglund <fredrik@kde.org>
0003     SPDX-FileCopyrightText: 2019 Benjamin Port <benjamin.port@enioka.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include <KNSCore/Entry>
0011 #include <KQuickManagedConfigModule>
0012 #include <QAbstractItemModel>
0013 
0014 #include "cursorthemesettings.h"
0015 #include "launchfeedbacksettings.h"
0016 
0017 class QQmlListReference;
0018 class QStandardItemModel;
0019 class QTemporaryFile;
0020 
0021 class CursorThemeModel;
0022 class SortProxyModel;
0023 class CursorTheme;
0024 class CursorThemeData;
0025 
0026 namespace KIO
0027 {
0028 class FileCopyJob;
0029 }
0030 
0031 class CursorThemeConfig : public KQuickManagedConfigModule
0032 {
0033     Q_OBJECT
0034 
0035     Q_PROPERTY(CursorThemeSettings *cursorThemeSettings READ cursorThemeSettings CONSTANT)
0036     Q_PROPERTY(LaunchFeedbackSettings *launchFeedbackSettings READ launchFeedbackSettings CONSTANT)
0037     Q_PROPERTY(bool canInstall READ canInstall WRITE setCanInstall NOTIFY canInstallChanged)
0038     Q_PROPERTY(bool canResize READ canResize WRITE setCanResize NOTIFY canResizeChanged)
0039     Q_PROPERTY(bool canConfigure READ canConfigure WRITE setCanConfigure NOTIFY canConfigureChanged)
0040     Q_PROPERTY(QAbstractItemModel *cursorsModel READ cursorsModel CONSTANT)
0041     Q_PROPERTY(QAbstractItemModel *sizesModel READ sizesModel CONSTANT)
0042 
0043     Q_PROPERTY(bool downloadingFile READ downloadingFile NOTIFY downloadingFileChanged)
0044     Q_PROPERTY(int preferredSize READ preferredSize WRITE setPreferredSize NOTIFY preferredSizeChanged)
0045 
0046 public:
0047     CursorThemeConfig(QObject *parent, const KPluginMetaData &data);
0048     ~CursorThemeConfig() override;
0049 
0050     void load() override;
0051     void save() override;
0052     void defaults() override;
0053 
0054     // for QML properties
0055     CursorThemeSettings *cursorThemeSettings() const;
0056     LaunchFeedbackSettings *launchFeedbackSettings() const;
0057 
0058     bool canInstall() const;
0059     void setCanInstall(bool can);
0060 
0061     bool canResize() const;
0062     void setCanResize(bool can);
0063 
0064     bool canConfigure() const;
0065     void setCanConfigure(bool can);
0066 
0067     int preferredSize() const;
0068     void setPreferredSize(int size);
0069 
0070     bool downloadingFile() const;
0071 
0072     QAbstractItemModel *cursorsModel();
0073     QAbstractItemModel *sizesModel();
0074 
0075     Q_INVOKABLE int cursorSizeIndex(int cursorSize) const;
0076     Q_INVOKABLE int cursorSizeFromIndex(int index);
0077     Q_INVOKABLE QSize iconSizeFromIndex(int index);
0078     Q_INVOKABLE int cursorThemeIndex(const QString &cursorTheme) const;
0079     Q_INVOKABLE QString cursorThemeFromIndex(int index) const;
0080 
0081 Q_SIGNALS:
0082     void canInstallChanged();
0083     void canResizeChanged();
0084     void canConfigureChanged();
0085     void downloadingFileChanged();
0086     void preferredSizeChanged();
0087     void themeApplied();
0088 
0089     void showSuccessMessage(const QString &message);
0090     void showInfoMessage(const QString &message);
0091     void showErrorMessage(const QString &message);
0092 
0093 public Q_SLOTS:
0094     void ghnsEntryChanged(const KNSCore::Entry &entry);
0095     void installThemeFromFile(const QUrl &url);
0096 
0097 private Q_SLOTS:
0098     /** Updates the size combo box. It loads the size list of the selected cursor
0099         theme with the corresponding icons and chooses an appropriate entry. It
0100         enables the combo box and the label if the theme provides more than one
0101         size, otherwise it disables it. If the size setting is looked in kiosk
0102         mode, it stays always disabled. */
0103     void updateSizeComboBox();
0104 
0105 private:
0106     bool isSaveNeeded() const override;
0107     void installThemeFile(const QString &path);
0108     bool iconsIsWritable() const;
0109     void removeThemes();
0110 
0111     CursorThemeModel *m_themeModel;
0112     SortProxyModel *m_themeProxyModel;
0113     QStandardItemModel *m_sizesModel;
0114     CursorThemeData *m_data;
0115 
0116     /** Holds the last size that was chosen by the user. Example: The user chooses
0117         theme1 which provides the sizes 24 and 36. He chooses 36. preferredSize gets
0118         set to 36. Now, he switches to theme2 which provides the sizes 30 and 40.
0119         preferredSize still is 36, so the UI will default to 40, which is next to 36.
0120         Now, he chooses theme3 which provides the sizes 34 and 44. preferredSize is
0121         still 36, so the UI defaults to 34. Now the user changes manually to 44. This
0122         will also change preferredSize. */
0123     int m_preferredSize;
0124 
0125     bool m_canInstall;
0126     bool m_canResize;
0127     bool m_canConfigure;
0128 
0129     std::unique_ptr<QTemporaryFile> m_tempInstallFile;
0130     QPointer<KIO::FileCopyJob> m_tempCopyJob;
0131 };