Move startup shortcut handling to FortSettings.

This commit is contained in:
Nodir Temirkhodjaev 2017-09-03 12:20:07 +05:00
parent 42435f2ad4
commit e7a29cdb26
5 changed files with 33 additions and 33 deletions

View File

@ -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<FortManager>("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";
}

View File

@ -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

View File

@ -1,5 +1,6 @@
#include "fortsettings.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QJsonDocument>
#include <QSettings>
@ -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";
}

View File

@ -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;

View File

@ -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