home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / contacts / Contact.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  6.7 KB  |  214 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import traceback
  5. from util import callsback
  6. import common.actions as common
  7. action = common.actions.action
  8. ObservableActionMeta = common.actions.ObservableActionMeta
  9. from common import profile
  10. from logging import getLogger
  11. log = getLogger('Contact')
  12. objget = object.__getattribute__
  13. CONTACT_ATTRS = set([
  14.     'id',
  15.     'buddy',
  16.     'remove',
  17.     'watched',
  18.     '__repr__',
  19.     'rename_gui',
  20.     'rename',
  21.     'edit_alerts',
  22.     'alias',
  23.     'get_group',
  24.     'move_to_group__getattr__',
  25.     '__hash__',
  26.     '__cmp__',
  27.     'sort',
  28.     '_notify_dirty'])
  29.  
  30. class Contact(object):
  31.     watched = 'online '.split()
  32.     __metaclass__ = ObservableActionMeta
  33.     
  34.     def __init__(self, buddy, id):
  35.         self.buddy = buddy
  36.         self.id = id
  37.         self._metacontact = None
  38.  
  39.     
  40.     def remove(self):
  41.         self.protocol.remove_buddy(self.id)
  42.  
  43.     
  44.     def _compatible_accounts(self):
  45.         is_compatible = is_compatible
  46.         import common.protocolmeta
  47.         result = []
  48.         for account in profile.connected_accounts:
  49.             if is_compatible(account.protocol, self.buddy.service):
  50.                 result.append(account)
  51.                 continue
  52.         
  53.         return result
  54.  
  55.     
  56.     def _all_buddies(self, check_if_has = False):
  57.         result = []
  58.         for account in self._compatible_accounts():
  59.             connection = account.connection
  60.             if connection:
  61.                 if not check_if_has or connection.has_buddy(self.buddy.name):
  62.                     buddy = connection.get_buddy(self.buddy.name)
  63.                     if buddy is not None:
  64.                         result.append(buddy)
  65.                     
  66.                 
  67.             connection.has_buddy(self.buddy.name)
  68.         
  69.         return result
  70.  
  71.     
  72.     def _is_blocked(self):
  73.         buddies = [ buddy.blocked for buddy in self._all_buddies(check_if_has = True) ]
  74.         if buddies:
  75.             pass
  76.         return bool(all(buddies))
  77.  
  78.     blocked = property(_is_blocked)
  79.     
  80.     def _block_pred(self, block = True, **k):
  81.         if bool(block) ^ self._is_blocked():
  82.             return True
  83.  
  84.     
  85.     def _unblock_pred(self, *a, **k):
  86.         if self._is_blocked():
  87.             return True
  88.  
  89.     
  90.     def block(self, block = True, **k):
  91.         for buddy in self._all_buddies():
  92.             if bool(block) ^ bool(buddy.blocked):
  93.                 buddy.block(block, **k)
  94.                 continue
  95.         
  96.  
  97.     block = action(_block_pred)(block)
  98.     
  99.     def unblock(self, *a, **k):
  100.         self.block(False, *a, **k)
  101.  
  102.     unblock = action(_unblock_pred)(unblock)
  103.     
  104.     def get_notify_dirty(self):
  105.         return self.buddy._notify_dirty
  106.  
  107.     
  108.     def set_notify_dirty(self, value):
  109.         self.buddy._notify_dirty = value
  110.  
  111.     _notify_dirty = property(get_notify_dirty, set_notify_dirty)
  112.     
  113.     def rename_gui(self):
  114.         GetTextFromUser = GetTextFromUser
  115.         import gui.toolbox
  116.         localalias = self.alias
  117.         if localalias is None:
  118.             localalias = ''
  119.         
  120.         s = GetTextFromUser(_('Enter an alias for %s:') % self.name, caption = _('Rename %s') % self.name, default_value = localalias)
  121.         if s is not None:
  122.             if s == '' or s.strip():
  123.                 None(self.rename if s else None)
  124.                 return s
  125.         
  126.  
  127.     rename_gui = action()(rename_gui)
  128.     
  129.     def rename(self, new_alias):
  130.         log.info('setting alias for %r to %r', self, new_alias)
  131.         profile.set_contact_info(self, 'alias', new_alias)
  132.         self.buddy.notify('alias')
  133.  
  134.     
  135.     def edit_alerts(self):
  136.         import gui.pref.prefsdialog as prefsdialog
  137.         prefsdialog.show('notifications')
  138.  
  139.     edit_alerts = action()(edit_alerts)
  140.     
  141.     def alias(self):
  142.         a = profile.get_contact_info(self, 'alias')
  143.         if a:
  144.             return a
  145.         for attr in ('local_alias', 'remote_alias', 'nice_name'):
  146.             
  147.             try:
  148.                 a = getattr(self, attr, None)
  149.             except Exception:
  150.                 a
  151.                 a
  152.                 traceback.print_exc()
  153.                 continue
  154.             except:
  155.                 a
  156.  
  157.             if a:
  158.                 return a
  159.         
  160.         return self.name
  161.  
  162.     alias = property(alias)
  163.     
  164.     def get_group(self):
  165.         g = self.protocol.group_for(self)
  166.         return g
  167.  
  168.     
  169.     def move_to_group(self, groupname, index = 0, callback = None):
  170.         if not isinstance(groupname, basestring):
  171.             raise TypeError, 'groupname must be a string: %r' % groupname
  172.         isinstance(groupname, basestring)
  173.         self.protocol.move_buddy_creating_group(self, groupname, self.get_group(), index, callback = callback)
  174.  
  175.     move_to_group = callsback(move_to_group)
  176.     
  177.     def __getattr__(self, attr):
  178.         if attr in CONTACT_ATTRS:
  179.             return objget(self, attr)
  180.         return getattr(objget(self, 'buddy'), attr)
  181.  
  182.     
  183.     def __repr__(self):
  184.         return '<%s %s>' % (self.__class__.__name__, self.buddy)
  185.  
  186.     
  187.     def __hash__(self):
  188.         b = self.buddy
  189.         id = self.id
  190.         if isinstance(id, bytes):
  191.             id = id.decode('fuzzy utf-8')
  192.         
  193.         return hash(u'/'.join((b.protocol.name, b.protocol.username, b.name, unicode(id))))
  194.  
  195.     
  196.     def __cmp__(self, other):
  197.         if self is other:
  198.             return 0
  199.         return cmp((self.buddy, self.id), (getattr(other, 'buddy', None), getattr(other, 'id', None)))
  200.  
  201.  
  202.  
  203. class ContactCapabilities:
  204.     INFO = 'INFO'
  205.     IM = 'IM'
  206.     FILES = 'FILES'
  207.     PICTURES = 'PICTURES'
  208.     SMS = 'SMS'
  209.     BLOCKABLE = 'BLOCKABLE'
  210.     EMAIL = 'EMAIL'
  211.     BOT = 'BOT'
  212.     VIDEO = 'VIDEO'
  213.  
  214.