File indexing completed on 2025-01-26 05:08:10

0001 /*
0002     SPDX-FileCopyrightText: 2003-2007 Craig Drummond <craig@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #pragma once
0007 
0008 #include "FontInstInterface.h"
0009 #include <QDialog>
0010 #include <QUrl>
0011 
0012 class QLabel;
0013 class QProgressBar;
0014 class QStackedWidget;
0015 class QCloseEvent;
0016 class QCheckBox;
0017 class QDialogButtonBox;
0018 class QAbstractButton;
0019 class QTemporaryDir;
0020 
0021 namespace KFI
0022 {
0023 class CActionLabel;
0024 
0025 class CJobRunner : public QDialog
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     struct Item : public QUrl {
0031         enum EType {
0032             TYPE1_FONT,
0033             TYPE1_AFM,
0034             TYPE1_PFM,
0035             OTHER_FONT,
0036         };
0037 
0038         Item(const QUrl &u = QUrl(), const QString &n = QString(), bool dis = false);
0039         Item(const QString &file, const QString &family, quint32 style, bool system);
0040         QString displayName() const
0041         {
0042             return name.isEmpty() ? url() : name;
0043         }
0044         QString name,
0045             fileName; // Only required so that we can sort an ItemList so that afm/pfms follow after pfa/pfbs
0046         EType type;
0047         bool isDisabled;
0048 
0049         bool operator<(const Item &o) const;
0050     };
0051 
0052     typedef QList<Item> ItemList;
0053 
0054     enum ECommand {
0055         CMD_INSTALL,
0056         CMD_DELETE,
0057         CMD_ENABLE,
0058         CMD_DISABLE,
0059         CMD_UPDATE,
0060         CMD_MOVE,
0061         CMD_REMOVE_FILE,
0062     };
0063 
0064     explicit CJobRunner(QWidget *parent, int xid = 0);
0065     ~CJobRunner() override;
0066 
0067     static FontInstInterface *dbus();
0068     static QString folderName(bool sys);
0069     static void startDbusService();
0070 
0071     static QUrl encode(const QString &family, quint32 style, bool system);
0072 
0073     static void getAssociatedUrls(const QUrl &url, QList<QUrl> &list, bool afmAndPfm, QWidget *widget);
0074     int exec(ECommand cmd, const ItemList &urls, bool destIsSystem);
0075 
0076 Q_SIGNALS:
0077 
0078     void configuring();
0079 
0080 private Q_SLOTS:
0081 
0082     void doNext();
0083     void checkInterface();
0084     void dbusServiceOwnerChanged(const QString &name, const QString &from, const QString &to);
0085     void dbusStatus(int pid, int status);
0086     void slotButtonClicked(QAbstractButton *button);
0087 
0088 private:
0089     void contineuToNext(bool cont);
0090     void closeEvent(QCloseEvent *e) override;
0091     void setPage(int page, const QString &msg = QString());
0092     QString fileName(const QUrl &url);
0093     QString errorString(int value) const;
0094 
0095 private:
0096     ECommand m_cmd;
0097     ItemList m_urls;
0098     ItemList::ConstIterator m_it, m_end, m_prev;
0099     bool m_destIsSystem;
0100     QLabel *m_statusLabel, *m_skipLabel, *m_errorLabel;
0101     QProgressBar *m_progress;
0102     bool m_autoSkip, m_cancelClicked, m_modified;
0103     QTemporaryDir *m_tempDir;
0104     QString m_currentFile;
0105     CActionLabel *m_actionLabel;
0106     QStackedWidget *m_stack;
0107     int m_lastDBusStatus;
0108     QCheckBox *m_dontShowFinishedMsg;
0109     QDialogButtonBox *m_buttonBox;
0110     QPushButton *m_skipButton;
0111     QPushButton *m_autoSkipButton;
0112 };
0113 
0114 }