Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kcontrol / kfontinst / kio / KioFonts.h
blob47aebd004948c6f6b6a143da1a3132fda65d5d87
1 #ifndef __KIO_FONTS_H__
2 #define __KIO_FONTS_H__
4 /*
5 * KFontInst - KDE Font Installer
7 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
9 * ----
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
27 #include <fontconfig/fontconfig.h>
28 #include <time.h>
29 #include <KDE/KIO/SlaveBase>
30 #include <KDE/KUrl>
31 #include <KDE/KLocale>
33 #include <QtCore/QByteArray>
34 #include <QtCore/QHash>
35 #include <QtCore/QSet>
36 #include <QtCore/QList>
37 #include <QtCore/QVariant>
38 #include "Misc.h"
39 #include "KfiConstants.h"
40 #include "DisabledFonts.h"
41 #include "Server.h"
42 #include "Helper.h"
44 namespace KFI
47 class CSuProc;
48 class CSocket;
50 class CKioFonts : public KIO::SlaveBase
52 private:
54 enum EFileType
56 FILE_UNKNOWN,
57 FILE_FONT,
58 FILE_METRICS
61 enum EFolder
63 FOLDER_SYS,
64 FOLDER_USER,
66 FOLDER_COUNT
69 enum EOp
71 OP_COPY,
72 OP_MOVE,
73 OP_DELETE,
74 OP_ENABLE,
75 OP_DISABLE
78 class CDirList : public QSet<QString>
80 public:
82 CDirList() { }
83 CDirList(const QString &str) { add(str); }
84 void add(const QString &d) { insert(d); }
87 struct TFontDetails
89 TFontDetails() : writingSystems(0) { }
91 CDisabledFonts::TFileList files;
92 quint32 styleVal;
93 qulonglong writingSystems;
96 typedef QHash<QString, TFontDetails> TFontMap;
98 struct TFolder
100 TFolder() : disabled(NULL) { }
101 void setLocation(const QString &l, bool sys);
103 QString location;
104 CDirList modified;
105 TFontMap fontMap; // Maps from "Times New Roman" -> $HOME/.fonts/times.ttf
106 CDisabledFonts *disabled;
109 public:
111 struct TCommand
113 TCommand(ECommands c) : cmd(c) { }
114 TCommand(ECommands c, const QVariant &v) : cmd(c) { args.append(v); }
115 ECommands cmd;
116 QList<QVariant> args;
119 public:
121 CKioFonts(const QByteArray &pool, const QByteArray &app);
122 virtual ~CKioFonts() { cleanup(); }
124 static QString getSect(const QString &f) { return f.section('/', 1, 1); }
126 void listDir(const KUrl &url);
127 void listDir(EFolder folder, KIO::UDSEntry &entry);
128 void stat(const KUrl &url);
129 bool createStatEntry(KIO::UDSEntry &entry, const KUrl &url, EFolder folder);
130 bool createStatEntryReal(KIO::UDSEntry &entry, const KUrl &url, EFolder folder);
131 void get(const KUrl &url);
132 void put(const KUrl &url, int mode, KIO::JobFlags flags);
133 void copy(const KUrl &src, const KUrl &dest, int mode, KIO::JobFlags flags);
134 void rename(const KUrl &src, const KUrl &dest, KIO::JobFlags flags);
135 void del(const KUrl &url, bool isFile);
136 void cleanup();
138 private:
140 QString getUserName(uid_t uid);
141 QString getGroupName(gid_t gid);
142 bool createFontUDSEntry(KIO::UDSEntry &entry, const QString &name,
143 const CDisabledFonts::TFileList &patterns,
144 quint32 styleVal, qulonglong writingSystems,
145 bool sys, bool hidden=false);
146 bool createFolderUDSEntry(KIO::UDSEntry &entry, const QString &name, const QString &path,
147 bool sys);
148 bool putReal(const QString &destOrig, const QByteArray &destOrigC, bool origExists,
149 int mode, KIO::JobFlags flags);
150 void modified(int timeout, EFolder folder, bool clearList=true,
151 const CDirList &dirs=CDirList());
152 void special(const QByteArray &a);
153 bool configure(EFolder folder);
154 void doModified();
155 bool getRootPasswd(bool askPasswd=true);
156 void quitHelper();
157 bool doRootCmd(const TCommand &cmd, bool askPasswd=true);
158 bool doRootCmd(QList<TCommand> &cmd, bool askPasswd=true);
159 void correctUrl(KUrl &url);
160 void clearFontList();
161 bool updateFontList();
162 EFolder getFolder(const KUrl &url);
163 TFontMap::Iterator getMap(const KUrl &url);
164 const CDisabledFonts::TFileList * getEntries(const KUrl &url, TFontMap::Iterator &enabledIt,
165 CDisabledFonts::TFontList::Iterator &disabledIt);
166 QStringList getFontNameEntries(EFolder folder, const QString &file, bool disabledFonts);
167 QMap<int, QString> getFontIndexToNameEntries(EFolder folder, const QString &file);
168 QString * getEntry(EFolder folder, const QString &file, bool full=false);
169 EFileType checkFile(const QString &file, const KUrl &url);
170 bool getSourceFiles(const KUrl &src, CDisabledFonts::TFileList &files,
171 bool removeSymLinks=true);
172 bool checkDestFile(const KUrl &src, const KUrl &dest, EFolder destFolder,
173 KIO::JobFlags flags);
174 bool checkDestFiles(const KUrl &src, QMap<QString, QString> &map, const KUrl &dest,
175 EFolder destFolder, KIO::JobFlags flags);
176 bool confirmMultiple(const KUrl &url, const CDisabledFonts::TFileList &files,
177 EFolder folder, EOp op);
178 bool confirmMultiple(const KUrl &url, const CDisabledFonts::TFileList *patterns,
179 EFolder folder, EOp op);
180 bool checkUrl(const KUrl &u, bool rootOk=false, bool logError=true);
181 bool checkAllowed(const KUrl &u);
182 void createAfm(const QString &file, bool nrs=false);
183 int reconfigTimeout();
185 private:
187 bool itsRoot,
188 itsAddToSysFc;
189 QString itsPasswd;
190 QByteArray itsHelper;
191 time_t itsLastFcCheckTime;
192 FcFontSet *itsFontList;
193 TFolder itsFolders[FOLDER_COUNT];
194 QHash<uid_t, QString> itsUserCache;
195 QHash<gid_t, QString> itsGroupCache;
196 CServer itsServer;
197 CSocket *itsSocket;
198 CSuProc *itsSuProc;
203 #endif