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

Generated on Tue Jul 7 16:58:11 2009 for Vidalia by  doxygen 1.4.7