Vidalia  0.2.21
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  if (_vidaliaSettings->getBrowserExecutable().length() > 0) {
52  ui.lineHorizontalSeparator->setVisible(false);
53  ui.chkRunVidaliaAtSystemStartup->setVisible(false);
54  }
55 }
56 
57 /** Destructor */
59 {
60  delete _vidaliaSettings;
61  delete _torSettings;
62 }
63 
64 /** Called when the user changes the UI translation. */
65 void
67 {
68  ui.retranslateUi(this);
69 }
70 
71 /** Displays a file dialog allowing the user to browse for an executable
72  * file. <b>caption</b> will be displayed in the dialog's title bar and
73  * <b>file</b>, if specified, is the default file selected in the dialog.
74  */
75 QString
76 GeneralPage::browseExecutable(const QString &caption, const QString &file)
77 {
78 #if defined(Q_OS_WIN32)
79  QString filter = tr("Executables (*.exe)");
80 #else
81  QString filter = "";
82 #endif
83 
84  QString filePath = QFileDialog::getOpenFileName(this, caption, file, filter);
85  return QDir::convertSeparators(filePath);
86 }
87 
88 /** Open a QFileDialog to browse for a Tor executable file. */
89 void
91 {
92  QString filePath = browseExecutable(tr("Select Path to Tor"),
93  ui.lineTorExecutable->text());
94  if (! filePath.isEmpty())
95  ui.lineTorExecutable->setText(filePath);
96 }
97 
98 /** Open a QFileDialog to browse for a proxy executable file. */
99 void
101 {
102  QString filePath = browseExecutable(tr("Select Proxy Executable"),
103  ui.lineProxyExecutable->text());
104 
105  if (! filePath.isEmpty())
106  ui.lineProxyExecutable->setText(filePath);
107 }
108 
109 /** Saves all settings for this page */
110 bool
111 GeneralPage::save(QString &errmsg)
112 {
113  QString torExecutable = ui.lineTorExecutable->text();
114  if (torExecutable.isEmpty()) {
115  errmsg = tr("You must specify the name of your Tor executable.");
116  return false;
117  }
118  if (ui.chkRunProxyAtTorStartup->isChecked()) {
119  _vidaliaSettings->setProxyExecutable(ui.lineProxyExecutable->text());
121  ui.lineProxyExecutableArguments->text());
122  }
123 
124  _torSettings->setExecutable(torExecutable);
125  _vidaliaSettings->setRunTorAtStart(ui.chkRunTorAtVidaliaStartup->isChecked());
127  ui.chkRunVidaliaAtSystemStartup->isChecked());
129  ui.chkRunProxyAtTorStartup->isChecked());
130  return true;
131 }
132 
133 /** Loads previously saved settings */
134 void
136 {
137  ui.chkRunVidaliaAtSystemStartup->setChecked(
139 
140  ui.lineTorExecutable->setText(_torSettings->getExecutable());
141  ui.chkRunTorAtVidaliaStartup->setChecked(_vidaliaSettings->runTorAtStart());
142 
143  ui.lineProxyExecutable->setText(_vidaliaSettings->getProxyExecutable());
144  ui.lineProxyExecutableArguments->setText(
146  ui.chkRunProxyAtTorStartup->setChecked(_vidaliaSettings->runProxyAtStart());
147 }
148 
149 void
151 {
152  emit checkForUpdates();
153 }
154