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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. import wx
  6. import cgui
  7. from cgui import LoginWindow, IsMainThread
  8. from traceback import print_exc
  9. DEFAULT_SPLASH_POS = (300, 300)
  10. from cPickle import dump, load
  11. import os.path as os
  12. import sys
  13. import path
  14. import syck
  15. import re
  16. import logging
  17. log = logging.getLogger('loginwindow')
  18.  
  19. try:
  20.     _
  21. except:
  22.     
  23.     _ = lambda s: s
  24.  
  25. SIGN_IN = _('&Sign In')
  26. RESDIR = 'res'
  27. if not True:
  28.     pass
  29. USE_NEW_STORAGE = sys.DEV
  30. import datetime
  31. if datetime.date.today().timetuple()[1:3] == (3, 17):
  32.     digsby_logo_filename = 'digsby_stpatricks.png'
  33. else:
  34.     digsby_logo_filename = 'digsbybig.png'
  35. connection_errors = dict(auth = _('Authentication Error'), connlost = _('Connection Lost'), server = _('We are upgrading Digsby. Please try connecting again in a few minutes.'), client = _('Could not contact remote server. Check your network configuration.'))
  36.  
  37. class DataProblems(object):
  38.     BAD_USERNAME = _('Invalid Digsby Username')
  39.  
  40.  
  41. def GetUserTempDir():
  42.     import stdpaths
  43.     if getattr(sys, 'is_portable', False):
  44.         base_temp = stdpaths.temp / 'digsby'
  45.     else:
  46.         base_temp = stdpaths.userlocaldata
  47.     pth = path.path(base_temp) / 'temp'
  48.     if not pth.isdir():
  49.         os.makedirs(pth)
  50.     
  51.     return pth
  52.  
  53.  
  54. class SplashDiskStorage(object):
  55.     info_default = {
  56.         '': dict(username = '', password = '', save = False, autologin = False, pos = (200, 200)),
  57.         None: dict() }
  58.     last_default = ''
  59.     
  60.     def get_conf_dir(self):
  61.         import stdpaths
  62.         c_dir = stdpaths.userdata
  63.         
  64.         try:
  65.             return c_dir
  66.         finally:
  67.             if not os.path.exists(c_dir):
  68.                 os.mkdir(c_dir)
  69.             
  70.  
  71.  
  72.     
  73.     def get_splash_data_path(self):
  74.         return None(os.path.join, self.get_conf_dir() % self.data_file_name if sys.REVISION == 'dev' else '')
  75.  
  76.     
  77.     def crypt_pws(self, info, codec):
  78.         for user in info:
  79.             if 'password' in info[user]:
  80.                 if codec == 'encode':
  81.                     info[user]['password'] = self.simple_crypt(info[user]['password'].encode('utf8'), keymat = user.encode('utf8'))
  82.                 elif codec == 'decode':
  83.                     info[user]['password'] = self.simple_crypt(info[user]['password'], keymat = user.encode('utf8')).decode('utf8')
  84.                 else:
  85.                     raise AssertionError
  86.             codec == 'encode'
  87.         
  88.  
  89.     
  90.     def simple_crypt(self, s, k = None, keymat = ''):
  91.         raise NotImplementedError
  92.  
  93.     
  94.     def save_to_disk(self, last, info):
  95.         raise NotImplementedError
  96.  
  97.     
  98.     def load_from_disk(self):
  99.         raise NotImplementedError
  100.  
  101.     
  102.     def can_write(self):
  103.         fname = os.path.join(self.get_conf_dir(), '__test__')
  104.         test_data = 'test'
  105.         
  106.         try:
  107.             
  108.             try:
  109.                 f = _[1]
  110.                 f.write(test_data)
  111.             finally:
  112.                 pass
  113.  
  114.             
  115.             try:
  116.                 f = _[2]
  117.                 if f.read() == test_data:
  118.                     return True
  119.             finally:
  120.                 pass
  121.  
  122.             return False
  123.         except Exception:
  124.             return False
  125.         finally:
  126.             
  127.             try:
  128.                 if os.path.exists(fname):
  129.                     os.remove(fname)
  130.             except Exception:
  131.                 pass
  132.  
  133.  
  134.  
  135.  
  136.  
  137. class NewSplashDiskStorage(SplashDiskStorage):
  138.     data_file_name = 'logininfo%s.yaml'
  139.     
  140.     def __init__(self):
  141.         SplashDiskStorage.__init__(self)
  142.         self.fallback = OldSplashDiskStorage()
  143.  
  144.     
  145.     def get_conf_dir(self):
  146.         import stdpaths
  147.         c_dir = stdpaths.userlocaldata
  148.         
  149.         try:
  150.             return c_dir
  151.         finally:
  152.             if not os.path.exists(c_dir):
  153.                 os.makedirs(c_dir)
  154.             
  155.  
  156.  
  157.     
  158.     def simple_crypt(self, s, k = None, keymat = ''):
  159.         RC4 = RC4
  160.         import M2Crypto.RC4
  161.         if k is None:
  162.             k = self._get_key(keymat)
  163.         
  164.         return RC4(k).update(s)
  165.  
  166.     
  167.     def _get_key(self, keymat = ''):
  168.         keys = getattr(self, '_keys', None)
  169.         if keys is None:
  170.             keys = self._keys = { }
  171.         
  172.         key = keys.get(keymat, None)
  173.         if key is not None:
  174.             return key
  175.         sysident = sysident
  176.         import sysident
  177.         self._keys[keymat] = sysident(append = keymat)
  178.         return self._keys[keymat]
  179.  
  180.     
  181.     def load_from_disk(self):
  182.         path = self.get_splash_data_path()
  183.         
  184.         try:
  185.             
  186.             try:
  187.                 f = _[1]
  188.                 all_info = syck.load(f)
  189.             finally:
  190.                 pass
  191.  
  192.             info = all_info.get('users', self.info_default)
  193.             last = all_info.get('last', self.last_default)
  194.             self.crypt_pws(info, 'decode')
  195.         except Exception:
  196.             e = None
  197.             print_exc()
  198.             (last, info) = self.fallback.load_from_disk()
  199.             oldpth = self.fallback.get_splash_data_path()
  200.             if os.path.exists(oldpth):
  201.                 
  202.                 try:
  203.                     os.remove(oldpth)
  204.                 except Exception:
  205.                     print_exc()
  206.                 except:
  207.                     None<EXCEPTION MATCH>Exception
  208.                 
  209.  
  210.             None<EXCEPTION MATCH>Exception
  211.  
  212.         return (last, info)
  213.  
  214.     
  215.     def save_to_disk(self, last, info):
  216.         path = self.get_splash_data_path()
  217.         self.crypt_pws(info, 'encode')
  218.         for_yaml = {
  219.             'users': info,
  220.             'last': last }
  221.         
  222.         try:
  223.             
  224.             try:
  225.                 f = _[1]
  226.                 syck.dump(for_yaml, f)
  227.             finally:
  228.                 pass
  229.  
  230.         except Exception:
  231.             print_exc()
  232.  
  233.         self.crypt_pws(info, 'decode')
  234.         return True
  235.  
  236.  
  237.  
  238. class OldSplashDiskStorage(SplashDiskStorage):
  239.     data_file_name = 'digsby%s.dat'
  240.     
  241.     def simple_crypt(self, s, k = None, keymat = ''):
  242.         RC4 = RC4
  243.         import M2Crypto.RC4
  244.         if k is None:
  245.             k = 'foo'
  246.         
  247.         return RC4(k).update(s)
  248.  
  249.     
  250.     def load_from_disk(self):
  251.         path = self.get_splash_data_path()
  252.         last = self.last_default
  253.         info = self.info_default
  254.         
  255.         try:
  256.             if os.path.exists(path):
  257.                 
  258.                 try:
  259.                     f = _[1]
  260.                     last = load(f)
  261.                     info = load(f)
  262.                 finally:
  263.                     pass
  264.  
  265.                 self.crypt_pws(info, 'decode')
  266.         except Exception:
  267.             e = None
  268.             print_exc()
  269.  
  270.         return (last, info)
  271.  
  272.     
  273.     def save_to_disk(self, last, info):
  274.         path = self.get_splash_data_path()
  275.         self.crypt_pws(info, 'encode')
  276.         
  277.         try:
  278.             
  279.             try:
  280.                 f = _[1]
  281.                 dump(last, f)
  282.                 dump(info, f)
  283.             finally:
  284.                 pass
  285.  
  286.         except Exception:
  287.             print_exc()
  288.  
  289.         self.crypt_pws(info, 'decode')
  290.         return True
  291.  
  292.  
  293.  
  294. class PortableSplashDiskStorage(OldSplashDiskStorage):
  295.     pass
  296.  
  297.  
  298. def res(*a):
  299.     return os.path.join(RESDIR, *a)
  300.  
  301.  
  302. def digsby_icon_filename():
  303.     return res('digsby.ico')
  304.  
  305. _icon_bundle = None
  306.  
  307. def icon_bundle():
  308.     global _icon_bundle
  309.     if _icon_bundle is None:
  310.         _icon_bundle = wx.IconBundleFromFile(digsby_icon_filename(), wx.BITMAP_TYPE_ANY)
  311.     
  312.     return _icon_bundle
  313.  
  314.  
  315. class LoginController(object):
  316.     have_shown_updated = False
  317.     
  318.     def __init__(self, on_success = (lambda : pass), autologin_override = None):
  319.         self.allow_autologin = sys.opts.autologin
  320.         self.cancelling = False
  321.         self.on_success = on_success
  322.         if getattr(sys, 'is_portable', False):
  323.             self._datastore = PortableSplashDiskStorage()
  324.         elif USE_NEW_STORAGE:
  325.             self._datastore = NewSplashDiskStorage()
  326.         else:
  327.             self._datastore = OldSplashDiskStorage()
  328.         self._profile = sentinel
  329.         (username, self.allinfo) = self._datastore.load_from_disk()
  330.         position = self.allinfo.get('pos', DEFAULT_SPLASH_POS)
  331.         login_bitmap = wx.Bitmap(res('digsbybig.png'))
  332.         help_bitmap = wx.Bitmap(res('skins/default/help.png'))
  333.         revision_string = ' '.join((lambda .0: for x in .0:
  334. str(x))((getattr(sys, 'REVISION', ''), getattr(sys, 'TAG', ''), getattr(sys, 'BRAND', ''))))
  335.         self.window = LoginWindow(None, position, login_bitmap, help_bitmap, str(revision_string))
  336.         self.bind_events()
  337.         
  338.         try:
  339.             self._set_frame_icon()
  340.         except Exception:
  341.             print_exc()
  342.  
  343.         cgui.FitInMonitors(self.window)
  344.         
  345.         try:
  346.             info = self.allinfo[username]
  347.         except KeyError:
  348.             info = dict(username = self._get_window_username(), password = '', save = False, autologin = False, pos = DEFAULT_SPLASH_POS)
  349.  
  350.         
  351.         try:
  352.             status_message = self.allinfo[None]['status']
  353.             self.allinfo[None]['status'] = ''
  354.         except KeyError:
  355.             if None not in self.allinfo:
  356.                 self.allinfo[None] = dict(status = '')
  357.             elif 'status' not in self.allinfo[None]:
  358.                 self.allinfo[None]['status'] = ''
  359.             
  360.             status_message = ''
  361.  
  362.         if not status_message:
  363.             if not (self.have_shown_updated) and sys.opts.updated:
  364.                 status_message = _('Update Successful')
  365.                 LoginController.have_shown_updated = True
  366.             
  367.         
  368.         self.set_status(status_message)
  369.         self.apply_info(info)
  370.         if not info['password']:
  371.             autologin_override = False
  372.         
  373.         self._init_state(autologin_override)
  374.  
  375.     
  376.     def _should_show_register(self):
  377.         if sys.opts.register:
  378.             return True
  379.         if not self._datastore.can_write():
  380.             return False
  381.         return not bool(self.allinfo)
  382.  
  383.     
  384.     def _set_frame_icon(self):
  385.         wx.Log.SetActiveTarget(wx.LogStderr())
  386.         wx.Log.EnableLogging(False)
  387.         self.window.SetIcons(icon_bundle())
  388.         wx.Log.EnableLogging(True)
  389.  
  390.     
  391.     def ShowWindow(self):
  392.         self.window.Show()
  393.         self.window.Raise()
  394.  
  395.     
  396.     def DestroyWindow(self):
  397.         import digsbyprofile
  398.         
  399.         try:
  400.             if digsbyprofile.profile and getattr(digsbyprofile.profile, 'connection', None) is not None:
  401.                 digsbyprofile.profile.connection.remove_observer(self.OnStatusChange, 'state')
  402.             
  403.             self.window.Hide()
  404.         finally:
  405.             self.window.Destroy()
  406.  
  407.  
  408.     
  409.     def bind_events(self):
  410.         bind = self.window.Bind
  411.         bind(wx.EVT_CHECKBOX, self.OnCheck)
  412.         bind(wx.EVT_TEXT, self.OnText)
  413.         bind(wx.EVT_BUTTON, self.OnButton, id = wx.ID_OK)
  414.         bind(wx.EVT_BUTTON, self.OnHelpButton, id = LoginWindow.HELPBUTTON)
  415.         bind(wx.EVT_HYPERLINK, self.OnPWLink, id = LoginWindow.FORGOTPASSWORD)
  416.         bind(wx.EVT_HYPERLINK, show_conn_settings, id = LoginWindow.CONNSETTINGS)
  417.         bind(wx.EVT_HYPERLINK, self.OnNoAcct, id = LoginWindow.NOACCOUNT)
  418.         bind(wx.EVT_CLOSE, self.OnClose)
  419.  
  420.     
  421.     def _init_state(self, autologin_override):
  422.         self.OnCheck(None)
  423.         self.OnText(None)
  424.         if self._should_autologin(autologin_override):
  425.             
  426.             def paint():
  427.                 self.window.Refresh()
  428.                 self.window.Update()
  429.  
  430.             wx.CallAfter(paint)
  431.             wx.CallAfter(self.signin)
  432.         
  433.  
  434.     
  435.     def _should_autologin(self, autologin_override):
  436.         if not self.allow_autologin:
  437.             return False
  438.         if autologin_override is not None and not autologin_override:
  439.             return False
  440.         if (not self.window.GetAutoLogin() or autologin_override is not None) and not autologin_override:
  441.             return False
  442.         return True
  443.  
  444.     
  445.     def disconnect_prof(self):
  446.         import digsbyprofile as d
  447.         if d.profile:
  448.             call_later = call_later
  449.             import AsyncoreThread
  450.             call_later(d.profile.disconnect)
  451.             if d.profile is self._profile:
  452.                 self.unwatch_profile(d.profile)
  453.             
  454.         
  455.  
  456.     
  457.     def OnClose(self, evt):
  458.         sys.util_allowed = True
  459.         self.window.Hide()
  460.         self.cleanup()
  461.         wx.CallAfter(self.exit)
  462.  
  463.     
  464.     def cleanup(self):
  465.         
  466.         try:
  467.             self.disconnect_prof()
  468.             self.save_info()
  469.         except Exception:
  470.             print_exc()
  471.  
  472.  
  473.     
  474.     def exit(self):
  475.         
  476.         try:
  477.             self.DestroyWindow()
  478.         except:
  479.             print_exc()
  480.  
  481.         wx.GetApp().DigsbyCleanupAndQuit()
  482.  
  483.     
  484.     def watch_profile(self, p):
  485.         if self._profile is not sentinel:
  486.             self.unwatch_profile(self._profile)
  487.         
  488.         self._profile = p
  489.  
  490.     
  491.     def unwatch_profile(self, p = None):
  492.         if p is None:
  493.             p = self._profile
  494.         
  495.         if p is self._profile:
  496.             self._profile = sentinel
  497.         
  498.  
  499.     
  500.     def OnButton(self, evt):
  501.         self.signin()
  502.  
  503.     
  504.     def signin(self):
  505.         if 'digsbyprofile' not in sys.modules:
  506.             sys.util_allowed = True
  507.             self.set_status(_('Loading...'))
  508.             self.window.EnableControls(False, SIGN_IN, False)
  509.             self.window.Update()
  510.             m2 = m2
  511.             import M2Crypto
  512.             m2.rand_bytes(16)
  513.         
  514.         import digsbyprofile
  515.         if digsbyprofile.profile and digsbyprofile.profile.is_connected:
  516.             self.window.EnableControls(True, SIGN_IN, True)
  517.             self.disconnect_prof()
  518.             self.cancelling = True
  519.         else:
  520.             self.login()
  521.  
  522.     
  523.     def login(self):
  524.         (good_data, reason) = validate_data(self.get_info().values()[0])
  525.         if not good_data:
  526.             self.set_status(reason)
  527.             self.window.EnableControls(True, SIGN_IN, True)
  528.             self.window.Update()
  529.             return None
  530.         self.set_status(_('Connecting...'))
  531.         self.window.EnableControls(False, SIGN_IN)
  532.         self.window.Update()
  533.         self.save_info()
  534.         info = self.allinfo[self._get_window_username()]
  535.         
  536.         def myfunc():
  537.             import digsby
  538.             
  539.             try:
  540.                 print 'calling cb'
  541.                 self.cancelling = False
  542.                 self.on_success(info)
  543.                 import digsbyprofile
  544.                 self.watch_profile(digsbyprofile.profile)
  545.             except digsby.DigsbyLoginError:
  546.                 print 'login error'
  547.                 self.set_status(_('Login error!'))
  548.                 self.window.EnableControls(True, SIGN_IN, True)
  549.                 return None
  550.  
  551.             import digsbyprofile
  552.             if digsbyprofile.profile and getattr(digsbyprofile.profile, 'connection', None) is not None:
  553.                 conn = digsbyprofile.profile.connection
  554.                 cb = self.OnStatusChange
  555.                 conn.add_observer(cb, 'state')
  556.             
  557.  
  558.         wx.CallAfter(myfunc)
  559.  
  560.     
  561.     def OnText(self, evt):
  562.         self._ontextcount = getattr(self, '_ontextcount', 0) + 1
  563.         if getattr(self, '_in_on_text', False):
  564.             return evt.Skip()
  565.         self._in_on_text = True
  566.         
  567.         try:
  568.             if evt is not None:
  569.                 evt.Skip()
  570.             
  571.             window = self.window
  572.             if not hasattr(self, 'allinfo'):
  573.                 return None
  574.             if evt and evt.Id == LoginWindow.USERNAME:
  575.                 if self._get_window_username() in self.allinfo:
  576.                     self.apply_info(self.allinfo[self._get_window_username()], set_username = False)
  577.                 else:
  578.                     window.SetPassword('')
  579.             
  580.             if self._get_window_username():
  581.                 pass
  582.             enabled = bool(window.GetPassword())
  583.             window.FindWindowById(wx.ID_OK).Enable(enabled)
  584.         finally:
  585.             self._in_on_text = False
  586.  
  587.  
  588.     
  589.     def OnCheck(self, evt):
  590.         if not self.window.GetSaveInfo():
  591.             self.window.SetAutoLogin(False)
  592.         
  593.         if evt and evt.GetId() == LoginWindow.SAVEPASSWORD and evt.GetInt() and getattr(sys, 'is_portable', False):
  594.             if not self.do_portable_security_warning():
  595.                 self.window.SetAutoLogin(False)
  596.                 self.window.FindWindowById(LoginWindow.SAVEPASSWORD).Value = False
  597.                 self.save_info()
  598.                 return None
  599.         
  600.         if evt and evt.GetId() in (LoginWindow.SAVEPASSWORD, LoginWindow.AUTOLOGIN):
  601.             self.save_info()
  602.         
  603.  
  604.     
  605.     def do_portable_security_warning(self):
  606.         dlg = wx.MessageDialog(self.window, _('Your password will be saved on your portable device.\n\nAnyone with access to this device will be able to log into your Digsby account. Are you sure you want to save your password?'), _('Security Information'), wx.ICON_EXCLAMATION | wx.YES_NO)
  607.         response = dlg.ShowModal()
  608.         return response == wx.ID_YES
  609.  
  610.     
  611.     def OnPWLink(self, evt):
  612.         wx.LaunchDefaultBrowser('https://accounts.digsby.com/forgot_pw.php')
  613.  
  614.     
  615.     def OnNoAcct(self, evt):
  616.         show_register_page(self.window)
  617.  
  618.     
  619.     def OnHelpButton(self, evt = None):
  620.         wx.LaunchDefaultBrowser('http://wiki.digsby.com')
  621.  
  622.     
  623.     def OnStatusChange(self, src, attr, old, new):
  624.         wx.CallAfter(self.OnStatusChanged, src, attr, old, new)
  625.  
  626.     
  627.     def OnStatusChanged(self, src, attr, old, new):
  628.         if wx.IsDestroyed(self.window):
  629.             print >>sys.stderr, 'Warning: splash screen is Destroyed but still getting notified.'
  630.             return None
  631.         if self.cancelling and new != src.Statuses.OFFLINE:
  632.             src.disconnect()
  633.         
  634.         if new in (src.Statuses.CONNECTING, src.Statuses.AUTHENTICATING, src.Statuses.SYNC_PREFS, src.Statuses.AUTHORIZED):
  635.             self.window.EnableControls(False, SIGN_IN, False)
  636.         
  637.         
  638.         def f():
  639.             if self.cancelling or new == src.Statuses.OFFLINE:
  640.                 if self.cancelling:
  641.                     self.set_status('')
  642.                 else:
  643.                     self.set_status(src.offline_reason)
  644.                 self.window.EnableControls(True, SIGN_IN, True)
  645.             else:
  646.                 self.window.EnableControls(False, SIGN_IN)
  647.                 self.set_status(new)
  648.  
  649.         wx.CallAfter(f)
  650.  
  651.     
  652.     def set_status(self, label, window_title = None, do_conn_error = False):
  653.         conn_fail_message = _('Failed to Connect')
  654.         if not window_title:
  655.             pass
  656.         self.window.SetStatus(label, '')
  657.         if label == _('Authentication Error') and not getattr(self, 'auth_error_fired', False):
  658.             self.auth_error_fired = True
  659.             wx.MessageBox(_('Please make sure you have entered your Digsby username and password correctly.\nIf you need an account or forgot your password, use the links on the login screen. '), _('Authentication Error'))
  660.         
  661.         if do_conn_error:
  662.             if label == conn_fail_message and not getattr(self, 'connect_error_fired', False):
  663.                 self.connect_error_fired = True
  664.                 wx.MessageBox(_('Please check your Internet connection and make sure a firewall isn\'t blocking Digsby.\nIf you connect to the Internet through a proxy server,\nclick the "Connection Settings" link to set up the proxy.\nIf you are still unable to connect, email bugs@digsby.com for technical support.'), _('Failed to Connect'))
  665.             
  666.         
  667.  
  668.     
  669.     def _get_window_username(self):
  670.         return self.window.GetUsername().strip()
  671.  
  672.     
  673.     def get_info(self):
  674.         find = self.window.FindWindowById
  675.         window = self.window
  676.         username = self._get_window_username()
  677.         info_dict = dict(username = username, password = window.GetPassword(), save = window.GetSaveInfo(), autologin = window.GetAutoLogin())
  678.         return {
  679.             username: info_dict }
  680.  
  681.     
  682.     def apply_info(self, info, set_username = True):
  683.         w = self.window
  684.         if set_username:
  685.             w.SetUsername(info['username'])
  686.         
  687.         w.SetPassword(info['password'])
  688.         w.SetSaveInfo(info['save'])
  689.         w.SetAutoLogin(info['autologin'])
  690.  
  691.     
  692.     def set_username(self, username):
  693.         self.window.SetUsername(username)
  694.  
  695.     
  696.     def set_password(self, password):
  697.         self.window.SetPassword(password)
  698.  
  699.     
  700.     def save_info(self):
  701.         username = self._get_window_username()
  702.         self.allinfo.update(self.get_info())
  703.         info = self.allinfo[username]
  704.         password = info['password']
  705.         if not info['save']:
  706.             info['password'] = ''
  707.         
  708.         self.allinfo['pos'] = tuple(self.window.Position)
  709.         self._datastore.save_to_disk(username, self.allinfo)
  710.         if not info['password']:
  711.             info['password'] = password
  712.         
  713.  
  714.     
  715.     def proto_error(self, exc):
  716.         import digsby
  717.         msgbox = None
  718.         if exc is None:
  719.             message = _('Failed to Connect')
  720.         else:
  721.             
  722.             try:
  723.                 raise exc
  724.             except digsby.DigsbyLoginError:
  725.                 if exc.reason == 'auth':
  726.                     message = _('Authentication Error')
  727.                 elif exc.reason == 'connlost':
  728.                     message = _('Connection Lost')
  729.                 else:
  730.                     message = _('Failed to Connect')
  731.                 if exc.reason == 'server':
  732.                     msgbox = _('We are upgrading Digsby. Please try connecting again in a few minutes.')
  733.                 elif exc.reason == 'client':
  734.                     msgbox = _('Could not contact remote server. Check your network configuration.')
  735.                 
  736.             except Exception:
  737.                 print_exc()
  738.                 message = _('Failed to Connect')
  739.  
  740.         self.set_status(message, do_conn_error = True)
  741.         self.window.EnableControls(True, SIGN_IN, True)
  742.         self.disconnect_prof()
  743.         if msgbox is not None:
  744.             wx.MessageBox(msgbox, message)
  745.         
  746.  
  747.  
  748.  
  749. def _ensure_proxy_setup():
  750.     import wx.webview as wx
  751.     f = wx.Frame(None)
  752.     wx.webview.WebView(f)
  753.     f.Destroy()
  754.     import main
  755.     main.set_did_create_webview()
  756.  
  757.  
  758. def _register_frame(splash):
  759.     REGISTER_TITLE = _('Register a Digsby Account')
  760.     REGISTER_SIZE = (675, 421)
  761.     f = wx.Frame(splash, size = REGISTER_SIZE, title = REGISTER_TITLE, style = wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER) | wx.STAY_ON_TOP)
  762.     f.SetBackgroundColour(wx.Color(168, 145, 102))
  763.     
  764.     def paint(e):
  765.         TEXT = _('Loading...')
  766.         dc = wx.PaintDC(f)
  767.         r = f.ClientRect
  768.         dc.Font = f.Font
  769.         (w, h) = dc.GetTextExtent(TEXT)
  770.         (x, y) = r.CenterPoint((w, h))
  771.         dc.Brush = wx.WHITE_BRUSH
  772.         dc.Pen = wx.TRANSPARENT_PEN
  773.         dc.DrawRoundedRectangle(x - 10, y - 10, w + 20, h + 20, 5)
  774.         dc.DrawText(TEXT, x, y)
  775.  
  776.     f.Bind(wx.EVT_PAINT, paint)
  777.     cgui.SetFrameIcon(f, wx.Image(res('skins/default/digsbybig.png')))
  778.     return f
  779.  
  780.  
  781. def show_register_page(splash):
  782.     import wx
  783.     REGISTER_URL = 'https://accounts.digsby.com/reg.php'
  784.     if sys.BRAND is not None:
  785.         REGISTER_URL = REGISTER_URL + '?code=' + sys.BRAND
  786.     
  787.     f = _register_frame(splash)
  788.     f.CenterOnScreen()
  789.     f.Show()
  790.     f.Update()
  791.     f.Sizer = wx.BoxSizer(wx.HORIZONTAL)
  792.     _ensure_proxy_setup()
  793.     UrlQuery = UrlQuery
  794.     import util.net
  795.     import util.checkoptions as util
  796.     import wx.webview as wx
  797.     
  798.     class WebBrowser((wx.webview.WebView,)):
  799.         
  800.         def __init__(self, parent, url = (None,)):
  801.             wx.webview.WebView.__init__(self, parent)
  802.             if url is not None:
  803.                 self.LoadURL(url)
  804.             
  805.  
  806.  
  807.     browser = WebBrowser(f, url = REGISTER_URL)
  808.     browser.SetPosition((-3000, -3000))
  809.     
  810.     def on_nav(url):
  811.         if url.startswith(REGISTER_URL):
  812.             query = UrlQuery.parse(url)['query']
  813.             if query.get('done'):
  814.                 username = query.get('u')
  815.                 if username is not None:
  816.                     splash.FindWindowById(LoginWindow.USERNAME).Value = username
  817.                     
  818.                     def after():
  819.                         splash.FindWindowById(LoginWindow.PASSWORD).SetFocus()
  820.                         splash.Raise()
  821.  
  822.                     after = (wx.CallAfter,)(after)
  823.                 
  824.                 if query.get('s') == 'true':
  825.                     util.checkoptions.set_search_active()
  826.                     util.checkoptions.set_homepage_active()
  827.                 
  828.             
  829.         
  830.  
  831.     
  832.     def on_load(e):
  833.         if e.State == wx.webview.WEBVIEW_LOAD_DOC_COMPLETED:
  834.             on_nav(e.URL)
  835.         else:
  836.             e.Skip()
  837.  
  838.     browser.Bind(wx.webview.EVT_WEBVIEW_LOAD, on_load)
  839.     add_window_open_redirect = add_window_open_redirect
  840.     import gui.browser.webkit.webkitwindow
  841.     add_window_open_redirect(browser, blank_opens_browser = True)
  842.     
  843.     def later():
  844.         f.Sizer.Add(browser, 1, wx.EXPAND)
  845.         f.Layout()
  846.  
  847.     wx.CallLater(500, later)
  848.  
  849.  
  850. def show_conn_settings(evt):
  851.     sys.util_allowed = True
  852.     ProxyDialog = ProxyDialog
  853.     import gui.proxydialog
  854.     import util
  855.     p = ProxyDialog()
  856.     
  857.     def later():
  858.         
  859.         try:
  860.             p.ShowModal()
  861.         except Exception:
  862.             print_exc()
  863.         else:
  864.             import hooks
  865.             hooks.notify('proxy.info_changed', util.GetProxyInfo())
  866.         finally:
  867.             p.Destroy()
  868.  
  869.  
  870.     wx.CallAfter(later)
  871.  
  872.  
  873. def validate_data(info):
  874.     email_regex_string = '^(?:([a-zA-Z0-9_][a-zA-Z0-9_\\-\\.]*)(\\+[a-zA-Z0-9_\\-\\.]+)?@((?:[a-zA-Z0-9\\-_]+\\.?)*[a-zA-Z]{1,4}))$'
  875.     if not re.match(email_regex_string, info['username'] + '@digsby.org'):
  876.         log.error('Bad username: %r', info['username'])
  877.         return (False, DataProblems.BAD_USERNAME)
  878.     return (True, None)
  879.  
  880.