GeneralPage.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 GeneralPage.cpp
00013 ** \version $Id: GeneralPage.cpp 4132 2009-09-24 02:28:18Z edmanm $
00014 ** \brief General Tor and Vidalia configuration options
00015 */
00016 
00017 #include "config.h"
00018 #include "GeneralPage.h"
00019 
00020 #include "stringutil.h"
00021 
00022 #include <QDateTime>
00023 
00024 
00025 /** Constructor */
00026 GeneralPage::GeneralPage(QWidget *parent)
00027 : ConfigPage(parent, "General")
00028 {
00029   /* Invoke the Qt Designer generated object setup routine */
00030   ui.setupUi(this);
00031 
00032   /* Create settings objects */
00033   _vidaliaSettings = new VidaliaSettings;
00034   _torSettings = new TorSettings;
00035   
00036   /* Bind event to actions */
00037   connect(ui.btnBrowseTorExecutable, SIGNAL(clicked()), 
00038           this, SLOT(browseTorExecutable()));
00039   connect(ui.btnBrowseProxyExecutable, SIGNAL(clicked()), 
00040           this, SLOT(browseProxyExecutable()));
00041   connect(ui.btnUpdateNow, SIGNAL(clicked()), this, SLOT(updateNow()));
00042 
00043 #if !defined(Q_OS_WIN32)
00044   /* Hide platform specific features */
00045   ui.chkRunVidaliaAtSystemStartup->setVisible(false);
00046   ui.lineHorizontalSeparator->setVisible(false);
00047 #endif
00048 #if !defined(USE_AUTOUPDATE)
00049   ui.grpSoftwareUpdates->setVisible(false);
00050 #endif
00051 }
00052 
00053 /** Destructor */
00054 GeneralPage::~GeneralPage()
00055 {
00056   delete _vidaliaSettings;
00057   delete _torSettings;
00058 }
00059 
00060 /** Called when the user changes the UI translation. */
00061 void
00062 GeneralPage::retranslateUi()
00063 {
00064   ui.retranslateUi(this);
00065 }
00066 
00067 /** Displays a file dialog allowing the user to browse for an executable
00068  * file. <b>caption</b> will be displayed in the dialog's title bar and
00069  * <b>file</b>, if specified, is the default file selected in the dialog.
00070  */
00071 QString
00072 GeneralPage::browseExecutable(const QString &caption, const QString &file)
00073 {
00074 #if defined(Q_OS_WIN32)
00075   QString filter = tr("Executables (*.exe)");
00076 #else
00077   QString filter = "";
00078 #endif
00079  
00080   QString filePath = QFileDialog::getOpenFileName(this, caption, file, filter);
00081   return QDir::convertSeparators(filePath);
00082 }
00083 
00084 /** Open a QFileDialog to browse for a Tor executable file. */
00085 void
00086 GeneralPage::browseTorExecutable()
00087 {
00088   QString filePath = browseExecutable(tr("Select Path to Tor"),
00089                                       ui.lineTorExecutable->text());
00090   if (! filePath.isEmpty())
00091     ui.lineTorExecutable->setText(filePath);
00092 }
00093 
00094 /** Open a QFileDialog to browse for a proxy executable file. */
00095 void
00096 GeneralPage::browseProxyExecutable()
00097 {
00098   QString filePath = browseExecutable(tr("Select Proxy Executable"),
00099                                       ui.lineProxyExecutable->text());
00100 
00101   if (! filePath.isEmpty())
00102     ui.lineProxyExecutable->setText(filePath);
00103 }
00104 
00105 /** Saves all settings for this page */
00106 bool
00107 GeneralPage::save(QString &errmsg)
00108 {
00109   QString torExecutable = ui.lineTorExecutable->text();
00110   if (torExecutable.isEmpty()) {
00111     errmsg = tr("You must specify the name of your Tor executable.");
00112     return false;
00113   }
00114   if (ui.chkRunProxyAtTorStartup->isChecked()) {
00115     _vidaliaSettings->setProxyExecutable(ui.lineProxyExecutable->text());
00116     _vidaliaSettings->setProxyExecutableArguments(
00117       ui.lineProxyExecutableArguments->text());
00118   }
00119   
00120   _torSettings->setExecutable(torExecutable);
00121   _vidaliaSettings->setRunTorAtStart(ui.chkRunTorAtVidaliaStartup->isChecked());
00122   _vidaliaSettings->setRunVidaliaOnBoot(
00123     ui.chkRunVidaliaAtSystemStartup->isChecked());
00124   _vidaliaSettings->setRunProxyAtStart(
00125     ui.chkRunProxyAtTorStartup->isChecked());
00126   return true;
00127 }
00128 
00129 /** Loads previously saved settings */
00130 void
00131 GeneralPage::load()
00132 {
00133   ui.chkRunVidaliaAtSystemStartup->setChecked(
00134     _vidaliaSettings->runVidaliaOnBoot());
00135   
00136   ui.lineTorExecutable->setText(_torSettings->getExecutable());
00137   ui.chkRunTorAtVidaliaStartup->setChecked(_vidaliaSettings->runTorAtStart());
00138 
00139   ui.lineProxyExecutable->setText(_vidaliaSettings->getProxyExecutable());
00140   ui.lineProxyExecutableArguments->setText(
00141     _vidaliaSettings->getProxyExecutableArguments());
00142   ui.chkRunProxyAtTorStartup->setChecked(_vidaliaSettings->runProxyAtStart());
00143 }
00144 
00145 void
00146 GeneralPage::updateNow()
00147 {
00148   emit checkForUpdates();
00149 }
00150 
Generated on Mon Aug 30 22:58:54 2010 for Vidalia by  doxygen 1.6.3