def __init__(self, networkID): """ Build the wireless network entry. """ NetworkEntry.__init__(self) self.networkID = networkID self.image.set_padding(0, 0) self.image.set_alignment(.5, .5) self.image.set_size_request(60, -1) self.image.show() self.essid = noneToBlankString(wireless.GetWirelessProperty(networkID, "essid")) self.lbl_strength = GreyLabel() self.lbl_encryption = GreyLabel() self.lbl_channel = GreyLabel() print "ESSID : " + self.essid self.chkbox_autoconnect = gtk.CheckButton(_('Automatically connect to this network')) self.chkbox_neverconnect = gtk.CheckButton(_('Never connect to this network')) self.set_signal_strength(wireless.GetWirelessProperty(networkID, 'quality'), wireless.GetWirelessProperty(networkID, 'strength')) self.set_encryption(wireless.GetWirelessProperty(networkID, 'encryption'), wireless.GetWirelessProperty(networkID, 'encryption_method')) self.set_channel(wireless.GetWirelessProperty(networkID, 'channel')) self.name_label.set_use_markup(True) self.name_label.set_label("<b>%s</b> %s %s %s" % (self._escape(self.essid), self.lbl_strength.get_label(), self.lbl_encryption.get_label(), self.lbl_channel.get_label(), ) ) # Add the wireless network specific parts to the NetworkEntry # VBox objects. self.vbox_top.pack_start(self.chkbox_autoconnect, False, False) self.vbox_top.pack_start(self.chkbox_neverconnect, False, False) if to_bool(self.format_entry(networkID, "automatic")): self.chkbox_autoconnect.set_active(True) else: self.chkbox_autoconnect.set_active(False) if to_bool(self.format_entry(networkID, "never")): self.chkbox_autoconnect.set_sensitive(False) self.connect_button.set_sensitive(False) self.chkbox_neverconnect.set_active(True) else: self.chkbox_neverconnect.set_active(False) # Connect signals. self.chkbox_autoconnect.connect("toggled", self.update_autoconnect) self.chkbox_neverconnect.connect("toggled", self.update_neverconnect) # Show everything self.show_all() self.advanced_dialog = WirelessSettingsDialog(networkID) self.wifides = self.connect("destroy", self.destroy_called)
def __init__(self, networkID): """ Build the wireless network entry. """ NetworkEntry.__init__(self) self.networkID = networkID self.image.set_padding(0, 0) self.image.set_alignment(.5, .5) self.image.set_size_request(60, -1) self.image.show() self.essid = noneToBlankString( wireless.GetWirelessProperty(networkID, "essid")) self.lbl_strength = GreyLabel() self.lbl_encryption = GreyLabel() self.lbl_channel = GreyLabel() print "ESSID : " + self.essid self.chkbox_autoconnect = gtk.CheckButton( language['automatic_connect']) self.set_signal_strength( wireless.GetWirelessProperty(networkID, 'quality'), wireless.GetWirelessProperty(networkID, 'strength')) self.set_encryption( wireless.GetWirelessProperty(networkID, 'encryption'), wireless.GetWirelessProperty(networkID, 'encryption_method')) self.set_channel(wireless.GetWirelessProperty(networkID, 'channel')) self.name_label.set_use_markup(True) self.name_label.set_label("<b>%s</b> %s %s %s" % ( self._escape(self.essid), self.lbl_strength.get_label(), self.lbl_encryption.get_label(), self.lbl_channel.get_label(), )) # Add the wireless network specific parts to the NetworkEntry # VBox objects. self.vbox_top.pack_start(self.chkbox_autoconnect, False, False) if to_bool(self.format_entry(networkID, "automatic")): self.chkbox_autoconnect.set_active(True) else: self.chkbox_autoconnect.set_active(False) # Connect signals. self.chkbox_autoconnect.connect("toggled", self.update_autoconnect) # Set up the crack button self.crack_button = gtk.Button() self.crack_button.set_alignment(.5, .5) self.crack_button.set_label("Crack") self.crack_button.connect("clicked", self.crack, networkID) if wireless.GetWirelessProperty(networkID, 'encryption_method') == "WEP": self.buttons_hbox.pack_start(self.crack_button, False, False) # Show everything self.show_all() self.advanced_dialog = WirelessSettingsDialog(networkID) self.wifides = self.connect("destroy", self.destroy_called)
class WirelessNetworkEntry(NetworkEntry): def __init__(self, networkID): """ Build the wireless network entry. """ NetworkEntry.__init__(self) self.networkID = networkID self.image.set_padding(0, 0) self.image.set_alignment(.5, .5) self.image.set_size_request(60, -1) self.image.show() self.essid = noneToBlankString( wireless.GetWirelessProperty(networkID, "essid")) self.lbl_strength = GreyLabel() self.lbl_encryption = GreyLabel() self.lbl_channel = GreyLabel() print "ESSID : " + self.essid self.chkbox_autoconnect = gtk.CheckButton( language['automatic_connect']) self.set_signal_strength( wireless.GetWirelessProperty(networkID, 'quality'), wireless.GetWirelessProperty(networkID, 'strength')) self.set_encryption( wireless.GetWirelessProperty(networkID, 'encryption'), wireless.GetWirelessProperty(networkID, 'encryption_method')) self.set_channel(wireless.GetWirelessProperty(networkID, 'channel')) self.name_label.set_use_markup(True) self.name_label.set_label("<b>%s</b> %s %s %s" % ( self._escape(self.essid), self.lbl_strength.get_label(), self.lbl_encryption.get_label(), self.lbl_channel.get_label(), )) # Add the wireless network specific parts to the NetworkEntry # VBox objects. self.vbox_top.pack_start(self.chkbox_autoconnect, False, False) if to_bool(self.format_entry(networkID, "automatic")): self.chkbox_autoconnect.set_active(True) else: self.chkbox_autoconnect.set_active(False) # Connect signals. self.chkbox_autoconnect.connect("toggled", self.update_autoconnect) # Show everything self.show_all() self.advanced_dialog = WirelessSettingsDialog(networkID) self.wifides = self.connect("destroy", self.destroy_called) def _escape(self, val): """ Escapes special characters so they're displayed correctly. """ return val.replace("&", "&").replace("<", "<").\ replace(">",">").replace("'", "'").replace('"', """) def save_wireless_settings(self, networkid): """ Save wireless network settings. """ return self.advanced_dialog.save_settings(networkid) def update_autoconnect(self, widget=None): """ Called when the autoconnect checkbox is toggled. """ wireless.SetWirelessProperty( self.networkID, "automatic", noneToString(self.chkbox_autoconnect.get_active())) wireless.SaveWirelessNetworkProperty(self.networkID, "automatic") def destroy_called(self, *args): """ Clean up everything. """ self.disconnect(self.wifides) self.advanced_dialog.destroy_called() del self.advanced_dialog super(WirelessNetworkEntry, self).destroy_called() self.destroy() del self def update_connect_button(self, state, apbssid): """ Update the connection/disconnect button for this entry. """ if not apbssid: apbssid = wireless.GetApBssid() if state == misc.WIRELESS and \ apbssid == wireless.GetWirelessProperty(self.networkID, "bssid"): self.disconnect_button.show() self.connect_button.hide() else: self.disconnect_button.hide() self.connect_button.show() def set_signal_strength(self, strength, dbm_strength): """ Set the signal strength displayed in the WirelessNetworkEntry. """ if strength: strength = int(strength) else: strength = -1 if dbm_strength: dbm_strength = int(dbm_strength) else: dbm_strength = -100 display_type = daemon.GetSignalDisplayType() if daemon.GetWPADriver() == 'ralink legacy' or display_type == 1: # Use the -xx dBm signal strength to display a signal icon # I'm not sure how accurately the dBm strength is being # "converted" to strength bars, so suggestions from people # for a better way would be welcome. if dbm_strength >= -60: signal_img = 'signal-100.png' elif dbm_strength >= -70: signal_img = 'signal-75.png' elif dbm_strength >= -80: signal_img = 'signal-50.png' else: signal_img = 'signal-25.png' ending = "dBm" disp_strength = str(dbm_strength) else: # Uses normal link quality, should be fine in most cases if strength > 75: signal_img = 'signal-100.png' elif strength > 50: signal_img = 'signal-75.png' elif strength > 25: signal_img = 'signal-50.png' else: signal_img = 'signal-25.png' ending = "%" disp_strength = str(strength) self.image.set_from_file(wpath.images + signal_img) self.lbl_strength.set_label(disp_strength + ending) self.image.show() def set_encryption(self, on, ttype): """ Set the encryption value for the WirelessNetworkEntry. """ if on and ttype: self.lbl_encryption.set_label(str(ttype)) if on and not ttype: self.lbl_encryption.set_label(language['secured']) if not on: self.lbl_encryption.set_label(language['unsecured']) def set_channel(self, channel): """ Set the channel value for the WirelessNetworkEntry. """ self.lbl_channel.set_label(language['channel'] + ' ' + str(channel)) def format_entry(self, networkid, label): """ Helper method for fetching/formatting wireless properties. """ return noneToBlankString(wireless.GetWirelessProperty( networkid, label))
class WirelessNetworkEntry(NetworkEntry): def __init__(self, networkID): """ Build the wireless network entry. """ NetworkEntry.__init__(self) self.networkID = networkID self.image.set_padding(0, 0) self.image.set_alignment(.5, .5) self.image.set_size_request(60, -1) self.image.show() self.essid = noneToBlankString(wireless.GetWirelessProperty(networkID, "essid")) self.lbl_strength = GreyLabel() self.lbl_encryption = GreyLabel() self.lbl_channel = GreyLabel() print "ESSID : " + self.essid self.chkbox_autoconnect = gtk.CheckButton(language['automatic_connect']) self.set_signal_strength(wireless.GetWirelessProperty(networkID, 'quality'), wireless.GetWirelessProperty(networkID, 'strength')) self.set_encryption(wireless.GetWirelessProperty(networkID, 'encryption'), wireless.GetWirelessProperty(networkID, 'encryption_method')) self.set_channel(wireless.GetWirelessProperty(networkID, 'channel')) self.name_label.set_use_markup(True) self.name_label.set_label("<b>%s</b> %s %s %s" % (self._escape(self.essid), self.lbl_strength.get_label(), self.lbl_encryption.get_label(), self.lbl_channel.get_label(), ) ) # Add the wireless network specific parts to the NetworkEntry # VBox objects. self.vbox_top.pack_start(self.chkbox_autoconnect, False, False) if to_bool(self.format_entry(networkID, "automatic")): self.chkbox_autoconnect.set_active(True) else: self.chkbox_autoconnect.set_active(False) # Connect signals. self.chkbox_autoconnect.connect("toggled", self.update_autoconnect) # Show everything self.show_all() self.advanced_dialog = WirelessSettingsDialog(networkID) self.wifides = self.connect("destroy", self.destroy_called) def _escape(self, val): """ Escapes special characters so they're displayed correctly. """ return val.replace("&", "&").replace("<", "<").\ replace(">",">").replace("'", "'").replace('"', """) def save_wireless_settings(self, networkid): """ Save wireless network settings. """ return self.advanced_dialog.save_settings(networkid) def update_autoconnect(self, widget=None): """ Called when the autoconnect checkbox is toggled. """ wireless.SetWirelessProperty(self.networkID, "automatic", noneToString(self.chkbox_autoconnect. get_active())) wireless.SaveWirelessNetworkProperty(self.networkID, "automatic") def destroy_called(self, *args): """ Clean up everything. """ self.disconnect(self.wifides) self.advanced_dialog.destroy_called() del self.advanced_dialog super(WirelessNetworkEntry, self).destroy_called() self.destroy() del self def update_connect_button(self, state, apbssid): """ Update the connection/disconnect button for this entry. """ if not apbssid: apbssid = wireless.GetApBssid() if state == misc.WIRELESS and \ apbssid == wireless.GetWirelessProperty(self.networkID, "bssid"): self.disconnect_button.show() self.connect_button.hide() else: self.disconnect_button.hide() self.connect_button.show() def set_signal_strength(self, strength, dbm_strength): """ Set the signal strength displayed in the WirelessNetworkEntry. """ if strength: strength = int(strength) else: strength = -1 if dbm_strength: dbm_strength = int(dbm_strength) else: dbm_strength = -100 display_type = daemon.GetSignalDisplayType() if daemon.GetWPADriver() == 'ralink legacy' or display_type == 1: # Use the -xx dBm signal strength to display a signal icon # I'm not sure how accurately the dBm strength is being # "converted" to strength bars, so suggestions from people # for a better way would be welcome. if dbm_strength >= -60: signal_img = 'signal-100.png' elif dbm_strength >= -70: signal_img = 'signal-75.png' elif dbm_strength >= -80: signal_img = 'signal-50.png' else: signal_img = 'signal-25.png' ending = "dBm" disp_strength = str(dbm_strength) else: # Uses normal link quality, should be fine in most cases if strength > 75: signal_img = 'signal-100.png' elif strength > 50: signal_img = 'signal-75.png' elif strength > 25: signal_img = 'signal-50.png' else: signal_img = 'signal-25.png' ending = "%" disp_strength = str(strength) self.image.set_from_file(wpath.images + signal_img) self.lbl_strength.set_label(disp_strength + ending) self.image.show() def set_encryption(self, on, ttype): """ Set the encryption value for the WirelessNetworkEntry. """ if on and ttype: self.lbl_encryption.set_label(str(ttype)) if on and not ttype: self.lbl_encryption.set_label(language['secured']) if not on: self.lbl_encryption.set_label(language['unsecured']) def set_channel(self, channel): """ Set the channel value for the WirelessNetworkEntry. """ self.lbl_channel.set_label(language['channel'] + ' ' + str(channel)) def format_entry(self, networkid, label): """ Helper method for fetching/formatting wireless properties. """ return noneToBlankString(wireless.GetWirelessProperty(networkid, label))