예제 #1
0
JabberAdd::JabberAdd(JabberClient *client)
{
    m_client = client;
    m_wizard = NULL;
    m_result = NULL;
    m_idValidator = new IdValidator(edtID);
    edtID->setValidator(m_idValidator);
    connect(tabAdd, SIGNAL(currentChanged(QWidget*)), this, SLOT(currentChanged(QWidget*)));
    connect(edtID, SIGNAL(returnPressed()), this, SLOT(search()));
    connect(edtID, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&)));
    QStringList services;
    for (unsigned i = 0; i < getContacts()->nClients(); i++){
        Client *c = getContacts()->getClient(i);
        if ((c->protocol() != client->protocol()) || (c->getState() != Client::Connected))
            continue;
        JabberClient *jc = static_cast<JabberClient*>(c);
        QString vHost = QString::fromUtf8(jc->VHost().c_str());
        QStringList::Iterator it;
        for (it = services.begin(); it != services.end(); ++it){
            if ((*it) == vHost)
                break;
        }
        if (it != services.end())
            continue;
        services.append(vHost);
    }
    cmbServices->insertStringList(services);
    connect(cmbServices, SIGNAL(activated(const QString&)), this, SLOT(serviceChanged(const QString&)));
    serviceChanged(cmbServices->currentText());
    fillGroup();
}
예제 #2
0
JabberClient *JabberAdd::findClient(const char *host)
{
    for (unsigned i = 0; i < getContacts()->nClients(); i++){
        Client *client = getContacts()->getClient(i);
        if ((client->protocol() != m_client->protocol()) || (client->getState() != Client::Connected))
            continue;
        JabberClient *jc = static_cast<JabberClient*>(client);
        if (!strcmp(jc->VHost().c_str(), host))
            return jc;
    }
    return NULL;
}
예제 #3
0
void JabberAdd::serviceChanged(const QString &host)
{
    JabberClient *client = findClient(host.latin1());
    for (AGENTS_MAP::iterator it = m_agents.begin(); it != m_agents.end(); ++it){
        agentInfo &info = (*it).second;
        if (info.search){
            tabAdd->removePage(info.search);
            delete info.search;
        }
    }
    m_agents.clear();
    if (client)
        client->get_agents();
}
예제 #4
0
void JabberAdd::startSearch()
{
    if (m_result == NULL)
        return;
    JabberClient *client = findClient(cmbServices->currentText().latin1());
    if (client == NULL)
        return;
    if (tabAdd->currentPageIndex() == 0){
        QString jid = edtID->text();
        if (client->add_contact(jid.utf8())){
            unsigned grp_id = 0;
            ContactList::GroupIterator it;
            Group *grp;
            unsigned nGrp = cmbGroup->currentItem();
            while ((grp = ++it) != NULL){
                if (grp->id() == 0)
                    continue;
                if (nGrp-- == 0){
                    grp_id = grp->id();
                    break;
                }
            }
            Contact *contact;
            JabberUserData *data = client->findContact(jid.utf8(), NULL, false, contact);
            if (data && (contact->getGroup() != grp_id)){
                contact->setGroup(grp_id);
                Event e(EventContactChanged, contact);
                e.process();
            }
        }else{
            m_result->setText(i18n("%1 already in contact list") .arg(jid));
        }
    }else if (tabAdd->currentPage()->inherits("JabberSearch")){
        JabberSearch *search = static_cast<JabberSearch*>(tabAdd->currentPage());
        QString condition = search->condition();
        string search_id = client->search(search->id(), NULL, condition.utf8());
        m_result->setSearch(client, search_id.c_str());
    }
}
예제 #5
0
void JabberAdd::startSearch()
{
    if (m_result == NULL)
        return;
    JabberClient *client = findClient(cmbServices->currentText().latin1());
    if (client == NULL)
        return;
    if (tabAdd->currentPageIndex() == 0){
        QString jid = edtID->text();
        unsigned grp_id = 0;
        ContactList::GroupIterator it;
        Group *grp;
        unsigned nGrp = cmbGroup->currentItem();
        while ((grp = ++it) != NULL){
            if (grp->id() == 0)
                continue;
            if (nGrp-- == 0){
                grp_id = grp->id();
                break;
            }
        }
        if (client->add_contact(jid.utf8(), grp_id)){
            m_result->setText(i18n("%1 added to contact list") .arg(jid));
        }else{
            m_result->setText(i18n("%1 is already in contact list") .arg(jid));
        }
        if (m_wizard)
            m_wizard->setFinishEnabled(m_result, true);
    }else if (tabAdd->currentPage()->inherits("JabberSearch")){
        JabberSearch *search = static_cast<JabberSearch*>(tabAdd->currentPage());
        bool bXSearch;
        QString condition = search->condition(bXSearch);
        string search_id = client->search(search->id(), NULL, condition.utf8());
        m_result->setSearch(client, search_id.c_str(), bXSearch);
    }
}