Beispiel #1
0
def on_save_account(SP, MSP, info, callback=None):
    if SP is not None:
        for ctype in SP.get_component_types():
            comp = SP.get_component(ctype, create=False)
            if comp is None:
                continue
            conn = getattr(comp, 'connection', None)
            if conn is None:
                continue
            for updatee in getattr(conn, 'needs_update', []):
                try:
                    attr, fname = updatee
                    f = getattr(conn, fname)
                except (TypeError, ValueError) as e:
                    attr = updatee
                    f = lambda v: setattr(conn, attr, v)

                f(info.get(attr))

    if info.get('register', False):
        log.info_s('adding account: %r', info)
        common.profile().register_account(on_success=callback.success,
                                          on_fail=callback.error,
                                          **info)
    else:
        callback.success()
Beispiel #2
0
def on_save_account(SP, MSP, info, callback = None):
    if SP is not None:
        for ctype in SP.get_component_types():
            comp = SP.get_component(ctype, create = False)
            if comp is None:
                continue
            conn = getattr(comp, 'connection', None)
            if conn is None:
                continue
            for updatee in getattr(conn, 'needs_update', []):
                try:
                    attr, fname = updatee
                    f = getattr(conn, fname)
                except (TypeError,ValueError) as e:
                    attr = updatee
                    f = lambda v: setattr(conn, attr, v)

                f(info.get(attr))

    if info.get('register', False):
        log.info_s('adding account: %r', info)
        common.profile().register_account(
             on_success = callback.success,
             on_fail = callback.error,
             **info
        )
    else:
        callback.success()
Beispiel #3
0
    def edit(self, acct, connect=False, parent = None):

        # used to take linkparent

        import hooks, services.service_provider as SP
        sp = SP.get_provider_for_account(acct)
        diag = hooks.first('digsby.services.edit', parent = parent, sp = sp, impl="digsby_service_editor")
        old_offline = acct.offline_reason
        acct.offline_reason = StateMixin.Reasons.NONE

        info = None
        try:
            res = diag.ShowModal()
            from wx import ID_SAVE
            if diag.ReturnCode == ID_SAVE:
                info = diag.RetrieveData()
        finally:
            diag.Destroy()

        if info is None:
            return

        sp.update_info(info)
        sp.update_components(info)

        if not connect:
            return

        for ctype in sp.get_component_types():
            comp = sp.get_component(ctype, create = False)
            if comp is None:
                continue

            if comp is acct:
                #enable it.
                if hasattr(comp, 'enable'):
                    if old_offline == StateMixin.Reasons.BAD_PASSWORD:
                        log.info('comp.Connect() %r', comp)
                        comp.Connect()
                    elif not comp.enabled:
                        log.info('comp.enable() %r', comp)
                        comp.enable()
                else:
                    #UpdateMixin
                    if not comp.enabled:
                        log.info('comp.enabled = True %r', comp)
                        comp.enabled = True
                    else:
                        log.info('comp.Connect() %r', comp)
                        comp.Connect()
            else:
                if comp.enabled and hasattr(comp, 'enable'):
                    log.info('comp.enable() %r', comp)
                    comp.enable()
                else:
                    #UpdateMixin
                    if comp.enabled:
                        log.info('comp.Connect() %r', comp)
                        comp.Connect()
Beispiel #4
0
    def on_mouseclick(self, e):
        e.Skip()
        sp = self.service_provider_from_evt(e)
        if sp is None:
            return

        diag = hooks.first('digsby.services.create', parent = self.Top, sp_info = sp, impl="digsby_service_editor")
        diag.CenterOnParent()
        return_code = diag.ShowModal()

        if return_code != wx.ID_SAVE:
            log.info("Account creation cancelled. Return code = %r", return_code)
            return

        info = diag.extract()
        sp = hooks.first('digsby.service_provider',
                         impl = diag.sp_info.provider_id,
                         **info)

        log.info("Created %r", sp)
        components = []
        types_ = sp.get_component_types()
        if 'im' in types_:
            sp.autologin = True
        for type_ in types_:
            comp = sp.get_component(type_)
            components.append((comp, type_[:2]))
            log.info("\thas component %r: %r", type_, comp)
        import services.service_provider as sp
        with sp.ServiceProviderContainer(profile()).rebuilding() as container:
            profile.account_manager.add_multi(components)
            for comp, type_ in components:
                try:
                    if hasattr(comp, 'enable'):
                        comp.enable()
                    else:
                        comp.enabled = True
                except Exception:
                    print_exc()
                try:
                    on_create = getattr(comp, 'onCreate', None) #CamelCase for GUI code
                    if on_create is not None:
                        on_create()
                except Exception:
                    print_exc()
                if type_ == 'em':
                    hooks.notify('digsby.email.new_account', parent = self.Top, protocol = comp.protocol, **info)
            container.rebuild()