r7053 - in bigboard/trunk/bigboard: . stocks/people
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r7053 - in bigboard/trunk/bigboard: . stocks/people
- Date: Thu, 13 Dec 2007 14:45:51 -0600 (CST)
Author: hp
Date: 2007-12-13 14:45:51 -0600 (Thu, 13 Dec 2007)
New Revision: 7053
Modified:
bigboard/trunk/bigboard/people_tracker.py
bigboard/trunk/bigboard/stocks/people/PeopleStock.py
bigboard/trunk/bigboard/stocks/people/peoplewidgets.py
Log:
allow adding an IM buddy as a network contact; and better track the online flag, which improves sorting
Modified: bigboard/trunk/bigboard/people_tracker.py
===================================================================
--- bigboard/trunk/bigboard/people_tracker.py 2007-12-13 19:58:56 UTC (rev 7052)
+++ bigboard/trunk/bigboard/people_tracker.py 2007-12-13 20:45:51 UTC (rev 7053)
@@ -33,6 +33,7 @@
"xmpp-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
"xmpp-buddy-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
"local-buddy-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
+ "online-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
}
def __init__(self, resource):
@@ -40,9 +41,12 @@
self.resource = resource
self.is_contact = self.resource.class_id == "http://online.gnome.org/p/o/contact"
- # self._debug_rank = -100
+ #self._debug_rank = -100
self.icon_url = None
+ self.online = False
+ self.aim_buddy = None
+ self.xmpp_buddy = None
if self.is_contact:
self.resource.connect(self.__contact_name_changed, "name")
@@ -95,10 +99,31 @@
self.resource.connect(self.__buddy_alias_changed, "alias")
self.resource.connect(self.__buddy_icon_changed, "icon")
+ self.resource.connect(self.__buddy_online_changed, "isOnline")
self.__buddy_alias_changed(resource)
self.__buddy_icon_changed(resource)
+ self.__buddy_online_changed(resource)
+ def __contact_recompute_online(self):
+ isOnline = False
+
+ try:
+ isOnline = self.aim_buddy.isOnline
+ except AttributeError:
+ pass
+
+ if not isOnline:
+ try:
+ isOnline = self.xmpp_buddy.isOnline
+ except AttributeError:
+ pass
+
+ if isOnline != self.online:
+ self.online = isOnline
+ self.emit('online-changed')
+ _logger.debug('%s is now %d' % (self.display_name, self.online))
+
def __contact_name_changed(self, resource):
try:
self.display_name = resource.name
@@ -121,6 +146,7 @@
self.aim = None
self.emit("aim-changed")
+ self.__contact_recompute_online()
def __contact_xmpps_changed(self, resource):
try:
@@ -135,13 +161,19 @@
self.xmpp = None
self.emit("xmpp-changed")
+ self.__contact_recompute_online()
+ def __contact_buddy_online_changed(self, *args):
+ self.__contact_recompute_online()
+
def __contact_aim_buddies_changed(self, resource):
try:
self.aim_buddies = resource.aimBuddies
except AttributeError:
self.aim_buddies = []
+ old_aim_buddy = self.aim_buddy
+
## FIXME don't just pick one arbitrarily
if len(self.aim_buddies) > 0:
self.aim_buddy = self.aim_buddies[0]
@@ -150,7 +182,13 @@
self.__refresh_icon_url() # in case we were using the AIM buddy icon
- self.emit("aim-buddy-changed")
+ if old_aim_buddy != self.aim_buddy:
+ if old_aim_buddy:
+ old_aim_buddy.disconnect(self.__contact_buddy_online_changed)
+ if self.aim_buddy:
+ self.aim_buddy.connect(self.__contact_buddy_online_changed, 'isOnline')
+ self.emit("aim-buddy-changed")
+ self.__contact_recompute_online()
def __contact_xmpp_buddies_changed(self, resource):
try:
@@ -158,6 +196,8 @@
except AttributeError:
self.xmpp_buddies = []
+ old_xmpp_buddy = self.xmpp_buddy
+
## FIXME don't just pick one arbitrarily
if len(self.xmpp_buddies) > 0:
self.xmpp_buddy = self.xmpp_buddies[0]
@@ -166,7 +206,13 @@
self.__refresh_icon_url() # in case we were using the XMPP buddy icon
- self.emit("xmpp-buddy-changed")
+ if old_xmpp_buddy != self.xmpp_buddy:
+ if old_xmpp_buddy:
+ old_xmpp_buddy.disconnect(self.__contact_buddy_online_changed)
+ if self.xmpp_buddy:
+ self.xmpp_buddy.connect(self.__contact_buddy_online_changed, 'isOnline')
+ self.emit("xmpp-buddy-changed")
+ self.__contact_recompute_online()
def __contact_user_changed(self, resource):
try:
@@ -194,6 +240,7 @@
if new_buddy != self.local_buddy:
self.local_buddy = new_buddy
self.emit("local-buddy-changed")
+ self.__contact_recompute_online()
def __set_icon_url(self, new_icon_url):
if not new_icon_url:
@@ -202,7 +249,7 @@
except AttributeError:
pass
- _logger.debug("photo url now %s" % str(new_icon_url))
+ #_logger.debug("photo url now %s" % str(new_icon_url))
if new_icon_url != self.icon_url:
self.icon_url = new_icon_url
@@ -256,6 +303,11 @@
def __buddy_icon_changed(self, resource):
self.__refresh_icon_url()
+ def __buddy_online_changed(self, resource):
+ if resource.isOnline != self.online:
+ self.online = resource.isOnline
+ self.emit('online-changed')
+
def __hash__(self):
return hash(self.resource)
@@ -491,20 +543,7 @@
elif status == STATUS_BLOCKED:
return RANK_NO_DISPLAY
- isOnline = False
-
- try:
- isOnline = contact.resource.aim_buddy.isOnline
- except AttributeError:
- pass
-
- if not isOnline:
- try:
- isOnline = contact.resource.xmpp_buddy.isOnline
- except AttributeError:
- pass
-
- if isOnline:
+ if contact.online:
if status == STATUS_MEDIUM:
return RANK_MEDIUM_ONLINE
elif status == STATUS_HOT:
@@ -529,7 +568,7 @@
return rank
def __get_buddy_rank(buddy):
- if buddy.resource.isOnline:
+ if buddy.online:
return RANK_BUDDY_ONLINE
else:
return RANK_BUDDY_OFFLINE
@@ -564,8 +603,8 @@
else:
rankB = __get_buddy_rank(b)
- #debug_change_rank(a, rankA)
- #debug_change_rank(b, rankB)
+ # debug_change_rank(a, rankA)
+ # debug_change_rank(b, rankB)
if rankA != rankB:
return rankB - rankA
Modified: bigboard/trunk/bigboard/stocks/people/PeopleStock.py
===================================================================
--- bigboard/trunk/bigboard/stocks/people/PeopleStock.py 2007-12-13 19:58:56 UTC (rev 7052)
+++ bigboard/trunk/bigboard/stocks/people/PeopleStock.py 2007-12-13 20:45:51 UTC (rev 7053)
@@ -82,6 +82,8 @@
if person.is_contact:
person.resource.connect(resort, 'status')
+
+ person.connect('online-changed', resort)
person.connect('display-name-changed', resort)
map[person] = item
Modified: bigboard/trunk/bigboard/stocks/people/peoplewidgets.py
===================================================================
--- bigboard/trunk/bigboard/stocks/people/peoplewidgets.py 2007-12-13 19:58:56 UTC (rev 7052)
+++ bigboard/trunk/bigboard/stocks/people/peoplewidgets.py 2007-12-13 20:45:51 UTC (rev 7053)
@@ -139,7 +139,7 @@
self.__photo.set_property('yalign', hippo.ALIGNMENT_CENTER)
def __update(self, person):
- self.__name.set_property("text", self.person.display_name)
+ self.__name.set_property("text", self.person.display_name) #+ " " + str(self.person._debug_rank))
self.__photo.set_url(self.person.icon_url)
def __update_aim_buddy(self, person):
@@ -499,11 +499,15 @@
self.append(self.__contact_status_box)
if person.is_contact:
+ self.__add_link = None
self.__remove_link = ActionLink()
self.__remove_link.connect('activated', self.__remove_from_network_clicked)
self.append(self.__remove_link)
else:
self.__remove_link = None
+ self.__add_link = ActionLink(text=('Add %s to network' % self.person.display_name))
+ self.__add_link.connect('activated', self.__add_to_network_clicked)
+ self.append(self.__add_link)
# self.__online = hippo.CanvasText(text='Offline')
# self.append(self.__online)
@@ -598,6 +602,21 @@
dialog.show()
+ def __create_contact(self, addressType, address):
+ _logger.debug("creating contact %s %s" % (addressType, address))
+
+ model = globals.get_data_model()
+ query = model.update(("http://mugshot.org/p/contacts", "createContact"),
+ addressType=addressType,
+ address=address)
+ query.execute()
+
+ def __add_to_network_clicked(self, link):
+ if self.person.aim:
+ self.__create_contact('aim', self.person.aim)
+ elif self.person.xmpp:
+ self.__create_contact('xmpp', self.person.xmpp)
+
def __update_contact_status(self, person):
self.__contact_status_box.remove_all()
try:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]