3 https://github.com/micahflee/torbrowser-launcher/
5 Copyright (c) 2013-2017 Micah Lee <micah@micahflee.com>
7 Permission is hereby granted, free of charge, to any person
8 obtaining a copy of this software and associated documentation
9 files (the "Software"), to deal in the Software without
10 restriction, including without limitation the rights to use,
11 copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the
13 Software is furnished to do so, subject to the following
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 OTHER DEALINGS IN THE SOFTWARE.
32 from PyQt5 import QtCore, QtWidgets, QtGui
35 class Settings(QtWidgets.QMainWindow):
39 def __init__(self, common, app):
40 super(Settings, self).__init__()
46 self.setWindowTitle(_("Tor Browser Launcher Settings"))
47 self.setWindowIcon(QtGui.QIcon(self.common.paths['icon_file']))
49 # Download over system tor
50 self.tor_download_checkbox = QtWidgets.QCheckBox(_("Download over system Tor"))
51 if self.common.settings['download_over_tor']:
52 self.tor_download_checkbox.setCheckState(QtCore.Qt.Checked)
54 self.tor_download_checkbox.setCheckState(QtCore.Qt.Unchecked)
56 # Force en-US, only display if language isn't already en-US
57 self.force_en_checkbox = QtWidgets.QCheckBox(_("Force downloading English version of Tor Browser"))
58 if self.common.settings['force_en-US']:
59 self.force_en_checkbox.setCheckState(QtCore.Qt.Checked)
61 self.force_en_checkbox.setCheckState(QtCore.Qt.Unchecked)
62 if self.common.language == 'en-US':
63 self.force_en_checkbox.hide()
66 tor_addr_label = QtWidgets.QLabel(_('Tor server'))
67 self.tor_addr = QtWidgets.QLineEdit()
68 self.tor_addr.setText(self.common.settings['tor_socks_address'])
69 tor_addr_layout = QtWidgets.QHBoxLayout()
70 tor_addr_layout.addWidget(tor_addr_label)
71 tor_addr_layout.addWidget(self.tor_addr)
74 settings_layout = QtWidgets.QVBoxLayout()
75 settings_layout.addWidget(self.tor_download_checkbox)
76 settings_layout.addWidget(self.force_en_checkbox)
77 settings_layout.addLayout(tor_addr_layout)
80 status_label = QtWidgets.QLabel()
81 if(self.common.settings['installed']):
82 status_label.setText(_('Status: Installed'))
84 status_label.setText(_('Status: Not Installed'))
87 install_button = QtWidgets.QPushButton(_("Install Tor Browser"))
88 install_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_DialogApplyButton))
89 install_button.clicked.connect(self.install)
92 reinstall_button = QtWidgets.QPushButton(_("Reinstall Tor Browser"))
93 reinstall_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_DialogApplyButton))
94 reinstall_button.clicked.connect(self.reinstall)
96 if(self.common.settings['installed']):
98 reinstall_button.show()
100 install_button.show()
101 reinstall_button.hide()
104 status_layout = QtWidgets.QVBoxLayout()
105 status_layout.addWidget(status_label)
106 status_layout.addWidget(install_button)
107 status_layout.addWidget(reinstall_button)
110 top_layout = QtWidgets.QHBoxLayout()
111 top_layout.addLayout(settings_layout)
112 top_layout.addLayout(status_layout)
115 mirror_label = QtWidgets.QLabel(_('Mirror'))
117 self.mirror = QtWidgets.QComboBox()
118 for mirror in self.common.mirrors:
119 self.mirror.addItem(mirror)
121 if self.common.settings['mirror'] in self.common.mirrors:
122 self.mirror.setCurrentIndex(self.mirror.findText(self.common.settings['mirror']))
124 self.mirror.setCurrentIndex(0)
126 mirror_layout = QtWidgets.QHBoxLayout()
127 mirror_layout.addWidget(mirror_label)
128 mirror_layout.addWidget(self.mirror)
131 self.save_exit_button = QtWidgets.QPushButton(_("Save && Exit"))
132 self.save_exit_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_DialogApplyButton))
133 self.save_exit_button.clicked.connect(self.save_exit)
136 self.cancel_button = QtWidgets.QPushButton(_("Cancel"))
137 self.cancel_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_DialogCancelButton))
138 self.cancel_button.clicked.connect(self.close)
141 buttons_layout = QtWidgets.QHBoxLayout()
142 buttons_layout.addWidget(self.save_exit_button)
143 buttons_layout.addWidget(self.cancel_button)
146 layout = QtWidgets.QVBoxLayout()
147 layout.addLayout(top_layout)
148 layout.addLayout(mirror_layout)
149 layout.addLayout(buttons_layout)
151 central_widget = QtWidgets.QWidget()
152 central_widget.setLayout(layout)
153 self.setCentralWidget(central_widget)
158 subprocess.Popen([self.common.paths['tbl_bin']])
164 shutil.rmtree(self.common.paths['tbb']['dir'])
165 subprocess.Popen([self.common.paths['tbl_bin']])
176 self.common.settings['download_over_tor'] = self.tor_download_checkbox.isChecked()
177 self.common.settings['force_en-US'] = self.force_en_checkbox.isChecked()
178 self.common.settings['tor_socks_address'] = self.tor_addr.text()
180 # Figure out the selected mirror
181 self.common.settings['mirror'] = self.mirror.currentText()
184 self.common.save_settings()