home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / digsby / digsbybuddy.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  5.3 KB  |  156 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from jabber import jbuddy, jabber_util
  5. from util import Timer, callsback
  6. from common import pref, profile
  7. from common.actions import action
  8. from objects import ip, pagetime
  9. from pyxmpp.presence import Presence
  10. jbuddy_caps = jbuddy.caps
  11. import logging
  12. log = logging.getLogger('digsby.buddy')
  13.  
  14. def no_widgets(self, *a, **k):
  15.     return not (self.iswidget)
  16.  
  17.  
  18. class DigsbyBuddy(jbuddy):
  19.     
  20.     def __init__(self, jabber_, jid, rosteritem = None):
  21.         jbuddy.__init__(self, jabber_, jid, rosteritem)
  22.         iswidget = iswidget
  23.         import digsby.widgets.widget
  24.         self.iswidget = iswidget(self)
  25.         self.ip = None
  26.         self.online_time = None
  27.         profile.account_manager.buddywatcher.unregister(self)
  28.  
  29.     
  30.     def is_video_widget(self):
  31.         node = self.jid.node
  32.         if node:
  33.             pass
  34.         return node.startswith('video.')
  35.  
  36.     is_video_widget = property(is_video_widget)
  37.     
  38.     def remove(self, callback = None):
  39.         ret = jbuddy.remove(self, callback = callback)
  40.         if self.iswidget:
  41.             
  42.             def goaway():
  43.                 
  44.                 try:
  45.                     pres = Presence(stanza_type = 'unavailable', status = 'Logged Out', to_jid = self.jid)
  46.                     self.protocol.stream.send(pres)
  47.                 except (AttributeError, Exception):
  48.                     pass
  49.  
  50.  
  51.             Timer(3, goaway).start()
  52.         
  53.         return ret
  54.  
  55.     remove = action()(callsback(remove))
  56.     
  57.     def caps(self):
  58.         cs = []
  59.         caps = caps
  60.         import common
  61.         if self.id in self.protocol.bots:
  62.             cs.append(caps.BOT)
  63.         
  64.         if self.iswidget:
  65.             cs.extend([
  66.                 caps.INFO,
  67.                 caps.IM])
  68.         else:
  69.             cs.extend(jbuddy.get_caps(self))
  70.         return cs
  71.  
  72.     caps = property(caps)
  73.     
  74.     def service(self):
  75.         return 'digsby'
  76.  
  77.     service = property(service)
  78.     
  79.     def serviceicon(self):
  80.         skin = skin
  81.         import gui
  82.         return None if not self.iswidget else skin.get('serviceicons.widget')
  83.  
  84.     serviceicon = property(serviceicon)
  85.     
  86.     def update_presence(self, presence, buddy = None):
  87.         groups = jabber_util.xpath_eval(presence.xmlnode, 'd:group', {
  88.             'd': 'digsby:setgroup' })
  89.         if groups:
  90.             self.widget_to_group(groups[0].getContent())
  91.         
  92.         ips = jabber_util.xpath_eval(presence.xmlnode, 'i:ip', {
  93.             'i': ip.IP_NS })
  94.         if ips:
  95.             
  96.             try:
  97.                 self.ip = ip.Ip(ips[0]).ip
  98.  
  99.         
  100.         pagetimes = jabber_util.xpath_eval(presence.xmlnode, 'p:pagetime', {
  101.             'p': pagetime.PAGETIME_NS })
  102.         if pagetimes:
  103.             
  104.             try:
  105.                 self.online_time = pagetime.PageTime(pagetimes[0]).pagetime / 1000
  106.  
  107.         
  108.         jbuddy.update_presence(self, presence, buddy = buddy)
  109.  
  110.     
  111.     def widget_to_group(self, groupname, callback = None):
  112.         log.info('%s add_to_group %s', self, groupname)
  113.         pending = self.pending_adds
  114.         if groupname in pending:
  115.             log.info('ignoring request.')
  116.         else:
  117.             pending.add(groupname)
  118.         item = self.protocol.roster.get_item_by_jid(self.id).clone()
  119.         if groupname not in item.groups:
  120.             item.groups[:] = [
  121.                 groupname]
  122.             query = item.make_roster_push()
  123.             
  124.             def onsuccess(_s):
  125.                 pending.discard(groupname)
  126.                 callback.success()
  127.  
  128.             
  129.             def onerror(_s = (None, None, (None, None, None), None)):
  130.                 pending.discard(groupname)
  131.                 log.warning('error adding %r to %s', self.id, groupname)
  132.                 callback.error()
  133.  
  134.             self.protocol.send_cb(query, success = onsuccess, error = onerror, timeout = onerror)
  135.         
  136.  
  137.     widget_to_group = action(needs = ((unicode, 'Group name'),))(callsback(widget_to_group))
  138.     icon_disabled = property((lambda : True), (lambda : pass))
  139.     
  140.     def __repr__(self):
  141.         
  142.         try:
  143.             res = len(self.resources)
  144.         except:
  145.             res = 0
  146.  
  147.         
  148.         try:
  149.             n = self.name
  150.         except:
  151.             n = ''
  152.  
  153.         return '<DigsbyBuddy %s %d>' % (n, res)
  154.  
  155.  
  156.