From dab184ab67e8bcc1c40d80265b9cee8175ee33fa Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 20 Apr 2006 12:10:42 -0400 Subject: [PATCH] Removing avahi-python since it's already in the avahi-tools RPM --- browser/README | 7 +++++ browser/browser.py | 73 +++++++++++++++++++++++++++++----------------- chat/main.py | 16 ++++++++-- chat/presence.py | 3 ++ 4 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 browser/README diff --git a/browser/README b/browser/README new file mode 100644 index 00000000..e97efad9 --- /dev/null +++ b/browser/README @@ -0,0 +1,7 @@ +DEPENDENCIES +------------ + +gecko-embed + +http://gnome.org/~marco/gecko-embed-0.1-2.i386.rpm +http://gnome.org/~marco/gecko-embed-0.1-2.src.rpm diff --git a/browser/browser.py b/browser/browser.py index 84d11dea..d13bd80b 100755 --- a/browser/browser.py +++ b/browser/browser.py @@ -1,8 +1,13 @@ #!/usr/bin/env python +import dbus +import dbus.service +import dbus.glib + import pygtk pygtk.require('2.0') import gtk + import geckoembed class AddressToolbar(gtk.Toolbar): @@ -14,8 +19,7 @@ class AddressToolbar(gtk.Toolbar): address_item.show() def __open_address_cb(self, address): - browser = BrowserWindow(address) - browser.show() + web_activity.openAddress(address) class AddressItem(gtk.ToolItem): def __init__(self, callback): @@ -125,47 +129,35 @@ class NavigationToolbar(gtk.Toolbar): def __open_address_cb(self, address): self.embed.load_url(address) -class BrowserWindow(gtk.Window): +class BrowserActivity(gtk.VBox): def __init__(self, uri): - gtk.Window.__init__(self) - self.set_default_size(640, 480); - - vbox = gtk.VBox() + gtk.VBox.__init__(self) self.embed = geckoembed.Embed() - vbox.pack_start(self.embed) + self.pack_start(self.embed) self.embed.show() self.embed.load_url(uri) nav_toolbar = NavigationToolbar(self.embed) - vbox.pack_start(nav_toolbar, False) + self.pack_start(nav_toolbar, False) nav_toolbar.show() - self.add(vbox) - vbox.show() - -class SearchWindow(gtk.Window): +class SearchActivity(gtk.VBox): def __init__(self): - gtk.Window.__init__(self) + gtk.VBox.__init__(self) - self.set_default_size(640, 480); self.connect("delete-event", self.__delete_event); - vbox = gtk.VBox() - self.embed = geckoembed.Embed() self.embed.connect("open-address", self.__open_address); - vbox.pack_start(self.embed) + self.pack_start(self.embed) self.embed.show() address_toolbar = AddressToolbar() - vbox.pack_start(address_toolbar, False) + self.pack_start(address_toolbar, False) address_toolbar.show() - self.add(vbox) - vbox.show() - self.embed.load_url("http://www.google.com") def __delete_event(self, widget, event, data=None): @@ -175,10 +167,39 @@ class SearchWindow(gtk.Window): if uri.startswith("http://www.google.com"): return False else: - browser = BrowserWindow(uri) - browser.show() + web_activity.openAddress(uri) return True -window = SearchWindow() -window.show() +class WebActivity: + def __init__(self): + bus = dbus.SessionBus() + container_object = bus.get_object("com.redhat.Sugar.Shell", \ + "/com/redhat/Sugar/Shell/ActivityContainer") + self.container = dbus.Interface(container_object, \ + "com.redhat.Sugar.Shell.ActivityContainer") + + def run(self): + window_id = self.container.add_activity("Web") + + plug = gtk.Plug(window_id) + + window = SearchActivity() + plug.add(window) + window.show() + + plug.show() + + def openAddress(self, uri): + window_id = self.container.add_activity("Page") + + plug = gtk.Plug(window_id) + + window = BrowserActivity(uri) + plug.add(window) + window.show() + + plug.show() + +web_activity = WebActivity() +web_activity.run() gtk.main() diff --git a/chat/main.py b/chat/main.py index eeea2518..5eff7429 100755 --- a/chat/main.py +++ b/chat/main.py @@ -33,6 +33,11 @@ class ChatApp(SimpleGladeApp): realname = "Some Clueless User" return (nick, realname) + def new_service(self, action, interface, protocol, name, stype, domain, flags): + if action != 'added' or stype != presence.OLPC_CHAT_SERVICE: + return + self._pdiscovery.resolve_service(interface, protocol, name, stype, domain, self.service_resolved) + def on_buddyList_buddy_selected(self, widget, *args): (model, aniter) = widget.get_selection().get_selected() name = self.treemodel.get(aniter,0) @@ -67,6 +72,12 @@ class ChatApp(SimpleGladeApp): res[tmp[0]] = '' return res + def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags): + data = self._pair_to_dict(avahi.txt_array_to_string_array(txt)) + if len(data) > 0 and 'name' in data.keys(): + aniter = self.treemodel.insert_after(None,None) + self.treemodel.set(aniter, 0, data['name']) + def new(self): self._group_chat_buffer = gtk.TextBuffer() self.chatView.set_buffer(self._group_chat_buffer) @@ -86,13 +97,12 @@ class ChatApp(SimpleGladeApp): self.buddyList.append_column(column) self._pannounce.register_service(self._realname, 6666, presence.OLPC_CHAT_SERVICE, name=self._nick) + self._pdiscovery.add_service_listener(self.new_service) + self._pdiscovery.start() self._gc_controller = network.GroupChatController('224.0.0.221', 6666, self._recv_group_message) self._gc_controller.start() - aniter = self.treemodel.insert_after(None,None) - self.treemodel.set(aniter, 0, data['name']) - def cleanup(self): pass diff --git a/chat/presence.py b/chat/presence.py index d20d5a78..55d8011c 100644 --- a/chat/presence.py +++ b/chat/presence.py @@ -1,3 +1,6 @@ +#!/usr/bin/python -t + + import avahi, dbus, dbus.glib OLPC_CHAT_SERVICE = "_olpc_chat._udp"