Save to the journal when switching to another activity.

This commit is contained in:
Tomeu Vizoso 2007-05-16 21:30:49 +02:00
parent 1d31c51ecc
commit 3a1d514e9f
3 changed files with 41 additions and 0 deletions

View File

@ -101,6 +101,7 @@ class HomeModel(gobject.GObject):
self._remove_activity(window.get_xid()) self._remove_activity(window.get_xid())
if not self._activities: if not self._activities:
self.emit('active-activity-changed', None) self.emit('active-activity-changed', None)
self._notify_activity_activation(self._current_activity, None)
def _get_activity_by_xid(self, xid): def _get_activity_by_xid(self, xid):
for act in self._activities.values(): for act in self._activities.values():
@ -108,10 +109,25 @@ class HomeModel(gobject.GObject):
return act return act
return None return None
def _notify_activity_activation(self, old_activity, new_activity):
if old_activity == new_activity:
return
if old_activity:
service = old_activity.get_service()
if service:
service.set_active(False)
if new_activity:
service = new_activity.get_service()
if service:
service.set_active(True)
def _active_window_changed_cb(self, screen): def _active_window_changed_cb(self, screen):
window = screen.get_active_window() window = screen.get_active_window()
if window == None: if window == None:
self.emit('active-activity-changed', None) self.emit('active-activity-changed', None)
self._notify_activity_activation(self._current_activity, None)
return return
if window.get_window_type() != wnck.WINDOW_NORMAL: if window.get_window_type() != wnck.WINDOW_NORMAL:
return return
@ -120,11 +136,14 @@ class HomeModel(gobject.GObject):
act = self._get_activity_by_xid(window.get_xid()) act = self._get_activity_by_xid(window.get_xid())
if act: if act:
if act.get_launched() == True: if act.get_launched() == True:
self._notify_activity_activation(self._current_activity, act)
self._current_activity = act self._current_activity = act
else: else:
self._notify_activity_activation(self._current_activity, None)
self._current_activity = None self._current_activity = None
logging.error('Activity for window %d was not yet launched.' % xid) logging.error('Activity for window %d was not yet launched.' % xid)
else: else:
self._notify_activity_activation(self._current_activity, None)
self._current_activity = None self._current_activity = None
logging.error('Model for window %d does not exist.' % xid) logging.error('Model for window %d does not exist.' % xid)

View File

@ -146,6 +146,10 @@ class Activity(Window, gtk.Container):
'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) 'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
} }
__gproperties__ = {
'active': (bool, None, None, False, gobject.PARAM_READWRITE)
}
def __init__(self, handle, create_jobject=True): def __init__(self, handle, create_jobject=True):
"""Initialise the Activity """Initialise the Activity
@ -175,6 +179,7 @@ class Activity(Window, gtk.Container):
self.connect('destroy', self._destroy_cb) self.connect('destroy', self._destroy_cb)
self._active = False
self._activity_id = handle.activity_id self._activity_id = handle.activity_id
self._pservice = presenceservice.get_instance() self._pservice = presenceservice.get_instance()
self._shared_activity = None self._shared_activity = None
@ -213,6 +218,17 @@ class Activity(Window, gtk.Container):
else: else:
self.jobject = None self.jobject = None
def do_set_property(self, pspec, value):
if pspec.name == 'active':
if self._active != value:
self._active = value
if not self._active and self.jobject:
self.save()
def do_get_property(self, pspec):
if pspec.name == 'active':
return self._active
def _internal_jobject_create_cb(self): def _internal_jobject_create_cb(self):
pass pass

View File

@ -15,6 +15,8 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import logging
import dbus import dbus
import dbus.service import dbus.service
@ -81,3 +83,7 @@ class ActivityService(dbus.service.Object):
def execute(self, command, args): def execute(self, command, args):
return self._activity.execute(command, args) return self._activity.execute(command, args)
@dbus.service.method(_ACTIVITY_INTERFACE)
def set_active(self, active):
logging.debug('ActivityService.set_active: %s.' % active)
self._activity.props.active = active