r6929 - in bigboard/trunk/bigboard: . stocks/people



Author: hp
Date: 2007-11-19 15:05:06 -0600 (Mon, 19 Nov 2007)
New Revision: 6929

Modified:
   bigboard/trunk/bigboard/people_tracker.py
   bigboard/trunk/bigboard/stocks/people/PeopleStock.py
   bigboard/trunk/bigboard/stocks/people/peoplebrowser.py
   bigboard/trunk/bigboard/stocks/people/peoplewidgets.py
Log:
get code roughly working with latest server (breaks bigboard against production; no help for that really). lots of loose ends remain here.

Modified: bigboard/trunk/bigboard/people_tracker.py
===================================================================
--- bigboard/trunk/bigboard/people_tracker.py	2007-11-19 20:34:46 UTC (rev 6928)
+++ bigboard/trunk/bigboard/people_tracker.py	2007-11-19 21:05:06 UTC (rev 6929)
@@ -38,37 +38,52 @@
     def __init__(self, resource):
         gobject.GObject.__init__(self)
         self.resource = resource
-        self.is_user = self.resource.class_id == "http://mugshot.org/p/o/user";
+        self.is_contact = self.resource.class_id == "http://online.gnome.org/p/o/contact";
 
-        if self.is_user:
-            self.resource.connect(self.__user_name_changed, "name")
-            self.resource.connect(self.__user_photo_url_changed, "photoUrl")
-            self.resource.connect(self.__user_aim_changed, "aim")
-            self.resource.connect(self.__user_xmpp_changed, "xmpp")
-            self.resource.connect(self.__user_aim_buddy_changed, "aimBuddy")
-            self.resource.connect(self.__user_xmpp_buddy_changed, "xmppBuddy")
-            self.resource.connect(self.__user_local_buddy_changed, "mugshotLocalBuddy")
+        if self.is_contact:
+            self.resource.connect(self.__contact_name_changed, "name")
+            self.resource.connect(self.__contact_photo_url_changed, "photoUrl")
+            self.resource.connect(self.__contact_aims_changed, "aims")
+            self.resource.connect(self.__contact_xmpps_changed, "xmpps")
+            self.resource.connect(self.__contact_aim_buddies_changed, "aimBuddies")
+            self.resource.connect(self.__contact_xmpp_buddies_changed, "xmppBuddies")
+            ## FIXME restore local buddy functionality
+            #self.resource.connect(self.__contact_local_buddy_changed, "mugshotLocalBuddy")
 
-            self.__user_name_changed(resource)
-            self.__user_photo_url_changed(resource)
-            self.__user_aim_changed(resource)
-            self.__user_xmpp_changed(resource)
-            self.__user_aim_buddy_changed(resource)
-            self.__user_xmpp_buddy_changed(resource)
+            self.__contact_name_changed(resource)
+            self.__contact_photo_url_changed(resource)
+            self.__contact_aims_changed(resource)
+            self.__contact_xmpps_changed(resource)
+            self.__contact_aim_buddies_changed(resource)
+            self.__contact_xmpp_buddies_changed(resource)
+
+            ## FIXME restore local buddy functionality
+            self.local_buddy = None
         else:
+            if resource.class_id != 'online-desktop:/p/o/buddy':
+                raise Exception("unknown class ID %s for resource constructing Person" % resource.class_id)
+
             if resource.protocol == 'aim':
                 self.aim = resource.name
                 self.aim_buddy = resource
+                self.aims = [self.aim]
+                self.aim_buddies = [self.aim_buddy]
             else:
                 self.aim = None
                 self.aim_buddy = None
+                self.aims = []
+                self.aim_buddies = []
 
             if resource.protocol == 'xmpp':
                 self.xmpp = resource.name
                 self.xmpp_buddy = resource
+                self.xmpps = [self.xmpp]
+                self.xmpp_buddies = [self.xmpp_buddy]
             else:
                 self.xmpp = None
                 self.xmpp_buddy = None
+                self.xmpps = []
+                self.xmpp_buddies = []
 
             if resource.protocol == 'mugshot-local':
                 self.local_buddy = resource
@@ -81,16 +96,16 @@
             self.__buddy_alias_changed(resource)
             self.__buddy_icon_changed(resource)
 
-    def __user_name_changed(self, resource):
+    def __contact_name_changed(self, resource):
         try:
             self.display_name = resource.name
         except AttributeError:
             # FIXME: why does this happen
