1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-21 21:38:06 +01:00

Implemented rfkill support (LP: #293727)

This commit is contained in:
David Paleino
2011-09-18 10:31:15 +02:00
parent bda00d0627
commit c86cffd67e
6 changed files with 76 additions and 2 deletions

View File

@@ -542,6 +542,7 @@ class appGUI():
('H' ,'Help' ,None), ('H' ,'Help' ,None),
('right','Config',None), ('right','Config',None),
#(' ',' ',None), #(' ',' ',None),
('K' , 'RfKill',None),
('C' ,'Connect',None), ('C' ,'Connect',None),
('D' ,'Disconn',None), ('D' ,'Disconn',None),
('R' ,'Refresh',None), ('R' ,'Refresh',None),
@@ -803,6 +804,9 @@ class appGUI():
if "f5" in keys or 'R' in keys: if "f5" in keys or 'R' in keys:
self.lock_screen() self.lock_screen()
self.doScan() self.doScan()
if 'k' in keys or 'K' in keys:
wireless.SwitchRfKill()
self.update_netlist()
if "D" in keys: if "D" in keys:
# Disconnect from all networks. # Disconnect from all networks.
daemon.Disconnect() daemon.Disconnect()

View File

@@ -71,6 +71,21 @@
<property name="expand">False</property> <property name="expand">False</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkToolButton" id="rfkill_button">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="is_important">True</property>
<property name="label" translatable="yes">_Switch Off Wi-Fi</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-media-stop</property>
<signal name="clicked" handler="rfkill_clicked"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child> <child>
<object class="GtkToolButton" id="disconnect_button"> <object class="GtkToolButton" id="disconnect_button">
<property name="visible">True</property> <property name="visible">True</property>

View File

@@ -158,6 +158,7 @@ class appGui(object):
dic = { "refresh_clicked" : self.refresh_clicked, dic = { "refresh_clicked" : self.refresh_clicked,
"quit_clicked" : self.exit, "quit_clicked" : self.exit,
"rfkill_clicked" : self.switch_rfkill,
"disconnect_clicked" : self.disconnect_all, "disconnect_clicked" : self.disconnect_all,
"main_exit" : self.exit, "main_exit" : self.exit,
"cancel_clicked" : self.cancel_connect, "cancel_clicked" : self.cancel_connect,
@@ -175,6 +176,7 @@ class appGui(object):
probar = self.wTree.get_object("progressbar") probar = self.wTree.get_object("progressbar")
probar.set_text(language['connecting']) probar.set_text(language['connecting'])
self.rfkill_button = self.wTree.get_object("rfkill_button")
self.all_network_list = self.wTree.get_object("network_list_vbox") self.all_network_list = self.wTree.get_object("network_list_vbox")
self.all_network_list.show_all() self.all_network_list.show_all()
self.wired_network_box = gtk.VBox(False, 0) self.wired_network_box = gtk.VBox(False, 0)
@@ -287,6 +289,16 @@ class appGui(object):
""" Toggles the encryption key entry box for the ad-hoc dialog. """ """ Toggles the encryption key entry box for the ad-hoc dialog. """
self.key_entry.set_sensitive(self.chkbox_use_encryption.get_active()) self.key_entry.set_sensitive(self.chkbox_use_encryption.get_active())
def switch_rfkill(self, widget=None):
""" Switches wifi card on/off. """
wireless.SwitchRfKill()
if wireless.GetRfKillEnabled():
self.rfkill_button.set_stock_id(gtk.STOCK_MEDIA_PLAY)
self.rfkill_button.set_label(language['switch_on_wifi'])
else:
self.rfkill_button.set_stock_id(gtk.STOCK_MEDIA_STOP)
self.rfkill_button.set_label(language['switch_off_wifi'])
def disconnect_all(self, widget=None): def disconnect_all(self, widget=None):
""" Disconnects from any active network. """ """ Disconnects from any active network. """
def handler(*args): def handler(*args):

View File

@@ -765,6 +765,37 @@ class Wireless(Controller):
""" """
return self.wiface.GetKillSwitchStatus() return self.wiface.GetKillSwitchStatus()
def SwitchRfKill(self):
""" Switches the rfkill on/off for wireless cards. """
types = ['wifi', 'wlan', 'wimax', 'wwan']
try:
if self.GetRfKillStatus():
action = 'unblock'
else:
action = 'block'
for t in types:
cmd = ['rfkill', action, t]
print "rfkill: %sing %s" % (action, t)
misc.Run(cmd)
return True
except Exception, e:
raise e
return False
def GetRfKillStatus(self):
""" Determines if rfkill switch is active or not.
Returns:
True if rfkill (soft-)switch is enabled.
"""
cmd = 'rfkill list'
rfkill_out = misc.Run(cmd)
soft_blocks = filter(lambda x: x.startswith('Soft'), rfkill_out.split('\t'))
for line in map(lambda x: x.strip(), soft_blocks):
if line.endswith('yes'):
return True
return False
def Disconnect(self): def Disconnect(self):
""" Disconnect the given iface. """ Disconnect the given iface.

View File

@@ -242,3 +242,5 @@ language['conn_info_wired_labels'] = _('''Wired
IP: IP:
RX: RX:
TX:''') TX:''')
language['switch_on_wifi'] = _('''Switch On Wi-Fi''')
language['switch_off_wifi'] = _('''Switch Off Wi-Fi''')

View File

@@ -1025,6 +1025,16 @@ class WirelessDaemon(dbus.service.Object):
status = self.wifi.GetKillSwitchStatus() status = self.wifi.GetKillSwitchStatus()
return status return status
@dbus.service.method('org.wicd.daemon.wireless')
def SwitchRfKill(self):
""" Switches the rfkill on/off for wireless cards. """
return self.wifi.SwitchRfKill()
@dbus.service.method('org.wicd.daemon.wireless')
def GetRfKillEnabled(self):
""" Returns true if rfkill switch is enabled. """
return self.wifi.GetRfKillStatus()
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetWirelessProperty(self, networkid, property): def GetWirelessProperty(self, networkid, property):
""" Retrieves wireless property from the network specified """ """ Retrieves wireless property from the network specified """