home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / jabber / JabberResource.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  5.2 KB  |  150 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from contacts.BuddyListElement import BuddyListElement
  5. from common.Buddy import fileinfo
  6. from util import strip_html, Storage
  7. import common
  8. import jabber
  9. from common.actions import action
  10. from common.Buddy import get_status_orb
  11. GTALK = 'gtalk'
  12. JABBER = 'jabber'
  13. statuses = Storage(dnd = _('Do Not Disturb'), chat = _('Free for Chat'), xa = _('Extended Away'))
  14.  
  15. def MOBILE_RESOURCES():
  16.     if not common.pref('jabber.phone_is_mobile', type = bool, default = False):
  17.         return []
  18.     return [
  19.         'android',
  20.         'BlackBerry',
  21.         'Mobile']
  22.  
  23.  
  24. class JabberResource(BuddyListElement):
  25.     __metaclass__ = common.ActionMeta
  26.     
  27.     def __init__(self, jabber, jid, presence):
  28.         self.jid = jid
  29.         self._set_presence(presence)
  30.         self.name = self.jid.as_unicode()
  31.         self.alias = self.name
  32.         self.protocol = jabber
  33.         self.sms = False
  34.  
  35.     
  36.     def _set_presence(self, presence):
  37.         self.status_msg = presence.get_status()
  38.         self.show = presence.get_show()
  39.         self.priority = presence.get_priority()
  40.  
  41.     
  42.     def get_status_message(self):
  43.         return self.status_msg
  44.  
  45.     
  46.     def set_status_message(self, val):
  47.         self.status_msg = val
  48.  
  49.     status_message = property(get_status_message, set_status_message)
  50.     
  51.     def stripped_msg(self):
  52.         msg = self.status_message
  53.         if msg:
  54.             return strip_html(msg)
  55.         return u''
  56.  
  57.     stripped_msg = property(stripped_msg)
  58.     
  59.     def service(self):
  60.         if self.jid.domain == 'gmail.com':
  61.             return GTALK
  62.         return JABBER
  63.  
  64.     service = property(service)
  65.     
  66.     def away(self):
  67.         if self.away_is_idle:
  68.             if not (self.available):
  69.                 pass
  70.             return not (self.idle)
  71.         return not (self.available)
  72.  
  73.     away = property(away)
  74.     
  75.     def available(self):
  76.         return self.show in jabber.available_show_types
  77.  
  78.     available = property(available)
  79.     
  80.     def away_is_idle(self):
  81.         return self.service == GTALK
  82.  
  83.     away_is_idle = property(away_is_idle)
  84.     
  85.     def idle(self):
  86.         if self.away_is_idle:
  87.             return self.show == 'away'
  88.         return False
  89.  
  90.     idle = property(idle)
  91.     
  92.     def mobile(self):
  93.         if self.jid.resource is not None:
  94.             pass
  95.         return (any,)((lambda .0: for r in .0:
  96. self.jid.resource.startswith(r))(MOBILE_RESOURCES()))
  97.  
  98.     mobile = property(mobile)
  99.     
  100.     def icon(self):
  101.         return False
  102.  
  103.     icon = property(icon)
  104.     
  105.     def pending_auth(self):
  106.         return False
  107.  
  108.     pending_auth = property(pending_auth)
  109.     
  110.     def online(self):
  111.         return True
  112.  
  113.     online = property(online)
  114.     
  115.     def blocked(self):
  116.         return False
  117.  
  118.     blocked = property(blocked)
  119.     
  120.     def long_show(self):
  121.         pass
  122.  
  123.     long_show = property(long_show)
  124.     status_orb = property((lambda self: get_status_orb(self)))
  125.     
  126.     def sightly_status(self):
  127.         status = self.show
  128.         if status:
  129.             return statuses.get(status, status.title())
  130.         return _('Available')
  131.  
  132.     sightly_status = property(sightly_status)
  133.     
  134.     def __repr__(self):
  135.         return '<JabberResource %s>' % self.jid.as_unicode()
  136.  
  137.     
  138.     def send_file(self, filepath = None):
  139.         if filepath is None:
  140.             Hub = Hub
  141.             import hub
  142.             filepath = Hub.getInstance().get_file('Sending file to %s' % self.name)
  143.         
  144.         if filepath:
  145.             self.protocol.send_file(self, fileinfo(filepath))
  146.         
  147.  
  148.     send_file = action()(send_file)
  149.  
  150.