Beispiel #1
0
    def accounts_set(self, stanza=None, accounts=None):
        '''
        Handle incoming network changes to the accounts list.
        '''
        if stanza is None:
            assert accounts
        else:
            accounts = digsby.accounts.Accounts(stanza.get_query())

        if self.maybe_delay_accounts(
                lambda: self.accounts_set(accounts=accounts)):
            return

        from digsby.accounts import ADD, UPDATE, DELETE, Accounts

        del_accts = [acct for acct in accounts if acct.action == DELETE]
        add_accts = [
            acct for acct in accounts
            if acct.action == ADD or acct.action == None
        ]
        mod_accts = [acct for acct in accounts if acct.action == UPDATE]
        del_accts = Accounts(del_accts, accounts.order)
        add_accts = Accounts(add_accts, accounts.order)
        mod_accts = Accounts(mod_accts, accounts.order)

        import services.service_provider as sp
        with sp.ServiceProviderContainer(
                self.profile).rebuilding() as container:
            self.acct_del(del_accts)
            self.acct_add(add_accts)
            self.acct_update(mod_accts)
            self.save_all_info()
            container.rebuild(self)
        self.order_set(accounts.order)
Beispiel #2
0
 def add_multi(self, seq):
     import services.service_provider as sp
     with sp.ServiceProviderContainer(
             self.profile).rebuilding() as container:
         for acct, type in seq:
             self.add(acct, type)
         container.rebuild(self)
Beispiel #3
0
    def remove(self, acct):
        import services.service_provider as sp
        with sp.ServiceProviderContainer(
                self.profile).rebuilding() as container:
            log.info('removing account %r', acct)

            with acct.flagged(DELETING):
                if acct.connected and hasattr(acct, 'disable'):
                    with traceguard:
                        acct.disable()
                elif get(acct, 'enabled', False):
                    acct.enabled = False

            removed = False

            for x in self._all_accounts.values():
                try:
                    x.accounts.remove(acct)
                except ValueError:
                    continue
                else:
                    break

            try:
                self.connected_accounts.remove(acct)
            except ValueError:  #ok, so it wasn't in the list
                pass

            self.unwatch_account(acct)

            from gui import toast
            for id in getattr(acct, 'popupids', ()):
                toast.cancel_id(id)

            container.rebuild(self)
Beispiel #4
0
 def _set_order(self, new):
     import services.service_provider as sp
     lookup = dict((v,k) for (k,v) in enumerate(new))
     newlen = len(new)
     for k in ('im','em','so'):
         self._all_accounts[k].accounts.sort(key=lambda a: lookup.get(a.id, newlen))
     container = sp.ServiceProviderContainer(self.profile)
     container.set_order(new)
Beispiel #5
0
def validate(info, MSP, is_new):
    spc = SP.ServiceProviderContainer(common.profile())
    if is_new and spc.has_account(info):
        raise SP.AccountException(_("That account already exists."))

    try:
        sp = hooks.first('digsby.service_provider',
                         impl=MSP.provider_id,
                         raise_hook_exceptions=True,
                         **info)
    except SP.AccountException, e:
        raise e
Beispiel #6
0
    def __init__(self, profile):
        Observable.__init__(self)

        self.accounts_loaded = False

        self.profile = profile
        self.connected_accounts = ObservableList()
        self.reconnect_timers   = {}

        # holds "cancel" objects from Popups
        self.cancellers = {}

        self.profile.add_observer(self.on_state_change,   'state')
        self.profile.add_observer(self.on_offline_change, 'offline_reason')
        self.profile.add_observer(self.profile_state_changed, 'state')

        import wx
        wx.GetApp().OnBuddyListShown.append(lambda *a, **k: Timer(.25,
            threaded(self.release_accounts), *a, **k).start())

        self._hash = sentinel

        self.got_accounts = False

        self.acct_calls = Delegate()
        self.delay_accounts = True
        self.acct_delay_lock = RLock()

        self._all_acct_hash = {}
        self.last_server_order = None

        self._all_accounts = Storage()
        for type_ in ('im', 'em', 'so'):

            s = Storage(accounts = ObservableList(),
                        old = [])

            setattr(self._all_accounts, type_, s)

            # when the order of accounts changes, or accounts are added or deleted,
            # calls profile.accounts_changed('im', list)
            s.accounts.add_observer(getattr(self, type_ + '_accounts_changed'))

        self.accounts = self._all_accounts.im.accounts
        self.emailaccounts = self._all_accounts.em.accounts
        self.socialaccounts = self._all_accounts.so.accounts

        self.buddywatcher = BuddyWatcher()

        import services.service_provider as sp
        container = sp.ServiceProviderContainer(self.profile)
        container.on_order_changed += self._set_order
