2013-06-27 19:57:23 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QProcess>
|
2013-07-02 18:57:04 +02:00
|
|
|
#include <QNetworkProxy>
|
2013-07-20 21:11:52 +02:00
|
|
|
#include <QColorDialog>
|
2013-06-27 19:57:23 +02:00
|
|
|
|
2013-06-14 22:15:37 +02:00
|
|
|
#include "gui/formsettings.h"
|
2013-08-05 21:31:41 +02:00
|
|
|
#include "gui/iconthemefactory.h"
|
2013-09-20 18:18:49 +02:00
|
|
|
#include "gui/skinfactory.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-07-30 18:54:36 +02:00
|
|
|
#include "gui/webbrowser.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-27 19:57:23 +02:00
|
|
|
#include "core/localization.h"
|
2013-06-24 16:18:13 +02:00
|
|
|
#include "core/systemfactory.h"
|
2013-06-30 15:22:44 +02:00
|
|
|
#include "core/dynamicshortcuts.h"
|
2013-07-18 17:44:23 +02:00
|
|
|
#include "core/webbrowsernetworkaccessmanager.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
|
|
|
|
2013-06-26 19:04:38 +02:00
|
|
|
// Set flags and attributes.
|
2013-06-15 19:48:56 +02:00
|
|
|
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog);
|
2013-08-05 21:31:41 +02:00
|
|
|
setWindowIcon(IconThemeFactory::getInstance()->fromTheme("preferences-system"));
|
2013-06-15 19:48:56 +02:00
|
|
|
|
2013-06-27 19:57:23 +02:00
|
|
|
// Setup behavior.
|
|
|
|
m_ui->m_treeLanguages->setColumnCount(5);
|
|
|
|
m_ui->m_treeLanguages->setHeaderHidden(false);
|
2013-09-25 20:21:32 +02:00
|
|
|
m_ui->m_treeLanguages->setHeaderLabels(QStringList()
|
|
|
|
<< tr("Language")
|
|
|
|
<< tr("Code")
|
|
|
|
<< tr("Version")
|
|
|
|
<< tr("Author")
|
|
|
|
<< tr("Email"));
|
|
|
|
|
|
|
|
m_ui->m_treeSkins->setColumnCount(4);
|
|
|
|
m_ui->m_treeSkins->setHeaderHidden(false);
|
|
|
|
m_ui->m_treeSkins->setHeaderLabels(QStringList()
|
|
|
|
<< tr("Name")
|
|
|
|
<< tr("Version")
|
|
|
|
<< tr("Author")
|
|
|
|
<< tr("Email"));
|
|
|
|
|
2013-08-30 17:40:17 +02:00
|
|
|
#if QT_VERSION >= 0x050000
|
2013-09-20 18:18:49 +02:00
|
|
|
// Setup languages.
|
2013-06-27 19:57:23 +02:00
|
|
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
2013-09-20 18:18:49 +02:00
|
|
|
|
|
|
|
// Setup skins.
|
|
|
|
m_ui->m_treeSkins->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeSkins->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeSkins->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeSkins->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
2013-08-30 17:40:17 +02:00
|
|
|
#else
|
2013-09-20 18:18:49 +02:00
|
|
|
// Setup languages.
|
2013-08-30 17:40:17 +02:00
|
|
|
m_ui->m_treeLanguages->header()->setResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeLanguages->header()->setResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeLanguages->header()->setResizeMode(2, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeLanguages->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeLanguages->header()->setResizeMode(4, QHeaderView::ResizeToContents);
|
2013-09-20 18:18:49 +02:00
|
|
|
|
|
|
|
// Setup skins.
|
|
|
|
m_ui->m_treeSkins->header()->setResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeSkins->header()->setResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeSkins->header()->setResizeMode(2, QHeaderView::ResizeToContents);
|
|
|
|
m_ui->m_treeSkins->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
2013-08-30 17:40:17 +02:00
|
|
|
#endif
|
|
|
|
|
2013-06-15 19:48:56 +02:00
|
|
|
// Establish needed connections.
|
2013-09-20 18:18:49 +02:00
|
|
|
connect(m_ui->m_buttonBox, SIGNAL(accepted()),
|
|
|
|
this, SLOT(saveSettings()));
|
2013-08-30 17:40:17 +02:00
|
|
|
connect(m_ui->m_cmbProxyType, SIGNAL(currentIndexChanged(int)),
|
|
|
|
this, SLOT(onProxyTypeChanged(int)));
|
|
|
|
connect(m_ui->m_checkShowPassword, SIGNAL(stateChanged(int)),
|
|
|
|
this, SLOT(displayProxyPassword(int)));
|
|
|
|
connect(m_ui->m_btnBrowserProgressColor, SIGNAL(clicked()),
|
|
|
|
this, SLOT(changeBrowserProgressColor()));
|
2013-09-22 07:38:42 +02:00
|
|
|
connect(m_ui->m_treeSkins, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
|
|
|
this, SLOT(onSkinSelected(QTreeWidgetItem*,QTreeWidgetItem*)));
|
2013-12-09 16:05:16 +01:00
|
|
|
connect(m_ui->m_cmbExternalBrowserPreset, SIGNAL(currentIndexChanged(int)),
|
|
|
|
this, SLOT(changeDefaultBrowserArguments(int)));
|
2013-06-15 19:48:56 +02:00
|
|
|
|
|
|
|
// Load all settings.
|
2013-06-24 16:18:13 +02:00
|
|
|
loadGeneral();
|
2013-06-30 15:22:44 +02:00
|
|
|
loadShortcuts();
|
2013-06-15 19:48:56 +02:00
|
|
|
loadInterface();
|
2013-07-02 18:57:04 +02:00
|
|
|
loadProxy();
|
2013-07-24 19:06:09 +02:00
|
|
|
loadBrowser();
|
2013-06-27 19:57:23 +02:00
|
|
|
loadLanguage();
|
2013-12-09 16:05:16 +01:00
|
|
|
loadFeedsMessages();
|
2013-06-14 22:15:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FormSettings::~FormSettings() {
|
|
|
|
delete m_ui;
|
|
|
|
}
|
2013-06-15 19:48:56 +02:00
|
|
|
|
2013-12-09 16:05:16 +01:00
|
|
|
void FormSettings::changeDefaultBrowserArguments(int index) {
|
|
|
|
if (index != 0) {
|
|
|
|
m_ui->m_txtExternalBrowserArguments->setText(m_ui->m_cmbExternalBrowserPreset->itemData(index).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-22 07:38:42 +02:00
|
|
|
void FormSettings::onSkinSelected(QTreeWidgetItem *current,
|
|
|
|
QTreeWidgetItem *previous) {
|
|
|
|
Q_UNUSED(previous);
|
|
|
|
|
|
|
|
if (current != NULL) {
|
|
|
|
Skin skin = current->data(0, Qt::UserRole).value<Skin>();
|
|
|
|
m_ui->m_lblSelectedContents->setText(skin.m_visibleName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-20 21:11:52 +02:00
|
|
|
void FormSettings::changeBrowserProgressColor() {
|
|
|
|
QColorDialog color_dialog(m_initialSettings.m_webBrowserProgress, this);
|
|
|
|
color_dialog.setWindowTitle(tr("Select color for web browser progress bar"));
|
|
|
|
color_dialog.setOption(QColorDialog::ShowAlphaChannel);
|
|
|
|
color_dialog.exec();
|
|
|
|
|
|
|
|
m_initialSettings.m_webBrowserProgress = color_dialog.selectedColor();
|
|
|
|
}
|
|
|
|
|
2013-12-09 16:05:16 +01:00
|
|
|
void FormSettings::loadFeedsMessages() {
|
2013-12-10 18:54:55 +01:00
|
|
|
Settings *settings = Settings::getInstance();
|
|
|
|
|
2013-12-09 16:05:16 +01:00
|
|
|
m_ui->m_cmbExternalBrowserPreset->addItem("Chromium", "aa %1");
|
2013-12-10 18:54:55 +01:00
|
|
|
|
|
|
|
m_ui->m_txtExternalBrowserExecutable->setText(settings->value(APP_CFG_MESSAGES,
|
|
|
|
"external_browser_executable").toString());
|
|
|
|
m_ui->m_txtExternalBrowserArguments->setText(settings->value(APP_CFG_MESSAGES,
|
|
|
|
"external_browser_arguments").toString());
|
2013-12-09 16:05:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormSettings::saveFeedsMessages() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-17 20:42:42 +02:00
|
|
|
void FormSettings::displayProxyPassword(int state) {
|
|
|
|
if (state == Qt::Checked) {
|
|
|
|
m_ui->m_txtProxyPassword->setEchoMode(QLineEdit::Normal);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_ui->m_txtProxyPassword->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 18:18:49 +02:00
|
|
|
bool FormSettings::doSaveCheck() {
|
|
|
|
bool everything_ok = true;
|
2013-12-07 20:33:41 +01:00
|
|
|
QStringList resulting_information;
|
|
|
|
QMessageBox msg_error(this);
|
2013-09-20 18:18:49 +02:00
|
|
|
|
2013-12-07 20:33:41 +01:00
|
|
|
// Setup indication of settings consistence.
|
2013-09-20 18:18:49 +02:00
|
|
|
everything_ok &= m_ui->m_shortcuts->areShortcutsUnique();
|
|
|
|
|
|
|
|
if (!m_ui->m_shortcuts->areShortcutsUnique()) {
|
2013-12-07 20:33:41 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
resulting_information.append(tr(" • some keyboard shortcuts are not unique"));
|
|
|
|
#else
|
|
|
|
resulting_information.append(trUtf8(" • some keyboard shortcuts are not unique"));
|
|
|
|
#endif
|
2013-09-20 18:18:49 +02:00
|
|
|
}
|
|
|
|
|
2013-12-07 20:33:41 +01:00
|
|
|
// Setup dialog.
|
|
|
|
msg_error.setText(tr("Some critical settings are not set. You must fix these settings in order confirm new settings."));
|
|
|
|
msg_error.setWindowTitle(tr("Cannot save settings"));
|
|
|
|
msg_error.setDetailedText(tr("List of errors:\n %1.").arg(resulting_information.join(",\n")));
|
|
|
|
msg_error.setIcon(QMessageBox::Critical);
|
|
|
|
msg_error.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msg_error.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
2013-09-20 18:18:49 +02:00
|
|
|
if (!everything_ok) {
|
2013-12-07 20:33:41 +01:00
|
|
|
msg_error.exec();
|
2013-09-20 18:18:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return everything_ok;
|
|
|
|
}
|
|
|
|
|
2013-11-30 22:23:01 +01:00
|
|
|
void FormSettings::promptForRestart() {
|
|
|
|
if (m_changedDataTexts.count() > 0) {
|
|
|
|
QMessageBox msg_question(this);
|
|
|
|
|
|
|
|
msg_question.setText(tr("Some critical settings were changed and will be applied after the application gets restarted."));
|
|
|
|
msg_question.setInformativeText(tr("Do you want to restart now?"));
|
|
|
|
msg_question.setWindowTitle(tr("Critical settings were changed"));
|
|
|
|
msg_question.setDetailedText(tr("List of changes:\n %1.").arg(m_changedDataTexts.join(",\n")));
|
|
|
|
msg_question.setIcon(QMessageBox::Question);
|
|
|
|
msg_question.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
|
|
msg_question.setDefaultButton(QMessageBox::Yes);
|
|
|
|
|
|
|
|
if (msg_question.exec() == QMessageBox::Yes) {
|
|
|
|
if (!QProcess::startDetached(qApp->applicationFilePath())) {
|
|
|
|
QMessageBox::warning(this,
|
|
|
|
tr("Problem with application restart"),
|
|
|
|
tr("Application couldn't be restarted. Please, restart it manually for changes to take effect."));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qApp->quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-15 19:48:56 +02:00
|
|
|
void FormSettings::saveSettings() {
|
2013-09-20 18:18:49 +02:00
|
|
|
// Make sure everything is saveable.
|
|
|
|
if (!doSaveCheck()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-24 16:18:13 +02:00
|
|
|
// Save all settings.
|
|
|
|
saveGeneral();
|
2013-06-30 15:22:44 +02:00
|
|
|
saveShortcuts();
|
2013-06-15 19:48:56 +02:00
|
|
|
saveInterface();
|
2013-07-02 18:57:04 +02:00
|
|
|
saveProxy();
|
2013-07-24 19:06:09 +02:00
|
|
|
saveBrowser();
|
2013-06-27 19:57:23 +02:00
|
|
|
saveLanguage();
|
2013-12-09 16:05:16 +01:00
|
|
|
saveFeedsMessages();
|
2013-06-30 19:02:24 +02:00
|
|
|
|
|
|
|
Settings::getInstance()->checkSettings();
|
2013-11-30 22:23:01 +01:00
|
|
|
promptForRestart();
|
2013-09-20 18:18:49 +02:00
|
|
|
|
|
|
|
accept();
|
2013-06-27 19:57:23 +02:00
|
|
|
}
|
|
|
|
|
2013-07-02 18:57:04 +02:00
|
|
|
void FormSettings::onProxyTypeChanged(int index) {
|
|
|
|
QNetworkProxy::ProxyType selected_type = static_cast<QNetworkProxy::ProxyType>(m_ui->m_cmbProxyType->itemData(index).toInt());
|
|
|
|
bool is_proxy_selected = selected_type != QNetworkProxy::NoProxy;
|
|
|
|
|
2013-07-07 15:17:25 +02:00
|
|
|
m_ui->m_txtProxyHost->setEnabled(is_proxy_selected);
|
|
|
|
m_ui->m_txtProxyPassword->setEnabled(is_proxy_selected);
|
|
|
|
m_ui->m_txtProxyUsername->setEnabled(is_proxy_selected);
|
|
|
|
m_ui->m_spinProxyPort->setEnabled(is_proxy_selected);
|
|
|
|
m_ui->m_checkShowPassword->setEnabled(is_proxy_selected);
|
2013-07-23 20:42:06 +02:00
|
|
|
m_ui->m_lblProxyHost->setEnabled(is_proxy_selected);
|
|
|
|
m_ui->m_lblProxyInfo->setEnabled(is_proxy_selected);
|
|
|
|
m_ui->m_lblProxyPassword->setEnabled(is_proxy_selected);
|
|
|
|
m_ui->m_lblProxyPort->setEnabled(is_proxy_selected);
|
|
|
|
m_ui->m_lblProxyUsername->setEnabled(is_proxy_selected);
|
2013-07-02 18:57:04 +02:00
|
|
|
}
|
|
|
|
|
2013-07-24 19:06:09 +02:00
|
|
|
void FormSettings::loadBrowser() {
|
2013-08-30 17:40:17 +02:00
|
|
|
Settings *settings = Settings::getInstance();
|
|
|
|
|
2013-07-24 19:06:09 +02:00
|
|
|
// Load settings of web browser GUI.
|
2013-08-30 17:40:17 +02:00
|
|
|
m_initialSettings.m_webBrowserProgress = settings->value(APP_CFG_BROWSER,
|
|
|
|
"browser_progress_color",
|
|
|
|
QColor(0, 255, 0, 100)).value<QColor>();
|
|
|
|
m_ui->m_checkBrowserProgressColor->setChecked(settings->value(APP_CFG_BROWSER,
|
|
|
|
"browser_colored_progress_enabled",
|
|
|
|
true).toBool());
|
|
|
|
m_ui->m_checkMouseGestures->setChecked(settings->value(APP_CFG_BROWSER,
|
|
|
|
"gestures_enabled",
|
|
|
|
true).toBool());
|
|
|
|
m_ui->m_checkQueueTabs->setChecked(settings->value(APP_CFG_BROWSER,
|
|
|
|
"queue_tabs",
|
|
|
|
true).toBool());
|
2013-07-24 19:06:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormSettings::saveBrowser() {
|
2013-08-30 17:40:17 +02:00
|
|
|
Settings *settings = Settings::getInstance();
|
|
|
|
|
2013-07-24 19:06:09 +02:00
|
|
|
// Save settings of GUI of web browser.
|
2013-08-30 17:40:17 +02:00
|
|
|
settings->setValue(APP_CFG_BROWSER,
|
|
|
|
"browser_progress_color",
|
|
|
|
m_initialSettings.m_webBrowserProgress);
|
|
|
|
settings->setValue(APP_CFG_BROWSER,
|
|
|
|
"browser_colored_progress_enabled",
|
|
|
|
m_ui->m_checkBrowserProgressColor->isChecked());
|
|
|
|
settings->setValue(APP_CFG_BROWSER,
|
|
|
|
"gestures_enabled",
|
|
|
|
m_ui->m_checkMouseGestures->isChecked());
|
|
|
|
settings->setValue(APP_CFG_BROWSER,
|
|
|
|
"queue_tabs",
|
|
|
|
m_ui->m_checkQueueTabs->isChecked());
|
2013-07-24 19:06:09 +02:00
|
|
|
}
|
|
|
|
|
2013-07-02 18:57:04 +02:00
|
|
|
void FormSettings::loadProxy() {
|
|
|
|
m_ui->m_cmbProxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy);
|
|
|
|
m_ui->m_cmbProxyType->addItem(tr("Socks5"), QNetworkProxy::Socks5Proxy);
|
|
|
|
m_ui->m_cmbProxyType->addItem(tr("Http"), QNetworkProxy::HttpProxy);
|
2013-07-17 20:42:42 +02:00
|
|
|
|
|
|
|
// Load the settings.
|
|
|
|
QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(Settings::getInstance()->value(APP_CFG_PROXY,
|
|
|
|
"proxy_type",
|
|
|
|
QNetworkProxy::NoProxy).toInt());
|
2013-08-30 17:40:17 +02:00
|
|
|
Settings *settings = Settings::getInstance();
|
|
|
|
|
2013-07-17 20:42:42 +02:00
|
|
|
m_ui->m_cmbProxyType->setCurrentIndex(m_ui->m_cmbProxyType->findData(selected_proxy_type));
|
2013-08-30 17:40:17 +02:00
|
|
|
m_ui->m_txtProxyHost->setText(settings->value(APP_CFG_PROXY,
|
|
|
|
"host").toString());
|
|
|
|
m_ui->m_txtProxyUsername->setText(settings->value(APP_CFG_PROXY,
|
|
|
|
"username").toString());
|
|
|
|
m_ui->m_txtProxyPassword->setText(settings->value(APP_CFG_PROXY,
|
|
|
|
"password").toString());
|
|
|
|
m_ui->m_spinProxyPort->setValue(settings->value(APP_CFG_PROXY,
|
|
|
|
"port", 80).toInt());
|
2013-07-02 18:57:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormSettings::saveProxy() {
|
2013-08-30 17:40:17 +02:00
|
|
|
Settings *settings = Settings::getInstance();
|
|
|
|
|
|
|
|
settings->setValue(APP_CFG_PROXY, "proxy_type",
|
|
|
|
m_ui->m_cmbProxyType->itemData(m_ui->m_cmbProxyType->currentIndex()));
|
|
|
|
settings->setValue(APP_CFG_PROXY, "host",
|
|
|
|
m_ui->m_txtProxyHost->text());
|
|
|
|
settings->setValue(APP_CFG_PROXY, "username",
|
|
|
|
m_ui->m_txtProxyUsername->text());
|
|
|
|
settings->setValue(APP_CFG_PROXY, "password",
|
|
|
|
m_ui->m_txtProxyPassword->text());
|
|
|
|
settings->setValue(APP_CFG_PROXY, "port",
|
|
|
|
m_ui->m_spinProxyPort->value());
|
2013-07-18 17:44:23 +02:00
|
|
|
|
|
|
|
// Reload settings for all network access managers.
|
|
|
|
WebBrowser::globalNetworkManager()->loadSettings();
|
2013-07-02 18:57:04 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 19:57:23 +02:00
|
|
|
void FormSettings::loadLanguage() {
|
|
|
|
QList<Language> languages = Localization::getInstalledLanguages();
|
|
|
|
|
2013-12-03 18:38:43 +01:00
|
|
|
foreach (const Language &language, languages) {
|
2013-06-27 19:57:23 +02:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui->m_treeLanguages);
|
2013-12-03 18:38:43 +01:00
|
|
|
item->setText(0, language.m_name);
|
|
|
|
item->setText(1, language.m_code);
|
|
|
|
item->setText(2, language.m_version);
|
|
|
|
item->setText(3, language.m_author);
|
|
|
|
item->setText(4, language.m_email);
|
|
|
|
item->setIcon(0, QIcon(APP_FLAGS_PATH + "/" + language.m_code + ".png"));
|
2013-06-27 19:57:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem*> matching_items = m_ui->m_treeLanguages->findItems(Settings::getInstance()->value(APP_CFG_GEN,
|
|
|
|
"language",
|
|
|
|
"en").toString(),
|
|
|
|
Qt::MatchExactly,
|
|
|
|
1);
|
|
|
|
if (!matching_items.isEmpty()) {
|
|
|
|
m_ui->m_treeLanguages->setCurrentItem(matching_items[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormSettings::saveLanguage() {
|
2013-08-30 17:40:17 +02:00
|
|
|
if (m_ui->m_treeLanguages->currentItem() == NULL) {
|
2013-06-29 15:48:15 +02:00
|
|
|
qDebug("No localizations loaded in settings dialog, so no saving for them.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-30 17:40:17 +02:00
|
|
|
Settings *settings = Settings::getInstance();
|
|
|
|
QString actual_lang = settings->value(APP_CFG_GEN,
|
|
|
|
"language",
|
|
|
|
"en").toString();
|
2013-06-27 19:57:23 +02:00
|
|
|
QString new_lang = m_ui->m_treeLanguages->currentItem()->text(1);
|
|
|
|
|
2013-12-06 15:12:30 +01:00
|
|
|
// Save prompt for restart if language has changed.
|
2013-06-27 19:57:23 +02:00
|
|
|
if (new_lang != actual_lang) {
|
2013-12-03 18:38:43 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
m_changedDataTexts.append(tr(" • language changed"));
|
|
|
|
#else
|
|
|
|
m_changedDataTexts.append(trUtf8(" • language changed"));
|
|
|
|
#endif
|
2013-08-30 17:40:17 +02:00
|
|
|
settings->setValue(APP_CFG_GEN, "language", new_lang);
|
2013-06-27 19:57:23 +02:00
|
|
|
}
|
2013-06-15 19:48:56 +02:00
|
|
|
}
|
|
|
|
|
2013-06-30 15:22:44 +02:00
|
|
|
void FormSettings::loadShortcuts() {
|
|
|
|
m_ui->m_shortcuts->populate(FormMain::getInstance()->getActions());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormSettings::saveShortcuts() {
|
|
|
|
// Update the actual shortcuts of some actions.
|
|
|
|
m_ui->m_shortcuts->updateShortcuts();
|
|
|
|
|
|
|
|
// Save new shortcuts to the settings.
|
|
|
|
DynamicShortcuts::save(FormMain::getInstance()->getActions());
|
|
|
|
}
|
|
|
|
|
2013-06-24 16:18:13 +02:00
|
|
|
void FormSettings::loadGeneral() {
|
|
|
|
// Load auto-start status.
|
|
|
|
SystemFactory::AutoStartStatus autostart_status = SystemFactory::getAutoStartStatus();
|
|
|
|
switch (autostart_status) {
|
2013-12-09 16:05:16 +01:00
|
|
|
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;
|
2013-06-24 16:18:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-30 17:40:17 +02:00
|
|
|
Settings *settings = Settings::getInstance();
|
|
|
|
|
2013-06-17 20:17:13 +02:00
|
|
|
// Load settings of tray icon.
|
|
|
|
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
2013-08-30 17:40:17 +02:00
|
|
|
m_ui->m_radioTrayOff->setChecked(!settings->value(APP_CFG_GUI,
|
|
|
|
"use_tray_icon",
|
|
|
|
true).toBool());
|
|
|
|
m_ui->m_cmbTrayClose->setCurrentIndex(settings->value(APP_CFG_GUI,
|
|
|
|
"close_win_action",
|
|
|
|
0).toInt());
|
|
|
|
m_ui->m_checkHidden->setChecked(settings->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 {
|
2013-07-30 18:54:36 +02:00
|
|
|
m_ui->m_radioTrayOff->setText(tr("Disable (Tray icon is not available.)"));
|
2013-06-17 20:17:13 +02:00
|
|
|
m_ui->m_radioTrayOff->setChecked(true);
|
|
|
|
m_ui->m_grpTray->setDisabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load settings of icon theme.
|
2013-08-05 21:31:41 +02:00
|
|
|
QString current_theme = IconThemeFactory::getInstance()->getCurrentIconTheme();
|
2013-06-15 19:48:56 +02:00
|
|
|
|
2013-12-03 18:38:43 +01:00
|
|
|
foreach (const QString &icon_theme_name, IconThemeFactory::getInstance()->getInstalledIconThemes()) {
|
2013-12-10 08:03:30 +01:00
|
|
|
if (icon_theme_name == APP_NO_THEME) {
|
2013-12-08 14:02:28 +01:00
|
|
|
// Add just "no theme" on other systems.
|
2013-08-03 07:34:41 +02:00
|
|
|
m_ui->m_cmbIconTheme->addItem(tr("no icon theme"),
|
2013-12-10 08:03:30 +01:00
|
|
|
APP_NO_THEME);
|
2013-06-15 19:48:56 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_ui->m_cmbIconTheme->addItem(icon_theme_name,
|
|
|
|
icon_theme_name);
|
|
|
|
}
|
2013-08-03 07:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark active theme.
|
2013-12-10 08:03:30 +01:00
|
|
|
if (current_theme == APP_NO_THEME) {
|
|
|
|
// Because "no icon theme" lies at the index 0.
|
2013-08-03 07:34:41 +02:00
|
|
|
m_ui->m_cmbIconTheme->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
else {
|
2013-08-30 17:40:17 +02:00
|
|
|
#if QT_VERSION >= 0x050000
|
2013-08-03 07:34:41 +02:00
|
|
|
m_ui->m_cmbIconTheme->setCurrentText(current_theme);
|
2013-08-30 17:40:17 +02:00
|
|
|
#else
|
|
|
|
int theme_index = m_ui->m_cmbIconTheme->findText(current_theme);
|
|
|
|
if (theme_index >= 0) {
|
|
|
|
m_ui->m_cmbIconTheme->setCurrentIndex(theme_index);
|
|
|
|
}
|
|
|
|
#endif
|
2013-09-22 07:38:42 +02:00
|
|
|
}
|
2013-09-20 18:18:49 +02:00
|
|
|
|
2013-09-22 07:38:42 +02:00
|
|
|
// Load skin.
|
|
|
|
QList<Skin> installed_skins = SkinFactory::getInstance()->getInstalledSkins();
|
|
|
|
QString selected_skin = SkinFactory::getInstance()->getSelectedSkinName();
|
2013-09-20 18:18:49 +02:00
|
|
|
|
2013-12-03 18:38:43 +01:00
|
|
|
foreach (const Skin &skin, installed_skins) {
|
2013-09-22 07:38:42 +02:00
|
|
|
QTreeWidgetItem *new_item = new QTreeWidgetItem(QStringList() <<
|
|
|
|
skin.m_visibleName <<
|
|
|
|
skin.m_version <<
|
|
|
|
skin.m_author <<
|
|
|
|
skin.m_email);
|
|
|
|
new_item->setData(0, Qt::UserRole, QVariant::fromValue(skin));
|
2013-09-20 18:18:49 +02:00
|
|
|
|
2013-09-22 07:38:42 +02:00
|
|
|
// Add this skin and mark it as active if its active now.
|
|
|
|
m_ui->m_treeSkins->addTopLevelItem(new_item);
|
2013-09-20 18:18:49 +02:00
|
|
|
|
2013-09-22 07:38:42 +02:00
|
|
|
if (skin.m_baseName == selected_skin) {
|
|
|
|
m_ui->m_treeSkins->setCurrentItem(new_item);
|
2013-11-15 11:03:12 +01:00
|
|
|
m_ui->m_lblActiveContents->setText(skin.m_visibleName);
|
2013-09-20 18:18:49 +02:00
|
|
|
}
|
2013-06-15 19:48:56 +02:00
|
|
|
}
|
2013-07-30 18:54:36 +02:00
|
|
|
|
2013-11-15 11:03:12 +01:00
|
|
|
if (m_ui->m_treeSkins->currentItem() == NULL &&
|
|
|
|
m_ui->m_treeSkins->topLevelItemCount() > 0) {
|
|
|
|
// Currently active skin is NOT available, select another one as selected
|
|
|
|
// if possible.
|
2013-09-22 07:38:42 +02:00
|
|
|
m_ui->m_treeSkins->setCurrentItem(m_ui->m_treeSkins->topLevelItem(0));
|
|
|
|
}
|
|
|
|
|
2013-07-30 18:54:36 +02:00
|
|
|
// Load tab settings.
|
2013-08-30 17:40:17 +02:00
|
|
|
m_ui->m_checkCloseTabsMiddleClick->setChecked(settings->value(APP_CFG_GUI,
|
|
|
|
"tab_close_mid_button",
|
|
|
|
true).toBool());
|
|
|
|
m_ui->m_checkCloseTabsDoubleClick->setChecked(settings->value(APP_CFG_GUI,
|
|
|
|
"tab_close_double_button",
|
|
|
|
true).toBool());
|
|
|
|
m_ui->m_checkNewTabDoubleClick->setChecked(settings->value(APP_CFG_GUI,
|
|
|
|
"tab_new_double_button",
|
|
|
|
true).toBool());
|
2013-11-09 08:48:13 +01:00
|
|
|
m_ui->m_hideTabBarIfOneTabVisible->setChecked(settings->value(APP_CFG_GUI,
|
|
|
|
"hide_tabbar_one_tab",
|
|
|
|
true).toBool());
|
2013-06-15 19:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormSettings::saveInterface() {
|
2013-08-30 17:40:17 +02:00
|
|
|
Settings *settings = Settings::getInstance();
|
|
|
|
|
2013-06-17 20:17:13 +02:00
|
|
|
// Save tray icon.
|
|
|
|
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
2013-08-30 17:40:17 +02:00
|
|
|
settings->setValue(APP_CFG_GUI, "use_tray_icon",
|
|
|
|
m_ui->m_radioTrayOn->isChecked());
|
|
|
|
settings->setValue(APP_CFG_GUI, "close_win_action",
|
|
|
|
m_ui->m_cmbTrayClose->currentIndex());
|
|
|
|
settings->setValue(APP_CFG_GUI, "start_hidden",
|
|
|
|
m_ui->m_checkHidden->isChecked());
|
|
|
|
if (settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) {
|
2013-06-19 15:48:33 +02:00
|
|
|
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.
|
2013-07-30 18:54:36 +02:00
|
|
|
QString selected_icon_theme = m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString();
|
2013-12-06 15:12:30 +01:00
|
|
|
QString original_icon_theme = IconThemeFactory::getInstance()->getCurrentIconTheme();
|
2013-08-05 21:31:41 +02:00
|
|
|
IconThemeFactory::getInstance()->setCurrentIconTheme(selected_icon_theme);
|
2013-07-30 18:54:36 +02:00
|
|
|
|
2013-12-07 20:33:41 +01:00
|
|
|
// Check if icon theme was changed.
|
2013-12-06 15:12:30 +01:00
|
|
|
if (selected_icon_theme != original_icon_theme) {
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
m_changedDataTexts.append(tr(" • icon theme changed"));
|
|
|
|
#else
|
|
|
|
m_changedDataTexts.append(trUtf8(" • icon theme changed"));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-20 18:18:49 +02:00
|
|
|
// Save and activate new skin.
|
2013-11-15 22:09:38 +01:00
|
|
|
if (m_ui->m_treeSkins->selectedItems().size() > 0) {
|
|
|
|
Skin active_skin = m_ui->m_treeSkins->currentItem()->data(0, Qt::UserRole).value<Skin>();
|
2013-12-03 18:38:43 +01:00
|
|
|
|
|
|
|
if (SkinFactory::getInstance()->getSelectedSkinName() != active_skin.m_baseName) {
|
|
|
|
SkinFactory::getInstance()->setCurrentSkinName(active_skin.m_baseName);
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
m_changedDataTexts.append(tr(" • skin changed"));
|
|
|
|
#else
|
|
|
|
m_changedDataTexts.append(trUtf8(" • skin changed"));
|
|
|
|
#endif
|
|
|
|
}
|
2013-11-15 22:09:38 +01:00
|
|
|
}
|
2013-09-20 18:18:49 +02:00
|
|
|
|
2013-07-30 18:54:36 +02:00
|
|
|
// Save tab settings.
|
2013-08-30 17:40:17 +02:00
|
|
|
settings->setValue(APP_CFG_GUI, "tab_close_mid_button",
|
|
|
|
m_ui->m_checkCloseTabsMiddleClick->isChecked());
|
|
|
|
settings->setValue(APP_CFG_GUI, "tab_close_double_button",
|
|
|
|
m_ui->m_checkCloseTabsDoubleClick->isChecked());
|
|
|
|
settings->setValue(APP_CFG_GUI, "tab_new_double_button",
|
|
|
|
m_ui->m_checkNewTabDoubleClick->isChecked());
|
2013-11-09 08:48:13 +01:00
|
|
|
settings->setValue(APP_CFG_GUI, "hide_tabbar_one_tab",
|
|
|
|
m_ui->m_hideTabBarIfOneTabVisible->isChecked());
|
2013-06-15 19:48:56 +02:00
|
|
|
}
|