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

View File

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

View File

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