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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. import wx
  6. from gui.authorizationdialog import AuthorizationDialog
  7. from logging import getLogger
  8. log = getLogger('hub')
  9. info = log.info
  10. from util.singletonmixin import Singleton
  11. from util import Delegate, traceguard, get
  12. from common import profile, fire
  13. from cStringIO import StringIO
  14. from PIL import Image
  15. import sys
  16. from common.protocolmeta import protocols
  17. PROMOTE_STRING = '<br><br>I use <a href="http://www.digsby.com">digsby</a>!'
  18.  
  19. class Hub(Singleton):
  20.     
  21.     def __init__(self):
  22.         Singleton.__init__(self)
  23.         self._locale_obj = None
  24.         self.getting_profile_for = None
  25.  
  26.     
  27.     def signoff(self):
  28.         pass
  29.  
  30.     
  31.     def filter_message(self, mobj, *a, **k):
  32.         conv = mobj.conversation
  33.         conn = conv.protocol
  34.         if not mobj.buddy:
  35.             pass
  36.         buddy = mobj.conversation.buddy
  37.         if conn.allow_message(buddy, mobj) is False:
  38.             log.debug('Message from %r is being ignored', buddy)
  39.             log.debug_s('The message was %r', mobj)
  40.             return Delegate.VETO
  41.         
  42.  
  43.     
  44.     def launchurl(self, url):
  45.         wx.LaunchDefaultBrowser(url)
  46.  
  47.     
  48.     def windowparent(self):
  49.         wins = wx.GetTopLevelWindows()
  50.         return None if wins else None
  51.  
  52.     
  53.     def get_file(self, msg = 'Choose a file'):
  54.         filediag = wx.FileDialog(self.windowparent(), msg)
  55.         if filediag.ShowModal() == wx.ID_OK:
  56.             return filediag.GetPath()
  57.         
  58.  
  59.     
  60.     def get_dir(self, msg = 'Choose a directory'):
  61.         dirdiag = wx.DirDialog(self.windowparent(), msg)
  62.         return None if dirdiag.ShowModal() == wx.ID_OK else None
  63.  
  64.     
  65.     def on_conversation(self, convo, quiet = False):
  66.         log.critical('on_conversation is deprecated and does nothing')
  67.  
  68.     
  69.     def send_message(self, buddy, message):
  70.         buddy.protocol.send_message(buddy = buddy.name, msg = message)
  71.  
  72.     
  73.     def user_message(self, message, title = ''):
  74.         wx.CallAfter(wx.MessageBox, message, title)
  75.  
  76.     
  77.     def on_error(self, e):
  78.         import traceback
  79.         log.error(traceback.format_exc())
  80.         title = get(e, 'header', 'Error:')
  81.         msg = get(e, 'major', '%s: %s' % (type(e).__name__, str(e)))
  82.         details = get(e, 'minor', '')
  83.         close = (_('Close'), (lambda : pass))
  84.         fire('error', title = title, msg = msg, details = details, sticky = True, popupid = Exception, buttons = (close,), update = 'replace')
  85.  
  86.     
  87.     def call_later(self, c, *a, **k):
  88.         c(*a, **k)
  89.  
  90.     
  91.     def on_file_request(self, protocol, xferinfo):
  92.         type = xferinfo.type
  93.         if xferinfo not in profile.xfers:
  94.             xferinfo.state = xferinfo.states.WAITING_FOR_YOU
  95.             notifies = fire('filetransfer.request', buddy = xferinfo.buddy, target = xferinfo)
  96.             xferinfo.notifications = notifies
  97.             profile.xfers.insert(0, xferinfo)
  98.         
  99.  
  100.     
  101.     def on_direct_connect(self, dc):
  102.         caption = _('%s DirectIM') % dc.protocol.name.capitalize()
  103.         msg = _('%s wants to directly connect with you. (Your IP address will be revealed.)' % dc.buddy.name)
  104.         None if self.popup(msg, caption) else dc.decline()
  105.  
  106.     
  107.     def on_invite(self, protocol, buddy, room_name, message = '', on_yes = None, on_no = None):
  108.         log.info('chat rooms are not implemented')
  109.         return None if on_no is not None else None
  110.  
  111.     
  112.     def authorize_buddy(self, protocol, buddy, message = '', username_added = None, callback = None):
  113.         message = message.strip()
  114.         if message:
  115.             message = '\n\n"%s"' % message
  116.         
  117.         if not getattr(buddy, 'name', None):
  118.             pass
  119.         buddy = buddy
  120.         if callback is None:
  121.             callback = protocol.authorize_buddy
  122.         
  123.         if username_added is None:
  124.             username_added = protocol.username
  125.         
  126.         if buddy != protocol.self_buddy.name:
  127.             diag_message = _(u'Allow %s to add you (%s) as a buddy on %s?%s') % (buddy, username_added, protocols[protocol.service].name, message)
  128.             ad = AuthorizationDialog(protocol, buddy, diag_message, username_added, callback)
  129.             ad.Show(True)
  130.         else:
  131.             callback(buddy, True, username_added)
  132.  
  133.     
  134.     def on_mail(self, protocol, inbox_count, others_count = None):
  135.         log.info('%s has %s new mail messages', protocol.username, inbox_count)
  136.         if others_count:
  137.             log.info('%s has %s new OTHER mail messages', protocol.username, others_count)
  138.         
  139.  
  140.     
  141.     def send_typing_status(self, buddy, status):
  142.         buddy.protocol.send_typing_status(buddy.name, status)
  143.  
  144.     
  145.     def set_buddy_icon(self, wximage):
  146.         img = wximage.PIL
  147.         (w, h) = img.size
  148.         max = profile.MAX_ICON_SIZE
  149.         if w > max or h > max:
  150.             img = img.Resized(max)
  151.         
  152.         imgFile = StringIO()
  153.         img.save(imgFile, 'PNG', optimize = True)
  154.         self.set_buddy_icon_file(imgFile.getvalue())
  155.  
  156.     
  157.     def set_buddy_icon_file(self, bytes):
  158.         if hasattr(bytes, 'read'):
  159.             bytes = bytes.read()
  160.         
  161.         if not isinstance(bytes, str):
  162.             raise TypeError
  163.         
  164.         maxsz = profile.MAX_ICON_SIZE
  165.         maxbytes = MAX_BLOB_SIZE
  166.         import digsby.abstract_blob
  167.         nextsize = maxsz
  168.         tries = 0
  169.         while len(bytes) > maxbytes and tries < 10:
  170.             log.warning('image (%dx%d) is larger than %d bytes, have to resize', nextsize, nextsize, maxbytes)
  171.             img = Image.open(StringIO(bytes)).Resized(nextsize)
  172.             newimg = StringIO()
  173.             img.save(newimg, 'PNG', optimize = True)
  174.             bytes = newimg.getvalue()
  175.             nextsize = max(20, nextsize - 10)
  176.             tries += 1
  177.         log.info('setting %d bytes of icon data (max is %d): %s', len(bytes), maxbytes, bytes[:5])
  178.         profile.save_blob('icon', bytes)
  179.         for acct in profile.account_manager.connected_accounts:
  180.             traceguard.__enter__()
  181.             
  182.             try:
  183.                 acct.connection.set_and_size_icon(bytes)
  184.             finally:
  185.                 pass
  186.  
  187.         
  188.  
  189.     
  190.     def get_locale(self):
  191.         if not self._locale_obj:
  192.             self._locale_obj = [
  193.                 wx.Locale(wx.LANGUAGE_DEFAULT).GetCanonicalName(),
  194.                 sys.getfilesystemencoding()]
  195.         
  196.         return self._locale_obj
  197.  
  198.     
  199.     def get_lang_country(self):
  200.         lang_country = self.get_locale()[0]
  201.         (lang, country) = lang_country.split('_')
  202.         return (lang, country.lower().split('@')[0])
  203.  
  204.     
  205.     def get_country(self):
  206.         return self.get_lang_country()[1]
  207.  
  208.     country = property(get_country)
  209.     
  210.     def get_encoding(self):
  211.         return self.get_locale()[1]
  212.  
  213.     
  214.     def ProcessEvent(self, e):
  215.         print 'ProcessEvent', e
  216.  
  217.     
  218.     def get_language(self):
  219.         return self.get_lang_country()[0]
  220.  
  221.     language = property(get_language)
  222.     
  223.     def getThreadsafeInstance(cls):
  224.         ThreadsafeGUIProxy = ThreadsafeGUIProxy
  225.         import events
  226.         return ThreadsafeGUIProxy(cls.getInstance())
  227.  
  228.     getThreadsafeInstance = classmethod(getThreadsafeInstance)
  229.  
  230. get_instance = Hub.getInstance
  231.  
  232. def diskspace_check(size):
  233.     return True
  234.  
  235.