3
"""prefs_curses.py -- Pretty, tabbable, console preferences dialog"""
5
# Copyright (C) 2008-2009 Andrew Psaltis
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23
import urwid.curses_display
26
from wicd import dbusmanager
27
from curses_misc import SelText,DynWrap,DynRadioButton,ComboBox,TabColumns
33
from wicd.translations import language
35
class PrefsDialog(urwid.WidgetWrap):
36
def __init__(self,body,pos,ui,dbus=None):
37
global daemon, wireless, wired
39
daemon = dbus['daemon']
40
wireless = dbus['wireless']
43
width,height = ui.get_cols_rows()
47
# Stuff that goes at the top
49
header0_t = language["gen_settings"]
50
header1_t = language["ext_programs"]
51
header2_t = language["advanced_settings"]
52
self.header0 = urwid.AttrWrap(SelText(header0_t),'tab active','focus')
53
self.header1 = urwid.AttrWrap(SelText(header1_t),'body','focus')
54
self.header2 = urwid.AttrWrap(SelText(header2_t),'body','focus')
55
title = language['preferences']
58
_blank = urwid.Text('')
61
#### Text in the widgets
65
net_cat_t = ('header',language['network_interfaces'])
66
wired_t = ('editcp',language['wired_interface']+': ')
67
wless_t = ('editcp',language['wireless_interface']+':')
68
always_show_wired_t = language['wired_always_on']
69
prefer_wired_t = language['always_switch_to_wired']
71
global_dns_cat_t = ('header',language['global_dns_servers'])
72
global_dns_t = ('editcp',language['use_global_dns'])
73
dns_dom_t = ('editcp',' '+language['dns_domain']+': ')
74
search_dom_t = ('editcp',' '+language['search_domain']+':')
75
dns1_t = ('editcp',' DNS server 1: ')
76
dns2_t = ('editcp',' DNS server 2: ')
77
dns3_t = ('editcp',' DNS server 3: ')
80
wired_auto_cat_t= ('header',language['wired_autoconnect_settings'])
81
wired_auto_1_t = language['use_default_profile']
82
wired_auto_2_t = language['show_wired_list']
83
wired_auto_3_t = language['use_last_used_profile']
85
auto_reconn_cat_t = ('header',language['automatic_reconnection'])
86
auto_reconn_t = language['auto_reconnect']
88
#### External Programs
89
automatic_t = language['wicd_auto_config']
91
dhcp_header_t = ('header',language["dhcp_client"])
98
wired_detect_header_t = ('header',language["wired_detect"])
100
wired2_t = 'mii-tool'
102
flush_header_t = ('header',language["route_flush"])
106
#### Advanced Settings
107
#wpa_t=('editcp',language['wpa_supplicant_driver']+':')
108
wpa_cat_t=('header',language['wpa_supplicant'])
109
wpa_t=('editcp','Driver:')
110
wpa_list = ['spam','double spam','triple spam','quadruple spam']
111
wpa_warn_t = ('important',language['always_use_wext'])
113
backend_cat_t = ('header',language['backend'])
114
backend_t = language['backend']+':'
115
backend_list = ['spam','double spam','triple spam','quadruple spam']
116
#backend_warn_t = ('important',
117
# 'Changes to the backend (probably) requires a daemon restart')
119
debug_cat_t = ('header',language['debugging'])
120
debug_mode_t = language['use_debug_mode']
122
wless_cat_t = ('header',language['wireless_interface'])
123
use_dbm_t = language['display_type_dialog']
132
self.net_cat = urwid.Text(net_cat_t)
133
self.wired_edit = urwid.AttrWrap(urwid.Edit(wired_t),'editbx','editfc')
134
self.wless_edit = urwid.AttrWrap(urwid.Edit(wless_t),'editbx','editfc')
135
self.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t)
136
self.global_dns_cat = urwid.Text(global_dns_cat_t)
137
# Default the global DNS settings to off. They will be reenabled later
139
global_dns_state = False
140
self.global_dns_checkb = urwid.CheckBox(global_dns_t,global_dns_state,
141
on_state_change=self.global_dns_trigger)
142
self.search_dom = DynWrap(urwid.Edit(search_dom_t),global_dns_state)
143
self.dns_dom = DynWrap(urwid.Edit(dns_dom_t),global_dns_state)
144
self.dns1 = DynWrap(urwid.Edit(dns1_t),global_dns_state)
145
self.dns2 = DynWrap(urwid.Edit(dns2_t),global_dns_state)
146
self.dns3 = DynWrap(urwid.Edit(dns3_t),global_dns_state)
149
self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)
151
self.wired_auto_l = []
152
self.wired_auto_cat= urwid.Text(wired_auto_cat_t)
153
self.wired_auto_1 = urwid.RadioButton(self.wired_auto_l,wired_auto_1_t)
154
self.wired_auto_2 = urwid.RadioButton(self.wired_auto_l,wired_auto_2_t)
155
self.wired_auto_3 = urwid.RadioButton(self.wired_auto_l,wired_auto_3_t)
157
self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
158
self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
159
generalLB = urwid.ListBox([self.net_cat,
160
self.wless_edit,#_blank,
162
self.always_show_wired_checkb,
163
self.prefer_wired_chkbx,_blank,
165
self.global_dns_checkb,#_blank,
166
self.search_dom,self.dns_dom,
167
self.dns1,self.dns2,self.dns3,_blank,
171
self.wired_auto_3, _blank,
172
self.auto_reconn_cat,
173
self.auto_reconn_checkb
176
#### External Programs tab
177
automatic_t = language['wicd_auto_config']
179
self.dhcp_header = urwid.Text(dhcp_header_t)
182
# Order of these is flipped in the actual interface,
183
# (2,3,1 -> dhcpcd, pump, dhclient), because dhclient often doesn't like
184
# to work on several distros.
185
self.dhcp0 = urwid.RadioButton(self.dhcp_l,automatic_t)
186
self.dhcp1 = DynRadioButton(self.dhcp_l,dhcp1_t)
187
self.dhcp2 = DynRadioButton(self.dhcp_l,dhcp2_t)
188
self.dhcp3 = DynRadioButton(self.dhcp_l,dhcp3_t)
189
self.dhcp4 = DynRadioButton(self.dhcp_l,dhcp4_t)
190
self.dhcp_l = [self.dhcp0,self.dhcp1,self.dhcp2,self.dhcp3,self.dhcp4]
193
self.wired_detect_header = urwid.Text(wired_detect_header_t)
194
self.wired0 = urwid.RadioButton(self.wired_l,automatic_t)
195
self.wired1 = DynRadioButton(self.wired_l,wired1_t)
196
self.wired2 = DynRadioButton(self.wired_l,wired2_t)
197
self.wired_l = [self.wired0,self.wired1,self.wired2]
200
self.flush_header = urwid.Text(flush_header_t)
201
self.flush0 = urwid.RadioButton(self.flush_l,automatic_t)
202
self.flush1 = DynRadioButton(self.flush_l,flush1_t)
203
self.flush2 = DynRadioButton(self.flush_l,flush2_t)
204
self.flush_l = [self.flush0,self.flush1,self.flush2]
206
externalLB = urwid.ListBox([self.dhcp_header,
207
self.dhcp0,self.dhcp2,self.dhcp3,self.dhcp1,self.dhcp4,
209
self.wired_detect_header,
210
self.wired0,self.wired1,self.wired2,
213
self.flush0,self.flush1,self.flush2
217
#### Advanced settings
218
self.wpa_cat = urwid.Text(wpa_cat_t)
219
self.wpa_cbox = ComboBox(wpa_t)
220
self.wpa_warn = urwid.Text(wpa_warn_t)
222
self.backend_cat = urwid.Text(backend_cat_t)
223
self.backend_cbox = ComboBox(backend_t)
225
self.debug_cat = urwid.Text(debug_cat_t)
226
self.debug_mode_checkb = urwid.CheckBox(debug_mode_t)
228
self.wless_cat = urwid.Text(wless_cat_t)
229
self.use_dbm_checkb = urwid.CheckBox(use_dbm_t)
232
advancedLB = urwid.ListBox([self.wpa_cat,
233
self.wpa_cbox,self.wpa_warn,_blank,
235
self.backend_cbox,_blank,
237
self.debug_mode_checkb, _blank,
239
self.use_dbm_checkb, _blank
243
headerList = [self.header0,self.header1,self.header2]
244
lbList = [generalLB,externalLB,advancedLB]
245
self.tab_map = {self.header0 : generalLB,
246
self.header1 : externalLB,
247
self.header2 : advancedLB}
248
#self.load_settings()
250
self.tabs = TabColumns(headerList,lbList,language['preferences'])
251
self.__super.__init__(self.tabs)
253
def load_settings(self):
256
# ComboBox does not like dbus.Strings as text markups. My fault. :/
257
wless_iface = unicode(daemon.GetWirelessInterface())
258
wired_iface = unicode(daemon.GetWiredInterface())
259
self.wless_edit.set_edit_text(wless_iface)
260
self.wired_edit.set_edit_text(wired_iface)
262
self.always_show_wired_checkb.set_state(
263
daemon.GetAlwaysShowWiredInterface())
264
self.prefer_wired_chkbx.set_state(daemon.GetPreferWiredNetwork())
266
self.global_dns_checkb.set_state(daemon.GetUseGlobalDNS())
267
theDNS = daemon.GetGlobalDNSAddresses()
270
for w in self.dns1,self.dns2,self.dns3,self.dns_dom,self.search_dom :
271
w.set_edit_text(misc.noneToBlankString(theDNS[i]))
274
# Wired Automatic Connection
275
self.wired_auto_l[daemon.GetWiredAutoConnectMethod()-1]
276
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
278
def find_avail(apps):
280
app.set_sensitive(daemon.GetAppAvailable(app.get_label()))
282
### External Programs
283
find_avail(self.dhcp_l)
284
dhcp_method = daemon.GetDHCPClient()
285
self.dhcp_l[dhcp_method].set_state(True)
287
find_avail(self.wired_l)
288
wired_link_method = daemon.GetLinkDetectionTool()
289
self.wired_l[wired_link_method].set_state(True)
291
find_avail(self.flush_l)
292
flush_method = daemon.GetFlushTool()
293
self.flush_l[flush_method].set_state(True)
295
### Advanced settings
296
# wpa_supplicant janx
297
self.wpadrivers = ["wext", "hostap", "madwifi", "atmel",
298
"ndiswrapper", "ipw"]
299
self.wpadrivers = wireless.GetWpaSupplicantDrivers(self.wpadrivers)
300
self.wpadrivers.append("ralink_legacy")
301
# Same as above with the dbus.String
302
self.thedrivers = [unicode(w) for w in self.wpadrivers]
303
self.wpa_cbox.set_list(self.thedrivers)
305
# Pick where to begin first:
306
def_driver = daemon.GetWPADriver()
308
self.wpa_cbox.set_focus(self.wpadrivers.index(def_driver))
310
pass # It defaults to 0 anyway (I hope)
312
self.backends = daemon.GetBackendList()
313
self.thebackends= [unicode(w) for w in self.backends]
314
self.backend_cbox.set_list(self.thebackends)
315
cur_backend = daemon.GetSavedBackend()
317
self.backend_cbox.set_focus(self.thebackends.index(cur_backend))
319
self.backend_cbox.set_focus(0)
321
# Two last checkboxes
322
self.debug_mode_checkb.set_state(daemon.GetDebugMode())
323
self.use_dbm_checkb.set_state(daemon.GetSignalDisplayType())
325
def save_settings(self):
326
""" Pushes the selected settings to the daemon.
327
This exact order is found in prefs.py"""
328
daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state())
329
daemon.SetGlobalDNS(self.dns1.get_edit_text(), self.dns2.get_edit_text(),
330
self.dns3.get_edit_text(), self.dns_dom.get_edit_text(),
331
self.search_dom.get_edit_text())
332
daemon.SetWirelessInterface(self.wless_edit.get_edit_text())
333
daemon.SetWiredInterface(self.wired_edit.get_edit_text())
334
daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_focus()[1]])
335
daemon.SetAlwaysShowWiredInterface(self.always_show_wired_checkb.get_state())
336
daemon.SetAutoReconnect(self.auto_reconn_checkb.get_state())
337
daemon.SetDebugMode(self.debug_mode_checkb.get_state())
338
daemon.SetSignalDisplayType(int(self.use_dbm_checkb.get_state()))
339
daemon.SetPreferWiredNetwork(bool(self.prefer_wired_chkbx.get_state()))
340
if self.wired_auto_2.get_state():
341
daemon.SetWiredAutoConnectMethod(2)
342
elif self.wired_auto_3.get_state():
343
daemon.SetWiredAutoConnectMethod(3)
345
daemon.SetWiredAutoConnectMethod(1)
347
daemon.SetBackend(self.backends[self.backend_cbox.get_focus()[1]])
349
# External Programs Tab
350
if self.dhcp0.get_state():
351
dhcp_client = misc.AUTO
352
elif self.dhcp1.get_state():
353
dhcp_client = misc.DHCLIENT
354
elif self.dhcp2.get_state():
355
dhcp_client = misc.DHCPCD
356
elif self.dhcp3.get_state():
357
dhcp_client = misc.PUMP
359
dhcp_client = misc.UDHCPC
360
daemon.SetDHCPClient(dhcp_client)
362
if self.wired0.get_state():
363
link_tool = misc.AUTO
364
elif self.wired1.get_state():
365
link_tool = misc.ETHTOOL
367
link_tool = misc.MIITOOL
368
daemon.SetLinkDetectionTool(link_tool)
370
if self.flush0.get_state():
371
flush_tool = misc.AUTO
372
elif self.flush1.get_state():
375
flush_tool = misc.ROUTE
376
daemon.SetFlushTool(flush_tool)
378
# DNS CheckBox callback
379
def global_dns_trigger(self,check_box,new_state,user_data=None):
380
for w in self.dns1,self.dns2,self.dns3,self.dns_dom,self.search_dom:
381
w.set_sensitive(new_state)
383
def ready_widgets(self,ui,body):
384
self.wpa_cbox.build_combobox(body,ui,4)
385
self.backend_cbox.build_combobox(body,ui,8)