3 https://github.com/micahflee/torbrowser-launcher/
5 Copyright (c) 2013-2014 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
36 def __init__(self, common):
37 print _('Starting settings dialog')
41 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
42 self.window.set_title(_("Tor Browser Launcher Settings"))
43 self.window.set_icon_from_file(self.common.paths['icon_file'])
44 self.window.set_position(gtk.WIN_POS_CENTER)
45 self.window.set_border_width(10)
46 self.window.connect("delete_event", self.delete_event)
47 self.window.connect("destroy", self.destroy)
49 # build the rest of the UI
50 self.box = gtk.VBox(False, 10)
51 self.window.add(self.box)
54 self.hbox = gtk.HBox(False, 10)
55 self.box.pack_start(self.hbox, True, True, 0)
58 self.settings_box = gtk.VBox(False, 10)
59 self.hbox.pack_start(self.settings_box, True, True, 0)
60 self.settings_box.show()
62 self.labels_box = gtk.VBox(False, 10)
63 self.hbox.pack_start(self.labels_box, True, True, 0)
64 self.labels_box.show()
69 self.txsocks_found = True
71 self.txsocks_found = False
72 self.tor_update_checkbox = gtk.CheckButton(_("Download updates over Tor (recommended)"))
73 if self.txsocks_found:
74 self.tor_update_checkbox.set_tooltip_text(_("This option is only available when using a system wide Tor installation."))
76 self.tor_update_checkbox.set_tooltip_text(_("This option requires the python-txsocksx package."))
78 self.settings_box.pack_start(self.tor_update_checkbox, True, True, 0)
79 if self.common.settings['update_over_tor'] and self.txsocks_found:
80 self.tor_update_checkbox.set_active(True)
82 self.tor_update_checkbox.set_active(False)
84 if self.txsocks_found == False:
85 self.tor_update_checkbox.set_sensitive(False)
87 self.tor_update_checkbox.show()
90 self.update_checkbox = gtk.CheckButton(_("Check for updates next launch"))
91 self.settings_box.pack_start(self.update_checkbox, True, True, 0)
92 if self.common.settings['check_for_updates']:
93 self.update_checkbox.set_active(True)
95 self.update_checkbox.set_active(False)
96 self.update_checkbox.show()
99 self.modem_checkbox = gtk.CheckButton(_("Play modem sound, because Tor is slow :]"))
100 self.settings_box.pack_start(self.modem_checkbox, True, True, 0)
104 if self.common.settings['modem_sound']:
105 self.modem_checkbox.set_active(True)
107 self.modem_checkbox.set_active(False)
109 self.modem_checkbox.set_active(False)
110 self.modem_checkbox.set_sensitive(False)
111 self.modem_checkbox.set_tooltip_text(_("This option requires python-pygame to be installed"))
112 self.modem_checkbox.show()
115 if(self.common.settings['installed_version']):
116 self.label1 = gtk.Label(_('Installed version:\n{0}').format(self.common.settings['installed_version']))
118 self.label1 = gtk.Label(_('Not installed'))
119 self.label1.set_line_wrap(True)
120 self.labels_box.pack_start(self.label1, True, True, 0)
123 if(self.common.settings['last_update_check_timestamp'] > 0):
124 self.label1 = gtk.Label(_('Last checked for updates:\n{0}').format(time.strftime("%B %d, %Y %I:%M %P", time.gmtime(self.common.settings['last_update_check_timestamp']))))
126 self.label1 = gtk.Label(_('Never checked for updates'))
127 self.label1.set_line_wrap(True)
128 self.labels_box.pack_start(self.label1, True, True, 0)
132 self.mirrors_box = gtk.HBox(False, 10)
133 self.box.pack_start(self.mirrors_box, True, True, 0)
134 self.mirrors_box.show()
136 self.mirrors_label = gtk.Label(_('Mirror'))
137 self.mirrors_label.set_line_wrap(True)
138 self.mirrors_box.pack_start(self.mirrors_label, True, True, 0)
139 self.mirrors_label.show()
141 self.mirrors = gtk.combo_box_new_text()
142 for mirror in self.common.mirrors:
143 self.mirrors.append_text(mirror)
144 if self.common.settings['mirror'] in self.common.mirrors:
145 self.mirrors.set_active(self.common.mirrors.index(self.common.settings['mirror']))
147 self.mirrors.set_active(0)
148 self.mirrors_box.pack_start(self.mirrors, True, True, 0)
152 self.button_box = gtk.HButtonBox()
153 self.button_box.set_layout(gtk.BUTTONBOX_SPREAD)
154 self.box.pack_start(self.button_box, True, True, 0)
155 self.button_box.show()
157 # save and launch button
158 save_launch_image = gtk.Image()
159 save_launch_image.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
160 self.save_launch_button = gtk.Button(_("Launch Tor Browser"))
161 self.save_launch_button.set_image(save_launch_image)
162 self.save_launch_button.connect("clicked", self.save_launch, None)
163 self.button_box.add(self.save_launch_button)
164 self.save_launch_button.show()
166 # save and exit button
167 save_exit_image = gtk.Image()
168 save_exit_image.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
169 self.save_exit_button = gtk.Button(_("Save & Exit"))
170 self.save_exit_button.set_image(save_exit_image)
171 self.save_exit_button.connect("clicked", self.save_exit, None)
172 self.button_box.add(self.save_exit_button)
173 self.save_exit_button.show()
176 cancel_image = gtk.Image()
177 cancel_image.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON)
178 self.cancel_button = gtk.Button(_("Cancel"))
179 self.cancel_button.set_image(cancel_image)
180 self.cancel_button.connect("clicked", self.destroy, None)
181 self.button_box.add(self.cancel_button)
182 self.cancel_button.show()
190 # UI Callback for update over tor/use system tor
191 def on_system_tor_clicked(self, event):
192 if self.txsocks_found:
193 value = self.system_tor_checkbox.get_active()
197 self.tor_update_checkbox.set_active(value)
198 self.tor_update_checkbox.set_sensitive(value)
201 def save_launch(self, widget, data=None):
203 subprocess.Popen([self.common.paths['tbl_bin']])
207 def save_exit(self, widget, data=None):
214 self.common.settings['update_over_tor'] = self.tor_update_checkbox.get_active()
215 self.common.settings['check_for_updates'] = self.update_checkbox.get_active()
216 self.common.settings['modem_sound'] = self.modem_checkbox.get_active()
218 # figure out the selected mirror
219 self.common.settings['mirror'] = self.common.mirrors[self.mirrors.get_active()]
222 self.common.save_settings()
225 def delete_event(self, widget, event, data=None):
228 def destroy(self, widget, data=None):