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 ** \version $Id: AppearancePage.cpp 3735 2009-04-28 20:28:01Z edmanm $
00014 ** \brief Displays Vidalia language and style settings
00015 */
00016 
00017 #include "AppearancePage.h"
00018 #include "Vidalia.h"
00019 #include "VMessageBox.h"
00020 
00021 
00022 /** Default Constructor */
00023 AppearancePage::AppearancePage(QWidget *parent)
00024   : ConfigPage(parent, "Appearance")
00025 {
00026   /* Invoke Designer-generated object setup routine */
00027   ui.setupUi(this);
00028 
00029   /* Create VidaliaSettings object */
00030   _settings = new VidaliaSettings();
00031 
00032   /* Populate combo boxes */
00033   foreach (QString code, LanguageSupport::languageCodes()) {
00034     ui.cmboLanguage->addItem(LanguageSupport::languageName(code),
00035                              code);
00036   }
00037   foreach (QString style, QStyleFactory::keys()) {
00038     ui.cmboStyle->addItem(style, style.toLower());
00039   }
00040 }
00041 
00042 /** Destructor */
00043 AppearancePage::~AppearancePage()
00044 {
00045   delete _settings;
00046 }
00047 
00048 /** Called when the user changes the UI translation. */
00049 void
00050 AppearancePage::retranslateUi()
00051 {
00052   ui.retranslateUi(this);
00053 }
00054 
00055 /** Saves the changes on this page */
00056 bool
00057 AppearancePage::save(QString &errmsg)
00058 {
00059   QString prevLanguage = _settings->getLanguageCode();
00060   QString languageCode =
00061     LanguageSupport::languageCode(ui.cmboLanguage->currentText());
00062 
00063   /* Set the new language */
00064   if (prevLanguage != languageCode) {
00065     if (! Vidalia::retranslateUi(languageCode)) {
00066       errmsg = tr("Vidalia was unable to load the selected "
00067                   "language translation.");
00068       return false;
00069     }
00070     _settings->setLanguageCode(languageCode);
00071   }
00072 
00073   /* Set the new style */
00074   Vidalia::setStyle(ui.cmboStyle->currentText());
00075   _settings->setInterfaceStyle(ui.cmboStyle->currentText());
00076   return true;
00077 }
00078   
00079 /** Loads the settings for this page */
00080 void
00081 AppearancePage::load()
00082 {
00083   int index = ui.cmboLanguage->findData(_settings->getLanguageCode());
00084   ui.cmboLanguage->setCurrentIndex(index);
00085   
00086   index = ui.cmboStyle->findData(Vidalia::style().toLower());
00087   ui.cmboStyle->setCurrentIndex(index);
00088 }
00089 

Generated on 31 Mar 2010 for Vidalia by  doxygen 1.6.1