2007-06-24 14:45:05 +02:00
|
|
|
# Copyright (C) 2006-2007 Red Hat, Inc.
|
2006-10-15 01:24:45 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2006-09-04 17:00:45 +02:00
|
|
|
import gobject
|
2007-09-19 19:20:40 +02:00
|
|
|
from sugar.presence import presenceservice
|
2006-09-04 17:00:45 +02:00
|
|
|
|
|
|
|
class Invite:
|
2006-12-04 20:12:24 +01:00
|
|
|
def __init__(self, issuer, bundle_id, activity_id):
|
|
|
|
self._issuer = issuer
|
|
|
|
self._activity_id = activity_id
|
|
|
|
self._bundle_id = bundle_id
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def get_activity_id(self):
|
|
|
|
return self._activity_id
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def get_bundle_id(self):
|
|
|
|
return self._bundle_id
|
2006-09-04 17:00:45 +02:00
|
|
|
|
|
|
|
class Invites(gobject.GObject):
|
2006-12-04 20:12:24 +01:00
|
|
|
__gsignals__ = {
|
|
|
|
'invite-added': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([object])),
|
|
|
|
'invite-removed': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([object])),
|
|
|
|
}
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def __init__(self):
|
|
|
|
gobject.GObject.__init__(self)
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2007-09-17 14:03:15 +02:00
|
|
|
self._dict = {}
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2007-09-19 19:20:40 +02:00
|
|
|
ps = presenceservice.get_instance()
|
|
|
|
owner = ps.get_owner()
|
|
|
|
owner.connect('joined-activity', self._owner_joined_cb)
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def add_invite(self, issuer, bundle_id, activity_id):
|
2007-09-17 14:03:15 +02:00
|
|
|
if activity_id in self._dict:
|
|
|
|
# there is no point to add more than one time
|
|
|
|
# an invite for the same activity
|
|
|
|
return
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
invite = Invite(issuer, bundle_id, activity_id)
|
2007-09-17 14:03:15 +02:00
|
|
|
self._dict[activity_id] = invite
|
2006-12-04 20:12:24 +01:00
|
|
|
self.emit('invite-added', invite)
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def remove_invite(self, invite):
|
2007-09-17 14:03:15 +02:00
|
|
|
self._dict.pop(invite.get_activity_id())
|
2006-12-04 20:12:24 +01:00
|
|
|
self.emit('invite-removed', invite)
|
2006-09-09 14:37:11 +02:00
|
|
|
|
2007-09-17 14:03:15 +02:00
|
|
|
def remove_activity(self, activity_id):
|
|
|
|
invite = self._dict.get(activity_id)
|
|
|
|
if invite is not None:
|
|
|
|
self.remove_invite(invite)
|
|
|
|
|
2007-09-19 19:20:40 +02:00
|
|
|
def _owner_joined_cb(self, owner, activity):
|
|
|
|
self.remove_activity(activity.props.id)
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def __iter__(self):
|
2007-09-17 14:03:15 +02:00
|
|
|
return self._dict.values().__iter__()
|