diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2012-10-20 22:27:29 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2012-10-20 22:27:29 +0000 |
commit | 8942a206bef8abef8f6b9c7141d35c50d15049aa (patch) | |
tree | 8749955fc888e5b910e38c9b3721c9f1f5faba50 | |
parent | 01f5b9941dd8c9925fde3dfbb07fb28f41c01b51 (diff) |
- fixed contact search async loading
- added search by email
git-svn-id: http://svn.miranda-ng.org/main/trunk@2008 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/Skype/src/skype.h | 4 | ||||
-rw-r--r-- | protocols/Skype/src/skype_contacts.cpp | 118 | ||||
-rw-r--r-- | protocols/Skype/src/skype_proto.cpp | 31 | ||||
-rw-r--r-- | protocols/Skype/src/skype_proto.h | 7 | ||||
-rw-r--r-- | protocols/Skype/src/skype_subclassing.cpp | 48 | ||||
-rw-r--r-- | protocols/Skype/src/skype_subclassing.h | 21 |
6 files changed, 160 insertions, 69 deletions
diff --git a/protocols/Skype/src/skype.h b/protocols/Skype/src/skype.h index 0c23053a16..564c85dc80 100644 --- a/protocols/Skype/src/skype.h +++ b/protocols/Skype/src/skype.h @@ -55,6 +55,10 @@ #define SKYPE_SETTINGS_LOGIN "SkypeLogin"
#define SKYPE_SETTINGS_PASSWORD "Password"
+#define SKYPE_SEARCH_BYSID 1001
+#define SKYPE_SEARCH_BYEMAIL 1002
+#define SKYPE_SEARCH_BYNAMES 1003
+
extern CSkype* g_skype;
extern HINSTANCE g_hInstance;
diff --git a/protocols/Skype/src/skype_contacts.cpp b/protocols/Skype/src/skype_contacts.cpp index 589ad9fcf0..6d11ef7b43 100644 --- a/protocols/Skype/src/skype_contacts.cpp +++ b/protocols/Skype/src/skype_contacts.cpp @@ -708,7 +708,49 @@ void CSkypeProto::SetAllContactStatus(int status) }
}
-void __cdecl CSkypeProto::SearchContactBySidAsync(void* arg)
+void CSkypeProto::OnSearchCompleted(HANDLE hSearch)
+{
+ this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_SUCCESS, hSearch, 0);
+}
+
+void CSkypeProto::OnContactFinded(HANDLE hSearch, CContact::Ref contact)
+{
+ PROTOSEARCHRESULT isr = {0};
+ isr.cbSize = sizeof(isr);
+ isr.flags = PSR_TCHAR;
+
+ SEString data;
+ contact->GetPropSkypename(data);
+ isr.id = ::mir_utf8decodeW((const char *)data);
+ contact->GetPropDisplayname(data);
+ isr.nick = ::mir_utf8decodeW((const char *)data);
+ {
+ contact->GetPropFullname(data);
+ wchar_t *fullname = ::mir_utf8decodeW((const char*)data);
+
+ wchar_t *first = wcstok(fullname, L" ");
+ wchar_t *last = wcstok(NULL, L" ");
+ if (last != NULL)
+ {
+ last = L"";
+ }
+ isr.firstName = first;
+ isr.lastName = last;
+ }
+ {
+ contact->GetPropEmails(data);
+ wchar_t *emails = ::mir_utf8decodeW((const char*)data);
+
+ wchar_t* main = wcstok(emails, L" ");
+ if (main != NULL)
+ {
+ isr.email = main;
+ }
+ }
+ this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_DATA, hSearch, (LPARAM)&isr);
+}
+
+void __cdecl CSkypeProto::SearchBySidAsync(void* arg)
{
const wchar_t *sid = (wchar_t *)arg;
@@ -716,58 +758,50 @@ void __cdecl CSkypeProto::SearchContactBySidAsync(void* arg) if (hContact)
{
this->ShowNotification(sid, _T("Contact already in your contact list"), 0);
- this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)sid, 0);
+ this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)SKYPE_SEARCH_BYSID, 0);
return;
}
CContactSearch::Ref search; g_skype->CreateIdentitySearch(::mir_u2a(sid), search); - + search.fetch(); + search->SetProtoInfo(this, (HANDLE)SKYPE_SEARCH_BYSID); + search->SetOnContactFindedCallback( + (CContactSearch::OnContactFinded)&CSkypeProto::OnContactFinded); + search->SetOnSearchCompleatedCallback( + (CContactSearch::OnSearchCompleted)&CSkypeProto::OnSearchCompleted); + bool valid; if (!search->IsValid(valid) || !valid || !search->Submit()) { return; } - - CContact::Refs contacts; - search->GetResults(contacts); - for (int i = 0 ; i < contacts.size(); i++) - { - PROTOSEARCHRESULT isr = {0};
- isr.cbSize = sizeof(isr);
- isr.flags = PSR_TCHAR;
-
- SEString data;
- contacts[i]->GetPropSkypename(data);
- isr.id = ::mir_utf8decodeW((const char *)data);
- contacts[i]->GetPropDisplayname(data);
- isr.nick = ::mir_utf8decodeW((const char *)data);
- {
- contacts[i]->GetPropFullname(data);
- wchar_t *fullname = ::mir_utf8decodeW((const char*)data);
-
- wchar_t *first = wcstok(fullname, L" ");
- wchar_t *last = wcstok(NULL, L" ");
- if (last == NULL)
- {
- last = L"";
- }
- isr.firstName = first;
- isr.lastName = last;
- }
- {
- contacts[i]->GetPropEmails(data);
- wchar_t *emails = ::mir_utf8decodeW((const char*)data);
+ search->BlockWhileSearch(); + search->Release(); +}
- wchar_t* main = wcstok(emails, L" ");
- if (main == NULL)
- {
- isr.email = main;
- }
- }
+void __cdecl CSkypeProto::SearchByEmailAsync(void* arg)
+{
+ const wchar_t *email = (wchar_t *)arg;
- this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)sid, (LPARAM)&isr);
- } + CContactSearch::Ref search; + g_skype->CreateContactSearch(search); + search.fetch(); + search->SetProtoInfo(this, (HANDLE)SKYPE_SEARCH_BYEMAIL); + search->SetOnContactFindedCallback( + (CContactSearch::OnContactFinded)&CSkypeProto::OnContactFinded); + search->SetOnSearchCompleatedCallback( + (CContactSearch::OnSearchCompleted)&CSkypeProto::OnSearchCompleted); - this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)sid, 0);
+ bool valid; + if (!search->AddEmailTerm(::mir_u2a(email), valid) || !valid || !search->Submit()) + { + return; + } + search->BlockWhileSearch(); + search->Release();
+}
+
+void __cdecl CSkypeProto::SearchByNamesAsync(void* arg)
+{
}
\ No newline at end of file diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp index c40ce6c854..7c96753ce3 100644 --- a/protocols/Skype/src/skype_proto.cpp +++ b/protocols/Skype/src/skype_proto.cpp @@ -154,7 +154,7 @@ DWORD_PTR __cdecl CSkypeProto:: GetCaps(int type, HANDLE hContact) switch(type)
{
case PFLAGNUM_1:
- return PF1_IM | PF1_BASICSEARCH | PF1_ADDSEARCHRES/* | PF1_SEARCHBYEMAIL | PF1_SEARCHBYNAME*/;
+ return PF1_IM | PF1_BASICSEARCH | PF1_ADDSEARCHRES | PF1_SEARCHBYEMAIL/* | PF1_SEARCHBYNAME*/;
case PFLAGNUM_2:
case PFLAGNUM_3:
return PF2_ONLINE | PF2_SHORTAWAY | PF2_HEAVYDND | PF2_INVISIBLE;
@@ -187,19 +187,34 @@ HANDLE __cdecl CSkypeProto::SearchBasic(const TCHAR* id) if ( !this->IsOnline())
return 0;
- wchar_t *sid = ::mir_tstrdup(id);
- this->ForkThread(&CSkypeProto::SearchContactBySidAsync, sid); + wchar_t *data = ::mir_tstrdup(id);
+ this->ForkThread(&CSkypeProto::SearchBySidAsync, data); - return sid; + return (HANDLE)SKYPE_SEARCH_BYSID; }
-HANDLE __cdecl CSkypeProto::SearchByEmail( const TCHAR* email )
+HANDLE __cdecl CSkypeProto::SearchByEmail(const TCHAR* email)
{
- return 0;
+ if ( !this->IsOnline())
+ return 0;
+
+ wchar_t *data = ::mir_tstrdup(email);
+ this->ForkThread(&CSkypeProto::SearchByEmailAsync, data); + + return (HANDLE)SKYPE_SEARCH_BYEMAIL;
}
-HANDLE __cdecl CSkypeProto::SearchByName( const TCHAR* nick, const TCHAR* firstName, const TCHAR* lastName )
+HANDLE __cdecl CSkypeProto::SearchByName(const TCHAR* nick, const TCHAR* firstName, const TCHAR* lastName)
{
- return 0;
+ PROTOSEARCHRESULT isr = {0};
+ isr.cbSize = sizeof(isr);
+ isr.flags = PSR_TCHAR;
+ isr.nick = ::mir_wstrdup(nick);
+ isr.firstName = ::mir_wstrdup(firstName);
+ isr.lastName = ::mir_wstrdup(lastName);
+
+ this->ForkThread(&CSkypeProto::SearchByNamesAsync, &isr);
+
+ return (HANDLE)SKYPE_SEARCH_BYNAMES;
}
HWND __cdecl CSkypeProto::SearchAdvanced( HWND owner ) { return 0; }
diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index a7c488d8d9..d5ce7bc220 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -139,6 +139,9 @@ protected: void UpdateContactTimezone(HANDLE hContact, CContact::Ref contact);
void UpdateContactProfile(HANDLE hContact, CContact::Ref contact);
+ void OnSearchCompleted(HANDLE hSearch);
+ void OnContactFinded(HANDLE hSearch, CContact::Ref contact);
+
void OnContactChanged(CContact::Ref contact, int prop);
void OnContactListChanged(const ContactRef& contact);
@@ -152,7 +155,9 @@ protected: void SetAllContactStatus(int status);
void __cdecl LoadContactList(void*);
- void __cdecl SearchContactBySidAsync(void*);
+ void __cdecl SearchBySidAsync(void*);
+ void __cdecl SearchByNamesAsync(void*);
+ void __cdecl SearchByEmailAsync(void*);
// utils
static char* GetCountryNameById(int countryId);
diff --git a/protocols/Skype/src/skype_subclassing.cpp b/protocols/Skype/src/skype_subclassing.cpp index 587a4ba6cf..4a2d9773dd 100644 --- a/protocols/Skype/src/skype_subclassing.cpp +++ b/protocols/Skype/src/skype_subclassing.cpp @@ -22,6 +22,11 @@ CConversation* CSkype::newConversation(int oid) return new CConversation(oid, this); } +CContactSearch* CSkype::newContactSearch(int oid) +{ + return new CContactSearch(oid, this); +} + // CAccount CAccount::CAccount(unsigned int oid, SERootObject* root) : Account(oid, root) @@ -96,10 +101,11 @@ void CContactGroup::OnChange(const ContactRef& contact) // CContactSearch -CContactSearch::CContactSearch(unsigned int oid, SERootObject* root) : ContactSearch(oid, root) -{ - this->isSeachFailed = false; - this->isSeachFinished = false; +CContactSearch::CContactSearch(unsigned int oid, SERootObject* root) : ContactSearch(oid, root) +{ + this->proto = NULL; + this->SearchCompletedCallback == NULL; + this->ContactFindedCallback == NULL; } void CContactSearch::OnChange(int prop) @@ -108,10 +114,12 @@ void CContactSearch::OnChange(int prop) { CContactSearch::STATUS status; this->GetPropContactSearchStatus(status); - if (status == FINISHED) + if (status == FINISHED || status == FAILED) + { this->isSeachFinished = true; - if (status == FAILED) - this->isSeachFailed = true; + if (this->proto) + (proto->*SearchCompletedCallback)(this->hSearch); + } } //SEString value = GetProp(prop); @@ -121,18 +129,34 @@ void CContactSearch::OnChange(int prop) void CContactSearch::OnNewResult(const ContactRef& contact, const uint& rankValue) { - Sid::String identity; - contact->GetIdentity(identity); + if (this->proto) + (proto->*ContactFindedCallback)(this->hSearch, contact->ref()); } -void CContactSearch::BlockWhileSearching() +void CContactSearch::BlockWhileSearch() { - this->isSeachFailed = false; this->isSeachFinished = false; - while ( !this->isSeachFailed && !this->isSeachFinished) + this->isSeachFailed = false; + while (!this->isSeachFinished && !this->isSeachFailed) Sleep(1); } +void CContactSearch::SetProtoInfo(CSkypeProto* proto, HANDLE hSearch) +{ + this->proto = proto; + this->hSearch = hSearch; +} + +void CContactSearch::SetOnSearchCompleatedCallback(OnSearchCompleted callback) +{ + this->SearchCompletedCallback = callback; +} + +void CContactSearch::SetOnContactFindedCallback(OnContactFinded callback) +{ + this->ContactFindedCallback = callback; +} + // CContact CContact::CContact(unsigned int oid, SERootObject* root) : Contact(oid, root) diff --git a/protocols/Skype/src/skype_subclassing.h b/protocols/Skype/src/skype_subclassing.h index a8f87a6e50..a4da27ccbd 100644 --- a/protocols/Skype/src/skype_subclassing.h +++ b/protocols/Skype/src/skype_subclassing.h @@ -41,22 +41,30 @@ private: class CContactSearch : public ContactSearch { public: + typedef void (CSkypeProto::* OnSearchCompleted)(HANDLE hSearch); + typedef void (CSkypeProto::* OnContactFinded)(HANDLE hSearch, CContact::Ref contact); + typedef DRef<CContactSearch, ContactSearch> Ref; typedef DRefs<CContactSearch, ContactSearch> Refs; - - bool isSeachFailed; + bool isSeachFinished; + bool isSeachFailed; CContactSearch(unsigned int oid, SERootObject* root); - //void set_controller(CommandContactSearch* controller) { m_controller = controller; } - void OnChange(int prop); void OnNewResult(const ContactRef& contact, const uint& rankValue); - void BlockWhileSearching(); + void SetProtoInfo(CSkypeProto* proto, HANDLE hSearch); + void SetOnSearchCompleatedCallback(OnSearchCompleted callback); + void SetOnContactFindedCallback(OnContactFinded callback); - //CommandContactSearch* m_controller; + void BlockWhileSearch(); +private:
+ HANDLE hSearch;
+ CSkypeProto* proto;
+ OnSearchCompleted SearchCompletedCallback; + OnContactFinded ContactFindedCallback; };
class CContactGroup : public ContactGroup
@@ -106,5 +114,6 @@ public: CAccount* newAccount(int oid);
CContactGroup* newContactGroup(int oid);
CConversation* newConversation(int oid);
+ CContactSearch* newContactSearch(int oid);
CContact* newContact(int oid);
};
\ No newline at end of file |