-            self.display_name = "NO_NAME"
+            self.display_name = "NO_NAME_"
             
         self.emit("display-name-changed")
 
-    def __user_photo_url_changed(self, resource):
+    def __contact_photo_url_changed(self, resource):
         try:
             self.icon_url = resource.photoUrl
         except AttributeError:
@@ -98,43 +113,64 @@
             
         self.emit("icon-url-changed")
 
-    def __user_aim_changed(self, resource):
+    def __contact_aims_changed(self, resource):
         try:
-            self.aim = resource.aim
+            self.aims = resource.aims
         except AttributeError:
+            self.aims = []
+
+        ## FIXME don't just pick one arbitrarily
+        if len(self.aims) > 0:
+            self.aim = self.aims[0]
+        else:
             self.aim = None
 
         self.emit("aim-changed")
 
-    def __user_xmpp_changed(self, resource):
+    def __contact_xmpps_changed(self, resource):
         try:
-            self.xmpp = resource.xmpp
+            self.xmpps = resource.xmpps
         except AttributeError:
+            self.xmpps = []
+        
+        ## FIXME don't just pick one arbitrarily
+        if len(self.xmpps) > 0:
+            self.xmpp = self.xmpps[0]
+        else:
             self.xmpp = None
 
         self.emit("xmpp-changed")
 
-    def __user_aim_buddy_changed(self, resource):
+    def __contact_aim_buddies_changed(self, resource):
         try:
-            self.aim_buddy = resource.aimBuddy
+            self.aim_buddies = resource.aimBuddies
         except AttributeError:
+            self.aim_buddies = []
+
+        ## FIXME don't just pick one arbitrarily
+        if len(self.aim_buddies) > 0:
+            self.aim_buddy = self.aim_buddies[0]
+        else:
             self.aim_buddy = None
 
         self.emit("aim-buddy-changed")
 
-    def __user_xmpp_buddy_changed(self, resource):
+    def __contact_xmpp_buddies_changed(self, resource):
         try:
-            self.xmpp_buddy = resource.xmppBuddy
+            self.xmpp_buddies = resource.xmppBuddies
         except AttributeError:
+            self.xmpp_buddies = []
+
+        ## FIXME don't just pick one arbitrarily
+        if len(self.xmpp_buddies) > 0:
+            self.xmpp_buddy = self.xmpp_buddies[0]
+        else:
             self.xmpp_buddy = None
 
         self.emit("xmpp-buddy-changed")
 
-    def __user_local_buddy_changed(self, resource):
-        try:
-            self.local_buddy = resource.mugshotLocalBuddy
-        except AttributeError:
-            self.local_buddy = None
+    def __contact_local_buddies_changed(self, resource):
+        ## FIXME, update the fields
 
         self.emit("local-buddy-changed")
 
@@ -178,6 +214,7 @@
         "removed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
     }
 
+## PersonSet that wraps a list of Resource objects (each resource is wrapped in a Person object)
 class SinglePersonSet(PersonSet):
     def __init__(self):
         PersonSet.__init__(self)
@@ -237,6 +274,7 @@
     def __iter__(self):
         return self.__resolved.__iter__()
 
+## used to merge multiple PersonSet into one
 class UnionPersonSet(PersonSet):
     def __init__(self, *args):
         PersonSet.__init__(self)
@@ -297,11 +335,15 @@
         # When we disconnect from the server we freeze existing content, then on reconnect
         # we clear everything and start over.
 
-        query = self.__model.query_resource(self.__model.self_resource, "contacts [+;aim;aimBuddy +;mugshotLocalBuddy +;xmpp;xmppBuddy +;email;contactStatus]")
+        contact_props = '[+;name;user;aims;aimBuddies +;mugshotLocalBuddies +;xmpps;xmppBuddies +;emails;status]'
+
+        query = self.__model.query_resource(self.__model.self_resource, "contacts %s" % contact_props)
         query.add_handler(self.__on_got_self)
         query.execute()
         
