File indexing completed on 2024-05-12 05:56:49

0001 /*
0002   SPDX-FileCopyrightText: 2008 Eike Hein <hein@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef APPEARANCESETTINGS_H
0008 #define APPEARANCESETTINGS_H
0009 
0010 #include "ui_appearancesettings.h"
0011 
0012 #include <QTemporaryFile>
0013 
0014 #include <KIO/Job>
0015 
0016 class SkinListDelegate;
0017 
0018 class QStandardItem;
0019 class QStandardItemModel;
0020 
0021 class AppearanceSettings : public QWidget, private Ui::AppearanceSettings
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     explicit AppearanceSettings(QWidget *parent = nullptr);
0027     ~AppearanceSettings();
0028 
0029     enum DataRole {
0030         SkinId = Qt::UserRole + 1,
0031         SkinDir = Qt::UserRole + 2,
0032         SkinName = Qt::UserRole + 3,
0033         SkinAuthor = Qt::UserRole + 4,
0034         SkinIcon = Qt::UserRole + 5,
0035         SkinInstalledWithKns = Qt::UserRole + 6,
0036     };
0037 
0038 public Q_SLOTS:
0039     void resetSelection();
0040 
0041 Q_SIGNALS:
0042     void settingsChanged();
0043 
0044 protected:
0045     void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
0046 
0047 private Q_SLOTS:
0048     void populateSkinList();
0049 
0050     void updateSkinSetting();
0051 
0052     void installSkin();
0053     void installSkinArchive();
0054 
0055     /**
0056      * Validates the given skin.
0057      * This method checks if the fileList of the skin
0058      * contains all required files.
0059      *
0060      * @param skinId The SkinID of the skin which will be validated.
0061      * @param kns The skin has been installed from kns.
0062      *
0063      * @return True if the skin is valid, otherwise false.
0064      */
0065     bool validateSkin(const QString &skinId, bool kns);
0066 
0067     /**
0068      * Extracts the skin IDs from the given fileList.
0069      * There can be multiple skins, but only one skin per directory.
0070      * The files need to be located in the m_knsSkinDir.
0071      *
0072      * @param fileList All files which were installed.
0073      *
0074      * @return The list of skin IDs which were extracted from the
0075      *         given fileList.
0076      */
0077     QSet<QString> extractKnsSkinIds(const QStringList &fileList);
0078 
0079     void knsDialogFinished(const QList<KNSCore::Entry> &changedEntries);
0080 
0081     void updateRemoveSkinButton();
0082     void removeSelectedSkin();
0083 
0084 private:
0085     QStandardItem *createSkinItem(const QString &skinDir);
0086 
0087     void populateSkinList(const QString &installationDirectory);
0088     void checkForExistingSkin();
0089     void removeSkin(const QString &skinDir, std::function<void()> successCallback = nullptr);
0090     void installSkin(const QUrl &skinUrl);
0091     void failInstall(const QString &error);
0092     void cleanupAfterInstall();
0093 
0094     QString m_selectedSkinId;
0095 
0096     QStandardItemModel *m_skins;
0097     SkinListDelegate *m_skinListDelegate;
0098 
0099     QString m_localSkinsDir;
0100     QString m_knsSkinDir;
0101     QString m_installSkinId;
0102     QTemporaryFile m_installSkinFile;
0103     QStringList m_installSkinFileList;
0104 
0105     QString m_knsConfigFileName;
0106 };
0107 
0108 #endif