1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-24 15:12:31 +01:00

Merged r213 of main experimental branch

This commit is contained in:
Robby Workman
2008-12-15 17:40:07 +00:00
6 changed files with 141 additions and 142 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Sun Oct 12 01:15:35 2008 -->
<!--Generated with glade3 3.4.5 on Mon Dec 15 00:29:12 2008 -->
<glade-interface>
<widget class="GtkWindow" id="window1">
<property name="width_request">450</property>
@@ -36,107 +36,33 @@
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<child>
<widget class="GtkMenu" id="menu1">
<widget class="GtkMenu" id="menu2">
<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="attach_widget">network_menu</property>
<child>
<widget class="GtkImageMenuItem" id="create_adhoc_network_button">
<widget class="GtkImageMenuItem" id="create_ad_hoc_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="label" translatable="yes">Create Ad-Hoc Network</property>
<property name="label" translatable="yes">Create an ad-hoc network</property>
<property name="use_underline">True</property>
<signal name="activate" handler="create_adhoc_network_button_button"/>
<signal name="activate" handler="create_adhoc_clicked"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image2">
<widget class="GtkImage" id="menu-item-image10">
<property name="visible">True</property>
<property name="stock">gtk-add</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="iface_menu_button">
<widget class="GtkImageMenuItem" id="find_hidden_button">
<property name="visible">True</property>
<property name="label" translatable="yes">Enable/Disable Interfaces</property>
<property name="tooltip" translatable="yes">Enter a hidden network to try to locate.</property>
<property name="label" translatable="yes">Find a hidden network</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="iface_menu">
<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>
<child>
<widget class="GtkImageMenuItem" id="iface_menu_enable_wired">
<property name="visible">True</property>
<property name="label" translatable="yes">Enable Wired Interface</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_iface_menu_enable_wired"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image5">
<property name="visible">True</property>
<property name="stock">gtk-yes</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="iface_menu_enable_wireless">
<property name="visible">True</property>
<property name="label" translatable="yes">Enable Wireless Interface</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_iface_menu_enable_wireless"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image6">
<property name="visible">True</property>
<property name="stock">gtk-yes</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="iface_menu_disable_wired">
<property name="visible">True</property>
<property name="label" translatable="yes">Disable Wired Interface</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_iface_menu_disable_wired"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image7">
<property name="visible">True</property>
<property name="stock">gtk-stop</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="iface_menu_disable_wireless">
<property name="visible">True</property>
<property name="label" translatable="yes">Disable Wireless Interface</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_iface_menu_disable_wireless"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image8">
<property name="visible">True</property>
<property name="stock">gtk-stop</property>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="connect_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="label" translatable="yes">Hidden Network</property>
<property name="use_underline">True</property>
<signal name="activate" handler="connect_clicked"/>
<signal name="activate" handler="hidden_clicked"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image1">
<widget class="GtkImage" id="menu-item-image9">
<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="icon_name">network-wireless</property>
<property name="icon_name">wicd</property>
</widget>
</child>
</widget>
@@ -468,7 +394,6 @@
<property name="title" translatable="yes">Preferences</property>
<property name="default_width">125</property>
<property name="default_height">560</property>
<property name="icon">.</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox4">

View File

