Make activities emit an ActivityShared dbus signal; and have the shell & presence window detect that and disable the 'share' button
This commit is contained in:
parent
be992586b1
commit
f2ef2a6847
@ -40,6 +40,12 @@ class PresenceWindow(gtk.Window):
|
|||||||
def set_activity(self, activity):
|
def set_activity(self, activity):
|
||||||
self._activity = activity
|
self._activity = activity
|
||||||
self._update_buddies_visibility()
|
self._update_buddies_visibility()
|
||||||
|
if activity:
|
||||||
|
if self._activity.get_shared():
|
||||||
|
self._share_button.set_sensitive(False)
|
||||||
|
else:
|
||||||
|
self._share_button.set_sensitive(True)
|
||||||
|
self._activity.connect('shared', lambda w: self._share_button.set_sensitive(False))
|
||||||
|
|
||||||
def _setup_ui(self):
|
def _setup_ui(self):
|
||||||
vbox = gtk.VBox(False, 6)
|
vbox = gtk.VBox(False, 6)
|
||||||
@ -87,10 +93,10 @@ class PresenceWindow(gtk.Window):
|
|||||||
|
|
||||||
button_box = gtk.HButtonBox()
|
button_box = gtk.HButtonBox()
|
||||||
|
|
||||||
share_button = gtk.Button('Share')
|
self._share_button = gtk.Button('Share')
|
||||||
share_button.connect('clicked', self._share_button_clicked_cb)
|
self._share_button.connect('clicked', self._share_button_clicked_cb)
|
||||||
button_box.pack_start(share_button)
|
button_box.pack_start(self._share_button)
|
||||||
share_button.show()
|
self._share_button.show()
|
||||||
|
|
||||||
vbox.pack_start(button_box, False)
|
vbox.pack_start(button_box, False)
|
||||||
button_box.show()
|
button_box.show()
|
||||||
|
@ -19,11 +19,25 @@ from StartPage import StartPage
|
|||||||
from WindowManager import WindowManager
|
from WindowManager import WindowManager
|
||||||
from PresenceWindow import PresenceWindow
|
from PresenceWindow import PresenceWindow
|
||||||
|
|
||||||
class ActivityHost(dbus.service.Object):
|
class ActivityHostSignalHelper(gobject.GObject):
|
||||||
|
__gsignals__ = {
|
||||||
|
'shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, parent):
|
||||||
|
gobject.GObject.__init__(self)
|
||||||
|
self._parent = parent
|
||||||
|
|
||||||
|
def emit_shared(self):
|
||||||
|
self.emit('shared')
|
||||||
|
|
||||||
|
class ActivityHost(dbus.service.Object):
|
||||||
def __init__(self, activity_container, activity_name, default_type, activity_id = None):
|
def __init__(self, activity_container, activity_name, default_type, activity_id = None):
|
||||||
self.activity_name = activity_name
|
self.activity_name = activity_name
|
||||||
self.ellipsize_tab = False
|
self.ellipsize_tab = False
|
||||||
|
self._shared = False
|
||||||
|
|
||||||
|
self._signal_helper = ActivityHostSignalHelper(self)
|
||||||
|
|
||||||
self.activity_container = activity_container
|
self.activity_container = activity_container
|
||||||
|
|
||||||
@ -113,6 +127,18 @@ class ActivityHost(dbus.service.Object):
|
|||||||
#print "window_id = %d"%window_id
|
#print "window_id = %d"%window_id
|
||||||
return window_id
|
return window_id
|
||||||
|
|
||||||
|
def connect(self, signal, func):
|
||||||
|
self._signal_helper.connect(signal, func)
|
||||||
|
|
||||||
|
def get_shared(self):
|
||||||
|
"""Return True if this activity is shared, False if
|
||||||
|
it has not been shared yet."""
|
||||||
|
return self._shared
|
||||||
|
|
||||||
|
def _shared_signal(self):
|
||||||
|
self._shared = True
|
||||||
|
self._signal_helper.emit_shared()
|
||||||
|
|
||||||
@dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \
|
@dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \
|
||||||
in_signature="ss", \
|
in_signature="ss", \
|
||||||
out_signature="")
|
out_signature="")
|
||||||
@ -123,6 +149,11 @@ class ActivityHost(dbus.service.Object):
|
|||||||
self.peer_service = dbus.Interface(self.activity_container.bus.get_object( \
|
self.peer_service = dbus.Interface(self.activity_container.bus.get_object( \
|
||||||
self.__peer_service_name, self.__peer_object_name), \
|
self.__peer_service_name, self.__peer_object_name), \
|
||||||
"com.redhat.Sugar.Activity")
|
"com.redhat.Sugar.Activity")
|
||||||
|
self.activity_container.bus.add_signal_receiver(self._shared_signal,
|
||||||
|
signal_name="ActivityShared",
|
||||||
|
dbus_interface="com.redhat.Sugar.Activity",
|
||||||
|
named_service=self.__peer_service_name,
|
||||||
|
path=self.__peer_object_name)
|
||||||
|
|
||||||
@dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \
|
@dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \
|
||||||
in_signature="b", \
|
in_signature="b", \
|
||||||
@ -213,6 +244,11 @@ class ActivityHost(dbus.service.Object):
|
|||||||
get_id() function."""
|
get_id() function."""
|
||||||
return self.activity_id
|
return self.activity_id
|
||||||
|
|
||||||
|
def default_type(self):
|
||||||
|
"""Interface-type function to match activity.Activity's
|
||||||
|
default_type() function."""
|
||||||
|
return self._default_type
|
||||||
|
|
||||||
def get_object_path(self):
|
def get_object_path(self):
|
||||||
return self.dbus_object_name
|
return self.dbus_object_name
|
||||||
|
|
||||||
|
@ -141,6 +141,11 @@ class ActivityDbusService(dbus.service.Object):
|
|||||||
"""Called by the shell to request the activity to publish itself on the network."""
|
"""Called by the shell to request the activity to publish itself on the network."""
|
||||||
self._call_callback(ON_PUBLISH_CB)
|
self._call_callback(ON_PUBLISH_CB)
|
||||||
|
|
||||||
|
@dbus.service.signal(ACTIVITY_SERVICE_NAME)
|
||||||
|
def ActivityShared(self):
|
||||||
|
print "sent signal"
|
||||||
|
pass
|
||||||
|
|
||||||
class Activity(object):
|
class Activity(object):
|
||||||
"""Base Activity class that all other Activities derive from."""
|
"""Base Activity class that all other Activities derive from."""
|
||||||
|
|
||||||
@ -157,6 +162,7 @@ class Activity(object):
|
|||||||
self._plug = None
|
self._plug = None
|
||||||
self._initial_service = None
|
self._initial_service = None
|
||||||
self._activity_object = None
|
self._activity_object = None
|
||||||
|
self._shared = False
|
||||||
if type(default_type) != type("") or not len(default_type):
|
if type(default_type) != type("") or not len(default_type):
|
||||||
raise ValueError("Default type must be a valid string.")
|
raise ValueError("Default type must be a valid string.")
|
||||||
self._default_type = default_type
|
self._default_type = default_type
|
||||||
@ -180,6 +186,15 @@ class Activity(object):
|
|||||||
def default_type(self):
|
def default_type(self):
|
||||||
return self._default_type
|
return self._default_type
|
||||||
|
|
||||||
|
def set_shared(self):
|
||||||
|
"""Mark the activity as 'shared'."""
|
||||||
|
if not self._shared:
|
||||||
|
self._shared = True
|
||||||
|
self._dbus_service.ActivityShared()
|
||||||
|
|
||||||
|
def shared(self):
|
||||||
|
return self._shared
|
||||||
|
|
||||||
def has_focus(self):
|
def has_focus(self):
|
||||||
"""Return whether or not this Activity is visible to the user."""
|
"""Return whether or not this Activity is visible to the user."""
|
||||||
return self._has_focus
|
return self._has_focus
|
||||||
@ -197,6 +212,8 @@ class Activity(object):
|
|||||||
print "Activity: XEMBED window ID is %s" % self._window_id
|
print "Activity: XEMBED window ID is %s" % self._window_id
|
||||||
self._plug = gtk.Plug(self._window_id)
|
self._plug = gtk.Plug(self._window_id)
|
||||||
self._initial_service = service
|
self._initial_service = service
|
||||||
|
if service:
|
||||||
|
self.set_shared(True)
|
||||||
self.on_connected_to_shell()
|
self.on_connected_to_shell()
|
||||||
|
|
||||||
def _internal_on_disconnected_from_shell_cb(self):
|
def _internal_on_disconnected_from_shell_cb(self):
|
||||||
|
@ -492,6 +492,10 @@ class PresenceService(gobject.GObject):
|
|||||||
# random port #
|
# random port #
|
||||||
port = random.randint(5000, 65535)
|
port = random.randint(5000, 65535)
|
||||||
|
|
||||||
|
# Mark the activity as shared
|
||||||
|
if stype == activity.default_type():
|
||||||
|
activity.set_shared()
|
||||||
|
|
||||||
logging.debug('Share activity %s, type %s, address %s, port %d, properties %s' % (actid, stype, address, port, properties))
|
logging.debug('Share activity %s, type %s, address %s, port %d, properties %s' % (actid, stype, address, port, properties))
|
||||||
service = Service.Service(name=real_name, stype=stype, domain="local",
|
service = Service.Service(name=real_name, stype=stype, domain="local",
|
||||||
address=address, port=port, properties=properties)
|
address=address, port=port, properties=properties)
|
||||||
|
Loading…
Reference in New Issue
Block a user