From 6a58df67a0accd4baf454301599849a55aff3136 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Fri, 23 Feb 2007 20:39:52 +0100 Subject: [PATCH 01/29] Highlight buttons and change menu background to black. --- sugar/graphics/canvasicon.py | 24 ++++++++++++++++------ sugar/graphics/color.py | 2 +- sugar/graphics/iconbutton.py | 40 ++++++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 2f7e8925..82e9bd1e 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -173,8 +173,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): hippo.CanvasBox.__init__(self, **kwargs) - self.connect('motion-notify-event', self._motion_notify_event_cb) - self.connect('button-press-event', self._button_press_event_cb) + self.connect_after('button-press-event', self._button_press_event_cb) + self.connect_after('motion-notify-event', self._motion_notify_event_cb) def _clear_buffers(self): cur_buf_key = self._get_current_buffer_key() @@ -314,16 +314,16 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): def _button_press_event_cb(self, item, event): item.emit_activated() + return False def get_popup(self): if self._tooltip: tooltip_popup = Popup() canvas_text = hippo.CanvasText(text=self._tooltip) canvas_text.props.background_color = color.MENU_BACKGROUND.get_int() - canvas_text.props.border_color = color.MENU_BORDER.get_int() - canvas_text.props.border = units.points_to_pixels(1) canvas_text.props.color = color.LABEL_TEXT.get_int() canvas_text.props.font_desc = font.DEFAULT.get_pango_desc() + canvas_text.props.padding = units.points_to_pixels(5) tooltip_popup.append(canvas_text) return tooltip_popup @@ -364,7 +364,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): popup.popup(x, y) popup.connect('motion-notify-event', - self._popup_motion_notify_event_cb) + self.popup_motion_notify_event_cb) popup.connect('action-completed', self._popup_action_completed_cb) @@ -389,17 +389,29 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): def _motion_notify_event_cb(self, button, event): if event.detail == hippo.MOTION_DETAIL_ENTER: self._timeline.play(None, 'popup') + self.prelight(enter=True) elif event.detail == hippo.MOTION_DETAIL_LEAVE: if not self._hover_popup: self._timeline.play('before_popdown', 'popdown') + self.prelight(enter=False) + return False - def _popup_motion_notify_event_cb(self, popup, event): + def popup_motion_notify_event_cb(self, popup, event): if event.detail == hippo.MOTION_DETAIL_ENTER: self._hover_popup = True self._timeline.play('popup', 'popup') + self.prelight(enter=True) elif event.detail == hippo.MOTION_DETAIL_LEAVE: self._hover_popup = False self._timeline.play('popdown', 'popdown') + self.prelight(enter=False) + return False def _popup_action_completed_cb(self, popup): self.popdown() + + def prelight(self, enter): + """ + Override this method for adding prelighting behavior. + """ + pass diff --git a/sugar/graphics/color.py b/sugar/graphics/color.py index a52b1ff0..e07df4a7 100644 --- a/sugar/graphics/color.py +++ b/sugar/graphics/color.py @@ -12,7 +12,7 @@ _system_colors = { 'entry-border' : '#D1D1D2', 'label-text' : '#FFFFFF', 'desktop-background' : '#E2E2E3', - 'menu-background' : '#414141', + 'menu-background' : '#000000', 'menu-separator' : '#D1D1D2', 'menu-border' : '#D1D1D2', 'button-normal' : '#FFFFFF', diff --git a/sugar/graphics/iconbutton.py b/sugar/graphics/iconbutton.py index 568d6ef1..fc164519 100644 --- a/sugar/graphics/iconbutton.py +++ b/sugar/graphics/iconbutton.py @@ -21,8 +21,8 @@ import gobject import hippo from canvasicon import CanvasIcon -from xocolor import XoColor from sugar.graphics import units +from sugar.graphics import color from sugar import profile STANDARD_SIZE = 0 @@ -44,16 +44,20 @@ class IconButton(CanvasIcon): CanvasIcon.__init__(self, cache=True, **kwargs) - self._prelight_color = profile.get_color() - self._inactive_color = XoColor('#808080,#424242') - self._normal_color = XoColor('white') - - if not self.props.xo_color: - self.props.xo_color = self._normal_color + if not self.props.fill_color: + self.props.fill_color = color.BUTTON_BACKGROUND_NORMAL + if not self.props.stroke_color: + self.props.stroke_color = color.BUTTON_NORMAL + self.props.background_color = color.BUTTON_BACKGROUND_NORMAL.get_int() + self._normal_fill_color = self.props.fill_color + self._normal_stroke_color = self.props.stroke_color + self._normal_background_color = self.props.background_color + self._set_size(STANDARD_SIZE) - self.connect('button-press-event', self._button_press_event_cb) + self.connect('button-press-event', + self._icon_button_button_press_event_cb) def _set_size(self, size): if size == SMALL_SIZE: @@ -73,9 +77,13 @@ class IconButton(CanvasIcon): elif pspec.name == 'active': self._active = value if self._active: - self.props.xo_color = self._normal_color + self.props.fill_color = self._normal_fill_color + self.props.stroke_color = self._normal_stroke_color + self.props.background_color = self._normal_background_color else: - self.props.xo_color = self._inactive_color + self.props.fill_color = color.BUTTON_BACKGROUND_INACTIVE + self.props.stroke_color = color.BUTTON_INACTIVE + self.props.background_color = color.BUTTON_BACKGROUND_INACTIVE.get_int() else: CanvasIcon.do_set_property(self, pspec, value) @@ -87,7 +95,17 @@ class IconButton(CanvasIcon): else: return CanvasIcon.do_get_property(self, pspec) - def _button_press_event_cb(self, widget, event): + def _icon_button_button_press_event_cb(self, widget, event): if self._active: self.emit_activated() return True + + def prelight(self, enter): + if enter: + if self._active: + self.props.fill_color = color.BLACK + self.props.background_color = color.BLACK.get_int() + else: + if self._active: + self.props.fill_color = self._normal_fill_color + self.props.background_color = self._normal_background_color From 4200f1edeb81807bc2e25812dc3d0be75259d4ea Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Sat, 24 Feb 2007 00:39:54 +0100 Subject: [PATCH 02/29] replace _connect_to_server with a protocol/cm independent equivalent --- services/presence2/presenceservice.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/services/presence2/presenceservice.py b/services/presence2/presenceservice.py index 109fd0fd..532c77d9 100644 --- a/services/presence2/presenceservice.py +++ b/services/presence2/presenceservice.py @@ -60,7 +60,12 @@ class PresenceService(dbus.service.Object): self._registry = ManagerRegistry() self._registry.LoadManagers() - self._server_client = self._connect_to_server() + account = { + 'account': 'olpc@collabora.co.uk', + 'password': 'learn', + 'server': 'light.bluelinux.co.uk' + } + self._server_client = self._connect_to_connection_manager("jabber", account) self._handles[self._server_client] = {} # Telepathy link local connection @@ -72,15 +77,13 @@ class PresenceService(dbus.service.Object): dbus.service.Object.__init__(self, self._bus_name, _PRESENCE_PATH) - def _connect_to_server(self): - protocol = 'jabber' - account = { - 'account': 'olpc@collabora.co.uk', - 'password': 'learn', - 'server': 'light.bluelinux.co.uk' - } + def _connect_to_connection_manager(self, protocol, account): + if protocol == "jabber": + cm = "gabble" + else: + return - mgr = self._registry.GetManager('gabble') + mgr = self._registry.GetManager(cm) conn = None # Search existing connections, if any, that we might be able to use @@ -88,7 +91,7 @@ class PresenceService(dbus.service.Object): for item in connections: if item[CONN_INTERFACE].GetProtocol() != protocol: continue - if not item.object_path.startswith("/org/freedesktop/Telepathy/Connection/gabble/jabber/"): + if not item.object_path.startswith("/org/freedesktop/Telepathy/Connection/%s/%s/" % (cm, protocol)): continue if item[CONN_INTERFACE].GetStatus() == CONNECTION_STATUS_CONNECTED: self_name = account['account'] From c58ea7feebfabba24e3d3749d9c92be72db965e7 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sat, 24 Feb 2007 11:40:25 +0100 Subject: [PATCH 03/29] Bump snapshot --- tools/build-snapshot.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build-snapshot.sh b/tools/build-snapshot.sh index f9062dae..aaca040e 100755 --- a/tools/build-snapshot.sh +++ b/tools/build-snapshot.sh @@ -1,6 +1,6 @@ VERSION=0.63 DATE=`date +%Y%m%d` -RELEASE=2.21 +RELEASE=2.22 TARBALL=sugar-$VERSION-$RELEASE.${DATE}git.tar.bz2 rm sugar-$VERSION.tar.bz2 From 52fc6826ab0d3962f710da2a55ddc2dcf868708a Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sat, 24 Feb 2007 14:23:18 +0100 Subject: [PATCH 04/29] Typo. --- shell/view/clipboardicon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/view/clipboardicon.py b/shell/view/clipboardicon.py index faf2e18d..3725ba9f 100644 --- a/shell/view/clipboardicon.py +++ b/shell/view/clipboardicon.py @@ -43,9 +43,9 @@ class ClipboardIcon(CanvasIcon): self._menu.set_state(name, percent, preview, activity) if activity and percent < 100: - self.set_property('color', XoColor("#000000,#424242")) + self.props.xo_color = XoColor("#000000,#424242") else: - self.set_property('color', XoColor("#000000,#FFFFFF")) + self.props.xo_color = XoColor("#000000,#FFFFFF") def _activity_create_success_cb(self, handler, activity): activity.start(util.unique_id()) From 940b50b4e6d507b4e4a1e4a6aa42f418219df87b Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sat, 24 Feb 2007 14:35:31 +0100 Subject: [PATCH 05/29] Add hover to ClipboardIcon. --- shell/view/clipboardicon.py | 7 +++++++ shell/view/clipboardmenu.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/shell/view/clipboardicon.py b/shell/view/clipboardicon.py index 3725ba9f..caa949ad 100644 --- a/shell/view/clipboardicon.py +++ b/shell/view/clipboardicon.py @@ -4,6 +4,7 @@ from sugar.graphics.canvasicon import CanvasIcon from view.clipboardmenu import ClipboardMenu from sugar.graphics.xocolor import XoColor from sugar.graphics import units +from sugar.graphics import color from sugar.activity import activityfactory from sugar.clipboard import clipboardservice from sugar import util @@ -81,3 +82,9 @@ class ClipboardIcon(CanvasIcon): def get_object_id(self): return self._object_id + + def prelight(self, enter): + if enter: + self.props.background_color = color.BLACK.get_int() + else: + self.props.background_color = color.TOOLBAR_BACKGROUND.get_int() diff --git a/shell/view/clipboardmenu.py b/shell/view/clipboardmenu.py index 1ea53616..3e8239d6 100644 --- a/shell/view/clipboardmenu.py +++ b/shell/view/clipboardmenu.py @@ -13,7 +13,7 @@ class ClipboardProgressBar(ClipboardBubble): def __init__(self, percent = 0): self._text_item = None ClipboardBubble.__init__(self, percent=percent) - + self._text_item = hippo.CanvasText(text=str(percent) + ' %') self._text_item.props.color = color.LABEL_TEXT.get_int() self._text_item.props.font_desc = font.DEFAULT.get_pango_desc() @@ -35,6 +35,7 @@ class ClipboardMenu(Menu): def __init__(self, name, percent, preview, activity): Menu.__init__(self, name) + self.props.border = 0 if percent < 100: self._progress_bar = ClipboardProgressBar(percent) From ce800fbc66c2790f5bf9a38006812a16478342aa Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sat, 24 Feb 2007 14:58:38 +0100 Subject: [PATCH 06/29] Add hover to BuddyIcon in the Frame. --- shell/view/BuddyMenu.py | 2 ++ shell/view/frame/FriendsBox.py | 21 ++++++++++++++++++--- shell/view/frame/framepopupcontext.py | 2 +- sugar/graphics/snowflakebox.py | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/shell/view/BuddyMenu.py b/shell/view/BuddyMenu.py index b4548224..ad4a5d40 100644 --- a/shell/view/BuddyMenu.py +++ b/shell/view/BuddyMenu.py @@ -35,6 +35,8 @@ class BuddyMenu(Menu): self._shell = shell Menu.__init__(self, buddy.get_name()) + self.props.border = 0 + self.props.padding = units.points_to_pixels(5) pixbuf = self._get_buddy_icon_pixbuf() if pixbuf: icon_item = hippo.CanvasImage() diff --git a/shell/view/frame/FriendsBox.py b/shell/view/frame/FriendsBox.py index 9b12f6c2..481b1288 100644 --- a/shell/view/frame/FriendsBox.py +++ b/shell/view/frame/FriendsBox.py @@ -17,15 +17,30 @@ import hippo from sugar.graphics.canvasicon import CanvasIcon +from sugar.graphics import color from sugar.presence import PresenceService from view.BuddyIcon import BuddyIcon from model.BuddyModel import BuddyModel +class FriendIcon(BuddyIcon): + def __init__(self, shell, popup_context, buddy): + BuddyIcon.__init__(self, shell, popup_context, buddy) + self._popup_context = popup_context + + def get_popup_context(self): + return self._popup_context + + def prelight(self, enter): + if enter: + self.props.background_color = color.BLACK.get_int() + else: + self.props.background_color = color.TOOLBAR_BACKGROUND.get_int() + class FriendsBox(hippo.CanvasBox): - def __init__(self, shell, menu_shell): + def __init__(self, shell, popup_context): hippo.CanvasBox.__init__(self) self._shell = shell - self._menu_shell = menu_shell + self._popup_context = popup_context self._activity_ps = None self._joined_hid = -1 self._left_hid = -1 @@ -48,7 +63,7 @@ class FriendsBox(hippo.CanvasBox): return model = BuddyModel(buddy=buddy) - icon = BuddyIcon(self._shell, self._menu_shell, model) + icon = FriendIcon(self._shell, self._popup_context, model) self.append(icon) self._buddies[buddy.get_name()] = icon diff --git a/shell/view/frame/framepopupcontext.py b/shell/view/frame/framepopupcontext.py index b4b5c094..63304cc1 100644 --- a/shell/view/frame/framepopupcontext.py +++ b/shell/view/frame/framepopupcontext.py @@ -36,7 +36,7 @@ class FramePopupContext(PopupContext): left_x = item_x + item_w left_y = item_y - right_x = item_x + item_w + right_x = item_x - popup_w right_y = item_y top_x = item_x top_y = item_y + item_h diff --git a/sugar/graphics/snowflakebox.py b/sugar/graphics/snowflakebox.py index 9e2fd784..f0d446c2 100644 --- a/sugar/graphics/snowflakebox.py +++ b/sugar/graphics/snowflakebox.py @@ -85,7 +85,7 @@ class SnowflakeBox(hippo.CanvasBox, hippo.CanvasItem): return width def do_allocate(self, width, height, origin_changed): - hippo.CanvasBox.do_allocate(self, width, height) + hippo.CanvasBox.do_allocate(self, width, height, origin_changed) self._layout_root() From 2b1445be6cb71b0eef611b397c2a17278409667b Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sat, 24 Feb 2007 15:22:16 +0100 Subject: [PATCH 07/29] Adjusted rounded box radius. --- sugar/graphics/roundbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sugar/graphics/roundbox.py b/sugar/graphics/roundbox.py index a24f8202..1559ec2a 100644 --- a/sugar/graphics/roundbox.py +++ b/sugar/graphics/roundbox.py @@ -31,7 +31,7 @@ class RoundBox(hippo.CanvasBox, hippo.CanvasItem): hippo.CanvasBox.__init__(self, **kwargs) # TODO: we should calculate this value depending on the height of the box. - self._radius = units.points_to_pixels(10) + self._radius = units.points_to_pixels(7) self.props.orientation = hippo.ORIENTATION_HORIZONTAL self.props.border_top = self._BORDER_DEFAULT From 5714396e342d77de5bcc69d4d00da90c010e0e27 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sat, 24 Feb 2007 15:30:16 +0100 Subject: [PATCH 08/29] Add hovering to MenuItem. --- sugar/graphics/color.py | 2 ++ sugar/graphics/menu.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/sugar/graphics/color.py b/sugar/graphics/color.py index e07df4a7..32d248cc 100644 --- a/sugar/graphics/color.py +++ b/sugar/graphics/color.py @@ -13,6 +13,7 @@ _system_colors = { 'label-text' : '#FFFFFF', 'desktop-background' : '#E2E2E3', 'menu-background' : '#000000', + 'menu-background-hover' : '#424242', 'menu-separator' : '#D1D1D2', 'menu-border' : '#D1D1D2', 'button-normal' : '#FFFFFF', @@ -90,6 +91,7 @@ ENTRY_BORDER = SystemColor('entry-border') LABEL_TEXT = SystemColor('label-text') DESKTOP_BACKGROUND = SystemColor('desktop-background') MENU_BACKGROUND = SystemColor('menu-background') +MENU_BACKGROUND_HOVER = SystemColor('menu-background-hover') MENU_SEPARATOR = SystemColor('menu-separator') MENU_BORDER = SystemColor('menu-border') BUTTON_NORMAL = SystemColor('button-normal') diff --git a/sugar/graphics/menu.py b/sugar/graphics/menu.py index e60bd61a..2a80c878 100644 --- a/sugar/graphics/menu.py +++ b/sugar/graphics/menu.py @@ -56,6 +56,14 @@ class MenuItem(hippo.CanvasBox): self._canvas_text.props.color = color.LABEL_TEXT.get_int() self._canvas_text.props.font_desc = font.DEFAULT.get_pango_desc() self.append(self._canvas_text) + + self.connect('motion-notify-event', self._motion_notify_event_cb) + + def _motion_notify_event_cb(self, menu_item, event): + if event.detail == hippo.MOTION_DETAIL_ENTER: + self.props.background_color = color.MENU_BACKGROUND_HOVER.get_int() + elif event.detail == hippo.MOTION_DETAIL_LEAVE: + self.props.background_color = color.MENU_BACKGROUND.get_int() def do_set_property(self, pspec, value): if pspec.name == 'action-id': From 951e92395bd80758081fe501d4f73727273dc7ad Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sat, 24 Feb 2007 17:15:47 +0100 Subject: [PATCH 09/29] Make the default icon scale depend on the screen resolution. --- sugar/graphics/canvasicon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 82e9bd1e..76d29b0b 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -143,7 +143,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): 'stroke-color' : (object, None, None, gobject.PARAM_READWRITE), 'scale' : (float, None, None, - 0.0, 1024.0, 1.0, + 0.0, 1024.0, units.STANDARD_ICON_SCALE, gobject.PARAM_READWRITE), 'cache' : (bool, None, None, False, gobject.PARAM_READWRITE), @@ -156,7 +156,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): def __init__(self, **kwargs): self._buffers = {} self._cur_buffer = None - self._scale = 1.0 + self._scale = units.STANDARD_ICON_SCALE self._fill_color = None self._stroke_color = None self._icon_name = None From 3b7670a3645c58f1c43075de0f4e4f55d133b6ae Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sat, 24 Feb 2007 17:40:18 +0100 Subject: [PATCH 10/29] Don't present from inside the Activity constructor --- sugar/activity/activity.py | 2 -- sugar/activity/activityfactoryservice.py | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index 54589ff1..ca2d12fd 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -47,8 +47,6 @@ class Activity(gtk.Window): self._bus = ActivityService(self) - self.present() - def get_service_name(self): """Gets the activity service name.""" return os.environ['SUGAR_BUNDLE_SERVICE_NAME'] diff --git a/sugar/activity/activityfactoryservice.py b/sugar/activity/activityfactoryservice.py index 822bf99d..548ff33f 100644 --- a/sugar/activity/activityfactoryservice.py +++ b/sugar/activity/activityfactoryservice.py @@ -61,6 +61,7 @@ class ActivityFactoryService(dbus.service.Object): def create(self, handle): activity_handle = activityhandle.create_from_dict(handle) activity = self._constructor(activity_handle) + activity.present() self._activities.append(activity) activity.connect('destroy', self._activity_destroy_cb) From 067f703bfe7787bd4706172f0c56e57874899966 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sat, 24 Feb 2007 18:18:50 +0100 Subject: [PATCH 11/29] Make OptionMenu grab the pointer on popup. --- sugar/graphics/canvasicon.py | 2 +- sugar/graphics/optionmenu.py | 8 +++++++- sugar/graphics/popup.py | 8 ++++++++ tests/test-option-menu.py | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 76d29b0b..fe04074f 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -355,7 +355,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): [x, y] = context.translate_to_screen(self) # TODO: Any better place to do this? - popup.props.box_width = max(popup.props.box_width, + popup.props.box_width = max(popup.get_width_request(), self.get_width_request()) [width, height] = self.get_allocation() diff --git a/sugar/graphics/optionmenu.py b/sugar/graphics/optionmenu.py index edd1d39e..f5a44175 100644 --- a/sugar/graphics/optionmenu.py +++ b/sugar/graphics/optionmenu.py @@ -64,6 +64,8 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): self._round_box = RoundBox() self._round_box.props.border_color = color.FRAME_BORDER.get_int() + self._round_box.props.spacing = units.points_to_pixels(3) + self._round_box.props.padding = units.points_to_pixels(1) self.append(self._round_box, hippo.PACK_EXPAND) self._canvas_text = hippo.CanvasText() @@ -111,10 +113,14 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): [x, y] = context.translate_to_screen(self._round_box) # TODO: Any better place to do this? - self._menu.props.box_width = self.get_width_request() + self._menu.props.box_width = max(self.get_width_request(), + self._menu.get_width_request()) [width, height] = self._round_box.get_allocation() self._menu.popup(x, y + height) + + # Grab the pointer so the menu will popdown on mouse click. + self._menu.grab_pointer() def _menu_action_cb(self, menu, menu_item): action_id = menu_item.props.action_id diff --git a/sugar/graphics/popup.py b/sugar/graphics/popup.py index 5c63b6e3..d0bee06e 100644 --- a/sugar/graphics/popup.py +++ b/sugar/graphics/popup.py @@ -46,5 +46,13 @@ class Popup(hippo.CanvasBox, hippo.CanvasItem): self._window.hide() self._visible = False + def grab_pointer(self): + gtk.gdk.pointer_grab(self._window.window, owner_events=False, + event_mask=gtk.gdk.BUTTON_PRESS_MASK | + gtk.gdk.BUTTON_RELEASE_MASK | + gtk.gdk.ENTER_NOTIFY_MASK | + gtk.gdk.LEAVE_NOTIFY_MASK | + gtk.gdk.POINTER_MOTION_MASK) + def _button_press_event_cb(self, menu, event): self.emit('action-completed') diff --git a/tests/test-option-menu.py b/tests/test-option-menu.py index bbcc03a0..f320afcc 100755 --- a/tests/test-option-menu.py +++ b/tests/test-option-menu.py @@ -48,7 +48,7 @@ canvas.set_root(vbox) toolbar = Toolbar() vbox.append(toolbar) -button = IconButton('theme:stock-close') +button = IconButton(icon_name='theme:stock-close') toolbar.append(button) OPTION_ANYTHING = 1 From d7eb3fd73400bef047ba49bf50d8673aa121dab0 Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Sat, 24 Feb 2007 13:28:04 -0500 Subject: [PATCH 12/29] Fix part of bug 853, reposition and resize sugar frame after rotate --- shell/view/frame/PanelWindow.py | 46 +++++++++++++++++++++------------ shell/view/frame/frame.py | 23 ++++++++++++----- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/shell/view/frame/PanelWindow.py b/shell/view/frame/PanelWindow.py index e14f6b4b..6edd4bd7 100644 --- a/shell/view/frame/PanelWindow.py +++ b/shell/view/frame/PanelWindow.py @@ -22,6 +22,7 @@ from sugar.graphics import units class PanelWindow(gtk.Window): def __init__(self, orientation): gtk.Window.__init__(self) + self._orientation = orientation self.set_decorated(False) self.connect('realize', self._realize_cb) @@ -29,35 +30,46 @@ class PanelWindow(gtk.Window): self._canvas = hippo.Canvas() self._bg = hippo.CanvasBox(background_color=0x414141ff, - orientation=orientation) - - padding = units.grid_to_pixels(1) - if orientation == hippo.ORIENTATION_HORIZONTAL: - self._bg.props.padding_left = padding - self._bg.props.padding_right = padding - - width = gtk.gdk.screen_width() - height = units.grid_to_pixels(1) - else: - self._bg.props.padding_top = padding - self._bg.props.padding_bottom = padding - - width = units.grid_to_pixels(1) - height = gtk.gdk.screen_height() + orientation=self._orientation) + self._update_size() self._canvas.set_root(self._bg) self.add(self._canvas) self._canvas.show() - - self.resize(width, height) + + screen = gtk.gdk.screen_get_default() + screen.connect('size-changed', self._size_changed_cb) def get_root(self): return self._bg def get_canvas(self): return self._canvas + + def _update_size(self): + padding = units.grid_to_pixels(1) + if self._orientation == hippo.ORIENTATION_HORIZONTAL: + self._bg.props.padding_left = padding + self._bg.props.padding_right = padding + self._bg.props.padding_top = 0 + self._bg.props.padding_bottom = 0 + + width = gtk.gdk.screen_width() + height = units.grid_to_pixels(1) + else: + self._bg.props.padding_left = 0 + self._bg.props.padding_right = 0 + self._bg.props.padding_top = padding + self._bg.props.padding_bottom = padding + + width = units.grid_to_pixels(1) + height = gtk.gdk.screen_height() + self.resize(width, height) def _realize_cb(self, widget): self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.window.set_accept_focus(False) + + def _size_changed_cb(self, screen): + self._update_size() diff --git a/shell/view/frame/frame.py b/shell/view/frame/frame.py index 27658f03..f15bf35f 100644 --- a/shell/view/frame/frame.py +++ b/shell/view/frame/frame.py @@ -50,6 +50,7 @@ class Frame: self._hover_frame = False self._shell = shell self._mode = Frame.INACTIVE + self._current_position = 0 self._timeline = Timeline(self) self._timeline.add_tag('slide_in', 18, 24) @@ -75,6 +76,9 @@ class Frame: shell.get_model().connect('notify::state', self._shell_state_changed_cb) + + screen = gtk.gdk.screen_get_default() + screen.connect('size-changed', self._size_changed_cb) def _create_top_panel(self): panel = self._create_panel(hippo.ORIENTATION_HORIZONTAL) @@ -219,24 +223,28 @@ class Frame: def notify_key_release(self): if self._mode == Frame.TEMPORARY: self._timeline.play('before_slide_out', 'slide_out') - + def _move(self, pos): + self._current_position = pos + self._update_position() + + def _update_position(self): screen_h = gtk.gdk.screen_height() screen_w = gtk.gdk.screen_width() - self._move_panel(self._top_panel, pos, + self._move_panel(self._top_panel, self._current_position, 0, units.grid_to_pixels(-1), 0, 0) - self._move_panel(self._bottom_panel, pos, + self._move_panel(self._bottom_panel, self._current_position, 0, screen_h, 0, screen_h - units.grid_to_pixels(1)) - self._move_panel(self._left_panel, pos, + self._move_panel(self._left_panel, self._current_position, units.grid_to_pixels(-1), 0, 0, 0) - self._move_panel(self._right_panel, pos, + self._move_panel(self._right_panel, self._current_position, screen_w, 0, screen_w - units.grid_to_pixels(1), 0) @@ -255,7 +263,10 @@ class Frame: self._move(0) if not self._event_frame.is_visible(): self._event_frame.show() - + + def _size_changed_cb(self, screen): + self._update_position() + def is_visible(self): return self._top_panel.props.visible From 89aa65d0f6ae70e928c8b3db6df921cc6205df51 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 01:07:05 +0100 Subject: [PATCH 13/29] Move hardwaremanager out of the view to his own module --- configure.ac | 1 + shell/hardware/Makefile.am | 4 +++ shell/hardware/__init__.py | 0 shell/{view => hardware}/hardwaremanager.py | 29 ++++++++++++++------- shell/view/Makefile.am | 3 +-- shell/view/Shell.py | 11 -------- shell/view/keyhandler.py | 10 +++---- 7 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 shell/hardware/Makefile.am create mode 100644 shell/hardware/__init__.py rename shell/{view => hardware}/hardwaremanager.py (73%) diff --git a/configure.ac b/configure.ac index a6c65ab5..59408908 100644 --- a/configure.ac +++ b/configure.ac @@ -117,6 +117,7 @@ services/clipboard/Makefile services/datastore/Makefile shell/Makefile shell/data/Makefile +shell/hardware/Makefile shell/view/Makefile shell/view/devices/Makefile shell/view/frame/Makefile diff --git a/shell/hardware/Makefile.am b/shell/hardware/Makefile.am new file mode 100644 index 00000000..86cc0c75 --- /dev/null +++ b/shell/hardware/Makefile.am @@ -0,0 +1,4 @@ +sugardir = $(pkgdatadir)/shell/hardware +sugar_PYTHON = \ + __init__.py \ + hardwaremanager.py diff --git a/shell/hardware/__init__.py b/shell/hardware/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/shell/view/hardwaremanager.py b/shell/hardware/hardwaremanager.py similarity index 73% rename from shell/view/hardwaremanager.py rename to shell/hardware/hardwaremanager.py index 30b65b0a..39ae767f 100644 --- a/shell/view/hardwaremanager.py +++ b/shell/hardware/hardwaremanager.py @@ -18,20 +18,22 @@ import logging import dbus -HARDWARE_MANAGER_INTERFACE = 'org.laptop.HardwareManager' -HARDWARE_MANAGER_SERVICE = 'org.laptop.HardwareManager' -HARDWARE_MANAGER_OBJECT_PATH = '/org/laptop/HardwareManager' +from _sugar import AudioManager + +_HARDWARE_MANAGER_INTERFACE = 'org.laptop.HardwareManager' +_HARDWARE_MANAGER_SERVICE = 'org.laptop.HardwareManager' +_HARDWARE_MANAGER_OBJECT_PATH = '/org/laptop/HardwareManager' + +COLOR_MODE = 0 +B_AND_W_MODE = 1 class HardwareManager(object): - COLOR_MODE = 0 - B_AND_W_MODE = 1 - def __init__(self): try: bus = dbus.SystemBus() - proxy = bus.get_object(HARDWARE_MANAGER_SERVICE, - HARDWARE_MANAGER_OBJECT_PATH) - self._service = dbus.Interface(proxy, HARDWARE_MANAGER_INTERFACE) + proxy = bus.get_object(_HARDWARE_MANAGER_SERVICE, + _HARDWARE_MANAGER_OBJECT_PATH) + self._service = dbus.Interface(proxy, _HARDWARE_MANAGER_INTERFACE) except dbus.DBusException: self._service = None logging.error('Hardware manager service not found.') @@ -56,3 +58,12 @@ class HardwareManager(object): self._service.set_keyboard_brightness(False) else: self._service.set_keyboard_brightness(True) + +def get_hardware_manager(): + return _hardware_manager + +def get_audio_manager(): + return _audio_manager + +_hardware_manager = HardwareManager() +_audio_manager = AudioManager() diff --git a/shell/view/Makefile.am b/shell/view/Makefile.am index c463084c..7b571ec3 100644 --- a/shell/view/Makefile.am +++ b/shell/view/Makefile.am @@ -11,5 +11,4 @@ sugar_PYTHON = \ clipboardmenu.py \ keyhandler.py \ OverlayWindow.py \ - Shell.py \ - hardwaremanager.py + Shell.py diff --git a/shell/view/Shell.py b/shell/view/Shell.py index 812698fb..c032831d 100644 --- a/shell/view/Shell.py +++ b/shell/view/Shell.py @@ -26,8 +26,6 @@ from view.ActivityHost import ActivityHost from sugar.activity import activityfactory from view.frame.frame import Frame from view.keyhandler import KeyHandler -from view.hardwaremanager import HardwareManager -from _sugar import AudioManager import sugar class Shell(gobject.GObject): @@ -40,9 +38,6 @@ class Shell(gobject.GObject): self._current_host = None self._screen_rotation = 0 - self._hw_manager = HardwareManager() - self._audio_manager = AudioManager() - self._home_window = HomeWindow(self) self._home_window.show() self.set_zoom_level(sugar.ZOOM_HOME) @@ -88,12 +83,6 @@ class Shell(gobject.GObject): if self._current_host: self._current_host.set_active(True) - def get_hardware_manager(self): - return self._hw_manager - - def get_audio_manager(self): - return self._audio_manager - def get_model(self): return self._model diff --git a/shell/view/keyhandler.py b/shell/view/keyhandler.py index fb2dfdb9..511e722a 100644 --- a/shell/view/keyhandler.py +++ b/shell/view/keyhandler.py @@ -2,7 +2,7 @@ import dbus import gobject from sugar import env -from view.hardwaremanager import HardwareManager +from hardware import hardwaremanager from model.ShellModel import ShellModel from _sugar import KeyGrabber import sugar @@ -40,8 +40,8 @@ _actions_table = { class KeyHandler(object): def __init__(self, shell): self._shell = shell - self._hw_manager = shell.get_hardware_manager() - self._audio_manager = shell.get_audio_manager() + self._hw_manager = hardwaremanager.get_hardware_manager() + self._audio_manager = hardwaremanager.get_audio_manager() self._screen_rotation = 0 self._key_grabber = KeyGrabber() @@ -90,10 +90,10 @@ class KeyHandler(object): self._audio_manager.set_volume(100) def handle_color_mode(self): - self._hw_manager.set_display_mode(HardwareManager.COLOR_MODE) + self._hw_manager.set_display_mode(hardwaremanager.COLOR_MODE) def handle_b_and_w_mode(self): - self._hw_manager.set_display_mode(HardwareManager.B_AND_W_MODE) + self._hw_manager.set_display_mode(hardwaremanager.B_AND_W_MODE) def handle_console(self): gobject.idle_add(self._toggle_console_visibility_cb) From 755250947a5b49c7fc8353055f65db6c4b277cbd Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 02:00:40 +0100 Subject: [PATCH 14/29] Some work on the network devices --- shell/Makefile.am | 2 +- shell/hardware/Makefile.am | 4 +- shell/hardware/hardwaremanager.py | 5 + shell/hardware/nmclient.py | 467 ++++++++++++++++++ shell/hardware/nminfo.py | 467 ++++++++++++++++++ shell/model/devices/Makefile.am | 3 +- shell/model/devices/battery.py | 2 +- shell/model/devices/devicesmodel.py | 22 +- .../devices/{network.py => wirednetwork.py} | 8 +- shell/model/devices/wirelessnetwork.py | 12 + shell/view/devices/Makefile.am | 3 +- shell/view/devices/battery.py | 2 +- .../devices/{network.py => wirednetwork.py} | 2 +- shell/view/devices/wirelessnetwork.py | 6 + 14 files changed, 990 insertions(+), 15 deletions(-) create mode 100644 shell/hardware/nmclient.py create mode 100644 shell/hardware/nminfo.py rename shell/model/devices/{network.py => wirednetwork.py} (56%) create mode 100644 shell/model/devices/wirelessnetwork.py rename shell/view/devices/{network.py => wirednetwork.py} (74%) create mode 100644 shell/view/devices/wirelessnetwork.py diff --git a/shell/Makefile.am b/shell/Makefile.am index 6d6f6336..e5a566f5 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = data model view +SUBDIRS = data hardware model view bin_SCRIPTS = \ sugar-activity \ diff --git a/shell/hardware/Makefile.am b/shell/hardware/Makefile.am index 86cc0c75..da992764 100644 --- a/shell/hardware/Makefile.am +++ b/shell/hardware/Makefile.am @@ -1,4 +1,6 @@ sugardir = $(pkgdatadir)/shell/hardware sugar_PYTHON = \ __init__.py \ - hardwaremanager.py + hardwaremanager.py \ + nmclient.py \ + nminfo.py diff --git a/shell/hardware/hardwaremanager.py b/shell/hardware/hardwaremanager.py index 39ae767f..007241bb 100644 --- a/shell/hardware/hardwaremanager.py +++ b/shell/hardware/hardwaremanager.py @@ -18,6 +18,7 @@ import logging import dbus +from hardware.nmclient import NMClient from _sugar import AudioManager _HARDWARE_MANAGER_INTERFACE = 'org.laptop.HardwareManager' @@ -65,5 +66,9 @@ def get_hardware_manager(): def get_audio_manager(): return _audio_manager +def get_network_manager(): + return _network_manager + _hardware_manager = HardwareManager() _audio_manager = AudioManager() +_network_manager = NMClient() diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py new file mode 100644 index 00000000..9a2c5a80 --- /dev/null +++ b/shell/hardware/nmclient.py @@ -0,0 +1,467 @@ +# +# Copyright (C) 2006, Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# 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, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import logging +import os + +import dbus +import dbus.glib +import dbus.decorators +import gobject + +from hardware import nminfo + +IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001 +IW_AUTH_ALG_SHARED_KEY = 0x00000002 + +NM_DEVICE_STAGE_STRINGS=("Unknown", + "Prepare", + "Config", + "Need Users Key", + "IP Config", + "IP Config Get", + "IP Config Commit", + "Activated", + "Failed", + "Cancled" +) + +NM_SERVICE = 'org.freedesktop.NetworkManager' +NM_IFACE = 'org.freedesktop.NetworkManager' +NM_IFACE_DEVICES = 'org.freedesktop.NetworkManager.Devices' +NM_PATH = '/org/freedesktop/NetworkManager' + +DEVICE_TYPE_UNKNOWN = 0 +DEVICE_TYPE_802_3_ETHERNET = 1 +DEVICE_TYPE_802_11_WIRELESS = 2 + +NM_DEVICE_CAP_NONE = 0x00000000 +NM_DEVICE_CAP_NM_SUPPORTED = 0x00000001 +NM_DEVICE_CAP_CARRIER_DETECT = 0x00000002 +NM_DEVICE_CAP_WIRELESS_SCAN = 0x00000004 + +sys_bus = dbus.SystemBus() + +NM_802_11_CAP_NONE = 0x00000000 +NM_802_11_CAP_PROTO_NONE = 0x00000001 +NM_802_11_CAP_PROTO_WEP = 0x00000002 +NM_802_11_CAP_PROTO_WPA = 0x00000004 +NM_802_11_CAP_PROTO_WPA2 = 0x00000008 +NM_802_11_CAP_KEY_MGMT_PSK = 0x00000040 +NM_802_11_CAP_KEY_MGMT_802_1X = 0x00000080 +NM_802_11_CAP_CIPHER_WEP40 = 0x00001000 +NM_802_11_CAP_CIPHER_WEP104 = 0x00002000 +NM_802_11_CAP_CIPHER_TKIP = 0x00004000 +NM_802_11_CAP_CIPHER_CCMP = 0x00008000 + + +class Network(gobject.GObject): + __gsignals__ = { + 'init-failed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) + } + + def __init__(self, op): + gobject.GObject.__init__(self) + self._op = op + self._ssid = None + self._mode = None + self._strength = 0 + self._valid = False + + obj = sys_bus.get_object(NM_SERVICE, self._op) + net = dbus.Interface(obj, NM_IFACE_DEVICES) + net.getProperties(reply_handler=self._update_reply_cb, + error_handler=self._update_error_cb) + + def _update_reply_cb(self, *props): + self._ssid = props[1] + self._strength = props[3] + self._mode = props[6] + caps = props[7] + if caps & NM_802_11_CAP_PROTO_WPA or caps & NM_802_11_CAP_PROTO_WPA2: + # We do not support WPA at this time, so don't show + # WPA-enabled access points in the menu + logging.debug("Net(%s): ssid '%s' dropping because WPA[2] unsupported" % (self._op, + self._ssid)) + self._valid = False + self.emit('init-failed') + else: + self._valid = True + logging.debug("Net(%s): ssid '%s', mode %d, strength %d" % (self._op, + self._ssid, self._mode, self._strength)) + + def _update_error_cb(self, err): + logging.debug("Net(%s): failed to update. (%s)" % (self._op, err)) + self._valid = False + self.emit('init-failed') + + def get_ssid(self): + return self._ssid + + def get_op(self): + return self._op + + def get_strength(self): + return self._strength + + def set_strength(self, strength): + self._strength = strength + + def is_valid(self): + return self._valid + +class Device(gobject.GObject): + __gsignals__ = { + 'init-failed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), + 'activated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), + 'strength-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])) + } + + def __init__(self, op): + gobject.GObject.__init__(self) + self._op = op + self._iface = None + self._type = DEVICE_TYPE_UNKNOWN + self._udi = None + self._active = False + self._strength = 0 + self._link = False + self._valid = False + self._networks = {} + self._active_net = None + self._caps = 0 + + obj = sys_bus.get_object(NM_SERVICE, self._op) + dev = dbus.Interface(obj, NM_IFACE_DEVICES) + dev.getProperties(reply_handler=self._update_reply_cb, + error_handler=self._update_error_cb) + + def _update_reply_cb(self, *props): + self._iface = props[1] + self._type = props[2] + self._udi = props[3] + self._active = props[4] + if self._active: + self.emit('activated') + self._link = props[15] + self._caps = props[17] + + if self._type == DEVICE_TYPE_802_11_WIRELESS: + old_strength = self._strength + self._strength = props[14] + if self._strength != old_strength: + self.emit('strength-changed', self._strength) + self._update_networks(props[20], props[19]) + + self._valid = True + + def _update_networks(self, net_ops, active_op): + for op in net_ops: + net = Network(op) + self._networks[op] = net + net.connect('init-failed', self._net_init_failed) + if op == active_op: + self._active_net = op + + def _update_error_cb(self, err): + logging.debug("Device(%s): failed to update. (%s)" % (self._op, err)) + self._valid = False + self.emit('init-failed') + + def _net_init_failed(self, net): + net_op = net.get_op() + if not self._networks.has_key(net_op): + return + if net_op == self._active_net: + self._active_net = None + del self._networks[net_op] + + def get_op(self): + return self._op + + def get_network(self, op): + if self._networks.has_key(op): + return self._networks[op] + return None + + def get_network_ops(self): + return self._networks.keys() + + def get_strength(self): + return self._strength + + def set_strength(self, strength): + if strength == self._strength: + return False + + if strength >= 0 and strength <= 100: + self._strength = strength + else: + self._strength = 0 + + self.emit('strength-changed', self._strength) + + def network_appeared(self, network): + if self._networks.has_key(network): + return + net = Network(network) + self._networks[network] = net + net.connect('init-failed', self._net_init_failed) + + def network_disappeared(self, network): + if not self._networks.has_key(network): + return + if network == self._active_net: + self._active_net = None + del self._networks[network] + + def get_active(self): + return self._active + + def set_active(self, active, ssid=None): + self._active = active + if self._type == DEVICE_TYPE_802_11_WIRELESS: + if not ssid: + self._active_net = None + else: + for (op, net) in self._networks.items(): + if net.get_ssid() == ssid: + self._active_net = op + + def get_type(self): + return self._type + + def is_valid(self): + return self._valid + + def set_carrier(self, on): + self._link = on + + def get_capabilities(self): + return self._caps + +NM_STATE_UNKNOWN = 0 +NM_STATE_ASLEEP = 1 +NM_STATE_CONNECTING = 2 +NM_STATE_CONNECTED = 3 +NM_STATE_DISCONNECTED = 4 + +class NMClient(object): + def __init__(self): + self.nminfo = None + self._nm_present = False + self._nm_state = NM_STATE_UNKNOWN + self._update_timer = 0 + self._active_device = None + self._devices = {} + + try: + self.nminfo = nminfo.NMInfo(self) + except RuntimeError: + pass + self._setup_dbus() + if self._nm_present: + self._get_nm_state() + self._get_initial_devices() + + def get_devices(self): + return self._devices + + def _get_nm_state(self): + # Grab NM's state + self._nm_obj.state(reply_handler=self._get_state_reply_cb, \ + error_handler=self._get_state_error_cb) + + def _get_state_reply_cb(self, state): + self._nm_state = state + + def _get_state_error_cb(self, err): + logging.debug("Failed to get NetworkManager state! %s" % err) + + def _get_initial_devices_reply_cb(self, ops): + for op in ops: + self._add_device(op) + + def _dev_init_failed_cb(self, dev): + # Device failed to initialize, likely due to dbus errors or something + op = dev.get_op() + self._remove_device(op) + + def _get_initial_devices_error_cb(self, err): + logging.debug("Error updating devices (%s)" % err) + + def _get_initial_devices(self): + self._nm_obj.getDevices(reply_handler=self._get_initial_devices_reply_cb, \ + error_handler=self._get_initial_devices_error_cb) + + def _add_device(self, dev_op): + if self._devices.has_key(dev_op): + return + dev = Device(dev_op) + self._devices[dev_op] = dev + dev.connect('init-failed', self._dev_init_failed_cb) + dev.connect('activated', self._dev_activated_cb) + dev.connect('strength-changed', self._dev_strength_changed_cb) + + def _remove_device(self, dev_op): + if not self._devices.has_key(dev_op): + return + if self._active_device == dev_op: + self._active_device = None + dev = self._devices[dev_op] + dev.disconnect('activated') + dev.disconnect('init-failed') + dev.disconnect('strength-changed') + del self._devices[dev_op] + + def _dev_activated_cb(self, dev): + op = dev.get_op() + if not self._devices.has_key(op): + return + if not dev.get_active(): + return + self._active_device = op + + def _dev_strength_changed_cb(self, dev, strength): + op = dev.get_op() + if not self._devices.has_key(op): + return + if not dev.get_active(): + return + + def get_device(self, dev_op): + if not self._devices.has_key(dev_op): + return None + return self._devices[dev_op] + + def _setup_dbus(self): + self._sig_handlers = { + 'StateChange': self.state_change_sig_handler, + 'DeviceAdded': self.device_added_sig_handler, + 'DeviceRemoved': self.device_removed_sig_handler, + 'DeviceActivationStage': self.device_activation_stage_sig_handler, + 'DeviceActivating': self.device_activating_sig_handler, + 'DeviceNowActive': self.device_now_active_sig_handler, + 'DeviceNoLongerActive': self.device_no_longer_active_sig_handler, + 'DeviceCarrierOn': self.device_carrier_on_sig_handler, + 'DeviceCarrierOff': self.device_carrier_off_sig_handler, + 'DeviceStrengthChanged': self.wireless_device_strength_changed_sig_handler, + 'WirelessNetworkAppeared': self.wireless_network_appeared_sig_handler, + 'WirelessNetworkDisappeared': self.wireless_network_disappeared_sig_handler, + 'WirelessNetworkStrengthChanged': self.wireless_network_strength_changed_sig_handler + } + + self._nm_proxy = sys_bus.get_object(NM_SERVICE, NM_PATH) + self._nm_obj = dbus.Interface(self._nm_proxy, NM_IFACE) + + sys_bus.add_signal_receiver(self.name_owner_changed_sig_handler, + signal_name="NameOwnerChanged", + dbus_interface="org.freedesktop.DBus") + + for (signal, handler) in self._sig_handlers.items(): + sys_bus.add_signal_receiver(handler, signal_name=signal, dbus_interface=NM_IFACE) + + # Find out whether or not NM is running + try: + bus_object = sys_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') + name = bus_object.GetNameOwner("org.freedesktop.NetworkManagerInfo", \ + dbus_interface='org.freedesktop.DBus') + if name: + self._nm_present = True + except dbus.DBusException: + pass + + def get_key_for_network(self, net, async_cb, async_err_cb): + pass + + def device_activation_stage_sig_handler(self, device, stage): + logging.debug('Device Activation Stage "%s" for device %s' % (NM_DEVICE_STAGE_STRINGS[stage], device)) + + def state_change_sig_handler(self, state): + self._nm_state = state + + def device_activating_sig_handler(self, device): + self._active_device = device + + def device_now_active_sig_handler(self, device, ssid=None): + if not self._devices.has_key(device): + return + self._active_device = device + self._devices[device].set_active(True, ssid) + + def device_no_longer_active_sig_handler(self, device): + if not self._devices.has_key(device): + return + if self._active_device == device: + self._active_device = None + self._devices[device].set_active(False) + + def name_owner_changed_sig_handler(self, name, old, new): + if name != NM_SERVICE: + return + if (old and len(old)) and (not new and not len(new)): + # NM went away + self._nm_present = False + for op in self._devices.keys(): + del self._devices[op] + self._devices = {} + self._active_device = None + self._nm_state = NM_STATE_UNKNOWN + elif (not old and not len(old)) and (new and len(new)): + # NM started up + self._nm_present = True + self._get_nm_state() + self._get_initial_devices() + + def device_added_sig_handler(self, device): + self._add_device(device) + + def device_removed_sig_handler(self, device): + self._remove_device(device) + + def wireless_network_appeared_sig_handler(self, device, network): + if not self._devices.has_key(device): + return + self._devices[device].network_appeared(network) + + def wireless_network_disappeared_sig_handler(self, device, network): + if not self._devices.has_key(device): + return + self._devices[device].network_disappeared(network) + + def wireless_device_strength_changed_sig_handler(self, device, strength): + if not self._devices.has_key(device): + return + self._devices[device].set_strength(strength) + + def wireless_network_strength_changed_sig_handler(self, device, network, strength): + if not self._devices.has_key(device): + return + net = self._devices[device].get_network(network) + if net: + net.set_strength(strength) + + def device_carrier_on_sig_handler(self, device): + if not self._devices.has_key(device): + return + self._devices[device].set_carrier(True) + + def device_carrier_off_sig_handler(self, device): + if not self._devices.has_key(device): + return + self._devices[device].set_carrier(False) diff --git a/shell/hardware/nminfo.py b/shell/hardware/nminfo.py new file mode 100644 index 00000000..f512a8b8 --- /dev/null +++ b/shell/hardware/nminfo.py @@ -0,0 +1,467 @@ +# vi: ts=4 ai noet +# +# Copyright (C) 2006, Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# 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, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import dbus +import dbus.service +import time +import os +import binascii +import ConfigParser +import logging + +import nmclient +try: + from sugar import env +except ImportError: + pass + +NM_INFO_IFACE='org.freedesktop.NetworkManagerInfo' +NM_INFO_PATH='/org/freedesktop/NetworkManagerInfo' + + +class NoNetworks(dbus.DBusException): + def __init__(self): + dbus.DBusException.__init__(self) + self._dbus_error_name = NM_INFO_IFACE + '.NoNetworks' + +class CanceledKeyRequestError(dbus.DBusException): + def __init__(self): + dbus.DBusException.__init__(self) + self._dbus_error_name = NM_INFO_IFACE + '.CanceledError' + + +class NetworkInvalidError(Exception): + pass + + +class NMConfig(ConfigParser.ConfigParser): + def get_bool(self, section, name): + opt = self.get(section, name) + if type(opt) == type(""): + if opt.lower() == 'yes' or opt.lower() == 'true': + return True + elif opt.lower() == 'no' or opt.lower() == 'false': + return False + raise ValueError("Invalid format for %s/%s. Should be one of [yes, no, true, false]." % (section, name)) + + def get_list(self, section, name): + opt = self.get(section, name) + if type(opt) == type(""): + if not len(opt): + return [] + try: + return opt.split() + except Exception: + pass + raise ValueError("Invalid format for %s/%s. Should be a space-separate list." % (section, name)) + + def get_int(self, section, name): + opt = self.get(section, name) + try: + return int(opt) + except Exception: + pass + raise ValueError("Invalid format for %s/%s. Should be a valid integer." % (section, name)) + + def get_float(self, section, name): + opt = self.get(section, name) + try: + return float(opt) + except Exception: + pass + raise ValueError("Invalid format for %s/%s. Should be a valid float." % (section, name)) + + +IW_AUTH_CIPHER_NONE = 0x00000001 +IW_AUTH_CIPHER_WEP40 = 0x00000002 +IW_AUTH_CIPHER_TKIP = 0x00000004 +IW_AUTH_CIPHER_CCMP = 0x00000008 +IW_AUTH_CIPHER_WEP104 = 0x00000010 + +IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001 +IW_AUTH_ALG_SHARED_KEY = 0x00000002 + +NETWORK_TYPE_UNKNOWN = 0 +NETWORK_TYPE_ALLOWED = 1 +NETWORK_TYPE_INVALID = 2 + + +class Security(object): + def __init__(self, we_cipher): + self._we_cipher = we_cipher + + def read_from_config(self, cfg, name): + pass + + def read_from_args(self, args): + pass + + def new_from_config(cfg, name): + security = None + try: + we_cipher = cfg.get_int(name, "we_cipher") + if we_cipher == IW_AUTH_CIPHER_NONE: + security = Security(we_cipher) + elif we_cipher == IW_AUTH_CIPHER_WEP40 or we_cipher == IW_AUTH_CIPHER_WEP104: + security = WEPSecurity(we_cipher) + else: + # FIXME: find a way to make WPA config option matrix not + # make you want to throw up + raise ValueError("Unsupported security combo") + security.read_from_config(cfg, name) + except (ConfigParser.NoOptionError, ValueError), e: + return None + return security + new_from_config = staticmethod(new_from_config) + + def new_from_args(we_cipher, args): + security = None + try: + if we_cipher == IW_AUTH_CIPHER_NONE: + security = Security(we_cipher) + elif we_cipher == IW_AUTH_CIPHER_WEP40 or we_cipher == IW_AUTH_CIPHER_WEP104: + security = WEPSecurity(we_cipher) + else: + # FIXME: find a way to make WPA config option matrix not + # make you want to throw up + raise ValueError("Unsupported security combo") + security.read_from_args(args) + except ValueError, e: + logging.debug("Error reading security information: %s" % e) + del security + return None + return security + new_from_args = staticmethod(new_from_args) + + def get_properties(self): + return [dbus.Int32(self._we_cipher)] + + def write_to_config(self, section, config): + config.set(section, "we_cipher", self._we_cipher) + + +class WEPSecurity(Security): + def read_from_args(self, args): + if len(args) != 2: + raise ValueError("not enough arguments") + key = args[0] + auth_alg = args[1] + if isinstance(key, unicode): + key = key.encode() + if not isinstance(key, str): + raise ValueError("wrong argument type for key") + if not isinstance(auth_alg, int): + raise ValueError("wrong argument type for auth_alg") + self._key = key + self._auth_alg = auth_alg + + def read_from_config(self, cfg, name): + # Key should be a hex encoded string + self._key = cfg.get(name, "key") + if self._we_cipher == IW_AUTH_CIPHER_WEP40 and len(self._key) != 10: + raise ValueError("Key length not right for 40-bit WEP") + if self._we_cipher == IW_AUTH_CIPHER_WEP104 and len(self._key) != 26: + raise ValueError("Key length not right for 104-bit WEP") + + try: + a = binascii.a2b_hex(self._key) + except TypeError: + raise ValueError("Key was not a hexadecimal string.") + + self._auth_alg = cfg.get_int(name, "auth_alg") + if self._auth_alg != IW_AUTH_ALG_OPEN_SYSTEM and self._auth_alg != IW_AUTH_ALG_SHARED_KEY: + raise ValueError("Invalid authentication algorithm %d" % self._auth_alg) + + def get_properties(self): + args = Security.get_properties(self) + args.append(dbus.String(self._key)) + args.append(dbus.Int32(self._auth_alg)) + return args + + def write_to_config(self, section, config): + Security.write_to_config(self, section, config) + config.set(section, "key", self._key) + config.set(section, "auth_alg", self._auth_alg) + + +class Network: + def __init__(self, ssid): + self.ssid = ssid + self.timestamp = int(time.time()) + self.bssids = [] + self.we_cipher = 0 + self._security = None + + def get_properties(self): + bssid_list = dbus.Array([], signature="s") + for item in self.bssids: + bssid_list.append(dbus.String(item)) + args = [dbus.String(self.ssid), dbus.Int32(self.timestamp), dbus.Boolean(True), bssid_list] + args += self._security.get_properties() + return tuple(args) + + def get_security(self): + return self._security.get_properties() + + def set_security(self, security): + self._security = security + + def read_from_args(self, auto, bssid, we_cipher, args): + if auto == False: + self.timestamp = int(time.time()) + if not bssid in self.bssids: + self.bssids.append(bssid) + + self._security = Security.new_from_args(we_cipher, args) + if not self._security: + raise NetworkInvalidError("Invalid security information") + + def read_from_config(self, config): + try: + self.timestamp = config.get_int(self.ssid, "timestamp") + except (ConfigParser.NoOptionError, ValueError), e: + raise NetworkInvalidError(e) + + self._security = Security.new_from_config(config, self.ssid) + if not self._security: + raise NetworkInvalidError(e) + + # The following don't need to be present + try: + self.bssids = config.get_list(self.ssid, "bssids") + except (ConfigParser.NoOptionError, ValueError), e: + pass + + def write_to_config(self, config): + try: + config.add_section(self.ssid) + config.set(self.ssid, "timestamp", self.timestamp) + if len(self.bssids) > 0: + opt = " " + opt.join(self.bssids) + config.set(self.ssid, "bssids", opt) + self._security.write_to_config(self.ssid, config) + except Exception, e: + logging.debug("Error writing '%s': %s" % (self.ssid, e)) + + +class NotFoundError(dbus.DBusException): + pass +class UnsupportedError(dbus.DBusException): + pass + +class NMInfoDBusServiceHelper(dbus.service.Object): + def __init__(self, parent): + self._parent = parent + bus = dbus.SystemBus() + + # If NMI is already around, don't grab the NMI service + bus_object = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') + name = None + try: + name = bus_object.GetNameOwner("org.freedesktop.NetworkManagerInfo", \ + dbus_interface='org.freedesktop.DBus') + except dbus.DBusException: + pass + if name: + logging.debug("NMI service already owned by %s, won't claim it." % name) + raise RuntimeError + + bus_name = dbus.service.BusName(NM_INFO_IFACE, bus=bus) + dbus.service.Object.__init__(self, bus_name, NM_INFO_PATH) + + @dbus.service.method(NM_INFO_IFACE, in_signature='i', out_signature='as') + def getNetworks(self, net_type): + ssids = self._parent.get_networks(net_type) + if len(ssids) > 0: + return dbus.Array(ssids) + + raise NoNetworks() + + @dbus.service.method(NM_INFO_IFACE, in_signature='si', async_callbacks=('async_cb', 'async_err_cb')) + def getNetworkProperties(self, ssid, net_type, async_cb, async_err_cb): + self._parent.get_network_properties(ssid, net_type, async_cb, async_err_cb) + + @dbus.service.method(NM_INFO_IFACE) + def updateNetworkInfo(self, ssid, bauto, bssid, cipher, *args): + self._parent.update_network_info(ssid, bauto, bssid, cipher, args) + + @dbus.service.method(NM_INFO_IFACE, async_callbacks=('async_cb', 'async_err_cb')) + def getKeyForNetwork(self, dev_path, net_path, ssid, attempt, new_key, async_cb, async_err_cb): + self._parent.get_key_for_network(dev_path, net_path, ssid, + attempt, new_key, async_cb, async_err_cb) + + @dbus.service.method(NM_INFO_IFACE) + def cancelGetKeyForNetwork(self): + self._parent.cancel_get_key_for_network() + +class NMInfo(object): + def __init__(self, client): + try: + profile_path = env.get_profile_path() + except NameError: + home = os.path.expanduser("~") + profile_path = os.path.join(home, ".sugar", "default") + self._cfg_file = os.path.join(profile_path, "nm", "networks.cfg") + self._nmclient = client + self._allowed_networks = self._read_config() + self._dbus_helper = NMInfoDBusServiceHelper(self) + + def save_config(self): + self._write_config(self._allowed_networks) + + def _read_config(self): + if not os.path.exists(os.path.dirname(self._cfg_file)): + os.makedirs(os.path.dirname(self._cfg_file), 0755) + if not os.path.exists(self._cfg_file): + self._write_config({}) + return {} + + config = NMConfig() + config.read(self._cfg_file) + networks = {} + for name in config.sections(): + if not isinstance(name, unicode): + name = unicode(name) + net = Network(name) + try: + net.read_from_config(config) + networks[name] = net + except NetworkInvalidError, e: + logging.debug("Error: invalid stored network config: %s" % e) + del net + del config + return networks + + def _write_config(self, networks): + fp = open(self._cfg_file, 'w') + config = NMConfig() + for net in networks.values(): + net.write_to_config(config) + config.write(fp) + fp.close() + del config + + def get_networks(self, net_type): + if net_type != NETWORK_TYPE_ALLOWED: + raise ValueError("Bad network type") + nets = [] + for net in self._allowed_networks.values(): + nets.append(net.ssid) + logging.debug("Returning networks: %s" % nets) + return nets + + def get_network_properties(self, ssid, net_type, async_cb, async_err_cb): + if not isinstance(ssid, unicode): + async_err_cb(ValueError("Invalid arguments; ssid must be unicode.")) + if net_type != NETWORK_TYPE_ALLOWED: + async_err_cb(ValueError("Bad network type")) + if not self._allowed_networks.has_key(ssid): + async_err_cb(NotFoundError("Network '%s' not found." % ssid)) + network = self._allowed_networks[ssid] + props = network.get_properties() + + # DBus workaround: the normal method return handler wraps + # the returned arguments in a tuple and then converts that to a + # struct, but NetworkManager expects a plain list of arguments. + # It turns out that the async callback method return code _doesn't_ + # wrap the returned arguments in a tuple, so as a workaround use + # the async callback stuff here even though we're not doing it + # asynchronously. + async_cb(*props) + + def update_network_info(self, ssid, auto, bssid, we_cipher, args): + if not isinstance(ssid, unicode): + raise ValueError("Invalid arguments; ssid must be unicode.") + if self._allowed_networks.has_key(ssid): + del self._allowed_networks[ssid] + net = Network(ssid) + try: + net.read_from_args(auto, bssid, we_cipher, args) + logging.debug("Updated network information for '%s'." % ssid) + self._allowed_networks[ssid] = net + self.save_config() + except NetworkInvalidError, e: + logging.debug("Error updating network information: %s" % e) + del net + + def get_key_for_network(self, dev_op, net_op, ssid, attempt, new_key, async_cb, async_err_cb): + if not isinstance(ssid, unicode): + raise ValueError("Invalid arguments; ssid must be unicode.") + if self._allowed_networks.has_key(ssid) and not new_key: + # We've got the info already + net = self._allowed_networks[ssid] + async_cb(tuple(net.get_security())) + return + + # Otherwise, ask the user for it + net = None + dev = self._nmclient.get_device(dev_op) + if not dev: + async_err_cb(NotFoundError("Device was unknown.")) + return + + if dev.get_type() == nmclient.DEVICE_TYPE_802_3_ETHERNET: + # We don't support wired 802.1x yet... + async_err_cb(UnsupportedError("Device type is unsupported by NMI.")) + return + + net = dev.get_network(net_op) + if not net: + async_err_cb(NotFoundError("Network was unknown.")) + return + + self._nmclient.get_key_for_network(net, async_cb, async_err_cb) + + def get_key_for_network_cb(self, net, key, auth_alg, async_cb, async_err_cb, canceled=False): + """ + Called by the NMClient when the Wireless Network Key dialog + is closed. + """ + if canceled: + e = CanceledKeyRequestError("Request was canceled.") + # key dialog dialog was canceled; send the error back to NM + async_err_cb(e) + return + + if not key or not auth_alg: + # no key returned, *** BUG ***; the key dialog + # should always return either a key + auth_alg, or a + #cancel error + raise RuntimeError("No key or auth alg given! Bug!") + + we_cipher = None + if len(key) == 26: + we_cipher = IW_AUTH_CIPHER_WEP104 + elif len(key) == 10: + we_cipher = IW_AUTH_CIPHER_WEP40 + else: + raise RuntimeError("Invalid key length!") + + # Stuff the returned key and auth algorithm into a security object + # and return it to NetworkManager + sec = Security.new_from_args(we_cipher, (key, auth_alg)) + if not sec: + raise RuntimeError("Invalid security arguments.") + props = sec.get_properties() + a = tuple(props) + async_cb(*a) + + def cancel_get_key_for_network(self): + # Tell the NMClient to close the key request dialog + self._nmclient.cancel_get_key_for_network() diff --git a/shell/model/devices/Makefile.am b/shell/model/devices/Makefile.am index c987bb7b..f798c96c 100644 --- a/shell/model/devices/Makefile.am +++ b/shell/model/devices/Makefile.am @@ -4,4 +4,5 @@ sugar_PYTHON = \ device.py \ devicesmodel.py \ battery.py \ - network.py + wirednetwork.py \ + wirelessnetwork.py diff --git a/shell/model/devices/battery.py b/shell/model/devices/battery.py index 1d325ac8..3e8d434c 100644 --- a/shell/model/devices/battery.py +++ b/shell/model/devices/battery.py @@ -5,7 +5,7 @@ class Device(device.Device): device.Device.__init__(self) def get_type(self): - return 'network' + return 'battery' def get_level(self): return 0 diff --git a/shell/model/devices/devicesmodel.py b/shell/model/devices/devicesmodel.py index e5a06389..2eab979b 100644 --- a/shell/model/devices/devicesmodel.py +++ b/shell/model/devices/devicesmodel.py @@ -1,8 +1,10 @@ import gobject from model.devices import device -from model.devices import network +from model.devices import wirednetwork +from model.devices import wirelessnetwork from model.devices import battery +from hardware import hardwaremanager class DevicesModel(gobject.GObject): __gsignals__ = { @@ -18,12 +20,26 @@ class DevicesModel(gobject.GObject): gobject.GObject.__init__(self) self._devices = [] - - self.add_device(network.Device()) self.add_device(battery.Device()) + self._observe_network_manager() + + def _observe_network_manager(self): + network_manager = hardwaremanager.get_network_manager() + for device in network_manager.get_devices(): + self._check_network_device(device) + + def _check_network_device(self, device): + if not device.is_valid(): + return + + if device.get_type() == DEVICE_TYPE_802_11_WIRELESS: + if device.get_active(): + self._add_device(device) + def __iter__(self): return iter(self._devices) def add_device(self, device): self._devices.append(device) + self.emit('device-appeared', device) diff --git a/shell/model/devices/network.py b/shell/model/devices/wirednetwork.py similarity index 56% rename from shell/model/devices/network.py rename to shell/model/devices/wirednetwork.py index 1d325ac8..871a552f 100644 --- a/shell/model/devices/network.py +++ b/shell/model/devices/wirednetwork.py @@ -1,11 +1,9 @@ from model.devices import device class Device(device.Device): - def __init__(self): + def __init__(self, nm_device): device.Device.__init__(self) + self._nm_device = device def get_type(self): - return 'network' - - def get_level(self): - return 0 + return 'wirednetwork' diff --git a/shell/model/devices/wirelessnetwork.py b/shell/model/devices/wirelessnetwork.py new file mode 100644 index 00000000..6a53d341 --- /dev/null +++ b/shell/model/devices/wirelessnetwork.py @@ -0,0 +1,12 @@ +from model.devices import device + +class Device(device.Device): + def __init__(self, nm_device): + device.Device.__init__(self) + self._nm_device = device + + def get_type(self): + return 'wirelessnetwork' + + def get_level(self): + return self._nm_device.get_strength() diff --git a/shell/view/devices/Makefile.am b/shell/view/devices/Makefile.am index 54290e03..d48504da 100644 --- a/shell/view/devices/Makefile.am +++ b/shell/view/devices/Makefile.am @@ -3,4 +3,5 @@ sugar_PYTHON = \ __init__.py \ battery.py \ deviceview.py \ - network.py + wirednetwork.py \ + wirelessnetwork.py diff --git a/shell/view/devices/battery.py b/shell/view/devices/battery.py index 149e9b24..a13304e2 100644 --- a/shell/view/devices/battery.py +++ b/shell/view/devices/battery.py @@ -1,6 +1,6 @@ from view.devices import deviceview -class DeviceView(deviceview.DeviceView) +class DeviceView(deviceview.DeviceView): def __init__(self, model): deviceview.DeviceView.__init__(self, model) self.props.icon_name = 'theme:stock-close' diff --git a/shell/view/devices/network.py b/shell/view/devices/wirednetwork.py similarity index 74% rename from shell/view/devices/network.py rename to shell/view/devices/wirednetwork.py index a13304e2..c484b75c 100644 --- a/shell/view/devices/network.py +++ b/shell/view/devices/wirednetwork.py @@ -3,4 +3,4 @@ from view.devices import deviceview class DeviceView(deviceview.DeviceView): def __init__(self, model): deviceview.DeviceView.__init__(self, model) - self.props.icon_name = 'theme:stock-close' + self.props.icon_name = 'theme:stock-net-wired' diff --git a/shell/view/devices/wirelessnetwork.py b/shell/view/devices/wirelessnetwork.py new file mode 100644 index 00000000..659ec6b2 --- /dev/null +++ b/shell/view/devices/wirelessnetwork.py @@ -0,0 +1,6 @@ +from view.devices import deviceview + +class DeviceView(deviceview.DeviceView): + def __init__(self, model): + deviceview.DeviceView.__init__(self, model) + self.props.icon_name = 'theme:stock-net-wireless-00' From 6a4170a51e2be4f0f3d2ba45aac19819a9aee7f0 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 02:28:14 +0100 Subject: [PATCH 15/29] Get the wireless device to show. --- shell/hardware/nmclient.py | 22 +++++++++++++++++++--- shell/model/devices/devicesmodel.py | 13 ++++++++++--- shell/view/home/HomeBox.py | 15 ++++++++++++++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index 9a2c5a80..8bd29999 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -156,8 +156,6 @@ class Device(gobject.GObject): self._type = props[2] self._udi = props[3] self._active = props[4] - if self._active: - self.emit('activated') self._link = props[15] self._caps = props[17] @@ -170,6 +168,9 @@ class Device(gobject.GObject): self._valid = True + if self._active: + self.emit('activated') + def _update_networks(self, net_ops, active_op): for op in net_ops: net = Network(op) @@ -261,8 +262,19 @@ NM_STATE_CONNECTING = 2 NM_STATE_CONNECTED = 3 NM_STATE_DISCONNECTED = 4 -class NMClient(object): +class NMClient(gobject.GObject): + __gsignals__ = { + 'device-activated' : (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])), + 'device-removed' : (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])) + } + def __init__(self): + gobject.GObject.__init__(self) + self.nminfo = None self._nm_present = False self._nm_state = NM_STATE_UNKNOWN @@ -329,6 +341,8 @@ class NMClient(object): dev.disconnect('strength-changed') del self._devices[dev_op] + self.emit('device-removed', dev) + def _dev_activated_cb(self, dev): op = dev.get_op() if not self._devices.has_key(op): @@ -337,6 +351,8 @@ class NMClient(object): return self._active_device = op + self.emit('device-activated', dev) + def _dev_strength_changed_cb(self, dev, strength): op = dev.get_op() if not self._devices.has_key(op): diff --git a/shell/model/devices/devicesmodel.py b/shell/model/devices/devicesmodel.py index 2eab979b..01db8711 100644 --- a/shell/model/devices/devicesmodel.py +++ b/shell/model/devices/devicesmodel.py @@ -5,6 +5,7 @@ from model.devices import wirednetwork from model.devices import wirelessnetwork from model.devices import battery from hardware import hardwaremanager +from hardware import nmclient class DevicesModel(gobject.GObject): __gsignals__ = { @@ -26,16 +27,22 @@ class DevicesModel(gobject.GObject): def _observe_network_manager(self): network_manager = hardwaremanager.get_network_manager() + for device in network_manager.get_devices(): self._check_network_device(device) + network_manager.connect('device-activated', + self._network_device_added_cb) + + def _network_device_added_cb(self, network_manager, device): + self._check_network_device(device) + def _check_network_device(self, device): if not device.is_valid(): return - if device.get_type() == DEVICE_TYPE_802_11_WIRELESS: - if device.get_active(): - self._add_device(device) + if device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS: + self.add_device(wirelessnetwork.Device(device)) def __iter__(self): return iter(self._devices) diff --git a/shell/view/home/HomeBox.py b/shell/view/home/HomeBox.py index a7936cf6..4ab11409 100644 --- a/shell/view/home/HomeBox.py +++ b/shell/view/home/HomeBox.py @@ -46,14 +46,27 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem): self._shell_state_changed_cb) self._device_icons = [] - for device in shell_model.get_devices(): + + devices_model = shell_model.get_devices() + for device in devices_model: self._add_device(device) + devices_model.connect('device-appeared', + self._device_appeared_cb) + devices_model.connect('device-disappeared', + self._device_disappeared_cb) + def _add_device(self, device): view = deviceview.create(device) self.append(view, hippo.PACK_FIXED) self._device_icons.append(view) + def _device_appeared_cb(self, model, device): + self._add_device(device) + + def _device_disappeared_cb(self, model, device): + pass + def _shell_state_changed_cb(self, model, pspec): # FIXME handle all possible mode switches if model.props.state == ShellModel.STATE_SHUTDOWN: From 06e09236879b0fa12b102ebf570fd717000553e9 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 11:39:35 +0100 Subject: [PATCH 16/29] First go at access points on the mesh view --- shell/hardware/nmclient.py | 24 ++++++++++-- shell/model/MeshModel.py | 75 ++++++++++++++++++++++++++++++++------ shell/view/home/MeshBox.py | 34 +++++++++++++++++ 3 files changed, 118 insertions(+), 15 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index 8bd29999..b3b05c81 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -126,10 +126,19 @@ class Network(gobject.GObject): class Device(gobject.GObject): __gsignals__ = { - 'init-failed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), - 'activated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), - 'strength-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([gobject.TYPE_PYOBJECT])) + 'init-failed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])), + 'activated': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])), + 'strength-changed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])), + 'network-appeared': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])), + 'network-disappeared': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])) } def __init__(self, op): @@ -195,6 +204,9 @@ class Device(gobject.GObject): def get_op(self): return self._op + def get_networks(self): + return self._networks.values() + def get_network(self, op): if self._networks.has_key(op): return self._networks[op] @@ -223,12 +235,16 @@ class Device(gobject.GObject): net = Network(network) self._networks[network] = net net.connect('init-failed', self._net_init_failed) + self.emit('network-appeared', net) def network_disappeared(self, network): if not self._networks.has_key(network): return if network == self._active_net: self._active_net = None + + self.emit('network-disappeared', self._networks[network]) + del self._networks[network] def get_active(self): diff --git a/shell/model/MeshModel.py b/shell/model/MeshModel.py index bb3c223b..13dc1acd 100644 --- a/shell/model/MeshModel.py +++ b/shell/model/MeshModel.py @@ -20,6 +20,17 @@ from sugar.graphics.xocolor import XoColor from sugar.presence import PresenceService from sugar.activity import bundleregistry from model.BuddyModel import BuddyModel +from hardware import hardwaremanager + +class AccessPointModel: + def __init__(self, nm_network): + self._nm_network = nm_network + + def get_id(self): + return self._nm_network.get_op() + + def get_name(self): + return self._nm_network.get_ssid() class ActivityModel: def __init__(self, activity, bundle, service): @@ -41,17 +52,22 @@ class ActivityModel: class MeshModel(gobject.GObject): __gsignals__ = { - 'activity-added': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), - 'activity-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), - 'buddy-added': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), - 'buddy-moved': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT, - gobject.TYPE_PYOBJECT])), - 'buddy-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])) + 'activity-added': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), + 'activity-removed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), + 'buddy-added': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), + 'buddy-moved': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT, + gobject.TYPE_PYOBJECT])), + 'buddy-removed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), + 'access-point-added': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), + 'access-point-removed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])) } def __init__(self): @@ -59,6 +75,7 @@ class MeshModel(gobject.GObject): self._activities = {} self._buddies = {} + self._access_points = {} self._bundle_registry = bundleregistry.get_registry() self._pservice = PresenceService.get_instance() @@ -78,6 +95,42 @@ class MeshModel(gobject.GObject): for service in self._pservice.get_services(): self._check_service(service) + network_manager = hardwaremanager.get_network_manager() + for nm_device in network_manager.get_devices(): + self._add_network_device(nm_device) + network_manager.connect('device-activated', + self._nm_device_activated_cb) + + def _nm_device_activated_cb(self, manager, nm_device): + self._add_network_device(nm_device) + + def _nm_network_appeared_cb(self, manager, nm_network): + self._add_access_point(nm_network) + + def _nm_network_disappeared_cb(self, manager, nm_network): + self._remove_access_point(nm_network) + + def _add_network_device(self, nm_device): + for network in nm_device.get_networks(): + self._add_access_point(network) + nm_device.connect('network-appeared', + self._nm_network_appeared_cb) + nm_device.connect('network-disappeared', + self._nm_network_disappeared_cb) + + def _add_access_point(self, nm_network): + model = AccessPointModel(nm_network) + self._access_points[nm_network.get_op()] = model + self.emit('access-point-added', model) + + def _remove_access_point(self, nm_network): + self.emit('access-point-removed', + self._access_points[nm_network.get_op()]) + del self._access_points[nm_network.get_op()] + + def get_access_points(self): + return self._access_points.values() + def get_activities(self): return self._activities.values() diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index b8ff3eae..c4f447db 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -24,6 +24,14 @@ from sugar.graphics.snowflakebox import SnowflakeBox from sugar.graphics.canvasicon import CanvasIcon from view.BuddyIcon import BuddyIcon +class AccessPointView(CanvasIcon): + def __init__(self, model): + CanvasIcon.__init__(self) + self._update_icon() + + def _update_icon(self): + self.props.icon_name = 'theme:stock-net-wireless-00' + class ActivityView(SnowflakeBox): def __init__(self, shell, menu_shell, model): SnowflakeBox.__init__(self) @@ -63,6 +71,7 @@ class MeshBox(SpreadBox): self._model = shell.get_model().get_mesh() self._buddies = {} self._activities = {} + self._access_points = {} self._buddy_to_activity = {} for buddy_model in self._model.get_buddies(): @@ -78,6 +87,14 @@ class MeshBox(SpreadBox): self._model.connect('activity-added', self._activity_added_cb) self._model.connect('activity-removed', self._activity_removed_cb) + for ap_model in self._model.get_access_points(): + self._add_access_point(ap_model) + + self._model.connect('access-point-added', + self._access_point_added_cb) + self._model.connect('access-point-removed', + self._access_point_removed_cb) + def _buddy_added_cb(self, model, buddy_model): self._add_alone_buddy(buddy_model) @@ -93,6 +110,12 @@ class MeshBox(SpreadBox): def _activity_removed_cb(self, model, activity_model): self._remove_activity(activity_model) + def _access_point_added_cb(self, model, ap_model): + self._add_access_point(ap_model) + + def _access_point_removed_cb(self, model, ap_model): + self._add_access_point(ap_model) + def _add_alone_buddy(self, buddy_model): icon = BuddyIcon(self._shell, self._menu_shell, buddy_model) self.add_item(icon) @@ -136,3 +159,14 @@ class MeshBox(SpreadBox): icon = self._activities[activity_model.get_id()] self.remove_item(icon) del self._activities[activity_model.get_id()] + + def _add_access_point(self, ap_model): + icon = AccessPointView(ap_model) + self.add_item(icon) + + self._access_points[ap_model.get_id()] = icon + + def _remove_access_point(self, ap_model): + icon = self._access_points[ap_model.get_id()] + self.remove_item(icon) + del self._access_points[ap_model.get_id()] From 91722dfebc4d21bccf5591dbe211ddbe4ffd51ef Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 11:52:14 +0100 Subject: [PATCH 17/29] Add a tooltip with the ap name, not working for some reason --- shell/view/home/MeshBox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index c4f447db..39fd63a6 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -26,7 +26,7 @@ from view.BuddyIcon import BuddyIcon class AccessPointView(CanvasIcon): def __init__(self, model): - CanvasIcon.__init__(self) + CanvasIcon.__init__(self, tooltip=model.get_name()) self._update_icon() def _update_icon(self): From 38ac42d6650154659dd2f1c354c023f29f07de7d Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 12:17:45 +0100 Subject: [PATCH 18/29] Activate the network on click --- shell/hardware/nmclient.py | 15 +++++++++++++++ shell/model/MeshModel.py | 25 ++++++++++++++++--------- shell/view/home/MeshBox.py | 12 ++++++++++++ 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index b3b05c81..c98f1e2d 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -418,6 +418,21 @@ class NMClient(gobject.GObject): except dbus.DBusException: pass + def set_active_device(self, device, network): + net_op = "" + if network: + net_op = network.get_op() + try: + # NM 0.6.4 and earlier have a bug which returns an + # InvalidArguments error if no security information is passed + # for wireless networks + self._nm_obj.setActiveDevice(device.get_op(), network.get_ssid()) + except dbus.DBusException, e: + if str(e).find("invalid arguments"): + pass + else: + raise dbus.DBusException(e) + def get_key_for_network(self, net, async_cb, async_err_cb): pass diff --git a/shell/model/MeshModel.py b/shell/model/MeshModel.py index 13dc1acd..7c86bbc7 100644 --- a/shell/model/MeshModel.py +++ b/shell/model/MeshModel.py @@ -23,8 +23,9 @@ from model.BuddyModel import BuddyModel from hardware import hardwaremanager class AccessPointModel: - def __init__(self, nm_network): + def __init__(self, nm_device, nm_network): self._nm_network = nm_network + self._nm_device = nm_device def get_id(self): return self._nm_network.get_op() @@ -32,6 +33,12 @@ class AccessPointModel: def get_name(self): return self._nm_network.get_ssid() + def get_nm_device(self): + return self._nm_device + + def get_nm_network(self): + return self._nm_network + class ActivityModel: def __init__(self, activity, bundle, service): self._service = service @@ -104,22 +111,22 @@ class MeshModel(gobject.GObject): def _nm_device_activated_cb(self, manager, nm_device): self._add_network_device(nm_device) - def _nm_network_appeared_cb(self, manager, nm_network): - self._add_access_point(nm_network) + def _nm_network_appeared_cb(self, nm_device, nm_network): + self._add_access_point(nm_device, nm_network) - def _nm_network_disappeared_cb(self, manager, nm_network): - self._remove_access_point(nm_network) + def _nm_network_disappeared_cb(self, nm_device, nm_network): + self._remove_access_point(nm_device, nm_network) def _add_network_device(self, nm_device): - for network in nm_device.get_networks(): - self._add_access_point(network) + for nm_network in nm_device.get_networks(): + self._add_access_point(nm_device, nm_network) nm_device.connect('network-appeared', self._nm_network_appeared_cb) nm_device.connect('network-disappeared', self._nm_network_disappeared_cb) - def _add_access_point(self, nm_network): - model = AccessPointModel(nm_network) + def _add_access_point(self, nm_device, nm_network): + model = AccessPointModel(nm_device, nm_network) self._access_points[nm_network.get_op()] = model self.emit('access-point-added', model) diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index 39fd63a6..55d8cce1 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -22,13 +22,25 @@ import gobject from sugar.graphics.spreadbox import SpreadBox from sugar.graphics.snowflakebox import SnowflakeBox from sugar.graphics.canvasicon import CanvasIcon +from hardware import hardwaremanager from view.BuddyIcon import BuddyIcon class AccessPointView(CanvasIcon): def __init__(self, model): CanvasIcon.__init__(self, tooltip=model.get_name()) + self._model = model + + self.connect('activated', self._activate_cb) self._update_icon() + def _activate_cb(self, icon): + network_manager = hardwaremanager.get_network_manager() + + device = self._model.get_nm_device() + network = self._model.get_nm_network() + + network_manager.set_active_device(device, network) + def _update_icon(self): self.props.icon_name = 'theme:stock-net-wireless-00' From 7c135804bc53708a23c808640145e37ae3b22f6b Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 12:36:44 +0100 Subject: [PATCH 19/29] Handle device removal --- shell/hardware/nmclient.py | 4 +++ shell/model/devices/devicesmodel.py | 45 +++++++++++++++++++------- shell/model/devices/wirednetwork.py | 3 ++ shell/model/devices/wirelessnetwork.py | 5 ++- shell/view/home/HomeBox.py | 12 ++++--- 5 files changed, 53 insertions(+), 16 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index c98f1e2d..acbac920 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -130,6 +130,8 @@ class Device(gobject.GObject): gobject.TYPE_NONE, ([])), 'activated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), + 'deactivated': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])), 'strength-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), @@ -179,6 +181,8 @@ class Device(gobject.GObject): if self._active: self.emit('activated') + else: + self.emit('deactivated') def _update_networks(self, net_ops, active_op): for op in net_ops: diff --git a/shell/model/devices/devicesmodel.py b/shell/model/devices/devicesmodel.py index 01db8711..dd535961 100644 --- a/shell/model/devices/devicesmodel.py +++ b/shell/model/devices/devicesmodel.py @@ -20,7 +20,7 @@ class DevicesModel(gobject.GObject): def __init__(self): gobject.GObject.__init__(self) - self._devices = [] + self._devices = {} self.add_device(battery.Device()) self._observe_network_manager() @@ -32,21 +32,44 @@ class DevicesModel(gobject.GObject): self._check_network_device(device) network_manager.connect('device-activated', - self._network_device_added_cb) + self._network_device_activated_cb) + network_manager.connect('device-removed', + self._network_device_removed_cb) - def _network_device_added_cb(self, network_manager, device): - self._check_network_device(device) + def _network_device_activated_cb(self, network_manager, nm_device): + self._check_network_device(nm_device) - def _check_network_device(self, device): - if not device.is_valid(): + def _network_device_removed_cb(self, nm_device): + self._remove_network_device(nm_device) + + def _network_device_deactivated_cb(self, nm_device): + self._remove_network_device(nm_device) + + def _check_network_device(self, nm_device): + if not nm_device.is_valid(): return - if device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS: - self.add_device(wirelessnetwork.Device(device)) - + if nm_device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS: + self._add_network_device(nm_device) + + def _get_network_device(self, nm_device): + return self._devices[nm_device.get_op()] + + def _add_network_device(self, nm_device): + self.add_device(wirelessnetwork.Device(nm_device)) + nm_device.connect('deactivated', + self._network_device_deactivated_cb) + + def _remove_network_device(self, nm_device): + self.remove_device(self._get_network_device(nm_device)) + def __iter__(self): - return iter(self._devices) + return iter(self._devices.values()) def add_device(self, device): - self._devices.append(device) + self._devices[device.get_id()] = device self.emit('device-appeared', device) + + def remove_device(self, device): + self.emit('device-disappeared', self._devices[device.get_id()]) + del self._devices[device.get_id()] diff --git a/shell/model/devices/wirednetwork.py b/shell/model/devices/wirednetwork.py index 871a552f..5ea0bb69 100644 --- a/shell/model/devices/wirednetwork.py +++ b/shell/model/devices/wirednetwork.py @@ -5,5 +5,8 @@ class Device(device.Device): device.Device.__init__(self) self._nm_device = device + def get_id(self): + return self._nm_device.get_op() + def get_type(self): return 'wirednetwork' diff --git a/shell/model/devices/wirelessnetwork.py b/shell/model/devices/wirelessnetwork.py index 6a53d341..97f16cd5 100644 --- a/shell/model/devices/wirelessnetwork.py +++ b/shell/model/devices/wirelessnetwork.py @@ -3,10 +3,13 @@ from model.devices import device class Device(device.Device): def __init__(self, nm_device): device.Device.__init__(self) - self._nm_device = device + self._nm_device = nm_device def get_type(self): return 'wirelessnetwork' + def get_id(self): + return self._nm_device.get_op() + def get_level(self): return self._nm_device.get_strength() diff --git a/shell/view/home/HomeBox.py b/shell/view/home/HomeBox.py index 4ab11409..e2483d27 100644 --- a/shell/view/home/HomeBox.py +++ b/shell/view/home/HomeBox.py @@ -45,7 +45,7 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem): shell_model.connect('notify::state', self._shell_state_changed_cb) - self._device_icons = [] + self._device_icons = {} devices_model = shell_model.get_devices() for device in devices_model: @@ -59,13 +59,17 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem): def _add_device(self, device): view = deviceview.create(device) self.append(view, hippo.PACK_FIXED) - self._device_icons.append(view) + self._device_icons[device.get_id()] = view + + def _remove_device(self, device): + self.remove(self._device_icons[device.get_id()]) + del self._device_icons[device.get_id()] def _device_appeared_cb(self, model, device): self._add_device(device) def _device_disappeared_cb(self, model, device): - pass + self._remove_device(device) def _shell_state_changed_cb(self, model, pspec): # FIXME handle all possible mode switches @@ -87,7 +91,7 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem): (height - icon_height) / 2) i = 0 - for icon in self._device_icons: + for icon in self._device_icons.values(): angle = 2 * math.pi / len(self._device_icons) * i + math.pi / 2 radius = units.grid_to_pixels(5) From c0c753d169fce161355bdbc5f67aad771782d8b1 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 12:44:54 +0100 Subject: [PATCH 20/29] Add back wep key dialog --- shell/hardware/Makefile.am | 3 +- shell/hardware/nmclient.py | 50 ++++++++++++++++++++- shell/hardware/wepkeydialog.py | 81 ++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 shell/hardware/wepkeydialog.py diff --git a/shell/hardware/Makefile.am b/shell/hardware/Makefile.am index da992764..9414f860 100644 --- a/shell/hardware/Makefile.am +++ b/shell/hardware/Makefile.am @@ -3,4 +3,5 @@ sugar_PYTHON = \ __init__.py \ hardwaremanager.py \ nmclient.py \ - nminfo.py + nminfo.py \ + wepkeydialog.py diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index acbac920..90a21258 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -22,7 +22,9 @@ import dbus import dbus.glib import dbus.decorators import gobject +import gtk +from hardware.wepkeydialog import WEPKeyDialog from hardware import nminfo IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001 @@ -438,7 +440,53 @@ class NMClient(gobject.GObject): raise dbus.DBusException(e) def get_key_for_network(self, net, async_cb, async_err_cb): - pass + # Throw up a dialog asking for the key here, and set + # the authentication algorithm to the given one, if any + # + # Key needs to be limited to _either_ 10 or 26 digits long, + # and contain _only_ _hex_ digits, 0-9 or a-f + # + # Auth algorithm should be a dropdown of: [Open System, Shared Key], + # mapping to the values [IW_AUTH_ALG_OPEN_SYSTEM, IW_AUTH_ALG_SHARED_KEY] + # above + + self._key_dialog = WEPKeyDialog(net, async_cb, async_err_cb) + self._key_dialog.connect("response", self._key_dialog_response_cb) + self._key_dialog.connect("destroy", self._key_dialog_destroy_cb) + self._key_dialog.show_all() + + def _key_dialog_destroy_cb(self, widget, foo=None): + if widget != self._key_dialog: + return + self._key_dialog_response_cb(widget, gtk.RESPONSE_CANCEL) + + def _key_dialog_response_cb(self, widget, response_id): + if widget != self._key_dialog: + return + key = self._key_dialog.get_key() + wep_auth_alg = self._key_dialog.get_auth_alg() + net = self._key_dialog.get_network() + (async_cb, async_err_cb) = self._key_dialog.get_callbacks() + + # Clear self._key_dialog before we call destroy(), otherwise + # the destroy will trigger and we'll get called again by + # self._key_dialog_destroy_cb + self._key_dialog = None + widget.destroy() + + if response_id == gtk.RESPONSE_OK: + self.nminfo.get_key_for_network_cb( + net, key, wep_auth_alg, async_cb, async_err_cb, canceled=False) + else: + self.nminfo.get_key_for_network_cb( + net, None, None, async_cb, async_err_cb, canceled=True) + + def cancel_get_key_for_network(self): + # Close the wireless key dialog and just have it return + # with the 'canceled' argument set to true + if not self._key_dialog: + return + self._key_dialog_destroy_cb(self._key_dialog) def device_activation_stage_sig_handler(self, device, stage): logging.debug('Device Activation Stage "%s" for device %s' % (NM_DEVICE_STAGE_STRINGS[stage], device)) diff --git a/shell/hardware/wepkeydialog.py b/shell/hardware/wepkeydialog.py new file mode 100644 index 00000000..13c7908b --- /dev/null +++ b/shell/hardware/wepkeydialog.py @@ -0,0 +1,81 @@ +# vi: ts=4 ai noet +# +# Copyright (C) 2006, Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# 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, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import gtk + +IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001 +IW_AUTH_ALG_SHARED_KEY = 0x00000002 + +class WEPKeyDialog(gtk.Dialog): + def __init__(self, net, async_cb, async_err_cb): + gtk.Dialog.__init__(self) + self.set_title("Wireless Key Required") + + self._net = net + self._async_cb = async_cb + self._async_err_cb = async_err_cb + + self.set_has_separator(False) + + label = gtk.Label("A wireless encryption key is required for\n" \ + " the wireless network '%s'." % net.get_ssid()) + self.vbox.pack_start(label) + + self._entry = gtk.Entry() + self._entry.props.visibility = False + self._entry.connect('changed', self._entry_changed_cb) + self.vbox.pack_start(self._entry) + self.vbox.show_all() + + self.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OK, gtk.RESPONSE_OK) + + self.set_default_response(gtk.RESPONSE_OK) + self._update_response_sensitivity() + + def get_key(self): + return self._entry.get_text() + + def get_auth_alg(self): + return IW_AUTH_ALG_OPEN_SYSTEM + + def get_network(self): + return self._net + + def get_callbacks(self): + return (self._async_cb, self._async_err_cb) + + def _entry_changed_cb(self, entry): + self._update_response_sensitivity() + + def _update_response_sensitivity(self): + key = self.get_key() + + is_hex = True + for c in key: + if not 'a' <= c <= 'f' and not '0' <= c <= '9': + is_hex = False + + valid_len = (len(key) == 10 or len(key) == 26) + self.set_response_sensitive(gtk.RESPONSE_OK, is_hex and valid_len) + +if __name__ == "__main__": + dialog = WEPKeyDialog() + dialog.run() + + print dialog.get_key() From 81e2e9ed8db11aff7daab714b7328b099cc73d8a Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 13:40:24 +0100 Subject: [PATCH 21/29] Get rid of the old nm applet --- configure.ac | 1 - lib/python/_sugar.defs | 61 -- lib/python/_sugar.override | 4 - lib/src/Makefile.am | 2 - lib/src/sugar-tray-manager.c | 908 -------------------------- lib/src/sugar-tray-manager.h | 98 --- services/Makefile.am | 2 +- services/nm/Makefile.am | 15 - services/nm/NetworkManagerInfo.conf | 26 - services/nm/__init__.py | 0 services/nm/bubble.py | 132 ---- services/nm/nmclient.py | 917 --------------------------- services/nm/nminfo.py | 467 -------------- services/nm/style.py | 59 -- services/nm/sugar-nm-applet | 38 -- services/nm/wepkeydialog.py | 81 --- shell/sugar-shell | 6 - shell/view/frame/Makefile.am | 1 - shell/view/frame/frame.py | 11 - shell/view/frame/notificationtray.py | 18 - 20 files changed, 1 insertion(+), 2846 deletions(-) delete mode 100644 lib/src/sugar-tray-manager.c delete mode 100644 lib/src/sugar-tray-manager.h delete mode 100644 services/nm/Makefile.am delete mode 100644 services/nm/NetworkManagerInfo.conf delete mode 100644 services/nm/__init__.py delete mode 100644 services/nm/bubble.py delete mode 100644 services/nm/nmclient.py delete mode 100644 services/nm/nminfo.py delete mode 100644 services/nm/style.py delete mode 100644 services/nm/sugar-nm-applet delete mode 100644 services/nm/wepkeydialog.py delete mode 100644 shell/view/frame/notificationtray.py diff --git a/configure.ac b/configure.ac index 59408908..6eebdfea 100644 --- a/configure.ac +++ b/configure.ac @@ -112,7 +112,6 @@ lib/threadframe/Makefile services/Makefile services/presence/Makefile services/presence2/Makefile -services/nm/Makefile services/clipboard/Makefile services/datastore/Makefile shell/Makefile diff --git a/lib/python/_sugar.defs b/lib/python/_sugar.defs index 2963628f..add3b8fe 100644 --- a/lib/python/_sugar.defs +++ b/lib/python/_sugar.defs @@ -21,13 +21,6 @@ (gtype-id "SUGAR_TYPE_KEY_GRABBER") ) -(define-object TrayManager - (in-module "Sugar") - (parent "GObject") - (c-name "SugarTrayManager") - (gtype-id "SUGAR_TYPE_TRAY_MANAGER") -) - (define-object PushScroller (in-module "Sugar") (parent "GObject") @@ -124,60 +117,6 @@ ) ) -;; From sugar-tray-manager.h - -(define-function tray_manager_get_type - (c-name "sugar_tray_manager_get_type") - (return-type "GType") -) - -(define-function tray_manager_check_running - (c-name "sugar_tray_manager_check_running") - (return-type "gboolean") - (parameters - '("GdkScreen*" "screen") - ) -) - -(define-function tray_manager_new - (c-name "sugar_tray_manager_new") - (is-constructor-of "SugarTrayManager") - (return-type "SugarTrayManager*") -) - -(define-method manage_screen - (of-object "SugarTrayManager") - (c-name "sugar_tray_manager_manage_screen") - (return-type "gboolean") - (parameters - '("GdkScreen*" "screen") - ) -) - -(define-method get_child_title - (of-object "SugarTrayManager") - (c-name "sugar_tray_manager_get_child_title") - (return-type "char*") - (parameters - '("SugarTrayManagerChild*" "child") - ) -) - -(define-method set_orientation - (of-object "SugarTrayManager") - (c-name "sugar_tray_manager_set_orientation") - (return-type "none") - (parameters - '("GtkOrientation" "orientation") - ) -) - -(define-method get_orientation - (of-object "SugarTrayManager") - (c-name "sugar_tray_manager_get_orientation") - (return-type "GtkOrientation") -) - ;; From sugar-push-scroller.h (define-function push_scroller_get_type diff --git a/lib/python/_sugar.override b/lib/python/_sugar.override index 6f80b7b5..3c035808 100644 --- a/lib/python/_sugar.override +++ b/lib/python/_sugar.override @@ -7,7 +7,6 @@ headers #include "sugar-browser.h" #include "sugar-key-grabber.h" #include "sugar-address-entry.h" -#include "sugar-tray-manager.h" #include "sugar-push-scroller.h" #include "sugar-download-manager.h" #include "sugar-download.h" @@ -22,9 +21,6 @@ extern Pycairo_CAPI_t *Pycairo_CAPI; %% modulename gecko %% -ignore -sugar_tray_manager_new -%% import gobject.GObject as PyGObject_Type import gtk.Entry as PyGtkEntry_Type import gtk.gdk.Screen as PyGdkScreen_Type diff --git a/lib/src/Makefile.am b/lib/src/Makefile.am index 837d72ca..56e1cc4d 100644 --- a/lib/src/Makefile.am +++ b/lib/src/Makefile.am @@ -44,8 +44,6 @@ libsugarprivate_la_SOURCES = \ sugar-key-grabber.c \ sugar-push-scroller.c \ sugar-push-scroller.h \ - sugar-tray-manager.c \ - sugar-tray-manager.h \ sugar-utils.c \ sugar-utils.h diff --git a/lib/src/sugar-tray-manager.c b/lib/src/sugar-tray-manager.c deleted file mode 100644 index 7f12fc99..00000000 --- a/lib/src/sugar-tray-manager.c +++ /dev/null @@ -1,908 +0,0 @@ -/* na-tray-manager.c - * Copyright (C) 2002 Anders Carlsson - * Copyright (C) 2003-2006 Vincent Untz - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Used to be: eggtraymanager.c - */ - -#include -#include -#include - -#include "sugar-tray-manager.h" - -#include -#include -#if defined (GDK_WINDOWING_X11) -#include -#include -#elif defined (GDK_WINDOWING_WIN32) -#include -#endif -#include -#include -#include - -#include "sugar-marshal.h" - -/* Signals */ -enum -{ - TRAY_ICON_ADDED, - TRAY_ICON_REMOVED, - MESSAGE_SENT, - MESSAGE_CANCELLED, - LOST_SELECTION, - LAST_SIGNAL -}; - -enum { - PROP_0, - PROP_ORIENTATION -}; - -typedef struct -{ - long id, len; - long remaining_len; - - long timeout; - char *str; -#ifdef GDK_WINDOWING_X11 - Window window; -#endif -} PendingMessage; - -static guint manager_signals[LAST_SIGNAL] = { 0 }; - -#define SYSTEM_TRAY_REQUEST_DOCK 0 -#define SYSTEM_TRAY_BEGIN_MESSAGE 1 -#define SYSTEM_TRAY_CANCEL_MESSAGE 2 - -#define SYSTEM_TRAY_ORIENTATION_HORZ 0 -#define SYSTEM_TRAY_ORIENTATION_VERT 1 - -#ifdef GDK_WINDOWING_X11 -static gboolean sugar_tray_manager_check_running_screen_x11 (GdkScreen *screen); -#endif - -static void sugar_tray_manager_finalize (GObject *object); -static void sugar_tray_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void sugar_tray_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static void sugar_tray_manager_unmanage (SugarTrayManager *manager); - -G_DEFINE_TYPE (SugarTrayManager, sugar_tray_manager, G_TYPE_OBJECT) - -static void -sugar_tray_manager_init (SugarTrayManager *manager) -{ - manager->invisible = NULL; - manager->socket_table = g_hash_table_new (NULL, NULL); -} - -static void -sugar_tray_manager_class_init (SugarTrayManagerClass *klass) -{ - GObjectClass *gobject_class; - - gobject_class = (GObjectClass *)klass; - - gobject_class->finalize = sugar_tray_manager_finalize; - gobject_class->set_property = sugar_tray_manager_set_property; - gobject_class->get_property = sugar_tray_manager_get_property; - - g_object_class_install_property (gobject_class, - PROP_ORIENTATION, - g_param_spec_enum ("orientation", - _("Orientation"), - _("The orientation of the tray."), - GTK_TYPE_ORIENTATION, - GTK_ORIENTATION_HORIZONTAL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - manager_signals[TRAY_ICON_ADDED] = - g_signal_new ("tray_icon_added", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (SugarTrayManagerClass, tray_icon_added), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - GTK_TYPE_SOCKET); - - manager_signals[TRAY_ICON_REMOVED] = - g_signal_new ("tray_icon_removed", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (SugarTrayManagerClass, tray_icon_removed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - GTK_TYPE_SOCKET); - manager_signals[MESSAGE_SENT] = - g_signal_new ("message_sent", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (SugarTrayManagerClass, message_sent), - NULL, NULL, - sugar_marshal_VOID__OBJECT_STRING_LONG_LONG, - G_TYPE_NONE, 4, - GTK_TYPE_SOCKET, - G_TYPE_STRING, - G_TYPE_LONG, - G_TYPE_LONG); - manager_signals[MESSAGE_CANCELLED] = - g_signal_new ("message_cancelled", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (SugarTrayManagerClass, message_cancelled), - NULL, NULL, - sugar_marshal_VOID__OBJECT_LONG, - G_TYPE_NONE, 2, - GTK_TYPE_SOCKET, - G_TYPE_LONG); - manager_signals[LOST_SELECTION] = - g_signal_new ("lost_selection", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (SugarTrayManagerClass, lost_selection), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - -#if defined (GDK_WINDOWING_X11) - /* Nothing */ -#elif defined (GDK_WINDOWING_WIN32) - g_warning ("Port SugarTrayManager to Win32"); -#else - g_warning ("Port SugarTrayManager to this GTK+ backend"); -#endif -} - -static void -sugar_tray_manager_finalize (GObject *object) -{ - SugarTrayManager *manager; - - manager = SUGAR_TRAY_MANAGER (object); - - sugar_tray_manager_unmanage (manager); - - g_list_free (manager->messages); - g_hash_table_destroy (manager->socket_table); - - G_OBJECT_CLASS (sugar_tray_manager_parent_class)->finalize (object); -} - -static void -sugar_tray_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SugarTrayManager *manager = SUGAR_TRAY_MANAGER (object); - - switch (prop_id) - { - case PROP_ORIENTATION: - sugar_tray_manager_set_orientation (manager, g_value_get_enum (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -sugar_tray_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SugarTrayManager *manager = SUGAR_TRAY_MANAGER (object); - - switch (prop_id) - { - case PROP_ORIENTATION: - g_value_set_enum (value, manager->orientation); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -SugarTrayManager * -sugar_tray_manager_new (void) -{ - SugarTrayManager *manager; - - manager = g_object_new (SUGAR_TYPE_TRAY_MANAGER, NULL); - - return manager; -} - -#ifdef GDK_WINDOWING_X11 - -static gboolean -sugar_tray_manager_plug_removed (GtkSocket *socket, - SugarTrayManager *manager) -{ - Window *window; - - window = g_object_get_data (G_OBJECT (socket), "na-tray-child-window"); - - g_hash_table_remove (manager->socket_table, GINT_TO_POINTER (*window)); - g_object_set_data (G_OBJECT (socket), "na-tray-child-window", - NULL); - - g_signal_emit (manager, manager_signals[TRAY_ICON_REMOVED], 0, socket); - - /* This destroys the socket. */ - return FALSE; -} - -static void -sugar_tray_manager_make_socket_transparent (GtkWidget *widget, - gpointer user_data) -{ - if (GTK_WIDGET_NO_WINDOW (widget)) - return; - - gdk_window_set_back_pixmap (widget->window, NULL, TRUE); -} - -static gboolean -sugar_tray_manager_socket_exposed (GtkWidget *widget, - GdkEventExpose *event, - gpointer user_data) -{ - gdk_window_clear_area (widget->window, - event->area.x, event->area.y, - event->area.width, event->area.height); - return FALSE; -} - -static void -sugar_tray_manager_socket_style_set (GtkWidget *widget, - GtkStyle *previous_style, - gpointer user_data) -{ - if (widget->window == NULL) - return; - - sugar_tray_manager_make_socket_transparent (widget, user_data); -} - -static void -sugar_tray_manager_handle_dock_request (SugarTrayManager *manager, - XClientMessageEvent *xevent) -{ - GtkWidget *socket; - Window *window; - GtkRequisition req; - - if (g_hash_table_lookup (manager->socket_table, GINT_TO_POINTER (xevent->data.l[2]))) - { - /* We already got this notification earlier, ignore this one */ - return; - } - - socket = gtk_socket_new (); - - gtk_widget_set_app_paintable (socket, TRUE); - //FIXME: need to find a theme where this (and expose event) is needed - gtk_widget_set_double_buffered (socket, FALSE); - -/* FIXME Disabled this so that I can customize the icons background in theme. - I couldn't find a way to set a specific color for the GtkPlug. - g_signal_connect (socket, "realize", - G_CALLBACK (sugar_tray_manager_make_socket_transparent), NULL); -*/ - - g_signal_connect (socket, "expose_event", - G_CALLBACK (sugar_tray_manager_socket_exposed), NULL); - g_signal_connect_after (socket, "style_set", - G_CALLBACK (sugar_tray_manager_socket_style_set), NULL); - - /* We need to set the child window here - * so that the client can call _get functions - * in the signal handler - */ - window = g_new (Window, 1); - *window = xevent->data.l[2]; - - g_object_set_data_full (G_OBJECT (socket), - "na-tray-child-window", - window, g_free); - g_signal_emit (manager, manager_signals[TRAY_ICON_ADDED], 0, - socket); - - /* Add the socket only if it's been attached */ - if (GTK_IS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (socket)))) - { - g_signal_connect (socket, "plug_removed", - G_CALLBACK (sugar_tray_manager_plug_removed), manager); - - gtk_socket_add_id (GTK_SOCKET (socket), *window); - - g_hash_table_insert (manager->socket_table, GINT_TO_POINTER (*window), socket); - - /* - * Make sure the icons have a meaningfull size ... - */ - req.width = req.height = 1; - gtk_widget_size_request (socket, &req); - /* - if ((req.width < 16) || (req.height < 16)) - { - gint nw = MAX (24, req.width); - gint nh = MAX (24, req.height); - g_warning (_("tray icon has requested a size of (%i x %i), resizing to (%i x %i)"), - req.width, req.height, nw, nh); - gtk_widget_set_size_request(icon, nw, nh); - } - */ - gtk_widget_show(socket); - } - else - gtk_widget_destroy (socket); -} - -static void -pending_message_free (PendingMessage *message) -{ - g_free (message->str); - g_free (message); -} - -static GdkFilterReturn -sugar_tray_manager_handle_client_message_message_data (GdkXEvent *xev, - GdkEvent *event, - gpointer data) -{ - XClientMessageEvent *xevent; - SugarTrayManager *manager; - GList *p; - int len; - - xevent = (XClientMessageEvent *) xev; - manager = data; - - /* Try to see if we can find the pending message in the list */ - for (p = manager->messages; p; p = p->next) - { - PendingMessage *msg = p->data; - - if (xevent->window == msg->window) - { - /* Append the message */ - len = MIN (msg->remaining_len, 20); - - memcpy ((msg->str + msg->len - msg->remaining_len), - &xevent->data, len); - msg->remaining_len -= len; - - if (msg->remaining_len == 0) - { - GtkSocket *socket; - - socket = g_hash_table_lookup (manager->socket_table, - GINT_TO_POINTER (msg->window)); - - if (socket) - g_signal_emit (manager, manager_signals[MESSAGE_SENT], 0, - socket, msg->str, msg->id, msg->timeout); - - pending_message_free (msg); - manager->messages = g_list_remove_link (manager->messages, p); - g_list_free_1 (p); - } - - break; - } - } - - return GDK_FILTER_REMOVE; -} - -static void -sugar_tray_manager_handle_begin_message (SugarTrayManager *manager, - XClientMessageEvent *xevent) -{ - GtkSocket *socket; - GList *p; - PendingMessage *msg; - long timeout; - long len; - long id; - - socket = g_hash_table_lookup (manager->socket_table, - GINT_TO_POINTER (xevent->window)); - /* we don't know about this tray icon, so ignore the message */ - if (!socket) - return; - - /* Check if the same message is already in the queue and remove it if so */ - for (p = manager->messages; p; p = p->next) - { - PendingMessage *msg = p->data; - - if (xevent->window == msg->window && - xevent->data.l[4] == msg->id) - { - /* Hmm, we found it, now remove it */ - pending_message_free (msg); - manager->messages = g_list_remove_link (manager->messages, p); - g_list_free_1 (p); - break; - } - } - - timeout = xevent->data.l[2]; - len = xevent->data.l[3]; - id = xevent->data.l[4]; - - if (len == 0) - { - g_signal_emit (manager, manager_signals[MESSAGE_SENT], 0, - socket, "", id, timeout); - } - else - { - /* Now add the new message to the queue */ - msg = g_new0 (PendingMessage, 1); - msg->window = xevent->window; - msg->timeout = timeout; - msg->len = len; - msg->id = id; - msg->remaining_len = msg->len; - msg->str = g_malloc (msg->len + 1); - msg->str[msg->len] = '\0'; - manager->messages = g_list_prepend (manager->messages, msg); - } -} - -static void -sugar_tray_manager_handle_cancel_message (SugarTrayManager *manager, - XClientMessageEvent *xevent) -{ - GList *p; - GtkSocket *socket; - - /* Check if the message is in the queue and remove it if so */ - for (p = manager->messages; p; p = p->next) - { - PendingMessage *msg = p->data; - - if (xevent->window == msg->window && - xevent->data.l[4] == msg->id) - { - pending_message_free (msg); - manager->messages = g_list_remove_link (manager->messages, p); - g_list_free_1 (p); - break; - } - } - - socket = g_hash_table_lookup (manager->socket_table, - GINT_TO_POINTER (xevent->window)); - - if (socket) - { - g_signal_emit (manager, manager_signals[MESSAGE_CANCELLED], 0, - socket, xevent->data.l[2]); - } -} - -static GdkFilterReturn -sugar_tray_manager_handle_client_message_opcode (GdkXEvent *xev, - GdkEvent *event, - gpointer data) -{ - XClientMessageEvent *xevent; - SugarTrayManager *manager; - - xevent = (XClientMessageEvent *) xev; - manager = data; - - switch (xevent->data.l[1]) - { - case SYSTEM_TRAY_REQUEST_DOCK: - /* Ignore this one since we don't know on which window this was received - * and so we can't know for which screen this is. It will be handled - * in sugar_tray_manager_window_filter() since we also receive it there */ - break; - - case SYSTEM_TRAY_BEGIN_MESSAGE: - sugar_tray_manager_handle_begin_message (manager, xevent); - return GDK_FILTER_REMOVE; - - case SYSTEM_TRAY_CANCEL_MESSAGE: - sugar_tray_manager_handle_cancel_message (manager, xevent); - return GDK_FILTER_REMOVE; - default: - break; - } - - return GDK_FILTER_CONTINUE; -} - -static GdkFilterReturn -sugar_tray_manager_window_filter (GdkXEvent *xev, - GdkEvent *event, - gpointer data) -{ - XEvent *xevent = (GdkXEvent *)xev; - SugarTrayManager *manager = data; - - if (xevent->type == ClientMessage) - { - /* We handle this client message here. See comment in - * sugar_tray_manager_handle_client_message_opcode() for details */ - if (xevent->xclient.message_type == manager->opcode_atom && - xevent->xclient.data.l[1] == SYSTEM_TRAY_REQUEST_DOCK) - { - sugar_tray_manager_handle_dock_request (manager, - (XClientMessageEvent *) xevent); - return GDK_FILTER_REMOVE; - } - } - else if (xevent->type == SelectionClear) - { - g_signal_emit (manager, manager_signals[LOST_SELECTION], 0); - sugar_tray_manager_unmanage (manager); - } - - return GDK_FILTER_CONTINUE; -} - -#if 0 -//FIXME investigate why this doesn't work -static gboolean -sugar_tray_manager_selection_clear_event (GtkWidget *widget, - GdkEventSelection *event, - SugarTrayManager *manager) -{ - g_signal_emit (manager, manager_signals[LOST_SELECTION], 0); - sugar_tray_manager_unmanage (manager); - - return FALSE; -} -#endif -#endif - -static void -sugar_tray_manager_unmanage (SugarTrayManager *manager) -{ -#ifdef GDK_WINDOWING_X11 - GdkDisplay *display; - guint32 timestamp; - GtkWidget *invisible; - - if (manager->invisible == NULL) - return; - - invisible = manager->invisible; - g_assert (GTK_IS_INVISIBLE (invisible)); - g_assert (GTK_WIDGET_REALIZED (invisible)); - g_assert (GDK_IS_WINDOW (invisible->window)); - - display = gtk_widget_get_display (invisible); - - if (gdk_selection_owner_get_for_display (display, manager->selection_atom) == - invisible->window) - { - timestamp = gdk_x11_get_server_time (invisible->window); - gdk_selection_owner_set_for_display (display, - NULL, - manager->selection_atom, - timestamp, - TRUE); - } - - //FIXME: we should also use gdk_remove_client_message_filter when it's - //available - // See bug #351254 - gdk_window_remove_filter (invisible->window, - sugar_tray_manager_window_filter, manager); - - manager->invisible = NULL; /* prior to destroy for reentrancy paranoia */ - gtk_widget_destroy (invisible); - g_object_unref (G_OBJECT (invisible)); -#endif -} - -static void -sugar_tray_manager_set_orientation_property (SugarTrayManager *manager) -{ -#ifdef GDK_WINDOWING_X11 - GdkDisplay *display; - Atom orientation_atom; - gulong data[1]; - - if (!manager->invisible || !manager->invisible->window) - return; - - display = gtk_widget_get_display (manager->invisible); - orientation_atom = gdk_x11_get_xatom_by_name_for_display (display, - "_NET_SYSTEM_TRAY_ORIENTATION"); - - data[0] = manager->orientation == GTK_ORIENTATION_HORIZONTAL ? - SYSTEM_TRAY_ORIENTATION_HORZ : - SYSTEM_TRAY_ORIENTATION_VERT; - - XChangeProperty (GDK_DISPLAY_XDISPLAY (display), - GDK_WINDOW_XWINDOW (manager->invisible->window), - orientation_atom, - XA_CARDINAL, 32, - PropModeReplace, - (guchar *) &data, 1); -#endif -} - -#ifdef GDK_WINDOWING_X11 - -static gboolean -sugar_tray_manager_manage_screen_x11 (SugarTrayManager *manager, - GdkScreen *screen) -{ - GdkDisplay *display; - Screen *xscreen; - GtkWidget *invisible; - char *selection_atom_name; - guint32 timestamp; - - g_return_val_if_fail (SUGAR_IS_TRAY_MANAGER (manager), FALSE); - g_return_val_if_fail (manager->screen == NULL, FALSE); - - /* If there's already a manager running on the screen - * we can't create another one. - */ -#if 0 - if (sugar_tray_manager_check_running_screen_x11 (screen)) - return FALSE; -#endif - display = gdk_screen_get_display (screen); - xscreen = GDK_SCREEN_XSCREEN (screen); - - invisible = gtk_invisible_new_for_screen (screen); - gtk_widget_realize (invisible); - - gtk_widget_add_events (invisible, - GDK_PROPERTY_CHANGE_MASK | GDK_STRUCTURE_MASK); - - selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d", - gdk_screen_get_number (screen)); - manager->selection_atom = gdk_atom_intern (selection_atom_name, FALSE); - g_free (selection_atom_name); - - sugar_tray_manager_set_orientation_property (manager); - - timestamp = gdk_x11_get_server_time (invisible->window); - - /* Check if we could set the selection owner successfully */ - if (gdk_selection_owner_set_for_display (display, - invisible->window, - manager->selection_atom, - timestamp, - TRUE)) - { - XClientMessageEvent xev; - GdkAtom opcode_atom; - GdkAtom message_data_atom; - - xev.type = ClientMessage; - xev.window = RootWindowOfScreen (xscreen); - xev.message_type = gdk_x11_get_xatom_by_name_for_display (display, - "MANAGER"); - - xev.format = 32; - xev.data.l[0] = timestamp; - xev.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, - manager->selection_atom); - xev.data.l[2] = GDK_WINDOW_XWINDOW (invisible->window); - xev.data.l[3] = 0; /* manager specific data */ - xev.data.l[4] = 0; /* manager specific data */ - - XSendEvent (GDK_DISPLAY_XDISPLAY (display), - RootWindowOfScreen (xscreen), - False, StructureNotifyMask, (XEvent *)&xev); - - manager->invisible = invisible; - g_object_ref (G_OBJECT (manager->invisible)); - - opcode_atom = gdk_atom_intern ("_NET_SYSTEM_TRAY_OPCODE", FALSE); - manager->opcode_atom = gdk_x11_atom_to_xatom_for_display (display, - opcode_atom); - - message_data_atom = gdk_atom_intern ("_NET_SYSTEM_TRAY_MESSAGE_DATA", - FALSE); - - /* Add a window filter */ -#if 0 - /* This is for when we lose the selection of _NET_SYSTEM_TRAY_Sx */ - g_signal_connect (invisible, "selection-clear-event", - G_CALLBACK (sugar_tray_manager_selection_clear_event), - manager); -#endif - /* This is for SYSTEM_TRAY_REQUEST_DOCK and SelectionClear */ - gdk_window_add_filter (invisible->window, - sugar_tray_manager_window_filter, manager); - /* This is for SYSTEM_TRAY_BEGIN_MESSAGE and SYSTEM_TRAY_CANCEL_MESSAGE */ - gdk_display_add_client_message_filter (display, opcode_atom, - sugar_tray_manager_handle_client_message_opcode, - manager); - /* This is for _NET_SYSTEM_TRAY_MESSAGE_DATA */ - gdk_display_add_client_message_filter (display, message_data_atom, - sugar_tray_manager_handle_client_message_message_data, - manager); - return TRUE; - } - else - { - gtk_widget_destroy (invisible); - - return FALSE; - } -} - -#endif - -gboolean -sugar_tray_manager_manage_screen (SugarTrayManager *manager, - GdkScreen *screen) -{ - g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); - g_return_val_if_fail (manager->screen == NULL, FALSE); - -#ifdef GDK_WINDOWING_X11 - return sugar_tray_manager_manage_screen_x11 (manager, screen); -#else - return FALSE; -#endif -} - -#ifdef GDK_WINDOWING_X11 - -static gboolean -sugar_tray_manager_check_running_screen_x11 (GdkScreen *screen) -{ - GdkDisplay *display; - Atom selection_atom; - char *selection_atom_name; - - display = gdk_screen_get_display (screen); - selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d", - gdk_screen_get_number (screen)); - selection_atom = gdk_x11_get_xatom_by_name_for_display (display, - selection_atom_name); - g_free (selection_atom_name); - - if (XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display), - selection_atom) != None) - return TRUE; - else - return FALSE; -} - -#endif - -gboolean -sugar_tray_manager_check_running (GdkScreen *screen) -{ - g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); - -#ifdef GDK_WINDOWING_X11 - return sugar_tray_manager_check_running_screen_x11 (screen); -#else - return FALSE; -#endif -} - -char * -sugar_tray_manager_get_child_title (SugarTrayManager *manager, - SugarTrayManagerChild *child) -{ - char *retval = NULL; -#ifdef GDK_WINDOWING_X11 - GdkDisplay *display; - Window *child_window; - Atom utf8_string, atom, type; - int result; - int format; - gulong nitems; - gulong bytes_after; - guchar *val; - - g_return_val_if_fail (SUGAR_IS_TRAY_MANAGER (manager), NULL); - g_return_val_if_fail (GTK_IS_SOCKET (child), NULL); - - display = gdk_screen_get_display (manager->screen); - - child_window = g_object_get_data (G_OBJECT (child), - "na-tray-child-window"); - - utf8_string = gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"); - atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"); - - gdk_error_trap_push (); - - result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), - *child_window, - atom, - 0, G_MAXLONG, - False, utf8_string, - &type, &format, &nitems, - &bytes_after, (guchar **)&val); - - if (gdk_error_trap_pop () || result != Success) - return NULL; - - if (type != utf8_string || - format != 8 || - nitems == 0) - { - if (val) - XFree (val); - return NULL; - } - - if (!g_utf8_validate (val, nitems, NULL)) - { - XFree (val); - return NULL; - } - - retval = g_strndup (val, nitems); - - XFree (val); -#endif - return retval; -} - -void -sugar_tray_manager_set_orientation (SugarTrayManager *manager, - GtkOrientation orientation) -{ - g_return_if_fail (SUGAR_IS_TRAY_MANAGER (manager)); - - if (manager->orientation != orientation) - { - manager->orientation = orientation; - - sugar_tray_manager_set_orientation_property (manager); - - g_object_notify (G_OBJECT (manager), "orientation"); - } -} - -GtkOrientation -sugar_tray_manager_get_orientation (SugarTrayManager *manager) -{ - g_return_val_if_fail (SUGAR_IS_TRAY_MANAGER (manager), GTK_ORIENTATION_HORIZONTAL); - - return manager->orientation; -} diff --git a/lib/src/sugar-tray-manager.h b/lib/src/sugar-tray-manager.h deleted file mode 100644 index bc7f40e7..00000000 --- a/lib/src/sugar-tray-manager.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* na-tray-manager.h - * Copyright (C) 2002 Anders Carlsson - * Copyright (C) 2003-2006 Vincent Untz - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Used to be: eggtraymanager.h - */ - -#ifndef __SUGAR_TRAY_MANAGER_H__ -#define __SUGAR_TRAY_MANAGER_H__ - -#include -#ifdef GDK_WINDOWING_X11 -#include -#endif - -G_BEGIN_DECLS - -#define SUGAR_TYPE_TRAY_MANAGER (sugar_tray_manager_get_type ()) -#define SUGAR_TRAY_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SUGAR_TYPE_TRAY_MANAGER, SugarTrayManager)) -#define SUGAR_TRAY_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SUGAR_TYPE_TRAY_MANAGER, SugarTrayManagerClass)) -#define SUGAR_IS_TRAY_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SUGAR_TYPE_TRAY_MANAGER)) -#define SUGAR_IS_TRAY_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SUGAR_TYPE_TRAY_MANAGER)) -#define SUGAR_TRAY_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SUGAR_TYPE_TRAY_MANAGER, SugarTrayManagerClass)) - -typedef struct _SugarTrayManager SugarTrayManager; -typedef struct _SugarTrayManagerClass SugarTrayManagerClass; -typedef struct _SugarTrayManagerChild SugarTrayManagerChild; - -struct _SugarTrayManager -{ - GObject parent_instance; - -#ifdef GDK_WINDOWING_X11 - GdkAtom selection_atom; - Atom opcode_atom; -#endif - - GtkWidget *invisible; - GdkScreen *screen; - GtkOrientation orientation; - - GList *messages; - GHashTable *socket_table; -}; - -struct _SugarTrayManagerClass -{ - GObjectClass parent_class; - - void (* tray_icon_added) (SugarTrayManager *manager, - SugarTrayManagerChild *child); - void (* tray_icon_removed) (SugarTrayManager *manager, - SugarTrayManagerChild *child); - - void (* message_sent) (SugarTrayManager *manager, - SugarTrayManagerChild *child, - const gchar *message, - glong id, - glong timeout); - - void (* message_cancelled) (SugarTrayManager *manager, - SugarTrayManagerChild *child, - glong id); - - void (* lost_selection) (SugarTrayManager *manager); -}; - -GType sugar_tray_manager_get_type (void); - -gboolean sugar_tray_manager_check_running (GdkScreen *screen); -SugarTrayManager *sugar_tray_manager_new (void); -gboolean sugar_tray_manager_manage_screen (SugarTrayManager *manager, - GdkScreen *screen); -char *sugar_tray_manager_get_child_title (SugarTrayManager *manager, - SugarTrayManagerChild *child); -void sugar_tray_manager_set_orientation (SugarTrayManager *manager, - GtkOrientation orientation); -GtkOrientation sugar_tray_manager_get_orientation (SugarTrayManager *manager); - -G_END_DECLS - -#endif /* __SUGAR_TRAY_MANAGER_H__ */ diff --git a/services/Makefile.am b/services/Makefile.am index 7dbbc87e..4ba8cdd2 100644 --- a/services/Makefile.am +++ b/services/Makefile.am @@ -1 +1 @@ -SUBDIRS = presence presence2 nm clipboard datastore console +SUBDIRS = presence presence2 clipboard datastore console diff --git a/services/nm/Makefile.am b/services/nm/Makefile.am deleted file mode 100644 index f963d949..00000000 --- a/services/nm/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -sugardir = $(pkgdatadir)/services/nm -sugar_PYTHON = \ - __init__.py \ - nmclient.py \ - nminfo.py \ - bubble.py \ - style.py \ - wepkeydialog.py - -bin_SCRIPTS = sugar-nm-applet - -dbusservicedir = $(sysconfdir)/dbus-1/system.d/ -dbusservice_DATA = NetworkManagerInfo.conf - -EXTRA_DIST = $(dbusservice_DATA) $(bin_SCRIPTS) diff --git a/services/nm/NetworkManagerInfo.conf b/services/nm/NetworkManagerInfo.conf deleted file mode 100644 index 4fb82705..00000000 --- a/services/nm/NetworkManagerInfo.conf +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - 512 - - diff --git a/services/nm/__init__.py b/services/nm/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/services/nm/bubble.py b/services/nm/bubble.py deleted file mode 100644 index bb44cd08..00000000 --- a/services/nm/bubble.py +++ /dev/null @@ -1,132 +0,0 @@ -# Copyright (C) 2006, Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -import math - -import gobject -import gtk -import hippo - -class Bubble(hippo.CanvasBox, hippo.CanvasItem): - __gtype_name__ = 'NetworkBubble' - - __gproperties__ = { - 'fill-color': (object, None, None, - gobject.PARAM_READWRITE), - 'stroke-color': (object, None, None, - gobject.PARAM_READWRITE), - 'progress-color': (object, None, None, - gobject.PARAM_READWRITE), - 'percent' : (object, None, None, - gobject.PARAM_READWRITE), - } - - def __init__(self, **kwargs): - self._stroke_color = 0xFFFFFFFF - self._fill_color = 0xFFFFFFFF - self._progress_color = 0x000000FF - self._percent = 0 - self._radius = 8 - - hippo.CanvasBox.__init__(self, **kwargs) - - def do_set_property(self, pspec, value): - if pspec.name == 'fill-color': - self._fill_color = value - self.emit_paint_needed(0, 0, -1, -1) - elif pspec.name == 'stroke-color': - self._stroke_color = value - self.emit_paint_needed(0, 0, -1, -1) - elif pspec.name == 'progress-color': - self._progress_color = value - self.emit_paint_needed(0, 0, -1, -1) - elif pspec.name == 'percent': - self._percent = value - self.emit_paint_needed(0, 0, -1, -1) - - def do_get_property(self, pspec): - if pspec.name == 'fill-color': - return self._fill_color - elif pspec.name == 'stroke-color': - return self._stroke_color - elif pspec.name == 'progress-color': - return self._progress_color - elif pspec.name == 'percent': - return self._percent - - def _int_to_rgb(self, int_color): - red = (int_color >> 24) & 0x000000FF - green = (int_color >> 16) & 0x000000FF - blue = (int_color >> 8) & 0x000000FF - alpha = int_color & 0x000000FF - return (red / 255.0, green / 255.0, blue / 255.0) - - def do_paint_below_children(self, cr, damaged_box): - [width, height] = self.get_allocation() - - line_width = 3.0 - x = line_width - y = line_width - width -= line_width * 2 - height -= line_width * 2 - - cr.move_to(x + self._radius, y); - cr.arc(x + width - self._radius, y + self._radius, - self._radius, math.pi * 1.5, math.pi * 2); - cr.arc(x + width - self._radius, x + height - self._radius, - self._radius, 0, math.pi * 0.5); - cr.arc(x + self._radius, y + height - self._radius, - self._radius, math.pi * 0.5, math.pi); - cr.arc(x + self._radius, y + self._radius, self._radius, - math.pi, math.pi * 1.5); - - color = self._int_to_rgb(self._fill_color) - cr.set_source_rgb(*color) - cr.fill_preserve(); - - color = self._int_to_rgb(self._stroke_color) - cr.set_source_rgb(*color) - cr.set_line_width(line_width) - cr.stroke(); - - if self._percent > 0: - self._paint_progress_bar(cr, x, y, width, height, line_width) - - def _paint_progress_bar(self, cr, x, y, width, height, line_width): - prog_x = x + line_width - prog_y = y + line_width - prog_width = (width - (line_width * 2)) * (self._percent / 100.0) - prog_height = (height - (line_width * 2)) - - x = prog_x - y = prog_y - width = prog_width - height = prog_height - - cr.move_to(x + self._radius, y); - cr.arc(x + width - self._radius, y + self._radius, - self._radius, math.pi * 1.5, math.pi * 2); - cr.arc(x + width - self._radius, x + height - self._radius, - self._radius, 0, math.pi * 0.5); - cr.arc(x + self._radius, y + height - self._radius, - self._radius, math.pi * 0.5, math.pi); - cr.arc(x + self._radius, y + self._radius, self._radius, - math.pi, math.pi * 1.5); - - color = self._int_to_rgb(self._progress_color) - cr.set_source_rgb(*color) - cr.fill_preserve(); diff --git a/services/nm/nmclient.py b/services/nm/nmclient.py deleted file mode 100644 index e9db0eec..00000000 --- a/services/nm/nmclient.py +++ /dev/null @@ -1,917 +0,0 @@ -# vi: ts=4 ai noet -# -# Copyright (C) 2006, Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# 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, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import dbus -import dbus.glib -import dbus.decorators -import gobject -import gtk -import logging -import os -from gettext import gettext as _ - -import hippo -import style -from sugar.graphics.timeline import Timeline -from wepkeydialog import WEPKeyDialog -from bubble import Bubble - -import nminfo - -IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001 -IW_AUTH_ALG_SHARED_KEY = 0x00000002 - - -NM_DEVICE_STAGE_STRINGS=("Unknown", - "Prepare", - "Config", - "Need Users Key", - "IP Config", - "IP Config Get", - "IP Config Commit", - "Activated", - "Failed", - "Cancled" -) - -NM_SERVICE = 'org.freedesktop.NetworkManager' -NM_IFACE = 'org.freedesktop.NetworkManager' -NM_IFACE_DEVICES = 'org.freedesktop.NetworkManager.Devices' -NM_PATH = '/org/freedesktop/NetworkManager' - -DEVICE_TYPE_UNKNOWN = 0 -DEVICE_TYPE_802_3_ETHERNET = 1 -DEVICE_TYPE_802_11_WIRELESS = 2 - -NM_DEVICE_CAP_NONE = 0x00000000 -NM_DEVICE_CAP_NM_SUPPORTED = 0x00000001 -NM_DEVICE_CAP_CARRIER_DETECT = 0x00000002 -NM_DEVICE_CAP_WIRELESS_SCAN = 0x00000004 - - -sys_bus = dbus.SystemBus() - - -NM_802_11_CAP_NONE = 0x00000000 -NM_802_11_CAP_PROTO_NONE = 0x00000001 -NM_802_11_CAP_PROTO_WEP = 0x00000002 -NM_802_11_CAP_PROTO_WPA = 0x00000004 -NM_802_11_CAP_PROTO_WPA2 = 0x00000008 -NM_802_11_CAP_KEY_MGMT_PSK = 0x00000040 -NM_802_11_CAP_KEY_MGMT_802_1X = 0x00000080 -NM_802_11_CAP_CIPHER_WEP40 = 0x00001000 -NM_802_11_CAP_CIPHER_WEP104 = 0x00002000 -NM_802_11_CAP_CIPHER_TKIP = 0x00004000 -NM_802_11_CAP_CIPHER_CCMP = 0x00008000 - - -class Network(gobject.GObject): - __gsignals__ = { - 'init-failed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) - } - - def __init__(self, op): - gobject.GObject.__init__(self) - self._op = op - self._ssid = None - self._mode = None - self._strength = 0 - self._valid = False - - obj = sys_bus.get_object(NM_SERVICE, self._op) - net = dbus.Interface(obj, NM_IFACE_DEVICES) - net.getProperties(reply_handler=self._update_reply_cb, - error_handler=self._update_error_cb) - - def _update_reply_cb(self, *props): - self._ssid = props[1] - self._strength = props[3] - self._mode = props[6] - caps = props[7] - if caps & NM_802_11_CAP_PROTO_WPA or caps & NM_802_11_CAP_PROTO_WPA2: - # We do not support WPA at this time, so don't show - # WPA-enabled access points in the menu - logging.debug("Net(%s): ssid '%s' dropping because WPA[2] unsupported" % (self._op, - self._ssid)) - self._valid = False - self.emit('init-failed') - else: - self._valid = True - logging.debug("Net(%s): ssid '%s', mode %d, strength %d" % (self._op, - self._ssid, self._mode, self._strength)) - - def _update_error_cb(self, err): - logging.debug("Net(%s): failed to update. (%s)" % (self._op, err)) - self._valid = False - self.emit('init-failed') - - def get_ssid(self): - return self._ssid - - def get_op(self): - return self._op - - def get_strength(self): - return self._strength - - def set_strength(self, strength): - self._strength = strength - - def is_valid(self): - return self._valid - - def add_to_menu(self, menu, callback, dev): - strength = self._strength - if strength > 100: - strength = 100 - elif strength < 0: - strength = 0 - item = NetworkMenuItem(text=self._ssid, percent=strength) - item.connect('button-press-event', callback, (dev, self)) - menu.add_item(item) - - -class Device(gobject.GObject): - __gsignals__ = { - 'init-failed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), - 'activated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), - 'strength-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([gobject.TYPE_PYOBJECT])) - } - - def __init__(self, op): - gobject.GObject.__init__(self) - self._op = op - self._iface = None - self._type = DEVICE_TYPE_UNKNOWN - self._udi = None - self._active = False - self._strength = 0 - self._link = False - self._valid = False - self._networks = {} - self._active_net = None - self._caps = 0 - - obj = sys_bus.get_object(NM_SERVICE, self._op) - dev = dbus.Interface(obj, NM_IFACE_DEVICES) - dev.getProperties(reply_handler=self._update_reply_cb, - error_handler=self._update_error_cb) - - def _update_reply_cb(self, *props): - self._iface = props[1] - self._type = props[2] - self._udi = props[3] - self._active = props[4] - if self._active: - self.emit('activated') - self._link = props[15] - self._caps = props[17] - - if self._type == DEVICE_TYPE_802_11_WIRELESS: - old_strength = self._strength - self._strength = props[14] - if self._strength != old_strength: - self.emit('strength-changed', self._strength) - self._update_networks(props[20], props[19]) - - self._valid = True - - def _update_networks(self, net_ops, active_op): - for op in net_ops: - net = Network(op) - self._networks[op] = net - net.connect('init-failed', self._net_init_failed) - if op == active_op: - self._active_net = op - - def _update_error_cb(self, err): - logging.debug("Device(%s): failed to update. (%s)" % (self._op, err)) - self._valid = False - self.emit('init-failed') - - def _net_init_failed(self, net): - net_op = net.get_op() - if not self._networks.has_key(net_op): - return - if net_op == self._active_net: - self._active_net = None - del self._networks[net_op] - - def _add_to_menu_wired(self, menu, callback): - item = NetworkMenuItem(_("Wired Network"), stylesheet="nm.Bubble.Wired", - hi_stylesheet="nm.Bubble.Wired.Hi", - act_stylesheet="nm.Bubble.Wired.Activated") - item.connect('button-press-event', callback, (self, None)) - menu.add_item(item) - - def _add_to_menu_wireless(self, menu, callback, active_only): - act_net = None - if self._active_net and self._networks.has_key(self._active_net): - act_net = self._networks[self._active_net] - - # Only add the active network if active_only == True - if active_only: - if act_net: - act_net.add_to_menu(menu, callback, self) - return - - # Otherwise, add all networks _except_ the active one - for net in self._networks.values(): - if not net.is_valid(): - continue - if act_net == net: - continue - net.add_to_menu(menu, callback, self) - - def add_to_menu(self, menu, callback, active_only=False): - if self._type == DEVICE_TYPE_802_3_ETHERNET: - self._add_to_menu_wired(menu, callback) - elif self._type == DEVICE_TYPE_802_11_WIRELESS: - self._add_to_menu_wireless(menu, callback, active_only) - - def get_op(self): - return self._op - - def get_network(self, op): - if self._networks.has_key(op): - return self._networks[op] - return None - - def get_network_ops(self): - return self._networks.keys() - - def get_strength(self): - return self._strength - - def set_strength(self, strength): - if strength == self._strength: - return False - - if strength >= 0 and strength <= 100: - self._strength = strength - else: - self._strength = 0 - - self.emit('strength-changed', self._strength) - - def network_appeared(self, network): - if self._networks.has_key(network): - return - net = Network(network) - self._networks[network] = net - net.connect('init-failed', self._net_init_failed) - - def network_disappeared(self, network): - if not self._networks.has_key(network): - return - if network == self._active_net: - self._active_net = None - del self._networks[network] - - def get_active(self): - return self._active - - def set_active(self, active, ssid=None): - self._active = active - if self._type == DEVICE_TYPE_802_11_WIRELESS: - if not ssid: - self._active_net = None - else: - for (op, net) in self._networks.items(): - if net.get_ssid() == ssid: - self._active_net = op - - def get_type(self): - return self._type - - def is_valid(self): - return self._valid - - def set_carrier(self, on): - self._link = on - - def get_capabilities(self): - return self._caps - -nm_bubble_wireless = { - 'fill-color' : 0x646464FF, - 'stroke-color' : 0x646464FF, - 'progress-color': 0x333333FF, - 'spacing' : style.space_unit, - 'padding' : style.space_unit * 1.5 -} - -nm_bubble_wireless_hi = { - 'fill-color' : 0x979797FF, - 'stroke-color' : 0x979797FF, - 'progress-color': 0x666666FF, - 'spacing' : style.space_unit, - 'padding' : style.space_unit * 1.5 -} - -nm_bubble_wireless_activated = { - 'fill-color' : 0xA7A7A7FF, - 'stroke-color' : 0xA7A7A7FF, - 'progress-color': 0x777777FF, - 'spacing' : style.space_unit, - 'padding' : style.space_unit * 1.5 -} - -nm_bubble_wired = { - 'fill-color' : 0x000000FF, - 'stroke-color' : 0x000000FF, - 'progress-color': 0x000000FF, - 'spacing' : style.space_unit, - 'padding' : style.space_unit * 1.5 -} - -nm_bubble_wired_hi = { - 'fill-color' : 0x333333FF, - 'stroke-color' : 0x333333FF, - 'progress-color': 0x000000FF, - 'spacing' : style.space_unit, - 'padding' : style.space_unit * 1.5 -} - -nm_bubble_wired_activated = { - 'fill-color' : 0x444444FF, - 'stroke-color' : 0x444444FF, - 'progress-color': 0x000000FF, - 'spacing' : style.space_unit, - 'padding' : style.space_unit * 1.5 -} - -nm_menu_item_title = { - 'xalign': hippo.ALIGNMENT_START, - 'padding-left': 5, - 'color' : 0xFFFFFFFF, - 'font' : style.get_font_description('Bold', 1.2) -} - - -style.register_stylesheet("nm.Bubble.Wireless", nm_bubble_wireless) -style.register_stylesheet("nm.Bubble.Wireless.Hi", nm_bubble_wireless_hi) -style.register_stylesheet("nm.Bubble.Wireless.Activated", nm_bubble_wireless_activated) -style.register_stylesheet("nm.Bubble.Wired", nm_bubble_wired) -style.register_stylesheet("nm.Bubble.Wired.Hi", nm_bubble_wired_hi) -style.register_stylesheet("nm.Bubble.Wired.Activated", nm_bubble_wired_activated) -style.register_stylesheet("nm.MenuItem.Title", nm_menu_item_title) - -class NetworkMenuItem(Bubble): - def __init__(self, text, percent=0, stylesheet="nm.Bubble.Wireless", - hi_stylesheet="nm.Bubble.Wireless.Hi", - act_stylesheet="nm.Bubble.Wireless.Activated"): - Bubble.__init__(self, percent=percent) - self._hover = False - self._default_stylesheet = stylesheet - self._hi_stylesheet = hi_stylesheet - self._act_stylesheet = act_stylesheet - style.apply_stylesheet(self, stylesheet) - - text_item = hippo.CanvasText(text=text) - style.apply_stylesheet(text_item, 'nm.MenuItem.Title') - self.append(text_item) - - self.connect('motion-notify-event', self._motion_notify_event_cb) - # Disable active hilight for now... - #self.connect('button-press-event', self._button_press_event_cb) - - def _motion_notify_event_cb(self, widget, event): - if event.detail == hippo.MOTION_DETAIL_ENTER: - if not self._hover: - self._hover = True - style.apply_stylesheet(self, self._hi_stylesheet) - elif event.detail == hippo.MOTION_DETAIL_LEAVE: - if self._hover: - self._hover = False - style.apply_stylesheet(self, self._default_stylesheet) - return True - - def _button_press_event_cb(self, widget, event): - style.apply_stylesheet(self, self._act_stylesheet) - return False - -class NetworkMenu(gtk.Window): - __gsignals__ = { - 'action': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([int])), - } - - def __init__(self): - gtk.Window.__init__(self, gtk.WINDOW_POPUP) - - canvas = hippo.Canvas() - self.add(canvas) - canvas.show() - - self._root = hippo.CanvasBox() - style.apply_stylesheet(self._root, 'menu') - canvas.set_root(self._root) - - def add_separator(self): - separator = hippo.CanvasBox() - style.apply_stylesheet(separator, 'menu.Separator') - self._root.append(separator) - - def add_item(self, item): - self._root.append(item) - - - -NM_STATE_UNKNOWN = 0 -NM_STATE_ASLEEP = 1 -NM_STATE_CONNECTING = 2 -NM_STATE_CONNECTED = 3 -NM_STATE_DISCONNECTED = 4 - -ICON_WIRED = "stock-net-wired" -ICON_WIRELESS_00 = "stock-net-wireless-00" -ICON_WIRELESS_01_20 = "stock-net-wireless-01-20" -ICON_WIRELESS_21_40 = "stock-net-wireless-21-40" -ICON_WIRELESS_41_60 = "stock-net-wireless-41-60" -ICON_WIRELESS_61_80 = "stock-net-wireless-61-80" -ICON_WIRELESS_81_100 = "stock-net-wireless-81-100" - -class NMClientApp: - def __init__(self): - self.nminfo = None - self._nm_present = False - self._nm_state = NM_STATE_UNKNOWN - self._update_timer = 0 - self._active_device = None - self._devices = {} - self._key_dialog = None - - self._icon_theme = gtk.icon_theme_get_default() - self._icons = {} - self._cur_icon = None - try: - self._icons = self._load_icons() - except RuntimeError: - logging.debug("Couldn't find required icon resources, will exit.") - os._exit(1) - self._setup_trayicon() - - self._menu = None - self._hover_menu = False - self._timeline = Timeline(self) - self._timeline.add_tag('popup', 6, 6) - self._timeline.add_tag('before_popdown', 7, 7) - self._timeline.add_tag('popdown', 8, 8) - - try: - self.nminfo = nminfo.NMInfo(self) - except RuntimeError: - pass - self._setup_dbus() - if self._nm_present: - self._get_nm_state() - self._get_initial_devices() - - def _get_one_icon_pixbuf(self, name): - info = self._icon_theme.lookup_icon(name, 75, 0) - if not info or not info.get_filename(): - raise RuntimeError - return gtk.gdk.pixbuf_new_from_file(info.get_filename()) - - def _load_icons(self): - icons = {} - icons[ICON_WIRED] = self._get_one_icon_pixbuf(ICON_WIRED) - icons[ICON_WIRELESS_00] = self._get_one_icon_pixbuf(ICON_WIRELESS_00) - icons[ICON_WIRELESS_01_20] = self._get_one_icon_pixbuf(ICON_WIRELESS_01_20) - icons[ICON_WIRELESS_21_40] = self._get_one_icon_pixbuf(ICON_WIRELESS_21_40) - icons[ICON_WIRELESS_41_60] = self._get_one_icon_pixbuf(ICON_WIRELESS_41_60) - icons[ICON_WIRELESS_61_80] = self._get_one_icon_pixbuf(ICON_WIRELESS_61_80) - icons[ICON_WIRELESS_81_100] = self._get_one_icon_pixbuf(ICON_WIRELESS_81_100) - return icons - - def _get_nm_state(self): - # Grab NM's state - self._nm_obj.state(reply_handler=self._get_state_reply_cb, \ - error_handler=self._get_state_error_cb) - - def _get_state_reply_cb(self, state): - if self._nm_state != state: - self._schedule_icon_update(immediate=True) - self._nm_state = state - - def _get_state_error_cb(self, err): - logging.debug("Failed to get NetworkManager state! %s" % err) - - def _get_icon(self): - act_dev = None - if self._active_device and self._devices.has_key(self._active_device): - act_dev = self._devices[self._active_device] - - pixbuf = None - if not self._nm_present \ - or not act_dev \ - or self._nm_state == NM_STATE_UNKNOWN \ - or self._nm_state == NM_STATE_ASLEEP \ - or self._nm_state == NM_STATE_DISCONNECTED: - pixbuf = self._icons[ICON_WIRELESS_00] - elif act_dev.get_type() == DEVICE_TYPE_802_3_ETHERNET: - pixbuf = self._icons[ICON_WIRED] - elif act_dev.get_type() == DEVICE_TYPE_802_11_WIRELESS: - strength = act_dev.get_strength() - if strength <= 0: - pixbuf = self._icons[ICON_WIRELESS_00] - elif strength >= 1 and strength <= 20: - pixbuf = self._icons[ICON_WIRELESS_01_20] - elif strength >= 21 and strength <= 40: - pixbuf = self._icons[ICON_WIRELESS_21_40] - elif strength >= 41 and strength <= 60: - pixbuf = self._icons[ICON_WIRELESS_41_60] - elif strength >= 61 and strength <= 80: - pixbuf = self._icons[ICON_WIRELESS_61_80] - elif strength >= 81 and strength: - pixbuf = self._icons[ICON_WIRELESS_81_100] - - if not pixbuf: - pixbuf = self._icons[ICON_WIRELESS_00] - return pixbuf - - def _setup_trayicon(self): - pixbuf = self._get_icon() - self._trayicon = gtk.status_icon_new_from_pixbuf(pixbuf) - self._trayicon.connect("popup_menu", self._status_icon_clicked) - self._trayicon.connect("activate", self._status_icon_clicked) - self._schedule_icon_update() - - def _status_icon_clicked(self, button=0, time=None): - self._timeline.play(None, 'popup') - - def _get_menu_position(self, menu, item): - (screen, rect, orientation) = item.get_geometry() - [item_x, item_y, item_w, item_h] = rect - [menu_w, menu_h] = menu.size_request() - - x = item_x + item_w - menu_w - y = item_y + item_h - - x = min(x, screen.get_width() - menu_w) - x = max(0, x) - - y = min(y, screen.get_height() - menu_h) - y = max(0, y) - - return (x, y) - - def do_popup(self, current, n_frames): - if self._menu: - return - - self._menu = self._create_menu() - self._menu.connect('enter-notify-event', - self._menu_enter_notify_event_cb) - self._menu.connect('leave-notify-event', - self._menu_leave_notify_event_cb) - (x, y) = self._get_menu_position(self._menu, self._trayicon) - self._menu.move(x, y) - self._menu.show_all() - - def do_popdown(self, current, frame): - if self._menu: - self._menu.destroy() - self._menu = None - - def _popdown(self): - self._timeline.play('popdown', 'popdown') - - def _menu_enter_notify_event_cb(self, widget, event): - self._hover_menu = True - self._timeline.play('popup', 'popup') - - def _menu_leave_notify_event_cb(self, widget, event): - self._hover_menu = False - self._popdown() - - def _create_menu(self): - menu = NetworkMenu() - - # Active device goes above the separator - act_dev = None - if self._active_device and self._devices.has_key(self._active_device): - act_dev = self._devices[self._active_device] - - if act_dev: - act_dev.add_to_menu(menu, self._menu_item_clicked_cb, active_only=True) - menu.add_separator() - - # Wired devices first, if they don't support carrier detect - for dev in self._devices.values(): - if not dev.is_valid(): - continue - if dev.get_type() != DEVICE_TYPE_802_3_ETHERNET: - continue - if dev.get_capabilities() & NM_DEVICE_CAP_CARRIER_DETECT: - continue - if dev == act_dev: - continue - dev.add_to_menu(menu, self._menu_item_clicked_cb) - - # Wireless devices second - for dev in self._devices.values(): - if not dev.is_valid(): - continue - if dev.get_type() != DEVICE_TYPE_802_11_WIRELESS: - continue - dev.add_to_menu(menu, self._menu_item_clicked_cb) - - return menu - - def _update_icon(self): - pixbuf = self._get_icon() - if self._cur_icon != pixbuf: - self._trayicon.set_from_pixbuf(pixbuf) - self._cur_icon = pixbuf - - blink = False - if self._nm_state == NM_STATE_CONNECTING: - blink = True - self._trayicon.set_blinking(blink) - - self._update_timer = 0 - return False - - def _schedule_icon_update(self, immediate=False): - if immediate and self._update_timer: - gobject.source_remove(self._update_timer) - self._update_timer = 0 - - if self._update_timer != 0: - # There is already an update scheduled - return - - if immediate: - self._update_timer = gobject.idle_add(self._update_icon) - else: - self._update_timer = gobject.timeout_add(2000, self._update_icon) - - def _get_initial_devices_reply_cb(self, ops): - for op in ops: - self._add_device(op) - - def _dev_init_failed_cb(self, dev): - # Device failed to initialize, likely due to dbus errors or something - op = dev.get_op() - self._remove_device(op) - - def _get_initial_devices_error_cb(self, err): - logging.debug("Error updating devices (%s)" % err) - - def _get_initial_devices(self): - self._nm_obj.getDevices(reply_handler=self._get_initial_devices_reply_cb, \ - error_handler=self._get_initial_devices_error_cb) - - def _add_device(self, dev_op): - if self._devices.has_key(dev_op): - return - dev = Device(dev_op) - self._devices[dev_op] = dev - dev.connect('init-failed', self._dev_init_failed_cb) - dev.connect('activated', self._dev_activated_cb) - dev.connect('strength-changed', self._dev_strength_changed_cb) - - def _remove_device(self, dev_op): - if not self._devices.has_key(dev_op): - return - if self._active_device == dev_op: - self._active_device = None - dev = self._devices[dev_op] - dev.disconnect('activated') - dev.disconnect('init-failed') - dev.disconnect('strength-changed') - del self._devices[dev_op] - self._schedule_icon_update(immediate=True) - - def _dev_activated_cb(self, dev): - op = dev.get_op() - if not self._devices.has_key(op): - return - if not dev.get_active(): - return - self._active_device = op - self._schedule_icon_update(immediate=True) - - def _dev_strength_changed_cb(self, dev, strength): - op = dev.get_op() - if not self._devices.has_key(op): - return - if not dev.get_active(): - return - self._schedule_icon_update() - - def get_device(self, dev_op): - if not self._devices.has_key(dev_op): - return None - return self._devices[dev_op] - - def _setup_dbus(self): - self._sig_handlers = { - 'StateChange': self.state_change_sig_handler, - 'DeviceAdded': self.device_added_sig_handler, - 'DeviceRemoved': self.device_removed_sig_handler, - 'DeviceActivationStage': self.device_activation_stage_sig_handler, - 'DeviceActivating': self.device_activating_sig_handler, - 'DeviceNowActive': self.device_now_active_sig_handler, - 'DeviceNoLongerActive': self.device_no_longer_active_sig_handler, - 'DeviceCarrierOn': self.device_carrier_on_sig_handler, - 'DeviceCarrierOff': self.device_carrier_off_sig_handler, - 'DeviceStrengthChanged': self.wireless_device_strength_changed_sig_handler, - 'WirelessNetworkAppeared': self.wireless_network_appeared_sig_handler, - 'WirelessNetworkDisappeared': self.wireless_network_disappeared_sig_handler, - 'WirelessNetworkStrengthChanged': self.wireless_network_strength_changed_sig_handler - } - - self._nm_proxy = sys_bus.get_object(NM_SERVICE, NM_PATH) - self._nm_obj = dbus.Interface(self._nm_proxy, NM_IFACE) - - sys_bus.add_signal_receiver(self.name_owner_changed_sig_handler, - signal_name="NameOwnerChanged", - dbus_interface="org.freedesktop.DBus") - - for (signal, handler) in self._sig_handlers.items(): - sys_bus.add_signal_receiver(handler, signal_name=signal, dbus_interface=NM_IFACE) - - # Find out whether or not NM is running - try: - bus_object = sys_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') - name = bus_object.GetNameOwner("org.freedesktop.NetworkManagerInfo", \ - dbus_interface='org.freedesktop.DBus') - if name: - self._nm_present = True - except dbus.DBusException: - pass - - def _menu_item_clicked_cb(self, widget, event, dev_data): - (device, network) = dev_data - net_op = "" - if network: - net_op = network.get_op() - try: - # NM 0.6.4 and earlier have a bug which returns an - # InvalidArguments error if no security information is passed - # for wireless networks - self._nm_obj.setActiveDevice(device.get_op(), network.get_ssid()) - except dbus.DBusException, e: - if str(e).find("invalid arguments"): - pass - else: - raise dbus.DBusException(e) - - self._popdown() - - def get_key_for_network(self, net, async_cb, async_err_cb): - # Throw up a dialog asking for the key here, and set - # the authentication algorithm to the given one, if any - # - # Key needs to be limited to _either_ 10 or 26 digits long, - # and contain _only_ _hex_ digits, 0-9 or a-f - # - # Auth algorithm should be a dropdown of: [Open System, Shared Key], - # mapping to the values [IW_AUTH_ALG_OPEN_SYSTEM, IW_AUTH_ALG_SHARED_KEY] - # above - - self._key_dialog = WEPKeyDialog(net, async_cb, async_err_cb) - self._key_dialog.connect("response", self._key_dialog_response_cb) - self._key_dialog.connect("destroy", self._key_dialog_destroy_cb) - self._key_dialog.show_all() - - def _key_dialog_destroy_cb(self, widget, foo=None): - if widget != self._key_dialog: - return - self._key_dialog_response_cb(widget, gtk.RESPONSE_CANCEL) - - def _key_dialog_response_cb(self, widget, response_id): - if widget != self._key_dialog: - return - key = self._key_dialog.get_key() - wep_auth_alg = self._key_dialog.get_auth_alg() - net = self._key_dialog.get_network() - (async_cb, async_err_cb) = self._key_dialog.get_callbacks() - - # Clear self._key_dialog before we call destroy(), otherwise - # the destroy will trigger and we'll get called again by - # self._key_dialog_destroy_cb - self._key_dialog = None - widget.destroy() - - if response_id == gtk.RESPONSE_OK: - self.nminfo.get_key_for_network_cb( - net, key, wep_auth_alg, async_cb, async_err_cb, canceled=False) - else: - self.nminfo.get_key_for_network_cb( - net, None, None, async_cb, async_err_cb, canceled=True) - - def cancel_get_key_for_network(self): - # Close the wireless key dialog and just have it return - # with the 'canceled' argument set to true - if not self._key_dialog: - return - self._key_dialog_destroy_cb(self._key_dialog) - - def device_activation_stage_sig_handler(self, device, stage): - logging.debug('Device Activation Stage "%s" for device %s' % (NM_DEVICE_STAGE_STRINGS[stage], device)) - - def state_change_sig_handler(self, state): - self._nm_state = state - self._schedule_icon_update(immediate=True) - - def device_activating_sig_handler(self, device): - self._active_device = device - - def device_now_active_sig_handler(self, device, ssid=None): - if not self._devices.has_key(device): - return - self._active_device = device - self._devices[device].set_active(True, ssid) - self._schedule_icon_update(immediate=True) - - def device_no_longer_active_sig_handler(self, device): - if not self._devices.has_key(device): - return - if self._active_device == device: - self._active_device = None - self._devices[device].set_active(False) - self._schedule_icon_update(immediate=True) - - def name_owner_changed_sig_handler(self, name, old, new): - if name != NM_SERVICE: - return - if (old and len(old)) and (not new and not len(new)): - # NM went away - self._nm_present = False - self._schedule_icon_update(immediate=True) - for op in self._devices.keys(): - del self._devices[op] - self._devices = {} - self._active_device = None - self._nm_state = NM_STATE_UNKNOWN - elif (not old and not len(old)) and (new and len(new)): - # NM started up - self._nm_present = True - self._get_nm_state() - self._get_initial_devices() - - def device_added_sig_handler(self, device): - self._add_device(device) - - def device_removed_sig_handler(self, device): - self._remove_device(device) - - def wireless_network_appeared_sig_handler(self, device, network): - if not self._devices.has_key(device): - return - self._devices[device].network_appeared(network) - - def wireless_network_disappeared_sig_handler(self, device, network): - if not self._devices.has_key(device): - return - self._devices[device].network_disappeared(network) - - def wireless_device_strength_changed_sig_handler(self, device, strength): - if not self._devices.has_key(device): - return - self._devices[device].set_strength(strength) - - def wireless_network_strength_changed_sig_handler(self, device, network, strength): - if not self._devices.has_key(device): - return - net = self._devices[device].get_network(network) - if net: - net.set_strength(strength) - - def device_carrier_on_sig_handler(self, device): - if not self._devices.has_key(device): - return - self._devices[device].set_carrier(True) - - def device_carrier_off_sig_handler(self, device): - if not self._devices.has_key(device): - return - self._devices[device].set_carrier(False) - - def run(self): - loop = gobject.MainLoop() - try: - loop.run() - except KeyboardInterrupt: - pass - diff --git a/services/nm/nminfo.py b/services/nm/nminfo.py deleted file mode 100644 index f512a8b8..00000000 --- a/services/nm/nminfo.py +++ /dev/null @@ -1,467 +0,0 @@ -# vi: ts=4 ai noet -# -# Copyright (C) 2006, Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# 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, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import dbus -import dbus.service -import time -import os -import binascii -import ConfigParser -import logging - -import nmclient -try: - from sugar import env -except ImportError: - pass - -NM_INFO_IFACE='org.freedesktop.NetworkManagerInfo' -NM_INFO_PATH='/org/freedesktop/NetworkManagerInfo' - - -class NoNetworks(dbus.DBusException): - def __init__(self): - dbus.DBusException.__init__(self) - self._dbus_error_name = NM_INFO_IFACE + '.NoNetworks' - -class CanceledKeyRequestError(dbus.DBusException): - def __init__(self): - dbus.DBusException.__init__(self) - self._dbus_error_name = NM_INFO_IFACE + '.CanceledError' - - -class NetworkInvalidError(Exception): - pass - - -class NMConfig(ConfigParser.ConfigParser): - def get_bool(self, section, name): - opt = self.get(section, name) - if type(opt) == type(""): - if opt.lower() == 'yes' or opt.lower() == 'true': - return True - elif opt.lower() == 'no' or opt.lower() == 'false': - return False - raise ValueError("Invalid format for %s/%s. Should be one of [yes, no, true, false]." % (section, name)) - - def get_list(self, section, name): - opt = self.get(section, name) - if type(opt) == type(""): - if not len(opt): - return [] - try: - return opt.split() - except Exception: - pass - raise ValueError("Invalid format for %s/%s. Should be a space-separate list." % (section, name)) - - def get_int(self, section, name): - opt = self.get(section, name) - try: - return int(opt) - except Exception: - pass - raise ValueError("Invalid format for %s/%s. Should be a valid integer." % (section, name)) - - def get_float(self, section, name): - opt = self.get(section, name) - try: - return float(opt) - except Exception: - pass - raise ValueError("Invalid format for %s/%s. Should be a valid float." % (section, name)) - - -IW_AUTH_CIPHER_NONE = 0x00000001 -IW_AUTH_CIPHER_WEP40 = 0x00000002 -IW_AUTH_CIPHER_TKIP = 0x00000004 -IW_AUTH_CIPHER_CCMP = 0x00000008 -IW_AUTH_CIPHER_WEP104 = 0x00000010 - -IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001 -IW_AUTH_ALG_SHARED_KEY = 0x00000002 - -NETWORK_TYPE_UNKNOWN = 0 -NETWORK_TYPE_ALLOWED = 1 -NETWORK_TYPE_INVALID = 2 - - -class Security(object): - def __init__(self, we_cipher): - self._we_cipher = we_cipher - - def read_from_config(self, cfg, name): - pass - - def read_from_args(self, args): - pass - - def new_from_config(cfg, name): - security = None - try: - we_cipher = cfg.get_int(name, "we_cipher") - if we_cipher == IW_AUTH_CIPHER_NONE: - security = Security(we_cipher) - elif we_cipher == IW_AUTH_CIPHER_WEP40 or we_cipher == IW_AUTH_CIPHER_WEP104: - security = WEPSecurity(we_cipher) - else: - # FIXME: find a way to make WPA config option matrix not - # make you want to throw up - raise ValueError("Unsupported security combo") - security.read_from_config(cfg, name) - except (ConfigParser.NoOptionError, ValueError), e: - return None - return security - new_from_config = staticmethod(new_from_config) - - def new_from_args(we_cipher, args): - security = None - try: - if we_cipher == IW_AUTH_CIPHER_NONE: - security = Security(we_cipher) - elif we_cipher == IW_AUTH_CIPHER_WEP40 or we_cipher == IW_AUTH_CIPHER_WEP104: - security = WEPSecurity(we_cipher) - else: - # FIXME: find a way to make WPA config option matrix not - # make you want to throw up - raise ValueError("Unsupported security combo") - security.read_from_args(args) - except ValueError, e: - logging.debug("Error reading security information: %s" % e) - del security - return None - return security - new_from_args = staticmethod(new_from_args) - - def get_properties(self): - return [dbus.Int32(self._we_cipher)] - - def write_to_config(self, section, config): - config.set(section, "we_cipher", self._we_cipher) - - -class WEPSecurity(Security): - def read_from_args(self, args): - if len(args) != 2: - raise ValueError("not enough arguments") - key = args[0] - auth_alg = args[1] - if isinstance(key, unicode): - key = key.encode() - if not isinstance(key, str): - raise ValueError("wrong argument type for key") - if not isinstance(auth_alg, int): - raise ValueError("wrong argument type for auth_alg") - self._key = key - self._auth_alg = auth_alg - - def read_from_config(self, cfg, name): - # Key should be a hex encoded string - self._key = cfg.get(name, "key") - if self._we_cipher == IW_AUTH_CIPHER_WEP40 and len(self._key) != 10: - raise ValueError("Key length not right for 40-bit WEP") - if self._we_cipher == IW_AUTH_CIPHER_WEP104 and len(self._key) != 26: - raise ValueError("Key length not right for 104-bit WEP") - - try: - a = binascii.a2b_hex(self._key) - except TypeError: - raise ValueError("Key was not a hexadecimal string.") - - self._auth_alg = cfg.get_int(name, "auth_alg") - if self._auth_alg != IW_AUTH_ALG_OPEN_SYSTEM and self._auth_alg != IW_AUTH_ALG_SHARED_KEY: - raise ValueError("Invalid authentication algorithm %d" % self._auth_alg) - - def get_properties(self): - args = Security.get_properties(self) - args.append(dbus.String(self._key)) - args.append(dbus.Int32(self._auth_alg)) - return args - - def write_to_config(self, section, config): - Security.write_to_config(self, section, config) - config.set(section, "key", self._key) - config.set(section, "auth_alg", self._auth_alg) - - -class Network: - def __init__(self, ssid): - self.ssid = ssid - self.timestamp = int(time.time()) - self.bssids = [] - self.we_cipher = 0 - self._security = None - - def get_properties(self): - bssid_list = dbus.Array([], signature="s") - for item in self.bssids: - bssid_list.append(dbus.String(item)) - args = [dbus.String(self.ssid), dbus.Int32(self.timestamp), dbus.Boolean(True), bssid_list] - args += self._security.get_properties() - return tuple(args) - - def get_security(self): - return self._security.get_properties() - - def set_security(self, security): - self._security = security - - def read_from_args(self, auto, bssid, we_cipher, args): - if auto == False: - self.timestamp = int(time.time()) - if not bssid in self.bssids: - self.bssids.append(bssid) - - self._security = Security.new_from_args(we_cipher, args) - if not self._security: - raise NetworkInvalidError("Invalid security information") - - def read_from_config(self, config): - try: - self.timestamp = config.get_int(self.ssid, "timestamp") - except (ConfigParser.NoOptionError, ValueError), e: - raise NetworkInvalidError(e) - - self._security = Security.new_from_config(config, self.ssid) - if not self._security: - raise NetworkInvalidError(e) - - # The following don't need to be present - try: - self.bssids = config.get_list(self.ssid, "bssids") - except (ConfigParser.NoOptionError, ValueError), e: - pass - - def write_to_config(self, config): - try: - config.add_section(self.ssid) - config.set(self.ssid, "timestamp", self.timestamp) - if len(self.bssids) > 0: - opt = " " - opt.join(self.bssids) - config.set(self.ssid, "bssids", opt) - self._security.write_to_config(self.ssid, config) - except Exception, e: - logging.debug("Error writing '%s': %s" % (self.ssid, e)) - - -class NotFoundError(dbus.DBusException): - pass -class UnsupportedError(dbus.DBusException): - pass - -class NMInfoDBusServiceHelper(dbus.service.Object): - def __init__(self, parent): - self._parent = parent - bus = dbus.SystemBus() - - # If NMI is already around, don't grab the NMI service - bus_object = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') - name = None - try: - name = bus_object.GetNameOwner("org.freedesktop.NetworkManagerInfo", \ - dbus_interface='org.freedesktop.DBus') - except dbus.DBusException: - pass - if name: - logging.debug("NMI service already owned by %s, won't claim it." % name) - raise RuntimeError - - bus_name = dbus.service.BusName(NM_INFO_IFACE, bus=bus) - dbus.service.Object.__init__(self, bus_name, NM_INFO_PATH) - - @dbus.service.method(NM_INFO_IFACE, in_signature='i', out_signature='as') - def getNetworks(self, net_type): - ssids = self._parent.get_networks(net_type) - if len(ssids) > 0: - return dbus.Array(ssids) - - raise NoNetworks() - - @dbus.service.method(NM_INFO_IFACE, in_signature='si', async_callbacks=('async_cb', 'async_err_cb')) - def getNetworkProperties(self, ssid, net_type, async_cb, async_err_cb): - self._parent.get_network_properties(ssid, net_type, async_cb, async_err_cb) - - @dbus.service.method(NM_INFO_IFACE) - def updateNetworkInfo(self, ssid, bauto, bssid, cipher, *args): - self._parent.update_network_info(ssid, bauto, bssid, cipher, args) - - @dbus.service.method(NM_INFO_IFACE, async_callbacks=('async_cb', 'async_err_cb')) - def getKeyForNetwork(self, dev_path, net_path, ssid, attempt, new_key, async_cb, async_err_cb): - self._parent.get_key_for_network(dev_path, net_path, ssid, - attempt, new_key, async_cb, async_err_cb) - - @dbus.service.method(NM_INFO_IFACE) - def cancelGetKeyForNetwork(self): - self._parent.cancel_get_key_for_network() - -class NMInfo(object): - def __init__(self, client): - try: - profile_path = env.get_profile_path() - except NameError: - home = os.path.expanduser("~") - profile_path = os.path.join(home, ".sugar", "default") - self._cfg_file = os.path.join(profile_path, "nm", "networks.cfg") - self._nmclient = client - self._allowed_networks = self._read_config() - self._dbus_helper = NMInfoDBusServiceHelper(self) - - def save_config(self): - self._write_config(self._allowed_networks) - - def _read_config(self): - if not os.path.exists(os.path.dirname(self._cfg_file)): - os.makedirs(os.path.dirname(self._cfg_file), 0755) - if not os.path.exists(self._cfg_file): - self._write_config({}) - return {} - - config = NMConfig() - config.read(self._cfg_file) - networks = {} - for name in config.sections(): - if not isinstance(name, unicode): - name = unicode(name) - net = Network(name) - try: - net.read_from_config(config) - networks[name] = net - except NetworkInvalidError, e: - logging.debug("Error: invalid stored network config: %s" % e) - del net - del config - return networks - - def _write_config(self, networks): - fp = open(self._cfg_file, 'w') - config = NMConfig() - for net in networks.values(): - net.write_to_config(config) - config.write(fp) - fp.close() - del config - - def get_networks(self, net_type): - if net_type != NETWORK_TYPE_ALLOWED: - raise ValueError("Bad network type") - nets = [] - for net in self._allowed_networks.values(): - nets.append(net.ssid) - logging.debug("Returning networks: %s" % nets) - return nets - - def get_network_properties(self, ssid, net_type, async_cb, async_err_cb): - if not isinstance(ssid, unicode): - async_err_cb(ValueError("Invalid arguments; ssid must be unicode.")) - if net_type != NETWORK_TYPE_ALLOWED: - async_err_cb(ValueError("Bad network type")) - if not self._allowed_networks.has_key(ssid): - async_err_cb(NotFoundError("Network '%s' not found." % ssid)) - network = self._allowed_networks[ssid] - props = network.get_properties() - - # DBus workaround: the normal method return handler wraps - # the returned arguments in a tuple and then converts that to a - # struct, but NetworkManager expects a plain list of arguments. - # It turns out that the async callback method return code _doesn't_ - # wrap the returned arguments in a tuple, so as a workaround use - # the async callback stuff here even though we're not doing it - # asynchronously. - async_cb(*props) - - def update_network_info(self, ssid, auto, bssid, we_cipher, args): - if not isinstance(ssid, unicode): - raise ValueError("Invalid arguments; ssid must be unicode.") - if self._allowed_networks.has_key(ssid): - del self._allowed_networks[ssid] - net = Network(ssid) - try: - net.read_from_args(auto, bssid, we_cipher, args) - logging.debug("Updated network information for '%s'." % ssid) - self._allowed_networks[ssid] = net - self.save_config() - except NetworkInvalidError, e: - logging.debug("Error updating network information: %s" % e) - del net - - def get_key_for_network(self, dev_op, net_op, ssid, attempt, new_key, async_cb, async_err_cb): - if not isinstance(ssid, unicode): - raise ValueError("Invalid arguments; ssid must be unicode.") - if self._allowed_networks.has_key(ssid) and not new_key: - # We've got the info already - net = self._allowed_networks[ssid] - async_cb(tuple(net.get_security())) - return - - # Otherwise, ask the user for it - net = None - dev = self._nmclient.get_device(dev_op) - if not dev: - async_err_cb(NotFoundError("Device was unknown.")) - return - - if dev.get_type() == nmclient.DEVICE_TYPE_802_3_ETHERNET: - # We don't support wired 802.1x yet... - async_err_cb(UnsupportedError("Device type is unsupported by NMI.")) - return - - net = dev.get_network(net_op) - if not net: - async_err_cb(NotFoundError("Network was unknown.")) - return - - self._nmclient.get_key_for_network(net, async_cb, async_err_cb) - - def get_key_for_network_cb(self, net, key, auth_alg, async_cb, async_err_cb, canceled=False): - """ - Called by the NMClient when the Wireless Network Key dialog - is closed. - """ - if canceled: - e = CanceledKeyRequestError("Request was canceled.") - # key dialog dialog was canceled; send the error back to NM - async_err_cb(e) - return - - if not key or not auth_alg: - # no key returned, *** BUG ***; the key dialog - # should always return either a key + auth_alg, or a - #cancel error - raise RuntimeError("No key or auth alg given! Bug!") - - we_cipher = None - if len(key) == 26: - we_cipher = IW_AUTH_CIPHER_WEP104 - elif len(key) == 10: - we_cipher = IW_AUTH_CIPHER_WEP40 - else: - raise RuntimeError("Invalid key length!") - - # Stuff the returned key and auth algorithm into a security object - # and return it to NetworkManager - sec = Security.new_from_args(we_cipher, (key, auth_alg)) - if not sec: - raise RuntimeError("Invalid security arguments.") - props = sec.get_properties() - a = tuple(props) - async_cb(*a) - - def cancel_get_key_for_network(self): - # Tell the NMClient to close the key request dialog - self._nmclient.cancel_get_key_for_network() diff --git a/services/nm/style.py b/services/nm/style.py deleted file mode 100644 index 3bfcb4ae..00000000 --- a/services/nm/style.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (C) 2006, Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -import logging - -import gtk - -### Deprecated: we should drop this once we removed stylesheets ### - -_styles = {} - -screen_factor = gtk.gdk.screen_width() / 1200.0 - -space_unit = 9 * screen_factor -separator_thickness = 3 * screen_factor - -standard_icon_scale = 1.0 * screen_factor -small_icon_scale = 0.5 * screen_factor -medium_icon_scale = 1.5 * screen_factor -large_icon_scale = 2.0 * screen_factor -xlarge_icon_scale = 3.0 * screen_factor - -default_font_size = 9.0 * screen_factor - -def load_stylesheet(module): - for objname in dir(module): - if not objname.startswith('_'): - obj = getattr(module, objname) - if isinstance(obj, dict): - register_stylesheet(objname.replace('_', '.'), obj) - -def register_stylesheet(name, style): - _styles[name] = style - -def apply_stylesheet(item, stylesheet_name): - if _styles.has_key(stylesheet_name): - style_sheet = _styles[stylesheet_name] - for name in style_sheet.keys(): - item.set_property(name, style_sheet[name]) - else: - logging.debug('Stylesheet %s not found.' % stylesheet_name) - -def get_font_description(style, relative_size): - base_size = 18 * screen_factor - return '%s %dpx' % (style, int(base_size * relative_size)) diff --git a/services/nm/sugar-nm-applet b/services/nm/sugar-nm-applet deleted file mode 100644 index 5671d5ab..00000000 --- a/services/nm/sugar-nm-applet +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python -# vi: ts=4 ai noet -# -# Copyright (C) 2006, Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# 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, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import sys -import logging - -import pygtk -pygtk.require('2.0') - -from sugar import logger -from sugar import env - -sys.path.insert(0, env.get_services_dir()) - -from nm import nmclient - -logger.start('nm-applet') - -logging.info('Starting network applet') - -app = nmclient.NMClientApp() -app.run() diff --git a/services/nm/wepkeydialog.py b/services/nm/wepkeydialog.py deleted file mode 100644 index 13c7908b..00000000 --- a/services/nm/wepkeydialog.py +++ /dev/null @@ -1,81 +0,0 @@ -# vi: ts=4 ai noet -# -# Copyright (C) 2006, Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# 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, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import gtk - -IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001 -IW_AUTH_ALG_SHARED_KEY = 0x00000002 - -class WEPKeyDialog(gtk.Dialog): - def __init__(self, net, async_cb, async_err_cb): - gtk.Dialog.__init__(self) - self.set_title("Wireless Key Required") - - self._net = net - self._async_cb = async_cb - self._async_err_cb = async_err_cb - - self.set_has_separator(False) - - label = gtk.Label("A wireless encryption key is required for\n" \ - " the wireless network '%s'." % net.get_ssid()) - self.vbox.pack_start(label) - - self._entry = gtk.Entry() - self._entry.props.visibility = False - self._entry.connect('changed', self._entry_changed_cb) - self.vbox.pack_start(self._entry) - self.vbox.show_all() - - self.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, - gtk.STOCK_OK, gtk.RESPONSE_OK) - - self.set_default_response(gtk.RESPONSE_OK) - self._update_response_sensitivity() - - def get_key(self): - return self._entry.get_text() - - def get_auth_alg(self): - return IW_AUTH_ALG_OPEN_SYSTEM - - def get_network(self): - return self._net - - def get_callbacks(self): - return (self._async_cb, self._async_err_cb) - - def _entry_changed_cb(self, entry): - self._update_response_sensitivity() - - def _update_response_sensitivity(self): - key = self.get_key() - - is_hex = True - for c in key: - if not 'a' <= c <= 'f' and not '0' <= c <= '9': - is_hex = False - - valid_len = (len(key) == 10 or len(key) == 26) - self.set_response_sensitive(gtk.RESPONSE_OK, is_hex and valid_len) - -if __name__ == "__main__": - dialog = WEPKeyDialog() - dialog.run() - - print dialog.get_key() diff --git a/shell/sugar-shell b/shell/sugar-shell index 5b85da16..54c1705f 100755 --- a/shell/sugar-shell +++ b/shell/sugar-shell @@ -62,12 +62,6 @@ model = ShellModel() service = ShellService(model) shell = Shell(model) -# Start the NetworkManager applet -# FIXME: do this somewhere else, better planned out -args = ["sugar-nm-applet"] -flags = gobject.SPAWN_SEARCH_PATH -result = gobject.spawn_async(args, flags=flags, standard_output=False) - tbh = TracebackUtils.TracebackHelper() try: gtk.main() diff --git a/shell/view/frame/Makefile.am b/shell/view/frame/Makefile.am index c4e6dc22..e936989b 100644 --- a/shell/view/frame/Makefile.am +++ b/shell/view/frame/Makefile.am @@ -8,7 +8,6 @@ sugar_PYTHON = \ eventframe.py \ frame.py \ ZoomBox.py \ - notificationtray.py \ overlaybox.py \ PanelWindow.py \ framepopupcontext.py diff --git a/shell/view/frame/frame.py b/shell/view/frame/frame.py index f15bf35f..d2b224f6 100644 --- a/shell/view/frame/frame.py +++ b/shell/view/frame/frame.py @@ -26,7 +26,6 @@ from view.frame.overlaybox import OverlayBox from view.frame.FriendsBox import FriendsBox from view.frame.PanelWindow import PanelWindow from view.frame.clipboardpanelwindow import ClipboardPanelWindow -from view.frame.notificationtray import NotificationTray from view.frame.framepopupcontext import FramePopupContext from model.ShellModel import ShellModel from sugar.graphics.timeline import Timeline @@ -87,16 +86,6 @@ class Frame: box = ZoomBox(self._shell, self._popup_context) root.append(box) - tray = NotificationTray() - tray_box = hippo.CanvasBox(box_width=units.grid_to_pixels(1), - box_height=units.grid_to_pixels(1), - xalign=hippo.ALIGNMENT_END) - - tray_widget = hippo.CanvasWidget() - tray_widget.props.widget = tray - tray_box.append(tray_widget, gtk.EXPAND) - root.append(tray_box) - box = OverlayBox(self._shell) root.append(box, hippo.PACK_FIXED) diff --git a/shell/view/frame/notificationtray.py b/shell/view/frame/notificationtray.py deleted file mode 100644 index b3048682..00000000 --- a/shell/view/frame/notificationtray.py +++ /dev/null @@ -1,18 +0,0 @@ -import gtk - -from _sugar import TrayManager - -class NotificationTray(gtk.HBox): - def __init__(self): - gtk.HBox.__init__(self) - - self._manager = TrayManager() - self._manager.connect('tray-icon-added', self._icon_added_cb) - self._manager.connect('tray-icon-removed', self._icon_removed_cb) - self._manager.manage_screen(gtk.gdk.screen_get_default()) - - def _icon_added_cb(self, manager, icon): - self.pack_start(icon, False) - - def _icon_removed_cb(self, manager, icon): - icon.destroy() From f907ceeae67f0a42ddd4a1b4e17ddcaf5cfa8ae8 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 14:30:17 +0100 Subject: [PATCH 22/29] Display strength of wireless device/networks --- shell/hardware/nmclient.py | 7 +++++-- shell/model/MeshModel.py | 18 +++++++++++++++++- shell/model/devices/device.py | 5 ++++- shell/model/devices/wirelessnetwork.py | 20 +++++++++++++++++--- shell/view/devices/wirelessnetwork.py | 21 ++++++++++++++++++++- shell/view/home/MeshBox.py | 12 +++++++++++- 6 files changed, 74 insertions(+), 9 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index 90a21258..41bf5e2e 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -70,10 +70,12 @@ NM_802_11_CAP_CIPHER_WEP104 = 0x00002000 NM_802_11_CAP_CIPHER_TKIP = 0x00004000 NM_802_11_CAP_CIPHER_CCMP = 0x00008000 - class Network(gobject.GObject): __gsignals__ = { - 'init-failed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) + 'init-failed' : (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])), + 'strength-changed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])) } def __init__(self, op): @@ -122,6 +124,7 @@ class Network(gobject.GObject): def set_strength(self, strength): self._strength = strength + self.emit('strength-changed') def is_valid(self): return self._valid diff --git a/shell/model/MeshModel.py b/shell/model/MeshModel.py index 7c86bbc7..c2d42ba6 100644 --- a/shell/model/MeshModel.py +++ b/shell/model/MeshModel.py @@ -22,11 +22,23 @@ from sugar.activity import bundleregistry from model.BuddyModel import BuddyModel from hardware import hardwaremanager -class AccessPointModel: +class AccessPointModel(gobject.GObject): + __gproperties__ = { + 'strength' : (int, None, None, 0, 100, 0, + gobject.PARAM_READABLE) + } + def __init__(self, nm_device, nm_network): + gobject.GObject.__init__(self) self._nm_network = nm_network self._nm_device = nm_device + self._nm_network.connect('strength-changed', + self._strength_changed_cb) + + def _strength_changed_cb(self, nm_network): + self.notity('strength') + def get_id(self): return self._nm_network.get_op() @@ -39,6 +51,10 @@ class AccessPointModel: def get_nm_network(self): return self._nm_network + def do_get_property(self, pspec): + if pspec.name == 'strength': + return self._nm_network.get_strength() + class ActivityModel: def __init__(self, activity, bundle, service): self._service = service diff --git a/shell/model/devices/device.py b/shell/model/devices/device.py index 02afd3cd..32bee0d2 100644 --- a/shell/model/devices/device.py +++ b/shell/model/devices/device.py @@ -1,7 +1,10 @@ +import gobject + from sugar import util -class Device(object): +class Device(gobject.GObject): def __init__(self): + gobject.GObject.__init__(self) self._id = util.unique_id() def get_type(self): diff --git a/shell/model/devices/wirelessnetwork.py b/shell/model/devices/wirelessnetwork.py index 97f16cd5..efbc1b10 100644 --- a/shell/model/devices/wirelessnetwork.py +++ b/shell/model/devices/wirelessnetwork.py @@ -1,15 +1,29 @@ +import gobject + from model.devices import device class Device(device.Device): + __gproperties__ = { + 'strength' : (int, None, None, 0, 100, 0, + gobject.PARAM_READABLE) + } + def __init__(self, nm_device): device.Device.__init__(self) self._nm_device = nm_device + self._nm_device.connect('strength-changed', + self._strength_changed_cb) + + def _strength_changed_cb(self, nm_device): + self.notity('strength') + + def do_get_property(self, pspec): + if pspec.name == 'strength': + return self._nm_device.get_strength() + def get_type(self): return 'wirelessnetwork' def get_id(self): return self._nm_device.get_op() - - def get_level(self): - return self._nm_device.get_strength() diff --git a/shell/view/devices/wirelessnetwork.py b/shell/view/devices/wirelessnetwork.py index 659ec6b2..a08de583 100644 --- a/shell/view/devices/wirelessnetwork.py +++ b/shell/view/devices/wirelessnetwork.py @@ -3,4 +3,23 @@ from view.devices import deviceview class DeviceView(deviceview.DeviceView): def __init__(self, model): deviceview.DeviceView.__init__(self, model) - self.props.icon_name = 'theme:stock-net-wireless-00' + self._model = model + + self._update_icon() + model.connect('notify::strength', self._strength_changed_cb) + + def _strength_changed_cb(self, model, pspec): + self._update_icon() + + def _update_icon(self): + strength = self._model.props.strength + if strength < 21: + self.props.icon_name = 'theme:stock-net-wireless-00' + elif strength < 41: + self.props.icon_name = 'theme:stock-net-wireless-21-40' + elif strength < 61: + self.props.icon_name = 'theme:stock-net-wireless-41-60' + elif strength < 81: + self.props.icon_name = 'theme:stock-net-wireless-61-80' + else: + self.props.icon_name = 'theme:stock-net-wireless-81-100' diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index 55d8cce1..707ad6e4 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -42,7 +42,17 @@ class AccessPointView(CanvasIcon): network_manager.set_active_device(device, network) def _update_icon(self): - self.props.icon_name = 'theme:stock-net-wireless-00' + strength = self._model.props.strength + if strength < 21: + self.props.icon_name = 'theme:stock-net-wireless-00' + elif strength < 41: + self.props.icon_name = 'theme:stock-net-wireless-21-40' + elif strength < 61: + self.props.icon_name = 'theme:stock-net-wireless-41-60' + elif strength < 81: + self.props.icon_name = 'theme:stock-net-wireless-61-80' + else: + self.props.icon_name = 'theme:stock-net-wireless-81-100' class ActivityView(SnowflakeBox): def __init__(self, shell, menu_shell, model): From bba86e5b74ea70ecde1d3fbc8753ecff986e5226 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sun, 25 Feb 2007 14:58:18 +0100 Subject: [PATCH 23/29] First try at menu sizing in OptionMenu. --- sugar/graphics/optionmenu.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sugar/graphics/optionmenu.py b/sugar/graphics/optionmenu.py index f5a44175..2bb6fde4 100644 --- a/sugar/graphics/optionmenu.py +++ b/sugar/graphics/optionmenu.py @@ -68,10 +68,10 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): self._round_box.props.padding = units.points_to_pixels(1) self.append(self._round_box, hippo.PACK_EXPAND) - self._canvas_text = hippo.CanvasText() - self._canvas_text.props.text = _('No options') - self._canvas_text.props.color = color.LABEL_TEXT.get_int() - self._canvas_text.props.font_desc = font.DEFAULT.get_pango_desc() + self._canvas_text = hippo.CanvasText(text=_('No options'), + color=color.LABEL_TEXT.get_int(), + font_desc=font.DEFAULT.get_pango_desc(), + xalign=hippo.ALIGNMENT_START) self._round_box.append(self._canvas_text, hippo.PACK_EXPAND) # TODO: Substitute for the right icon. @@ -102,6 +102,16 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): self._menu.add_item(menu_item) + def do_get_width_request(self): + max_width = max(self._canvas_text.do_get_content_width_request(self._canvas_text), + self._menu.do_get_content_width_request(self._menu)) + + self._canvas_text.props.box_width = max_width + + current_width = hippo.CanvasBox.do_get_width_request(self) + self._menu.props.box_width = current_width + return current_width + def add_separator(self): self._menu.add_separator() @@ -112,10 +122,6 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): context = self._round_box.get_context() [x, y] = context.translate_to_screen(self._round_box) - # TODO: Any better place to do this? - self._menu.props.box_width = max(self.get_width_request(), - self._menu.get_width_request()) - [width, height] = self._round_box.get_allocation() self._menu.popup(x, y + height) From 10bfe004a8b5ab9176b9b26455f2da14ac052340 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 15:05:56 +0100 Subject: [PATCH 24/29] Fix strength propagation --- shell/hardware/nmclient.py | 2 ++ shell/model/MeshModel.py | 2 +- shell/model/devices/wirelessnetwork.py | 4 ++-- shell/view/home/MeshBox.py | 6 ++++++ sugar/graphics/canvasicon.py | 12 ++++++------ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index 41bf5e2e..d1189f0f 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -108,6 +108,8 @@ class Network(gobject.GObject): logging.debug("Net(%s): ssid '%s', mode %d, strength %d" % (self._op, self._ssid, self._mode, self._strength)) + self.emit('strength-changed') + def _update_error_cb(self, err): logging.debug("Net(%s): failed to update. (%s)" % (self._op, err)) self._valid = False diff --git a/shell/model/MeshModel.py b/shell/model/MeshModel.py index c2d42ba6..2e4b912b 100644 --- a/shell/model/MeshModel.py +++ b/shell/model/MeshModel.py @@ -37,7 +37,7 @@ class AccessPointModel(gobject.GObject): self._strength_changed_cb) def _strength_changed_cb(self, nm_network): - self.notity('strength') + self.notify('strength') def get_id(self): return self._nm_network.get_op() diff --git a/shell/model/devices/wirelessnetwork.py b/shell/model/devices/wirelessnetwork.py index efbc1b10..c18cf879 100644 --- a/shell/model/devices/wirelessnetwork.py +++ b/shell/model/devices/wirelessnetwork.py @@ -15,8 +15,8 @@ class Device(device.Device): self._nm_device.connect('strength-changed', self._strength_changed_cb) - def _strength_changed_cb(self, nm_device): - self.notity('strength') + def _strength_changed_cb(self, nm_device, strength): + self.notify('strength') def do_get_property(self, pspec): if pspec.name == 'strength': diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index 707ad6e4..6dcfb0c1 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -31,6 +31,12 @@ class AccessPointView(CanvasIcon): self._model = model self.connect('activated', self._activate_cb) + + model.connect('notify::strength', self._strength_changed_cb) + + self._update_icon() + + def _strength_changed_cb(self, model, pspec): self._update_icon() def _activate_cb(self, icon): diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index fe04074f..56423d8e 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -319,12 +319,12 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): def get_popup(self): if self._tooltip: tooltip_popup = Popup() - canvas_text = hippo.CanvasText(text=self._tooltip) - canvas_text.props.background_color = color.MENU_BACKGROUND.get_int() - canvas_text.props.color = color.LABEL_TEXT.get_int() - canvas_text.props.font_desc = font.DEFAULT.get_pango_desc() - canvas_text.props.padding = units.points_to_pixels(5) - tooltip_popup.append(canvas_text) + text = hippo.CanvasText(text=self._tooltip) + text.props.background_color = color.MENU_BACKGROUND.get_int() + text.props.color = color.LABEL_TEXT.get_int() + text.props.font_desc = font.DEFAULT.get_pango_desc() + text.props.padding = units.points_to_pixels(5) + tooltip_popup.append(text) return tooltip_popup else: From e803f6534f3aaccdb31bc6b8aa7281a85e1e09f2 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 15:24:04 +0100 Subject: [PATCH 25/29] Add ssid tooltip to the home too. Not working yet. --- shell/hardware/nmclient.py | 3 +++ shell/model/devices/wirelessnetwork.py | 7 +++++++ shell/view/devices/wirelessnetwork.py | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index d1189f0f..910b6829 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -218,6 +218,9 @@ class Device(gobject.GObject): def get_networks(self): return self._networks.values() + def get_active_network(self): + return self.get_network(self._active_net) + def get_network(self, op): if self._networks.has_key(op): return self._networks[op] diff --git a/shell/model/devices/wirelessnetwork.py b/shell/model/devices/wirelessnetwork.py index c18cf879..6cd7c577 100644 --- a/shell/model/devices/wirelessnetwork.py +++ b/shell/model/devices/wirelessnetwork.py @@ -27,3 +27,10 @@ class Device(device.Device): def get_id(self): return self._nm_device.get_op() + + def get_name(self): + active_net = self._nm_device.get_active_network() + if active_net: + return active_net.get_ssid() + else: + return None diff --git a/shell/view/devices/wirelessnetwork.py b/shell/view/devices/wirelessnetwork.py index a08de583..19eba5c1 100644 --- a/shell/view/devices/wirelessnetwork.py +++ b/shell/view/devices/wirelessnetwork.py @@ -5,9 +5,11 @@ class DeviceView(deviceview.DeviceView): deviceview.DeviceView.__init__(self, model) self._model = model - self._update_icon() model.connect('notify::strength', self._strength_changed_cb) + self.props.tooltip = model.get_name() + self._update_icon() + def _strength_changed_cb(self, model, pspec): self._update_icon() From 66f26e4b8b9745d7700bae169cd10f60cf36597c Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 17:34:15 +0100 Subject: [PATCH 26/29] Fixup tooltips. Still not working for the home page case, since the active device logic is pretty broken. --- shell/hardware/nmclient.py | 6 ++++++ shell/model/MeshModel.py | 12 +++++++++--- shell/model/devices/wirelessnetwork.py | 20 +++++++++++++------- shell/view/devices/wirelessnetwork.py | 9 ++++++++- shell/view/home/MeshBox.py | 10 +++++++++- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index 910b6829..8eaab2f9 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -75,6 +75,8 @@ class Network(gobject.GObject): 'init-failed' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'strength-changed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])), + 'essid-changed' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) } @@ -109,6 +111,7 @@ class Network(gobject.GObject): self._ssid, self._mode, self._strength)) self.emit('strength-changed') + self.emit('essid-changed') def _update_error_cb(self, err): logging.debug("Net(%s): failed to update. (%s)" % (self._op, err)) @@ -142,6 +145,8 @@ class Device(gobject.GObject): 'strength-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), + 'essid-changed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])), 'network-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), @@ -273,6 +278,7 @@ class Device(gobject.GObject): for (op, net) in self._networks.items(): if net.get_ssid() == ssid: self._active_net = op + self.emit('essid-changed') def get_type(self): return self._type diff --git a/shell/model/MeshModel.py b/shell/model/MeshModel.py index 2e4b912b..30358c72 100644 --- a/shell/model/MeshModel.py +++ b/shell/model/MeshModel.py @@ -24,6 +24,8 @@ from hardware import hardwaremanager class AccessPointModel(gobject.GObject): __gproperties__ = { + 'name' : (str, None, None, None, + gobject.PARAM_READABLE), 'strength' : (int, None, None, 0, 100, 0, gobject.PARAM_READABLE) } @@ -35,16 +37,18 @@ class AccessPointModel(gobject.GObject): self._nm_network.connect('strength-changed', self._strength_changed_cb) + self._nm_network.connect('essid-changed', + self._essid_changed_cb) def _strength_changed_cb(self, nm_network): self.notify('strength') + def _essid_changed_cb(self, nm_network): + self.notify('name') + def get_id(self): return self._nm_network.get_op() - def get_name(self): - return self._nm_network.get_ssid() - def get_nm_device(self): return self._nm_device @@ -54,6 +58,8 @@ class AccessPointModel(gobject.GObject): def do_get_property(self, pspec): if pspec.name == 'strength': return self._nm_network.get_strength() + elif pspec.name == 'name': + return self._nm_network.get_ssid() class ActivityModel: def __init__(self, activity, bundle, service): diff --git a/shell/model/devices/wirelessnetwork.py b/shell/model/devices/wirelessnetwork.py index 6cd7c577..45bc5fe5 100644 --- a/shell/model/devices/wirelessnetwork.py +++ b/shell/model/devices/wirelessnetwork.py @@ -4,6 +4,8 @@ from model.devices import device class Device(device.Device): __gproperties__ = { + 'name' : (str, None, None, None, + gobject.PARAM_READABLE), 'strength' : (int, None, None, 0, 100, 0, gobject.PARAM_READABLE) } @@ -14,23 +16,27 @@ class Device(device.Device): self._nm_device.connect('strength-changed', self._strength_changed_cb) + self._nm_device.connect('essid-changed', + self._essid_changed_cb) def _strength_changed_cb(self, nm_device, strength): self.notify('strength') + def _essid_changed_cb(self, nm_device): + self.notify('name') + def do_get_property(self, pspec): if pspec.name == 'strength': return self._nm_device.get_strength() + elif pspec.name == 'name': + active_net = self._nm_device.get_active_network() + if active_net: + return active_net.get_ssid() + else: + return None def get_type(self): return 'wirelessnetwork' def get_id(self): return self._nm_device.get_op() - - def get_name(self): - active_net = self._nm_device.get_active_network() - if active_net: - return active_net.get_ssid() - else: - return None diff --git a/shell/view/devices/wirelessnetwork.py b/shell/view/devices/wirelessnetwork.py index 19eba5c1..4a9e3780 100644 --- a/shell/view/devices/wirelessnetwork.py +++ b/shell/view/devices/wirelessnetwork.py @@ -5,14 +5,21 @@ class DeviceView(deviceview.DeviceView): deviceview.DeviceView.__init__(self, model) self._model = model + model.connect('notify::name', self._name_changed_cb) model.connect('notify::strength', self._strength_changed_cb) - self.props.tooltip = model.get_name() + self._update_name() self._update_icon() def _strength_changed_cb(self, model, pspec): self._update_icon() + def _name_changed_cb(self, model, pspec): + self._update_name() + + def _update_name(self): + self.props.tooltip = self._model.props.name + def _update_icon(self): strength = self._model.props.strength if strength < 21: diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index 6dcfb0c1..7b5e5da4 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -27,18 +27,23 @@ from view.BuddyIcon import BuddyIcon class AccessPointView(CanvasIcon): def __init__(self, model): - CanvasIcon.__init__(self, tooltip=model.get_name()) + CanvasIcon.__init__(self) self._model = model self.connect('activated', self._activate_cb) model.connect('notify::strength', self._strength_changed_cb) + model.connect('notify::name', self._name_changed_cb) self._update_icon() + self._update_name() def _strength_changed_cb(self, model, pspec): self._update_icon() + def _name_changed_cb(self, model, pspec): + self._update_name() + def _activate_cb(self, icon): network_manager = hardwaremanager.get_network_manager() @@ -47,6 +52,9 @@ class AccessPointView(CanvasIcon): network_manager.set_active_device(device, network) + def _update_name(self): + self.props.tooltip = self._model.props.name + def _update_icon(self): strength = self._model.props.strength if strength < 21: From 4299dd67657d03a6312ae33e00023e6f07ac45d8 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 17:51:30 +0100 Subject: [PATCH 27/29] Cleanups --- shell/hardware/nmclient.py | 3 --- shell/model/devices/wirelessnetwork.py | 9 ++------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index 8eaab2f9..e100a1fb 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -145,8 +145,6 @@ class Device(gobject.GObject): 'strength-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), - 'essid-changed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([])), 'network-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), @@ -278,7 +276,6 @@ class Device(gobject.GObject): for (op, net) in self._networks.items(): if net.get_ssid() == ssid: self._active_net = op - self.emit('essid-changed') def get_type(self): return self._type diff --git a/shell/model/devices/wirelessnetwork.py b/shell/model/devices/wirelessnetwork.py index 45bc5fe5..a3648274 100644 --- a/shell/model/devices/wirelessnetwork.py +++ b/shell/model/devices/wirelessnetwork.py @@ -16,8 +16,6 @@ class Device(device.Device): self._nm_device.connect('strength-changed', self._strength_changed_cb) - self._nm_device.connect('essid-changed', - self._essid_changed_cb) def _strength_changed_cb(self, nm_device, strength): self.notify('strength') @@ -29,11 +27,8 @@ class Device(device.Device): if pspec.name == 'strength': return self._nm_device.get_strength() elif pspec.name == 'name': - active_net = self._nm_device.get_active_network() - if active_net: - return active_net.get_ssid() - else: - return None + # FIXME + return None def get_type(self): return 'wirelessnetwork' From a9c4e4b8e5c57519af557a0543aa19a89c8f693c Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sun, 25 Feb 2007 18:03:17 +0100 Subject: [PATCH 28/29] Fix bug #920. --- shell/shellservice.py | 4 +++- tools/sugar-install-bundle | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/shell/shellservice.py b/shell/shellservice.py index dcbfc0e6..c31e501b 100644 --- a/shell/shellservice.py +++ b/shell/shellservice.py @@ -1,5 +1,7 @@ import dbus +from sugar.activity import bundleregistry + _DBUS_SERVICE = "org.laptop.Shell" _DBUS_INTERFACE = "org.laptop.Shell" _DBUS_PATH = "/org/laptop/Shell" @@ -15,5 +17,5 @@ class ShellService(dbus.service.Object): @dbus.service.method(_DBUS_INTERFACE, in_signature="s", out_signature="b") def add_bundle(self, bundle_path): - registry = self._shellModel.get_bundle_registry() + registry = bundleregistry.get_registry() return registry.add_bundle(bundle_path) diff --git a/tools/sugar-install-bundle b/tools/sugar-install-bundle index 0945c29a..971d9743 100755 --- a/tools/sugar-install-bundle +++ b/tools/sugar-install-bundle @@ -14,7 +14,7 @@ def get_bundle_root_dir(file_names): bundle_root_dir = None for file_name in file_names: if not bundle_root_dir: - bundle_root_dir = file_name.partition('/')[0] + bundle_root_dir = file_name.split('/')[0] if not bundle_root_dir.endswith('.activity'): raise 'Incorrect bundle.' else: From 69b48ade35088d2cceda6904360cb596c1a56b0b Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 21:19:18 +0100 Subject: [PATCH 29/29] s/essid/ssid --- shell/hardware/nmclient.py | 4 ++-- shell/model/MeshModel.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index e100a1fb..a60ba238 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -76,7 +76,7 @@ class Network(gobject.GObject): gobject.TYPE_NONE, ([])), 'strength-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), - 'essid-changed' : (gobject.SIGNAL_RUN_FIRST, + 'ssid-changed' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) } @@ -111,7 +111,7 @@ class Network(gobject.GObject): self._ssid, self._mode, self._strength)) self.emit('strength-changed') - self.emit('essid-changed') + self.emit('ssid-changed') def _update_error_cb(self, err): logging.debug("Net(%s): failed to update. (%s)" % (self._op, err)) diff --git a/shell/model/MeshModel.py b/shell/model/MeshModel.py index 30358c72..8fd74b27 100644 --- a/shell/model/MeshModel.py +++ b/shell/model/MeshModel.py @@ -37,7 +37,7 @@ class AccessPointModel(gobject.GObject): self._nm_network.connect('strength-changed', self._strength_changed_cb) - self._nm_network.connect('essid-changed', + self._nm_network.connect('ssid-changed', self._essid_changed_cb) def _strength_changed_cb(self, nm_network):