mirror of
https://github.com/gryf/wicd.git
synced 2025-12-21 05:18:02 +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)
|
self.AutoConnect(True)
|
||||||
else:
|
else:
|
||||||
self.Scan()
|
self.Scan()
|
||||||
self.SetForcedDisconnect(True)
|
#self.SetForcedDisconnect(True)
|
||||||
print "--no-scan detected, not autoconnecting..."
|
print "--no-scan detected, not autoconnecting..."
|
||||||
|
|
||||||
########## DAEMON FUNCTIONS
|
########## DAEMON FUNCTIONS
|
||||||
|
|||||||
24
monitor.py
24
monitor.py
@@ -155,6 +155,7 @@ class ConnectionStatus():
|
|||||||
wired_ip = None
|
wired_ip = None
|
||||||
wifi_ip = None
|
wifi_ip = None
|
||||||
|
|
||||||
|
try:
|
||||||
if daemon.GetSuspend():
|
if daemon.GetSuspend():
|
||||||
print "Suspended."
|
print "Suspended."
|
||||||
state = misc.SUSPENDED
|
state = misc.SUSPENDED
|
||||||
@@ -189,6 +190,9 @@ class ConnectionStatus():
|
|||||||
from_wireless = False
|
from_wireless = False
|
||||||
self.auto_reconnect(from_wireless)
|
self.auto_reconnect(from_wireless)
|
||||||
self.update_state(state)
|
self.update_state(state)
|
||||||
|
except dbus.exceptions.DBusException, e:
|
||||||
|
print 'DBus Error: ' + str(e)
|
||||||
|
finally:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def update_state(self, state, wired_ip=None, wifi_ip=None):
|
def update_state(self, state, wired_ip=None, wifi_ip=None):
|
||||||
@@ -262,6 +266,17 @@ class ConnectionStatus():
|
|||||||
error_handler=err_handle)
|
error_handler=err_handle)
|
||||||
self.reconnecting = False
|
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():
|
def reply_handle():
|
||||||
""" Just a dummy function needed for asynchronous dbus calls. """
|
""" Just a dummy function needed for asynchronous dbus calls. """
|
||||||
pass
|
pass
|
||||||
@@ -272,9 +287,16 @@ def err_handle(error):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
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()
|
monitor = ConnectionStatus()
|
||||||
gobject.timeout_add(2000, monitor.update_connection_status)
|
gobject.timeout_add(2000, monitor.update_connection_status)
|
||||||
|
gobject.timeout_add(120000, monitor.rescan_networks)
|
||||||
|
|
||||||
mainloop = gobject.MainLoop()
|
mainloop = gobject.MainLoop()
|
||||||
mainloop.run()
|
mainloop.run()
|
||||||
|
|||||||
105
wicd.py
105
wicd.py
@@ -325,7 +325,8 @@ class TrayIcon:
|
|||||||
<ui>
|
<ui>
|
||||||
<menubar name="Menubar">
|
<menubar name="Menubar">
|
||||||
<menu action="Menu">
|
<menu action="Menu">
|
||||||
<menuitem action="Connect"/>
|
<menu action="Connect">
|
||||||
|
</menu>
|
||||||
<separator/>
|
<separator/>
|
||||||
<menuitem action="About"/>
|
<menuitem action="About"/>
|
||||||
<menuitem action="Quit"/>
|
<menuitem action="Quit"/>
|
||||||
@@ -335,8 +336,7 @@ class TrayIcon:
|
|||||||
"""
|
"""
|
||||||
actions = [
|
actions = [
|
||||||
('Menu', None, 'Menu'),
|
('Menu', None, 'Menu'),
|
||||||
('Connect', gtk.STOCK_CONNECT, '_Connect...', None,
|
('Connect', gtk.STOCK_CONNECT, "Connect"),
|
||||||
'Connect to network', self.on_preferences),
|
|
||||||
('About', gtk.STOCK_ABOUT, '_About...', None,
|
('About', gtk.STOCK_ABOUT, '_About...', None,
|
||||||
'About wicd-tray-icon', self.on_about),
|
'About wicd-tray-icon', self.on_about),
|
||||||
('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon',
|
('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon',
|
||||||
@@ -361,20 +361,103 @@ class TrayIcon:
|
|||||||
""" Closes the tray icon. """
|
""" Closes the tray icon. """
|
||||||
sys.exit(0)
|
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. """
|
""" Opens the About Dialog. """
|
||||||
dialog = gtk.AboutDialog()
|
dialog = gtk.AboutDialog()
|
||||||
dialog.set_name('wicd tray icon')
|
dialog.set_name('Wicd Tray Icon')
|
||||||
dialog.set_version('1.0')
|
dialog.set_version('2.0')
|
||||||
dialog.set_comments('An icon that shows your network connectivity')
|
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.run()
|
||||||
dialog.destroy()
|
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):
|
def toggle_wicd_gui(self):
|
||||||
""" Toggles the wicd GUI. """
|
""" Toggles the wicd GUI. """
|
||||||
if not self.gui_win:
|
if not self.gui_win:
|
||||||
@@ -419,6 +502,7 @@ class TrayIcon:
|
|||||||
if event.button == 1:
|
if event.button == 1:
|
||||||
self.toggle_wicd_gui()
|
self.toggle_wicd_gui()
|
||||||
elif event.button == 3:
|
elif event.button == 3:
|
||||||
|
self.populate_network_menu()
|
||||||
self.menu.popup(None, None, None, event.button, event.time)
|
self.menu.popup(None, None, None, event.button, event.time)
|
||||||
|
|
||||||
def set_from_file(self, val=None):
|
def set_from_file(self, val=None):
|
||||||
@@ -461,6 +545,7 @@ class TrayIcon:
|
|||||||
|
|
||||||
def on_popup_menu(self, status, button, timestamp):
|
def on_popup_menu(self, status, button, timestamp):
|
||||||
""" Opens the right click menu for the tray icon. """
|
""" Opens the right click menu for the tray icon. """
|
||||||
|
self.populate_network_menu()
|
||||||
self.menu.popup(None, None, None, button, timestamp)
|
self.menu.popup(None, None, None, button, timestamp)
|
||||||
|
|
||||||
def set_from_file(self, path = None):
|
def set_from_file(self, path = None):
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ class Interface(object):
|
|||||||
pipe -- stdout pipe to the dhcpcd process.
|
pipe -- stdout pipe to the dhcpcd process.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
'success' if succesful', an error code string otherwise.
|
'success' if succesful, an error code string otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pump_complete = False
|
pump_complete = False
|
||||||
@@ -452,7 +452,7 @@ class Interface(object):
|
|||||||
success -- boolean specifying if DHCP was succesful.
|
success -- boolean specifying if DHCP was succesful.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
'success' if success = True, 'dhcp_failed' otherwise.
|
'success' if success == True, 'dhcp_failed' otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if success:
|
if success:
|
||||||
|
|||||||
Reference in New Issue
Block a user