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