-        query = self.__model.query_resource(self.__model.global_resource, "aimBuddies [+;user [+;aim;aimBuddy +;mugshotLocalBuddy +;xmpp;xmppBuddy +;email;contactStatus]];xmppBuddies [+;user [+;aim;aimBuddy +;mugshotLocalBuddy +;xmpp;xmppBuddy +;email;contactStatus]];mugshotLocalBuddies [+;user [+;aim;aimBuddy +;mugshotLocalBuddy +;xmpp;xmppBuddy +;email;contactStatus]]")
+        query = self.__model.query_resource(self.__model.global_resource,
+                                            "aimBuddies [+;contact %s]; xmppBuddies [+;contact %s]; mugshotLocalBuddies [+;contact %s]" % (contact_props, contact_props, contact_props))
+
         query.add_handler(self.__on_got_global)
         query.execute()
 
@@ -322,8 +364,8 @@
 
     def __on_contacts_changed(self, self_resource):
         new_contacts = set()
-        for user in self_resource.contacts:
-            new_contacts.add(user)
+        for contact in self_resource.contacts:
+            new_contacts.add(contact)
 
         self.contacts._update(new_contacts)
         
@@ -349,17 +391,17 @@
         self.xmpp_people._update(global_resource.xmppBuddies)
 
 def sort_people(a,b):
-    if a.is_user:
+    if a.is_contact:
         try:
-            statusA = a.resource.contactStatus
+            statusA = a.resource.status
         except AttributeError:
             statusA = 0
     else:
         statusA = 0
 
-    if b.is_user:
+    if b.is_contact:
         try:
-            statusB = b.resource.contactStatus
+            statusB = b.resource.status
         except AttributeError:
             statusB = 0
     else:

Modified: bigboard/trunk/bigboard/stocks/people/PeopleStock.py
===================================================================
--- bigboard/trunk/bigboard/stocks/people/PeopleStock.py	2007-11-19 20:34:46 UTC (rev 6928)
+++ bigboard/trunk/bigboard/stocks/people/PeopleStock.py	2007-11-19 21:05:06 UTC (rev 6929)
@@ -95,8 +95,8 @@
             box.remove(item)
             box.insert_sorted(item, hippo.PACK_IF_FITS, lambda a,b: sort_people(a.person, b.person))
 
-        if person.is_user:
-            person.resource.connect(resort, 'contactStatus')
+        if person.is_contact:
+            person.resource.connect(resort, 'status')
         person.connect('display-name-changed', resort)
         
         map[person] = item
@@ -203,16 +203,26 @@
         for p in self.__tracker.contacts:
             #_logger.debug("contact: " + str(p))
 
-            email = None
-            if person.is_user:
+            matched = False
+            if query in p.display_name:
+                matched = True
+
+            if p.is_contact and not matched:
+                emails = []
                 try:
-                    email = p.resource.email
+                    emails = person.resource.emails
                 except AttributeError:
                     pass
-
-            aim = p.aim
+                for email in emails:
+                    if query in email.lower():
+                        matched = True
+                        break
             
-            if query in p.display_name or (email and (query in email)) or (p.aim and (query in p.aim)):
+            if not matched:
+                if p.aim and query in p.aim:
+                    matched = True
+                    
+            if matched:
                 results.append(PeopleSearchResult(self, p))
                 
         for p in self.__tracker.aim_people:

Modified: bigboard/trunk/bigboard/stocks/people/peoplebrowser.py
===================================================================
--- bigboard/trunk/bigboard/stocks/people/peoplebrowser.py	2007-11-19 20:34:46 UTC (rev 6928)
+++ bigboard/trunk/bigboard/stocks/people/peoplebrowser.py	2007-11-19 21:05:06 UTC (rev 6929)
@@ -63,8 +63,8 @@
             self.remove(item)
             self.add_column_item(section, item, lambda a,b: sort_people(a.person, b.person))
 
-        if person.is_user:
-            person.resource.connect(resort, 'contactStatus')
+        if person.is_contact:
+            person.resource.connect(resort, 'status')
         person.connect('display-name-changed', resort)
         
         self.__update_visibility(section, item)

Modified: bigboard/trunk/bigboard/stocks/people/peoplewidgets.py
===================================================================
--- bigboard/trunk/bigboard/stocks/people/peoplewidgets.py	2007-11-19 20:34:46 UTC (rev 6928)
+++ bigboard/trunk/bigboard/stocks/people/peoplewidgets.py	2007-11-19 21:05:06 UTC (rev 6929)
@@ -70,14 +70,20 @@
         self.__current_track = None
         self.__current_track_timeout = None
 
