Пример #1
0
LiveJournalUserData *LiveJournalClient::findContact(const char *user, Contact *&contact, bool bCreate, bool bJoin)
{
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL) {
        LiveJournalUserData *data;
        ClientDataIterator itc(contact->clientData, this);
        while ((data = (LiveJournalUserData*)(++itc)) != NULL) {
            if (!strcmp(data->User.ptr, user))
                return data;
        }
    }
    if (!bCreate)
        return NULL;
    QString sname = QString::fromUtf8(user);
    if (bJoin) {
        it.reset();
        while ((contact = ++it) != NULL) {
            if (contact->getName().lower() == sname.lower())
                break;;
        }
    }
    if (contact == NULL) {
        contact = getContacts()->contact(0, true);
        contact->setName(sname);
    }
    LiveJournalUserData *data = (LiveJournalUserData*)(contact->clientData.createData(this));
    set_str(&data->User.ptr, user);
    Event e(EventContactChanged, contact);
    e.process();
    return data;
}
Пример #2
0
void YahooClient::loadList(const char *str)
{
    Contact *contact;
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL) {
        YahooUserData *data;
        ClientDataIterator itd(contact->clientData, this);
        while ((data = (YahooUserData*)(++itd)) != NULL) {
            data->bChecked.bValue = (contact->getGroup() == 0);
        }
    }
    if (str) {
        string s = str;
        while (!s.empty()) {
            string line = getToken(s, '\n');
            string grp = getToken(line, ':');
            if (line.empty()) {
                line = grp;
                grp = "";
            }
            while (!line.empty()) {
                string id = getToken(line, ',');
                Contact *contact;
                YahooUserData *data = findContact(id.c_str(), grp.c_str(), contact, false);
                data->bChecked.bValue = true;
            }
        }
    }
    it.reset();
    list<Contact*> forRemove;
    while ((contact = ++it) != NULL) {
        YahooUserData *data;
        ClientDataIterator itd(contact->clientData, this);
        list<YahooUserData*> dataForRemove;
        bool bChanged = false;
        while ((data = (YahooUserData*)(++itd)) != NULL) {
            if (!data->bChecked.bValue) {
                dataForRemove.push_back(data);
                bChanged = true;
            }
        }
        if (!bChanged)
            continue;
        for (list<YahooUserData*>::iterator it = dataForRemove.begin(); it != dataForRemove.end(); ++it)
            contact->clientData.freeData(*it);
        if (contact->clientData.size()) {
            Event e(EventContactChanged, contact);
            e.process();
        } else {
            forRemove.push_back(contact);
        }
    }
    for (list<Contact*>::iterator itr = forRemove.begin(); itr != forRemove.end(); ++itr)
        delete *itr;
}
Пример #3
0
YahooUserData *YahooClient::findContact(const char *id, const char *grpname, Contact *&contact, bool bSend)
{
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL) {
        YahooUserData *data;
        ClientDataIterator itd(contact->clientData);
        while ((data = (YahooUserData*)(++itd)) != NULL) {
            if (data->Login.ptr && !strcmp(id, data->Login.ptr))
                return data;
        }
    }
    it.reset();
    while ((contact = ++it) != NULL) {
        if (contact->getName() == id) {
            YahooUserData *data = (YahooUserData*)contact->clientData.createData(this);
            set_str(&data->Login.ptr, id);
            set_str(&data->Group.ptr, grpname);
            Event e(EventContactChanged, contact);
            e.process();
            return data;
        }
    }
    if (grpname == NULL)
        return NULL;
    Group *grp = NULL;
    if (*grpname) {
        ContactList::GroupIterator it;
        while ((grp = ++it) != NULL)
            if (grp->getName() == QString::fromLocal8Bit(grpname))
                break;
        if (grp == NULL) {
            grp = getContacts()->group(0, true);
            grp->setName(QString::fromLocal8Bit(grpname));
            Event e(EventGroupChanged, grp);
            e.process();
        }
    }
    if (grp == NULL)
        grp = getContacts()->group(0);
    contact = getContacts()->contact(0, true);
    YahooUserData *data = (YahooUserData*)(contact->clientData.createData(this));
    set_str(&data->Login.ptr, id);
    contact->setName(id);
    contact->setGroup(grp->id());
    Event e(EventContactChanged, contact);
    e.process();
    if (bSend)
        addBuddy(data);
    return data;
}
Пример #4
0
JabberUserData *JabberClient::findContact(const char *alias, const char *name, bool bCreate, Contact *&contact)
{
    char *resource = NULL;
    char *p = strchr((char*)alias, '@');
    if (p){
        p = strchr(p, '/');
        if (p){
            *p = 0;
            resource = p + 1;
        }
    }
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL){
        JabberUserData *data;
        ClientDataIterator it(contact->clientData, this);
        while ((data = (JabberUserData*)(++it)) != NULL){
            if (strcmp(data->ID, alias))
                continue;
            if (resource)
                set_str(&data->Resource, resource);
            if (name)
                set_str(&data->Name, name);
            return data;
        }
    }
    if (!bCreate)
        return NULL;
    it.reset();
    QString sname;
    if (name && *name){
        sname = QString::fromUtf8(name).lower();
    }else{
        sname = QString::fromUtf8(alias).lower();
        int pos = sname.find('@');
        if (pos > 0)
            sname = sname.left(pos);
    }
    while ((contact = ++it) != NULL){
        if (contact->getName().lower() == sname.lower()){
            JabberUserData *data = (JabberUserData*)(contact->clientData.createData(this));
            set_str(&data->ID, alias);
            if (resource)
                set_str(&data->Resource, resource);
            if (name)
                set_str(&data->Name, name);
            info_request(data);
            Event e(EventContactChanged, contact);
            e.process();
            return data;
        }
    }
    contact = getContacts()->contact(0, true);
    JabberUserData *data = (JabberUserData*)(contact->clientData.createData(this));
    set_str(&data->ID, alias);
    if (resource)
        set_str(&data->Resource, resource);
    if (name)
        set_str(&data->Name, name);
    contact->setName(sname);
    info_request(data);
    Event e(EventContactChanged, contact);
    e.process();
    return data;
}
Пример #5
0
JabberUserData *JabberClient::findContact(const char *alias, const char *host, const char *name, bool bCreate, Contact *&contact)
{
    char *resource = NULL;
    char *p = strchr((char*)alias, '@');
    if (p){
        *p = 0;
        host = p + 1;
        p = strchr((char*)host, '/');
        if (p){
            *p = 0;
            resource = p + 1;
        }
    }
    if (host == NULL)
        host = data.owner.VHost;
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL){
        JabberUserData *data;
        ClientDataIterator it(contact->clientData, this);
        while ((data = (JabberUserData*)(++it)) != NULL){
            if (strcmp(data->ID, alias) || strcmp(data->VHost, host))
                continue;
            if (resource)
                set_str(&data->Resource, resource);
            if (name)
                set_str(&data->Name, name);
            return data;
        }
    }
    if (!bCreate)
        return NULL;
    it.reset();
    while ((contact = ++it) != NULL){
        QString name = QString::fromUtf8(alias).lower();
        if (name && *name)
            name = QString::fromUtf8(name).lower();
        QString cname = contact->getName().lower();
        if (contact->getName().lower() == name){
            JabberUserData *data = (JabberUserData*)(contact->clientData.createData(this));
            set_str(&data->ID, alias);
            set_str(&data->VHost, host);
            if (resource)
                set_str(&data->Resource, resource);
            if (name)
                set_str(&data->Name, name);
            info_request(data);
            Event e(EventContactChanged, contact);
            e.process();
            return data;
        }
    }
    contact = getContacts()->contact(0, true);
    JabberUserData *data = (JabberUserData*)(contact->clientData.createData(this));
    set_str(&data->ID, alias);
    set_str(&data->VHost, host);
    if (resource)
        set_str(&data->Resource, resource);
    if (name)
        set_str(&data->Name, name);
    contact->setName(QString::fromUtf8(alias));
    if (name && *name)
        contact->setName(QString::fromUtf8(name));
    info_request(data);
    Event e(EventContactChanged, contact);
    e.process();
    return data;
}