~ubuntu-branches/ubuntu/saucy/wicd/saucy

« back to all changes in this revision

Viewing changes to wicd/netentry.py

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2009-06-22 17:59:27 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090622175927-iax3alden0bmj6zg
Tags: 1.6.1-3
* debian/config, debian/templates updated:
  - only show users to add to netdev, skip those who are already
    members (Closes: #534138)
  - gracefully handle upgrades from previous broken versions, where
    debconf set a value of ${default} for wicd/users
    (Closes: #532112)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
""" netentry -- Network entry widgets for the GUI.
 
2
 
 
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
 
5
contained within them.
 
6
 
 
7
"""
 
8
#
 
9
#   Copyright (C) 2008-2009 Adam Blackburn
 
10
#   Copyright (C) 2008-2009 Dan O'Reilly
 
11
#
 
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.
 
15
#
 
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.
 
20
#
 
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/>.
 
23
#
 
24
 
 
25
import gtk
 
26
import os
 
27
 
 
28
import misc
 
29
import wpath
 
30
import dbusmanager
 
31
from misc import noneToString, stringToNone, noneToBlankString, to_bool
 
32
from guiutil import error, LabelEntry, GreyLabel, LeftAlignedLabel, string_input
 
33
 
 
34
from translations import language
 
35
 
 
36
# These get set when a NetworkEntry is instantiated.
 
37
daemon = None
 
38
wired = None
 
39
wireless = None
 
40
        
 
41
def setup_dbus():
 
42
    global daemon, wireless, wired
 
43
    daemon = dbusmanager.get_interface('daemon')
 
44
    wireless = dbusmanager.get_interface('wireless')
 
45
    wired = dbusmanager.get_interface('wired')
 
46
    
 
47
class AdvancedSettingsDialog(gtk.Dialog):
 
48
    def __init__(self, network_name=None):
 
49
        """ Build the base advanced settings dialog.
 
50
        
 
51
        This class isn't used by itself, instead it is used as a parent for
 
52
        the WiredSettingsDialog and WirelessSettingsDialog.
 
53
        
 
54
        """
 
55
        # if no network name was passed, just use Properties as the title
 
56
        if network_name:
 
57
            title = '%s - %s' % (network_name, language['properties'])
 
58
        else:
 
59
            title = language['properties']      
 
60
 
 
61
        gtk.Dialog.__init__(self, title=title,
 
62
                            flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CANCEL,
 
63
                                                           gtk.RESPONSE_REJECT,
 
64
                                                           gtk.STOCK_OK,
 
65
                                                           gtk.RESPONSE_ACCEPT))
 
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)
 
82
        
 
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'])
 
91
        
 
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()
 
95
        
 
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)
 
108
        
 
109
        
 
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)
 
114
        
 
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)
 
118
        
 
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)
 
125
        if ip_parts:
 
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')
 
129
 
 
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.")
 
134
 
 
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)
 
141
        else:
 
142
            self.chkbox_static_ip.set_active(False)
 
143
            self.chkbox_static_dns.set_sensitive(True)
 
144
 
 
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)
 
148
        else:
 
149
            self.chkbox_static_dns.set_active(False)
 
150
 
 
151
        # This will properly disable unused boxes.
 
152
        self.toggle_ip_checkbox()
 
153
        self.toggle_dns_checkbox()
 
154
        self.toggle_global_dns_checkbox()
 
155
 
 
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)
 
163
        else:
 
164
            self.chkbox_static_dns.set_sensitive(True)
 
165
 
 
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())
 
169
 
 
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)
 
176
 
 
177
        self.chkbox_global_dns.set_sensitive(self.chkbox_static_dns.
 
178
                                                            get_active())
 
179
        
 
180
        l = [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain,
 
181
             self.txt_search_dom]
 
182
        if self.chkbox_static_dns.get_active():
 
183
            # If global dns is on, don't use local dns
 
184
            for w in l:
 
185
                w.set_sensitive(not self.chkbox_global_dns.get_active())
 
186
        else:
 
187
            for w in l:
 
188
                w.set_sensitive(False)
 
189
            self.chkbox_global_dns.set_active(False)
 
190
 
 
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())
 
201
                
 
202
    def destroy_called(self, *args):
 
