Ejemplo n.º 1
0
 def local_load(self):
     self.profile.defaultprefs = prefs.defaultprefs()
     for name in self.blob_names:
         b = self.blob_load_cache(name)
         useful_data = b.data
         self.waiting_blobs.discard(name)
         self.profile.update_blob(name, useful_data)
Ejemplo n.º 2
0
 def local_load(self):
     self.profile.defaultprefs = prefs.defaultprefs()
     for name in self.blob_names:
         b = self.blob_load_cache(name)
         useful_data = b.data
         self.waiting_blobs.discard(name)
         self.profile.update_blob(name, useful_data)
Ejemplo n.º 3
0
 def load_from_identity(self, identity = None):
     self.profile.defaultprefs = prefs.defaultprefs()
     for blob_name in self.blob_names:
         try:
             useful_data = identity.load_data(blob_name)
         except Exception:
             useful_data = None
         if useful_data is None:
             useful_data = name_to_obj[blob_name]('0', rawdata=None).data
         blob = name_to_obj[blob_name](data=useful_data)
         useful_data = blob.data
         del blob
         self.waiting_blobs.discard(blob_name)
         self.profile.update_blob(blob_name, useful_data)
Ejemplo n.º 4
0
 def load_from_identity(self, identity=None):
     self.profile.defaultprefs = prefs.defaultprefs()
     for blob_name in self.blob_names:
         try:
             useful_data = identity.load_data(blob_name)
         except Exception:
             useful_data = None
         if useful_data is None:
             useful_data = name_to_obj[blob_name]('0', rawdata=None).data
         blob = name_to_obj[blob_name](data=useful_data)
         useful_data = blob.data
         del blob
         self.waiting_blobs.discard(blob_name)
         self.profile.update_blob(blob_name, useful_data)
Ejemplo n.º 5
0
    def profile_state_changed(self, src, attr, old, new):
        '''
        notify target.
        used to initiate retrieval of blobs from the server
        when the profile goes online
        '''
        assert src == self.profile
        assert attr == 'state'
        from digsby import protocol as digsby_protocol

        if new == digsby_protocol.Statuses.SYNC_PREFS:
            self.profile.defaultprefs = prefs.defaultprefs()
            for blob in self.blob_names:
                b = self.blob_load_cache(blob)
                self.from_cache[blob] = b._data
                self.server_retrieve(blob, str(b.tstamp),
                                     success=self.retrieved_blob,
                                     error=self.blob_failed,
                                     timeout=lambda blob=blob: self.blob_timed_out(blob))
Ejemplo n.º 6
0
    def profile_state_changed(self, src, attr, old, new):
        '''
        notify target.
        used to initiate retrieval of blobs from the server
        when the profile goes online
        '''
        assert src == self.profile
        assert attr == 'state'
        from digsby import protocol as digsby_protocol

        if new == digsby_protocol.Statuses.SYNC_PREFS:
            self.profile.defaultprefs = prefs.defaultprefs()
            for blob in self.blob_names:
                b = self.blob_load_cache(blob)
                self.from_cache[blob] = b._data
                self.server_retrieve(
                    blob,
                    str(b.tstamp),
                    success=self.retrieved_blob,
                    error=self.blob_failed,
                    timeout=lambda blob=blob: self.blob_timed_out(blob))
Ejemplo n.º 7
0
 def get_data(self):
     if self.diskdata is None:
         defaults = prefs.defaultprefs()
         self.diskdata = defaults
     return self.diskdata
Ejemplo n.º 8
0
    def __init__(self, identity):
        Observable.__init__(self)
        ChatProtocol.__init__(self)

        self.identity = identity

        from AccountManager import AccountManager

        self.PreDisconnectHooks  = Delegate()
        self.PostDisconnectHooks = Delegate()

        if not getattr(getattr(sys, 'opts', None), 'limit_log', True):
            DelayedStreamLimiter = lambda s: s
        else:
            from fileutil import DelayedStreamLimiter

        self.consolehandlers = defaultdict(lambda: console_handler_class(DelayedStreamLimiter(sys.stdout)))

        self._status = None

        self.error_count = 0
        self.offline_reason = StateMixin.Reasons.NONE
        self.account_manager = AccountManager(profile = self)
        self.last_hiber_req = None
        self.hibernated = False
        self.linked_observers = False
        self.xfers = ObservableList()
        self.prefs = ObservableDict()
        self.defaultprefs = ObservableDict(prefs.defaultprefs())
        self.quiet = False
        self.prefs_loaded = False

        # set the common.pref lookup to point to our prefs
        import common
        common.set_active_prefs(self.prefs, self.defaultprefs)

        self.prefs.add_observer(self._prefs_changed)

        self.has_authorized = False

        self.statuses = ObservableList()
        self.statuses.add_observer(self._statuses_changed)

        self._xfercount = 0
        self.xfers.add_observer(self._on_file_transfer)

        self.widgets = ObservableList()

        self._encrypter, self._decrypter = util.cryptography.cipher_functions(sha1(self.password.encode('utf8')).digest()[:16])

        self.log_sizes = LogSizeDict()

        global profile
        if profile not in (self, None):
            warnmsg = 'Another DigsbyProfile has been created but the old one is still around!'
            if __debug__:
                raise ValueError(warnmsg)
            else:
                log.critical(warnmsg)

        profile = self  # hack! BuddyListStore needs profile.username

        from contacts.buddyliststore import BuddyListStore
        self.blist = BuddyListStore(self.account_manager.connected_accounts)

        self.set_contact_info = self.blist.set_contact_info
        self.get_contact_info = self.blist.get_contact_info

        from BlobManager import BlobManager
        self.blob_manager = BlobManager(self)

        self.account_manager.add_observer(self.check_loading, 'got_accounts')
        self.account_manager.add_observer(self.on_accounts_loaded, 'accounts_loaded')

        self.blob_manager.add_observer(self.check_loading, 'loading')
        self.loaded = False

        self.OnReturnFromIdle = Delegate()
        self.on_message = PausableDelegate()

        self.OnStatusChange = Delegate()

        self.setup_hub()

        self.idle_timer = None
        self.idle = False

        self.plugins_setup = False
        self.connection = None
        self.setup_plugins()

        self.do_local_load()
