OSDN Git Service

Version: 0.3.1
[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 <QDir>
44 #include <QStringList>
45 #include <QUrl>
46 #include <QVariant>
47
48 #include "fontinfo.h"
49
50 class FontConfigManager;
51 class InstalledFontInfo;
52
53 class ApplicationController : public QObject
54 {
55     Q_OBJECT
56     Q_PROPERTY(QString fontDir READ fontDir WRITE setFontDir NOTIFY fontDirChanged)
57     Q_PROPERTY(QStringList fontList READ fontList NOTIFY fontListChanged)
58     Q_PROPERTY(bool fontDirExists READ fontDirExists)
59     Q_PROPERTY(bool showSystemFont READ showSystemFont WRITE setShowSystemFont NOTIFY showSystemFontChanged)
60
61     Q_PROPERTY(QString localFontsConf READ localFontsConf NOTIFY localFontsConfPathChanged)
62     Q_PROPERTY(bool localFontsConfExists READ localFontsConfExists NOTIFY localFontsConfPathChanged)
63
64     Q_PROPERTY(bool configHasUninstalledFonts READ configHasUninstalledFonts NOTIFY configHasUninstalledFontsChanged)
65
66 public:
67     explicit ApplicationController(QObject *parent = 0);
68     
69 public slots:
70     void init();
71
72 public:
73     QString currentLanguage() const;
74
75     QString fontDir() const;
76     void setFontDir(const QString &dirpath);
77
78     bool fontDirExists() const;
79
80     bool showSystemFont() const;
81     void setShowSystemFont(bool show);
82
83     QStringList fontList() const;
84
85     Q_INVOKABLE FontInfo *checkFontInfo(const QUrl &path);
86     Q_INVOKABLE InstalledFontInfo *fontInfo(const QString &family, const QString &fullname = QString()) const;
87     Q_INVOKABLE QStringList fontCount(const QString &fontpath) const;
88
89     bool localFontsConfExists() const;
90     QString localFontsConf() const;
91
92     bool configHasUninstalledFonts() const;
93 public slots:
94     void removeUninstalledFontsFromConfig();
95
96 signals:
97     void alertDialog(const QString &message);
98
99     void confirmDialog(const QString &title, const QString &message);
100
101     void fontDirChanged(const QString dirpath);
102     void fontListChanged();
103
104     void showSystemFontChanged();
105
106     void installFinished(const QString &fontpath);
107     void uninstallFinished(const QString &fontpath);
108
109     void clearInstalledFontList();
110     void appendInstalledFont(const QString &family, const QString &fullname);
111
112     void localFontsConfPathChanged();
113     void configHasUninstalledFontsChanged();
114
115 public slots:
116     void installFont();
117     void installFont(FontInfo *fontinfo);
118     void postInstall();
119
120     void updateFontsConf(InstalledFontInfo *fontInfo);
121
122     void uninstallFont(const QString &fontpath);
123     void confirm(bool ok);
124     
125     void syncInstalledFonts();
126
127     void saveFontsConf();
128
129 private:
130     enum FontJob { Nothing, StartInstall, CreateFontsDir, CheckDstFont, InstallFont, UninstallFont };
131
132 private:
133     QString mLang;
134     QString mFontDirPath;
135     bool mFontDirExists;
136     bool mShowSystemFont;
137
138     FontJob mNextJob;
139     QVariant mJobOption;
140
141     bool forceOverwrite;
142
143     FontConfigManager *mFontConfig;
144 };
145
146 #endif // APPLICATIONCONTROLLER_H