OSDN Git Service

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