203
        """ Clean up everything. """
 
204
        super(AdvancedSettingsDialog, self).destroy()
 
205
        self.destroy()
 
206
        del self
 
207
    
 
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()))
 
214
        else:
 
215
            self.set_net_prop("ip", '')
 
216
            self.set_net_prop("netmask", '')
 
217
            self.set_net_prop("gateway", '')
 
218
 
 
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)
 
232
        else:
 
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", '')
 
240
 
 
241
        
 
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
 
249
        
 
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)
 
253
        
 
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"]
 
258
        if os.getuid() != 0:
 
259
            cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'],
 
260
                                        prog_num=daemon.GetSudoApp())
 
261
            if not cmdbase:
 
262
                error(None, language["no_sudo_prog"]) 
 
263
                return
 
264
            cmdbase.extend(cmdend)
 
265
            misc.LaunchAndWait(cmdbase)
 
266
        else:
 
267
            misc.LaunchAndWait(cmdend)
 
268
        
 
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"))
 
274
 
 
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()
 
282
        
 
283
    def save_settings(self):
 
284
        AdvancedSettingsDialog.save_settings(self)
 
285
        wired.SaveWiredNetworkProfile(self.prof_name)
 
286
        return True
 
287
 
 
288
    def format_entry(self, label):
 
289
        """ Helper method to fetch and format wired properties. """
 
290
        return noneToBlankString(wired.GetWiredProperty(label))
 
291
    
 
292
    def destroy_called(self, *args):
 
293
        """ Clean up everything. """
 
294
        self.disconnect(self.des)
 
295
        super(WiredSettingsDialog, self).destroy_called()
 
296
        self.destroy()
 
297
        del self
 
298
 
 
299
        
 
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()
 
315
        
 
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()
 
320
        
 
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"):
 
326
                activeID = x
 
327
        self.combo_encryption.set_active(activeID)
 
328
        if activeID != -1:
 
329
            self.chkbox_encryption.set_active(True)
 
330
            self.combo_encryption.set_sensitive(True)
 
331
            self.vbox_encrypt_info.set_sensitive(True)
 
332
        else:
 
333
            self.combo_encryption.set_active(0)
 
334
        self.change_encrypt_method()
 
335
 
 
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)
 
340
        
 
341
        # Connect signals.
 
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)
 
346
 
 
347
    def destroy_called(self, *args):
 
348
        """ Clean up everything. """
 
349
        self.disconnect(self.des)
 
350
        super(WirelessSettingsDialog, self).destroy_called()
 
351
        self.destroy()
 
352
        del self
 
353
        
 
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"]
 
358
        if os.getuid() != 0:
 
359
            cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'],
 
360
                                        prog_num=daemon.GetSudoApp())
 
361
            if not cmdbase:
 
362
                error(None, language["no_sudo_prog"]) 
 
363
                return
 
364
            cmdbase.extend(cmdend)
 
365
            misc.LaunchAndWait(cmdbase)
 
366
        else:
 
367
            misc.LaunchAndWait(cmdend)
 
368
        
 
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)
 
372
        
 
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"))
 
379
 
 
380
        self.chkbox_global_dns.set_active(bool(wireless.GetWirelessProperty(networkID,
 
381
                                                                  'use_global_dns')))
 
382
        self.chkbox_static_dns.set_active(bool(wireless.GetWirelessProperty(networkID,
 
383
                                                                  'use_static_dns')))
 
384
        
 
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"))
 
390
        
 
391
        self.reset_static_checkboxes()
 
392
        self.chkbox_encryption.set_active(bool(wireless.GetWirelessProperty(networkID,
 
393
                                                                       'encryption')))
 
394
        self.chkbox_global_settings.set_active(bool(wireless.GetWirelessProperty(networkID,
 
395
                                                             'use_settings_globally')))
 
396
 
 
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:
 
401
                activeID = x
 
402
        
 
403
        self.combo_encryption.set_active(activeID)
 
404
        if activeID != -1:
 
405
            self.chkbox_encryption.set_active(True)
 
406
            self.combo_encryption.set_sensitive(True)
 
407
            self.vbox_encrypt_info.set_sensitive(True)
 
408
        else:
 
409
            self.combo_encryption.set_active(0)
 
