示例#1
0
    def add_contact(self, name, account):
        if not isinstance(self.name, unicode):
            raise TypeError('DGroup.name must always be unicode')

        if not isinstance(name, basestring):
            raise TypeError('name must be a string: %s' % type(name))

        from common import profile
        import hub
        x = (name, account.connection.service)
        if x in profile.blist.metacontacts.buddies_to_metas:
            id = list(profile.blist.metacontacts.buddies_to_metas[x])[0].id
            m = profile.blist.metacontacts[id]
            alias = m.alias
            group = list(m.groups)[0][-1]
            message = _('That buddy is already part of metacontact '
                        '"{alias}" in group "{group}."').format(alias=alias, group=group)
            hub.get_instance().user_message(message, _('Add Contact'))


        if account.connection:
            proto = account.connection

            def do_add(groupid):
                proto.add_contact(name, groupid)
                self.protocols.append(proto)
                self.ids.append(groupid)
                self.id_lookup[proto] = groupid

            if proto not in self.protocols:
                # the group doesn't exist yet
                netcall(lambda: proto.add_group(self.name, success = do_add))
            else:
                # the group already exists.
                netcall(lambda: do_add(self.id_lookup[proto]))
示例#2
0
    def OnOk(self, event):

        self.Show(False)

        import hooks
        hooks.notify('digsby.statistics.contact_added')
        proto = self.protocombo.Value.id
        name = self.namefield.Value
        group = self.groupcombo.Value if isinstance(
            self.groupcombo.Value,
            basestring) else self.groupcombo.Value.GetContentAsString()
        alias = self.aliasfield.Value
        accounts = self.accountchecks.theset

        import hub
        from common import profile
        meta = False
        x = None
        for account in accounts:
            with traceguard:
                account.connection.add_new_buddy(name, group, proto, alias)
                x = (name, account.connection.service)
                if x in profile.blist.metacontacts.buddies_to_metas:
                    meta = True

        if meta:
            id = list(profile.blist.metacontacts.buddies_to_metas[x])[0].id
            m = profile.blist.metacontacts[id]
            alias = m.alias
            group = list(m.groups)[0][-1]
            hub.get_instance().user_message(
                "That buddy is already part of metacontact \"" + alias +
                "\" in group \"" + group + "\"")

        self.Close()
示例#3
0
    def OnOk(self,event):

        self.Show(False)

        import hooks; hooks.notify('digsby.statistics.contact_added')
        proto    = self.protocombo.Value.id
        name     = self.namefield.Value
        group    = self.groupcombo.Value if isinstance(self.groupcombo.Value,basestring) else self.groupcombo.Value.GetContentAsString()
        alias    = self.aliasfield.Value
        accounts = self.accountchecks.theset


        import hub
        from common import profile
        meta = False
        x = None
        for account in accounts:
            with traceguard:
                account.connection.add_new_buddy(name, group, proto, alias)
                x = (name, account.connection.service)
                if x in profile.blist.metacontacts.buddies_to_metas:
                    meta = True

        if meta:
            id = list(profile.blist.metacontacts.buddies_to_metas[x])[0].id
            m = profile.blist.metacontacts[id]
            alias = m.alias
            group = list(m.groups)[0][-1]
            hub.get_instance().user_message(
            "That buddy is already part of metacontact \"" + alias +
            "\" in group \"" + group + "\"")

        self.Close()
