mirror of
https://github.com/gryf/wicd.git
synced 2025-12-25 16:02:28 +01:00
Merged mainline.
This commit is contained in:
29
wicd/gui.py
29
wicd/gui.py
@@ -223,10 +223,7 @@ class appGui(object):
|
||||
|
||||
self._do_statusbar_update(*daemon.GetConnectionStatus())
|
||||
self.wait_for_events(0.1)
|
||||
if hasattr(gobject, "timeout_add_seconds"):
|
||||
self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar)
|
||||
else:
|
||||
self.update_cb = gobject.timeout_add(2000, self.update_statusbar)
|
||||
self.update_cb = misc.timeout_add(2, self.update_statusbar)
|
||||
self.refresh_clicked()
|
||||
|
||||
def handle_connection_results(self, results):
|
||||
@@ -393,26 +390,32 @@ class appGui(object):
|
||||
return True
|
||||
|
||||
def set_not_connected_state(self, info):
|
||||
self.connecting = False
|
||||
self._set_not_connecting_state()
|
||||
if self.connecting:
|
||||
self._set_not_connecting_state()
|
||||
self.set_status(language['not_connected'])
|
||||
return True
|
||||
|
||||
def _set_not_connecting_state(self):
|
||||
self.connecting = False
|
||||
if self.connecting:
|
||||
gobject.source_remove(self.update_cb)
|
||||
self.update_cb = misc.timeout_add(2, self.update_statusbar)
|
||||
self.connecting = False
|
||||
if self.pulse_active:
|
||||
self.pulse_active = False
|
||||
gobject.idle_add(self.network_list.set_sensitive, True)
|
||||
gobject.idle_add(self.status_area.hide_all)
|
||||
|
||||
if self.statusID:
|
||||
gobject.idle_add(self.status_bar.remove, 1, self.statusID)
|
||||
|
||||
def set_connecting_state(self, info):
|
||||
self.connecting = True
|
||||
if not self.connecting:
|
||||
gobject.source_remove(self.update_cb)
|
||||
self.update_cb = misc.timeout_add(500, self.update_statusbar,
|
||||
milli=True)
|
||||
self.connecting = True
|
||||
if not self.pulse_active:
|
||||
self.pulse_active = True
|
||||
gobject.timeout_add(100, self.pulse_progress_bar)
|
||||
misc.timeout_add(100, self.pulse_progress_bar, milli=True)
|
||||
gobject.idle_add(self.network_list.set_sensitive, False)
|
||||
gobject.idle_add(self.status_area.show_all)
|
||||
if self.statusID:
|
||||
@@ -713,12 +716,10 @@ class appGui(object):
|
||||
daemon.SetGUIOpen(True)
|
||||
self.wait_for_events(0.1)
|
||||
gobject.idle_add(self.refresh_clicked)
|
||||
self._do_statusbar_update(*daemon.GetConnectionStatus())
|
||||
bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged',
|
||||
'org.wicd.daemon')
|
||||
if hasattr(gobject, "timeout_add_seconds"):
|
||||
self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar)
|
||||
else:
|
||||
self.update_cb = gobject.timeout_add(2000, self.update_statusbar)
|
||||
self.update_cb = misc.timeout_add(2, self.update_statusbar)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
16
wicd/misc.py
16
wicd/misc.py
@@ -22,6 +22,7 @@ import locale
|
||||
import gettext
|
||||
import sys
|
||||
import re
|
||||
import gobject
|
||||
from threading import Thread
|
||||
from subprocess import Popen, STDOUT, PIPE, call
|
||||
from commands import getoutput
|
||||
@@ -68,7 +69,7 @@ class WicdError(Exception):
|
||||
|
||||
|
||||
__LANG = None
|
||||
def Run(cmd, include_stderr=False, return_pipe=False):
|
||||
def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False):
|
||||
""" Run a command.
|
||||
|
||||
Runs the given command, returning either the output
|
||||
@@ -111,6 +112,8 @@ def Run(cmd, include_stderr=False, return_pipe=False):
|
||||
return ""
|
||||
|
||||
|
||||
if return_obj:
|
||||
return f
|
||||
if return_pipe:
|
||||
return f.stdout
|
||||
else:
|
||||
@@ -421,7 +424,6 @@ def choose_sudo_prog(prog_num=0):
|
||||
|
||||
for path in paths:
|
||||
if os.path.exists(path):
|
||||
print "returning %s" % path
|
||||
return path
|
||||
|
||||
return None
|
||||
@@ -461,6 +463,7 @@ def get_language_list_gui():
|
||||
language['use_static_dns'] = _('Use Static DNS')
|
||||
language['use_encryption'] = _('Use Encryption')
|
||||
language['advanced_settings'] = _('Advanced Settings')
|
||||
language['properties'] = _('Properties')
|
||||
language['wired_network'] = _('Wired Network')
|
||||
language['wired_network_instructions'] = _('To connect to a wired network,'
|
||||
' you must create a network profile. To create a network profile, type a'
|
||||
@@ -656,3 +659,12 @@ def threaded(f):
|
||||
wrapper.__module__ = f.__module__
|
||||
|
||||
return wrapper
|
||||
|
||||
def timeout_add(time, func, milli=False):
|
||||
""" Convience function for running a function on a timer. """
|
||||
if hasattr(gobject, "timeout_add_seconds") and not milli:
|
||||
return gobject.timeout_add_seconds(time, func)
|
||||
else:
|
||||
if not milli: time = time * 1000
|
||||
return gobject.timeout_add(time, func)
|
||||
|
||||
@@ -54,6 +54,8 @@ def diewithdbus(func):
|
||||
self.__lost_dbus_count = 0
|
||||
return ret
|
||||
except dbusmanager.DBusException:
|
||||
if not hasattr(self, "__lost_dbus_count"):
|
||||
self.__lost_dbus_count = 0
|
||||
if self.__lost_dbus_count > 3:
|
||||
sys.exit(1)
|
||||
self.__lost_dbus_count += 1
|
||||
@@ -330,12 +332,8 @@ def err_handle(error):
|
||||
def add_poll_callback():
|
||||
global monitor, to_time, update_callback
|
||||
|
||||
if hasattr(gobject, "timeout_add_seconds"):
|
||||
update_callback = gobject.timeout_add_seconds(to_time,
|
||||
monitor.update_connection_status)
|
||||
else:
|
||||
update_callback = gobject.timeout_add(to_time * 1000,
|
||||
monitor.update_connection_status)
|
||||
update_callback = misc.timeout_add(to_time,
|
||||
monitor.update_connection_status)
|
||||
|
||||
def main():
|
||||
""" Starts the connection monitor.
|
||||
|
||||
@@ -45,7 +45,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
||||
the WiredSettingsDialog and WirelessSettingsDialog.
|
||||
|
||||
"""
|
||||
gtk.Dialog.__init__(self, title=language['advanced_settings'],
|
||||
gtk.Dialog.__init__(self, title=language['properties'],
|
||||
flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_REJECT,
|
||||
gtk.STOCK_OK,
|
||||
@@ -149,7 +149,6 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
||||
self.chkbox_static_dns.set_sensitive(False)
|
||||
else:
|
||||
self.chkbox_static_dns.set_sensitive(True)
|
||||
#self.chkbox_static_dns.set_active(False)
|
||||
|
||||
self.txt_ip.set_sensitive(self.chkbox_static_ip.get_active())
|
||||
self.txt_netmask.set_sensitive(self.chkbox_static_ip.get_active())
|
||||
@@ -513,18 +512,13 @@ class NetworkEntry(gtk.HBox):
|
||||
self.advanced_image.set_from_stock(gtk.STOCK_EDIT, 4)
|
||||
self.advanced_image.set_padding(4, 0)
|
||||
self.advanced_button.set_alignment(.5, .5)
|
||||
self.advanced_button.set_label(language['advanced_settings'])
|
||||
self.advanced_button.set_label(language['properties'])
|
||||
self.advanced_button.set_image(self.advanced_image)
|
||||
|
||||
#self.buttons_hbox.pack_start(self.script_button, False, False)
|
||||
self.buttons_hbox.pack_start(self.connect_hbox, False, False)
|
||||
self.buttons_hbox.pack_start(self.advanced_button, False, False)
|
||||
|
||||
self.vbox_top = gtk.VBox(False, 0)
|
||||
#self.vbox_top.pack_end(self.buttons_hbox, False, False)
|
||||
#self.vbox_top.pack_end(self.connect_hbox, False, False)
|
||||
|
||||
|
||||
self.expander_vbox.pack_start(self.name_label)
|
||||
self.expander_vbox.pack_start(self.vbox_top)
|
||||
self.expander_vbox.pack_start(self.buttons_hbox)
|
||||
@@ -550,7 +544,6 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
|
||||
self.name_label.set_label(language['wired_network'])
|
||||
|
||||
#self.reset_static_checkboxes()
|
||||
self.is_full_gui = True
|
||||
|
||||
self.button_add = gtk.Button(stock=gtk.STOCK_ADD)
|
||||
@@ -759,7 +752,6 @@ class WirelessNetworkEntry(NetworkEntry):
|
||||
# Add the wireless network specific parts to the NetworkEntry
|
||||
# VBox objects.
|
||||
self.vbox_top.pack_start(self.chkbox_autoconnect, False, False)
|
||||
# self.vbox_top.pack_start(self.hbox_status, True, True)
|
||||
|
||||
if to_bool(self.format_entry(networkID, "automatic")):
|
||||
self.chkbox_autoconnect.set_active(True)
|
||||
@@ -813,11 +805,11 @@ class WirelessNetworkEntry(NetworkEntry):
|
||||
|
||||
def set_signal_strength(self, strength, dbm_strength):
|
||||
""" Set the signal strength displayed in the WirelessNetworkEntry. """
|
||||
if strength is not None:
|
||||
if strength:
|
||||
strength = int(strength)
|
||||
else:
|
||||
strength = -1
|
||||
if dbm_strength is not None:
|
||||
if dbm_strength:
|
||||
dbm_strength = int(dbm_strength)
|
||||
else:
|
||||
dbm_strength = -100
|
||||
|
||||
@@ -44,7 +44,9 @@ class WiredConnectThread() -- Connection thread for wired
|
||||
import re
|
||||
import time
|
||||
import threading
|
||||
import os
|
||||
import thread
|
||||
from signal import SIGTERM
|
||||
|
||||
# wicd imports
|
||||
import misc
|
||||
@@ -202,7 +204,8 @@ class Controller(object):
|
||||
iface = self.iface
|
||||
if self.disconnect_script != None:
|
||||
print 'Running disconnect script'
|
||||
misc.ExecuteScript(expand_script_macros(self.disconnect_script, 'disconnection', *args))
|
||||
misc.ExecuteScript(expand_script_macros(self.disconnect_script,
|
||||
'disconnection', *args))
|
||||
iface.ReleaseDHCP()
|
||||
iface.SetAddress('0.0.0.0')
|
||||
iface.FlushRoutes()
|
||||
@@ -213,6 +216,14 @@ class Controller(object):
|
||||
""" Release the DHCP lease for this interface. """
|
||||
return self.iface.ReleaseDHCP()
|
||||
|
||||
def KillDHCP(self):
|
||||
""" Kill the managed DHCP client if its in a connecting state. """
|
||||
if (self.connecting_thread.is_connecting and
|
||||
self.iface.dhcp_object):
|
||||
if self.iface.dhcp_object.poll() is None:
|
||||
os.kill(self.iface.dhcp_object.pid, SIGTERM)
|
||||
self.iface.dhcp_object = None
|
||||
|
||||
def IsUp(self):
|
||||
""" Calls the IsUp method for the wired interface.
|
||||
|
||||
@@ -254,7 +265,6 @@ class ConnectThread(threading.Thread):
|
||||
"""
|
||||
|
||||
is_connecting = None
|
||||
connecting_thread = None
|
||||
should_die = False
|
||||
lock = thread.allocate_lock()
|
||||
|
||||
@@ -405,7 +415,8 @@ class ConnectThread(threading.Thread):
|
||||
print "Running DHCP"
|
||||
dhcp_status = iface.StartDHCP()
|
||||
if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']:
|
||||
self.abort_connection(dhcp_status)
|
||||
if self.connect_result != "aborted":
|
||||
self.abort_connection(dhcp_status)
|
||||
return
|
||||
|
||||
@abortable
|
||||
|
||||
@@ -69,7 +69,7 @@ misc.RenameProcess("wicd-client")
|
||||
if __name__ == '__main__':
|
||||
wpath.chdir(__file__)
|
||||
|
||||
daemon = wireless = wired = None
|
||||
daemon = wireless = wired = lost_dbus_id = None
|
||||
DBUS_AVAIL = False
|
||||
|
||||
language = misc.get_language_list_tray()
|
||||
@@ -80,7 +80,7 @@ def catchdbus(func):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except DBusException, e:
|
||||
print "warning: ignoring exception %s" % egg
|
||||
print "warning: ignoring exception %s" % e
|
||||
return None
|
||||
wrapper.__name__ = func.__name__
|
||||
wrapper.__module__ = func.__module__
|
||||
@@ -664,7 +664,7 @@ Arguments:
|
||||
""" % wpath.version
|
||||
|
||||
def setup_dbus(force=True):
|
||||
global daemon, wireless, wired, DBUS_AVAIL
|
||||
global daemon, wireless, wired, DBUS_AVAIL, lost_dbus_id
|
||||
print "Connecting to daemon..."
|
||||
try:
|
||||
dbusmanager.connect_to_dbus()
|
||||
@@ -681,13 +681,15 @@ def setup_dbus(force=True):
|
||||
else:
|
||||
return False
|
||||
|
||||
if lost_dbus_id:
|
||||
gobject.source_remove(lost_dbus_id)
|
||||
lost_dbus_id = None
|
||||
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
||||
daemon = dbus_ifaces['daemon']
|
||||
wireless = dbus_ifaces['wireless']
|
||||
wired = dbus_ifaces['wired']
|
||||
DBUS_AVAIL = True
|
||||
print "Connected."
|
||||
|
||||
return True
|
||||
|
||||
def on_exit():
|
||||
@@ -698,11 +700,13 @@ def on_exit():
|
||||
pass
|
||||
|
||||
def handle_no_dbus():
|
||||
global DBUS_AVAIL
|
||||
""" Called when dbus announces its shutting down. """
|
||||
global DBUS_AVAIL, lost_dbus_id
|
||||
DBUS_AVAIL = False
|
||||
gui.handle_no_dbus(from_tray=True)
|
||||
print "Wicd daemon is shutting down!"
|
||||
error(None, language['lost_dbus'], block=False)
|
||||
lost_dbus_id = misc.timeout_add(5, lambda:error(None, language['lost_dbus'],
|
||||
block=False))
|
||||
return False
|
||||
|
||||
def main(argv):
|
||||
|
||||
@@ -380,6 +380,9 @@ class WicdDaemon(dbus.service.Object):
|
||||
if self.wifi.connecting_thread:
|
||||
self.wifi.connecting_thread.should_die = True
|
||||
self.wifi.ReleaseDHCP()
|
||||
# We have to actually kill dhcp if its still hanging
|
||||
# around. It could still be trying to get a lease.
|
||||
self.wifi.KillDHCP()
|
||||
self.wifi.StopWPA()
|
||||
self.wifi.connecting_thread.connect_result = 'aborted'
|
||||
if self.wired.connecting_thread:
|
||||
@@ -1012,10 +1015,7 @@ class WirelessDaemon(dbus.service.Object):
|
||||
value = self.LastScan[networkid].get(property)
|
||||
except IndexError:
|
||||
return ""
|
||||
try:
|
||||
value = misc.to_unicode(value)
|
||||
except:
|
||||
pass
|
||||
value = misc.to_unicode(value)
|
||||
return value
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
@@ -1027,14 +1027,13 @@ class WirelessDaemon(dbus.service.Object):
|
||||
+ " permitted."
|
||||
return False
|
||||
self.LastScan[networkid][property] = misc.Noneify(value)
|
||||
#end function SetProperty
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def DetectWirelessInterface(self):
|
||||
""" Returns an automatically detected wireless interface. """
|
||||
iface = self.wifi.DetectWirelessInterface()
|
||||
if iface:
|
||||
print 'automatically detected wireless interface ' + iface
|
||||
print 'Automatically detected wireless interface ' + iface
|
||||
else:
|
||||
print "Couldn't detect a wireless interface."
|
||||
return str(iface)
|
||||
|
||||
@@ -453,7 +453,8 @@ class BaseInterface(object):
|
||||
cmd = self._get_dhcp_command('connect')
|
||||
#cmd = self.DHCP_CMD + " " + self.iface
|
||||
if self.verbose: print cmd
|
||||
pipe = misc.Run(cmd, include_stderr=True, return_pipe=True)
|
||||
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True)
|
||||
pipe = self.dhcp_object.stdout
|
||||
|
||||
DHCP_CLIENT = self.DHCP_CLIENT
|
||||
if DHCP_CLIENT == misc.DHCLIENT:
|
||||
|
||||
Reference in New Issue
Block a user