Fix up message sending
This commit is contained in:
parent
33545aa034
commit
f1efb436b0
@ -10,9 +10,141 @@ import gtk
|
|||||||
|
|
||||||
import geckoembed
|
import geckoembed
|
||||||
|
|
||||||
import sys
|
################################################################################
|
||||||
sys.path.append('../shell/example-activity/')
|
# Code below will be moved to a module someday
|
||||||
import activity
|
|
||||||
|
class Activity(dbus.service.Object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def name_owner_changed(self, service_name, old_service_name, new_service_name):
|
||||||
|
#print "in name_owner_changed: svc=%s oldsvc=%s newsvc=%s"%(service_name, old_service_name, new_service_name)
|
||||||
|
if service_name == "com.redhat.Sugar.Shell" and new_service_name == "":
|
||||||
|
self.activity_on_disconnected_from_shell()
|
||||||
|
#elif service_name == "com.redhat.Sugar.Shell" and old_service_name == "":
|
||||||
|
# self.activity_on_shell_reappeared()
|
||||||
|
|
||||||
|
def activity_connect_to_shell(self):
|
||||||
|
self.__bus = dbus.SessionBus()
|
||||||
|
|
||||||
|
self.__bus.add_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged")
|
||||||
|
|
||||||
|
self.__activity_container_object = self.__bus.get_object("com.redhat.Sugar.Shell", \
|
||||||
|
"/com/redhat/Sugar/Shell/ActivityContainer")
|
||||||
|
self.__activity_container = dbus.Interface(self.__activity_container_object, \
|
||||||
|
"com.redhat.Sugar.Shell.ActivityContainer")
|
||||||
|
|
||||||
|
self.__activity_id = self.__activity_container.add_activity("")
|
||||||
|
self.__object_path = "/com/redhat/Sugar/Shell/Activities/%d"%self.__activity_id
|
||||||
|
|
||||||
|
print "object_path = %s"%self.__object_path
|
||||||
|
|
||||||
|
self.__activity_object = dbus.Interface(self.__bus.get_object("com.redhat.Sugar.Shell", self.__object_path), \
|
||||||
|
"com.redhat.Sugar.Shell.ActivityHost")
|
||||||
|
self.__window_id = self.__activity_object.get_host_xembed_id()
|
||||||
|
|
||||||
|
print "XEMBED window_id = %d"%self.__window_id
|
||||||
|
|
||||||
|
self.__plug = gtk.Plug(self.__window_id)
|
||||||
|
|
||||||
|
# Now let the Activity register a peer service so the Shell can poke it
|
||||||
|
self.__peer_service_name = "com.redhat.Sugar.Activity%d"%self.__activity_id
|
||||||
|
self.__peer_object_name = "/com/redhat/Sugar/Activity/%d"%self.__activity_id
|
||||||
|
self.__service = dbus.service.BusName(self.__peer_service_name, bus=self.__bus)
|
||||||
|
dbus.service.Object.__init__(self, self.__service, self.__peer_object_name)
|
||||||
|
|
||||||
|
self.__activity_object.set_peer_service_name(self.__peer_service_name, self.__peer_object_name)
|
||||||
|
|
||||||
|
self.activity_on_connected_to_shell()
|
||||||
|
|
||||||
|
def activity_get_gtk_plug(self):
|
||||||
|
return self.__plug
|
||||||
|
|
||||||
|
def activity_set_can_close(self, can_close):
|
||||||
|
self.__activity_object.set_can_close(can_close)
|
||||||
|
|
||||||
|
@dbus.service.method("com.redhat.Sugar.Activity", \
|
||||||
|
in_signature="", \
|
||||||
|
out_signature="")
|
||||||
|
|
||||||
|
def activity_set_tab_text(self, text):
|
||||||
|
self.__activity_object.set_tab_text(text)
|
||||||
|
|
||||||
|
@dbus.service.method("com.redhat.Sugar.Activity", \
|
||||||
|
in_signature="", \
|
||||||
|
out_signature="")
|
||||||
|
def lost_focus(self):
|
||||||
|
self.activity_on_lost_focus()
|
||||||
|
|
||||||
|
@dbus.service.method("com.redhat.Sugar.Activity", \
|
||||||
|
in_signature="", \
|
||||||
|
out_signature="")
|
||||||
|
def got_focus(self):
|
||||||
|
self.activity_on_got_focus()
|
||||||
|
|
||||||
|
|
||||||
|
@dbus.service.method("com.redhat.Sugar.Activity", \
|
||||||
|
in_signature="", \
|
||||||
|
out_signature="")
|
||||||
|
def close_from_user(self):
|
||||||
|
self.activity_on_close_from_user()
|
||||||
|
|
||||||
|
def activity_get_id(self):
|
||||||
|
return self.__activity_id
|
||||||
|
|
||||||
|
|
||||||
|
def __shutdown_reply_cb(self):
|
||||||
|
print "in __reply_cb"
|
||||||
|
|
||||||
|
self.__plug.destroy()
|
||||||
|
self.__plug = None
|
||||||
|
|
||||||
|
self.__bus = None
|
||||||
|
self.__activity_container_object = None
|
||||||
|
self.__activity_container = None
|
||||||
|
self.__activity_object = None
|
||||||
|
self.__service = None
|
||||||
|
|
||||||
|
self.__bus.remove_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged")
|
||||||
|
|
||||||
|
self.activity_on_disconnected_from_shell()
|
||||||
|
|
||||||
|
|
||||||
|
del self
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def __shutdown_error_cb(self, error):
|
||||||
|
print "in __error_cb"
|
||||||
|
|
||||||
|
def activity_shutdown(self):
|
||||||
|
self.__activity_object.shutdown(reply_handler = self.__shutdown_reply_cb, error_handler = self.__shutdown_error_cb)
|
||||||
|
|
||||||
|
# pure virtual methods
|
||||||
|
|
||||||
|
def activity_on_connected_to_shell(self):
|
||||||
|
print "act %d: you need to override activity_on_connected_to_shell"%self.activity_get_id()
|
||||||
|
|
||||||
|
def activity_on_disconnected_from_shell(self):
|
||||||
|
print "act %d: you need to override activity_on_disconnected_from_shell"%self.activity_get_id()
|
||||||
|
|
||||||
|
def activity_on_close_from_user(self):
|
||||||
|
print "act %d: you need to override activity_on_close_from_user"%self.activity_get_id()
|
||||||
|
|
||||||
|
def activity_on_lost_focus(self):
|
||||||
|
print "act %d: you need to override activity_on_lost_focus"%self.activity_get_id()
|
||||||
|
|
||||||
|
def activity_on_got_focus(self):
|
||||||
|
print "act %d: you need to override activity_on_got_focus"%self.activity_get_id()
|
||||||
|
|
||||||
|
def my_exit():
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
def deferred_exit():
|
||||||
|
gobject.timeout_add(0, my_exit)
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
|
||||||
class AddressToolbar(gtk.Toolbar):
|
class AddressToolbar(gtk.Toolbar):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -142,9 +274,9 @@ class NavigationToolbar(gtk.Toolbar):
|
|||||||
def __open_address_cb(self, address):
|
def __open_address_cb(self, address):
|
||||||
self.embed.load_url(address)
|
self.embed.load_url(address)
|
||||||
|
|
||||||
class BrowserActivity(activity.Activity):
|
class BrowserActivity(Activity):
|
||||||
def __init__(self, uri):
|
def __init__(self, uri):
|
||||||
activity.Activity.__init__(self)
|
Activity.__init__(self)
|
||||||
self.uri = uri
|
self.uri = uri
|
||||||
|
|
||||||
def activity_on_connected_to_shell(self):
|
def activity_on_connected_to_shell(self):
|
||||||
@ -176,9 +308,9 @@ class BrowserActivity(activity.Activity):
|
|||||||
def activity_on_close_from_user(self):
|
def activity_on_close_from_user(self):
|
||||||
self.activity_shutdown()
|
self.activity_shutdown()
|
||||||
|
|
||||||
class WebActivity(activity.Activity):
|
class WebActivity(Activity):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
activity.Activity.__init__(self)
|
Activity.__init__(self)
|
||||||
|
|
||||||
def activity_on_connected_to_shell(self):
|
def activity_on_connected_to_shell(self):
|
||||||
self.activity_set_tab_text("Web Browser")
|
self.activity_set_tab_text("Web Browser")
|
||||||
|
@ -78,7 +78,8 @@ class BuddyList(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def find_buddy_by_address(self, address):
|
def find_buddy_by_address(self, address):
|
||||||
for buddy in self._buddies.keys():
|
for buddy_name in self._buddies.keys():
|
||||||
|
buddy = self._buddies[buddy_name]
|
||||||
if buddy.address() == address:
|
if buddy.address() == address:
|
||||||
return buddy
|
return buddy
|
||||||
return None
|
return None
|
||||||
|
@ -173,7 +173,9 @@ class ChatActivity(activity.Activity):
|
|||||||
def _get_current_chat(self):
|
def _get_current_chat(self):
|
||||||
selection = self._buddy_list_view.get_selection()
|
selection = self._buddy_list_view.get_selection()
|
||||||
(model, aniter) = selection.get_selected()
|
(model, aniter) = selection.get_selected()
|
||||||
buddy = model.get_value(aniter, 1)
|
buddy = None
|
||||||
|
if aniter:
|
||||||
|
buddy = model.get_value(aniter, 1)
|
||||||
if not buddy:
|
if not buddy:
|
||||||
return self._group_chat
|
return self._group_chat
|
||||||
return buddy.chat()
|
return buddy.chat()
|
||||||
|
@ -61,13 +61,6 @@ class Activity(dbus.service.Object):
|
|||||||
def activity_get_gtk_plug(self):
|
def activity_get_gtk_plug(self):
|
||||||
return self.__plug
|
return self.__plug
|
||||||
|
|
||||||
def activity_set_can_close(self, can_close):
|
|
||||||
self.__activity_object.set_can_close(can_close)
|
|
||||||
|
|
||||||
@dbus.service.method("com.redhat.Sugar.Activity", \
|
|
||||||
in_signature="", \
|
|
||||||
out_signature="")
|
|
||||||
|
|
||||||
def activity_set_tab_text(self, text):
|
def activity_set_tab_text(self, text):
|
||||||
self.__activity_object.set_tab_text(text)
|
self.__activity_object.set_tab_text(text)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user