Ejemplo n.º 9
0
 def get_data(self):
     if self.diskdata is None:
         defaults = prefs.defaultprefs()
         self.diskdata = defaults
     return self.diskdata
Ejemplo n.º 10
0
def testapp(pypath = None, appname = 'Digsby', skinname = 'default', prefs = None, username = '******',
            on_message = lambda message: None,
            plugins = True, logging = True):
    'A test application framework for test __main__s.'


    if wxMSW: preload_comctrls()

    import gettext, os.path

    import options
    sys.opts, _args = options.parser.parse_args()
    import logextensions

    digsbysite.COLORIZE_EXCEPTIONS = sys.opts.console_color

    # Install gui elements
    gettext.install(appname, unicode=True)

    from bootstrap import install_N_
    install_N_()

    # Create the app
    app = TestApp()
    app.SetAppName(appname)

    # initialize stdpaths
    from stdpaths import init
    init()

    if wxMSW:
        import gui.native.win.winutil as winutil
        winutil.disable_callback_filter()

    from gui import skin
    from gui.toolbox import setuplogging
    if logging:
        import logging
        setuplogging(level=logging.INFO)


    # make wxLogError go to stderr, not popup dialogs
    wx.Log.SetActiveTarget(wx.LogStderr())

    app.PreShutdown = Delegate()

    if pypath is None:
        pypath = discover_digsby_root()

    sys.path.insert(0, pypath)

    skin.set_resource_paths([
                             util.program_dir() / 'res', # Apparently this has to be first?
                             stdpaths.userdata,
                             stdpaths.config,
                             ])

    if plugins:
        from main import init_plugins
        app.plugins = init_plugins()
    else:
        app.plugins = []


    skin.skininit(os.path.join(pypath, 'res'), skinname = skinname)

    from util.threads.threadpool import ThreadPool
    ThreadPool(5)

    from prefs.prefsdata import flatten
    import syck
    from util.observe import ObservableDict


    prefs_path = os.path.join(pypath, 'res', 'defaults.yaml')

    prefs = ObservableDict(prefs) if prefs is not None else ObservableDict()
    prefs.update({'appearance.skin': skinname,
                  'appearance.variant': None,
                  'debug.shell.font': shellfont()})
    import common
    common.set_active_prefs(prefs, {})

    from util.observe import ObservableDict

    sys.modules['digsbyprofile'] = Storage()
    import digsbyprofile
    from common.notifications import default_notifications
    p = digsbyprofile.profile = Storage(name     = username,
                                    username = username,
                                    prefs    = prefs,
                                    on_message = on_message,
                                    notifications = default_notifications)



    f = file(prefs_path)
    defaults = Storage(flatten(syck.load(f)))
    f.close()
    user = ObservableDict(defaults)
    user.update(prefs)

    from prefs.prefsdata import localprefs
    import prefs
    p.defaultprefs = prefs.defaultprefs()
    p.localprefs = localprefs()

    import common
    common.setfakeprefs(user)

    def toggle_prefs(user=user, defaults=defaults):
        import prefs
        prefs.edit(user, defaults, None)

    def toggle_crust(app=app):
        if not getattr(app, 'crust', None):
            import gui.shell
            wins =  wx.GetTopLevelWindows()
            parent = wins[0] if wins else None
            app.crust = gui.shell.PyCrustFrame(None)
            if parent is not None:
                parent.crust = app.crust
            app.crust.Bind(wx.EVT_CLOSE, lambda evt: app.Exit())
        app.crust.toggle_shown()

        # keyboard focus goes to shell prompt
        if app.crust.IsShown():
            app.crust.crust.SetFocus()

    def on_key(e):
        code = e.GetKeyCode()
        if code == wx.WXK_F11:
            toggle_prefs()
        elif code == wx.WXK_F12:
            toggle_crust()
        elif code == wx.WXK_F5:
            from gui import skin
            skin.reload()
        else:
            e.Skip()

    app.Bind(wx.EVT_KEY_DOWN, on_key)
    app.toggle_crust = toggle_crust

    from main import initialize_webkit, SetStatusPrompt
    initialize_webkit()
    app.SetStatusPrompt = SetStatusPrompt

    return app