Add autostart option
This commit is contained in:
@@ -35,6 +35,8 @@ GeneneralConf::GeneneralConf(QWidget *parent) : QGroupBox(parent) {
|
||||
initShowHelp();
|
||||
initShowDesktopNotification();
|
||||
initShowTrayIcon();
|
||||
initAutostart();
|
||||
|
||||
initConfingButtons();
|
||||
updateComponents();
|
||||
}
|
||||
@@ -43,6 +45,7 @@ void GeneneralConf::updateComponents() {
|
||||
ConfigHandler config;
|
||||
m_helpMessage->setChecked(config.showHelpValue());
|
||||
m_sysNotifications->setChecked(config.desktopNotificationValue());
|
||||
m_autostart->setChecked(config.startupLaunchValue());
|
||||
#ifdef Q_OS_LINUX
|
||||
m_showTray->setChecked(!config.disabledTrayIconValue());
|
||||
#endif
|
||||
@@ -62,7 +65,11 @@ void GeneneralConf::showTrayIconChanged(bool checked) {
|
||||
controller->enableTrayIcon();
|
||||
} else {
|
||||
controller->disableTrayIcon();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GeneneralConf::autostartChanged(bool checked) {
|
||||
ConfigHandler().setStartupLaunch(checked);
|
||||
}
|
||||
|
||||
void GeneneralConf::importConfiguration() {
|
||||
@@ -164,5 +171,18 @@ void GeneneralConf::initConfingButtons() {
|
||||
m_resetButton = new QPushButton(tr("Reset"));
|
||||
buttonLayout->addWidget(m_resetButton);
|
||||
connect(m_resetButton, &QPushButton::clicked, this,
|
||||
&GeneneralConf::resetConfiguration);
|
||||
&GeneneralConf::resetConfiguration);
|
||||
}
|
||||
|
||||
void GeneneralConf::initAutostart() {
|
||||
m_autostart =
|
||||
new QCheckBox(tr("Launch at startup"), this);
|
||||
ConfigHandler config;
|
||||
bool checked = config.startupLaunchValue();
|
||||
m_autostart->setChecked(checked);
|
||||
m_autostart->setToolTip(tr("Launch Flameshot "));
|
||||
m_layout->addWidget(m_autostart);
|
||||
|
||||
connect(m_autostart, &QCheckBox::clicked, this,
|
||||
&GeneneralConf::autostartChanged);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ private slots:
|
||||
void showHelpChanged(bool checked);
|
||||
void showDesktopNotificationChanged(bool checked);
|
||||
void showTrayIconChanged(bool checked);
|
||||
void autostartChanged(bool checked);
|
||||
void importConfiguration();
|
||||
void exportConfiguration();
|
||||
void resetConfiguration();
|
||||
@@ -45,14 +46,16 @@ private:
|
||||
QCheckBox *m_sysNotifications;
|
||||
QCheckBox *m_showTray;
|
||||
QCheckBox *m_helpMessage;
|
||||
QPushButton *m_importButton;
|
||||
QPushButton *m_exportButton;
|
||||
QPushButton *m_resetButton;
|
||||
QCheckBox *m_autostart;
|
||||
QPushButton *m_importButton;
|
||||
QPushButton *m_exportButton;
|
||||
QPushButton *m_resetButton;
|
||||
|
||||
void initShowHelp();
|
||||
void initShowDesktopNotification();
|
||||
void initShowTrayIcon();
|
||||
void initConfingButtons();
|
||||
void initConfingButtons();
|
||||
void initAutostart();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#include "confighandler.h"
|
||||
#include <algorithm>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
|
||||
ConfigHandler::ConfigHandler(){
|
||||
m_settings.setDefaultFormat(QSettings::IniFormat);
|
||||
@@ -117,6 +119,44 @@ void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen) {
|
||||
m_settings.setValue("keepOpenAppLauncher", keepOpen);
|
||||
}
|
||||
|
||||
bool ConfigHandler::startupLaunchValue() {
|
||||
bool res = false;
|
||||
#if defined(Q_OS_LINUX)
|
||||
QString path = QDir::homePath() + "/.config/autostart/Flameshot.desktop";
|
||||
res = QFile(path).exists();
|
||||
#elif defined(Q_OS_WIN)
|
||||
QSettings bootUpSettings(
|
||||
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||
QSettings::NativeFormat);
|
||||
res = !bootUpSettings.value("Flameshot").toString().isEmpty();
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setStartupLaunch(const bool start) {
|
||||
#if defined(Q_OS_LINUX)
|
||||
QString path = QDir::homePath() + "/.config/autostart/Flameshot.desktop";
|
||||
QFile file(path);
|
||||
if (start) {
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
file.write("[Desktop Entry]\nIcon=system-run\nExec=flameshot\nTerminal=false");
|
||||
}
|
||||
} else {
|
||||
file.remove();
|
||||
}
|
||||
#elif defined(Q_OS_WIN)
|
||||
QSettings bootUpSettings(
|
||||
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||
QSettings::NativeFormat);
|
||||
if (start) {
|
||||
QString app_path = QCoreApplication::applicationFilePath();
|
||||
bootUpSettings.setValue("Flameshot", app_path);
|
||||
} else {
|
||||
bootUpSettings.remove("Flameshot");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ConfigHandler::initiatedIsSet() {
|
||||
return m_settings.value("initiated").toBool();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ public:
|
||||
bool keepOpenAppLauncherValue();
|
||||
void setKeepOpenAppLauncher(const bool);
|
||||
|
||||
bool startupLaunchValue();
|
||||
void setStartupLaunch(const bool);
|
||||
|
||||
bool initiatedIsSet();
|
||||
void setInitiated();
|
||||
void setNotInitiated();
|
||||
|
||||
Reference in New Issue
Block a user