home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyo (Python 2.6) from __future__ import with_statement import wx from gui.authorizationdialog import AuthorizationDialog from logging import getLogger log = getLogger('hub') info = log.info from util.singletonmixin import Singleton from util.primitives.error_handling import traceguard from util.primitives.funcs import Delegate, get from common import profile, fire, pref from cStringIO import StringIO from PIL import Image import sys from common.protocolmeta import protocols PROMOTE_STRING = '<br><br>I use <a href="http://www.digsby.com">digsby</a>!' class Hub(Singleton): def __init__(self): Singleton.__init__(self) self._locale_obj = None self.getting_profile_for = None def signoff(self): pass def filter_message(self, mobj = None, *a, **k): if mobj is None: return None conv = mobj.conversation conn = conv.protocol if not mobj.buddy: pass buddy = mobj.conversation.buddy if conn.allow_message(buddy, mobj) is False: log.debug('Message from %r is being ignored', buddy) log.debug_s('The message was %r', mobj) return Delegate.VETO def launchurl(self, url): wx.LaunchDefaultBrowser(url) def windowparent(self): wins = wx.GetTopLevelWindows() if wins: return wins[0] def get_file(self, msg = 'Choose a file'): filediag = wx.FileDialog(self.windowparent(), msg) if filediag.ShowModal() == wx.ID_OK: return filediag.GetPath() def get_dir(self, msg = 'Choose a directory'): dirdiag = wx.DirDialog(self.windowparent(), msg) if dirdiag.ShowModal() == wx.ID_OK: return dirdiag.GetPath() def on_conversation(self, convo, quiet = False): log.critical('on_conversation is deprecated and does nothing') def send_message(self, buddy, message): buddy.protocol.send_message(buddy = buddy.name, msg = message) def user_message(self, message, title = ''): wx.CallAfter(wx.MessageBox, message, title) def on_error(self, e): import traceback log.error(traceback.format_exc()) title = get(e, 'header', 'Error:') msg = get(e, 'major', '%s: %s' % (type(e).__name__, str(e))) details = get(e, 'minor', '') close = (_('Close'), (lambda : pass)) fire('error', title = title, msg = msg, details = details, sticky = True, popupid = Exception, buttons = (close,), update = 'replace') def call_later(self, c, *a, **k): c(*a, **k) def on_file_request(self, protocol, xferinfo): type = xferinfo.type if xferinfo not in profile.xfers: if pref('filetransfer.auto_accept_from_blist', default = False) and profile.blist.on_buddylist(xferinfo.buddy): profile.xfers.insert(0, xferinfo) wx.CallAfter(xferinfo.save) else: xferinfo.state = xferinfo.states.WAITING_FOR_YOU notifies = fire('filetransfer.request', buddy = xferinfo.buddy, target = xferinfo) xferinfo.notifications = notifies profile.xfers.insert(0, xferinfo) def on_direct_connect(self, dc): caption = _('%s DirectIM') % dc.protocol.name.capitalize() msg = _('%s wants to directly connect with you. (Your IP address will be revealed.)' % dc.buddy.name) None if self.popup(msg, caption) else dc.decline() def on_invite(self, protocol, buddy, room_name, message = '', on_yes = None, on_no = None): if not pref('messaging.groupchat.enabled', False): log.warning('groupchat pref is off, ignoring chat invite') maybe_safe_call(on_no) return None message = pref('messaging.groupchat.enabled', False) if message else _('\n\nWould you like to join?') buddy_name = getattr(buddy, 'name', unicode(buddy)) if buddy is not None: msg = _('%s has invited you to a group chat%s') % (buddy_name, message) else: msg = _('You have been invited to a group chat.%s') % message def cb(join): if join: None if on_yes is not None else protocol.join_chat_room(room_name) else: maybe_safe_call(on_no) res = fire('chatinvite.received', buddy = buddy, minor = msg, buttons = [ ((_('Join'),), (lambda : on_yes())), ((_('Ignore'),), (lambda : maybe_safe_call(on_no)))]) def after(): if res.had_reaction('Popup'): return None SimpleMessageDialog = SimpleMessageDialog import gui.toolbox protocol_name = protocol.account.protocol_info().name title = protocol_name + _(' Invite') diag = SimpleMessageDialog(None, title = title, message = msg.strip(), ok_caption = _('Join Chat'), icon = protocol.serviceicon.Resized(32), cancel_caption = _('Ignore Invite'), wrap = 450) diag.OnTop = True diag.ShowWithCallback(cb) after = (None, None, (None, None, None, None), wx.CallAfter)(after) def authorize_buddy(self, protocol, buddy, message = '', username_added = None, callback = None): message = message.strip() if message: message = '\n\n"%s"' % message if not getattr(buddy, 'name', None): pass buddy = buddy if callback is None: callback = protocol.authorize_buddy if username_added is None: username_added = protocol.username if buddy != protocol.self_buddy.name: diag_message = _(u'Allow {buddy} to add you ({you}) as a buddy on {protocol}?').format(buddy = buddy, you = username_added, protocol = protocols[protocol.service].name) diag_message += message ad = AuthorizationDialog(protocol, buddy, diag_message, username_added, callback) ad.Show(True) else: callback(buddy, True, username_added) def on_mail(self, protocol, inbox_count, others_count = None): log.info('%s has %s new mail messages', protocol.username, inbox_count) if others_count: log.info('%s has %s new OTHER mail messages', protocol.username, others_count) def send_typing_status(self, buddy, status): buddy.protocol.send_typing_status(buddy.name, status) def set_buddy_icon(self, wximage): img = wximage.PIL (w, h) = img.size max = profile.MAX_ICON_SIZE if w > max or h > max: img = img.Resized(max) imgFile = StringIO() img.save(imgFile, 'PNG', optimize = True) self.set_buddy_icon_file(imgFile.getvalue()) def set_buddy_icon_file(self, bytes): if hasattr(bytes, 'read'): bytes = bytes.read() if not isinstance(bytes, str): raise TypeError isinstance(bytes, str) maxsz = profile.MAX_ICON_SIZE maxbytes = MAX_BLOB_SIZE import digsby.abstract_blob nextsize = maxsz tries = 0 while len(bytes) > maxbytes and tries < 10: log.warning('image (%dx%d) is larger than %d bytes, have to resize', nextsize, nextsize, maxbytes) img = Image.open(StringIO(bytes)).Resized(nextsize) newimg = StringIO() img.save(newimg, 'PNG', optimize = True) bytes = newimg.getvalue() nextsize = max(20, nextsize - 10) tries += 1 log.info('setting %d bytes of icon data (max is %d): %s', len(bytes), maxbytes, bytes[:5]) profile.save_blob('icon', bytes) for acct in profile.account_manager.connected_accounts: traceguard.__enter__() try: acct.connection.set_and_size_icon(bytes) finally: pass def get_locale(self): if not self._locale_obj: self._locale_obj = [ wx.Locale(wx.LANGUAGE_DEFAULT).GetCanonicalName(), sys.getfilesystemencoding()] return self._locale_obj def get_lang_country(self): lang_country = self.get_locale()[0] (lang, country) = lang_country.split('_') return (lang, country.lower().split('@')[0]) def get_country(self): return self.get_lang_country()[1] country = property(get_country) def get_encoding(self): return self.get_locale()[1] def ProcessEvent(self, e): print 'ProcessEvent', e def get_language(self): return self.get_lang_country()[0] language = property(get_language) def getThreadsafeInstance(cls): ThreadsafeGUIProxy = ThreadsafeGUIProxy import events return ThreadsafeGUIProxy(cls.getInstance()) getThreadsafeInstance = classmethod(getThreadsafeInstance) get_instance = Hub.getInstance def diskspace_check(size): return True def maybe_safe_call(cb): v = None return v