3 https://github.com/micahflee/torbrowser-launcher/
5 Copyright (c) 2013-2021 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):
40 def __init__(self, common, app):
41 super(Settings, self).__init__()
47 self.setWindowTitle(_("Tor Browser Launcher Settings"))
48 self.setWindowIcon(QtGui.QIcon(self.common.paths["icon_file"]))
50 # Download over system tor
51 self.tor_download_checkbox = QtWidgets.QCheckBox(_("Download over system Tor"))
52 if self.common.settings["download_over_tor"]:
53 self.tor_download_checkbox.setCheckState(QtCore.Qt.Checked)
55 self.tor_download_checkbox.setCheckState(QtCore.Qt.Unchecked)
57 # Force en-US, only display if language isn't already en-US
58 self.force_en_checkbox = QtWidgets.QCheckBox(
59 _("Force downloading English version of Tor Browser")
61 if self.common.settings["force_en-US"]:
62 self.force_en_checkbox.setCheckState(QtCore.Qt.Checked)
64 self.force_en_checkbox.setCheckState(QtCore.Qt.Unchecked)
65 if self.common.language == "en-US":
66 self.force_en_checkbox.hide()
69 tor_addr_label = QtWidgets.QLabel(_("Tor server"))
70 self.tor_addr = QtWidgets.QLineEdit()
71 self.tor_addr.setText(self.common.settings["tor_socks_address"])
72 tor_addr_layout = QtWidgets.QHBoxLayout()
73 tor_addr_layout.addWidget(tor_addr_label)
74 tor_addr_layout.addWidget(self.tor_addr)
77 settings_layout = QtWidgets.QVBoxLayout()
78 settings_layout.addWidget(self.tor_download_checkbox)
79 settings_layout.addWidget(self.force_en_checkbox)
80 settings_layout.addLayout(tor_addr_layout)
83 status_label = QtWidgets.QLabel()
84 if self.common.settings["installed"]:
85 status_label.setText(_("Status: Installed"))
87 status_label.setText(_("Status: Not Installed"))
90 install_button = QtWidgets.QPushButton(_("Install Tor Browser"))
91 install_button.setIcon(
92 self.style().standardIcon(QtWidgets.QStyle.SP_DialogApplyButton)
94 install_button.clicked.connect(self.install)
97 reinstall_button = QtWidgets.QPushButton(_("Reinstall Tor Browser"))
98 reinstall_button.setIcon(
99 self.style().standardIcon(QtWidgets.QStyle.SP_DialogApplyButton)
101 reinstall_button.clicked.connect(self.reinstall)
103 if self.common.settings["installed"]:
104 install_button.hide()
105 reinstall_button.show()
107 install_button.show()
108 reinstall_button.hide()
111 status_layout = QtWidgets.QVBoxLayout()
112 status_layout.addWidget(status_label)
113 status_layout.addWidget(install_button)
114 status_layout.addWidget(reinstall_button)
117 top_layout = QtWidgets.QHBoxLayout()
118 top_layout.addLayout(settings_layout)
119 top_layout.addLayout(status_layout)
122 mirror_label = QtWidgets.QLabel(_("Mirror"))
124 self.mirror = QtWidgets.QComboBox()
125 for mirror in self.common.mirrors:
126 self.mirror.addItem(mirror)
128 if self.common.settings["mirror"] in self.common.mirrors:
129 self.mirror.setCurrentIndex(
130 self.mirror.findText(self.common.settings["mirror"])
133 self.mirror.setCurrentIndex(0)
135 mirror_layout = QtWidgets.QHBoxLayout()
136 mirror_layout.addWidget(mirror_label)
137 mirror_layout.addWidget(self.mirror)
140 self.save_exit_button = QtWidgets.QPushButton(_("Save && Exit"))
141 self.save_exit_button.setIcon(
142 self.style().standardIcon(QtWidgets.QStyle.SP_DialogApplyButton)
144 self.save_exit_button.clicked.connect(self.save_exit)
147 self.cancel_button = QtWidgets.QPushButton(_("Cancel"))
148 self.cancel_button.setIcon(
149 self.style().standardIcon(QtWidgets.QStyle.SP_DialogCancelButton)
151 self.cancel_button.clicked.connect(self.close)
154 buttons_layout = QtWidgets.QHBoxLayout()
155 buttons_layout.addWidget(self.save_exit_button)
156 buttons_layout.addWidget(self.cancel_button)
159 layout = QtWidgets.QVBoxLayout()
160 layout.addLayout(top_layout)
161 layout.addLayout(mirror_layout)
162 layout.addLayout(buttons_layout)
164 central_widget = QtWidgets.QWidget()
165 central_widget.setLayout(layout)
166 self.setCentralWidget(central_widget)
171 subprocess.Popen([self.common.paths["tbl_bin"]])
177 shutil.rmtree(self.common.paths["tbb"]["dir"])
178 subprocess.Popen([self.common.paths["tbl_bin"]])
189 self.common.settings[
191 ] = self.tor_download_checkbox.isChecked()
192 self.common.settings["force_en-US"] = self.force_en_checkbox.isChecked()
193 self.common.settings["tor_socks_address"] = self.tor_addr.text()
195 # Figure out the selected mirror
196 self.common.settings["mirror"] = self.mirror.currentText()
199 self.common.save_settings()