Initial implementation of auto-start functionality.
This commit is contained in:
parent
1706a36b66
commit
3cf6a90d50
@ -166,6 +166,7 @@ set(APP_SOURCES
|
|||||||
# CORE sources.
|
# CORE sources.
|
||||||
src/core/debugging.cpp
|
src/core/debugging.cpp
|
||||||
src/core/settings.cpp
|
src/core/settings.cpp
|
||||||
|
src/core/systemfactory.cpp
|
||||||
|
|
||||||
# Basic application sources.
|
# Basic application sources.
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
94
src/core/systemfactory.cpp
Normal file
94
src/core/systemfactory.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
#include "core/systemfactory.h"
|
||||||
|
#include "core/defs.h"
|
||||||
|
|
||||||
|
|
||||||
|
SystemFactory::SystemFactory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() {
|
||||||
|
// User registry way to auto-start the application on Windows.
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
QSettings sett("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||||
|
bool autostart_enabled = sett.value(APP_LOW_NAME,
|
||||||
|
"").toString().replace('\\', '/') == QApplication::applicationFilePath();
|
||||||
|
|
||||||
|
if (autostart_enabled) {
|
||||||
|
return SystemFactory::Enabled;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SystemFactory::Disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use proper freedesktop.org way to auto-start the application on Linux.
|
||||||
|
// INFO: http://standards.freedesktop.org/autostart-spec/latest/
|
||||||
|
#elif defined(Q_OS_LINUX)
|
||||||
|
QString xdg_config_path(qgetenv("XDG_CONFIG_HOME"));
|
||||||
|
QString desktop_file_location;
|
||||||
|
|
||||||
|
if (!xdg_config_path.isEmpty()) {
|
||||||
|
// XDG_CONFIG_HOME variable is specified. Look for .desktop file
|
||||||
|
// in 'autostart' subdirectory.
|
||||||
|
desktop_file_location = xdg_config_path + "/autostart/rssguard.desktop";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Desired variable is not set, look for the default 'autostart' subdirectory.
|
||||||
|
QString home_directory(qgetenv("HOME"));
|
||||||
|
if (!home_directory.isEmpty()) {
|
||||||
|
// Home directory exists. Check if target .desktop file exists and
|
||||||
|
// return according status.
|
||||||
|
desktop_file_location = home_directory + "/.config/autostart/rssguard.desktop";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug("Searching for auto-start function status failed. HOME variable not found.");
|
||||||
|
return SystemFactory::Unavailable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We found correct path, now check if file exists and return correct status.
|
||||||
|
if (QFile::exists(desktop_file_location)) {
|
||||||
|
return SystemFactory::Enabled;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SystemFactory::Disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable auto-start functionality on unsupported platforms.
|
||||||
|
#else
|
||||||
|
return SystemFactory::Unavailable;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Finish implementation of SystemFactory auto-start methods.
|
||||||
|
bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) {
|
||||||
|
SystemFactory::AutoStartStatus current_status = SystemFactory::getAutoStartStatus();
|
||||||
|
|
||||||
|
if (current_status == SystemFactory::Unavailable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (new_status) {
|
||||||
|
case SystemFactory::Enabled:
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
|
||||||
|
#elif defined(Q_OS_LINUX)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case SystemFactory::Disabled:
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
|
||||||
|
#elif defined(Q_OS_LINUX)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
25
src/core/systemfactory.h
Normal file
25
src/core/systemfactory.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef SYSTEMFACTORY_H
|
||||||
|
#define SYSTEMFACTORY_H
|
||||||
|
|
||||||
|
|
||||||
|
class SystemFactory {
|
||||||
|
private:
|
||||||
|
SystemFactory();
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum AutoStartStatus {
|
||||||
|
Enabled,
|
||||||
|
Disabled,
|
||||||
|
Unavailable
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns current status of auto-start function.
|
||||||
|
static SystemFactory::AutoStartStatus getAutoStartStatus();
|
||||||
|
|
||||||
|
// Sets new status for auto-start function.
|
||||||
|
// Function returns false if setting of
|
||||||
|
// new status failed.
|
||||||
|
static bool setAutoStartStatus(const SystemFactory::AutoStartStatus &new_status);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SYSTEMFACTORY_H
|
@ -36,6 +36,7 @@ void FormMain::processExecutionMessage(const QString &message) {
|
|||||||
// TODO: Implement proper reaction when application is launched more than once.
|
// TODO: Implement proper reaction when application is launched more than once.
|
||||||
qDebug("Received '%s' execution message from another application instance.",
|
qDebug("Received '%s' execution message from another application instance.",
|
||||||
qPrintable(message));
|
qPrintable(message));
|
||||||
|
display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormMain::quit() {
|
void FormMain::quit() {
|
||||||
@ -44,10 +45,15 @@ void FormMain::quit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FormMain::display() {
|
void FormMain::display() {
|
||||||
|
// Make sure window is not minimized.
|
||||||
setWindowState(windowState() & ~Qt::WindowMinimized);
|
setWindowState(windowState() & ~Qt::WindowMinimized);
|
||||||
|
|
||||||
|
// Display the window and make sure it is raised on top.
|
||||||
show();
|
show();
|
||||||
activateWindow();
|
activateWindow();
|
||||||
raise();
|
raise();
|
||||||
|
|
||||||
|
// Raise alert event. Check the documentation for more info on this.
|
||||||
QtSingleApplication::alert(this);
|
QtSingleApplication::alert(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "gui/formmain.h"
|
#include "gui/formmain.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
|
#include "core/systemfactory.h"
|
||||||
|
|
||||||
|
|
||||||
FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormSettings) {
|
FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormSettings) {
|
||||||
@ -16,6 +17,7 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
|
|||||||
connect(this, &FormSettings::accepted, this, &FormSettings::saveSettings);
|
connect(this, &FormSettings::accepted, this, &FormSettings::saveSettings);
|
||||||
|
|
||||||
// Load all settings.
|
// Load all settings.
|
||||||
|
loadGeneral();
|
||||||
loadInterface();
|
loadInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,15 +26,49 @@ FormSettings::~FormSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FormSettings::saveSettings() {
|
void FormSettings::saveSettings() {
|
||||||
// Save all categories.
|
// Save all settings.
|
||||||
//saveGeneral();
|
saveGeneral();
|
||||||
saveInterface();
|
saveInterface();
|
||||||
//saveLanguages();
|
|
||||||
|
|
||||||
// Make sure that settings is synced.
|
// Make sure that settings is synced.
|
||||||
Settings::getInstance()->checkSettings();
|
Settings::getInstance()->checkSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FormSettings::loadGeneral() {
|
||||||
|
// Load auto-start status.
|
||||||
|
SystemFactory::AutoStartStatus autostart_status = SystemFactory::getAutoStartStatus();
|
||||||
|
switch (autostart_status) {
|
||||||
|
case SystemFactory::Enabled:
|
||||||
|
m_ui->m_checkAutostart->setChecked(true);
|
||||||
|
break;
|
||||||
|
case SystemFactory::Disabled:
|
||||||
|
m_ui->m_checkAutostart->setChecked(false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
m_ui->m_checkAutostart->setEnabled(false);
|
||||||
|
m_ui->m_checkAutostart->setText(m_ui->m_checkAutostart->text() +
|
||||||
|
tr(" (not supported on this platform)"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormSettings::saveGeneral() {
|
||||||
|
// Save auto-start on Windows.
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
QSettings sett("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||||
|
if (m_ui->m_checkAutostart->isChecked()) {
|
||||||
|
sett.setValue(APP_LOW_NAME, QApplication::applicationFilePath().replace('/', '\\'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sett.remove(APP_LOW_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save auto-start on Linux.
|
||||||
|
#elif defined(Q_OS_LINUX)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void FormSettings::loadInterface() {
|
void FormSettings::loadInterface() {
|
||||||
// Load settings of tray icon.
|
// Load settings of tray icon.
|
||||||
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
||||||
|
@ -24,6 +24,9 @@ class FormSettings : public QDialog {
|
|||||||
// Load/save GUI settings.
|
// Load/save GUI settings.
|
||||||
void loadInterface();
|
void loadInterface();
|
||||||
void saveInterface();
|
void saveInterface();
|
||||||
|
|
||||||
|
void loadGeneral();
|
||||||
|
void saveGeneral();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FormSettings *m_ui;
|
Ui::FormSettings *m_ui;
|
||||||
|
@ -45,9 +45,31 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QStackedWidget" name="m_stackedSettings">
|
<widget class="QStackedWidget" name="m_stackedSettings">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="m_pageGeneral"/>
|
<widget class="QWidget" name="m_pageGeneral">
|
||||||
|
<layout class="QFormLayout" name="formLayout_5">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QCheckBox" name="m_checkAutostart">
|
||||||
|
<property name="text">
|
||||||
|
<string>Launch RSS Guard on operating system startup</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QWidget" name="m_pageUi">
|
<widget class="QWidget" name="m_pageUi">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
|
@ -80,9 +80,11 @@ int main(int argc, char *argv[]) {
|
|||||||
if (Settings::getInstance()->value(APP_CFG_GUI, "start_hidden",
|
if (Settings::getInstance()->value(APP_CFG_GUI, "start_hidden",
|
||||||
false).toBool() &&
|
false).toBool() &&
|
||||||
SystemTrayIcon::isSystemTrayActivated()) {
|
SystemTrayIcon::isSystemTrayActivated()) {
|
||||||
|
qDebug("Hiding the main window when the application is starting.");
|
||||||
window.hide();
|
window.hide();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
qDebug("Showing the main window when the application is starting.");
|
||||||
window.show();
|
window.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +94,6 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup single-instance behavior.
|
// Setup single-instance behavior.
|
||||||
application.setActivationWindow(&window, true);
|
|
||||||
QObject::connect(&application, &QtSingleApplication::messageReceived,
|
QObject::connect(&application, &QtSingleApplication::messageReceived,
|
||||||
&window, &FormMain::processExecutionMessage);
|
&window, &FormMain::processExecutionMessage);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user