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:
@@ -542,6 +542,7 @@ class appGUI():
|
||||
('H' ,'Help' ,None),
|
||||
('right','Config',None),
|
||||
#(' ',' ',None),
|
||||
('K' , 'RfKill',None),
|
||||
('C' ,'Connect',None),
|
||||
('D' ,'Disconn',None),
|
||||
('R' ,'Refresh',None),
|
||||
@@ -803,6 +804,9 @@ class appGUI():
|
||||
if "f5" in keys or 'R' in keys:
|
||||
self.lock_screen()
|
||||
self.doScan()
|
||||
if 'k' in keys or 'K' in keys:
|
||||
wireless.SwitchRfKill()
|
||||
self.update_netlist()
|
||||
if "D" in keys:
|
||||
# Disconnect from all networks.
|
||||
daemon.Disconnect()
|
||||
|
||||
15
data/wicd.ui
15
data/wicd.ui
@@ -71,6 +71,21 @@
|
||||
<property name="expand">False</property>
|
||||
</packing>
|
||||
</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>
|
||||
<object class="GtkToolButton" id="disconnect_button">
|
||||
<property name="visible">True</property>
|
||||
|
||||
12
gtk/gui.py
12
gtk/gui.py
@@ -158,6 +158,7 @@ class appGui(object):
|
||||
|
||||
dic = { "refresh_clicked" : self.refresh_clicked,
|
||||
"quit_clicked" : self.exit,
|
||||
"rfkill_clicked" : self.switch_rfkill,
|
||||
"disconnect_clicked" : self.disconnect_all,
|
||||
"main_exit" : self.exit,
|
||||
"cancel_clicked" : self.cancel_connect,
|
||||
@@ -175,6 +176,7 @@ class appGui(object):
|
||||
probar = self.wTree.get_object("progressbar")
|
||||
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.show_all()
|
||||
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. """
|
||||
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):
|
||||
""" Disconnects from any active network. """
|
||||
def handler(*args):
|
||||
|
||||
@@ -765,6 +765,37 @@ class Wireless(Controller):
|
||||
"""
|
||||
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):
|
||||
""" Disconnect the given iface.
|
||||
|
||||
|
||||
@@ -242,3 +242,5 @@ language['conn_info_wired_labels'] = _('''Wired
|
||||
IP:
|
||||
RX:
|
||||
TX:''')
|
||||
language['switch_on_wifi'] = _('''Switch On Wi-Fi''')
|
||||
language['switch_off_wifi'] = _('''Switch Off Wi-Fi''')
|
||||
|
||||
@@ -1025,6 +1025,16 @@ class WirelessDaemon(dbus.service.Object):
|
||||
status = self.wifi.GetKillSwitchStatus()
|
||||
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')
|
||||
def GetWirelessProperty(self, networkid, property):
|
||||
""" Retrieves wireless property from the network specified """
|
||||
|
||||
Reference in New Issue
Block a user