Refactor a bit to keep host independent from the shell

This commit is contained in:
Marco Pesenti Gritti 2006-10-19 15:22:42 +02:00
parent cf13a7ff5b
commit cd29967c2e
3 changed files with 29 additions and 18 deletions

View File

@ -42,9 +42,7 @@ class ActivityChatWindow(gtk.Window):
self.add(chat_widget)
class ActivityHost:
def __init__(self, shell, window):
self._shell = shell
def __init__(self, window):
self._window = window
self._xid = window.get_xid()
self._pservice = PresenceService.get_instance()
@ -73,8 +71,6 @@ class ActivityHost:
self._chat_window = ActivityChatWindow(win, self._chat_widget)
self._frame_was_visible = False
self._shell.connect('activity-changed', self._activity_changed_cb)
self._shell.connect('activity-closed', self._activity_closed_cb)
def get_id(self):
return self._id
@ -143,13 +139,11 @@ class ActivityHost:
def is_chat_visible(self):
return self._chat_window.get_property('visible')
def _activity_changed_cb(self, shell, activity):
if activity != self:
def set_active(self, active):
if not active:
self.chat_hide()
self._frame_was_visible = False
def _activity_closed_cb(self, shell, activity):
if activity == self:
self._chat_window.destroy()
self._frame_was_visible = False
def destroy(self):
self._chat_window.destroy()
self._frame_was_visible = False

View File

@ -45,6 +45,7 @@ class Shell(gobject.GObject):
self._model = model
self._hosts = {}
self._screen = wnck.screen_get_default()
self._current_host = None
style.load_stylesheet(view.stylesheet)
@ -95,7 +96,7 @@ class Shell(gobject.GObject):
def __window_opened_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:
activity_host = ActivityHost(self, window)
activity_host = ActivityHost(window)
self._hosts[activity_host.get_xid()] = activity_host
self.emit('activity-opened', activity_host)
@ -104,24 +105,39 @@ class Shell(gobject.GObject):
if window and window.get_window_type() == wnck.WINDOW_NORMAL:
activity_host = self._hosts[window.get_xid()]
current = self._model.get_current_activity()
if activity_host.get_id() == current:
return
self._model.set_current_activity(activity_host.get_id())
self.emit('activity-changed', activity_host)
self._set_current_activity(activity_host)
def __window_closed_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:
if self._hosts.has_key(window.get_xid()):
host = self._hosts[window.get_xid()]
host.destroy()
self.emit('activity-closed', host)
del self._hosts[window.get_xid()]
if len(self._hosts) == 0:
self._set_current_activity(None)
def _set_current_activity(self, host):
if host:
self._model.set_current_activity(host.get_id())
else:
self._model.set_current_activity(None)
self.emit('activity-changed', None)
if self._current_host:
self._current_host.set_active(False)
self._current_host = host
if self._current_host:
self._current_host.set_active(True)
self.emit('activity-changed', host)
def get_model(self):
return self._model

View File

@ -63,4 +63,5 @@ class ActivityChat(GroupChat):
self._setup_stream(self._chat_service)
def _destroy_cb(self, widget):
self._pservice.unregister_service(self._chat_service)
if self._chat_service:
self._pservice.unregister_service(self._chat_service)