410
        self.change_encrypt_method()
 
411
        
 
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())
 
426
                          )
 
427
                    return False
 
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'])
 
436
            return False
 
437
        else:
 
438
            print "no encryption specified..."
 
439
            self.set_net_prop("enctype", "None")
 
440
        AdvancedSettingsDialog.save_settings(self)
 
441
        
 
442
        if self.chkbox_global_settings.get_active():
 
443
            self.set_net_prop('use_settings_globally', True)
 
444
        else:
 
445
            self.set_net_prop('use_settings_globally', False)
 
446
            wireless.RemoveGlobalEssidEntry(networkid)
 
447
            
 
448
        wireless.SaveWirelessNetworkProfile(networkid)
 
449
        return True
 
450
 
 
451
    def format_entry(self, networkid, label):
 
452
        """ Helper method for fetching/formatting wireless properties. """
 
453
        return noneToBlankString(wireless.GetWirelessProperty(networkid, label))
 
454
    
 
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)
 
460
 
 
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 = {}
 
468
        
 
469
        # If nothing is selected, select the first entry.
 
470
        if ID == -1:
 
471
            self.combo_encryption.set_active(0)
 
472
            ID = 0
 
473
 
 
474
        for type_ in ['required', 'optional']:
 
475
            fields = methods[ID][type_]
 
476
            for field in fields:
 
477
                if language.has_key(field[1]):
 
478
                    box = LabelEntry(language[field[1].lower().replace(' ','_')])
 
479
                else:
 
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
 
485
                # data.
 
486
                self.encryption_info[field[0]] = [box, type_]
 
487
 
 
488
                box.entry.set_text(noneToBlankString(
 
489
                    wireless.GetWirelessProperty(self.networkID, field[0])))
 
490
        self.vbox_encrypt_info.show_all()
 
491
        
 
492
        
 
493
class NetworkEntry(gtk.HBox):
 
494
    def __init__(self):
 
495
        """ Base network entry class.
 
496
        
 
497
        Provides gtk objects used by both the WiredNetworkEntry and
 
498
        WirelessNetworkEntry classes.
 
499
        
 
500
        """
 
501
        setup_dbus()
 
502
        gtk.HBox.__init__(self, False, 2)
 
503
        self.image = gtk.Image()
 
504
        self.pack_start(self.image, False, False)
 
505
 
 
506
        # Create an HBox to hold the buttons
 
507
        self.buttons_hbox = gtk.HBox(False, 6)
 
508
        
 
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()
 
514
        
 
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)
 
518
 
 
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)
 
522
        
 
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)
 
527
        
 
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)
 
536
        
 
537
        self.buttons_hbox.pack_start(self.connect_hbox, False, False)
 
538
        self.buttons_hbox.pack_start(self.advanced_button, False, False)
 
539
 
 
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)
 
544
    
 
545
    def destroy_called(self, *args):
 
546
        """ Clean up everything. """
 
547
        super(NetworkEntry, self).destroy()
 
548
        self.destroy()
 
549
        del self
 
550
        
 
551
 
 
552
class WiredNetworkEntry(NetworkEntry):
 
553
    def __init__(self):
 
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")
 
561
        self.image.show()
 
562
        self.connect_button.show()
 
563
 
 
564
        self.name_label.set_use_markup(True)
 
565
        self.name_label.set_label("<b>" + language['wired_network'] + "</b>")
 
566
        
 
567
        self.is_full_gui = True
 
568
        
 
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() 
 
574
        
 
575
        # Format the profile help label.
 
576
        self.profile_help.set_justify(gtk.JUSTIFY_LEFT)
 
577
        self.profile_help.set_line_wrap(True)
 
578
 
 
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)
 
589
 
 
590
        # Connect events
 
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)
 
596
        
 
597
        # Build profile list.
 
598
        self.profile_list = wired.GetWiredProfileList()
 
599
        default_prof = wired.GetDefaultWiredNetwork()
 
600
        if self.profile_list:
 
601
            starting_index = 0
 
602
            for x, prof in enumerate(self.profile_list):
 
603
                self.combo_profile_names.append_text(prof)
 
604
                if default_prof == prof:
 
605
                    starting_index = x
 
606
            self.combo_profile_names.set_active(starting_index)
 
