summaryrefslogtreecommitdiff
path: root/protocols/Skype/src/skype_contacts.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2012-10-02 17:48:44 +0000
committerAlexander Lantsev <aunsane@gmail.com>2012-10-02 17:48:44 +0000
commita5ea1613d623ad8d7027ddd402632a842ba5f0af (patch)
tree5b859ebf9309fa8763bc52cca41cb9db52ae832f /protocols/Skype/src/skype_contacts.cpp
parentefea4456e19eb42826af55c9ff327c25291cad3c (diff)
git-svn-id: http://svn.miranda-ng.org/main/trunk@1764 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Skype/src/skype_contacts.cpp')
-rw-r--r--protocols/Skype/src/skype_contacts.cpp186
1 files changed, 109 insertions, 77 deletions
diff --git a/protocols/Skype/src/skype_contacts.cpp b/protocols/Skype/src/skype_contacts.cpp
index 2943e05e12..c5b4aeb513 100644
--- a/protocols/Skype/src/skype_contacts.cpp
+++ b/protocols/Skype/src/skype_contacts.cpp
@@ -5,100 +5,132 @@ void CSkypeProto::OnContactChanged(CContact* contact, int prop)
{
}
-HANDLE CSkypeProto::GetContactBySkypeLogin(const char* skypeLogin)
+bool CSkypeProto::IsSkypeContact(HANDLE hContact)
{
- for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
- hContact;
- hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0))
- {
- //if(!IsMyContact(hContact))
- // continue;
+ return ::CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName) > 0;
+}
- DBVARIANT dbv;
- if( !DBGetContactSettingString(hContact, this->m_szModuleName, SKYPE_SETTINGS_LOGIN, &dbv))
+HANDLE CSkypeProto::GetContactBySkypeName(wchar_t* skypeName)
+{
+ HANDLE hContact = (HANDLE)::CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
+ while (hContact)
+ {
+ if (this->IsSkypeContact(hContact))
{
- if(strcmp(skypeLogin, dbv.pszVal) == 0)
- {
- DBFreeVariant(&dbv);
+ if (::wcscmp(skypeName, this->GetSettingString(hContact, "SkypeName", L"")) == 0)
return hContact;
- }
- else
- DBFreeVariant(&dbv);
}
+
+ hContact = (HANDLE)::CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0);
}
return 0;
}
-void __cdecl CSkypeProto::LoadContactList(void*)
+HANDLE CSkypeProto::AddContactBySkypeName(wchar_t* skypeName, wchar_t* displayName, DWORD flags)
{
- g_skype->GetHardwiredContactGroup(CContactGroup::ALL_KNOWN_CONTACTS, this->contactGroup);
+ HANDLE hContact = this->GetContactBySkypeName(skypeName);
+ if ( !hContact)
+ {
+ hContact = (HANDLE)::CallService(MS_DB_CONTACT_ADD, 0, 0);
+ ::CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName);
- this->contactGroup->GetContacts(this->contactGroup->ContactList);
- fetch(this->contactGroup->ContactList);
+ this->SetSettingString(hContact, "SkypeName", skypeName);
+ this->SetSettingString(hContact, "DisplayName", displayName);
+ //::DBWriteContactSettingWString(hContact, "CList", "MyHandle", displayName);
- for (unsigned int i = 0; i < this->contactGroup->ContactList.size(); i++)
- {
- SEString name;
- SEString skypeLogin;
+ if (flags & PALF_TEMPORARY)
+ {
+ ::DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
+ ::DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
+ }
+ }
+ else
+ {
+ if (!(flags & PALF_TEMPORARY))
+ ::DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
+ }
- int status = ID_STATUS_OFFLINE;
- CContact::AVAILABILITY availability = CContact::OFFLINE;
+ return hContact;
+}
- this->contactGroup->ContactList[i]->GetPropSkypename(skypeLogin);
- printf("%3d. %s\n", i+1, (const char*)skypeLogin);
+int CSkypeProto::SkypeToMirandaStatus(CContact::AVAILABILITY availability)
+{
+ int status = ID_STATUS_OFFLINE;
- HANDLE hContact = this->GetContactBySkypeLogin(skypeLogin);
- if (!hContact)
- {
- hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
- DBWriteContactSettingString(hContact, this->m_szModuleName, SKYPE_SETTINGS_LOGIN, skypeLogin);
- }
+ switch (availability)
+ {
+ case CContact::ONLINE:
+ case CContact::ONLINE_FROM_MOBILE:
+ status = ID_STATUS_ONLINE;
+ break;
+
+ case CContact::AWAY:
+ case CContact::AWAY_FROM_MOBILE:
+ status = ID_STATUS_AWAY;
+ break;
+
+ case CContact::DO_NOT_DISTURB:
+ case CContact::DO_NOT_DISTURB_FROM_MOBILE:
+ status = ID_STATUS_DND;
+ break;
+ }
- if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName) == 0 )
- {
+ return status;
+}
- this->contactGroup->ContactList[i]->GetPropDisplayname(name);
- this->contactGroup->ContactList[i]->GetPropAvailability(availability);
-
- switch (availability)
- {
- case CContact::ONLINE:
- case CContact::ONLINE_FROM_MOBILE:
- status = ID_STATUS_ONLINE;
- break;
-
- case CContact::AWAY:
- case CContact::AWAY_FROM_MOBILE:
- status = ID_STATUS_AWAY;
- break;
-
- case CContact::DO_NOT_DISTURB:
- case CContact::DO_NOT_DISTURB_FROM_MOBILE:
- status = ID_STATUS_DND;
- break;
- }
-
- DBDeleteContactSetting(hContact, "CList", "MyHandle");
-
- /*DBVARIANT dbv;
- if (!this->GetSettingString(this->m_szModuleName,FACEBOOK_KEY_DEF_GROUP,&dbv))
- {
- DBWriteContactSettingTString(hContact,"CList","Group",dbv.ptszVal);
- DBFreeVariant(&dbv);
- }*/
-
- DBWriteContactSettingString(hContact, this->m_szModuleName, SKYPE_SETTINGS_NAME, name);
- DBWriteContactSettingWord(hContact, this->m_szModuleName, SKYPE_SETTINGS_STATUS, ID_STATUS_ONLINE);
- DBWriteContactSettingString(hContact, this->m_szModuleName, SKYPE_SETTINGS_LOGIN, skypeLogin);
- }
- else
- {
- CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0);
- }
+CContact::AVAILABILITY CSkypeProto::MirandaToSkypeStatus(int status)
+{
+ CContact::AVAILABILITY availability = CContact::UNKNOWN;
+
+ switch(this->m_iStatus)
+ {
+ case ID_STATUS_ONLINE:
+ availability = CContact::ONLINE;
+ break;
+
+ case ID_STATUS_AWAY:
+ availability = CContact::AWAY;
+ break;
+
+ case ID_STATUS_DND:
+ availability = CContact::DO_NOT_DISTURB;
+ break;
+
+ case ID_STATUS_INVISIBLE:
+ availability = CContact::INVISIBLE;
+ break;
+ }
- //HANDLE hContact = AddToContactList(fbu, FACEBOOK_CONTACT_APPROVE, false, fbu->real_name.c_str());
- //DBWriteContactSettingByte(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, FACEBOOK_CONTACT_APPROVE);
+ return availability;
+}
+
+void __cdecl CSkypeProto::LoadContactList(void*)
+{
+ g_skype->GetHardwiredContactGroup(CContactGroup::ALL_KNOWN_CONTACTS, this->contactGroup);
+
+ this->contactGroup->GetContacts(this->contactGroup->ContactList);
+ fetch(this->contactGroup->ContactList);
+
+ for (unsigned int i = 0; i < this->contactGroup->ContactList.size(); i++)
+ {
+ //this->contactGroup->ContactList[i]->SetOnContactChangeCallback((OnContactChangeFunc)&CSkypeProto::OnContactChanged, this);
+
+ //SEString sn;
+ //this->contactGroup->ContactList[i]->GetPropSkypename(sn);
+ wchar_t* skypeName = L"1";//::mir_a2u((const char*)sn);
+
+ //SEString dn;
+ //this->contactGroup->ContactList[i]->GetPropDisplayname(dn);
+ wchar_t* displayName = L"1";//::mir_a2u((const char*)dn);
+
+ //HANDLE hContact = this->GetContactBySkypeName(L"321");
+ //if (!hContact)
+ HANDLE hContact = this->AddContactBySkypeName(skypeName, displayName, 0);
+
+ CContact::AVAILABILITY availability;
+ this->contactGroup->ContactList[i]->GetPropAvailability(availability);
+ this->SetSettingWord(hContact, SKYPE_SETTINGS_STATUS, this->SkypeToMirandaStatus(availability));
}
}
@@ -108,9 +140,9 @@ void CSkypeProto::SetAllContactStatuses(int status)
hContact;
hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0))
{
- if (DBGetContactSettingWord(hContact, this->m_szModuleName, SKYPE_SETTINGS_STATUS, ID_STATUS_OFFLINE) == status)
+ if (this->GetSettingWord(hContact, SKYPE_SETTINGS_STATUS, ID_STATUS_OFFLINE) == status)
continue;
- DBWriteContactSettingWord(hContact, this->m_szModuleName, SKYPE_SETTINGS_STATUS, status);
+ this->SetSettingWord(hContact, SKYPE_SETTINGS_STATUS, status);
}
} \ No newline at end of file