Beispiel #7
0
 def add_all(self, allnewaccts):
     import services.service_provider as sp
     with sp.ServiceProviderContainer(self.profile).rebuilding() as container:
         from imaccount import Account
         setup = [
                  ('im', is_im_account, Account),
                  ('em', email_accounts, EmailAccount),
                  ('so', social_accounts, social.network),
                 ]
         for type, pred, cls in setup:
             newaccts = self._xfrm_sort(allnewaccts, cls, pred)
             self._add_all(newaccts, type)
         container.rebuild(self)
Beispiel #8
0
    def add(self, acct, type, ignore_on_rebuild=False):
        import services.service_provider as sp
        if ignore_on_rebuild:
            new = (acct,)
        else:
            new = ()
        with sp.ServiceProviderContainer(self.profile).rebuilding(new=new) as container:
            accts = getattr(self._all_accounts, type).accounts

            if acct not in accts:
                accts.append(acct)
                self.watch_account(acct)
                #self.profile.add_account(acct)
            container.rebuild(self)
Beispiel #9
0
    def replace_local(self, accounts, do_save=True):
        '''
        This function should replace the local list with the server list
        '''
        accounts_debug('replace local')
        # find common simple hashes
        server_list = dict((a.min_hash(), a) for a in accounts)
        accounts_debug('server_list: %r, %r', server_list, accounts)
        local_list = dict((a.min_hash(), a) for a in self)
        accounts_debug('local_list: %r, %r', local_list, list(self))
        common = set(server_list.keys()).intersection(set(local_list.keys()))
        accounts_debug('common: %r', common)

        # update
        update = [server_list[k] for k in common]
        accounts_debug('update: %r', update)

        # delete remainder of local list
        local_del = set(local_list.keys()) - common
        accounts_debug('local_del: %r', local_del)
        delete = [local_list[k] for k in local_del]
        accounts_debug('delete: %r', delete)

        # add remainder of new list
        remote_add = set(server_list.keys()) - common
        accounts_debug('remote_add: %r', remote_add)
        add = [server_list[k] for k in remote_add]
        accounts_debug('add: %r', add)

        # get rid of hashes for things that don't exist anymore.
        # can happen between logins when the server has changed,
        # though it should also require something to have happened locally.
        disappeared = (set(self._all_acct_hash.keys()) -
                       set(a.id for a in accounts)) - set(a.id for a in self)
        for k in disappeared:
            self._all_acct_hash.pop(k, None)

        from digsby.accounts.accounts import Accounts
        add = Accounts(add, order=accounts.order)
        import services.service_provider as sp
        with sp.ServiceProviderContainer(
                self.profile).rebuilding() as container:
            self.acct_del(delete)
            self.acct_add(add)
            self.acct_update(update)
            container.rebuild(self)
        self.order_set(accounts.order)
        if do_save: self.save_all_info()
Beispiel #10
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()
Beispiel #11
0
 def _get_order(self):
     self_order = oset([a.id for a in self])
     import services.service_provider as sp
     container = sp.ServiceProviderContainer(self.profile)
     sp_order = oset(container.get_order())
     return list(sp_order | self_order)