summaryrefslogtreecommitdiff
path: root/protocols/Skype/src/skype_contacts.cpp
blob: 2943e05e12fb96aa7b2cf5662515d0411052a3fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "skype_proto.h"


void CSkypeProto::OnContactChanged(CContact* contact, int prop)
{
}

HANDLE CSkypeProto::GetContactBySkypeLogin(const char* skypeLogin)
{
	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;

		DBVARIANT dbv;
		if( !DBGetContactSettingString(hContact, this->m_szModuleName, SKYPE_SETTINGS_LOGIN, &dbv))
		{
			if(strcmp(skypeLogin, dbv.pszVal) == 0)
			{
				DBFreeVariant(&dbv);
				return hContact;
			}
			else
				DBFreeVariant(&dbv);
		}
	}

	return 0;
}

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++)
    {
		SEString name;
		SEString skypeLogin;

		int status = ID_STATUS_OFFLINE;
		CContact::AVAILABILITY availability = CContact::OFFLINE;

        this->contactGroup->ContactList[i]->GetPropSkypename(skypeLogin);
        printf("%3d. %s\n", i+1, (const char*)skypeLogin);

		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);
		}

		if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName) == 0 )
		{

			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);
		}

		//HANDLE hContact = AddToContactList(fbu, FACEBOOK_CONTACT_APPROVE, false, fbu->real_name.c_str());
		//DBWriteContactSettingByte(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, FACEBOOK_CONTACT_APPROVE);
	}
}

void CSkypeProto::SetAllContactStatuses(int status)
{
	for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
	    hContact;
	    hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0))
	{
		if (DBGetContactSettingWord(hContact, this->m_szModuleName, SKYPE_SETTINGS_STATUS, ID_STATUS_OFFLINE) == status)
			continue;

		DBWriteContactSettingWord(hContact, this->m_szModuleName, SKYPE_SETTINGS_STATUS, status);
	}
}