]> git.lizzy.rs Git - torbrowser-launcher.git/blob - torbrowser_launcher/settings.py
Merge branch 'silence-tor-browser-apparmor-logs' of https://github.com/intrigeri...
[torbrowser-launcher.git] / torbrowser_launcher / settings.py
1 """
2 Tor Browser Launcher
3 https://github.com/micahflee/torbrowser-launcher/
4
5 Copyright (c) 2013-2017 Micah Lee <micah@micahflee.com>
6
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
14 conditions:
15
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
18
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.
27 """
28
29 import subprocess, time, shutil
30
31 import pygtk
32 pygtk.require('2.0')
33 import gtk
34
35 class Settings:
36     def __init__(self, common):
37         self.common = common
38
39         # set up the window
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)
47
48         # build the rest of the UI
49         self.box = gtk.VBox(False, 10)
50         self.window.add(self.box)
51         self.box.show()
52
53         self.hbox = gtk.HBox(False, 10)
54         self.box.pack_start(self.hbox, True, True, 0)
55         self.hbox.show()
56
57         self.settings_box = gtk.VBox(False, 10)
58         self.hbox.pack_start(self.settings_box, True, True, 0)
59         self.settings_box.show()
60
61         self.status_box = gtk.VBox(False, 10)
62         self.hbox.pack_start(self.status_box, True, True, 0)
63         self.status_box.show()
64
65         # download over system tor
66         try:
67             import txsocksx
68             self.txsocks_found = True
69         except ImportError:
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."))
74         else:
75             self.tor_download_checkbox.set_tooltip_text(_("This option requires the python-txsocksx package."))
76
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)
80         else:
81             self.tor_download_checkbox.set_active(False)
82
83         if self.txsocks_found == False:
84             self.tor_download_checkbox.set_sensitive(False)
85
86         self.tor_download_checkbox.show()
87
88         # modem sound
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)
91
92         try:
93             import pygame
94             if self.common.settings['modem_sound']:
95                 self.modem_checkbox.set_active(True)
96             else:
97                 self.modem_checkbox.set_active(False)
98         except ImportError:
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()
103
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)
109             else:
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()
113
114         # Tor SOCKS address
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()
118
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()
123
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)
127         self.tor_addr.show()
128
129         # status
130         if(self.common.settings['installed']):
131             self.status_label = gtk.Label(_('Status: Installed'))
132         else:
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()
137
138         if(self.common.settings['installed']):
139            # reinstall button
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()
147         else:
148             # install button
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()
156
157         # mirrors
158         self.mirrors_box = gtk.HBox(False, 10)
159         self.box.pack_start(self.mirrors_box, True, True, 0)
160         self.mirrors_box.show()
161
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()
166
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']))
172         else:
173             self.mirrors.set_active(0)
174         self.mirrors_box.pack_start(self.mirrors, True, True, 0)
175         self.mirrors.show()
176
177         # button box
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()
182
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()
191
192         # cancel button
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()
200
201         # show the window
202         self.window.show()
203
204         # start gtk
205         gtk.main()
206
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()
211         else:
212             value = False
213
214         self.tor_download_checkbox.set_active(value)
215         self.tor_download_checkbox.set_sensitive(value)
216
217     # install
218     def install(self, widget, data=None):
219         self.save()
220         subprocess.Popen([self.common.paths['tbl_bin']])
221         self.destroy(False)
222
223     # launch
224     def reinstall(self, widget, data=None):
225         self.save()
226         shutil.rmtree(self.common.paths['tbb']['dir'])
227         subprocess.Popen([self.common.paths['tbl_bin']])
228         self.destroy(False)
229
230     # save and exit
231     def save_exit(self, widget, data=None):
232         self.save()
233         self.destroy(False)
234
235     # save settings
236     def save(self):
237         # checkbox options
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()
242         else:
243             self.common.settings['force_en-US'] = False
244         self.common.settings['tor_socks_address'] = self.tor_addr.get_text()
245
246         # figure out the selected mirror
247         self.common.settings['mirror'] = self.common.mirrors[self.mirrors.get_active()]
248
249         # save them
250         self.common.save_settings()
251
252     # exit
253     def delete_event(self, widget, event, data=None):
254         return False
255
256     def destroy(self, widget, data=None):
257         gtk.main_quit()