607
        else:
 
608
            print "no wired profiles found"
 
609
            self.profile_help.show()
 
610
            
 
611
        self.advanced_dialog = WiredSettingsDialog(self.combo_profile_names.get_active_text())            
 
612
 
 
613
        # Show everything, but hide the profile help label.
 
614
        self.show_all()
 
615
        self.profile_help.hide()
 
616
        
 
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)
 
620
        else:
 
621
            self.chkbox_default_profile.set_active(False)
 
622
 
 
623
        self.check_enable()
 
624
        self.wireddis = self.connect("destroy", self.destroy_called)
 
625
        
 
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()
 
632
        self.destroy()
 
633
        del self
 
634
        
 
635
    def save_wired_settings(self):
 
636
        """ Save wired network settings. """
 
637
        return self.advanced_dialog.save_settings()
 
638
 
 
639
    def check_enable(self):
 
640
        """ Disable objects if the profile list is empty. """
 
641
        profile_list = wired.GetWiredProfileList()
 
642
        if not profile_list:
 
643
            self.button_delete.set_sensitive(False)
 
644
            self.connect_button.set_sensitive(False)
 
645
            self.advanced_button.set_sensitive(False)
 
646
            
 
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()
 
652
        else:
 
653
            self.disconnect_button.hide()
 
654
            self.connect_button.show()
 
655
            
 
656
    def add_profile(self, widget):
 
657
        """ Add a profile to the profile list. """
 
658
        print "adding profile"
 
659
 
 
660
        response = string_input("Enter a profile name", "The profile name " +
 
661
                                  "will not be used by the computer. It " +
 
662
                                  "allows you to " + 
 
663
                                  "easily distinguish between different network " +
 
664
                                  "profiles.", "Profile name:")
 
665
 
 
666
        # if response is "" or None
 
667
        if not response:
 
668
            return
 
669
 
 
670
        profile_name = response
 
671
        profile_list = wired.GetWiredProfileList()
 
672
        if profile_list:
 
673
            if profile_name in profile_list:
 
674
                return False
 
675
 
 
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
 
681
        if self.is_full_gui:
 
682
            self.button_delete.set_sensitive(True)
 
683
            self.connect_button.set_sensitive(True)
 
684
            self.advanced_button.set_sensitive(True)
 
685
 
 
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.
 
692
                                                                 get_active())
 
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
 
698
            entry.set_text("")
 
699
            if self.is_full_gui:
 
700
                self.button_delete.set_sensitive(False)
 
701
                self.advanced_button.set_sensitive(False)
 
702
                self.connect_button.set_sensitive(False)
 
703
        else:
 
704
            self.profile_help.hide()
 
705
 
 
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())
 
714
 
 
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:
 
720
                return
 
721
            
 
722
            profile_name = self.combo_profile_names.get_active_text()
 
723
            wired.ReadWiredNetworkProfile(profile_name)
 
724
 
 
725
            if hasattr(self, 'advanced_dialog'):
 
726
                self.advanced_dialog.prof_name = profile_name
 
727
                self.advanced_dialog.set_values()
 
728
            
 
729
            is_default = wired.GetWiredProperty("default")
 
730
            self.chkbox_default_profile.set_active(to_bool(is_default))
 
731
 
 
732
    def format_entry(self, label):
 
733
        """ Help method for fetching/formatting wired properties. """
 
734
        return noneToBlankString(wired.GetWiredProperty(label))
 
735
 
 
736
 
 
737
class WirelessNetworkEntry(NetworkEntry):
 
738
    def __init__(self, networkID):
 
739
        """ Build the wireless network entry. """
 
740
        NetworkEntry.__init__(self)
 
741
 
 
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)
 
746
        self.image.show()
 
747
        self.essid = noneToBlankString(wireless.GetWirelessProperty(networkID,
 
748
                                                                    "essid"))
 
749
        self.lbl_strength = GreyLabel()
 
750
        self.lbl_encryption = GreyLabel()
 
751
        self.lbl_channel = GreyLabel()
 
752
        
 
753
        print "ESSID : " + self.essid
 
754
        self.chkbox_autoconnect = gtk.CheckButton(language['automatic_connect'])
 
