Vidalia 0.2.15
AppearancePage.cpp
Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file AppearancePage.cpp
00013 ** \brief Displays Vidalia language and style settings
00014 */
00015 
00016 #include "AppearancePage.h"
00017 #include "Vidalia.h"
00018 #include "VMessageBox.h"
00019 
00020 
00021 /** Default Constructor */
00022 AppearancePage::AppearancePage(QWidget *parent)
00023   : ConfigPage(parent, "Appearance")
00024 {
00025   /* Invoke Designer-generated object setup routine */
00026   ui.setupUi(this);
00027 
00028   /* Create VidaliaSettings object */
00029   _settings = new VidaliaSettings();
00030 
00031   /* Populate combo boxes */
00032   foreach (QString code, LanguageSupport::languageCodes()) {
00033     ui.cmboLanguage->addItem(LanguageSupport::languageName(code),
00034                              code);
00035   }
00036   foreach (QString style, QStyleFactory::keys()) {
00037     ui.cmboStyle->addItem(style, style.toLower());
00038   }
00039 }
00040 
00041 /** Destructor */
00042 AppearancePage::~AppearancePage()
00043 {
00044   delete _settings;
00045 }
00046 
00047 /** Called when the user changes the UI translation. */
00048 void
00049 AppearancePage::retranslateUi()
00050 {
00051   ui.retranslateUi(this);
00052 }
00053 
00054 /** Saves the changes on this page */
00055 bool
00056 AppearancePage::save(QString &errmsg)
00057 {
00058   QString prevLanguage = _settings->getLanguageCode();
00059   QString languageCode =
00060     LanguageSupport::languageCode(ui.cmboLanguage->currentText());
00061 
00062   /* Set the new language */
00063   if (prevLanguage != languageCode) {
00064     if (! Vidalia::retranslateUi(languageCode)) {
00065       errmsg = tr("Vidalia was unable to load the selected "
00066                   "language translation.");
00067       return false;
00068     }
00069     _settings->setLanguageCode(languageCode);
00070   }
00071 
00072   /* Set the new style */
00073   Vidalia::setStyle(ui.cmboStyle->currentText());
00074   _settings->setInterfaceStyle(ui.cmboStyle->currentText());
00075 
00076 #if defined(Q_WS_MAC)
00077   /* Save new icon preference */
00078   if(ui.rdoIconPrefDock->isChecked()) {
00079     _settings->setIconPref(VidaliaSettings::Dock);
00080   }
00081   else if(ui.rdoIconPrefTray->isChecked()) {
00082     _settings->setIconPref(VidaliaSettings::Tray);
00083   }
00084   else {
00085     /* default setting */
00086     _settings->setIconPref(VidaliaSettings::Both);
00087   }
00088 #endif
00089 
00090   return true;
00091 }
00092   
00093 /** Loads the settings for this page */
00094 void
00095 AppearancePage::load()
00096 {
00097   int index = ui.cmboLanguage->findData(_settings->getLanguageCode());
00098   ui.cmboLanguage->setCurrentIndex(index);
00099   
00100   index = ui.cmboStyle->findData(Vidalia::style().toLower());
00101   ui.cmboStyle->setCurrentIndex(index);
00102 
00103 #if defined(Q_WS_MAC)
00104   /* set current icon preference */
00105   ui.rdoIconPrefBoth->setChecked(_settings->getIconPref() == VidaliaSettings::Both);
00106   ui.rdoIconPrefTray->setChecked(_settings->getIconPref() == VidaliaSettings::Tray);
00107   ui.rdoIconPrefDock->setChecked(_settings->getIconPref() == VidaliaSettings::Dock);
00108 #else
00109   /* hide preference on non-OSX platforms */
00110   ui.grpIconPref->setVisible(false);
00111   ui.rdoIconPrefBoth->setVisible(false);
00112   ui.rdoIconPrefTray->setVisible(false);
00113   ui.rdoIconPrefDock->setVisible(false);
00114 #endif
00115 }
00116