Progress in implementing auto-start on Windows, Linux remains.

This commit is contained in:
Martin Rotter 2013-06-24 18:40:13 +02:00
parent 3cf6a90d50
commit 9e5b205caa
2 changed files with 38 additions and 28 deletions

View File

@ -1,6 +1,11 @@
#include <QString>
#include <QFile>
#if defined(Q_OS_WIN)
#include <QSettings>
#include "qtsingleapplication/qtsingleapplication.h"
#endif
#include "core/systemfactory.h"
#include "core/defs.h"
@ -11,9 +16,12 @@ 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();
QSettings registr_key("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
QSettings::NativeFormat);
bool autostart_enabled = registr_key.value(APP_LOW_NAME,
"").toString().replace('\\',
'/') ==
QtSingleApplication::applicationFilePath();
if (autostart_enabled) {
return SystemFactory::Enabled;
@ -65,30 +73,36 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() {
bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) {
SystemFactory::AutoStartStatus current_status = SystemFactory::getAutoStartStatus();
// Auto-start feature is not even available, exit.
if (current_status == SystemFactory::Unavailable) {
return false;
}
#if defined(Q_OS_WIN)
QSettings registy_key("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
QSettings::NativeFormat);
switch (new_status) {
case SystemFactory::Enabled:
#if defined(Q_OS_WIN)
registy_key.setValue(APP_LOW_NAME,
QtSingleApplication::applicationFilePath().replace('/', '\\'));
return true;
case SystemFactory::Disabled:
registy_key.remove(APP_LOW_NAME);
return true;
default:
return false;
}
#elif defined(Q_OS_LINUX)
switch (new_status) {
case SystemFactory::Enabled:
#else
#endif
break;
case SystemFactory::Disabled:
#if defined(Q_OS_WIN)
#elif defined(Q_OS_LINUX)
#else
#endif
break;
default:
return false;
}
#else
return false;
#endif
}

View File

@ -53,20 +53,16 @@ void FormSettings::loadGeneral() {
}
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('/', '\\'));
// If auto-start feature is available and user wants
// to turn it on, then turn it on.
if (SystemFactory::getAutoStartStatus() != SystemFactory::Unavailable) {
if (m_ui->m_checkAutostart->isChecked()) {
SystemFactory::setAutoStartStatus(SystemFactory::Enabled);
}
else {
SystemFactory::setAutoStartStatus(SystemFactory::Disabled);
}
}
else {
sett.remove(APP_LOW_NAME);
}
// Save auto-start on Linux.
#elif defined(Q_OS_LINUX)
#endif
}
void FormSettings::loadInterface() {