From ea4ab09984de3ad220dc1e80bc15b97a3ac475fb Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Mon, 19 Jan 2009 01:06:57 -0500 Subject: [PATCH 1/5] Fix ttls template Add a guiutils module for gui-related functions/classes that are used in multiple modules. Replace os.access with os.path.exists Make the static gateway entry optional. Don't auto-connect/reconnect when the gui is open. Fix bug that would keep the gui from working if the wired network entry was displayed. --- encryption/templates/ttls | 4 +- setup.py | 27 +++++----- wicd/configmanager.py | 3 +- wicd/dbusmanager.py | 1 + wicd/gui.py | 107 ++++++-------------------------------- wicd/misc.py | 4 +- wicd/monitor.py | 20 +++---- wicd/netentry.py | 79 +--------------------------- wicd/networking.py | 5 +- wicd/prefs.py | 8 --- wicd/wicd-client.py | 21 +++++--- wicd/wicd-daemon.py | 7 ++- wicd/wnettools.py | 9 ++-- 13 files changed, 78 insertions(+), 217 deletions(-) diff --git a/encryption/templates/ttls b/encryption/templates/ttls index 65db422..002a92b 100644 --- a/encryption/templates/ttls +++ b/encryption/templates/ttls @@ -1,7 +1,7 @@ name = TTLS with WEP author = Adam Blackburn version = 1 -require anonymous_identity *Anonymous_Identity identity *Identity password *Password auth *Authentication +require identity *Identity password *Password auth *Authentication ----- ctrl_interface=/var/run/wpa_supplicant network={ @@ -9,7 +9,7 @@ network={ scan_ssid=$_SCAN eap=TTLS key_mgmt=IEEE8021X - identity="$_USERNAME" + identity="$_IDENTITY" password="$_PASSWORD" phase2="auth=$_AUTH" } diff --git a/setup.py b/setup.py index 65ee989..3235238 100755 --- a/setup.py +++ b/setup.py @@ -123,32 +123,32 @@ class configure(Command): self.distro_detect_failed = False self.initfile = 'init/default/wicd' - if os.access('/etc/redhat-release', os.F_OK): + if os.path.exists('/etc/redhat-release'): self.init = '/etc/rc.d/init.d/' self.initfile = 'init/redhat/wicd' - elif os.access('/etc/SuSE-release', os.F_OK): + elif os.path.exists('/etc/SuSE-release'): self.init = '/etc/init.d/' self.initfile = 'init/suse/wicd' - elif os.access('/etc/fedora-release', os.F_OK): + elif os.path.exists('/etc/fedora-release'): self.init = '/etc/rc.d/init.d/' self.initfile = 'init/redhat/wicd' - elif os.access('/etc/gentoo-release', os.F_OK): + elif os.path.exists('/etc/gentoo-release'): self.init = '/etc/init.d/' self.initfile = 'init/gentoo/wicd' - elif os.access('/etc/debian_version', os.F_OK): + elif os.path.exists('/etc/debian_version'): self.init = '/etc/init.d/' self.initfile = 'init/debian/wicd' - elif os.access('/etc/arch-release', os.F_OK): + elif os.path.exists('/etc/arch-release'): self.init = '/etc/rc.d/' self.initfile = 'init/arch/wicd' - elif os.access('/etc/slackware-version', os.F_OK) or \ - os.access('/etc/slamd64-version', os.F_OK): + elif os.path.exists('/etc/slackware-version') or \ + os.path.exists('/etc/slamd64-version'): self.init = '/etc/rc.d/' self.initfile = 'init/slackware/rc.wicd' self.docdir = '/usr/doc/wicd-%s' % VERSION_NUM self.mandir = '/usr/man/' self.no_install_acpi = True - elif os.access('/etc/pld-release', os.F_OK): + elif os.path.exists('/etc/pld-release'): self.init = '/etc/rc.d/init.d/' self.initfile = 'init/pld/wicd' else: @@ -174,7 +174,7 @@ class configure(Command): if len(pmutils_candidate) == 0 or returncode != 0 or not os.path.isabs(pmutils_candidate): raise ValueError else: - self.pmutils = pmutils_candidate + self.pmutils = pmutils_candidate except (OSError, ValueError): pass # use our default @@ -185,7 +185,7 @@ class configure(Command): if len(kdedir_candidate) == 0 or returncode != 0 or not os.path.isabs(kdedir_candidate): raise ValueError else: - self.kdedir = kdedir_candidate + '/share/autostart' + self.kdedir = kdedir_candidate + '/share/autostart' except (OSError, ValueError): # If kde-config isn't present or returns an error, then we can # assume that kde isn't installed on the user's system @@ -454,7 +454,10 @@ connect at startup to any preferred network within range. url="http://wicd.net", license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html", ## scripts=['configscript.py', 'autoconnect.py', 'gui.py', 'wicd.py', 'daemon.py', 'suspend.py', 'monitor.py'], - py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', 'wicd.configmanager'], ext_modules=[iwscan_ext, wpactrl_ext], + py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', + 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', + 'wicd.configmanager', 'wicd.guiutil'], + ext_modules=[iwscan_ext, wpactrl_ext], data_files=data ) ##print "Running post-install configuration..." diff --git a/wicd/configmanager.py b/wicd/configmanager.py index c95b911..b636678 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -87,8 +87,7 @@ class ConfigManager(RawConfigParser): str(ret)]) else: if default != "__None__": - if self.debug: - print 'did not find %s in configuration, setting default %s' % (option, str(default)) + print 'did not find %s in configuration, setting default %s' % (option, str(default)) self.set(section, option, str(default), save=True) ret = default else: diff --git a/wicd/dbusmanager.py b/wicd/dbusmanager.py index 0063f64..0c25b6c 100644 --- a/wicd/dbusmanager.py +++ b/wicd/dbusmanager.py @@ -24,6 +24,7 @@ A module for managing wicd's dbus interfaces. # import dbus +from dbus import DBusException if getattr(dbus, "version", (0, 0, 0)) < (0, 80, 0): import dbus.glib else: diff --git a/wicd/gui.py b/wicd/gui.py index b1a3065..b630d15 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -40,6 +40,7 @@ from wicd import dbusmanager from wicd.misc import noneToString from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry from wicd.prefs import PreferencesDialog +from wicd.guiutil import error, GreyLabel, LabelEntry, SmallLabel if __name__ == '__main__': wpath.chdir(__file__) @@ -87,92 +88,6 @@ def handle_no_dbus(from_tray=False): error(None, language['lost_dbus'], block=False) return False -def error(parent, message, block=True): - """ Shows an error dialog """ - def delete_event(dialog, id): - dialog.destroy() - dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, - gtk.BUTTONS_OK) - dialog.set_markup(message) - if not block: - dialog.present() - dialog.connect("response", delete_event) - else: - dialog.run() - dialog.destroy() - -def alert(parent, message): - """ Shows an warning dialog """ - dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, - gtk.BUTTONS_OK) - dialog.set_markup(message) - dialog.present() - dialog.connect("response", lambda *args: dialog.destroy()) - -def dummy(x=None):pass - -######################################## -##### GTK EXTENSION CLASSES -######################################## - -class SmallLabel(gtk.Label): - def __init__(self, text=''): - gtk.Label.__init__(self, text) - self.set_size_request(50, -1) - -class LabelEntry(gtk.HBox): - """ A label on the left with a textbox on the right. """ - def __init__(self,text): - gtk.HBox.__init__(self) - self.entry = gtk.Entry() - self.entry.set_size_request(200, -1) - self.label = SmallLabel() - self.label.set_text(text) - self.label.set_size_request(170, -1) - self.pack_start(self.label, fill=False, expand=False) - self.pack_start(self.entry, fill=False, expand=False) - self.label.show() - self.entry.show() - self.entry.connect('focus-out-event', self.hide_characters) - self.entry.connect('focus-in-event', self.show_characters) - self.auto_hide_text = False - self.show() - - def set_text(self, text): - # For compatibility... - self.entry.set_text(text) - - def get_text(self): - return self.entry.get_text() - - def set_auto_hidden(self, value): - self.entry.set_visibility(False) - self.auto_hide_text = value - - def show_characters(self, widget=None, event=None): - # When the box has focus, show the characters - if self.auto_hide_text and widget: - self.entry.set_visibility(True) - - def set_sensitive(self, value): - self.entry.set_sensitive(value) - self.label.set_sensitive(value) - - def hide_characters(self, widget=None, event=None): - # When the box looses focus, hide them - if self.auto_hide_text and widget: - self.entry.set_visibility(False) - - -class GreyLabel(gtk.Label): - """ Creates a grey gtk.Label. """ - def __init__(self): - gtk.Label.__init__(self) - - def set_label(self, text): - self.set_markup("" + text + "") - self.set_alignment(0, 0) - class WiredProfileChooser: """ Class for displaying the wired profile chooser. """ @@ -291,6 +206,7 @@ class appGui(object): self.wait_for_events(0.2) self.window.connect('delete_event', self.exit) self.window.connect('key-release-event', self.key_event) + daemon.SetGUIOpen(True) bus.add_signal_receiver(self.dbus_scan_finished, 'SendEndScanSignal', 'org.wicd.daemon.wireless') bus.add_signal_receiver(self.dbus_scan_started, 'SendStartScanSignal', @@ -649,21 +565,30 @@ class appGui(object): # First make sure all the Addresses entered are valid. if entry.chkbox_static_ip.get_active(): - entlist = [ent for ent in [entry.txt_ip, entry.txt_netmask, - entry.txt_gateway]] + req_entlist = [entry.txt_ip, enty.txt_netmask] + opt_entlist = [entry.txt_gateway] if entry.chkbox_static_dns.get_active() and \ not entry.chkbox_global_dns.get_active(): - entlist.append(entry.txt_dns_1) + req_entlist.append(entry.txt_dns_1) # Only append additional dns entries if they're entered. for ent in [entry.txt_dns_2, entry.txt_dns_3]: if ent.get_text() != "": - entlist.append(ent) - for lblent in entlist: + opt_entlist.append(ent) + + # Required entries. + for lblent in req_entlist: if not misc.IsValidIP(lblent.get_text()): error(self.window, language['invalid_address']. replace('$A', lblent.label.get_label())) return False + + # Optional entries, only check for validity if they're entered. + for lblent in opt_entlist: + if lblent.get_text() and not misc.IsValidIP(lblent.get_text()): + error(self.window, language['invalid_address']. + replace('$A', lblent.label.get_label())) + return False # Now save the settings. if nettype == "wireless": diff --git a/wicd/misc.py b/wicd/misc.py index 5f7f928..30b473a 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -399,7 +399,7 @@ def choose_sudo_prog(): for p in env_path: paths.extend([p + '/gksudo', p + "/gksu", p + '/ktsuss']) for path in paths: - if os.access(path, os.F_OK): + if os.path.exists(path): return path return None @@ -414,7 +414,7 @@ def find_path(cmd): """ 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): + if os.path.exists(os.path.join(path, cmd)): return os.path.join(path, cmd) return None diff --git a/wicd/monitor.py b/wicd/monitor.py index 0256932..47fe3b5 100755 --- a/wicd/monitor.py +++ b/wicd/monitor.py @@ -268,16 +268,16 @@ class ConnectionStatus(object): error_handler=err_handle) self.reconnecting = False - def rescan_networks(self): - """ Calls a wireless scan. """ - try: - if daemon.GetSuspend() or daemon.CheckIfConnecting(): - return True - wireless.Scan() - except dbus.exceptions.DBusException, e: - print 'dbus exception while attempting rescan: %s' % str(e) - finally: - return True + #def rescan_networks(self): + # """ Calls a wireless scan. """ + # try: + # if daemon.GetSuspend() or daemon.CheckIfConnecting(): + # return True + # wireless.Scan() + # except dbus.exceptions.DBusException, e: + # print 'dbus exception while attempting rescan: %s' % str(e) + # finally: + # return True def reply_handle(): """ Just a dummy function needed for asynchronous dbus calls. """ diff --git a/wicd/netentry.py b/wicd/netentry.py index e000e93..4474b99 100644 --- a/wicd/netentry.py +++ b/wicd/netentry.py @@ -19,8 +19,9 @@ import gtk import os import misc -from misc import noneToString, stringToNone, noneToBlankString, to_bool import wpath +from misc import noneToString, stringToNone, noneToBlankString, to_bool +from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel language = misc.get_language_list_gui() @@ -28,78 +29,6 @@ language = misc.get_language_list_gui() daemon = None wired = None wireless = None - -def error(parent, message): - """ Shows an error dialog """ - dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, - gtk.BUTTONS_OK) - dialog.set_markup(message) - dialog.run() - dialog.destroy() - -class SmallLabel(gtk.Label): - def __init__(self, text=''): - gtk.Label.__init__(self, text) - self.set_size_request(50, -1) - -class LeftAlignedLabel(gtk.Label): - def __init__(self, label=None): - gtk.Label.__init__(self, label) - self.set_alignment(0.0, 0.5) - -class LabelEntry(gtk.HBox): - """ A label on the left with a textbox on the right. """ - def __init__(self, text): - gtk.HBox.__init__(self) - self.entry = gtk.Entry() - self.entry.set_size_request(200, -1) - self.label = SmallLabel() - self.label.set_text(text) - self.label.set_size_request(170, -1) - self.pack_start(self.label, fill=False, expand=False) - self.pack_start(self.entry, fill=False, expand=False) - self.label.show() - self.entry.show() - self.entry.connect('focus-out-event', self.hide_characters) - self.entry.connect('focus-in-event', self.show_characters) - self.auto_hide_text = False - self.show() - - def set_text(self, text): - # For compatibility... - self.entry.set_text(text) - - def get_text(self): - return self.entry.get_text() - - def set_auto_hidden(self, value): - self.entry.set_visibility(False) - self.auto_hide_text = value - - def show_characters(self, widget=None, event=None): - # When the box has focus, show the characters - if self.auto_hide_text and widget: - self.entry.set_visibility(True) - - def set_sensitive(self, value): - self.entry.set_sensitive(value) - self.label.set_sensitive(value) - - def hide_characters(self, widget=None, event=None): - # When the box looses focus, hide them - if self.auto_hide_text and widget: - self.entry.set_visibility(False) - - -class GreyLabel(gtk.Label): - """ Creates a grey gtk.Label. """ - def __init__(self): - gtk.Label.__init__(self) - - def set_label(self, text): - self.set_markup("" + text + "") - self.set_alignment(0, 0) - class AdvancedSettingsDialog(gtk.Dialog): def __init__(self): @@ -651,7 +580,6 @@ class WiredNetworkEntry(NetworkEntry): self.chkbox_default_profile.connect("toggled", self.toggle_default_profile) self.combo_profile_names.connect("changed", self.change_profile) - self.script_button.connect("button-press-event", self.edit_scripts) # Toggle the default profile checkbox to the correct state. if to_bool(wired.GetWiredProperty("default")): @@ -701,7 +629,6 @@ class WiredNetworkEntry(NetworkEntry): self.button_delete.set_sensitive(False) self.connect_button.set_sensitive(False) self.advanced_button.set_sensitive(False) - self.script_button.set_sensitive(False) def update_connect_button(self, state, apbssid=None): """ Update the connection/disconnect button for this entry. """ @@ -730,7 +657,6 @@ class WiredNetworkEntry(NetworkEntry): self.button_delete.set_sensitive(True) self.connect_button.set_sensitive(True) self.advanced_button.set_sensitive(True) - self.script_button.set_sensitive(True) def remove_profile(self, widget): """ Remove a profile from the profile list. """ @@ -748,7 +674,6 @@ class WiredNetworkEntry(NetworkEntry): if self.is_full_gui: self.button_delete.set_sensitive(False) self.advanced_button.set_sensitive(False) - self.script_button.set_sensitive(False) self.connect_button.set_sensitive(False) else: self.profile_help.hide() diff --git a/wicd/networking.py b/wicd/networking.py index a0a8d58..dcecce8 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -393,8 +393,9 @@ class ConnectThread(threading.Thread): self.SetStatus('setting_static_ip') print 'Setting static IP : ' + self.network['ip'] iface.SetAddress(self.network['ip'], self.network['netmask']) - print 'Setting default gateway : ' + self.network['gateway'] - iface.SetDefaultRoute(self.network['gateway']) + if self.network.get('gateway'): + print 'Setting default gateway : ' + self.network['gateway'] + iface.SetDefaultRoute(self.network['gateway']) else: # Run dhcp... self.SetStatus('running_dhcp') diff --git a/wicd/prefs.py b/wicd/prefs.py index 29f5c12..b5779fb 100644 --- a/wicd/prefs.py +++ b/wicd/prefs.py @@ -40,14 +40,6 @@ wired = None language = misc.get_language_list_gui() -def alert(parent, message): - """ Shows an alert dialog """ - dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, - gtk.BUTTONS_OK) - dialog.set_markup(message) - dialog.run() - dialog.destroy() - class PreferencesDialog(object): """ Class for handling the wicd preferences dialog window. """ def __init__(self, wTree, dbus): diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index a74429a..b751965 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -43,13 +43,14 @@ import getopt import os import pango import time -from dbus import DBusException +import atexit # Wicd specific imports from wicd import wpath from wicd import misc from wicd import gui from wicd import dbusmanager +from wicd.guiutil import error ICON_AVAIL = True USE_EGG = False @@ -364,7 +365,7 @@ class TrayIcon(object): if DBUS_AVAIL: self.toggle_wicd_gui() else: - # gui.error(None, language["daemon_unavailable"]) + # error(None, language["daemon_unavailable"]) pass def on_quit(self, widget=None): @@ -652,8 +653,8 @@ def setup_dbus(force=True): misc.PromptToStartDaemon() try: dbusmanager.connect_to_dbus() - except DBusException: - gui.error(None, "Could not connect to wicd's D-Bus interface. " + + except dbusmanager.DBusException: + error(None, "Could not connect to wicd's D-Bus interface. " + "Check the wicd log for error messages.") return False else: @@ -669,12 +670,19 @@ def setup_dbus(force=True): return True +def on_exit(): + if DBUS_AVAIL: + try: + daemon.SetGUIOpen(False) + except dbusmanager.DBusException: + pass + 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, language['lost_dbus'], block=False) + error(None, language['lost_dbus'], block=False) return False def main(argv): @@ -709,7 +717,8 @@ def main(argv): print 'Loading...' setup_dbus() - + atexit.register(on_exit) + if not use_tray or not ICON_AVAIL: the_gui = gui.appGui(standalone=True) mainloop = gobject.MainLoop() diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index b12e0e4..8087c87 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -320,6 +320,10 @@ class WicdDaemon(dbus.service.Object): fails it tries a wireless connection. """ + # We don't want to rescan/connect if the gui is open. + if self.gui_open: + return + if fresh: self.wireless_bus.Scan() if self.wired_bus.CheckPluggedIn(): @@ -401,7 +405,8 @@ class WicdDaemon(dbus.service.Object): def ShouldAutoReconnect(self): """ Returns True if it's the right time to try autoreconnecting. """ if self.GetAutoReconnect() and not self.CheckIfConnecting() and \ - not self.GetForcedDisconnect() and not self.auto_connecting: + not self.GetForcedDisconnect() and not self.auto_connecting and \ + not self.gui_open: return True else: return False diff --git a/wicd/wnettools.py b/wicd/wnettools.py index 1df4398..0cea30e 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -33,6 +33,7 @@ class WirelessInterface() -- Control a wireless network interface. import os import re +import random from string import maketrans, translate, punctuation import wpath @@ -138,8 +139,8 @@ def NeedsExternalCalls(): def IsValidWpaSuppDriver(driver): """ Returns True if given string is a valid wpa_supplicant driver. """ - output = misc.Run(["wpa_supplicant", "-D%s" % driver, "-iwlan9", - "-c/etc/zzzzzzzz.confzzz"]) + output = misc.Run(["wpa_supplicant", "-D%s" % driver, "-iolan19", + "-c/etc/abcd%sdefzz.zconfz" % random.randint(1, 1000)]) if re.match("Unsupported driver", output): return False else: @@ -195,7 +196,7 @@ class BaseInterface(object): paths = ['/sbin/', '/usr/sbin/', '/bin/', '/usr/bin/', '/usr/local/sbin/', '/usr/local/bin/'] for path in paths: - if os.access("%s%s" % (path, client), os.F_OK): + if os.path.exists("%s%s" % (path, client)): return "%s%s" % (path, client) if self.verbose: print "WARNING: No path found for %s" % (client) @@ -416,7 +417,7 @@ class BaseInterface(object): pipe -- stdout pipe to the dhcpcd process. Returns: - 'success' if succesful', an error code string otherwise. + 'success' if succesful, an error code string otherwise. """ dhcpcd_complete = False From 87539f75e7fa8cc050fd739b9afa712591d9a999 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Mon, 19 Jan 2009 23:37:35 -0500 Subject: [PATCH 2/5] Fix bug that was keeping DHCP release from working. --- wicd/wnettools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wicd/wnettools.py b/wicd/wnettools.py index 0cea30e..0a4235f 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -476,7 +476,8 @@ class BaseInterface(object): def ReleaseDHCP(self): """ Release the DHCP lease for this interface. """ if not self.iface: return False - cmd = self.DHCP_RELEASE + " " + self.iface + " 2>/dev/null" + cmd = self.DHCP_RELEASE + " " + self.iface + if self.verbose: print cmd misc.Run(cmd) def FlushRoutes(self): From 1269bcd0483a10c0dd5c31d428b445c950153a78 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Mon, 19 Jan 2009 23:45:05 -0500 Subject: [PATCH 3/5] Fix a few typos in the option gateway code. --- wicd/gui.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wicd/gui.py b/wicd/gui.py index b630d15..b0a2687 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -561,11 +561,12 @@ class appGui(object): def save_settings(self, nettype, networkid, networkentry): """ Verifies and saves the settings for the network entry. """ entry = networkentry.advanced_dialog - entlist = [] + opt_entlist = [] + req_entlist = [] # First make sure all the Addresses entered are valid. if entry.chkbox_static_ip.get_active(): - req_entlist = [entry.txt_ip, enty.txt_netmask] + req_entlist = [entry.txt_ip, entry.txt_netmask] opt_entlist = [entry.txt_gateway] if entry.chkbox_static_dns.get_active() and \ From f6d7579859833d69f682bb1a62c07a780fb4ebd5 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Tue, 20 Jan 2009 00:32:56 -0500 Subject: [PATCH 4/5] Add support for writing config data with whitespace kept intact. Propgate debug setting to the ConfigManager instances. Don't write essid key sections to the config file if we're not actually using them. --- wicd/configmanager.py | 14 ++++++++++++-- wicd/wicd-daemon.py | 33 ++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/wicd/configmanager.py b/wicd/configmanager.py index b636678..29d4320 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -31,10 +31,11 @@ from wicd.misc import stringToNone, Noneify, to_unicode class ConfigManager(RawConfigParser): """ A class that can be used to manage a given configuration file. """ - def __init__(self, path, debug=False): + def __init__(self, path, debug=False, mark_whitespace="`'`"): RawConfigParser.__init__(self) self.config_file = path self.debug = debug + self.mrk_ws = mark_whitespace self.read(path) def __repr__(self): @@ -60,6 +61,9 @@ class ConfigManager(RawConfigParser): self.add_section(section) if isinstance(value, basestring): value = to_unicode(value) + if value.startswith(' ') or value.endswith(' '): + value = "%(ws)s%(value)s%(ws)s" % {"value" : value, + "ws" : self.mrk_ws} RawConfigParser.set(self, section, str(option), value) if save: self.write() @@ -77,10 +81,16 @@ class ConfigManager(RawConfigParser): """ if not self.has_section(section): - self.add_section(section) + if default != "__None__": + self.add_section(section) + else: + return None if self.has_option(section, option): ret = RawConfigParser.get(self, section, option) + if (isinstance(ret, basestring) and ret.startswith(self.mrk_ws) + and ret.endswith(self.mrk_ws)): + ret = ret[3:-3] if default: if self.debug: print ''.join(['found ', option, ' in configuration ', diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 8087c87..8fb98bb 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -91,7 +91,7 @@ class WicdDaemon(dbus.service.Object): self.vpn_session = None self.gui_open = False self.suspended = False - self.debug_mode = False + self._debug_mode = False self.connection_state = misc.NOT_CONNECTED self.connection_info = [""] self.auto_connecting = False @@ -123,6 +123,13 @@ class WicdDaemon(dbus.service.Object): self.SetForcedDisconnect(True) print "--no-autoconnect detected, not autoconnecting..." + def get_debug_mode(self): + return self._debug_mode + def set_debug_mode(self, mode): + self._debug_mode = mode + self.config.debug = mode + debug_mode = property(get_debug_mode, set_debug_mode) + @dbus.service.method('org.wicd.daemon') def Hello(self): """ Returns the version number. @@ -874,10 +881,18 @@ class WirelessDaemon(dbus.service.Object): self.hidden_essid = None self.daemon = daemon self.wifi = wifi - self.debug_mode = debug + self._debug_mode = debug self.forced_disconnect = False self.config = ConfigManager(os.path.join(wpath.etc, - "wireless-settings.conf")) + "wireless-settings.conf"), + debug=debug) + + def get_debug_mode(self): + return self._debug_mode + def set_debug_mode(self, mode): + self._debug_mode = mode + self.config.debug = mode + debug_mode = property(get_debug_mode, set_debug_mode) @dbus.service.method('org.wicd.daemon.wireless') def SetHiddenNetworkESSID(self, essid): @@ -1223,11 +1238,19 @@ class WiredDaemon(dbus.service.Object): object_path="/org/wicd/daemon/wired") self.daemon = daemon self.wired = wired - self.debug_mode = debug + self._debug_mode = debug self.forced_disconnect = False self.WiredNetwork = {} self.config = ConfigManager(os.path.join(wpath.etc, - "wired-settings.conf")) + "wired-settings.conf"), + debug=debug) + + def get_debug_mode(self): + return self._debug_mode + def set_debug_mode(self, mode): + self._debug_mode = mode + self.config.debug = mode + debug_mode = property(get_debug_mode, set_debug_mode) @dbus.service.method('org.wicd.daemon.wired') def GetWiredIP(self, ifconfig=""): From 33a08b696eda759e2a2b66d60d250705997ac156 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Tue, 20 Jan 2009 23:55:43 -0500 Subject: [PATCH 5/5] Add missing guiutil module --- wicd/guiutil.py | 111 ++++++++++++++++++++++++++++++++++++++++++++ wicd/wicd-daemon.py | 19 ++++++++ 2 files changed, 130 insertions(+) create mode 100644 wicd/guiutil.py diff --git a/wicd/guiutil.py b/wicd/guiutil.py new file mode 100644 index 0000000..e84c753 --- /dev/null +++ b/wicd/guiutil.py @@ -0,0 +1,111 @@ +""" guiutil - A collection of commonly used gtk/gui functions and classes. """ +# +# Copyright (C) 2007 - 2008 Adam Blackburn +# Copyright (C) 2007 - 2008 Dan O'Reilly +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License Version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import gtk + +def error(parent, message, block=True): + """ Shows an error dialog. """ + def delete_event(dialog, id): + dialog.destroy() + dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, + gtk.BUTTONS_OK) + dialog.set_markup(message) + if not block: + dialog.present() + dialog.connect("response", delete_event) + else: + dialog.run() + dialog.destroy() + +def alert(parent, message, block=True): + """ Shows an warning dialog. """ + def delete_event(dialog, id): + dialog.destroy() + dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, + gtk.BUTTONS_OK) + dialog.set_markup(message) + if not block: + dialog.present() + dialog.connect("response", delete_event) + else: + dialog.run() + dialog.destroy() + + +class SmallLabel(gtk.Label): + def __init__(self, text=''): + gtk.Label.__init__(self, text) + self.set_size_request(50, -1) + +class LeftAlignedLabel(gtk.Label): + def __init__(self, label=None): + gtk.Label.__init__(self, label) + self.set_alignment(0.0, 0.5) + +class LabelEntry(gtk.HBox): + """ A label on the left with a textbox on the right. """ + def __init__(self,text): + gtk.HBox.__init__(self) + self.entry = gtk.Entry() + self.entry.set_size_request(200, -1) + self.label = SmallLabel() + self.label.set_text(text) + self.label.set_size_request(170, -1) + self.pack_start(self.label, fill=False, expand=False) + self.pack_start(self.entry, fill=False, expand=False) + self.label.show() + self.entry.show() + self.entry.connect('focus-out-event', self.hide_characters) + self.entry.connect('focus-in-event', self.show_characters) + self.auto_hide_text = False + self.show() + + def set_text(self, text): + # For compatibility... + self.entry.set_text(text) + + def get_text(self): + return self.entry.get_text() + + def set_auto_hidden(self, value): + self.entry.set_visibility(False) + self.auto_hide_text = value + + def show_characters(self, widget=None, event=None): + # When the box has focus, show the characters + if self.auto_hide_text and widget: + self.entry.set_visibility(True) + + def set_sensitive(self, value): + self.entry.set_sensitive(value) + self.label.set_sensitive(value) + + def hide_characters(self, widget=None, event=None): + # When the box looses focus, hide them + if self.auto_hide_text and widget: + self.entry.set_visibility(False) + + +class GreyLabel(gtk.Label): + """ Creates a grey gtk.Label. """ + def __init__(self): + gtk.Label.__init__(self) + + def set_label(self, text): + self.set_markup("" + text + "") + self.set_alignment(0, 0) diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 8fb98bb..06638c2 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -95,6 +95,7 @@ class WicdDaemon(dbus.service.Object): self.connection_state = misc.NOT_CONNECTED self.connection_info = [""] self.auto_connecting = False + self.prefer_wired = False self.dhcp_client = 0 self.link_detect_tool = 0 self.flush_tool = 0 @@ -506,7 +507,23 @@ class WicdDaemon(dbus.service.Object): def GetWiredAutoConnectMethod(self): """ Returns the wired autoconnect method. """ return int(self.wired_connect_mode) + + + @dbus.service.method('org.wicd.dameon') + def GetPreferWiredNetwork(self): + """ Returns True if wired network preference is set. + If this is True, wicd will switch from a wireless connection + to a wired one if an ethernet connection is available. + + """ + return self.prefer_wired + + @dbus.service.method('org.wicd.daemon') + def SetPreferWiredNetwork(self, value): + """ Sets the prefer_wired state. """ + self.prefer_wired = value + @dbus.service.method('org.wicd.daemon') def SetConnectionStatus(self, state, info): """ Sets the connection status. @@ -837,6 +854,8 @@ class WicdDaemon(dbus.service.Object): self.SetLinkDetectionTool(app_conf.get("Settings", "link_detect_tool", default=0)) self.SetFlushTool(app_conf.get("Settings", "flush_tool", default=0)) + self.SetPreferWiredNetwork(app_conf.get("Settings", "prefer_wired", + default=False)) app_conf.write() if os.path.isfile(wireless_conf):