2013-06-14 22:15:37 +02:00
|
|
|
#include "gui/formsettings.h"
|
2013-06-15 19:48:56 +02:00
|
|
|
#include "gui/themefactory.h"
|
2013-06-17 20:17:13 +02:00
|
|
|
#include "gui/systemtrayicon.h"
|
2013-06-20 18:16:23 +02:00
|
|
|
#include "gui/formmain.h"
|
2013-06-15 19:48:56 +02:00
|
|
|
#include "core/settings.h"
|
2013-06-17 20:17:13 +02:00
|
|
|
#include "core/defs.h"
|
2013-06-24 16:18:13 +02:00
|
|
|
#include "core/systemfactory.h"
|
2013-06-14 22:15:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormSettings) {
|
|
|
|
m_ui->setupUi(this);
|
2013-06-15 19:48:56 +02:00
|
|
|
|
|
|
|
// Set flags.
|
|
|
|
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog);
|
|
|
|
|
|
|
|
// Establish needed connections.
|
|
|
|
connect(this, &FormSettings::accepted, this, &FormSettings::saveSettings);
|
|
|
|
|
|
|
|
// Load all settings.
|
2013-06-24 16:18:13 +02:00
|
|
|
loadGeneral();
|
2013-06-15 19:48:56 +02:00
|
|
|
loadInterface();
|
2013-06-14 22:15:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FormSettings::~FormSettings() {
|
|
|
|
delete m_ui;
|
|
|
|
}
|
2013-06-15 19:48:56 +02:00
|
|
|
|
|
|
|
void FormSettings::saveSettings() {
|
2013-06-24 16:18:13 +02:00
|
|
|
// Save all settings.
|
|
|
|
saveGeneral();
|
2013-06-15 19:48:56 +02:00
|
|
|
saveInterface();
|
|
|
|
|
|
|
|
// Make sure that settings is synced.
|
2013-06-17 20:17:13 +02:00
|
|
|
Settings::getInstance()->checkSettings();
|
2013-06-15 19:48:56 +02:00
|
|
|
}
|
|
|
|
|
2013-06-24 16:18:13 +02:00
|
|
|
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() {
|
2013-06-24 18:40:13 +02:00
|
|
|
// 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);
|
|
|
|
}
|
2013-06-24 16:18:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-15 19:48:56 +02:00
|
|
|
void FormSettings::loadInterface() {
|
2013-06-17 20:17:13 +02:00
|
|
|
// Load settings of tray icon.
|
|
|
|
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
|
|
|
m_ui->m_radioTrayOff->setChecked(!Settings::getInstance()->value(APP_CFG_GUI,
|
|
|
|
"use_tray_icon",
|
|
|
|
true).toBool());
|
|
|
|
m_ui->m_cmbTrayClose->setCurrentIndex(Settings::getInstance()->value(APP_CFG_GUI,
|
|
|
|
"close_win_action",
|
|
|
|
0).toInt());
|
2013-06-23 18:40:21 +02:00
|
|
|
m_ui->m_checkHidden->setChecked(Settings::getInstance()->value(APP_CFG_GUI,
|
|
|
|
"start_hidden",
|
|
|
|
false).toBool());
|
2013-06-17 20:17:13 +02:00
|
|
|
}
|
2013-06-19 21:28:26 +02:00
|
|
|
// Tray icon is not supported on this machine.
|
2013-06-17 20:17:13 +02:00
|
|
|
else {
|
|
|
|
m_ui->m_radioTrayOff->setText(tr("disable (Tray icon is not available.)"));
|
|
|
|
m_ui->m_radioTrayOff->setChecked(true);
|
|
|
|
m_ui->m_grpTray->setDisabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load settings of icon theme.
|
2013-06-15 19:48:56 +02:00
|
|
|
QString current_theme = ThemeFactory::getCurrentIconTheme();
|
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
QString system_theme = ThemeFactory::getSystemIconTheme();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foreach (QString icon_theme_name, ThemeFactory::getInstalledIconThemes()) {
|
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
if (icon_theme_name == system_theme) {
|
|
|
|
m_ui->m_cmbIconTheme->addItem(tr("system icon theme (default)"),
|
|
|
|
icon_theme_name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif
|
|
|
|
m_ui->m_cmbIconTheme->addItem(icon_theme_name,
|
|
|
|
icon_theme_name);
|
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
}
|
|
|
|
if (current_theme == system_theme) {
|
|
|
|
// Because system icon theme lies at the index 0.
|
|
|
|
// See ThemeFactory::getInstalledIconThemes() for more info.
|
|
|
|
m_ui->m_cmbIconTheme->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif
|
|
|
|
// TODO: Display correct theme on linux.
|
|
|
|
m_ui->m_cmbIconTheme->setCurrentText(current_theme);
|
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormSettings::saveInterface() {
|
2013-06-17 20:17:13 +02:00
|
|
|
// Save tray icon.
|
|
|
|
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
|
|
|
Settings::getInstance()->setValue(APP_CFG_GUI, "use_tray_icon",
|
|
|
|
m_ui->m_radioTrayOn->isChecked());
|
|
|
|
Settings::getInstance()->setValue(APP_CFG_GUI, "close_win_action",
|
|
|
|
m_ui->m_cmbTrayClose->currentIndex());
|
2013-06-23 18:40:21 +02:00
|
|
|
Settings::getInstance()->setValue(APP_CFG_GUI, "start_hidden",
|
|
|
|
m_ui->m_checkHidden->isChecked());
|
2013-06-19 15:48:33 +02:00
|
|
|
if (Settings::getInstance()->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) {
|
|
|
|
SystemTrayIcon::getInstance()->show();
|
|
|
|
}
|
|
|
|
else {
|
2013-06-20 18:16:23 +02:00
|
|
|
FormMain::getInstance()->display();
|
2013-06-19 15:48:33 +02:00
|
|
|
SystemTrayIcon::deleteInstance();
|
|
|
|
}
|
2013-06-17 20:17:13 +02:00
|
|
|
}
|
|
|
|
|
2013-06-15 19:48:56 +02:00
|
|
|
// Save selected icon theme.
|
|
|
|
ThemeFactory::setCurrentIconTheme(m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString());
|
|
|
|
}
|