@@ -52,29 +52,54 @@ except:
proxy_obj = daemon = wireless = wired = bus = None
language = misc.get_language_list_gui()
DBUS_AVAIL = False
def setup_dbus():
global bus, daemon, wireless, wired
def setup_dbus(force=True):
global bus, daemon, wireless, wired, DBUS_AVAIL
try:
dbusmanager.connect_to_dbus()
except DBusException:
print "Can't connect to the daemon, trying to start it automatically..."
misc.PromptToStartDaemon()
try:
dbusmanager.connect_to_dbus()
except DBusException:
error(None, "Could not connect to wicd's D-Bus interface. " +
"Make sure the daemon is started.")
sys.exit(1)
if force:
print "Can't connect to the daemon, trying to start it automatically..."
misc.PromptToStartDaemon()
try:
dbusmanager.connect_to_dbus()
except DBusException:
error(None, "Could not connect to wicd's D-Bus interface. " +
"Check the wicd log for error messages.")
return False
else:
return False
bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces()
daemon = dbus_ifaces['daemon']
wireless = dbus_ifaces['wireless']
wired = dbus_ifaces['wired']
DBUS_AVAIL = True
return True
def handle_no_dbus(from_tray=False):
global DBUS_AVAIL
DBUS_AVAIL = False
if from_tray: return False
print "Wicd daemon is shutting down!"
error(None, "The wicd daemon has shut down, the UI will not function properly until it is restarted.")
_wait_for_dbus()
return False
@misc.threaded
def _wait_for_dbus():
global DBUS_AVAIL
while True:
time.sleep(10)
print "Trying to reconnect.."
if not setup_dbus(force=False):
print "Failed to reconnect to the daemon."
else:
print "Successfully reconnected to the daemon."
DBUS_AVAIL = True
return
def error(parent, message):
""" Shows an error dialog """
@@ -215,7 +240,7 @@ class appGui(object):
""" Initializes everything needed for the GUI. """
setup_dbus()
gladefile = wpath.share + "wicd.glade"
gladefile = os.path.join(wpath.share, "wicd.glade")
self.wTree = gtk.glade.XML(gladefile)
self.window = self.wTree.get_widget("window1")
size = daemon.ReadWindowSize("main")
@@ -232,10 +257,10 @@ class appGui(object):
"disconnect_clicked" : self.disconnect_all,
"main_exit" : self.exit,
"cancel_clicked" : self.cancel_connect,
"connect_clicked" : self.connect_hidden,
"hidden_clicked" : self.connect_hidden,
"preferences_clicked" : self.settings_dialog,
"about_clicked" : self.about_dialog,
"create_adhoc_network_button_button" : self.create_adhoc_network,
"create_adhoc_clicked" : self.create_adhoc_network,
}
self.wTree.signal_autoconnect(dic)
@@ -253,8 +278,8 @@ class appGui(object):
self.status_area.hide_all()
if os.path.exists(wpath.images + "wicd.png"):
self.window.set_icon_from_file(wpath.images + "wicd.png")
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
self.window.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
self.statusID = None
self.first_dialog_load = True
self.is_visible = True
@@ -277,7 +302,9 @@ class appGui(object):
'org.wicd.daemon.wireless')
bus.add_signal_receiver(self.update_connect_buttons, 'StatusChanged',
'org.wicd.daemon')
bus.add_signal_receiver(setup_dbus, "DaemonClosing", "org.wicd.daemon")
if standalone:
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
"org.wicd.daemon")
try:
gobject.timeout_add_seconds(1, self.update_statusbar)
except:
@@ -465,6 +492,7 @@ class appGui(object):
current network state is the same as the previous.
"""
if not DBUS_AVAIL: return
if not state:
state, x = daemon.GetConnectionStatus()
@@ -520,15 +548,18 @@ class appGui(object):
This method is called after a wireless scan is completed.
"""
if not DBUS_AVAIL: return
if not self.connecting:
gobject.idle_add(self.refresh_networks, None, False, None)
def dbus_scan_started(self):
""" Called when a wireless scan starts. """
if not DBUS_AVAIL: return
self.network_list.set_sensitive(False)
def refresh_clicked(self, widget=None):
""" Kick off an asynchronous wireless scan. """
if not DBUS_AVAIL: return
self.refreshing = True
wireless.Scan(reply_handler=None, error_handler=None)

View File

@@ -69,7 +69,7 @@ def Run(cmd, include_stderr=False, return_pipe=False):
one output string from the command.
"""
if type(cmd) is not list:
if not isinstance(cmd, list):
cmd = to_unicode(str(cmd))
cmd = cmd.split()
if include_stderr:
@@ -82,8 +82,12 @@ def Run(cmd, include_stderr=False, return_pipe=False):
tmpenv = os.environ.copy()
tmpenv["LC_ALL"] = "C"
tmpenv["LANG"] = "C"
f = Popen(cmd, shell=False, stdout=PIPE, stderr=err, close_fds=fds, cwd='/',
env=tmpenv)
try:
f = Popen(cmd, shell=False, stdout=PIPE, stderr=err, close_fds=fds,
cwd='/', env=tmpenv)
except OSError, e:
print "Running command %s failed: %s" % (str(cmd), str(e))
return ""
if return_pipe:
return f.stdout
@@ -383,7 +387,7 @@ def find_path(cmd):
the file can not be found.
"""
paths = os.getenv("PATH", default=["/usr/bin", "/usr/local/bin"]).split(':')
paths = os.getenv("PATH", default="/usr/bin:/usr/local/bin").split(':')
for path in paths:
if os.access(os.path.join(path, cmd), os.F_OK):
return os.path.join(path, cmd)
@@ -531,6 +535,7 @@ def get_language_list_tray():
language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface." + \
"This typically means there was a problem starting the daemon." + \
"Check the wicd log for more info")
language['no_daemon_tooltip'] = _("Wicd daemon unreachable")
return language
def noneToBlankString(text):

