31 #include "gui/formsettings.h"
33 #include "definitions/definitions.h"
34 #include "miscellaneous/settings.h"
35 #include "miscellaneous/localization.h"
36 #include "miscellaneous/systemfactory.h"
37 #include "miscellaneous/iconfactory.h"
38 #include "network-web/webfactory.h"
39 #include "network-web/silentnetworkaccessmanager.h"
40 #include "gui/systemtrayicon.h"
41 #include "gui/formmain.h"
42 #include "gui/custommessagebox.h"
43 #include "miscellaneous/application.h"
44 #include "miscellaneous/skinfactory.h"
45 #include "dynamic-shortcuts/dynamicshortcutswidget.h"
46 #include "dynamic-shortcuts/dynamicshortcuts.h"
47 #include "core/templatefactory.h"
50 #include <QNetworkProxy>
51 #include <QColorDialog>
52 #include <QFileDialog>
60 setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
64 m_ui->m_listSettings->setCurrentRow(0);
65 m_ui->m_treeLanguages->setColumnCount(4);
66 m_ui->m_treeLanguages->setHeaderHidden(
false);
67 m_ui->m_treeLanguages->setHeaderLabels(QStringList()
73 m_ui->m_treeSkins->setColumnCount(4);
74 m_ui->m_treeSkins->setHeaderHidden(
false);
75 m_ui->m_treeSkins->setHeaderLabels(QStringList()
81 #if QT_VERSION >= 0x050000
83 m_ui->m_treeLanguages->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
84 m_ui->m_treeLanguages->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
85 m_ui->m_treeLanguages->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
86 m_ui->m_treeLanguages->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
89 m_ui->m_treeSkins->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
90 m_ui->m_treeSkins->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
91 m_ui->m_treeSkins->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
92 m_ui->m_treeSkins->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
95 m_ui->m_treeLanguages->header()->setResizeMode(0, QHeaderView::ResizeToContents);
96 m_ui->m_treeLanguages->header()->setResizeMode(1, QHeaderView::ResizeToContents);
97 m_ui->m_treeLanguages->header()->setResizeMode(2, QHeaderView::ResizeToContents);
98 m_ui->m_treeLanguages->header()->setResizeMode(3, QHeaderView::ResizeToContents);
101 m_ui->m_treeSkins->header()->setResizeMode(0, QHeaderView::ResizeToContents);
102 m_ui->m_treeSkins->header()->setResizeMode(1, QHeaderView::ResizeToContents);
103 m_ui->m_treeSkins->header()->setResizeMode(2, QHeaderView::ResizeToContents);
104 m_ui->m_treeSkins->header()->setResizeMode(3, QHeaderView::ResizeToContents);
112 loadExternalUtilites();
118 loadGenerationStuff();
121 FormSettings::~FormSettings() {
122 qDebug(
"Destroying FormSettings distance.");
126 void FormSettings::changeDefaultBrowserArguments(
int index) {
128 m_ui->m_txtExternalBrowserArguments->setText(m_ui->m_cmbExternalBrowserPreset->itemData(index).toString());
132 void FormSettings::createConnections() {
133 connect(m_ui->m_buttonBox, SIGNAL(accepted()),
this, SLOT(saveSettings()));
134 connect(m_ui->m_cmbProxyType, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onProxyTypeChanged(
int)));
135 connect(m_ui->m_checkShowPassword, SIGNAL(stateChanged(
int)),
this, SLOT(displayProxyPassword(
int)));
136 connect(m_ui->m_cmbExternalBrowserPreset, SIGNAL(currentIndexChanged(
int)),
this, SLOT(changeDefaultBrowserArguments(
int)));
137 connect(m_ui->m_btnExternalBrowserExecutable, SIGNAL(clicked()),
this, SLOT(selectBrowserExecutable()));
138 connect(m_ui->m_btnSelectZip, SIGNAL(clicked()),
this, SLOT(selectZip()));
139 connect(m_ui->m_btnSelectJava, SIGNAL(clicked()),
this, SLOT(selectJava()));
140 connect(m_ui->m_btnSelectSignapk, SIGNAL(clicked()),
this, SLOT(selectSignApk()));
141 connect(m_ui->m_btnGenerationOutputSelect, SIGNAL(clicked()),
this, SLOT(selectOutputDirectory()));
142 connect(m_ui->m_btnGenerationTempSelect, SIGNAL(clicked()),
this, SLOT(selectTempDirectory()));
143 connect(m_ui->m_treeSkins, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
144 this, SLOT(onSkinSelected(QTreeWidgetItem*,QTreeWidgetItem*)));
147 void FormSettings::onSkinSelected(QTreeWidgetItem *current,
148 QTreeWidgetItem *previous) {
151 if (current != NULL) {
152 Skin skin = current->data(0, Qt::UserRole).value<
Skin>();
153 m_ui->m_lblSelectedContents->setText(skin.m_visibleName);
157 void FormSettings::selectBrowserExecutable() {
158 QString executable_file = QFileDialog::getOpenFileName(
this,
159 tr(
"Select web browser executable"),
162 tr(
"Executables (*.*)"));
164 if (!executable_file.isEmpty()) {
165 m_ui->m_txtExternalBrowserExecutable->setText(QDir::toNativeSeparators(executable_file));
169 void FormSettings::displayProxyPassword(
int state) {
170 if (state == Qt::Checked) {
171 m_ui->m_txtProxyPassword->setEchoMode(QLineEdit::Normal);
174 m_ui->m_txtProxyPassword->setEchoMode(QLineEdit::Password);
178 bool FormSettings::doSaveCheck() {
179 bool everything_ok =
true;
180 QStringList resulting_information;
183 if (!m_ui->m_shortcutsEditor->areShortcutsUnique()) {
184 everything_ok =
false;
185 resulting_information.append(tr(
"some keyboard shortcuts are not unique"));
190 if (m_ui->m_grpCustomExternalBrowser->isChecked() &&
191 (m_ui->m_txtExternalBrowserExecutable->text().simplified().isEmpty() ||
192 !m_ui->m_txtExternalBrowserArguments->text().simplified().contains(
"%1"))) {
193 everything_ok =
false;
194 resulting_information.append(tr(
"custom external browser is not set correctly"));
197 if (!everything_ok) {
198 resulting_information.replaceInStrings(QRegExp(
"^"),
199 QString::fromUtf8(
" • "));
202 QMessageBox::Critical,
203 tr(
"Cannot save settings"),
204 tr(
"Some critical settings are not set. You must fix these settings in order confirm new settings."),
206 tr(
"List of errors:\n%1.").arg(resulting_information.join(
",\n")));
209 return everything_ok;
212 void FormSettings::promptForRestart() {
213 if (m_changedDataTexts.count() > 0) {
214 QStringList changed_data_texts = m_changedDataTexts;
216 changed_data_texts.replaceInStrings(QRegExp(
"^"),
217 QString::fromUtf8(
" • "));
220 QMessageBox::Question,
221 tr(
"Critical settings were changed"),
222 tr(
"Some critical settings were changed and will be applied after the application gets restarted."),
223 tr(
"Do you want to restart now?"),
224 tr(
"List of changes:\n%1.").arg(changed_data_texts.join(
",\n")),
225 QMessageBox::Yes | QMessageBox::No,
228 if (question_result == QMessageBox::Yes) {
229 if (!QProcess::startDetached(qApp->applicationFilePath())) {
231 qApp->trayIcon()->showMessage(tr(
"Problem with application restart"),
232 tr(
"Application couldn't be restarted. "
233 "Please, restart it manually for changes to take effect."),
234 QSystemTrayIcon::Warning);
238 QMessageBox::Warning,
239 tr(
"Problem with application restart"),
240 tr(
"Application couldn't be restarted. "
241 "Please, restart it manually for changes to take effect."));
251 void FormSettings::saveSettings() {
253 if (!doSaveCheck()) {
259 saveExternalUtilites();
265 saveGenerationStuff();
267 qApp->settings()->checkSettings();
273 void FormSettings::loadGeneral() {
274 m_ui->m_checkCheckForUpdatesOnStartup->setChecked(qApp->settings()->value(APP_CFG_GEN,
275 "check_for_updates_startup",
279 void FormSettings::saveGeneral() {
280 qApp->settings()->setValue(APP_CFG_GEN,
281 "check_for_updates_startup",
282 m_ui->m_checkCheckForUpdatesOnStartup->isChecked());
285 void FormSettings::loadExternalUtilites() {
286 checkZip(QDir::toNativeSeparators(qApp->zipUtilityPath()));
287 checkJava(QDir::toNativeSeparators(qApp->javaInterpreterPath()));
288 checkSignApk(QDir::toNativeSeparators(qApp->signApkUtlityPath()));
291 void FormSettings::saveExternalUtilites() {
292 qApp->setZipUtilityPath(m_ui->m_lblExternalZip->label()->text());
293 qApp->setJavaInterpreterPath(m_ui->m_lblExternalJava->label()->text());
294 qApp->setSignApkUtilityPath(m_ui->m_lblExternalSignapk->label()->text());
295 qApp->recheckExternalApplications(
true);
298 void FormSettings::checkZip(
const QString &new_path) {
299 int zip_output = qApp->checkZip(new_path);
300 QString textual_info = qApp->interpretZip(zip_output);
302 switch (zip_output) {
303 case EXIT_STATUS_NOT_STARTED:
304 m_ui->m_lblExternalZip->setStatus(WidgetWithStatus::Error,
309 case EXIT_STATUS_ZIP_NORMAL:
310 m_ui->m_lblExternalZip->setStatus(WidgetWithStatus::Ok,
315 case EXIT_STATUS_CRASH:
317 m_ui->m_lblExternalZip->setStatus(WidgetWithStatus::Warning,
324 void FormSettings::checkJava(
const QString &new_path) {
325 int java_output = qApp->checkJava(new_path);
326 QString textual_info = qApp->interpretJava(java_output);
328 switch (java_output) {
329 case EXIT_STATUS_NOT_STARTED:
330 m_ui->m_lblExternalJava->setStatus(WidgetWithStatus::Error,
335 case EXIT_STATUS_JAVA_NORMAL:
336 m_ui->m_lblExternalJava->setStatus(WidgetWithStatus::Ok,
341 case EXIT_STATUS_CRASH:
343 m_ui->m_lblExternalJava->setStatus(WidgetWithStatus::Warning,
350 void FormSettings::checkSignApk(
const QString &new_path) {
351 int signapk_output = qApp->checkSignApk(new_path, m_ui->m_lblExternalJava->label()->text());
352 QString textual_info = qApp->interpretSignApk(signapk_output);
354 switch (signapk_output) {
355 case EXIT_STATUS_SIGNAPK_NOT_FOUND:
356 case EXIT_STATUS_NOT_STARTED:
357 m_ui->m_lblExternalSignapk->setStatus(WidgetWithStatus::Error,
362 case EXIT_STATUS_SIGNAPK_NORMAL:
363 m_ui->m_lblExternalSignapk->setStatus(WidgetWithStatus::Ok,
368 case EXIT_STATUS_CRASH:
369 case EXIT_STATUS_SIGNAPK_WORKING:
371 m_ui->m_lblExternalSignapk->setStatus(WidgetWithStatus::Warning,
378 void FormSettings::selectJava() {
379 QString executable_file = QFileDialog::getOpenFileName(
this,
380 tr(
"Select JAVA executable"),
381 m_ui->m_lblExternalJava->label()->text(),
383 tr(
"Executables (java*)"),
386 if (!executable_file.isEmpty()) {
387 checkJava(QDir::toNativeSeparators(executable_file));
388 checkSignApk(m_ui->m_lblExternalSignapk->label()->text());
392 void FormSettings::selectZip() {
393 QString executable_file = QFileDialog::getOpenFileName(
this,
394 tr(
"Select ZIP executable"),
395 m_ui->m_lblExternalZip->label()->text(),
397 tr(
"Executables (zip*)"),
400 if (!executable_file.isEmpty()) {
401 checkZip(QDir::toNativeSeparators(executable_file));
405 void FormSettings::selectSignApk() {
406 QString executable_file = QFileDialog::getOpenFileName(
this,
407 tr(
"Select SIGNAPK executable"),
408 m_ui->m_lblExternalSignapk->label()->text(),
410 tr(
"Executables (signapk.jar)"),
413 if (!executable_file.isEmpty()) {
414 checkSignApk(QDir::toNativeSeparators(executable_file));
418 void FormSettings::onProxyTypeChanged(
int index) {
419 QNetworkProxy::ProxyType selected_type =
static_cast<QNetworkProxy::ProxyType
>(m_ui->m_cmbProxyType->itemData(index).toInt());
420 bool is_proxy_selected = selected_type != QNetworkProxy::NoProxy && selected_type != QNetworkProxy::DefaultProxy;
422 m_ui->m_txtProxyHost->setEnabled(is_proxy_selected);
423 m_ui->m_txtProxyPassword->setEnabled(is_proxy_selected);
424 m_ui->m_txtProxyUsername->setEnabled(is_proxy_selected);
425 m_ui->m_spinProxyPort->setEnabled(is_proxy_selected);
426 m_ui->m_checkShowPassword->setEnabled(is_proxy_selected);
427 m_ui->m_lblProxyHost->setEnabled(is_proxy_selected);
428 m_ui->m_lblProxyInfo->setEnabled(is_proxy_selected);
429 m_ui->m_lblProxyPassword->setEnabled(is_proxy_selected);
430 m_ui->m_lblProxyPort->setEnabled(is_proxy_selected);
431 m_ui->m_lblProxyUsername->setEnabled(is_proxy_selected);
434 void FormSettings::loadBrowser() {
435 Settings *settings = qApp->settings();
438 m_ui->m_cmbExternalBrowserPreset->addItem(tr(
"Opera 12 or older"),
"-nosession %1");
439 m_ui->m_txtExternalBrowserExecutable->setText(QDir::toNativeSeparators(settings->
value(APP_CFG_BROWSER,
440 "external_browser_executable").toString()));
441 m_ui->m_txtExternalBrowserArguments->setText(settings->
value(APP_CFG_BROWSER,
442 "external_browser_arguments",
444 m_ui->m_grpCustomExternalBrowser->setChecked(settings->
value(APP_CFG_BROWSER,
445 "custom_external_browser",
449 void FormSettings::saveBrowser() {
450 Settings *settings = qApp->settings();
454 "custom_external_browser",
455 m_ui->m_grpCustomExternalBrowser->isChecked());
457 "external_browser_executable",
458 m_ui->m_txtExternalBrowserExecutable->text());
460 "external_browser_arguments",
461 m_ui->m_txtExternalBrowserArguments->text());
464 void FormSettings::loadProxy() {
465 m_ui->m_cmbProxyType->addItem(tr(
"No proxy"), QNetworkProxy::NoProxy);
466 m_ui->m_cmbProxyType->addItem(tr(
"System proxy"), QNetworkProxy::DefaultProxy);
467 m_ui->m_cmbProxyType->addItem(tr(
"Socks5"), QNetworkProxy::Socks5Proxy);
468 m_ui->m_cmbProxyType->addItem(tr(
"Http"), QNetworkProxy::HttpProxy);
471 Settings *settings = qApp->settings();
473 QNetworkProxy::ProxyType selected_proxy_type =
static_cast<QNetworkProxy::ProxyType
>(settings->
value(APP_CFG_PROXY,
475 QNetworkProxy::NoProxy).toInt());
477 m_ui->m_cmbProxyType->setCurrentIndex(m_ui->m_cmbProxyType->findData(selected_proxy_type));
478 m_ui->m_txtProxyHost->setText(settings->
value(APP_CFG_PROXY,
480 m_ui->m_txtProxyUsername->setText(settings->
value(APP_CFG_PROXY,
481 "username").toString());
482 m_ui->m_txtProxyPassword->setText(settings->
value(APP_CFG_PROXY,
483 "password").toString());
484 m_ui->m_spinProxyPort->setValue(settings->
value(APP_CFG_PROXY,
485 "port", 80).toInt());
488 void FormSettings::saveProxy() {
489 Settings *settings = qApp->settings();
491 settings->
setValue(APP_CFG_PROXY,
"proxy_type",
492 m_ui->m_cmbProxyType->itemData(m_ui->m_cmbProxyType->currentIndex()));
493 settings->
setValue(APP_CFG_PROXY,
"host",
494 m_ui->m_txtProxyHost->text());
495 settings->
setValue(APP_CFG_PROXY,
"username",
496 m_ui->m_txtProxyUsername->text());
497 settings->
setValue(APP_CFG_PROXY,
"password",
498 m_ui->m_txtProxyPassword->text());
499 settings->
setValue(APP_CFG_PROXY,
"port",
500 m_ui->m_spinProxyPort->value());
503 void FormSettings::loadLanguage() {
505 QTreeWidgetItem *item =
new QTreeWidgetItem(m_ui->m_treeLanguages);
506 item->setText(0, language.m_name);
507 item->setText(1, language.m_code);
508 item->setText(2, language.m_author);
509 item->setText(3, language.m_email);
513 QList<QTreeWidgetItem*> matching_items = m_ui->m_treeLanguages->findItems(
Localization::instance()->loadedLanguage(),
516 if (!matching_items.isEmpty()) {
517 m_ui->m_treeLanguages->setCurrentItem(matching_items[0]);
521 void FormSettings::saveLanguage() {
522 if (m_ui->m_treeLanguages->currentItem() == NULL) {
523 qDebug(
"No localizations loaded in settings dialog, so no saving for them.");
527 Settings *settings = qApp->settings();
529 QString new_lang = m_ui->m_treeLanguages->currentItem()->text(1);
532 if (new_lang != actual_lang) {
533 m_changedDataTexts.append(tr(
"language changed"));
534 settings->
setValue(APP_CFG_GEN,
"language", new_lang);
538 void FormSettings::loadInterface() {
543 if (icon_theme_name == APP_NO_THEME) {
546 m_ui->m_cmbIconTheme->addItem(tr(
"no icon theme"),
550 m_ui->m_cmbIconTheme->addItem(icon_theme_name,
556 if (current_theme == APP_NO_THEME) {
558 m_ui->m_cmbIconTheme->setCurrentIndex(0);
561 #if QT_VERSION >= 0x050000
562 m_ui->m_cmbIconTheme->setCurrentText(current_theme);
564 int theme_index = m_ui->m_cmbIconTheme->findText(current_theme);
565 if (theme_index >= 0) {
566 m_ui->m_cmbIconTheme->setCurrentIndex(theme_index);
572 QString selected_skin = qApp->skinFactory()->selectedSkinName();
574 foreach (
const Skin &skin, qApp->skinFactory()->installedSkins()) {
575 QTreeWidgetItem *new_item =
new QTreeWidgetItem(QStringList() <<
576 skin.m_visibleName <<
580 new_item->setData(0, Qt::UserRole, QVariant::fromValue(skin));
583 m_ui->m_treeSkins->addTopLevelItem(new_item);
585 if (skin.m_baseName == selected_skin) {
586 m_ui->m_treeSkins->setCurrentItem(new_item);
587 m_ui->m_lblActiveContents->setText(skin.m_visibleName);
591 if (m_ui->m_treeSkins->currentItem() == NULL &&
592 m_ui->m_treeSkins->topLevelItemCount() > 0) {
595 m_ui->m_treeSkins->setCurrentItem(m_ui->m_treeSkins->topLevelItem(0));
599 void FormSettings::saveInterface() {
601 QString selected_icon_theme = m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString();
606 if (selected_icon_theme != original_icon_theme) {
607 m_changedDataTexts.append(tr(
"icon theme changed"));
611 if (m_ui->m_treeSkins->selectedItems().size() > 0) {
612 Skin active_skin = m_ui->m_treeSkins->currentItem()->data(0, Qt::UserRole).value<
Skin>();
614 if (qApp->skinFactory()->selectedSkinName() != active_skin.m_baseName) {
615 qApp->skinFactory()->setCurrentSkinName(active_skin.m_baseName);
616 m_changedDataTexts.append(tr(
"skin changed"));
621 void FormSettings::loadShortcuts() {
622 m_ui->m_shortcutsEditor->populate(qApp->availableActions());
625 void FormSettings::saveShortcuts() {
627 m_ui->m_shortcutsEditor->updateShortcuts();
633 void FormSettings::loadGenerationStuff() {
634 m_ui->m_lblGenerationTemp->setText(QDir::toNativeSeparators(qApp->templateManager()->tempDirectory()));
635 m_ui->m_lblGenerationOutput->setText(QDir::toNativeSeparators(qApp->templateManager()->outputDirectory()));
636 m_ui->m_txtGenerationOutputFilePattern->setText(QDir::toNativeSeparators(qApp->templateManager()->applicationFileNamePattern()));
639 void FormSettings::saveGenerationStuff() {
640 qApp->templateManager()->setOutputDirectory(m_ui->m_lblGenerationOutput->text());
641 qApp->templateManager()->setTempDirectory(m_ui->m_lblGenerationTemp->text());
642 qApp->templateManager()->setApplicationFileNamePattern(m_ui->m_txtGenerationOutputFilePattern->text());
645 void FormSettings::selectTempDirectory() {
646 QString temp_directory = QFileDialog::getExistingDirectory(
this,
647 tr(
"Select temporary directory"),
648 m_ui->m_lblGenerationTemp->text());
650 if (!temp_directory.isEmpty()) {
651 m_ui->m_lblGenerationTemp->setText(QDir::toNativeSeparators(temp_directory));
655 void FormSettings::selectOutputDirectory() {
656 QString output_directory = QFileDialog::getExistingDirectory(
this,
657 tr(
"Select output directory"),
658 m_ui->m_lblGenerationOutput->text());
660 if (!output_directory.isEmpty()) {
661 m_ui->m_lblGenerationOutput->setText(QDir::toNativeSeparators(output_directory));
QString loadedLanguage() const
Access to code of loaded language.
void setCurrentIconTheme(const QString &theme_name)
Sets icon theme with given name as the active one and loads it.
static Localization * instance()
Singleton getter.
static void save(const QList< QAction * > &actions)
Stores shortcut of each action from actions into the application settings.
void setValue(const QString §ion, const QString &key, const QVariant &value)
Sets new value into settings.
Application-wide settings mechanism.
static bool isSystemTrayAvailable()
Indicates whether tray icon is supported.
static QMessageBox::StandardButton show(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, const QString &informative_text=QString(), const QString &detailed_text=QString(), QMessageBox::StandardButtons buttons=QMessageBox::Ok, QMessageBox::StandardButton default_button=QMessageBox::Ok)
Displays custom message box.
QVariant value(const QString §ion, const QString &key, const QVariant &default_value=QVariant())
Getter/setter for settings values.
Representation of single localization.
static IconFactory * instance()
Singleton getter.
QString currentIconTheme() const
Gets name of current theme.