1 /****************************************************************************
3 ** Copyright (C) 2012 Takumi Asaki
4 ** All rights reserved.
5 ** Contact: Takumi Asaki (takumi.asaki@gmail.com)
7 ** This file is part of the fontmanager application.
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
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
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
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."
37 ****************************************************************************/
39 #ifndef APPLICATIONCONTROLLER_H
40 #define APPLICATIONCONTROLLER_H
43 #include <QStringList>
49 class FontConfigManager;
50 class InstalledFontInfo;
51 class FontsConfEditorController;
53 class ApplicationController : public QObject
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)
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 localFontsConfFileUpdated)
63 Q_PROPERTY(QString localFontsConf READ localFontsConf NOTIFY localFontsConfFileUpdated)
65 Q_PROPERTY(bool showSystemFont READ showSystemFont WRITE setShowSystemFont NOTIFY showSystemFontChanged)
67 Q_PROPERTY(bool working READ working NOTIFY workingChanged)
69 Q_PROPERTY(QUrl backupDir READ backupDir NOTIFY backupDirChanged)
71 Q_PROPERTY(QStringList installedFonts READ installedFonts NOTIFY installedFontsChanged)
73 explicit ApplicationController(QObject *parent = 0);
79 QString version() const;
81 QString currentLanguage() const;
83 QString fontDir() const;
84 void setFontDir(const QString &dirpath);
86 bool fontDirExists() const;
88 bool showSystemFont() const;
89 void setShowSystemFont(bool show);
91 Q_INVOKABLE FontInfo *checkFontInfo(const QUrl &path);
92 Q_INVOKABLE InstalledFontInfo *fontInfo(const QString &family, const QString &fullname = QString()) const;
93 Q_INVOKABLE QStringList fontCount(const QString &fontpath) const;
95 Q_INVOKABLE QString localeFamily(const QString &family) const;
97 Q_INVOKABLE bool fontExists(FontInfo *fontinfo);
99 Q_INVOKABLE FontsConfEditorController *editorController(const QString &family);
100 void updateEditorController(const QString &family);
102 QUrl backupDir() const;
103 Q_INVOKABLE QString defaultBackupFilename() const;
105 Q_INVOKABLE QString url2path(const QUrl &url) const;
106 Q_INVOKABLE QString path4display(const QString &path) const;
108 QStringList installedFonts() const;
111 void updateAllEditorController();
114 bool localFontsConfExists() const;
115 QString localFontsConfPath() const;
116 QString localFontsConf() const;
117 bool isEmptyFontsConf() const;
119 bool working() const;
122 void startUpdateLocalFontsConf();
123 void endUpdateLocalFontsConf();
124 void localFontsConfUpdated();
126 void resetLocalFontsConf();
127 void importSystemSettings(const QString &family);
129 void createRecommendedSettings();
131 void backupConfig(const QString &filename);
132 void restoreConfig(const QString &filename);
133 void restoreConfig(const QUrl &filename);
136 void alertDialog(const QString &message);
138 void fontDirChanged(const QString dirpath);
139 void fontDirExistsChanged();
141 void showSystemFontChanged();
142 void installedFontsChanged();
144 void installFinished(const QString &fontpath);
145 void uninstallFinished(const QString &fontpath);
146 void backupConfigFinished(const QString &filepath);
147 void restoreConfigFinished(const QString &filepath);
149 void clearInstalledFontList();
150 void appendInstalledFont(const QString &family, const QString &fullname);
152 void clearInstallableFamilyListFor(const QString &family);
153 void appendInstallableFamily(const QString &enfamily, const QString &family, bool systemFont);
155 void localFontsConfPathChanged();
156 void localFontsConfExistsChanged();
157 void localFontsConfChanged();
158 void localFontsConfFileUpdated();
160 void workingChanged();
162 void backupDirChanged();
167 void readFcListFinished();
170 void createFontDir();
172 void installFont(FontInfo *fontinfo);
174 void updateFontsConf(InstalledFontInfo *fontInfo);
176 void uninstallFont(const QString &fontpath);
178 void syncInstalledFonts();
179 void syncInstallableFamilyFor(const QString &family);
181 void saveFontsConf();
183 void appendFamilyToConfig(const QString &family, const QString &value, const QString &priority);
184 void insertFamilyToConfig(const QString &family, const QString &value, const QString &priority, int index);
185 void removeFamilyFromConfig(const QString &family, const QString &value, const QString &priority);
189 QString mFontDirPath;
191 bool mShowSystemFont;
192 QStringList mInstalledFonts;
198 FontConfigManager *mFontConfig;
199 QMap<QString, FontsConfEditorController*> mEditorController;
202 #endif // APPLICATIONCONTROLLER_H