Vidalia  0.3.1
AppearancePage.cpp
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file AppearancePage.cpp
13 ** \brief Displays Vidalia language and style settings
14 */
15 
16 #include "AppearancePage.h"
17 #include "Vidalia.h"
18 #include "VMessageBox.h"
19 
20 
21 /** Default Constructor */
23  : ConfigPage(parent, "Appearance")
24 {
25  /* Invoke Designer-generated object setup routine */
26  ui.setupUi(this);
27 
28  /* Create VidaliaSettings object */
29  _settings = new VidaliaSettings();
30 
31  /* Populate combo boxes */
32  foreach (QString code, LanguageSupport::languageCodes()) {
33  ui.cmboLanguage->addItem(LanguageSupport::languageName(code),
34  code);
35  }
36  foreach (QString style, QStyleFactory::keys()) {
37  ui.cmboStyle->addItem(style, style.toLower());
38  }
39 }
40 
41 /** Destructor */
43 {
44  delete _settings;
45 }
46 
47 /** Called when the user changes the UI translation. */
48 void
50 {
51  ui.retranslateUi(this);
52 }
53 
54 /** Saves the changes on this page */
55 bool
56 AppearancePage::save(QString &errmsg)
57 {
58  QString prevLanguage = _settings->getLanguageCode();
59  QString languageCode =
60  LanguageSupport::languageCode(ui.cmboLanguage->currentText());
61 
62  /* Set the new language */
63  if (prevLanguage != languageCode) {
64  if (! Vidalia::retranslateUi(languageCode)) {
65  errmsg = tr("Vidalia was unable to load the selected "
66  "language translation.");
67  return false;
68  }
69  _settings->setLanguageCode(languageCode);
70  }
71 
72  /* Set the new style */
73  Vidalia::setStyle(ui.cmboStyle->currentText());
74  _settings->setInterfaceStyle(ui.cmboStyle->currentText());
75 
76 #if defined(Q_WS_MAC)
77  /* Save new icon preference */
78  if(ui.rdoIconPrefDock->isChecked()) {
80  }
81  else if(ui.rdoIconPrefTray->isChecked()) {
83  }
84  else {
85  /* default setting */
87  }
88 #endif
89 
90  return true;
91 }
92 
93 /** Loads the settings for this page */
94 void
96 {
97  int index = ui.cmboLanguage->findData(_settings->getLanguageCode());
98  ui.cmboLanguage->setCurrentIndex(index);
99 
100  index = ui.cmboStyle->findData(Vidalia::style().toLower());
101  ui.cmboStyle->setCurrentIndex(index);
102 
103 #if defined(Q_WS_MAC)
104  /* set current icon preference */
105  ui.rdoIconPrefBoth->setChecked(_settings->getIconPref() == VidaliaSettings::Both);
106  ui.rdoIconPrefTray->setChecked(_settings->getIconPref() == VidaliaSettings::Tray);
107  ui.rdoIconPrefDock->setChecked(_settings->getIconPref() == VidaliaSettings::Dock);
108 #else
109  /* hide preference on non-OSX platforms */
110  ui.grpIconPref->setVisible(false);
111  ui.rdoIconPrefBoth->setVisible(false);
112  ui.rdoIconPrefTray->setVisible(false);
113  ui.rdoIconPrefDock->setVisible(false);
114 #endif
115 }
116 
Ui::AppearancePage ui
virtual void retranslateUi()
static bool retranslateUi(const QString &languageCode)
Definition: Vidalia.cpp:430
bool save(QString &errmsg)
static QStringList languageCodes()
VidaliaSettings * _settings
void setLanguageCode(QString languageCode)
static QString style()
Definition: Vidalia.h:71
static bool setStyle(QString styleKey=QString())
Definition: Vidalia.cpp:338
QString getLanguageCode()
void setInterfaceStyle(QString styleKey)
IconPosition getIconPref()
static QString languageName(const QString &languageCode)
static QString languageCode(const QString &languageName)
AppearancePage(QWidget *parent=0)
void setIconPref(const IconPosition iconPref)