add more spacing
[personal-kdebase.git] / workspace / kcontrol / kfontinst / kio / KioFonts.h
blob3c4e263196fa7a7dfa771f5c6a52decca324bfad
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 "../config-fontinst.h"
29 #include <time.h>
30 #include <KDE/KIO/SlaveBase>
31 #include <KDE/KUrl>
32 #include <KDE/KLocale>
34 #include <QtCore/QByteArray>
35 #include <QtCore/QHash>
36 #include <QtCore/QSet>
37 #include <QtCore/QList>
38 #include <QtCore/QVariant>
39 #include "Misc.h"
40 #include "KfiConstants.h"
41 #include "DisabledFonts.h"
42 #if defined USE_POLICYKIT && USE_POLICYKIT==1
43 #include "FontInstInterface.h"
44 #else
45 #include "Server.h"
46 #endif
47 #include "Helper.h"
49 class KTemporaryFile;
51 namespace KFI
54 #if !(defined USE_POLICYKIT && USE_POLICYKIT==1)
55 class CSuProc;
56 class CSocket;
57 #endif
59 class CKioFonts : public KIO::SlaveBase
61 private:
63 enum EFileType
65 FILE_UNKNOWN,
66 FILE_FONT,
67 FILE_METRICS
70 enum EFolder
72 FOLDER_SYS,
73 FOLDER_USER,
75 FOLDER_COUNT
78 enum EOp
80 OP_COPY,
81 OP_MOVE,
82 OP_DELETE,
83 OP_ENABLE,
84 OP_DISABLE
87 class CDirList : public QSet<QString>
89 public:
91 CDirList() { }
92 CDirList(const QString &str) { add(str); }
93 void add(const QString &d) { insert(d); }
96 struct TFontDetails
98 TFontDetails() : writingSystems(0) { }
100 CDisabledFonts::TFileList files;
101 quint32 styleVal;
102 qulonglong writingSystems;
105 typedef QHash<QString, TFontDetails> TFontMap;
107 struct TFolder
109 TFolder() : disabled(NULL) { }
110 void setLocation(const QString &l, bool sys);
112 QString location;
113 CDirList modified;
114 TFontMap fontMap; // Maps from "Times New Roman" -> $HOME/.fonts/times.ttf
115 CDisabledFonts *disabled;
118 public:
120 struct TCommand
122 TCommand(ECommands c) : cmd(c) { }
123 TCommand(ECommands c, const QVariant &v) : cmd(c) { args.append(v); }
124 ECommands cmd;
125 QList<QVariant> args;
128 public:
130 CKioFonts(const QByteArray &pool, const QByteArray &app);
131 virtual ~CKioFonts() { cleanup(); }
133 static QString getSect(const QString &f) { return f.section('/', 1, 1); }
135 void listDir(const KUrl &url);
136 void listDir(EFolder folder, KIO::UDSEntry &entry);
137 void stat(const KUrl &url);
138 bool createStatEntry(KIO::UDSEntry &entry, const KUrl &url, EFolder folder);
139 bool createStatEntryReal(KIO::UDSEntry &entry, const KUrl &url, EFolder folder);
140 void get(const KUrl &url);
141 void put(const KUrl &url, int mode, KIO::JobFlags flags);
142 void copy(const KUrl &src, const KUrl &dest, int mode, KIO::JobFlags flags);
143 void rename(const KUrl &src, const KUrl &dest, KIO::JobFlags flags);
144 void del(const KUrl &url, bool isFile);
145 void cleanup();
147 private:
149 QString getUserName(uid_t uid);
150 QString getGroupName(gid_t gid);
151 bool createFontUDSEntry(KIO::UDSEntry &entry, const QString &name,
152 const CDisabledFonts::TFileList &patterns,
153 quint32 styleVal, qulonglong writingSystems,
154 bool sys, bool hidden=false);
155 bool createFolderUDSEntry(KIO::UDSEntry &entry, const QString &name, const QString &path,
156 bool sys);
157 bool putReal(KTemporaryFile &dest);
158 void modified(int timeout, EFolder folder, bool clearList=true,
159 const CDirList &dirs=CDirList());
160 void special(const QByteArray &a);
161 bool configure(EFolder folder);
162 void doModified();
163 bool getRootPasswd(const KUrl &url, bool askPasswd=true);
164 #if !(defined USE_POLICYKIT && USE_POLICYKIT==1)
165 void quitHelper();
166 #endif
167 bool doRootCmd(const KUrl &url, const TCommand &cmd, bool askPasswd=true);
168 bool doRootCmd(const KUrl &url, QList<TCommand> &cmd, bool askPasswd=true);
169 #if defined USE_POLICYKIT && USE_POLICYKIT==1
170 int doLongRootCmd(const QString &method, const QString &param=QString());
171 #endif
172 void correctUrl(KUrl &url);
173 void clearFontList();
174 bool updateFontList();
175 EFolder getFolder(const KUrl &url);
176 TFontMap::Iterator getMap(const KUrl &url);
177 const CDisabledFonts::TFileList * getEntries(const KUrl &url, TFontMap::Iterator &enabledIt,
178 CDisabledFonts::TFontList::Iterator &disabledIt);
179 QStringList getFontNameEntries(EFolder folder, const QString &file, bool disabledFonts);
180 QMap<int, QString> getFontIndexToNameEntries(EFolder folder, const QString &file);
181 QString * getEntry(EFolder folder, const QString &file, bool full=false);
182 EFileType checkFile(const QString &file, const KUrl &url);
183 bool getSourceFiles(const KUrl &src, CDisabledFonts::TFileList &files,
184 bool removeSymLinks=true);
185 bool checkDestFile(const KUrl &src, const KUrl &dest, EFolder destFolder,
186 KIO::JobFlags flags);
187 bool checkDestFiles(const KUrl &src, QMap<QString, QString> &map, const KUrl &dest,
188 EFolder destFolder, KIO::JobFlags flags);
189 bool confirmMultiple(const KUrl &url, const CDisabledFonts::TFileList &files,
190 EFolder folder, EOp op);
191 bool confirmMultiple(const KUrl &url, const CDisabledFonts::TFileList *patterns,
192 EFolder folder, EOp op);
193 bool checkUrl(const KUrl &u, bool rootOk=false, bool logError=true);
194 bool checkAllowed(const KUrl &u);
195 void createAfm(const QString &file, bool nrs=false);
196 int reconfigTimeout();
198 private:
200 bool itsRoot,
201 itsAddToSysFc;
202 QByteArray itsHelper;
203 time_t itsLastFcCheckTime;
204 FcFontSet *itsFontList;
205 TFolder itsFolders[FOLDER_COUNT];
206 QHash<uid_t, QString> itsUserCache;
207 QHash<gid_t, QString> itsGroupCache;
208 #if defined USE_POLICYKIT && USE_POLICYKIT==1
209 org::kde::fontinst *itsFontInstIface;
210 uint itsPid;
211 #else
212 QString itsPasswd;
213 CServer itsServer;
214 CSocket *itsSocket;
215 CSuProc *itsSuProc;
216 #endif
221 #endif