1 #pragma once 2 3 /* 4 * SPDX-FileCopyrightText: 2003-2009 Craig Drummond <craig@kde.org> 5 * SPDX-License-Identifier: GPL-2.0-or-later 6 */ 7 8 #include "Family.h" 9 #include "Folder.h" 10 #include "FontinstIface.h" 11 #include "kfontinst_export.h" 12 #include <KJob> 13 #include <QDBusConnection> 14 #include <QObject> 15 #include <QSet> 16 #include <QStringList> 17 18 #define FONTINST_PATH "/FontInst" 19 20 class QTimer; 21 22 namespace KFI 23 { 24 class KFONTINST_EXPORT FontInst : public QObject 25 { 26 Q_OBJECT 27 Q_CLASSINFO("D-Bus Interface", "org.kde.fontinst") 28 29 public: 30 enum EStatus { 31 STATUS_OK = 0, 32 STATUS_SERVICE_DIED = KJob::UserDefinedError + 500, 33 STATUS_BITMAPS_DISABLED, 34 STATUS_ALREADY_INSTALLED, 35 STATUS_NOT_FONT_FILE, 36 STATUS_PARTIAL_DELETE, 37 STATUS_NO_SYS_CONNECTION, 38 }; 39 40 enum EFolder { 41 FOLDER_SYS, 42 FOLDER_USER, 43 44 FOLDER_COUNT, 45 }; 46 47 enum { 48 SYS_MASK = 0x01, 49 USR_MASK = 0x02, 50 }; 51 registerTypes()52 static void registerTypes() 53 { 54 qDBusRegisterMetaType<Families>(); 55 qDBusRegisterMetaType<Family>(); 56 qDBusRegisterMetaType<Style>(); 57 qDBusRegisterMetaType<File>(); 58 qDBusRegisterMetaType<Style>(); 59 qDBusRegisterMetaType<QList<Families>>(); 60 } 61 isStarted(OrgKdeFontinstInterface * iface)62 static bool isStarted(OrgKdeFontinstInterface *iface) 63 { 64 QDBusReply<QStringList> reply = iface->connection().interface()->registeredServiceNames(); 65 if (reply.isValid()) { 66 QStringList services(reply.value()); 67 QStringList::ConstIterator it(services.begin()), end(services.end()); 68 for (; it != end; ++it) 69 if ((*it) == OrgKdeFontinstInterface::staticInterfaceName()) 70 return true; 71 } 72 return false; 73 } 74 75 FontInst(); 76 ~FontInst() override; 77 78 public Q_SLOTS: 79 80 Q_NOREPLY void list(int folders, int pid); 81 Q_NOREPLY void statFont(const QString &font, int folders, int pid); 82 Q_NOREPLY void install(const QString &file, bool createAfm, bool toSystem, int pid, bool checkConfig); 83 Q_NOREPLY void uninstall(const QString &family, quint32 style, bool fromSystem, int pid, bool checkConfig); 84 Q_NOREPLY void uninstall(const QString &name, bool fromSystem, int pid, bool checkConfig); 85 Q_NOREPLY void move(const QString &family, quint32 style, bool toSystem, int pid, bool checkConfig); 86 Q_NOREPLY void enable(const QString &family, quint32 style, bool inSystem, int pid, bool checkConfig); 87 Q_NOREPLY void disable(const QString &family, quint32 style, bool inSystem, int pid, bool checkConfig); 88 Q_NOREPLY void removeFile(const QString &family, quint32 style, const QString &file, bool fromSystem, int pid, bool checkConfig); 89 Q_NOREPLY void reconfigure(int pid, bool force); 90 Q_SCRIPTABLE QString folderName(bool sys); 91 Q_SCRIPTABLE void saveDisabled(); 92 93 Q_SIGNALS: 94 95 void fontList(int pid, const QList<KFI::Families> &families); 96 void status(int pid, int status); 97 void fontStat(int pid, const KFI::Family &font); 98 void fontsAdded(const KFI::Families &families); 99 void fontsRemoved(const KFI::Families &families); 100 101 private Q_SLOTS: 102 103 void connectionsTimeout(); 104 void fontListTimeout(); 105 106 private: 107 void updateFontList(bool emitChanges = true); 108 void toggle(bool enable, const QString &family, quint32 style, bool inSystem, int pid, bool checkConfig); 109 void addModifedSysFolders(const Family &family); 110 void checkConnections(); 111 bool findFontReal(const QString &family, const QString &style, EFolder folder, FamilyCont::ConstIterator &fam, StyleCont::ConstIterator &st); 112 bool findFont(const QString &font, EFolder folder, FamilyCont::ConstIterator &fam, StyleCont::ConstIterator &st, bool updateList = true); 113 bool findFontReal(const QString &family, quint32 style, EFolder folder, FamilyCont::ConstIterator &fam, StyleCont::ConstIterator &st); 114 bool findFont(const QString &family, quint32 style, EFolder folder, FamilyCont::ConstIterator &fam, StyleCont::ConstIterator &st, bool updateList = true); 115 int performAction(const QVariantMap &args); 116 117 static void emergencySave(int sig); 118 119 private: 120 QTimer *itsConnectionsTimer, *itsFontListTimer; 121 QSet<int> itsConnections; 122 }; 123 124 } 125