1
""" netentry -- Network entry widgets for the GUI.
3
This module provides GUI widgets used to represent wired and wireless
4
entries in the GUI's network list, as well as any settings dialogs
9
# Copyright (C) 2008-2009 Adam Blackburn
10
# Copyright (C) 2008-2009 Dan O'Reilly
12
# This program is free software; you can redistribute it and/or modify
13
# it under the terms of the GNU General Public License Version 2 as
14
# published by the Free Software Foundation.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with this program. If not, see <http://www.gnu.org/licenses/>.
31
from misc import noneToString, stringToNone, noneToBlankString, to_bool
32
from guiutil import error, LabelEntry, GreyLabel, LeftAlignedLabel, string_input
34
from translations import language
36
# These get set when a NetworkEntry is instantiated.
42
global daemon, wireless, wired
43
daemon = dbusmanager.get_interface('daemon')
44
wireless = dbusmanager.get_interface('wireless')
45
wired = dbusmanager.get_interface('wired')
47
class AdvancedSettingsDialog(gtk.Dialog):
48
def __init__(self, network_name=None):
49
""" Build the base advanced settings dialog.
51
This class isn't used by itself, instead it is used as a parent for
52
the WiredSettingsDialog and WirelessSettingsDialog.
55
# if no network name was passed, just use Properties as the title
57
title = '%s - %s' % (network_name, language['properties'])
59
title = language['properties']
61
gtk.Dialog.__init__(self, title=title,
62
flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CANCEL,
66
# Set up the Advanced Settings Dialog.
67
self.txt_ip = LabelEntry(language['ip'])
68
self.txt_ip.entry.connect('focus-out-event', self.set_defaults)
69
self.txt_netmask = LabelEntry(language['netmask'])
70
self.txt_gateway = LabelEntry(language['gateway'])
71
self.txt_search_dom = LabelEntry(language['search_domain'])
72
self.txt_domain = LabelEntry(language['dns_domain'])
73
self.txt_dns_1 = LabelEntry(language['dns'] + ' 1')
74
self.txt_dns_2 = LabelEntry(language['dns'] + ' 2')
75
self.txt_dns_3 = LabelEntry(language['dns'] + ' 3')
76
self.chkbox_static_ip = gtk.CheckButton(language['use_static_ip'])
77
self.chkbox_static_dns = gtk.CheckButton(language['use_static_dns'])
78
self.chkbox_global_dns = gtk.CheckButton(language['use_global_dns'])
79
self.hbox_dns = gtk.HBox(False, 0)
80
self.hbox_dns.pack_start(self.chkbox_static_dns)
81
self.hbox_dns.pack_start(self.chkbox_global_dns)
83
# Set up the script settings button
84
self.script_button = gtk.Button()
85
script_image = gtk.Image()
86
script_image.set_from_stock(gtk.STOCK_EXECUTE, 4)
87
script_image.set_padding(4, 0)
88
#self.script_button.set_alignment(.5, .5)
89
self.script_button.set_image(script_image)
90
self.script_button.set_label(language['scripts'])
92
self.button_hbox = gtk.HBox(False, 2)
93
self.button_hbox.pack_start(self.script_button, fill=False, expand=False)
94
self.button_hbox.show()
96
assert(isinstance(self.vbox, gtk.VBox))
97
self.vbox.pack_start(self.chkbox_static_ip, fill=False, expand=False)
98
self.vbox.pack_start(self.txt_ip, fill=False, expand=False)
99
self.vbox.pack_start(self.txt_netmask, fill=False, expand=False)
100
self.vbox.pack_start(self.txt_gateway, fill=False, expand=False)
101
self.vbox.pack_start(self.hbox_dns, fill=False, expand=False)
102
self.vbox.pack_start(self.txt_domain, fill=False, expand=False)
103
self.vbox.pack_start(self.txt_search_dom, fill=False, expand=False)
104
self.vbox.pack_start(self.txt_dns_1, fill=False, expand=False)
105
self.vbox.pack_start(self.txt_dns_2, fill=False, expand=False)
106
self.vbox.pack_start(self.txt_dns_3, fill=False, expand=False)
107
self.vbox.pack_end(self.button_hbox, fill=False, expand=False, padding=5)
110
# Connect the events to the actions
111
self.chkbox_static_ip.connect("toggled", self.toggle_ip_checkbox)
112
self.chkbox_static_dns.connect("toggled", self.toggle_dns_checkbox)
113
self.chkbox_global_dns.connect("toggled", self.toggle_global_dns_checkbox)
115
# Start with all disabled, then they will be enabled later.
116
self.chkbox_static_ip.set_active(False)
117
self.chkbox_static_dns.set_active(False)
119
def set_defaults(self, widget=None, event=None):
120
""" Put some default values into entries to help the user out. """
121
ipAddress = self.txt_ip.get_text() # For easy typing :)
122
netmask = self.txt_netmask
123
gateway = self.txt_gateway
124
ip_parts = misc.IsValidIP(ipAddress)
126
if stringToNone(gateway.get_text()) is None: # Make sure the gateway box is blank
127
# Fill it in with a .1 at the end
128
gateway.set_text('.'.join(ip_parts[0:3]) + '.1')
130
if stringToNone(netmask.get_text()) is None: # Make sure the netmask is blank
131
netmask.set_text('255.255.255.0') # Fill in the most common one
132
elif ipAddress != "":
133
error(None, "Invalid IP Address Entered.")
135
def reset_static_checkboxes(self):
136
# Enable the right stuff
137
if stringToNone(self.txt_ip.get_text()):
138
self.chkbox_static_ip.set_active(True)
139
self.chkbox_static_dns.set_active(True)
140
self.chkbox_static_dns.set_sensitive(False)
142
self.chkbox_static_ip.set_active(False)
143
self.chkbox_static_dns.set_sensitive(True)
145
if stringToNone(self.txt_dns_1.get_text()) or \
146
self.chkbox_global_dns.get_active():
147
self.chkbox_static_dns.set_active(True)
149
self.chkbox_static_dns.set_active(False)
151
# This will properly disable unused boxes.
152
self.toggle_ip_checkbox()
153
self.toggle_dns_checkbox()
154
self.toggle_global_dns_checkbox()
156
def toggle_ip_checkbox(self, widget=None):
157
"""Toggle entries/checkboxes based on the static IP checkbox. """
158
# Should disable the static IP text boxes, and also enable the DNS
159
# checkbox when disabled and disable when enabled.
160
if self.chkbox_static_ip.get_active():
161
self.chkbox_static_dns.set_active(True)
162
self.chkbox_static_dns.set_sensitive(False)
164
self.chkbox_static_dns.set_sensitive(True)
166
self.txt_ip.set_sensitive(self.chkbox_static_ip.get_active())
167
self.txt_netmask.set_sensitive(self.chkbox_static_ip.get_active())
168
self.txt_gateway.set_sensitive(self.chkbox_static_ip.get_active())
170
def toggle_dns_checkbox(self, widget=None):
171
""" Toggle entries and checkboxes based on the static dns checkbox. """
172
# Should disable the static DNS boxes
173
if self.chkbox_static_ip.get_active():
174
self.chkbox_static_dns.set_active(True)
175
self.chkbox_static_dns.set_sensitive(False)
177
self.chkbox_global_dns.set_sensitive(self.chkbox_static_dns.
180
l = [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain,
182
if self.chkbox_static_dns.get_active():
183
# If global dns is on, don't use local dns
185
w.set_sensitive(not self.chkbox_global_dns.get_active())
188
w.set_sensitive(False)
189
self.chkbox_global_dns.set_active(False)
191
def toggle_global_dns_checkbox(self, widget=None):
192
""" Set the DNS entries' sensitivity based on the Global checkbox. """
193
global_dns_active = daemon.GetUseGlobalDNS()
194
if not global_dns_active and self.chkbox_global_dns.get_active():
195
error(None, language['global_dns_not_enabled'])
196
self.chkbox_global_dns.set_active(False)
197
if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active():
198
for w in [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3,
199
self.txt_domain, self.txt_search_dom]:
200
w.set_sensitive(not self.chkbox_global_dns.get_active())
202
def destroy_called(self, *args):
203
""" Clean up everything. """
204
super(AdvancedSettingsDialog, self).destroy()
208
def save_settings(self):
209
""" Save settings common to wired and wireless settings dialogs. """
210
if self.chkbox_static_ip.get_active():
211
self.set_net_prop("ip", noneToString(self.txt_ip.get_text()))
212
self.set_net_prop("netmask", noneToString(self.txt_netmask.get_text()))
213
self.set_net_prop("gateway", noneToString(self.txt_gateway.get_text()))
215
self.set_net_prop("ip", '')
216
self.set_net_prop("netmask", '')
217
self.set_net_prop("gateway", '')
219
if self.chkbox_static_dns.get_active() and \
220
not self.chkbox_global_dns.get_active():
221
self.set_net_prop('use_static_dns', True)
222
self.set_net_prop('use_global_dns', False)
223
self.set_net_prop('dns_domain', noneToString(self.txt_domain.get_text()))
224
self.set_net_prop("search_domain", noneToString(self.txt_search_dom.get_text()))
225
self.set_net_prop("dns1", noneToString(self.txt_dns_1.get_text()))
226
self.set_net_prop("dns2", noneToString(self.txt_dns_2.get_text()))
227
self.set_net_prop("dns3", noneToString(self.txt_dns_3.get_text()))
228
elif self.chkbox_static_dns.get_active() and \
229
self.chkbox_global_dns.get_active():
230
self.set_net_prop('use_static_dns', True)
231
self.set_net_prop('use_global_dns', True)
233
self.set_net_prop('use_static_dns', False)
234
self.set_net_prop('use_global_dns', False)
235
self.set_net_prop('dns_domain', '')
236
self.set_net_prop("search_domain", '')
237
self.set_net_prop("dns1", '')
238
self.set_net_prop("dns2", '')
239
self.set_net_prop("dns3", '')
242
class WiredSettingsDialog(AdvancedSettingsDialog):
243
def __init__(self, name):
244
""" Build the wired settings dialog. """
245
AdvancedSettingsDialog.__init__(self, language['wired_network'])
246
self.des = self.connect("destroy", self.destroy_called)
247
self.script_button.connect("clicked", self.edit_scripts)
248
self.prof_name = name
250
def set_net_prop(self, option, value):
251
""" Sets the given option to the given value for this network. """
252
wired.SetWiredProperty(option, value)
254
def edit_scripts(self, widget=None, event=None):
255
""" Launch the script editting dialog. """
256
profile = self.prof_name
257
cmdend = [os.path.join(wpath.lib, "configscript.py"), profile, "wired"]
259
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'],
260
prog_num=daemon.GetSudoApp())
262
error(None, language["no_sudo_prog"])
264
cmdbase.extend(cmdend)
265
misc.LaunchAndWait(cmdbase)
267
misc.LaunchAndWait(cmdend)
269
def set_values(self):
270
""" Fill in the Gtk.Entry objects with the correct values. """
271
self.txt_ip.set_text(self.format_entry("ip"))
272
self.txt_netmask.set_text(self.format_entry("netmask"))
273
self.txt_gateway.set_text(self.format_entry("gateway"))
275
self.txt_dns_1.set_text(self.format_entry("dns1"))
276
self.txt_dns_2.set_text(self.format_entry("dns2"))
277
self.txt_dns_3.set_text(self.format_entry("dns3"))
278
self.txt_domain.set_text(self.format_entry("dns_domain"))
279
self.txt_search_dom.set_text(self.format_entry("search_domain"))
280
self.chkbox_global_dns.set_active(bool(wired.GetWiredProperty("use_global_dns")))
281
self.reset_static_checkboxes()
283
def save_settings(self):
284
AdvancedSettingsDialog.save_settings(self)
285
wired.SaveWiredNetworkProfile(self.prof_name)
288
def format_entry(self, label):
289
""" Helper method to fetch and format wired properties. """
290
return noneToBlankString(wired.GetWiredProperty(label))
292
def destroy_called(self, *args):
293
""" Clean up everything. """
294
self.disconnect(self.des)
295
super(WiredSettingsDialog, self).destroy_called()
300
class WirelessSettingsDialog(AdvancedSettingsDialog):
301
def __init__(self, networkID):
302
""" Build the wireless settings dialog. """
303
AdvancedSettingsDialog.__init__(self, wireless.GetWirelessProperty(networkID, 'essid'))
304
# Set up encryption stuff
305
self.networkID = networkID
306
self.combo_encryption = gtk.combo_box_new_text()
307
self.chkbox_encryption = gtk.CheckButton(language['use_encryption'])
308
self.chkbox_global_settings = gtk.CheckButton(language['global_settings'])
309
# Make the vbox to hold the encryption stuff.
310
self.vbox_encrypt_info = gtk.VBox(False, 0)
311
self.toggle_encryption()
312
self.chkbox_encryption.set_active(False)
313
self.combo_encryption.set_sensitive(False)
314
self.encrypt_types = misc.LoadEncryptionMethods()
316
information_button = gtk.Button(stock=gtk.STOCK_INFO)
317
self.button_hbox.pack_start(information_button, False, False)
318
information_button.connect('clicked', lambda *a, **k: WirelessInformationDialog(networkID, self))
319
information_button.show()
321
# Build the encryption menu
322
activeID = -1 # Set the menu to this item when we are done
323
for x, enc_type in enumerate(self.encrypt_types):
324
self.combo_encryption.append_text(enc_type['name'])
325
if enc_type['type'] == wireless.GetWirelessProperty(networkID, "enctype"):
327
self.combo_encryption.set_active(activeID)
329
self.chkbox_encryption.set_active(True)
330
self.combo_encryption.set_sensitive(True)
331
self.vbox_encrypt_info.set_sensitive(True)
333
self.combo_encryption.set_active(0)
334
self.change_encrypt_method()
336
self.vbox.pack_start(self.chkbox_global_settings, False, False)
337
self.vbox.pack_start(self.chkbox_encryption, False, False)
338
self.vbox.pack_start(self.combo_encryption, False, False)
339
self.vbox.pack_start(self.vbox_encrypt_info, False, False)
342
self.chkbox_encryption.connect("toggled", self.toggle_encryption)
343
self.combo_encryption.connect("changed", self.change_encrypt_method)
344
self.script_button.connect("clicked", self.edit_scripts)
345
self.des = self.connect("destroy", self.destroy_called)
347
def destroy_called(self, *args):
348
""" Clean up everything. """
349
self.disconnect(self.des)
350
super(WirelessSettingsDialog, self).destroy_called()
354
def edit_scripts(self, widget=None, event=None):
355
""" Launch the script editting dialog. """
356
cmdend = [os.path.join(wpath.lib, "configscript.py"),
357
str(self.networkID), "wireless"]
359
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'],
360
prog_num=daemon.GetSudoApp())
362
error(None, language["no_sudo_prog"])
364
cmdbase.extend(cmdend)
365
misc.LaunchAndWait(cmdbase)
367
misc.LaunchAndWait(cmdend)
369
def set_net_prop(self, option, value):
370
""" Sets the given option to the given value for this network. """
371
wireless.SetWirelessProperty(self.networkID, option, value)
373
def set_values(self):
374
""" Set the various network settings to the right values. """
375
networkID = self.networkID
376
self.txt_ip.set_text(self.format_entry(networkID,"ip"))
377
self.txt_netmask.set_text(self.format_entry(networkID,"netmask"))
378
self.txt_gateway.set_text(self.format_entry(networkID,"gateway"))
380
self.chkbox_global_dns.set_active(bool(wireless.GetWirelessProperty(networkID,
382
self.chkbox_static_dns.set_active(bool(wireless.GetWirelessProperty(networkID,
385
self.txt_dns_1.set_text(self.format_entry(networkID, "dns1"))
386
self.txt_dns_2.set_text(self.format_entry(networkID, "dns2"))
387
self.txt_dns_3.set_text(self.format_entry(networkID, "dns3"))
388
self.txt_domain.set_text(self.format_entry(networkID, "dns_domain"))
389
self.txt_search_dom.set_text(self.format_entry(networkID, "search_domain"))
391
self.reset_static_checkboxes()
392
self.chkbox_encryption.set_active(bool(wireless.GetWirelessProperty(networkID,
394
self.chkbox_global_settings.set_active(bool(wireless.GetWirelessProperty(networkID,
395
'use_settings_globally')))
397
activeID = -1 # Set the menu to this item when we are done
398
user_enctype = wireless.GetWirelessProperty(networkID, "enctype")
399
for x, enc_type in enumerate(self.encrypt_types):
400
if enc_type['type'] == user_enctype:
403
self.combo_encryption.set_active(activeID)
405
self.chkbox_encryption.set_active(True)
406
self.combo_encryption.set_sensitive(True)
407
self.vbox_encrypt_info.set_sensitive(True)
409
self.combo_encryption.set_active(0)
410
self.change_encrypt_method()
412
def save_settings(self, networkid):
413
# Check encryption info
414
encrypt_info = self.encryption_info
415
if self.chkbox_encryption.get_active():
416
print "setting encryption info..."
417
encrypt_methods = self.encrypt_types
418
self.set_net_prop("enctype",
419
encrypt_methods[self.combo_encryption.get_active()]['type'])
420
# Make sure all required fields are filled in.
421
for entry_info in encrypt_info.itervalues():
422
if entry_info[0].entry.get_text() == "" and \
423
entry_info[1] == 'required':
424
error(self, "%s (%s)" % (language['encrypt_info_missing'],
425
entry_info[0].label.get_label())
428
# Now save all the entries.
429
for entry_key, entry_info in encrypt_info.iteritems():
430
self.set_net_prop(entry_key,
431
noneToString(entry_info[0].entry.get_text()))
432
elif not self.chkbox_encryption.get_active() and \
433
wireless.GetWirelessProperty(networkid, "encryption"):
434
# Encrypt checkbox is off, but the network needs it.
435
error(self, language['enable_encryption'])
438
print "no encryption specified..."
439
self.set_net_prop("enctype", "None")
440
AdvancedSettingsDialog.save_settings(self)
442
if self.chkbox_global_settings.get_active():
443
self.set_net_prop('use_settings_globally', True)
445
self.set_net_prop('use_settings_globally', False)
446
wireless.RemoveGlobalEssidEntry(networkid)
448
wireless.SaveWirelessNetworkProfile(networkid)
451
def format_entry(self, networkid, label):
452
""" Helper method for fetching/formatting wireless properties. """
453
return noneToBlankString(wireless.GetWirelessProperty(networkid, label))
455
def toggle_encryption(self, widget=None):
456
""" Toggle the encryption combobox based on the encryption checkbox. """
457
active = self.chkbox_encryption.get_active()
458
self.vbox_encrypt_info.set_sensitive(active)
459
self.combo_encryption.set_sensitive(active)
461
def change_encrypt_method(self, widget=None):
462
""" Load all the entries for a given encryption method. """
463
for z in self.vbox_encrypt_info:
464
z.destroy() # Remove stuff in there already
465
ID = self.combo_encryption.get_active()
466
methods = self.encrypt_types
467
self.encryption_info = {}
469
# If nothing is selected, select the first entry.
471
self.combo_encryption.set_active(0)
474
for type_ in ['required', 'optional']:
475
fields = methods[ID][type_]
477
if language.has_key(field[1]):
478
box = LabelEntry(language[field[1].lower().replace(' ','_')])
480
box = LabelEntry(field[1].replace('_',' '))
481
box.set_auto_hidden(True)
482
self.vbox_encrypt_info.pack_start(box)
483
# Add the data to a dict, so that the information
484
# can be easily accessed by giving the name of the wanted
486
self.encryption_info[field[0]] = [box, type_]
488
box.entry.set_text(noneToBlankString(
489
wireless.GetWirelessProperty(self.networkID, field[0])))
490
self.vbox_encrypt_info.show_all()
493
class NetworkEntry(gtk.HBox):
495
""" Base network entry class.
497
Provides gtk objects used by both the WiredNetworkEntry and
498
WirelessNetworkEntry classes.
502
gtk.HBox.__init__(self, False, 2)
503
self.image = gtk.Image()
504
self.pack_start(self.image, False, False)
506
# Create an HBox to hold the buttons
507
self.buttons_hbox = gtk.HBox(False, 6)
509
# Set up the Connect button
510
self.connect_button = gtk.Button(stock=gtk.STOCK_CONNECT)
511
self.connect_hbox = gtk.HBox(False, 2)
512
self.connect_hbox.pack_start(self.connect_button, False, False)
513
self.connect_hbox.show()
515
# Set up the Disconnect button
516
self.disconnect_button = gtk.Button(stock=gtk.STOCK_DISCONNECT)
517
self.connect_hbox.pack_start(self.disconnect_button, False, False)
519
# Create a label to hold the name of the entry
520
self.name_label = gtk.Label()
521
self.name_label.set_alignment(0, 0.5)
523
# Set up the VBox that goes in the gtk.Expander
524
self.expander_vbox = gtk.VBox(False, 1)
525
self.expander_vbox.show()
526
self.pack_end(self.expander_vbox)
528
# Set up the advanced settings button
529
self.advanced_button = gtk.Button()
530
self.advanced_image = gtk.Image()
531
self.advanced_image.set_from_stock(gtk.STOCK_EDIT, 4)
532
self.advanced_image.set_padding(4, 0)
533
self.advanced_button.set_alignment(.5, .5)
534
self.advanced_button.set_label(language['properties'])
535
self.advanced_button.set_image(self.advanced_image)
537
self.buttons_hbox.pack_start(self.connect_hbox, False, False)
538
self.buttons_hbox.pack_start(self.advanced_button, False, False)
540
self.vbox_top = gtk.VBox(False, 0)
541
self.expander_vbox.pack_start(self.name_label)
542
self.expander_vbox.pack_start(self.vbox_top)
543
self.expander_vbox.pack_start(self.buttons_hbox)
545
def destroy_called(self, *args):
546
""" Clean up everything. """
547
super(NetworkEntry, self).destroy()
552
class WiredNetworkEntry(NetworkEntry):
554
""" Load the wired network entry. """
555
NetworkEntry.__init__(self)
556
# Center the picture and pad it a bit
557
self.image.set_padding(0, 0)
558
self.image.set_alignment(.5, .5)
559
self.image.set_size_request(60, -1)
560
self.image.set_from_file(wpath.images + "wired-gui.svg")
562
self.connect_button.show()
564
self.name_label.set_use_markup(True)
565
self.name_label.set_label("<b>" + language['wired_network'] + "</b>")
567
self.is_full_gui = True
569
self.button_add = gtk.Button(stock=gtk.STOCK_ADD)
570
self.button_delete = gtk.Button(stock=gtk.STOCK_DELETE)
571
self.profile_help = gtk.Label(language['wired_network_instructions'])
572
self.chkbox_default_profile = gtk.CheckButton(language['default_wired'])
573
self.combo_profile_names = gtk.combo_box_new_text()
575
# Format the profile help label.
576
self.profile_help.set_justify(gtk.JUSTIFY_LEFT)
577
self.profile_help.set_line_wrap(True)
579
# Pack the various VBox objects.
580
self.hbox_temp = gtk.HBox(False, 0)
581
self.hbox_def = gtk.HBox(False, 0)
582
self.vbox_top.pack_start(self.profile_help, True, True)
583
self.vbox_top.pack_start(self.hbox_def)
584
self.vbox_top.pack_start(self.hbox_temp)
585
self.hbox_temp.pack_start(self.combo_profile_names, True, True)
586
self.hbox_temp.pack_start(self.button_add, False, False)
587
self.hbox_temp.pack_start(self.button_delete, False, False)
588
self.hbox_def.pack_start(self.chkbox_default_profile, False, False)
591
self.button_add.connect("clicked", self.add_profile)
592
self.button_delete.connect("clicked", self.remove_profile)
593
self.chkbox_default_profile.connect("toggled",
594
self.toggle_default_profile)
595
self.combo_profile_names.connect("changed", self.change_profile)
597
# Build profile list.
598
self.profile_list = wired.GetWiredProfileList()
599
default_prof = wired.GetDefaultWiredNetwork()
600
if self.profile_list:
602
for x, prof in enumerate(self.profile_list):
603
self.combo_profile_names.append_text(prof)
604
if default_prof == prof:
606
self.combo_profile_names.set_active(starting_index)
608
print "no wired profiles found"
609
self.profile_help.show()
611
self.advanced_dialog = WiredSettingsDialog(self.combo_profile_names.get_active_text())
613
# Show everything, but hide the profile help label.
615
self.profile_help.hide()
617
# Toggle the default profile checkbox to the correct state.
618
if to_bool(wired.GetWiredProperty("default")):
619
self.chkbox_default_profile.set_active(True)
621
self.chkbox_default_profile.set_active(False)
624
self.wireddis = self.connect("destroy", self.destroy_called)
626
def destroy_called(self, *args):
627
""" Clean up everything. """
628
self.disconnect(self.wireddis)
629
self.advanced_dialog.destroy_called()
630
del self.advanced_dialog
631
super(WiredNetworkEntry, self).destroy_called()
635
def save_wired_settings(self):
636
""" Save wired network settings. """
637
return self.advanced_dialog.save_settings()
639
def check_enable(self):
640
""" Disable objects if the profile list is empty. """
641
profile_list = wired.GetWiredProfileList()
643
self.button_delete.set_sensitive(False)
644
self.connect_button.set_sensitive(False)
645
self.advanced_button.set_sensitive(False)
647
def update_connect_button(self, state, apbssid=None):
648
""" Update the connection/disconnect button for this entry. """
649
if state == misc.WIRED:
650
self.disconnect_button.show()
651
self.connect_button.hide()
653
self.disconnect_button.hide()
654
self.connect_button.show()
656
def add_profile(self, widget):
657
""" Add a profile to the profile list. """
658
print "adding profile"
660
response = string_input("Enter a profile name", "The profile name " +
661
"will not be used by the computer. It " +
663
"easily distinguish between different network " +
664
"profiles.", "Profile name:")
666
# if response is "" or None
670
profile_name = response
671
profile_list = wired.GetWiredProfileList()
673
if profile_name in profile_list:
676
self.profile_help.hide()
677
wired.CreateWiredNetworkProfile(profile_name, False)
678
self.combo_profile_names.prepend_text(profile_name)
679
self.combo_profile_names.set_active(0)
680
self.advanced_dialog.prof_name = profile_name
682
self.button_delete.set_sensitive(True)
683
self.connect_button.set_sensitive(True)
684
self.advanced_button.set_sensitive(True)
686
def remove_profile(self, widget):
687
""" Remove a profile from the profile list. """
688
print "removing profile"
689
profile_name = self.combo_profile_names.get_active_text()
690
wired.DeleteWiredNetworkProfile(profile_name)
691
self.combo_profile_names.remove_text(self.combo_profile_names.
693
self.combo_profile_names.set_active(0)
694
self.advanced_dialog.prof_name = self.combo_profile_names.get_active_text()
695
if not wired.GetWiredProfileList():
696
self.profile_help.show()
697
entry = self.combo_profile_names.child
700
self.button_delete.set_sensitive(False)
701
self.advanced_button.set_sensitive(False)
702
self.connect_button.set_sensitive(False)
704
self.profile_help.hide()
706
def toggle_default_profile(self, widget):
707
""" Change the default profile. """
708
if self.chkbox_default_profile.get_active():
709
# Make sure there is only one default profile at a time
710
wired.UnsetWiredDefault()
711
wired.SetWiredProperty("default",
712
self.chkbox_default_profile.get_active())
713
wired.SaveWiredNetworkProfile(self.combo_profile_names.get_active_text())
715
def change_profile(self, widget):
716
""" Called when a new profile is chosen from the list. """
717
# Make sure the name doesn't change everytime someone types something
718
if self.combo_profile_names.get_active() > -1:
719
if not self.is_full_gui:
722
profile_name = self.combo_profile_names.get_active_text()
723
wired.ReadWiredNetworkProfile(profile_name)
725
if hasattr(self, 'advanced_dialog'):
726
self.advanced_dialog.prof_name = profile_name
727
self.advanced_dialog.set_values()
729
is_default = wired.GetWiredProperty("default")
730
self.chkbox_default_profile.set_active(to_bool(is_default))
732
def format_entry(self, label):
733
""" Help method for fetching/formatting wired properties. """
734
return noneToBlankString(wired.GetWiredProperty(label))
737
class WirelessNetworkEntry(NetworkEntry):
738
def __init__(self, networkID):
739
""" Build the wireless network entry. """
740
NetworkEntry.__init__(self)
742
self.networkID = networkID
743
self.image.set_padding(0, 0)
744
self.image.set_alignment(.5, .5)
745
self.image.set_size_request(60, -1)
747
self.essid = noneToBlankString(wireless.GetWirelessProperty(networkID,
749
self.lbl_strength = GreyLabel()
750
self.lbl_encryption = GreyLabel()
751
self.lbl_channel = GreyLabel()
753
print "ESSID : " + self.essid
754
self.chkbox_autoconnect = gtk.CheckButton(language['automatic_connect'])
756
self.set_signal_strength(wireless.GetWirelessProperty(networkID,
758
wireless.GetWirelessProperty(networkID,
760
self.set_encryption(wireless.GetWirelessProperty(networkID,
762
wireless.GetWirelessProperty(networkID,
763
'encryption_method'))
764
self.set_channel(wireless.GetWirelessProperty(networkID, 'channel'))
765
self.name_label.set_use_markup(True)
766
self.name_label.set_label("<b>%s</b> %s %s %s" % (self._escape(self.essid),
767
self.lbl_strength.get_label(),
768
self.lbl_encryption.get_label(),
769
self.lbl_channel.get_label(),
772
# Add the wireless network specific parts to the NetworkEntry
774
self.vbox_top.pack_start(self.chkbox_autoconnect, False, False)
776
if to_bool(self.format_entry(networkID, "automatic")):
777
self.chkbox_autoconnect.set_active(True)
779
self.chkbox_autoconnect.set_active(False)
782
self.chkbox_autoconnect.connect("toggled", self.update_autoconnect)
786
self.advanced_dialog = WirelessSettingsDialog(networkID)
787
self.wifides = self.connect("destroy", self.destroy_called)
789
def _escape(self, val):
790
""" Escapes special characters so they're displayed correctly. """
791
return val.replace("&", "&").replace("<", "<").\
792
replace(">",">").replace("'", "'").replace('"', """)
794
def save_wireless_settings(self, networkid):
795
""" Save wireless network settings. """
796
return self.advanced_dialog.save_settings(networkid)
798
def update_autoconnect(self, widget=None):
799
""" Called when the autoconnect checkbox is toggled. """
800
wireless.SetWirelessProperty(self.networkID, "automatic",
801
noneToString(self.chkbox_autoconnect.
803
wireless.SaveWirelessNetworkProperty(self.networkID, "automatic")
805
def destroy_called(self, *args):
806
""" Clean up everything. """
807
self.disconnect(self.wifides)
808
self.advanced_dialog.destroy_called()
809
del self.advanced_dialog
810
super(WirelessNetworkEntry, self).destroy_called()
814
def update_connect_button(self, state, apbssid):
815
""" Update the connection/disconnect button for this entry. """
817
apbssid = wireless.GetApBssid()
818
if state == misc.WIRELESS and \
819
apbssid == wireless.GetWirelessProperty(self.networkID, "bssid"):
820
self.disconnect_button.show()
821
self.connect_button.hide()
823
self.disconnect_button.hide()
824
self.connect_button.show()
826
def set_signal_strength(self, strength, dbm_strength):
827
""" Set the signal strength displayed in the WirelessNetworkEntry. """
829
strength = int(strength)
833
dbm_strength = int(dbm_strength)
836
display_type = daemon.GetSignalDisplayType()
837
if daemon.GetWPADriver() == 'ralink legacy' or display_type == 1:
838
# Use the -xx dBm signal strength to display a signal icon
839
# I'm not sure how accurately the dBm strength is being
840
# "converted" to strength bars, so suggestions from people
841
# for a better way would be welcome.
842
if dbm_strength >= -60:
843
signal_img = 'signal-100.png'
844
elif dbm_strength >= -70:
845
signal_img = 'signal-75.png'
846
elif dbm_strength >= -80:
847
signal_img = 'signal-50.png'
849
signal_img = 'signal-25.png'
851
disp_strength = str(dbm_strength)
853
# Uses normal link quality, should be fine in most cases
855
signal_img = 'signal-100.png'
857
signal_img = 'signal-75.png'
859
signal_img = 'signal-50.png'
861
signal_img = 'signal-25.png'
863
disp_strength = str(strength)
864
self.image.set_from_file(wpath.images + signal_img)
865
self.lbl_strength.set_label(disp_strength + ending)
868
def set_encryption(self, on, ttype):
869
""" Set the encryption value for the WirelessNetworkEntry. """
871
self.lbl_encryption.set_label(str(ttype))
873
self.lbl_encryption.set_label(language['secured'])
875
self.lbl_encryption.set_label(language['unsecured'])
877
def set_channel(self, channel):
878
""" Set the channel value for the WirelessNetworkEntry. """
879
self.lbl_channel.set_label(language['channel'] + ' ' + str(channel))
881
def format_entry(self, networkid, label):
882
""" Helper method for fetching/formatting wireless properties. """
883
return noneToBlankString(wireless.GetWirelessProperty(networkid, label))
886
class WirelessInformationDialog(gtk.Dialog):
887
def __init__(self, networkID, parent):
888
gtk.Dialog.__init__(self,parent=parent)
890
# Make the combo box.
891
self.lbl_strength = gtk.Label()
892
self.lbl_strength.set_alignment(0, 0.5)
893
self.lbl_encryption = gtk.Label()
894
self.lbl_encryption.set_alignment(0, 0.5)
895
self.lbl_mac = gtk.Label()
896
self.lbl_mac.set_alignment(0, 0.5)
897
self.lbl_channel = gtk.Label()
898
self.lbl_channel.set_alignment(0, 0.5)
899
self.lbl_mode = gtk.Label()
900
self.lbl_mode.set_alignment(0, 0.5)
901
self.hbox_status = gtk.HBox(False, 5)
903
# Set the values of the network info labels.
904
self.set_signal_strength(wireless.GetWirelessProperty(networkID,
906
wireless.GetWirelessProperty(networkID,
908
self.set_mac_address(wireless.GetWirelessProperty(networkID, 'bssid'))
909
self.set_mode(wireless.GetWirelessProperty(networkID, 'mode'))
910
self.set_channel(wireless.GetWirelessProperty(networkID, 'channel'))
911
self.set_encryption(wireless.GetWirelessProperty(networkID,
913
wireless.GetWirelessProperty(networkID,
914
'encryption_method'))
916
self.set_title('Network Information')
918
self.set_has_separator(False)
919
table = gtk.Table(5, 2)
920
table.set_col_spacings(12)
921
vbox.pack_start(table)
923
# Pack the network status HBox.
924
table.attach(LeftAlignedLabel('Signal strength:'), 0, 1, 0, 1)
925
table.attach(self.lbl_strength, 1, 2, 0, 1)
927
table.attach(LeftAlignedLabel('Encryption type:'), 0, 1, 1, 2)
928
table.attach(self.lbl_encryption, 1, 2, 1, 2)
930
table.attach(LeftAlignedLabel('Access point address:'), 0, 1, 2, 3)
931
table.attach(self.lbl_mac, 1, 2, 2, 3)
933
table.attach(LeftAlignedLabel('Mode:'), 0, 1, 3, 4)
934
table.attach(self.lbl_mode, 1, 2, 3, 4)
936
table.attach(LeftAlignedLabel('Channel:'), 0, 1, 4, 5)
937
table.attach(self.lbl_channel, 1, 2, 4, 5)
941
self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
946
def set_signal_strength(self, strength, dbm_strength):
947
""" Set the signal strength displayed in the WirelessNetworkEntry. """
948
if strength is not None:
949
strength = int(strength)
952
if dbm_strength is not None:
953
dbm_strength = int(dbm_strength)
956
display_type = daemon.GetSignalDisplayType()
957
if daemon.GetWPADriver() == 'ralink legacy' or display_type == 1:
958
# Use the -xx dBm signal strength to display a signal icon
959
# I'm not sure how accurately the dBm strength is being
960
# "converted" to strength bars, so suggestions from people
961
# for a better way would be welcome.
962
if dbm_strength >= -60:
963
signal_img = 'signal-100.png'
964
elif dbm_strength >= -70:
965
signal_img = 'signal-75.png'
966
elif dbm_strength >= -80:
967
signal_img = 'signal-50.png'
969
signal_img = 'signal-25.png'
971
disp_strength = str(dbm_strength)
973
# Uses normal link quality, should be fine in most cases
975
signal_img = 'signal-100.png'
977
signal_img = 'signal-75.png'
979
signal_img = 'signal-50.png'
981
signal_img = 'signal-25.png'
983
disp_strength = str(strength)
984
self.lbl_strength.set_label(disp_strength + ending)
986
def set_mac_address(self, address):
987
""" Set the MAC address for the WirelessNetworkEntry. """
988
self.lbl_mac.set_label(str(address))
990
def set_encryption(self, on, ttype):
991
""" Set the encryption value for the WirelessNetworkEntry. """
993
self.lbl_encryption.set_label(str(ttype))
995
self.lbl_encryption.set_label(language['secured'])
997
self.lbl_encryption.set_label(language['unsecured'])
999
def set_channel(self, channel):
1000
""" Set the channel value for the WirelessNetworkEntry. """
1001
self.lbl_channel.set_label(language['channel'] + ' ' + str(channel))
1003
def set_mode(self, mode):
1004
""" Set the mode value for the WirelessNetworkEntry. """
1005
self.lbl_mode.set_label(str(mode))
1007
def format_entry(self, networkid, label):
1008
""" Helper method for fetching/formatting wireless properties. """
1009
return noneToBlankString(wireless.GetWirelessProperty(networkid, label))