755
        
 
756
        self.set_signal_strength(wireless.GetWirelessProperty(networkID, 
 
757
                                                              'quality'),
 
758
                                 wireless.GetWirelessProperty(networkID, 
 
759
                                                              'strength'))
 
760
        self.set_encryption(wireless.GetWirelessProperty(networkID, 
 
761
                                                         'encryption'),
 
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(),
 
770
                                                        )
 
771
                                 )
 
772
        # Add the wireless network specific parts to the NetworkEntry
 
773
        # VBox objects.
 
774
        self.vbox_top.pack_start(self.chkbox_autoconnect, False, False)
 
775
 
 
776
        if to_bool(self.format_entry(networkID, "automatic")):
 
777
            self.chkbox_autoconnect.set_active(True)
 
778
        else:
 
779
            self.chkbox_autoconnect.set_active(False)
 
780
        
 
781
        # Connect signals.
 
782
        self.chkbox_autoconnect.connect("toggled", self.update_autoconnect)      
 
783
        
 
784
        # Show everything
 
785
        self.show_all()
 
786
        self.advanced_dialog = WirelessSettingsDialog(networkID)
 
787
        self.wifides = self.connect("destroy", self.destroy_called)
 
788
    
 
789
    def _escape(self, val):
 
790
        """ Escapes special characters so they're displayed correctly. """
 
791
        return val.replace("&", "&amp;").replace("<", "&lt;").\
 
792
                   replace(">","&gt;").replace("'", "&apos;").replace('"', "&quot;")
 
793
    
 
794
    def save_wireless_settings(self, networkid):
 
795
        """ Save wireless network settings. """
 
796
        return self.advanced_dialog.save_settings(networkid)
 
797
    
 
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.
 
802
                                                  get_active()))
 
803
        wireless.SaveWirelessNetworkProperty(self.networkID, "automatic")
 
804
 
 
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()
 
811
        self.destroy()
 
812
        del self
 
813
        
 
814
    def update_connect_button(self, state, apbssid):
 
815
        """ Update the connection/disconnect button for this entry. """
 
816
        if not apbssid:
 
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()
 
822
        else:
 
823
            self.disconnect_button.hide()
 
824
            self.connect_button.show()
 
825
            
 
826
    def set_signal_strength(self, strength, dbm_strength):
 
827
        """ Set the signal strength displayed in the WirelessNetworkEntry. """
 
828
        if strength:
 
829
            strength = int(strength)
 
830
        else:
 
831
            strength = -1
 
832
        if dbm_strength:
 
833
            dbm_strength = int(dbm_strength)
 
834
        else:
 
835
            dbm_strength = -100
 
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'
 
848
            else:
 
849
                signal_img = 'signal-25.png'
 
850
            ending = "dBm"
 
851
            disp_strength = str(dbm_strength)
 
852
        else:
 
853
            # Uses normal link quality, should be fine in most cases
 
854
            if strength > 75:
 
855
                signal_img = 'signal-100.png'
 
856
            elif strength > 50:
 
857
                signal_img = 'signal-75.png'
 
858
            elif strength > 25:
 
859
                signal_img = 'signal-50.png'
 
860
            else:
 
861
                signal_img = 'signal-25.png'
 
862
            ending = "%"
 
863
            disp_strength = str(strength)
 
864
        self.image.set_from_file(wpath.images + signal_img)
 
865
        self.lbl_strength.set_label(disp_strength + ending)
 
866
        self.image.show()
 
867
        
 
868
    def set_encryption(self, on, ttype):
 
869
        """ Set the encryption value for the WirelessNetworkEntry. """
 
870
        if on and ttype:
 
871
            self.lbl_encryption.set_label(str(ttype))
 
872
        if on and not ttype: 
 
873
            self.lbl_encryption.set_label(language['secured'])
 
874
        if not on:
 
875
            self.lbl_encryption.set_label(language['unsecured'])
 
876
            
 
877
    def set_channel(self, channel):
 
878
        """ Set the channel value for the WirelessNetworkEntry. """
 
879
        self.lbl_channel.set_label(language['channel'] + ' ' + str(channel))
 
880
 
 
881
    def format_entry(self, networkid, label):
 
882
        """ Helper method for fetching/formatting wireless properties. """
 
883
        return noneToBlankString(wireless.GetWirelessProperty(networkid, label))
 
