1 #ifndef __KIO_FONTS_H__
2 #define __KIO_FONTS_H__
5 * KFontInst - KDE Font Installer
7 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
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"
30 #include <KDE/KIO/SlaveBase>
32 #include <KDE/KLocale>
34 #include <QtCore/QByteArray>
35 #include <QtCore/QHash>
36 #include <QtCore/QSet>
37 #include <QtCore/QList>
38 #include <QtCore/QVariant>
40 #include "KfiConstants.h"
41 #include "DisabledFonts.h"
42 #if defined USE_POLICYKIT && USE_POLICYKIT==1
43 #include "FontInstInterface.h"
54 #if !(defined USE_POLICYKIT && USE_POLICYKIT==1)
59 class CKioFonts
: public KIO::SlaveBase
87 class CDirList
: public QSet
<QString
>
92 CDirList(const QString
&str
) { add(str
); }
93 void add(const QString
&d
) { insert(d
); }
98 TFontDetails() : writingSystems(0) { }
100 CDisabledFonts::TFileList files
;
102 qulonglong writingSystems
;
105 typedef QHash
<QString
, TFontDetails
> TFontMap
;
109 TFolder() : disabled(NULL
) { }
110 void setLocation(const QString
&l
, bool sys
);
114 TFontMap fontMap
; // Maps from "Times New Roman" -> $HOME/.fonts/times.ttf
115 CDisabledFonts
*disabled
;
122 TCommand(ECommands c
) : cmd(c
) { }
123 TCommand(ECommands c
, const QVariant
&v
) : cmd(c
) { args
.append(v
); }
125 QList
<QVariant
> args
;
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
);
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
,
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
);
163 bool getRootPasswd(const KUrl
&url
, bool askPasswd
=true);
164 #if !(defined USE_POLICYKIT && USE_POLICYKIT==1)
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
¶m
=QString());
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();
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
;