-        if self.person.is_user:
-            query = model.query_resource(self.person.resource, "currentTrack +;currentTrackPlayTime")
-            query.add_handler(self.__update_current_track)
-            query.execute()
+        if self.person.is_contact:
+            try:
+                user = self.person.resource.user
+            except AttributeError:
+                user = None
 
-            self.person.resource.connect(self.__update_current_track, 'currentTrack')
-            self.person.resource.connect(self.__update_current_track, 'currentTrackPlayTime')
-            self.__update_current_track(self.person.resource)
+            if user:
+                query = model.query_resource(user, "currentTrack +;currentTrackPlayTime")
+                query.add_handler(self.__update_current_track)
+                query.execute()
+
+                user.connect(self.__update_current_track, 'currentTrack')
+                user.connect(self.__update_current_track, 'currentTrackPlayTime')
+                self.__update_current_track(user)
             
         self.person.connect('display-name-changed', self.__update)
         self.person.connect('icon-url-changed', self.__update)
@@ -408,10 +414,15 @@
         self.__name = hippo.CanvasText(font="22px", padding=6)
         self.__header.append(self.__name)
 
-        if person.is_user:
-            mugshot_link = ActionLink(text="Mugshot", padding=6)
-            self.__header.append(mugshot_link, flags=hippo.PACK_END)
-            mugshot_link.connect("activated", self.__on_activate_web)
+        if person.is_contact:
+            try:
+                user = person.resource.user
+            except AttributeError:
+                user = None
+            if user:
+                mugshot_link = ActionLink(text="Mugshot", padding=6)
+                self.__header.append(mugshot_link, flags=hippo.PACK_END)
+                mugshot_link.connect("activated", self.__on_activate_web)
 
         self.__top_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL)
         self.append(self.__top_box)
@@ -420,9 +431,15 @@
                                             scale_height=60,
                                             border=5)
 
-        if person.is_user:
-            self.__photo.set_clickable(True)
-            self.__photo.connect("activated", self.__on_activate_web)
+        if person.is_contact:
+            try:
+                user = person.resource.user
+            except AttributeError:
+                user = None
+            if user:
+                self.__photo.set_clickable(True)
+                self.__photo.connect("activated", self.__on_activate_web)
+
         self.__top_box.append(self.__photo)
 
         self.__address_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL)
@@ -453,10 +470,16 @@
         self.person.connect('aim-changed', self.__update)
         self.person.connect('local-buddy-changed', self.__update_local_buddy)
         self.person.connect('xmpp-changed', self.__update)
-        if person.is_user:
-            self.person.resource.connect(lambda *args: self.__update(self.person), 'email')
-            self.person.resource.connect(self.__update_contact_status, "contactStatus")
-            self.person.resource.connect(self.__update_loved_accounts, "lovedAccounts")
+        if person.is_contact:
+            self.person.resource.connect(lambda *args: self.__update(self.person), 'emails')
+            self.person.resource.connect(self.__update_contact_status, "status")
+            try:
+                user = person.resource.user
+            except AttributeError:
+                user = None
+            
+            if user:
+                user.connect(self.__update_loved_accounts, "lovedAccounts")
         
         query = DataModel(bigboard.globals.server_name).query_resource(self.person.resource, "lovedAccounts +")
         query.add_handler(self.__update_loved_accounts)
@@ -465,10 +488,17 @@
         self.__update(self.person)
         self.__update_local_buddy(self.person)
         
-        if self.person.is_user:
+        if self.person.is_contact:
             self.__update_contact_status(self.person.resource)
-            self.__update_loved_accounts(self.person.resource)
 
+            try:
+                user = person.resource.user
+            except AttributeError:
+                user = None
+            
+            if user:
+                self.__update_loved_accounts(user)
+
     def __add_status_link(self, text, current_status, new_status):
         if current_status == new_status:
             link =hippo.CanvasText(text=text)
@@ -532,15 +562,15 @@
 
         self.__address_box.remove_all()
 
-        email = None
-        if person.is_user:
+        emails = None
+        if person.is_contact:
             try:
-                email = self.person.resource.email
+                emails = self.person.resource.emails
             except AttributeError:
                 pass
          
-        if email != None:
-            email = hippo.CanvasLink(text=email, xalign=hippo.ALIGNMENT_START)
+        if emails != None and len(emails) > 0:
+            email = hippo.CanvasLink(text=emails[0], xalign=hippo.ALIGNMENT_START)
             email.connect('activated', self.__on_activate_email)
             self.__address_box.append(email)
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]