From 07b0be8f4dbc6ebd8c14ef67f554899e87739ac6 Mon Sep 17 00:00:00 2001 From: Sean Robinson Date: Fri, 2 Jan 2009 11:03:07 -0700 Subject: [PATCH] Change ConnectionManager API Init without profile and check current state. Pass profile to connect_to_network() Change calls from radar_window to reflect new API. Update connect/disconnect buttons with ConnectionManager.state --- wifi-radar | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/wifi-radar b/wifi-radar index 9366aba..581bfb7 100755 --- a/wifi-radar +++ b/wifi-radar @@ -213,18 +213,22 @@ def scanning_thread( confFile, apQueue, commandQueue ): ### ConnectionManager ### class to manage connections class ConnectionManager(): - def __init__( self, profile, confFile, commandQueue ): - self.profile = profile + def __init__( self, confFile, commandQueue ): self.confFile = confFile self.commQueue = commandQueue + # is connection running? self.state = False + if self.get_current_ip(): + self.state = True + print "Connection state is currently:", self.state def if_change( self, state ): if ( (state.lower() == 'up') or (state.lower() == 'down') ): # call ifconfig command and wait for return Popen([self.confFile.get_opt('DEFAULT.ifconfig_command'), self.confFile.get_opt('DEFAULT.interface'), state]) - def connect_to_network( self, status_window ): + def connect_to_network( self, profile, status_window ): + self.profile = profile msg = "Connecting to the %s (%s) network" % ( self.profile['essid'], self.profile['bssid'] ) say( msg ) if __debug__: print " %s" % msg @@ -637,6 +641,9 @@ class radar_window: self.disconnect_button.hide() self.connect_button.hide() + # set up connection manager for later use + self.connection = ConnectionManager( self.confFile, self.commandQueue ) + # Add our known profiles in order for ap in self.confFile.auto_profile_order: ap = ap.strip() @@ -682,13 +689,14 @@ class radar_window: # update the current ip and essid # set the state of connect/disconnect buttons based on whether we have an IP address if self.connection: - self.current_network.set_text( "Connected to %s ip(%s)" % ( self.connection.get_current_essid(), self.connection.get_current_ip() ) ) - if self.connection.get_current_ip(): + if self.connection.state: + self.current_network.set_text( "Connected to %s ip(%s)" % ( self.connection.get_current_essid(), self.connection.get_current_ip() ) ) self.connect_button.hide() self.disconnect_button.show() - else: - self.disconnect_button.hide() - self.connect_button.show() + else: + self.current_network.set_text( "Not Connected." ) + self.disconnect_button.hide() + self.connect_button.show() while True: # Get profiles scanned by iwlist @@ -884,8 +892,7 @@ class radar_window: if not self.create_new_profile( widget, profile, data ): return apname = make_section_name( store.get_value( selected_iter, 0 ), store.get_value( selected_iter, 1 ) ) - self.connection = ConnectionManager( self.access_points[apname], self.confFile, self.commandQueue ) - self.connection.connect_to_network( status_window( self ) ) + self.connection.connect_to_network( self.access_points[apname], status_window( self ) ) def disconnect_profile( self, widget, data=None ): self.connection.disconnect_interface( status_window( self ) ) -- 2.11.4.GIT