From: <sh...@us...> - 2004-04-26 07:42:03
|
Update of /cvsroot/sim-icq/sim/plugins/yahoo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7687/plugins/yahoo Modified Files: yahoosearch.cpp yahoosearch.h Log Message: Fix search action Add yahoo search Index: yahoosearch.cpp =================================================================== RCS file: /cvsroot/sim-icq/sim/plugins/yahoo/yahoosearch.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** yahoosearch.cpp 25 Apr 2004 23:49:45 -0000 1.8 --- yahoosearch.cpp 26 Apr 2004 07:38:50 -0000 1.9 *************** *** 36,44 **** const ext_info genders[] = { ! { I18N_NOOP("Female"), 1 }, ! { I18N_NOOP("Male"), 2 }, { "", 0 } }; YahooSearch::YahooSearch(YahooClient *client, QWidget *parent) : YahooSearchBase(parent) --- 36,49 ---- const ext_info genders[] = { ! { I18N_NOOP("Male"), 1 }, ! { I18N_NOOP("Female"), 2 }, { "", 0 } }; + #if 0 + i18n("male") + i18n("female") + #endif + YahooSearch::YahooSearch(YahooClient *client, QWidget *parent) : YahooSearchBase(parent) *************** *** 59,66 **** --- 64,103 ---- void YahooSearch::search() { + if (grpID->isChecked()){ + search(edtID->text(), 1); + }else if (grpName->isChecked()){ + search(edtName->text(), 2); + }else if (grpKeyword->isChecked()){ + search(edtKeyword->text(), 0); + } + } + + void YahooSearch::search(const QString &text, int type) + { + string url; + url = "http://members.yahoo.com/interests?.oc=m&.kw="; + string kw = getContacts()->fromUnicode(NULL, text); + for (const char *p = kw.c_str(); *p; p++){ + if ((*p <= ' ') || (*p == '&') || (*p == '=')){ + char b[5]; + sprintf(b, "%%%02X", *p & 0xFF); + url += b; + continue; + } + url += *p; + } + url += "&.sb="; + url += number(type); + url += "&.g="; + url += number(getComboValue(cmbGender, genders)); + url += "&.ar="; + url += number(getComboValue(cmbAge, ages)); + url += "&.pg=y"; + fetch(url.c_str()); } void YahooSearch::searchStop() { + stop(); } *************** *** 70,83 **** } ! void YahooSearch::searchName(const QString&, const QString&, const QString&) { } ! bool YahooSearch::done(unsigned, Buffer&, const char*) { emit searchDone(this); return false; } #ifndef WIN32 #include "yahoosearch.moc" --- 107,190 ---- } ! void YahooSearch::searchName(const QString &first, const QString &last, const QString &nick) { + QString s = first; + if (s.isEmpty()) + s = last; + if (s.isEmpty()) + s = nick; + if (s.isEmpty()){ + emit searchDone(this); + return; + } + search(s, 2); } ! bool YahooSearch::done(unsigned code, Buffer &b, const char*) { + if (code == 200){ + QStringList l; + l.append(""); + l.append(i18n("Yahoo! ID")); + l.append("gender"); + l.append(i18n("Gender")); + l.append("age"); + l.append(i18n("Age")); + l.append("location"); + l.append(i18n("Location")); + emit setColumns(l, 0, this); + string data; + b.scan("\x04", data); + b.scan("\x04", data); + b.scan("\x04", data); + b.scan("\x04", data); + b.scan("\x04", data); + b.scan("\x04", data); + while (b.readPos() < b.writePos()){ + b.scan("\x04", data); + if (data.length() < 2) + break; + string id; + id = data.substr(2); + b.scan("\x04", data); + string gender; + b.scan("\x04", gender); + string age; + b.scan("\x04", age); + string location; + b.scan("\x04", location); + b.scan("\x04", data); + log(L_DEBUG, "%s %s", id.c_str(), data.c_str()); + QStringList l; + l.append("Yahoo!_online"); + l.append(id.c_str()); + l.append(id.c_str()); + l.append(i18n(gender.c_str())); + l.append(age.c_str()); + l.append(getContacts()->toUnicode(NULL, location.c_str())); + addItem(l, this); + } + } emit searchDone(this); return false; } + void YahooSearch::createContact(const QString &id, unsigned tmpFlags, Contact *&contact) + { + if (m_client->findContact(id.utf8(), NULL, contact, false, false)) + return; + QString grpName = ""; + Group *grp = NULL; + ContactList::GroupIterator it; + while ((grp = ++it) != NULL){ + if (grp->id()) + break; + } + if (grp) + grpName = grp->getName(); + m_client->findContact(id.utf8(), getContacts()->fromUnicode(NULL, grpName).c_str(), contact, false, false); + contact->setFlags(contact->getFlags() | tmpFlags); + } + #ifndef WIN32 #include "yahoosearch.moc" Index: yahoosearch.h =================================================================== RCS file: /cvsroot/sim-icq/sim/plugins/yahoo/yahoosearch.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** yahoosearch.h 25 Apr 2004 23:49:45 -0000 1.5 --- yahoosearch.h 26 Apr 2004 07:38:50 -0000 1.6 *************** *** 41,47 **** --- 41,49 ---- void searchMail(const QString&); void searchName(const QString&, const QString&, const QString&); + void createContact(const QString&, unsigned tmpFlags, Contact *&contact); protected: YahooClient *m_client; void showEvent(QShowEvent*); + void search(const QString&, int type); bool done(unsigned code, Buffer &data, const char *headers); }; |