OSDN Git Service

Version 0.5
[fontmanager/fontmanager.git] / fontsconf.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Takumi Asaki
4 ** All rights reserved.
5 ** Contact: Takumi Asaki (takumi.asaki@gmail.com)
6 **
7 ** This file is part of the fontmanager application.
8 **
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ****************************************************************************/
38
39 #ifndef FONTSCONF_H
40 #define FONTSCONF_H
41
42 #include <QObject>
43 #include <QStringList>
44
45 #include "fontsconfelement.h"
46
47 class FontsConf : public QObject
48 {
49     Q_OBJECT
50 public:
51     explicit FontsConf(QObject *parent = 0);
52
53     bool isEmpty() const;
54     bool modified() const;
55     void setModified(bool value);
56     bool hasUnknownConfig() const;
57
58     bool isValid() const;
59
60     void initFontsConf();
61
62     bool parse(const QByteArray &buf);
63
64     QStringList preferFamily() const;
65
66     QStringList aliasFamilyFor(const QString &family, const QString &mode) const;
67     int indxOfAliasFamilyFor(const QString &family, const QString &mode, const QString &value) const;
68     void appendAliasFamilyFor(const QString &family, const QString &mode, const QString &value);
69     void insertAliasFamilyFor(const QString &family, const QString &mode, const QString &value, int index);
70     void removeAliasFamilyFor(const QString &family, const QString &mode, const QString &value);
71
72     QStringList preferFamilyFor(const QString &family) const;
73     int indxOfPreferFamilyFor(const QString &family, const QString &value) const;
74     void appendPreferFamilyFor(const QString &family, const QString &value);
75     void insertPreferFamilyFor(const QString &family, const QString &value, int index);
76     void removePreferFamilyFor(const QString &family, const QString &value);
77
78     QStringList acceptFamilyFor(const QString &family) const;
79     int indxOfAcceptFamilyFor(const QString &family, const QString &value) const;
80     void appendAcceptFamilyFor(const QString &family, const QString &value);
81     void insertAcceptFamilyFor(const QString &family, const QString &value, int index);
82     void removeAcceptFamilyFor(const QString &family, const QString &value);
83
84     QStringList matchFamilyFor(const QString &config, bool val) const;
85     QString matchEditValueFor(const QString &config, const QString &family) const;
86     void setMatchEditValueFor(const QString &config, const QString &family, bool val);
87     void unsetMatchEditValueFor(const QString &config, const QString &family);
88
89     QStringList patternFamilyFor(const QString &family, const QString &mode) const;
90     int indxOfPatternFamilyFor(const QString &family, const QString &mode, const QString &value) const;
91     void appendPatternFamilyFor(const QString &family, const QString &mode, const QString &value);
92     void insertPatternFamilyFor(const QString &family, const QString &mode, const QString &value, int index);
93     void removePatternFamilyFor(const QString &family, const QString &mode, const QString &value);
94
95     QStringList prependFamilyFor(const QString &family) const;
96     int indxOfPrependFamilyFor(const QString &family, const QString &value) const;
97     void appendPrependFamilyFor(const QString &family, const QString &value);
98     void insertPrependFamilyFor(const QString &family, const QString &value, int index);
99     void removePrependFamilyFor(const QString &family, const QString &value);
100
101     QStringList appendFamilyFor(const QString &family) const;
102     int indxOfAppendFamilyFor(const QString &family, const QString &value) const;
103     void appendAppendFamilyFor(const QString &family, const QString &value);
104     void insertAppendFamilyFor(const QString &family, const QString &value, int index);
105     void removeAppendFamilyFor(const QString &family, const QString &value);
106
107     void copy(FontsConf *src);
108
109     static QStringList genericFamilies();
110     static QStringList configKeys();
111
112 private:
113     FontsConfElementPointer aliasElementFor(const QString &family) const;
114     FontsConfElementPointer matchElementFor(const QString &config, bool val) const;
115     FontsConfElementPointer patternElementFor(const QString &family) const;
116
117     bool appendFamilyToAlias(FontsConfElementPointer aliasElem, const QString &family, const QString &mode, const QString &value);
118     bool insertFamilyToAlias(FontsConfElementPointer aliasElem, const QString &family, const QString &mode, const QString &value, int index);
119     bool isMatchElementFor(FontsConfElementPointer matchElem, const QString &config, const QString &family, const QString &val = QString()) const;
120     bool isPatternElementFor(FontsConfElementPointer matchElem, const QString &family, const QString &mode = QString()) const;
121     FontsConfElementPointer getEditPatternElementFor(FontsConfElementPointer matchElem, const QString &family, const QString &mode = QString()) const;
122
123     bool containsTextElement(FontsConfElementPointer elem, const QString &tag, const QString &text) const;
124     QStringList textElementList(FontsConfElementPointer elem, const QString &tag) const;
125
126 signals:
127     
128 public slots:
129     void load(const QString &path);
130     void save(const QString &path);
131     
132 private:
133     bool mModified;
134     bool mValid;
135     bool mHasUnknownConfig;
136     FontsConfElementPointer mElements;
137 };
138
139 #endif // FONTSCONF_H