add more spacing
[personal-kdebase.git] / workspace / kcontrol / kfontinst / lib / DisabledFonts.h
blob2982685376476676ad67272763f68e84c02029a6
1 #ifndef __DISABLED_FONTS_H__
2 #define __DISABLED_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.
28 #include <QtCore/QSet>
29 #include <QtCore/QList>
30 #include <QtGui/QFontDatabase>
31 #include <time.h>
32 #include "KfiConstants.h"
33 #include "Misc.h"
34 #include "kfontinst_export.h"
35 #include <fontconfig/fontconfig.h>
37 class QDomElement;
38 class QTextStream;
41 // Class used to store list of disabled fonts, and font groups, within an XML file.
42 namespace KFI
45 class KFONTINST_EXPORT CDisabledFonts
47 public:
49 struct LangWritingSystemMap
51 QFontDatabase::WritingSystem ws;
52 const FcChar8 *lang;
55 struct TFile
57 TFile(const QString &p=QString(), int f=0, const QString &fnd=QString()) : path(p), foundry(fnd), face(f) { }
59 bool operator==(const TFile &o) const { return face==o.face && path==o.path; }
60 bool load(QDomElement &elem);
62 operator QString() const { return path; }
64 QString path,
65 foundry;
66 int face; // This is only really required for TTC fonts -> where a file will belong
67 }; // to more than one font.
69 struct KFONTINST_EXPORT TFileList : public QList<TFile>
71 Iterator locate(const TFile &t) { int i = indexOf(t); return (-1==i ? end() : (begin()+i)); }
72 void add(const TFile &t) const { (const_cast<TFileList *>(this))->append(t); }
74 QString toString(bool skipFirst=false) const;
75 void fromString(QString &s);
78 struct KFONTINST_EXPORT TFont : public Misc::TFont
80 TFont(const QString &f=QString(), unsigned long s=KFI_NO_STYLE_INFO, qulonglong ws=0) : Misc::TFont(f, s), writingSystems(ws) { }
81 TFont(const Misc::TFont &f) : Misc::TFont(f), writingSystems(0) { }
83 bool operator==(const TFont &o) const { return styleInfo==o.styleInfo && family==o.family; }
84 bool load(QDomElement &elem, bool &modified);
86 const QString & getName() const;
88 mutable QString name;
89 TFileList files;
90 qulonglong writingSystems;
93 struct KFONTINST_EXPORT TFontList : public QSet<TFont>
95 Iterator locate(const TFont &t);
96 Iterator locate(const Misc::TFont &t);
97 void add(const TFont &t) const;
100 explicit CDisabledFonts(bool sys=false);
101 ~CDisabledFonts() { save(); }
103 static const LangWritingSystemMap * languageForWritingSystemMap() { return theirLanguageForWritingSystem; }
106 // Refresh checks the timestamp of the file to determine if changes have been
107 // made elsewhere.
108 void reload();
109 bool refresh();
110 void load(bool lock=true);
111 bool save();
112 bool modifiable() const { return itsModifiable; }
113 bool modified() const { return itsModified; }
115 bool disable(const TFont &font);
116 bool enable(const QString &family, unsigned long styleInfo)
117 { return enable(TFont(family, styleInfo)); }
118 bool enable(const TFont &font)
119 { return enable(itsFonts.locate(font)); }
120 bool enable(TFontList::Iterator font);
122 TFontList::Iterator find(const QString &name, int face);
123 void remove(TFontList::Iterator it) { itsFonts.erase(it);
124 itsModified=true; }
125 TFontList & items() { return itsFonts; }
127 private:
129 CDisabledFonts(const CDisabledFonts &o);
130 void merge(const CDisabledFonts &other);
132 static void createWritingSystemMap();
134 private:
136 QString itsFileName;
137 time_t itsTimeStamp;
138 bool itsModified,
139 itsModifiable;
140 TFontList itsFonts;
141 int itsMods;
143 static LangWritingSystemMap theirLanguageForWritingSystem[];
146 inline KDE_EXPORT uint qHash(const CDisabledFonts::TFont &key)
148 return qHash((Misc::TFont&)key);
153 KFONTINST_EXPORT QTextStream & operator<<(QTextStream &s, const KFI::CDisabledFonts::TFile &f);
154 KFONTINST_EXPORT QTextStream & operator<<(QTextStream &s, const KFI::CDisabledFonts::TFont &f);
156 #endif