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 */
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. */
60void
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 */
70QString
71GeneralPage::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. */
84void
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. */
94void
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 */
105bool
106GeneralPage::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 */
129void
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
144void
146{
147 emit checkForUpdates();
148}
149
stop errmsg connect(const QHostAddress &address, quint16 port)
TorSettings * _torSettings
Definition: GeneralPage.h:65
Ui::GeneralPage ui
Definition: GeneralPage.h:67
bool save(QString &errmsg)
void updateNow()
virtual void retranslateUi()
Definition: GeneralPage.cpp:61
VidaliaSettings * _vidaliaSettings
Definition: GeneralPage.h:63
GeneralPage(QWidget *parent=0)
Definition: GeneralPage.cpp:25
QString browseExecutable(const QString &caption, const QString &file=QString())
Definition: GeneralPage.cpp:71
void checkForUpdates()
void browseProxyExecutable()
Definition: GeneralPage.cpp:95
void browseTorExecutable()
Definition: GeneralPage.cpp:85
QString getExecutable() const
void setExecutable(const QString &torExecutable)
void setRunProxyAtStart(bool run)
QString getProxyExecutable() const
QString getProxyExecutableArguments() const
void setProxyExecutable(const QString &proxyExecutable)
void setRunVidaliaOnBoot(bool run)
void setRunTorAtStart(bool run)
void setProxyExecutableArguments(const QString &proxyExecutableArguments)