View File

@@ -29,6 +29,7 @@ import gobject
import pango
from wicd import misc
from wicd import wpath
from wicd.misc import checkboxTextboxToggle, noneToBlankString
daemon = None
@@ -78,6 +79,8 @@ class PreferencesDialog(object):
self.dialog = self.wTree.get_widget("pref_dialog")
self.dialog.set_title(language['preferences'])
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
self.dialog.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
size = daemon.ReadWindowSize("pref")
width = size[0]
height = size[1]

View File

@@ -59,7 +59,7 @@ if not hasattr(gtk, "StatusIcon"):
import egg.trayicon
USE_EGG = True
except ImportError:
print 'Unable to load tray icon: Missing egg.trayicon module.'
print 'Unable to load tray icon: Missing both egg.trayicon and gtk.StatusIcon modules.'
ICON_AVAIL = False
misc.RenameProcess("wicd-client")
@@ -125,7 +125,11 @@ class TrayIcon(object):
self.max_snd_gain = 10000
self.max_rcv_gain = 10000
self.animate = animate
self.update_tray_icon()
if DBUS_AVAIL:
self.update_tray_icon()
else:
handle_no_dbus()
self.set_not_connected_state()
def wired_profile_chooser(self):
""" Launch the wired profile chooser. """
@@ -135,7 +139,7 @@ class TrayIcon(object):
def set_wired_state(self, info):
""" Sets the icon info for a wired state. """
wired_ip = info[0]
self.tr.set_from_file(wpath.images + "wired.png")
self.tr.set_from_file(os.path.join(wpath.images, "wired.png"))
self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
wired_ip))
@@ -165,12 +169,14 @@ class TrayIcon(object):
cur_network = info[1]
self.tr.set_tooltip(language['connecting'] + " to " +
cur_network + "...")
self.tr.set_from_file(wpath.images + "no-signal.png")
self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png"))
def set_not_connected_state(self, info):
def set_not_connected_state(self, info=None):
""" Set the icon info for the not connected state. """
self.tr.set_from_file(wpath.images + "no-signal.png")
if wireless.GetKillSwitchEnabled():
if not DBUS_AVAIL:
status = language['no_daemon_tooltip']
elif wireless.GetKillSwitchEnabled():
status = (language['not_connected'] + " (" +
language['killswitch_enabled'] + ")")
else:
@@ -179,7 +185,7 @@ class TrayIcon(object):
def update_tray_icon(self, state=None, info=None):
""" Updates the tray icon and current connection status. """
if not self.use_tray: return False
if not self.use_tray or not DBUS_AVAIL: return False
if not state or not info:
[state, info] = daemon.GetConnectionStatus()
@@ -342,22 +348,15 @@ class TrayIcon(object):
def tray_scan_started(self):
""" Callback for when a wireless scan is started. """
if not DBUS_AVAIL: return
self._is_scanning = True
self.init_network_menu()
def tray_scan_ended(self):
""" Callback for when a wireless scan finishes. """
if not DBUS_AVAIL: return
self._is_scanning = False
self.populate_network_menu()
def dbus_lost(self):
""" Callback for when the daemon is going down. """
global DBUS_AVAIL
print "The daemon is going down!!"
DBUS_AVAIL = False
time.sleep(1)
while not setup_dbus():
time.sleep(20)
def on_activate(self, data=None):
""" Opens the wicd GUI. """
@@ -474,6 +473,9 @@ class TrayIcon(object):
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
submenu = net_menuitem.get_submenu()
self._clear_menu(submenu)
if not DBUS_AVAIL:
net_menuitem.show()
return
is_connecting = daemon.CheckIfConnecting()
num_networks = wireless.GetNumberOfNetworks()
@@ -638,26 +640,57 @@ Arguments:
\t-a\t--no-animate\tRun the tray without network traffic tray animations.
"""
def setup_dbus():
global daemon, wireless, wired, DBUS_AVAIL
def setup_dbus(force=True):
global bus, daemon, wireless, wired, DBUS_AVAIL
try:
dbusmanager.connect_to_dbus()
except DBusException:
print "Can't connect to the daemon, trying to start it automatically..."
misc.PromptToStartDaemon()
try:
dbusmanager.connect_to_dbus()
except DBusException:
gui.error(None, language['cannot_start_daemon'])
sys.exit(1)
if force:
print "Can't connect to the daemon, trying to start it automatically..."
misc.PromptToStartDaemon()
try:
dbusmanager.connect_to_dbus()
except DBusException:
gui.error(None, "Could not connect to wicd's D-Bus interface. " +
"Check the wicd log for error messages.")
return False
else:
return False
bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces()
daemon = dbus_ifaces['daemon']
wireless = dbus_ifaces['wireless']
wired = dbus_ifaces['wired']
DBUS_AVAIL = True
return True
def handle_no_dbus():
global DBUS_AVAIL
DBUS_AVAIL = False
gui.handle_no_dbus(from_tray=True)
print "Wicd daemon is shutting down!"
gui.error(None, "The wicd daemon has shut down, the UI will not function " +
"properly until it is restarted.")
_wait_for_dbus()
return False
@misc.threaded
def _wait_for_dbus():
global DBUS_AVAIL
while True:
time.sleep(10)
print "Trying to reconnect.."
if not setup_dbus(force=False):
print "Failed to reconnect to the daemon."
else:
print "Successfully reconnected to the daemon."
gui.setup_dbus(force=False)
DBUS_AVAIL = True
return
def main(argv):
""" The main frontend program.
@@ -702,7 +735,7 @@ def main(argv):
# Check to see if wired profile chooser was called before icon
# was launched (typically happens on startup or daemon restart).
if daemon.GetNeedWiredProfileChooser():
if DBUS_AVAIL and daemon.GetNeedWiredProfileChooser():
daemon.SetNeedWiredProfileChooser(False)
tray_icon.icon_info.wired_profile_chooser()
@@ -715,7 +748,7 @@ def main(argv):
'org.wicd.daemon.wireless')
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
'SendStartScanSignal', 'org.wicd.daemon.wireless')
bus.add_signal_receiver(tray_icon.tr.dbus_lost,
bus.add_signal_receiver(lambda: handle_no_dbus() or tray_icon.icon_info.set_not_connected_state(),
"DaemonClosing", 'org.wicd.daemon')
print 'Done.'
mainloop = gobject.MainLoop()

View File

@@ -1540,10 +1540,11 @@ def main(argv):
daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect)
gobject.threads_init()
if not no_poll:
(child_pid, x, x, x) = gobject.spawn_async(["/usr/bin/python", "-O",
wpath.lib + "monitor.py"],
flags=gobject.SPAWN_CHILD_INHERITS_STDIN)
signal.signal(signal.SIGTERM, sigterm_caught)
(child_pid, x, x, x) = gobject.spawn_async(
[misc.find_path("python"), "-O", os.path.join(wpath.lib, "monitor.py")],
flags=gobject.SPAWN_CHILD_INHERITS_STDIN
)
signal.signal(signal.SIGTERM, sigterm_caught)
# Enter the main loop
mainloop = gobject.MainLoop()
@@ -1557,8 +1558,9 @@ def main(argv):
def sigterm_caught(sig=None, frame=None):
""" Called when a SIGTERM is caught, kills monitor.py before exiting. """
global child_pid
print 'Daemon going down, killing wicd-monitor...'
os.kill(child_pid, signal.SIGTERM)
if child_pid:
print 'Daemon going down, killing wicd-monitor...'
os.kill(child_pid, signal.SIGTERM)
print 'Removing PID file...'
if os.path.exists(wpath.pidfile):
os.remove(wpath.pidfile)