Vidalia 0.2.12

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.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  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   return true;
00076 }
00077   
00078 /** Loads the settings for this page */
00079 void
00080 AppearancePage::load()
00081 {
00082   int index = ui.cmboLanguage->findData(_settings->getLanguageCode());
00083   ui.cmboLanguage->setCurrentIndex(index);
00084   
00085   index = ui.cmboStyle->findData(Vidalia::style().toLower());
00086   ui.cmboStyle->setCurrentIndex(index);
00087 }
00088