From e7a29cdb260d9f6d2423ab3c35a97779200c8d08 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sun, 3 Sep 2017 12:20:07 +0500 Subject: [PATCH] Move startup shortcut handling to FortSettings. --- src/ui/fortmanager.cpp | 24 ------------------------ src/ui/fortmanager.h | 7 ------- src/ui/fortsettings.cpp | 24 ++++++++++++++++++++++++ src/ui/fortsettings.h | 7 +++++++ src/ui/qml/pages/OptionsPage.qml | 4 ++-- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index f1d00e17..fa8459e3 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -11,7 +11,6 @@ #include "conf/appgroup.h" #include "conf/firewallconf.h" #include "fortsettings.h" -#include "util/fileutil.h" FortManager::FortManager(QObject *parent) : QObject(parent), @@ -29,22 +28,6 @@ FortManager::FortManager(QObject *parent) : setupEngine(); } -bool FortManager::startWithWindows() const -{ - return FileUtil::fileExists(startupShortcutPath()); -} - -void FortManager::setStartWithWindows(bool start) -{ - const QString linkPath = startupShortcutPath(); - if (start) { - FileUtil::linkFile(qApp->applicationFilePath(), linkPath); - } else { - FileUtil::removeFile(linkPath); - } - emit startWithWindowsChanged(); -} - void FortManager::registerQmlTypes() { qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "FortManager", @@ -198,10 +181,3 @@ void FortManager::setActionCheckable(QAction *action, bool checked, connect(action, SIGNAL(toggled(bool)), receiver, member); } } - -QString FortManager::startupShortcutPath() -{ - return FileUtil::applicationsLocation() + QLatin1Char('\\') - + "Startup" + QLatin1Char('\\') - + qApp->applicationName() + ".lnk"; -} diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index 6a7dc94d..5155d475 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -15,7 +15,6 @@ class FortManager : public QObject Q_OBJECT Q_PROPERTY(FortSettings *fortSettings READ fortSettings CONSTANT) Q_PROPERTY(FirewallConf *firewallConfToEdit READ firewallConfToEdit NOTIFY firewallConfToEditChanged) - Q_PROPERTY(bool startWithWindows READ startWithWindows WRITE setStartWithWindows NOTIFY startWithWindowsChanged) public: explicit FortManager(QObject *parent = nullptr); @@ -26,12 +25,8 @@ public: return m_firewallConfToEdit ? m_firewallConfToEdit : m_firewallConf; } - bool startWithWindows() const; - void setStartWithWindows(bool start); - signals: void firewallConfToEditChanged(); - void startWithWindowsChanged(); public slots: void showTrayIcon(); @@ -65,8 +60,6 @@ private: static void setActionCheckable(QAction *action, bool checked = false, const QObject *receiver = 0, const char *member = 0); - static QString startupShortcutPath(); - private: QMainWindow m_window; // dummy window for tray icon diff --git a/src/ui/fortsettings.cpp b/src/ui/fortsettings.cpp index 73a434ec..956849f5 100644 --- a/src/ui/fortsettings.cpp +++ b/src/ui/fortsettings.cpp @@ -1,5 +1,6 @@ #include "fortsettings.h" +#include #include #include #include @@ -16,6 +17,22 @@ FortSettings::FortSettings(const QStringList &args, setupIni(); } +bool FortSettings::startWithWindows() const +{ + return FileUtil::fileExists(startupShortcutPath()); +} + +void FortSettings::setStartWithWindows(bool start) +{ + const QString linkPath = startupShortcutPath(); + if (start) { + FileUtil::linkFile(qApp->applicationFilePath(), linkPath); + } else { + FileUtil::removeFile(linkPath); + } + emit startWithWindowsChanged(); +} + void FortSettings::processArguments(const QStringList &args) { const QCommandLineOption profileOption("profile", "Directory to store settings."); @@ -191,3 +208,10 @@ void FortSettings::setIniValue(const QString &key, const QVariant &value, m_ini->setValue(key, value); emit iniChanged(); } + +QString FortSettings::startupShortcutPath() +{ + return FileUtil::applicationsLocation() + QLatin1Char('\\') + + "Startup" + QLatin1Char('\\') + + qApp->applicationName() + ".lnk"; +} diff --git a/src/ui/fortsettings.h b/src/ui/fortsettings.h index 9447cae0..beb6b568 100644 --- a/src/ui/fortsettings.h +++ b/src/ui/fortsettings.h @@ -12,6 +12,7 @@ class FortSettings : public QObject Q_PROPERTY(bool debug READ debug WRITE setDebug NOTIFY iniChanged) Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY iniChanged) Q_PROPERTY(QString updatesUrl READ updatesUrl WRITE setUpdatesUrl NOTIFY iniChanged) + Q_PROPERTY(bool startWithWindows READ startWithWindows WRITE setStartWithWindows NOTIFY startWithWindowsChanged) public: explicit FortSettings(const QStringList &args, @@ -26,8 +27,12 @@ public: QString updatesUrl() const { return iniText("base/updatesUrl"); } void setUpdatesUrl(const QString &v) { setIniValue("base/updatesUrl", v); } + bool startWithWindows() const; + void setStartWithWindows(bool start); + signals: void iniChanged(); + void startWithWindowsChanged(); public slots: QString confFilePath() const; @@ -58,6 +63,8 @@ private: void setIniValue(const QString &key, const QVariant &value, const QVariant &defaultValue = QVariant()); + static QString startupShortcutPath(); + private: QString m_profilePath; diff --git a/src/ui/qml/pages/OptionsPage.qml b/src/ui/qml/pages/OptionsPage.qml index 64fba47c..d3928b2d 100644 --- a/src/ui/qml/pages/OptionsPage.qml +++ b/src/ui/qml/pages/OptionsPage.qml @@ -6,7 +6,7 @@ import com.fortfirewall 1.0 BasePage { function onSaved() { // overload - fortManager.startWithWindows = cbStart.checked; + fortSettings.startWithWindows = cbStart.checked; } Column { @@ -15,7 +15,7 @@ BasePage { CheckBox { id: cbStart text: QT_TRANSLATE_NOOP("qml", "Start with Windows") - checked: fortManager.startWithWindows + checked: fortSettings.startWithWindows } CheckBox { id: cbFilter