Vidalia  0.3.1
GeneralPage.cpp
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file GeneralPage.cpp
13 ** \brief General Tor and Vidalia configuration options
14 */
15 
16 #include "config.h"
17 #include "GeneralPage.h"
18 
19 #include "stringutil.h"
20 
21 #include <QDateTime>
22 
23 
24 /** Constructor */
25 GeneralPage::GeneralPage(QWidget *parent)
26 : ConfigPage(parent, "General")
27 {
28  /* Invoke the Qt Designer generated object setup routine */
29  ui.setupUi(this);
30 
31  /* Create settings objects */
34 
35  /* Bind event to actions */
36  connect(ui.btnBrowseTorExecutable, SIGNAL(clicked()),
37  this, SLOT(browseTorExecutable()));
38  connect(ui.btnBrowseProxyExecutable, SIGNAL(clicked()),
39  this, SLOT(browseProxyExecutable()));
40  connect(ui.btnUpdateNow, SIGNAL(clicked()), this, SLOT(updateNow()));
41 
42 #if !defined(Q_OS_WIN32)
43  /* Hide platform specific features */
44  ui.chkRunVidaliaAtSystemStartup->setVisible(false);
45  ui.lineHorizontalSeparator->setVisible(false);
46 #endif
47 #if !defined(USE_AUTOUPDATE)
48  ui.grpSoftwareUpdates->setVisible(false);
49 #endif
50 }
51 
52 /** Destructor */
54 {
55  delete _vidaliaSettings;
56  delete _torSettings;
57 }
58 
59 /** Called when the user changes the UI translation. */
60 void
62 {
63  ui.retranslateUi(this);
64 }
65 
66 /** Displays a file dialog allowing the user to browse for an executable
67  * file. <b>caption</b> will be displayed in the dialog's title bar and
68  * <b>file</b>, if specified, is the default file selected in the dialog.
69  */
70 QString
71 GeneralPage::browseExecutable(const QString &caption, const QString &file)
72 {
73 #if defined(Q_OS_WIN32)
74  QString filter = tr("Executables (*.exe)");
75 #else
76  QString filter = "";
77 #endif
78 
79  QString filePath = QFileDialog::getOpenFileName(this, caption, file, filter);
80  return QDir::convertSeparators(filePath);
81 }
82 
83 /** Open a QFileDialog to browse for a Tor executable file. */
84 void
86 {
87  QString filePath = browseExecutable(tr("Select Path to Tor"),
88  ui.lineTorExecutable->text());
89  if (! filePath.isEmpty())
90  ui.lineTorExecutable->setText(filePath);
91 }
92 
93 /** Open a QFileDialog to browse for a proxy executable file. */
94 void
96 {
97  QString filePath = browseExecutable(tr("Select Proxy Executable"),
98  ui.lineProxyExecutable->text());
99 
100  if (! filePath.isEmpty())
101  ui.lineProxyExecutable->setText(filePath);
102 }
103 
104 /** Saves all settings for this page */
105 bool
106 GeneralPage::save(QString &errmsg)
107 {
108  QString torExecutable = ui.lineTorExecutable->text();
109  if (torExecutable.isEmpty()) {
110  errmsg = tr("You must specify the name of your Tor executable.");
111  return false;
112  }
113  if (ui.chkRunProxyAtTorStartup->isChecked()) {
114  _vidaliaSettings->setProxyExecutable(ui.lineProxyExecutable->text());
116  ui.lineProxyExecutableArguments->text());
117  }
118 
119  _torSettings->setExecutable(torExecutable);
120  _vidaliaSettings->setRunTorAtStart(ui.chkRunTorAtVidaliaStartup->isChecked());
122  ui.chkRunVidaliaAtSystemStartup->isChecked());
124  ui.chkRunProxyAtTorStartup->isChecked());
125  return true;
126 }
127 
128 /** Loads previously saved settings */
129 void
131 {
132  ui.chkRunVidaliaAtSystemStartup->setChecked(
134 
135  ui.lineTorExecutable->setText(_torSettings->getExecutable());
136  ui.chkRunTorAtVidaliaStartup->setChecked(_vidaliaSettings->runTorAtStart());
137 
138  ui.lineProxyExecutable->setText(_vidaliaSettings->getProxyExecutable());
139  ui.lineProxyExecutableArguments->setText(
141  ui.chkRunProxyAtTorStartup->setChecked(_vidaliaSettings->runProxyAtStart());
142 }
143 
144 void
146 {
147  emit checkForUpdates();
148 }
149 
GeneralPage::retranslateUi
virtual void retranslateUi()
Definition: GeneralPage.cpp:61
GeneralPage::browseTorExecutable
void browseTorExecutable()
Definition: GeneralPage.cpp:85
VidaliaSettings::setProxyExecutable
void setProxyExecutable(const QString &proxyExecutable)
Definition: VidaliaSettings.cpp:263
GeneralPage::~GeneralPage
~GeneralPage()
Definition: GeneralPage.cpp:53
TorSettings
Definition: TorSettings.h:26
VidaliaSettings::runTorAtStart
bool runTorAtStart()
Definition: VidaliaSettings.cpp:125
GeneralPage::GeneralPage
GeneralPage(QWidget *parent=0)
Definition: GeneralPage.cpp:25
VidaliaSettings::setRunVidaliaOnBoot
void setRunVidaliaOnBoot(bool run)
Definition: VidaliaSettings.cpp:171
VidaliaSettings::runProxyAtStart
bool runProxyAtStart()
Definition: VidaliaSettings.cpp:240
GeneralPage::browseProxyExecutable
void browseProxyExecutable()
Definition: GeneralPage.cpp:95
GeneralPage::_vidaliaSettings
VidaliaSettings * _vidaliaSettings
Definition: GeneralPage.h:63
VidaliaSettings::setRunTorAtStart
void setRunTorAtStart(bool run)
Definition: VidaliaSettings.cpp:132
GeneralPage.h
stringutil.h
TorSettings::setExecutable
void setExecutable(const QString &torExecutable)
Definition: TorSettings.cpp:174
GeneralPage::save
bool save(QString &errmsg)
Definition: GeneralPage.cpp:106
connect
stop errmsg connect(const QHostAddress &address, quint16 port)
GeneralPage::ui
Ui::GeneralPage ui
Definition: GeneralPage.h:67
GeneralPage::_torSettings
TorSettings * _torSettings
Definition: GeneralPage.h:65
ConfigPage
Definition: ConfigPage.h:22
VidaliaSettings::getProxyExecutable
QString getProxyExecutable() const
Definition: VidaliaSettings.cpp:255
GeneralPage::updateNow
void updateNow()
Definition: GeneralPage.cpp:145
VidaliaSettings::setRunProxyAtStart
void setRunProxyAtStart(bool run)
Definition: VidaliaSettings.cpp:247
GeneralPage::checkForUpdates
void checkForUpdates()
GeneralPage::load
void load()
Definition: GeneralPage.cpp:130
VidaliaSettings
Definition: VidaliaSettings.h:33
config.h
TorSettings::getExecutable
QString getExecutable() const
Definition: TorSettings.cpp:164
VidaliaSettings::getProxyExecutableArguments
QString getProxyExecutableArguments() const
Definition: VidaliaSettings.cpp:271
GeneralPage::browseExecutable
QString browseExecutable(const QString &caption, const QString &file=QString())
Definition: GeneralPage.cpp:71
VidaliaSettings::setProxyExecutableArguments
void setProxyExecutableArguments(const QString &proxyExecutableArguments)
Definition: VidaliaSettings.cpp:278
VidaliaSettings::runVidaliaOnBoot
bool runVidaliaOnBoot()
Definition: VidaliaSettings.cpp:155