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-15 19:48:56 +02:00
|
|
|
#include "core/settings.h"
|
2013-06-17 20:17:13 +02:00
|
|
|
#include "core/defs.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.
|
|
|
|
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() {
|
|
|
|
// Save all categories.
|
|
|
|
//saveGeneral();
|
|
|
|
saveInterface();
|
|
|
|
//saveLanguages();
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
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-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());
|
|
|
|
// TODO: Switch tray icon here (destroy it/create it) and
|
|
|
|
// if icon is should be destroyed and no main window is visible,
|
|
|
|
// then show main window and then destroy tray icon.
|
2013-06-19 15:48:33 +02:00
|
|
|
if (Settings::getInstance()->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) {
|
|
|
|
SystemTrayIcon::getInstance()->show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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());
|
|
|
|
}
|