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

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