File indexing completed on 2024-05-19 05:38:07
0001 /* 0002 main.h 0003 0004 SPDX-FileCopyrightText: 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org> 0005 SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@privat.broulik.de> 0006 SPDX-FileCopyrightText: 2019 Benjamin Port <benjamin.port@enioka.com> 0007 0008 KDE Frameworks 5 port: 0009 SPDX-FileCopyrightText: 2013 Jonathan Riddell <jr@jriddell.org> 0010 0011 SPDX-License-Identifier: GPL-2.0-or-later 0012 */ 0013 0014 #pragma once 0015 0016 #include <KQuickManagedConfigModule> 0017 0018 #include <QCache> 0019 #include <QTemporaryFile> 0020 0021 class KIconTheme; 0022 class IconsSettings; 0023 class IconsData; 0024 0025 class QQuickItem; 0026 0027 namespace KIO 0028 { 0029 class FileCopyJob; 0030 } 0031 0032 class IconsModel; 0033 0034 class IconModule : public KQuickManagedConfigModule 0035 { 0036 Q_OBJECT 0037 Q_PROPERTY(IconsSettings *iconsSettings READ iconsSettings CONSTANT) 0038 Q_PROPERTY(IconsModel *iconsModel READ iconsModel CONSTANT) 0039 Q_PROPERTY(bool downloadingFile READ downloadingFile NOTIFY downloadingFileChanged) 0040 0041 public: 0042 IconModule(QObject *parent, const KPluginMetaData &data); 0043 ~IconModule() override; 0044 0045 enum Roles { 0046 ThemeNameRole = Qt::UserRole + 1, 0047 DescriptionRole, 0048 RemovableRole, 0049 PendingDeletionRole, 0050 }; 0051 0052 IconsSettings *iconsSettings() const; 0053 IconsModel *iconsModel() const; 0054 0055 bool downloadingFile() const; 0056 0057 void load() override; 0058 Q_INVOKABLE void reloadConfig() 0059 { 0060 KQuickManagedConfigModule::load(); 0061 } 0062 0063 void save() override; 0064 void defaults() override; 0065 0066 Q_INVOKABLE void ghnsEntriesChanged(); 0067 Q_INVOKABLE void installThemeFromFile(const QUrl &url); 0068 0069 Q_INVOKABLE int pluginIndex(const QString &pluginName) const; 0070 0071 // QML doesn't understand QList<QPixmap>, hence wrapped in a QVariantList 0072 Q_INVOKABLE QVariantList previewIcons(const QString &themeName, int size, qreal dpr, int limit = -1); 0073 0074 Q_SIGNALS: 0075 void downloadingFileChanged(); 0076 0077 void showSuccessMessage(const QString &message); 0078 void showErrorMessage(const QString &message); 0079 0080 void showProgress(const QString &message); 0081 void hideProgress(); 0082 0083 private: 0084 bool isSaveNeeded() const override; 0085 0086 void processPendingDeletions(); 0087 0088 static QStringList findThemeDirs(const QString &archiveName); 0089 bool installThemes(const QStringList &themes, const QString &archiveName); 0090 void installThemeFile(const QString &path); 0091 0092 static QPixmap getBestIcon(KIconTheme &theme, const QStringList &iconNames, int size, qreal dpr); 0093 0094 IconsData *m_data; 0095 IconsModel *m_model; 0096 0097 mutable QCache<QString, KIconTheme> m_kiconThemeCache; 0098 0099 std::unique_ptr<QTemporaryFile> m_tempInstallFile; 0100 QPointer<KIO::FileCopyJob> m_tempCopyJob; 0101 };