BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
formsettings.cpp
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #include "gui/formsettings.h"
32 
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"
48 
49 #include <QProcess>
50 #include <QNetworkProxy>
51 #include <QColorDialog>
52 #include <QFileDialog>
53 
54 
56  : QDialog(parent), m_ui(new Ui::FormSettings) {
57  m_ui->setupUi(this);
58 
59  // Set flags and attributes.
60  setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
61  setWindowIcon(IconFactory::instance()->fromTheme("application-settings"));
62 
63  // Setup behavior.
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()
68  << /*: Language column of language list. */ tr("Language")
69  << /*: Lang. code column of language list. */ tr("Code")
70  << tr("Author")
71  << tr("Email"));
72 
73  m_ui->m_treeSkins->setColumnCount(4);
74  m_ui->m_treeSkins->setHeaderHidden(false);
75  m_ui->m_treeSkins->setHeaderLabels(QStringList()
76  << /*: Skin list name column. */ tr("Name")
77  << /*: Version column of skin list. */ tr("Version")
78  << tr("Author")
79  << tr("Email"));
80 
81 #if QT_VERSION >= 0x050000
82  // Setup languages.
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);
87 
88  // Setup skins.
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);
93 #else
94  // Setup languages.
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);
99 
100  // Setup skins.
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);
105 #endif
106 
107  // Establish needed connections.
108  createConnections();
109 
110  // Load all settings.
111  loadGeneral();
112  loadExternalUtilites();
113  loadInterface();
114  loadShortcuts();
115  loadProxy();
116  loadBrowser();
117  loadLanguage();
118  loadGenerationStuff();
119 }
120 
121 FormSettings::~FormSettings() {
122  qDebug("Destroying FormSettings distance.");
123  delete m_ui;
124 }
125 
126 void FormSettings::changeDefaultBrowserArguments(int index) {
127  if (index != 0) {
128  m_ui->m_txtExternalBrowserArguments->setText(m_ui->m_cmbExternalBrowserPreset->itemData(index).toString());
129  }
130 }
131 
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*)));
145 }
146 
147 void FormSettings::onSkinSelected(QTreeWidgetItem *current,
148  QTreeWidgetItem *previous) {
149  Q_UNUSED(previous)
150 
151  if (current != NULL) {
152  Skin skin = current->data(0, Qt::UserRole).value<Skin>();
153  m_ui->m_lblSelectedContents->setText(skin.m_visibleName);
154  }
155 }
156 
157 void FormSettings::selectBrowserExecutable() {
158  QString executable_file = QFileDialog::getOpenFileName(this,
159  tr("Select web browser executable"),
160  QDir::homePath(),
161  //: File filter for external browser selection dialog.
162  tr("Executables (*.*)"));
163 
164  if (!executable_file.isEmpty()) {
165  m_ui->m_txtExternalBrowserExecutable->setText(QDir::toNativeSeparators(executable_file));
166  }
167 }
168 
169 void FormSettings::displayProxyPassword(int state) {
170  if (state == Qt::Checked) {
171  m_ui->m_txtProxyPassword->setEchoMode(QLineEdit::Normal);
172  }
173  else {
174  m_ui->m_txtProxyPassword->setEchoMode(QLineEdit::Password);
175  }
176 }
177 
178 bool FormSettings::doSaveCheck() {
179  bool everything_ok = true;
180  QStringList resulting_information;
181 
182  // Setup indication of settings consistence.
183  if (!m_ui->m_shortcutsEditor->areShortcutsUnique()) {
184  everything_ok = false;
185  resulting_information.append(tr("some keyboard shortcuts are not unique"));
186  }
187 
188  // User selected custom external browser but did not set its
189  // properties.
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"));
195  }
196 
197  if (!everything_ok) {
198  resulting_information.replaceInStrings(QRegExp("^"),
199  QString::fromUtf8(" • "));
200 
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."),
205  QString(),
206  tr("List of errors:\n%1.").arg(resulting_information.join(",\n")));
207  }
208 
209  return everything_ok;
210 }
211 
212 void FormSettings::promptForRestart() {
213  if (m_changedDataTexts.count() > 0) {
214  QStringList changed_data_texts = m_changedDataTexts;
215 
216  changed_data_texts.replaceInStrings(QRegExp("^"),
217  QString::fromUtf8(" • "));
218 
219  int question_result = CustomMessageBox::show(this,
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,
226  QMessageBox::Yes);
227 
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);
235  }
236  else {
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."));
242  }
243  }
244  else {
245  qApp->quit();
246  }
247  }
248  }
249 }
250 
251 void FormSettings::saveSettings() {
252  // Make sure everything is saveable.
253  if (!doSaveCheck()) {
254  return;
255  }
256 
257  // Save all settings.
258  saveGeneral();
259  saveExternalUtilites();
260  saveInterface();
261  saveShortcuts();
262  saveProxy();
263  saveBrowser();
264  saveLanguage();
265  saveGenerationStuff();
266 
267  qApp->settings()->checkSettings();
268  promptForRestart();
269 
270  accept();
271 }
272 
273 void FormSettings::loadGeneral() {
274  m_ui->m_checkCheckForUpdatesOnStartup->setChecked(qApp->settings()->value(APP_CFG_GEN,
275  "check_for_updates_startup",
276  true).toBool());
277 }
278 
279 void FormSettings::saveGeneral() {
280  qApp->settings()->setValue(APP_CFG_GEN,
281  "check_for_updates_startup",
282  m_ui->m_checkCheckForUpdatesOnStartup->isChecked());
283 }
284 
285 void FormSettings::loadExternalUtilites() {
286  checkZip(QDir::toNativeSeparators(qApp->zipUtilityPath()));
287  checkJava(QDir::toNativeSeparators(qApp->javaInterpreterPath()));
288  checkSignApk(QDir::toNativeSeparators(qApp->signApkUtlityPath()));
289 }
290 
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);
296 }
297 
298 void FormSettings::checkZip(const QString &new_path) {
299  int zip_output = qApp->checkZip(new_path);
300  QString textual_info = qApp->interpretZip(zip_output);
301 
302  switch (zip_output) {
303  case EXIT_STATUS_NOT_STARTED:
304  m_ui->m_lblExternalZip->setStatus(WidgetWithStatus::Error,
305  new_path,
306  textual_info);
307  break;
308 
309  case EXIT_STATUS_ZIP_NORMAL:
310  m_ui->m_lblExternalZip->setStatus(WidgetWithStatus::Ok,
311  new_path,
312  textual_info);
313  break;
314 
315  case EXIT_STATUS_CRASH:
316  default:
317  m_ui->m_lblExternalZip->setStatus(WidgetWithStatus::Warning,
318  new_path,
319  textual_info);
320  break;
321  }
322 }
323 
324 void FormSettings::checkJava(const QString &new_path) {
325  int java_output = qApp->checkJava(new_path);
326  QString textual_info = qApp->interpretJava(java_output);
327 
328  switch (java_output) {
329  case EXIT_STATUS_NOT_STARTED:
330  m_ui->m_lblExternalJava->setStatus(WidgetWithStatus::Error,
331  new_path,
332  textual_info);
333  break;
334 
335  case EXIT_STATUS_JAVA_NORMAL:
336  m_ui->m_lblExternalJava->setStatus(WidgetWithStatus::Ok,
337  new_path,
338  textual_info);
339  break;
340 
341  case EXIT_STATUS_CRASH:
342  default:
343  m_ui->m_lblExternalJava->setStatus(WidgetWithStatus::Warning,
344  new_path,
345  textual_info);
346  break;
347  }
348 }
349 
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);
353 
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,
358  new_path,
359  textual_info);
360  break;
361 
362  case EXIT_STATUS_SIGNAPK_NORMAL:
363  m_ui->m_lblExternalSignapk->setStatus(WidgetWithStatus::Ok,
364  new_path,
365  textual_info);
366  break;
367 
368  case EXIT_STATUS_CRASH:
369  case EXIT_STATUS_SIGNAPK_WORKING:
370  default:
371  m_ui->m_lblExternalSignapk->setStatus(WidgetWithStatus::Warning,
372  new_path,
373  textual_info);
374  break;
375  }
376 }
377 
378 void FormSettings::selectJava() {
379  QString executable_file = QFileDialog::getOpenFileName(this,
380  tr("Select JAVA executable"),
381  m_ui->m_lblExternalJava->label()->text(),
382  //: File filter for external browser selection dialog.
383  tr("Executables (java*)"),
384  0);
385 
386  if (!executable_file.isEmpty()) {
387  checkJava(QDir::toNativeSeparators(executable_file));
388  checkSignApk(m_ui->m_lblExternalSignapk->label()->text());
389  }
390 }
391 
392 void FormSettings::selectZip() {
393  QString executable_file = QFileDialog::getOpenFileName(this,
394  tr("Select ZIP executable"),
395  m_ui->m_lblExternalZip->label()->text(),
396  //: File filter for external browser selection dialog.
397  tr("Executables (zip*)"),
398  0);
399 
400  if (!executable_file.isEmpty()) {
401  checkZip(QDir::toNativeSeparators(executable_file));
402  }
403 }
404 
405 void FormSettings::selectSignApk() {
406  QString executable_file = QFileDialog::getOpenFileName(this,
407  tr("Select SIGNAPK executable"),
408  m_ui->m_lblExternalSignapk->label()->text(),
409  //: File filter for external browser selection dialog.
410  tr("Executables (signapk.jar)"),
411  0);
412 
413  if (!executable_file.isEmpty()) {
414  checkSignApk(QDir::toNativeSeparators(executable_file));
415  }
416 }
417 
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;
421 
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);
432 }
433 
434 void FormSettings::loadBrowser() {
435  Settings *settings = qApp->settings();
436 
437  // Load settings of web browser GUI.
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",
443  "%1").toString());
444  m_ui->m_grpCustomExternalBrowser->setChecked(settings->value(APP_CFG_BROWSER,
445  "custom_external_browser",
446  false).toBool());
447 }
448 
449 void FormSettings::saveBrowser() {
450  Settings *settings = qApp->settings();
451 
452  // Save settings of GUI of web browser.
453  settings->setValue(APP_CFG_BROWSER,
454  "custom_external_browser",
455  m_ui->m_grpCustomExternalBrowser->isChecked());
456  settings->setValue(APP_CFG_BROWSER,
457  "external_browser_executable",
458  m_ui->m_txtExternalBrowserExecutable->text());
459  settings->setValue(APP_CFG_BROWSER,
460  "external_browser_arguments",
461  m_ui->m_txtExternalBrowserArguments->text());
462 }
463 
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);
469 
470  // Load the settings.
471  Settings *settings = qApp->settings();
472 
473  QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(settings->value(APP_CFG_PROXY,
474  "proxy_type",
475  QNetworkProxy::NoProxy).toInt());
476 
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,
479  "host").toString());
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());
486 }
487 
488 void FormSettings::saveProxy() {
489  Settings *settings = qApp->settings();
490 
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());
501 }
502 
503 void FormSettings::loadLanguage() {
504  foreach (const Language &language, Localization::instance()->installedLanguages()) {
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);
510  item->setIcon(0, IconFactory::instance()->fromTheme(language.m_code));
511  }
512 
513  QList<QTreeWidgetItem*> matching_items = m_ui->m_treeLanguages->findItems(Localization::instance()->loadedLanguage(),
514  Qt::MatchContains,
515  1);
516  if (!matching_items.isEmpty()) {
517  m_ui->m_treeLanguages->setCurrentItem(matching_items[0]);
518  }
519 }
520 
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.");
524  return;
525  }
526 
527  Settings *settings = qApp->settings();
528  QString actual_lang = Localization::instance()->loadedLanguage();
529  QString new_lang = m_ui->m_treeLanguages->currentItem()->text(1);
530 
531  // Save prompt for restart if language has changed.
532  if (new_lang != actual_lang) {
533  m_changedDataTexts.append(tr("language changed"));
534  settings->setValue(APP_CFG_GEN, "language", new_lang);
535  }
536 }
537 
538 void FormSettings::loadInterface() {
539  // Load settings of icon theme.
540  QString current_theme = IconFactory::instance()->currentIconTheme();
541 
542  foreach (const QString &icon_theme_name, IconFactory::instance()->installedIconThemes()) {
543  if (icon_theme_name == APP_NO_THEME) {
544  // Add just "no theme" on other systems.
545  //: Label for disabling icon theme.
546  m_ui->m_cmbIconTheme->addItem(tr("no icon theme"),
547  APP_NO_THEME);
548  }
549  else {
550  m_ui->m_cmbIconTheme->addItem(icon_theme_name,
551  icon_theme_name);
552  }
553  }
554 
555  // Mark active theme.
556  if (current_theme == APP_NO_THEME) {
557  // Because "no icon theme" lies at the index 0.
558  m_ui->m_cmbIconTheme->setCurrentIndex(0);
559  }
560  else {
561 #if QT_VERSION >= 0x050000
562  m_ui->m_cmbIconTheme->setCurrentText(current_theme);
563 #else
564  int theme_index = m_ui->m_cmbIconTheme->findText(current_theme);
565  if (theme_index >= 0) {
566  m_ui->m_cmbIconTheme->setCurrentIndex(theme_index);
567  }
568 #endif
569  }
570 
571  // Load skin.
572  QString selected_skin = qApp->skinFactory()->selectedSkinName();
573 
574  foreach (const Skin &skin, qApp->skinFactory()->installedSkins()) {
575  QTreeWidgetItem *new_item = new QTreeWidgetItem(QStringList() <<
576  skin.m_visibleName <<
577  skin.m_version <<
578  skin.m_author <<
579  skin.m_email);
580  new_item->setData(0, Qt::UserRole, QVariant::fromValue(skin));
581 
582  // Add this skin and mark it as active if its active now.
583  m_ui->m_treeSkins->addTopLevelItem(new_item);
584 
585  if (skin.m_baseName == selected_skin) {
586  m_ui->m_treeSkins->setCurrentItem(new_item);
587  m_ui->m_lblActiveContents->setText(skin.m_visibleName);
588  }
589  }
590 
591  if (m_ui->m_treeSkins->currentItem() == NULL &&
592  m_ui->m_treeSkins->topLevelItemCount() > 0) {
593  // Currently active skin is NOT available, select another one as selected
594  // if possible.
595  m_ui->m_treeSkins->setCurrentItem(m_ui->m_treeSkins->topLevelItem(0));
596  }
597 }
598 
599 void FormSettings::saveInterface() {
600  // Save selected icon theme.
601  QString selected_icon_theme = m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString();
602  QString original_icon_theme = IconFactory::instance()->currentIconTheme();
603  IconFactory::instance()->setCurrentIconTheme(selected_icon_theme);
604 
605  // Check if icon theme was changed.
606  if (selected_icon_theme != original_icon_theme) {
607  m_changedDataTexts.append(tr("icon theme changed"));
608  }
609 
610  // Save and activate new skin.
611  if (m_ui->m_treeSkins->selectedItems().size() > 0) {
612  Skin active_skin = m_ui->m_treeSkins->currentItem()->data(0, Qt::UserRole).value<Skin>();
613 
614  if (qApp->skinFactory()->selectedSkinName() != active_skin.m_baseName) {
615  qApp->skinFactory()->setCurrentSkinName(active_skin.m_baseName);
616  m_changedDataTexts.append(tr("skin changed"));
617  }
618  }
619 }
620 
621 void FormSettings::loadShortcuts() {
622  m_ui->m_shortcutsEditor->populate(qApp->availableActions());
623 }
624 
625 void FormSettings::saveShortcuts() {
626  // Update the actual shortcuts of some actions.
627  m_ui->m_shortcutsEditor->updateShortcuts();
628 
629  // Save new shortcuts to the settings.
630  DynamicShortcuts::save(qApp->availableActions());
631 }
632 
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()));
637 }
638 
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());
643 }
644 
645 void FormSettings::selectTempDirectory() {
646  QString temp_directory = QFileDialog::getExistingDirectory(this,
647  tr("Select temporary directory"),
648  m_ui->m_lblGenerationTemp->text());
649 
650  if (!temp_directory.isEmpty()) {
651  m_ui->m_lblGenerationTemp->setText(QDir::toNativeSeparators(temp_directory));
652  }
653 }
654 
655 void FormSettings::selectOutputDirectory() {
656  QString output_directory = QFileDialog::getExistingDirectory(this,
657  tr("Select output directory"),
658  m_ui->m_lblGenerationOutput->text());
659 
660  if (!output_directory.isEmpty()) {
661  m_ui->m_lblGenerationOutput->setText(QDir::toNativeSeparators(output_directory));
662  }
663 }
QString loadedLanguage() const
Access to code of loaded language.
Definition: localization.h:80
void setCurrentIconTheme(const QString &theme_name)
Sets icon theme with given name as the active one and loads it.
Definition: iconfactory.cpp:65
Form for displaying and editting settings.
Definition: formsettings.h:52
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 &section, const QString &key, const QVariant &value)
Sets new value into settings.
Definition: settings.h:74
FormSettings(QWidget *parent=0)
Constructor.
Application-wide settings mechanism.
Definition: settings.h:40
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 &section, const QString &key, const QVariant &default_value=QVariant())
Getter/setter for settings values.
Definition: settings.h:64
Representation of single localization.
Definition: localization.h:40
Skin representation.
Definition: skinfactory.h:41
static IconFactory * instance()
Singleton getter.
Definition: iconfactory.cpp:48
QString currentIconTheme() const
Gets name of current theme.
Definition: iconfactory.h:87