3
""" prefs -- Wicd Preferences Dialog.
5
Displays the main settings dialog window for wicd and
6
handles recieving/sendings the settings from/to the daemon.
11
# Copyright (C) 2008-2009 Adam Blackburn
12
# Copyright (C) 2008-2009 Dan O'Reilly
14
# This program is free software; you can redistribute it and/or modify
15
# it under the terms of the GNU General Public License Version 2 as
16
# published by the Free Software Foundation.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program. If not, see <http://www.gnu.org/licenses/>.
34
from wicd import wpath
35
from wicd import dbusmanager
36
from wicd.misc import checkboxTextboxToggle, noneToBlankString
42
from translations import language
44
USER_SETTINGS_DIR = os.path.expanduser('~/.wicd/')
47
global daemon, wireless, wired
48
daemon = dbusmanager.get_interface('daemon')
49
wireless = dbusmanager.get_interface('wireless')
50
wired = dbusmanager.get_interface('wired')
52
class PreferencesDialog(object):
53
""" Class for handling the wicd preferences dialog window. """
54
def __init__(self, parent, wTree):
58
self.prep_settings_diag()
59
self.load_preferences_diag()
61
def _setup_external_app_radios(self, radio_list, get_method, set_method):
62
""" Generic function for setting up external app radios. """
63
# Disable radios for apps that aren't installed.
64
for app in radio_list[1:]:
65
app.set_sensitive(daemon.GetAppAvailable(app.get_label()))
66
selected_app = get_method()
67
# Make sure the app we want to select is actually available.
68
if radio_list[selected_app].get_property("sensitive"):
69
radio_list[selected_app].set_active(True)
71
# If it isn't, default to Automatic.
73
radio_list[misc.AUTO].set_active(True)
75
def load_preferences_diag(self):
76
""" Loads data into the preferences Dialog. """
78
self.wiredcheckbox.set_active(daemon.GetAlwaysShowWiredInterface())
79
self.reconnectcheckbox.set_active(daemon.GetAutoReconnect())
80
self.debugmodecheckbox.set_active(daemon.GetDebugMode())
81
self.displaytypecheckbox.set_active(daemon.GetSignalDisplayType())
82
self.preferwiredcheckbox.set_active(daemon.GetPreferWiredNetwork())
84
dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio,
85
self.pumpradio, self.udhcpcradio]
86
self._setup_external_app_radios(dhcp_list, daemon.GetDHCPClient,
89
wired_link_list = [self.linkautoradio, self.ethtoolradio,
91
self._setup_external_app_radios(wired_link_list,
92
daemon.GetLinkDetectionTool,
93
daemon.SetLinkDetectionTool)
95
flush_list = [self.flushautoradio, self.ipflushradio,
97
self._setup_external_app_radios(flush_list, daemon.GetFlushTool,
100
sudo_list = [self.sudoautoradio, self.gksudoradio, self.kdesuradio,
102
self._setup_external_app_radios(sudo_list, daemon.GetSudoApp,
105
auto_conn_meth = daemon.GetWiredAutoConnectMethod()
106
if auto_conn_meth == 1:
107
self.usedefaultradiobutton.set_active(True)
108
elif auto_conn_meth == 2:
109
self.showlistradiobutton.set_active(True)
110
elif auto_conn_meth == 3:
111
self.lastusedradiobutton.set_active(True)
113
self.entryWirelessInterface.set_text(daemon.GetWirelessInterface())
114
self.entryWiredInterface.set_text(daemon.GetWiredInterface())
116
def_driver = daemon.GetWPADriver()
118
self.wpadrivercombo.set_active(self.wpadrivers.index(def_driver))
120
self.wpadrivercombo.set_active(0)
122
self.useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
123
(self.dns1Entry, self.dns2Entry,
124
self.dns3Entry, self.dnsDomEntry,
125
self.searchDomEntry))
127
dns_addresses = daemon.GetGlobalDNSAddresses()
128
self.useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
129
self.dns1Entry.set_text(noneToBlankString(dns_addresses[0]))
130
self.dns2Entry.set_text(noneToBlankString(dns_addresses[1]))
131
self.dns3Entry.set_text(noneToBlankString(dns_addresses[2]))
132
self.dnsDomEntry.set_text(noneToBlankString(dns_addresses[3]))
133
self.searchDomEntry.set_text(noneToBlankString(dns_addresses[4]))
135
if not daemon.GetUseGlobalDNS():
136
self.searchDomEntry.set_sensitive(False)
137
self.dnsDomEntry.set_sensitive(False)
138
self.dns1Entry.set_sensitive(False)
139
self.dns2Entry.set_sensitive(False)
140
self.dns3Entry.set_sensitive(False)
142
cur_backend = daemon.GetSavedBackend()
144
self.backendcombo.set_active(self.backends.index(cur_backend))
146
self.backendcombo.set_active(0)
148
self.notificationscheckbox.set_active(
150
os.path.join(USER_SETTINGS_DIR, 'USE_NOTIFICATIONS')
153
# if pynotify isn't installed disable the option
157
self.notificationscheckbox.set_active(False)
158
self.notificationscheckbox.set_sensitive(False)
160
# if notifications were disabled with the configure flag
161
if wpath.no_use_notifications:
162
self.notificationscheckbox.set_active(False)
163
self.notificationscheckbox.hide()
164
self.wTree.get_widget('label2').hide()
166
self.wTree.get_widget("notebook2").set_current_page(0)
169
""" Runs the preferences dialog window. """
170
return self.dialog.run()
173
""" Hides the preferences dialog window. """
177
self.dialog.destroy()
180
""" Shows the preferences dialog window. """
183
def save_results(self):
184
""" Pushes the selected settings to the daemon. """
185
daemon.SetUseGlobalDNS(self.useGlobalDNSCheckbox.get_active())
186
daemon.SetGlobalDNS(self.dns1Entry.get_text(), self.dns2Entry.get_text(),
187
self.dns3Entry.get_text(), self.dnsDomEntry.get_text(),
188
self.searchDomEntry.get_text())
189
daemon.SetWirelessInterface(self.entryWirelessInterface.get_text())
190
daemon.SetWiredInterface(self.entryWiredInterface.get_text())
191
daemon.SetWPADriver(self.wpadrivers[self.wpadrivercombo.get_active()])
192
daemon.SetAlwaysShowWiredInterface(self.wiredcheckbox.get_active())
193
daemon.SetAutoReconnect(self.reconnectcheckbox.get_active())
194
daemon.SetDebugMode(self.debugmodecheckbox.get_active())
195
daemon.SetSignalDisplayType(int(self.displaytypecheckbox.get_active()))
196
daemon.SetPreferWiredNetwork(bool(self.preferwiredcheckbox.get_active()))
197
if self.showlistradiobutton.get_active():
198
daemon.SetWiredAutoConnectMethod(2)
199
elif self.lastusedradiobutton.get_active():
200
daemon.SetWiredAutoConnectMethod(3)
202
daemon.SetWiredAutoConnectMethod(1)
204
daemon.SetBackend(self.backends[self.backendcombo.get_active()])
206
# External Programs Tab
207
if self.dhcpautoradio.get_active():
208
dhcp_client = misc.AUTO
209
elif self.dhclientradio.get_active():
210
dhcp_client = misc.DHCLIENT
211
elif self.dhcpcdradio.get_active():
212
dhcp_client = misc.DHCPCD
213
elif self.pumpradio.get_active():
214
dhcp_client = misc.PUMP
216
dhcp_client = misc.UDHCPC
217
daemon.SetDHCPClient(dhcp_client)
219
if self.linkautoradio.get_active():
220
link_tool = misc.AUTO
221
elif self.ethtoolradio.get_active():
222
link_tool = misc.ETHTOOL
224
link_tool = misc.MIITOOL
225
daemon.SetLinkDetectionTool(link_tool)
227
if self.flushautoradio.get_active():
228
flush_tool = misc.AUTO
229
elif self.ipflushradio.get_active():
232
flush_tool = misc.ROUTE
233
daemon.SetFlushTool(flush_tool)
235
if self.sudoautoradio.get_active():
236
sudo_tool = misc.AUTO
237
elif self.gksudoradio.get_active():
238
sudo_tool = misc.GKSUDO
239
elif self.kdesuradio.get_active():
240
sudo_tool = misc.KDESU
242
sudo_tool = misc.KTSUSS
243
daemon.SetSudoApp(sudo_tool)
245
[width, height] = self.dialog.get_size()
246
daemon.WriteWindowSize(width, height, "pref")
248
not_path = os.path.join(USER_SETTINGS_DIR, 'USE_NOTIFICATIONS')
249
if self.notificationscheckbox.get_active():
250
if not os.path.exists(not_path):
253
if os.path.exists(not_path):
255
# if this GUI was started by a tray icon,
256
# instantly change the notifications there
258
self.parent.tray.icon_info.use_notify = \
259
self.notificationscheckbox.get_active()
261
def set_label(self, glade_str, label):
262
""" Sets the label for the given widget in wicd.glade. """
263
self.wTree.get_widget(glade_str).set_label(label)
265
def prep_settings_diag(self):
266
""" Set up anything that doesn't have to be persisted later. """
267
def build_combobox(lbl):
268
""" Sets up a ComboBox using the given widget name. """
269
liststore = gtk.ListStore(gobject.TYPE_STRING)
270
combobox = self.wTree.get_widget(lbl)
272
combobox.set_model(liststore)
273
cell = gtk.CellRendererText()
274
combobox.pack_start(cell, True)
275
combobox.add_attribute(cell, 'text', 0)
278
def setup_label(name, lbl=""):
279
""" Sets up a label for the given widget name. """
280
widget = self.wTree.get_widget(name)
282
# widget.set_label(language[lbl])
284
raise ValueError('widget %s does not exist' % name)
287
# External Programs tab
288
# self.wTree.get_widget("gen_settings_label").set_label(language["gen_settings"])
289
# self.wTree.get_widget("ext_prog_label").set_label(language["ext_programs"])
290
# self.wTree.get_widget("dhcp_client_label").set_label(language["dhcp_client"])
291
# self.wTree.get_widget("wired_detect_label").set_label(language["wired_detect"])
292
# self.wTree.get_widget("route_flush_label").set_label(language["route_flush"])
293
# self.wTree.get_widget("pref_backend_label").set_label(language["backend"] + ":")
295
# entryWiredAutoMethod = self.wTree.get_widget("pref_wired_auto_label")
296
# entryWiredAutoMethod.set_label('Wired Autoconnect Setting:')
297
# entryWiredAutoMethod.set_alignment(0, 0)
298
# atrlist = pango.AttrList()
299
# atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 50))
300
# entryWiredAutoMethod.set_attributes(atrlist)
302
# self.set_label("pref_dns1_label", "%s %s" % (language['dns'], language['1']))
303
# self.set_label("pref_dns2_label", "%s %s" % (language['dns'], language['2']))
304
# self.set_label("pref_dns3_label", "%s %s" % (language['dns'], language['3']))
305
# self.set_label("pref_search_dom_label", "%s:" % language['search_domain'])
306
# self.set_label("pref_wifi_label", "%s:" % language['wireless_interface'])
307
# self.set_label("pref_wired_label", "%s:" % language['wired_interface'])
308
# self.set_label("pref_driver_label", "%s:" % language['wpa_supplicant_driver'])
310
self.dialog = self.wTree.get_widget("pref_dialog")
311
self.dialog.set_title(language['preferences'])
312
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
313
self.dialog.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
314
size = daemon.ReadWindowSize("pref")
317
if width > -1 and height > -1:
318
self.dialog.resize(int(width), int(height))
320
width = int(gtk.gdk.screen_width() / 2.4)
323
self.dialog.resize(width, int(gtk.gdk.screen_height() / 2))
325
self.wiredcheckbox = setup_label("pref_always_check",
327
self.preferwiredcheckbox = setup_label("pref_prefer_wired_check",
330
self.reconnectcheckbox = setup_label("pref_auto_check",
332
self.debugmodecheckbox = setup_label("pref_debug_check",
334
self.displaytypecheckbox = setup_label("pref_dbm_check",
335
'display_type_dialog')
336
self.usedefaultradiobutton = setup_label("pref_use_def_radio",
337
'use_default_profile')
338
self.showlistradiobutton = setup_label("pref_prompt_radio",
340
self.lastusedradiobutton = setup_label("pref_use_last_radio",
341
'use_last_used_profile')
344
self.notificationscheckbox = setup_label("pref_use_libnotify",
345
'display_notifications')
348
self.dhcpautoradio = setup_label("dhcp_auto_radio", "wicd_auto_config")
349
self.dhclientradio = self.wTree.get_widget("dhclient_radio")
350
self.pumpradio = self.wTree.get_widget("pump_radio")
351
self.dhcpcdradio = self.wTree.get_widget("dhcpcd_radio")
352
self.udhcpcradio = self.wTree.get_widget("udhcpc_radio")
354
# Wired Link Detection Apps
355
self.linkautoradio = setup_label("link_auto_radio", 'wicd_auto_config')
356
self.linkautoradio = setup_label("link_auto_radio")
357
self.ethtoolradio = setup_label("ethtool_radio")
358
self.miitoolradio = setup_label("miitool_radio")
360
# Route Flushing Apps
361
self.flushautoradio = setup_label("flush_auto_radio",
363
self.ipflushradio = setup_label("ip_flush_radio")
364
self.routeflushradio = setup_label("route_flush_radio")
366
# Graphical Sudo Apps
367
self.sudoautoradio = setup_label("sudo_auto_radio", "wicd_auto_config")
368
self.gksudoradio = setup_label("gksudo_radio")
369
self.kdesuradio = setup_label("kdesu_radio")
370
self.ktsussradio = setup_label("ktsuss_radio")
372
# Replacement for the combo box hack
373
self.wpadrivercombo = build_combobox("pref_wpa_combobox")
374
self.wpadrivers = ["wext", "hostap", "madwifi", "atmel",
375
"ndiswrapper", "ipw"]
376
self.wpadrivers = wireless.GetWpaSupplicantDrivers(self.wpadrivers)
377
self.wpadrivers.append("ralink_legacy")
379
for x in self.wpadrivers:
380
self.wpadrivercombo.append_text(x)
382
self.entryWirelessInterface = self.wTree.get_widget("pref_wifi_entry")
383
self.entryWiredInterface = self.wTree.get_widget("pref_wired_entry")
385
# Set up global DNS stuff
386
self.useGlobalDNSCheckbox = setup_label("pref_global_check",
388
self.searchDomEntry = self.wTree.get_widget("pref_search_dom_entry")
389
self.dnsDomEntry = self.wTree.get_widget("pref_dns_dom_entry")
390
self.dns1Entry = self.wTree.get_widget("pref_dns1_entry")
391
self.dns2Entry = self.wTree.get_widget("pref_dns2_entry")
392
self.dns3Entry = self.wTree.get_widget("pref_dns3_entry")
394
self.backendcombo = build_combobox("pref_backend_combobox")
395
self.backendcombo.connect("changed", self.be_combo_changed)
396
# Load backend combobox
397
self.backends = daemon.GetBackendList()
398
self.be_descriptions = daemon.GetBackendDescriptionDict()
400
for x in self.backends:
402
self.backendcombo.append_text(x)
404
def be_combo_changed(self, combo):
405
""" Update the description label for the given backend. """
406
self.backendcombo.set_tooltip_text(
407
self.be_descriptions[combo.get_active_text()]