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.
29 import subprocess, time, shutil
36 def __init__(self, common):
40 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
41 self.window.set_title(_("Tor Browser Launcher Settings"))
42 self.window.set_icon_from_file(self.common.paths['icon_file'])
43 self.window.set_position(gtk.WIN_POS_CENTER)
44 self.window.set_border_width(10)
45 self.window.connect("delete_event", self.delete_event)
46 self.window.connect("destroy", self.destroy)
48 # build the rest of the UI
49 self.box = gtk.VBox(False, 10)
50 self.window.add(self.box)
53 self.hbox = gtk.HBox(False, 10)
54 self.box.pack_start(self.hbox, True, True, 0)
57 self.settings_box = gtk.VBox(False, 10)
58 self.hbox.pack_start(self.settings_box, True, True, 0)
59 self.settings_box.show()
61 self.status_box = gtk.VBox(False, 10)
62 self.hbox.pack_start(self.status_box, True, True, 0)
63 self.status_box.show()
65 # download over system tor
68 self.txsocks_found = True
70 self.txsocks_found = False
71 self.tor_download_checkbox = gtk.CheckButton(_("Download over system Tor"))
72 if self.txsocks_found:
73 self.tor_download_checkbox.set_tooltip_text(_("This option is only available when using a system wide Tor installation."))
75 self.tor_download_checkbox.set_tooltip_text(_("This option requires the python-txsocksx package."))
77 self.settings_box.pack_start(self.tor_download_checkbox, True, True, 0)
78 if self.common.settings['download_over_tor'] and self.txsocks_found:
79 self.tor_download_checkbox.set_active(True)
81 self.tor_download_checkbox.set_active(False)
83 if self.txsocks_found == False:
84 self.tor_download_checkbox.set_sensitive(False)
86 self.tor_download_checkbox.show()
89 self.modem_checkbox = gtk.CheckButton(_("Play modem sound, because Tor is slow :]"))
90 self.settings_box.pack_start(self.modem_checkbox, True, True, 0)
94 if self.common.settings['modem_sound']:
95 self.modem_checkbox.set_active(True)
97 self.modem_checkbox.set_active(False)
99 self.modem_checkbox.set_active(False)
100 self.modem_checkbox.set_sensitive(False)
101 self.modem_checkbox.set_tooltip_text(_("This option requires python-pygame to be installed"))
102 self.modem_checkbox.show()
104 # force en-US, only display if language isn't already en-US
105 if self.common.language != 'en-US':
106 self.force_en_checkbox = gtk.CheckButton(_("Force downloading English version of Tor Browser"))
107 if self.common.settings['force_en-US']:
108 self.force_en_checkbox.set_active(True)
110 self.force_en_checkbox.set_active(False)
111 self.settings_box.pack_start(self.force_en_checkbox, True, True, 0)
112 self.force_en_checkbox.show()
115 self.tor_addr_box = gtk.HBox(False, 10)
116 self.settings_box.pack_start(self.tor_addr_box, True, True, 0)
117 self.tor_addr_box.show()
119 self.tor_addr_label = gtk.Label(_('Tor server'))
120 self.tor_addr_label.set_line_wrap(True)
121 self.tor_addr_box.pack_start(self.tor_addr_label, True, True, 0)
122 self.tor_addr_label.show()
124 self.tor_addr = gtk.Entry()
125 self.tor_addr.set_text(self.common.settings['tor_socks_address'])
126 self.tor_addr_box.pack_start(self.tor_addr, True, True, 0)
130 if(self.common.settings['installed']):
131 self.status_label = gtk.Label(_('Status: Installed'))
133 self.status_label = gtk.Label(_('Status: Not Installed'))
134 self.status_label.set_line_wrap(True)
135 self.status_box.pack_start(self.status_label, True, True, 0)
136 self.status_label.show()
138 if(self.common.settings['installed']):
140 reinstall_image = gtk.Image()
141 reinstall_image.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
142 self.reinstall_button = gtk.Button(_("Reinstall Tor Browser"))
143 self.reinstall_button.set_image(reinstall_image)
144 self.reinstall_button.connect("clicked", self.reinstall, None)
145 self.status_box.add(self.reinstall_button)
146 self.reinstall_button.show()
149 install_image = gtk.Image()
150 install_image.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
151 self.install_button = gtk.Button(_("Install Tor Browser"))
152 self.install_button.set_image(install_image)
153 self.install_button.connect("clicked", self.install, None)
154 self.status_box.add(self.install_button)
155 self.install_button.show()
158 self.mirrors_box = gtk.HBox(False, 10)
159 self.box.pack_start(self.mirrors_box, True, True, 0)
160 self.mirrors_box.show()
162 self.mirrors_label = gtk.Label(_('Mirror'))
163 self.mirrors_label.set_line_wrap(True)
164 self.mirrors_box.pack_start(self.mirrors_label, True, True, 0)
165 self.mirrors_label.show()
167 self.mirrors = gtk.combo_box_new_text()
168 for mirror in self.common.mirrors:
169 self.mirrors.append_text(mirror)
170 if self.common.settings['mirror'] in self.common.mirrors:
171 self.mirrors.set_active(self.common.mirrors.index(self.common.settings['mirror']))
173 self.mirrors.set_active(0)
174 self.mirrors_box.pack_start(self.mirrors, True, True, 0)
178 self.button_box = gtk.HButtonBox()
179 self.button_box.set_layout(gtk.BUTTONBOX_SPREAD)
180 self.box.pack_start(self.button_box, True, True, 0)
181 self.button_box.show()
183 # save and exit button
184 save_exit_image = gtk.Image()
185 save_exit_image.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
186 self.save_exit_button = gtk.Button(_("Save & Exit"))
187 self.save_exit_button.set_image(save_exit_image)
188 self.save_exit_button.connect("clicked", self.save_exit, None)
189 self.button_box.add(self.save_exit_button)
190 self.save_exit_button.show()
193 cancel_image = gtk.Image()
194 cancel_image.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON)
195 self.cancel_button = gtk.Button(_("Cancel"))
196 self.cancel_button.set_image(cancel_image)
197 self.cancel_button.connect("clicked", self.destroy, None)
198 self.button_box.add(self.cancel_button)
199 self.cancel_button.show()
207 # UI Callback for update over tor/use system tor
208 def on_system_tor_clicked(self, event):
209 if self.txsocks_found:
210 value = self.system_tor_checkbox.get_active()
214 self.tor_download_checkbox.set_active(value)
215 self.tor_download_checkbox.set_sensitive(value)
218 def install(self, widget, data=None):
220 subprocess.Popen([self.common.paths['tbl_bin']])
224 def reinstall(self, widget, data=None):
226 shutil.rmtree(self.common.paths['tbb']['dir'])
227 subprocess.Popen([self.common.paths['tbl_bin']])
231 def save_exit(self, widget, data=None):
238 self.common.settings['download_over_tor'] = self.tor_download_checkbox.get_active()
239 self.common.settings['modem_sound'] = self.modem_checkbox.get_active()
240 if hasattr(self, 'force_en_checkbox'):
241 self.common.settings['force_en-US'] = self.force_en_checkbox.get_active()
243 self.common.settings['force_en-US'] = False
244 self.common.settings['tor_socks_address'] = self.tor_addr.get_text()
246 # figure out the selected mirror
247 self.common.settings['mirror'] = self.common.mirrors[self.mirrors.get_active()]
250 self.common.save_settings()
253 def delete_event(self, widget, event, data=None):
256 def destroy(self, widget, data=None):