2006-10-15 01:24:45 +02:00
|
|
|
# Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2007-03-09 04:17:33 +01:00
|
|
|
import gobject
|
2006-06-20 09:19:33 +02:00
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import base64
|
2006-09-15 22:41:11 +02:00
|
|
|
import time
|
2006-10-16 13:34:43 +02:00
|
|
|
import logging
|
|
|
|
import dbus
|
2006-06-20 09:19:33 +02:00
|
|
|
|
2006-06-13 00:51:40 +02:00
|
|
|
from sugar import env
|
2006-10-16 13:34:43 +02:00
|
|
|
from sugar import profile
|
2007-04-09 20:40:56 +02:00
|
|
|
from sugar.presence import presenceservice
|
2006-09-25 16:56:12 +02:00
|
|
|
from sugar import util
|
2006-09-15 16:19:56 +02:00
|
|
|
from model.Invites import Invites
|
2006-07-23 06:56:40 +02:00
|
|
|
|
2007-03-09 04:17:33 +01:00
|
|
|
class ShellOwner(gobject.GObject):
|
|
|
|
__gtype_name__ = "ShellOwner"
|
|
|
|
|
|
|
|
__gsignals__ = {
|
|
|
|
'nick-changed' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_STRING])),
|
|
|
|
'color-changed' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT])),
|
|
|
|
'icon-changed' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT]))
|
|
|
|
}
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
"""Class representing the owner of this machine/instance. This class
|
|
|
|
runs in the shell and serves up the buddy icon and other stuff. It's the
|
|
|
|
server portion of the Owner, paired with the client portion in Buddy.py."""
|
|
|
|
def __init__(self):
|
2007-03-09 04:17:33 +01:00
|
|
|
gobject.GObject.__init__(self)
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._nick = profile.get_nick_name()
|
|
|
|
|
|
|
|
self._icon = None
|
|
|
|
self._icon_hash = ""
|
2007-03-09 16:18:23 +01:00
|
|
|
icon = os.path.join(env.get_profile_path(), "buddy-icon.jpg")
|
|
|
|
if not os.path.exists(icon):
|
|
|
|
raise RuntimeError("missing buddy icon")
|
2007-03-09 04:17:33 +01:00
|
|
|
|
2007-03-09 16:18:23 +01:00
|
|
|
fd = open(icon, "r")
|
|
|
|
self._icon = fd.read()
|
|
|
|
fd.close()
|
|
|
|
if not self._icon:
|
|
|
|
raise RuntimeError("invalid buddy icon")
|
|
|
|
|
|
|
|
# Get the icon's hash
|
|
|
|
import md5
|
|
|
|
digest = md5.new(self._icon).digest()
|
|
|
|
self._icon_hash = util.printable_hash(digest)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-04-09 20:40:56 +02:00
|
|
|
self._pservice = presenceservice.get_instance()
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
self._invites = Invites()
|
|
|
|
|
|
|
|
def get_invites(self):
|
|
|
|
return self._invites
|
|
|
|
|
2007-04-10 21:55:55 +02:00
|
|
|
def get_nick(self):
|
2006-12-04 20:12:24 +01:00
|
|
|
return self._nick
|
|
|
|
|
|
|
|
def _handle_invite(self, issuer, bundle_id, activity_id):
|
|
|
|
"""XMLRPC method, called when the owner is invited to an activity."""
|
|
|
|
self._invites.add_invite(issuer, bundle_id, activity_id)
|
|
|
|
return ''
|