示例#4
0
    def add_contact(self, name, account):
        if not isinstance(self.name, unicode):
            raise TypeError('DGroup.name must always be unicode')

        if not isinstance(name, basestring):
            raise TypeError('name must be a string: %s' % type(name))

        from common import profile
        import hub
        x = (name, account.connection.service)
        if x in profile.blist.metacontacts.buddies_to_metas:
            id = list(profile.blist.metacontacts.buddies_to_metas[x])[0].id
            m = profile.blist.metacontacts[id]
            alias = m.alias
            group = list(m.groups)[0][-1]
            message = _('That buddy is already part of metacontact '
                        '"{alias}" in group "{group}."').format(alias=alias,
                                                                group=group)
            hub.get_instance().user_message(message, _('Add Contact'))

        if account.connection:
            proto = account.connection

            def do_add(groupid):
                proto.add_contact(name, groupid)
                self.protocols.append(proto)
                self.ids.append(groupid)
                self.id_lookup[proto] = groupid

            if proto not in self.protocols:
                # the group doesn't exist yet
                netcall(lambda: proto.add_group(self.name, success=do_add))
            else:
                # the group already exists.
                netcall(lambda: do_add(self.id_lookup[proto]))
示例#5
0
 def after():
     import hub
     hub.get_instance().on_invite(protocol=protocol,
         buddy=buddy,
         message=message,
         room_name=room_name,
         on_yes=on_yes,
         on_no=on_no)
示例#6
0
    def info(self):
        "Returns a Storage containing the attributes edited by this dialog."

        info = Storage(name=self.name.Value, protocol=self.protocol_name)

        info.protocol, info.name = strip_acct_id(info.protocol, info.name)

        if hasattr(self, "password"):
            info.password_len = len(self.password.Value)
            try:
                info.password = profile.crypt_pw(self.password.Value)
            except UnicodeEncodeError:
                # the database has corrupted the password.
                log.warning("corrupted password")
                info.password = ""
                self.password.Value = ""
                import hub

                hub.get_instance().on_error(
                    "This account's password has been corrupted somehow. Please report it immediately."
                )

        if hasattr(self, "host"):
            info.server = (self.host.Value, int(self.port.Value) if self.port.Value else "")

        if hasattr(self, "remote_alias"):
            info.remote_alias = self.remote_alias.Value

        if hasattr(self, "autologin"):
            info.autologin = bool(self.autologin.Value)

        if hasattr(self, "resource"):
            info.update(
                resource=self.resource.Value,
                priority=try_this(lambda: int(self.priority.Value), DEFAULT_JABBER_PRIORITY),
            )
        #                        ,
        #                        confserver = self.confserver.Value
        if hasattr(self, "dataproxy"):
            info.update(dataproxy=self.dataproxy.Value)

        for d in getattr(self.protocolinfo, "more_details", []):
            attr = d["store"]
            ctrl = getattr(self, attr)
            info[attr] = ctrl.Value

        getattr(self, "info_" + self.formtype, lambda *a: {})(info)

        for info_cb in self.info_callbacks:
            info_cb(info)

        defaults = self.protocolinfo.get("defaults", {})
        for k in defaults:
            if k not in info:
                info[k] = getattr(self.account, k, defaults.get(k))

        return info
示例#7
0
    def info(self):
        'Returns a Storage containing the attributes edited by this dialog.'

        info = Storage(name = self.name.Value,
                       protocol = self.protocol_name)

        info.protocol, info.name = strip_acct_id(info.protocol, info.name)

        if hasattr(self, 'password'):
            info.password_len = len(self.password.Value)
            try:
                info.password = profile.crypt_pw(self.password.Value)
            except UnicodeEncodeError:
                # the database has corrupted the password.
                log.warning('corrupted password')
                info.password = ''
                self.password.Value = ''
                import hub
                hub.get_instance().on_error('This account\'s password has been corrupted somehow. Please report it immediately.')

        if hasattr(self, 'host'):
            info.server = (self.host.Value, int(self.port.Value) if self.port.Value else '')

        if hasattr(self, 'remote_alias'):
            info.remote_alias = self.remote_alias.Value

        if hasattr(self, 'autologin'):
            info.autologin = bool(self.autologin.Value)

        if hasattr(self, 'resource'):
            info.update(resource = self.resource.Value,
                        priority = try_this(lambda: int(self.priority.Value), DEFAULT_JABBER_PRIORITY))