884
 
 
885
        
 
886
class WirelessInformationDialog(gtk.Dialog):
 
887
    def __init__(self, networkID, parent):
 
888
        gtk.Dialog.__init__(self,parent=parent)
 
889
        
 
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)
 
902
        
 
903
        # Set the values of the network info labels.
 
904
        self.set_signal_strength(wireless.GetWirelessProperty(networkID, 
 
905
                                                              'quality'),
 
906
                                 wireless.GetWirelessProperty(networkID, 
 
907
                                                              'strength'))
 
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,
 
912
                                                         'encryption'),
 
913
                            wireless.GetWirelessProperty(networkID, 
 
914
                                                        'encryption_method'))
 
915
        
 
916
        self.set_title('Network Information')
 
917
        vbox = self.vbox
 
918
        self.set_has_separator(False)
 
919
        table = gtk.Table(5, 2)
 
920
        table.set_col_spacings(12) 
 
921
        vbox.pack_start(table)
 
922
        
 
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)
 
926
 
 
927
        table.attach(LeftAlignedLabel('Encryption type:'), 0, 1, 1, 2)
 
928
        table.attach(self.lbl_encryption, 1, 2, 1, 2)
 
929
 
 
930
        table.attach(LeftAlignedLabel('Access point address:'), 0, 1, 2, 3)
 
931
        table.attach(self.lbl_mac, 1, 2, 2, 3)
 
932
 
 
933
        table.attach(LeftAlignedLabel('Mode:'), 0, 1, 3, 4)
 
934
        table.attach(self.lbl_mode, 1, 2, 3, 4)
 
935
 
 
936
        table.attach(LeftAlignedLabel('Channel:'), 0, 1, 4, 5)
 
937
        table.attach(self.lbl_channel, 1, 2, 4, 5)
 
938
 
 
939
        vbox.show_all()
 
940
 
 
941
        self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
 
942
        self.show()
 
943
        self.run()
 
944
        self.destroy()
 
945
        
 
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)
 
950
        else:
 
951
            strength = -1
 
952
        if dbm_strength is not None:
 
953
            dbm_strength = int(dbm_strength)
 
954
        else:
 
955
            dbm_strength = -100
 
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'
 
968
            else:
 
969
                signal_img = 'signal-25.png'
 
970
            ending = "dBm"
 
971
            disp_strength = str(dbm_strength)
 
972
        else:
 
973
            # Uses normal link quality, should be fine in most cases
 
974
            if strength > 75:
 
975
                signal_img = 'signal-100.png'
 
976
            elif strength > 50:
 
977
                signal_img = 'signal-75.png'
 
978
            elif strength > 25:
 
979
                signal_img = 'signal-50.png'
 
980
            else:
 
981
                signal_img = 'signal-25.png'
 
982
            ending = "%"
 
983
            disp_strength = str(strength)
 
984
        self.lbl_strength.set_label(disp_strength + ending)
 
985
 
 
986
    def set_mac_address(self, address):
 
987
        """ Set the MAC address for the WirelessNetworkEntry. """
 
988
        self.lbl_mac.set_label(str(address))
 
989
 
 
990
    def set_encryption(self, on, ttype):
 
991
        """ Set the encryption value for the WirelessNetworkEntry. """
 
992
        if on and ttype:
 
993
            self.lbl_encryption.set_label(str(ttype))
 
994
        if on and not ttype: 
 
995
            self.lbl_encryption.set_label(language['secured'])
 
996
        if not on:
 
997
            self.lbl_encryption.set_label(language['unsecured'])
 
998
 
 
999
    def set_channel(self, channel):
 
1000
        """ Set the channel value for the WirelessNetworkEntry. """
 
1001
        self.lbl_channel.set_label(language['channel'] + ' ' + str(channel))
 
1002
 
 
1003
    def set_mode(self, mode):
 
1004
        """ Set the mode value for the WirelessNetworkEntry. """
 
1005
        self.lbl_mode.set_label(str(mode))
 
1006
 
 
1007
    def format_entry(self, networkid, label):
 
1008
        """ Helper method for fetching/formatting wireless properties. """
 
1009
        return noneToBlankString(wireless.GetWirelessProperty(networkid, label))