OSDN Git Service

e858eef8aa67573903c0a3ebeae232bf54056b95
[fontmanager/fontmanager.git] / applicationcontroller.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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 APPLICATIONCONTROLLER_H
40 #define APPLICATIONCONTROLLER_H
41
42 #include <QObject>
43 #include <QStringList>
44 #include <QVariant>
45 #include <QUrl>
46
47 #include "fontinfo.h"
48
49 class FontConfigManager;
50 class InstalledFontInfo;
51 class FontsConfEditorController;
52
53 class ApplicationController : public QObject
54 {
55     Q_OBJECT
56     Q_PROPERTY(QString version READ version NOTIFY dummySignal)
57     Q_PROPERTY(QString fontDir READ fontDir WRITE setFontDir NOTIFY fontDirChanged)
58     Q_PROPERTY(bool fontDirExists READ fontDirExists NOTIFY fontDirExistsChanged)
59
60     Q_PROPERTY(QString localFontsConfPath READ localFontsConfPath NOTIFY localFontsConfPathChanged)
61     Q_PROPERTY(bool localFontsConfExists READ localFontsConfExists NOTIFY localFontsConfExistsChanged)
62     Q_PROPERTY(bool isEmptyFontsConf READ isEmptyFontsConf NOTIFY localFontsConfChanged)
63     Q_PROPERTY(QString localFontsConf READ localFontsConf NOTIFY localFontsConfChanged)
64
65     Q_PROPERTY(bool showSystemFont READ showSystemFont WRITE setShowSystemFont NOTIFY showSystemFontChanged)
66
67     Q_PROPERTY(bool working READ working NOTIFY workingChanged)
68
69     Q_PROPERTY(QUrl backupDir READ backupDir NOTIFY backupDirChanged)
70 public:
71     explicit ApplicationController(QObject *parent = 0);
72     
73 public slots:
74     void init();
75
76 public:
77     QString version() const;
78
79     QString currentLanguage() const;
80
81     QString fontDir() const;
82     void setFontDir(const QString &dirpath);
83
84     bool fontDirExists() const;
85
86     bool showSystemFont() const;
87     void setShowSystemFont(bool show);
88
89     Q_INVOKABLE FontInfo *checkFontInfo(const QUrl &path);
90     Q_INVOKABLE InstalledFontInfo *fontInfo(const QString &family, const QString &fullname = QString()) const;
91     Q_INVOKABLE QStringList fontCount(const QString &fontpath) const;
92
93     Q_INVOKABLE QString localeFamily(const QString &family) const;
94
95     Q_INVOKABLE bool fontExists(FontInfo *fontinfo);
96
97     Q_INVOKABLE FontsConfEditorController *editorController(const QString &family);
98     void updateEditorController(const QString &family);
99
100     QUrl backupDir() const;
101     Q_INVOKABLE QString defaultBackupFilename() const;
102
103     Q_INVOKABLE QString url2path(const QUrl &url) const;
104
105 public slots:
106     void updateAllEditorController();
107
108 public:
109     bool localFontsConfExists() const;
110     QString localFontsConfPath() const;
111     QString localFontsConf() const;
112     bool isEmptyFontsConf() const;
113
114     bool working() const;
115
116 public slots:
117     void startUpdateLocalFontsConf();
118     void endUpdateLocalFontsConf();
119     void localFontsConfUpdated();
120
121     void resetLocalFontsConf();
122     void importSystemSettings(const QString &family);
123
124     void createRecommendedSettings();
125
126     void backupConfig(const QString &filename);
127     void restoreConfig(const QString &filename);
128
129 signals:
130     void alertDialog(const QString &message);
131
132     void fontDirChanged(const QString dirpath);
133     void fontDirExistsChanged();
134
135     void showSystemFontChanged();
136
137     void installFinished(const QString &fontpath);
138     void uninstallFinished(const QString &fontpath);
139     void backupConfigFinished(const QString &filepath);
140     void restoreConfigFinished(const QString &filepath);
141
142     void clearInstalledFontList();
143     void appendInstalledFont(const QString &family, const QString &fullname);
144
145     void clearInstallableFamilyListFor(const QString &family);
146     void appendInstallableFamily(const QString &enfamily, const QString &family, bool systemFont);
147
148     void localFontsConfPathChanged();
149     void localFontsConfExistsChanged();
150     void localFontsConfChanged();
151
152     void workingChanged();
153
154     void backupDirChanged();
155
156     void dummySignal();
157
158 private slots:
159     void readFcListFinished();
160
161 public slots:
162     void createFontDir();
163
164     void installFont(FontInfo *fontinfo);
165
166     void updateFontsConf(InstalledFontInfo *fontInfo);
167
168     void uninstallFont(const QString &fontpath);
169     
170     void syncInstalledFonts();
171     void syncInstallableFamilyFor(const QString &family);
172
173     void saveFontsConf();
174
175     void appendFamilyToConfig(const QString &family, const QString &value, const QString &priority);
176     void insertFamilyToConfig(const QString &family, const QString &value, const QString &priority, int index);
177     void removeFamilyFromConfig(const QString &family, const QString &value, const QString &priority);
178
179 private:
180     QString mLang;
181     QString mFontDirPath;
182     bool mFontDirExists;
183     bool mShowSystemFont;
184
185     int mUpdating;
186     bool mForceOverwrite;
187     bool mWorking;
188     bool mIgnoreUpdate;
189
190     FontConfigManager *mFontConfig;
191     QMap<QString, FontsConfEditorController*> mEditorController;
192 };
193
194 #endif // APPLICATIONCONTROLLER_H