#                        ,
#                        confserver = self.confserver.Value
        if hasattr(self, 'dataproxy'):
            info.update(dataproxy = self.dataproxy.Value)

        for d in getattr(self.protocolinfo, 'more_details', []):
            attr = d['store']
            ctrl = getattr(self, attr)
            info[attr] = ctrl.Value

        getattr(self, 'info_' + self.formtype, lambda *a: {})(info)

        for info_cb in self.info_callbacks:
            info_cb(info)

        defaults = self.protocolinfo.get('defaults', {})
        for k in defaults:
            if k not in info:
                info[k] = getattr(self.account, k, defaults.get(k))

        return info
示例#8
0
    def connect(self, **connect_args):
        # Find the protocol's __init__ method from the import path in ProtocolMeta.py
        log.info('Loading protocol for account %r...', self)
        connection_class = proto_init(self.protocol)

        # were_connected is a list of Accounts that were connected before the
        # status was set to "Offline"
        profile_obj = profile()
        profile_obj.maybe_return_from_offline()

        self.disconnect() # This will close an old connection and remove it from the reconnect_timers map

        import hub
        self.connection = connection_class(self.name, profile_obj.plain_pw(self.password),
                                           hub.get_instance(),
                                           **self.get_options(True))
        self.connection.account = self

        self.connection.add_observer(self.connection_state_changed, 'state', 'offline_reason')

        self.setnotifyif('offline_reason', self.connection.offline_reason)

        # if invisible was not specified, get from the profile's current status
        if 'invisible' not in connect_args:
            connect_args['invisible'] = profile_obj.status.for_account(self).invisible

        self._connect_args = connect_args
        self._reconnect(also_disconnect=False)
示例#9
0
 def onOK():
     if ie.ImageChanged:
         log.info('iconeditor.ImageChanged = True')
         import hub; h = hub.get_instance()
         bytes = ie.Bytes
         h.set_buddy_icon_file(bytes)
         icon_panel.icon = profile.get_icon_bitmap()
示例#10
0
    def _reconnect(self, initial=False):
        if getattr(self, 'connection', None) is not None:
            self.connection.observers.clear()
            self.connection.Disconnect()
            del self.connection

        self.disconnecting = False

        extra = {}
        resource = getattr(getattr(sys, 'opts', None), 'resource', None)
        if resource is not None:
            extra['resource'] = resource
        elif getattr(sys, 'DEV', False):
            extra['resource'] = 'dev'
        import hub
        conn = self.connection = DigsbyProtocol(self.username, self.password,
                                                self, hub.get_instance(),
                                                DIGSBY_SERVER,  # srvs,
                                                do_tls = False,
                                                sasl_md5 = False,
                                                digsby_login=True,
                                                initial=initial,
                                                **extra
                                                )
        conn.account = self

        conn.add_observer(self.connection_state_changed, 'state')
        conn.add_observer(self.offline_changed, 'offline_reason')

        conn.Connect(on_success = getattr(getattr(self, 'callback', None), 'success', None),
                     on_fail = self.connect_error)
示例#11
0
 def onOK():
     if ie.ImageChanged:
         log.info('iconeditor.ImageChanged = True')
         import hub
         h = hub.get_instance()
         bytes = ie.Bytes
         h.set_buddy_icon_file(bytes)
         icon_panel.icon = profile.get_icon_bitmap()
示例#12
0
    def setup_hub(self):
        import hub
        h = hub.get_instance()
        if h.filter_message not in self.on_message:
            self.on_message += h.filter_message

        # register IM windows for incoming messages
        from gui.imwin import on_message
        self.on_message += lambda *a, **k: wx.CallAfter(on_message, *a, **k)

        self.on_message.pause()
示例#13
0
    def get_options(self, type):
        import hub

        opts = dict(user = hub.get_instance())
        opts.update(vars(self))
        opts.pop('accounts')

        acct = self.accounts.get(type, None)
        if acct is not None:
            opts.update(acct.get_options())

            opts.update(name = acct.name,
                        password = acct.password)

        opts.pop('enabled', None)
        opts.pop('protocol', None)
        opts.pop('id', None)
        return opts