]> git.lizzy.rs Git - torbrowser-launcher.git/blob - torbrowser_launcher/settings.py
0aba63bf5fd0bde5e4510d1b99ad44c807a1cdb1
[torbrowser-launcher.git] / torbrowser_launcher / settings.py
1 """
2 Tor Browser Launcher
3 https://github.com/micahflee/torbrowser-launcher/
4
5 Copyright (c) 2013-2014 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
30
31 import pygtk
32 pygtk.require('2.0')
33 import gtk
34
35 class Settings:
36     def __init__(self, common):
37         print _('Starting settings dialog')
38         self.common = common
39
40         # set up the window
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)
48
49         # build the rest of the UI
50         self.box = gtk.VBox(False, 10)
51         self.window.add(self.box)
52         self.box.show()
53
54         self.hbox = gtk.HBox(False, 10)
55         self.box.pack_start(self.hbox, True, True, 0)
56         self.hbox.show()
57
58         self.settings_box = gtk.VBox(False, 10)
59         self.hbox.pack_start(self.settings_box, True, True, 0)
60         self.settings_box.show()
61
62         self.labels_box = gtk.VBox(False, 10)
63         self.hbox.pack_start(self.labels_box, True, True, 0)
64         self.labels_box.show()
65
66         # download over tor
67         try:
68             import txsocksx
69             self.txsocks_found = True
70         except ImportError:
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."))
75         else:
76             self.tor_update_checkbox.set_tooltip_text(_("This option requires the python-txsocksx package."))
77
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)
81         else:
82             self.tor_update_checkbox.set_active(False)
83
84         if self.txsocks_found == False:
85             self.tor_update_checkbox.set_sensitive(False)
86
87         self.tor_update_checkbox.show()
88
89         # check for updates
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)
94         else:
95             self.update_checkbox.set_active(False)
96         self.update_checkbox.show()
97
98         # modem sound
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)
101
102         try:
103             import pygame
104             if self.common.settings['modem_sound']:
105                 self.modem_checkbox.set_active(True)
106             else:
107                 self.modem_checkbox.set_active(False)
108         except ImportError:
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()
113
114         # labels
115         if(self.common.settings['installed_version']):
116             self.label1 = gtk.Label(_('Installed version:\n{0}').format(self.common.settings['installed_version']))
117         else:
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)
121         self.label1.show()
122
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']))))
125         else:
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)
129         self.label1.show()
130
131         # mirrors
132         self.mirrors_box = gtk.HBox(False, 10)
133         self.box.pack_start(self.mirrors_box, True, True, 0)
134         self.mirrors_box.show()
135
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()
140
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']))
146         else:
147             self.mirrors.set_active(0)
148         self.mirrors_box.pack_start(self.mirrors, True, True, 0)
149         self.mirrors.show()
150
151         # button box
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()
156
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()
165
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()
174
175         # cancel button
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()
183
184         # show the window
185         self.window.show()
186
187         # start gtk
188         gtk.main()
189
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()
194         else:
195             value = False
196
197         self.tor_update_checkbox.set_active(value)
198         self.tor_update_checkbox.set_sensitive(value)
199
200     # save and launch
201     def save_launch(self, widget, data=None):
202         self.save()
203         subprocess.Popen([self.common.paths['tbl_bin']])
204         self.destroy(False)
205
206     # save and exit
207     def save_exit(self, widget, data=None):
208         self.save()
209         self.destroy(False)
210
211     # save settings
212     def save(self):
213         # checkbox options
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()
217
218         # figure out the selected mirror
219         self.common.settings['mirror'] = self.common.mirrors[self.mirrors.get_active()]
220
221         # save them
222         self.common.save_settings()
223
224     # exit
225     def delete_event(self, widget, event, data=None):
226         return False
227
228     def destroy(self, widget, data=None):
229         gtk.main_quit()
230
231