OSDN Git Service

Version 0.5
[fontmanager/fontmanager.git] / applicationcontroller.h
index ebe3ea2..f81ff5a 100644 (file)
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2011 Takumi Asaki
+** Copyright (C) 2012 Takumi Asaki
 ** All rights reserved.
 ** Contact: Takumi Asaki (takumi.asaki@gmail.com)
 **
 #define APPLICATIONCONTROLLER_H
 
 #include <QObject>
-#include <QDir>
 #include <QStringList>
-#include <QUrl>
 #include <QVariant>
+#include <QUrl>
 
 #include "fontinfo.h"
 
 class FontConfigManager;
 class InstalledFontInfo;
+class FontsConfEditorController;
 
 class ApplicationController : public QObject
 {
     Q_OBJECT
+    Q_PROPERTY(QString version READ version NOTIFY dummySignal)
     Q_PROPERTY(QString fontDir READ fontDir WRITE setFontDir NOTIFY fontDirChanged)
-    Q_PROPERTY(QStringList fontList READ fontList NOTIFY fontListChanged)
-    Q_PROPERTY(bool fontDirExists READ fontDirExists)
+    Q_PROPERTY(bool fontDirExists READ fontDirExists NOTIFY fontDirExistsChanged)
+
+    Q_PROPERTY(QString localFontsConfPath READ localFontsConfPath NOTIFY localFontsConfPathChanged)
+    Q_PROPERTY(bool localFontsConfExists READ localFontsConfExists NOTIFY localFontsConfExistsChanged)
+    Q_PROPERTY(bool isEmptyFontsConf READ isEmptyFontsConf NOTIFY localFontsConfFileUpdated)
+    Q_PROPERTY(QString localFontsConf READ localFontsConf NOTIFY localFontsConfFileUpdated)
+
     Q_PROPERTY(bool showSystemFont READ showSystemFont WRITE setShowSystemFont NOTIFY showSystemFontChanged)
 
-    Q_PROPERTY(QString localFontsConf READ localFontsConf NOTIFY localFontsConfPathChanged)
-    Q_PROPERTY(bool localFontsConfExists READ localFontsConfExists NOTIFY localFontsConfPathChanged)
+    Q_PROPERTY(bool working READ working NOTIFY workingChanged)
 
-    Q_PROPERTY(bool configHasUninstalledFonts READ configHasUninstalledFonts NOTIFY configHasUninstalledFontsChanged)
+    Q_PROPERTY(QUrl backupDir READ backupDir NOTIFY backupDirChanged)
 
+    Q_PROPERTY(QStringList installedFonts READ installedFonts NOTIFY installedFontsChanged)
 public:
     explicit ApplicationController(QObject *parent = 0);
     
@@ -70,6 +76,8 @@ public slots:
     void init();
 
 public:
+    QString version() const;
+
     QString currentLanguage() const;
 
     QString fontDir() const;
@@ -80,67 +88,115 @@ public:
     bool showSystemFont() const;
     void setShowSystemFont(bool show);
 
-    QStringList fontList() const;
-
     Q_INVOKABLE FontInfo *checkFontInfo(const QUrl &path);
     Q_INVOKABLE InstalledFontInfo *fontInfo(const QString &family, const QString &fullname = QString()) const;
     Q_INVOKABLE QStringList fontCount(const QString &fontpath) const;
 
+    Q_INVOKABLE QString localeFamily(const QString &family) const;
+
+    Q_INVOKABLE bool fontExists(FontInfo *fontinfo);
+
+    Q_INVOKABLE FontsConfEditorController *editorController(const QString &family);
+    void updateEditorController(const QString &family);
+
+    QUrl backupDir() const;
+    Q_INVOKABLE QString defaultBackupFilename() const;
+
+    Q_INVOKABLE QString url2path(const QUrl &url) const;
+    Q_INVOKABLE QString path4display(const QString &path) const;
+
+    QStringList installedFonts() const;
+
+public slots:
+    void updateAllEditorController();
+
+public:
     bool localFontsConfExists() const;
+    QString localFontsConfPath() const;
     QString localFontsConf() const;
+    bool isEmptyFontsConf() const;
+
+    bool working() const;
 
-    bool configHasUninstalledFonts() const;
 public slots:
-    void removeUninstalledFontsFromConfig();
+    void startUpdateLocalFontsConf();
+    void endUpdateLocalFontsConf();
+    void localFontsConfUpdated();
+
+    void resetLocalFontsConf();
+    void importSystemSettings(const QString &family);
+
+    void createRecommendedSettings();
+
+    void backupConfig(const QString &filename);
+    void restoreConfig(const QString &filename);
+    void restoreConfig(const QUrl &filename);
 
 signals:
     void alertDialog(const QString &message);
 
-    void confirmDialog(const QString &title, const QString &message);
-
     void fontDirChanged(const QString dirpath);
-    void fontListChanged();
+    void fontDirExistsChanged();
 
     void showSystemFontChanged();
+    void installedFontsChanged();
 
     void installFinished(const QString &fontpath);
     void uninstallFinished(const QString &fontpath);
+    void backupConfigFinished(const QString &filepath);
+    void restoreConfigFinished(const QString &filepath);
 
     void clearInstalledFontList();
     void appendInstalledFont(const QString &family, const QString &fullname);
 
+    void clearInstallableFamilyListFor(const QString &family);
+    void appendInstallableFamily(const QString &enfamily, const QString &family, bool systemFont);
+
     void localFontsConfPathChanged();
-    void configHasUninstalledFontsChanged();
+    void localFontsConfExistsChanged();
+    void localFontsConfChanged();
+    void localFontsConfFileUpdated();
+
+    void workingChanged();
+
+    void backupDirChanged();
+
+    void dummySignal();
+
+private slots:
+    void readFcListFinished();
 
 public slots:
-    void installFont();
+    void createFontDir();
+
     void installFont(FontInfo *fontinfo);
-    void postInstall();
 
     void updateFontsConf(InstalledFontInfo *fontInfo);
 
     void uninstallFont(const QString &fontpath);
-    void confirm(bool ok);
     
     void syncInstalledFonts();
+    void syncInstallableFamilyFor(const QString &family);
 
     void saveFontsConf();
 
-private:
-    enum FontJob { Nothing, StartInstall, CreateFontsDir, CheckDstFont, InstallFont, UninstallFont };
+    void appendFamilyToConfig(const QString &family, const QString &value, const QString &priority);
+    void insertFamilyToConfig(const QString &family, const QString &value, const QString &priority, int index);
+    void removeFamilyFromConfig(const QString &family, const QString &value, const QString &priority);
 
 private:
     QString mLang;
     QString mFontDirPath;
     bool mFontDirExists;
     bool mShowSystemFont;
+    QStringList mInstalledFonts;
 
-    FontJob mNextJob;
-    QVariant mJobOption;
-
-    bool forceOverwrite;
+    int mUpdating;
+    bool mWorking;
+    bool mIgnoreUpdate;
 
     FontConfigManager *mFontConfig;
+    QMap<QString, FontsConfEditorController*> mEditorController;
 };
 
 #endif // APPLICATIONCONTROLLER_H