1 /*
2     main.h
3 
4     SPDX-FileCopyrightText: 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
5     SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@privat.broulik.de>
6     SPDX-FileCopyrightText: 2019 Benjamin Port <benjamin.port@enioka.com>
7 
8     KDE Frameworks 5 port:
9     SPDX-FileCopyrightText: 2013 Jonathan Riddell <jr@jriddell.org>
10 
11     SPDX-License-Identifier: GPL-2.0-or-later
12 */
13 
14 #pragma once
15 
16 #include <KQuickAddons/ManagedConfigModule>
17 
18 #include <QCache>
19 #include <QScopedPointer>
20 
21 class KIconTheme;
22 class IconsSettings;
23 class IconsData;
24 
25 class QQuickItem;
26 class QTemporaryFile;
27 
28 namespace KIO
29 {
30 class FileCopyJob;
31 }
32 
33 class IconsModel;
34 class IconSizeCategoryModel;
35 
36 class IconModule : public KQuickAddons::ManagedConfigModule
37 {
38     Q_OBJECT
39     Q_PROPERTY(IconsSettings *iconsSettings READ iconsSettings CONSTANT)
40     Q_PROPERTY(IconsModel *iconsModel READ iconsModel CONSTANT)
41     Q_PROPERTY(IconSizeCategoryModel *iconSizeCategoryModel READ iconSizeCategoryModel CONSTANT)
42     Q_PROPERTY(bool downloadingFile READ downloadingFile NOTIFY downloadingFileChanged)
43 
44 public:
45     IconModule(QObject *parent, const QVariantList &args);
46     ~IconModule() override;
47 
48     enum Roles {
49         ThemeNameRole = Qt::UserRole + 1,
50         DescriptionRole,
51         RemovableRole,
52         PendingDeletionRole,
53     };
54 
55     IconsSettings *iconsSettings() const;
56     IconsModel *iconsModel() const;
57     IconSizeCategoryModel *iconSizeCategoryModel() const;
58 
59     bool downloadingFile() const;
60 
61     void load() override;
reloadConfig()62     Q_INVOKABLE void reloadConfig()
63     {
64         ManagedConfigModule::load();
65     }
66 
67     void save() override;
68     void defaults() override;
69 
70     Q_INVOKABLE void ghnsEntriesChanged();
71     Q_INVOKABLE void installThemeFromFile(const QUrl &url);
72 
73     Q_INVOKABLE QList<int> availableIconSizes(int group) const;
74 
75     Q_INVOKABLE int pluginIndex(const QString &pluginName) const;
76 
77     // QML doesn't understand QList<QPixmap>, hence wrapped in a QVariantList
78     Q_INVOKABLE QVariantList previewIcons(const QString &themeName, int size, qreal dpr, int limit = -1);
79 
80 Q_SIGNALS:
81     void downloadingFileChanged();
82 
83     void showSuccessMessage(const QString &message);
84     void showErrorMessage(const QString &message);
85 
86     void showProgress(const QString &message);
87     void hideProgress();
88 
89 private:
90     bool isSaveNeeded() const override;
91 
92     void processPendingDeletions();
93 
94     static QStringList findThemeDirs(const QString &archiveName);
95     bool installThemes(const QStringList &themes, const QString &archiveName);
96     void installThemeFile(const QString &path);
97 
98     void exportToKDE4();
99 
100     static QPixmap getBestIcon(KIconTheme &theme, const QStringList &iconNames, int size, qreal dpr);
101 
102     IconsData *m_data;
103     IconsModel *m_model;
104     IconSizeCategoryModel *m_iconSizeCategoryModel;
105 
106     mutable QCache<QString, KIconTheme> m_kiconThemeCache;
107 
108     QScopedPointer<QTemporaryFile> m_tempInstallFile;
109     QPointer<KIO::FileCopyJob> m_tempCopyJob;
110 };
111