mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 12:58:07 +01:00
Testing/Experimental:
- Fixed bug where monitor would crash on resume because dbus wasn't ready yet. - Monitor now calls a rescan every 2 minutes. Experimental: - Added a network list submenu to the right-click menu of the tray icon.
This commit is contained in:
@@ -173,7 +173,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
self.AutoConnect(True)
|
||||
else:
|
||||
self.Scan()
|
||||
self.SetForcedDisconnect(True)
|
||||
#self.SetForcedDisconnect(True)
|
||||
print "--no-scan detected, not autoconnecting..."
|
||||
|
||||
########## DAEMON FUNCTIONS
|
||||
|
||||
90
monitor.py
90
monitor.py
@@ -155,42 +155,46 @@ class ConnectionStatus():
|
||||
wired_ip = None
|
||||
wifi_ip = None
|
||||
|
||||
if daemon.GetSuspend():
|
||||
print "Suspended."
|
||||
state = misc.SUSPENDED
|
||||
try:
|
||||
if daemon.GetSuspend():
|
||||
print "Suspended."
|
||||
state = misc.SUSPENDED
|
||||
self.update_state(state)
|
||||
return True
|
||||
|
||||
# Determine what our current state is.
|
||||
# Check for wired.
|
||||
wired_ip = wired.GetWiredIP(self.fast)
|
||||
wired_found = self.check_for_wired_connection(wired_ip)
|
||||
if wired_found:
|
||||
self.update_state(misc.WIRED, wired_ip=wired_ip)
|
||||
return True
|
||||
|
||||
# Check for wireless
|
||||
wifi_ip = wireless.GetWirelessIP(self.fast)
|
||||
#self.iwconfig = wireless.GetIwconfig()
|
||||
self.signal_changed = False
|
||||
wireless_found = self.check_for_wireless_connection(wifi_ip)
|
||||
if wireless_found:
|
||||
self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
|
||||
return True
|
||||
|
||||
# Are we currently connecting?
|
||||
if daemon.CheckIfConnecting():
|
||||
state = misc.CONNECTING
|
||||
else: # No connection at all.
|
||||
state = misc.NOT_CONNECTED
|
||||
if self.last_state == misc.WIRELESS:
|
||||
from_wireless = True
|
||||
else:
|
||||
from_wireless = False
|
||||
self.auto_reconnect(from_wireless)
|
||||
self.update_state(state)
|
||||
except dbus.exceptions.DBusException, e:
|
||||
print 'DBus Error: ' + str(e)
|
||||
finally:
|
||||
return True
|
||||
|
||||
# Determine what our current state is.
|
||||
# Check for wired.
|
||||
wired_ip = wired.GetWiredIP(self.fast)
|
||||
wired_found = self.check_for_wired_connection(wired_ip)
|
||||
if wired_found:
|
||||
self.update_state(misc.WIRED, wired_ip=wired_ip)
|
||||
return True
|
||||
|
||||
# Check for wireless
|
||||
wifi_ip = wireless.GetWirelessIP(self.fast)
|
||||
#self.iwconfig = wireless.GetIwconfig()
|
||||
self.signal_changed = False
|
||||
wireless_found = self.check_for_wireless_connection(wifi_ip)
|
||||
if wireless_found:
|
||||
self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
|
||||
return True
|
||||
|
||||
# Are we currently connecting?
|
||||
if daemon.CheckIfConnecting():
|
||||
state = misc.CONNECTING
|
||||
else: # No connection at all.
|
||||
state = misc.NOT_CONNECTED
|
||||
if self.last_state == misc.WIRELESS:
|
||||
from_wireless = True
|
||||
else:
|
||||
from_wireless = False
|
||||
self.auto_reconnect(from_wireless)
|
||||
self.update_state(state)
|
||||
return True
|
||||
|
||||
def update_state(self, state, wired_ip=None, wifi_ip=None):
|
||||
""" Set the current connection state. """
|
||||
# Set our connection state/info.
|
||||
@@ -262,6 +266,17 @@ class ConnectionStatus():
|
||||
error_handler=err_handle)
|
||||
self.reconnecting = False
|
||||
|
||||
def rescan_networks(self):
|
||||
""" Calls a wireless scan. """
|
||||
try:
|
||||
if daemon.GetSuspend():
|
||||
return True
|
||||
wireless.Scan()
|
||||
except dbus.exceptions.DBusException:
|
||||
pass
|
||||
finally:
|
||||
return True
|
||||
|
||||
def reply_handle():
|
||||
""" Just a dummy function needed for asynchronous dbus calls. """
|
||||
pass
|
||||
@@ -272,9 +287,16 @@ def err_handle(error):
|
||||
|
||||
|
||||
def main():
|
||||
""" Start the connection monitor and set the updater to run every 2 sec. """
|
||||
""" Starts the connection monitor.
|
||||
|
||||
Starts a ConnectionStatus instance, sets the status to update
|
||||
every two seconds, and sets a wireless scan to be called every
|
||||
two minutes.
|
||||
|
||||
"""
|
||||
monitor = ConnectionStatus()
|
||||
gobject.timeout_add(2000, monitor.update_connection_status)
|
||||
gobject.timeout_add(120000, monitor.rescan_networks)
|
||||
|
||||
mainloop = gobject.MainLoop()
|
||||
mainloop.run()
|
||||
|
||||
121
wicd.py
121
wicd.py
@@ -323,20 +323,20 @@ class TrayIcon:
|
||||
def __init__(self, use_tray):
|
||||
menu = """
|
||||
<ui>
|
||||
<menubar name="Menubar">
|
||||
<menu action="Menu">
|
||||
<menuitem action="Connect"/>
|
||||
<separator/>
|
||||
<menuitem action="About"/>
|
||||
<menuitem action="Quit"/>
|
||||
</menu>
|
||||
</menubar>
|
||||
<menubar name="Menubar">
|
||||
<menu action="Menu">
|
||||
<menu action="Connect">
|
||||
</menu>
|
||||
<separator/>
|
||||
<menuitem action="About"/>
|
||||
<menuitem action="Quit"/>
|
||||
</menu>
|
||||
</menubar>
|
||||
</ui>
|
||||
"""
|
||||
actions = [
|
||||
('Menu', None, 'Menu'),
|
||||
('Connect', gtk.STOCK_CONNECT, '_Connect...', None,
|
||||
'Connect to network', self.on_preferences),
|
||||
('Connect', gtk.STOCK_CONNECT, "Connect"),
|
||||
('About', gtk.STOCK_ABOUT, '_About...', None,
|
||||
'About wicd-tray-icon', self.on_about),
|
||||
('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon',
|
||||
@@ -361,20 +361,103 @@ class TrayIcon:
|
||||
""" Closes the tray icon. """
|
||||
sys.exit(0)
|
||||
|
||||
def on_preferences(self, data=None):
|
||||
""" Opens the wicd GUI. """
|
||||
self.toggle_wicd_gui()
|
||||
|
||||
def on_about(self, data = None):
|
||||
def on_about(self, data=None):
|
||||
""" Opens the About Dialog. """
|
||||
dialog = gtk.AboutDialog()
|
||||
dialog.set_name('wicd tray icon')
|
||||
dialog.set_version('1.0')
|
||||
dialog.set_name('Wicd Tray Icon')
|
||||
dialog.set_version('2.0')
|
||||
dialog.set_comments('An icon that shows your network connectivity')
|
||||
dialog.set_website('http://wicd.sourceforge.net')
|
||||
dialog.set_website('http://wicd.net')
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
def _add_item_to_menu(self, net_menu, lbl, type_, n_id, is_connecting):
|
||||
""" Add an item to the network list submenu. """
|
||||
def network_selected(widget, net_type, net_id):
|
||||
""" Callback method for a menu item selection. """
|
||||
if net_type == "wired":
|
||||
wired.ConnectWired()
|
||||
else:
|
||||
wireless.ConnectWireless(net_id)
|
||||
|
||||
item = gtk.ImageMenuItem(lbl)
|
||||
image = gtk.Image()
|
||||
|
||||
if type_ == "wired":
|
||||
image.set_from_icon_name("network-wired", 2)
|
||||
else:
|
||||
pb = gtk.gdk.pixbuf_new_from_file_at_size(self._get_img(n_id),
|
||||
20, 20)
|
||||
image.set_from_pixbuf(pb)
|
||||
item.set_image(image)
|
||||
item.connect("activate", network_selected, type_, n_id)
|
||||
net_menu.append(item)
|
||||
item.show()
|
||||
if is_connecting:
|
||||
item.set_sensitive(False)
|
||||
|
||||
def _get_img(self, net_id):
|
||||
""" Determines which image to use for the wireless entries. """
|
||||
def fix_strength(val, default):
|
||||
""" Assigns given strength to a default value if needed. """
|
||||
return val is not None and int(val) or default
|
||||
|
||||
def get_prop(prop):
|
||||
return wireless.GetWirelessProperty(net_id, prop)
|
||||
|
||||
strength = fix_strength(get_prop("quality"), -1)
|
||||
dbm_strength = fix_strength(get_prop('strength'), -100)
|
||||
|
||||
if daemon.GetWPADriver() == 'ralink legacy' or \
|
||||
daemon.GetSignalDisplayType() == 1:
|
||||
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'
|
||||
else:
|
||||
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'
|
||||
return wpath.images + signal_img
|
||||
|
||||
def populate_network_menu(self, data=None):
|
||||
""" Populates the network list submenu. """
|
||||
def get_prop(net_id, prop):
|
||||
return wireless.GetWirelessProperty(net_id, prop)
|
||||
|
||||
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
|
||||
net_menuitem.get_submenu().destroy()
|
||||
net_menu = gtk.Menu()
|
||||
is_connecting = daemon.CheckIfConnecting()
|
||||
num_networks = wireless.GetNumberOfNetworks()
|
||||
#TODO Eventually do something to indicate the active network.
|
||||
#[status, info] = daemon.GetConnectionStatus()
|
||||
|
||||
if wired.GetAlwaysShowWiredInterface() or \
|
||||
wired.CheckPluggedIn(True):
|
||||
self._add_item_to_menu(net_menu, "Wired Network", "wired", 0,
|
||||
is_connecting)
|
||||
sep = gtk.SeparatorMenuItem()
|
||||
net_menu.append(sep)
|
||||
sep.show()
|
||||
|
||||
if num_networks > 0:
|
||||
for x in range(0, num_networks):
|
||||
self._add_item_to_menu(net_menu, get_prop(x, "essid"),
|
||||
"wifi", x, is_connecting)
|
||||
|
||||
net_menuitem.set_submenu(net_menu)
|
||||
net_menuitem.show()
|
||||
|
||||
def toggle_wicd_gui(self):
|
||||
""" Toggles the wicd GUI. """
|
||||
if not self.gui_win:
|
||||
@@ -419,6 +502,7 @@ class TrayIcon:
|
||||
if event.button == 1:
|
||||
self.toggle_wicd_gui()
|
||||
elif event.button == 3:
|
||||
self.populate_network_menu()
|
||||
self.menu.popup(None, None, None, event.button, event.time)
|
||||
|
||||
def set_from_file(self, val=None):
|
||||
@@ -461,6 +545,7 @@ class TrayIcon:
|
||||
|
||||
def on_popup_menu(self, status, button, timestamp):
|
||||
""" Opens the right click menu for the tray icon. """
|
||||
self.populate_network_menu()
|
||||
self.menu.popup(None, None, None, button, timestamp)
|
||||
|
||||
def set_from_file(self, path = None):
|
||||
|
||||
@@ -404,7 +404,7 @@ class Interface(object):
|
||||
pipe -- stdout pipe to the dhcpcd process.
|
||||
|
||||
Returns:
|
||||
'success' if succesful', an error code string otherwise.
|
||||
'success' if succesful, an error code string otherwise.
|
||||
|
||||
"""
|
||||
pump_complete = False
|
||||
@@ -452,7 +452,7 @@ class Interface(object):
|
||||
success -- boolean specifying if DHCP was succesful.
|
||||
|
||||
Returns:
|
||||
'success' if success = True, 'dhcp_failed' otherwise.
|
||||
'success' if success == True, 'dhcp_failed' otherwise.
|
||||
|
||||
"""
|
||||
if success:
|
||||
|
||||
Reference in New Issue
Block a user