From 2bc831c184cced2db6ad62bafc1bd6a75fd84c72 Mon Sep 17 00:00:00 2001
From: Alexander Lantsev <aunsane@gmail.com>
Date: Sun, 16 Dec 2012 14:33:05 +0000
Subject: - added SkypeOut contact support

git-svn-id: http://svn.miranda-ng.org/main/trunk@2752 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
---
 protocols/Skype/src/skype_contacts.cpp | 89 +++++++++++++++++++++++-----------
 protocols/Skype/src/skype_database.cpp |  4 +-
 protocols/Skype/src/skype_proto.cpp    |  2 +-
 protocols/Skype/src/skype_proto.h      |  6 +--
 protocols/Skype/src/skype_utils.cpp    |  6 +--
 5 files changed, 70 insertions(+), 37 deletions(-)

(limited to 'protocols/Skype/src')

diff --git a/protocols/Skype/src/skype_contacts.cpp b/protocols/Skype/src/skype_contacts.cpp
index ae73b7bb17..500878ac08 100644
--- a/protocols/Skype/src/skype_contacts.cpp
+++ b/protocols/Skype/src/skype_contacts.cpp
@@ -258,10 +258,17 @@ void CSkypeProto::UpdateContactStatus(HANDLE hContact, CContact::Ref contact)
 	contact->GetPropAvailability(availability);
 	this->SetSettingWord(hContact, SKYPE_SETTINGS_STATUS, this->SkypeToMirandaStatus(availability));
 
-	if (availability == CContact::PENDINGAUTH)
-		this->SetSettingByte(hContact, "Auth", 1);
+	if (availability == CContact::SKYPEOUT)
+	{
+		this->SetSettingWord(hContact, SKYPE_SETTINGS_STATUS, ID_STATUS_OUTTOLUNCH);
+	}
 	else
-		this->DeleteSetting(hContact, "Auth");
+	{
+		if (availability == CContact::PENDINGAUTH)
+			this->SetSettingByte(hContact, "Auth", 1);
+		else
+			this->DeleteSetting(hContact, "Auth");
+	}
 }
 
 void CSkypeProto::UpdateContactStatusMessage(HANDLE hContact, CContact::Ref contact)
@@ -370,7 +377,7 @@ void CSkypeProto::OnContactChanged(CContact::Ref contact, int prop)
 {
 	SEString data;
 	contact->GetPropSkypename(data);
-	wchar_t* sid = ::mir_a2u((const char*)data);
+	const char *sid = (const char*)data;
 	HANDLE hContact = this->GetContactBySid(sid);
 
 	if (hContact)
@@ -387,8 +394,6 @@ void CSkypeProto::OnContactChanged(CContact::Ref contact, int prop)
 				DWORD oldTS = this->GetSettingDword(hContact, "AuthTS");
 				if (newTS > oldTS)
 				{
-					char* sid = ::mir_utf8decodeA((const char*)data);
-					
 					contact->GetPropDisplayname(data);
 					char* nick = ::mir_utf8decodeA((const char*)data);
 					
@@ -524,14 +529,14 @@ bool CSkypeProto::IsProtoContact(HANDLE hContact)
 	return ::CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName) < 0;
 }
 
-HANDLE CSkypeProto::GetContactBySid(const wchar_t* sid)
+HANDLE CSkypeProto::GetContactBySid(const char *sid)
 {
 	HANDLE hContact = db_find_first();
 	while (hContact)
 	{
 		if  (this->IsProtoContact(hContact))
 		{
-			if (::wcscmp(sid, this->GetSettingString(hContact, "sid", L"")) == 0)
+			if (::strcmp(sid, ::DBGetString(hContact, this->m_szModuleName, "sid")) == 0)
 				return hContact;
 		}
 
@@ -560,7 +565,7 @@ HANDLE CSkypeProto::GetContactFromAuthEvent(HANDLE hEvent)
 	return ::DbGetAuthEventContact(&dbei);
 }
 
-HANDLE CSkypeProto::AddContactBySid(const wchar_t* sid, const wchar_t* nick, DWORD flags)
+HANDLE CSkypeProto::AddContactBySid(const char* sid, const wchar_t* nick, DWORD flags)
 {
 	HANDLE hContact = this->GetContactBySid(sid);
 	if ( !hContact)
@@ -568,12 +573,11 @@ HANDLE CSkypeProto::AddContactBySid(const wchar_t* sid, const wchar_t* nick, DWO
 		hContact = (HANDLE)::CallService(MS_DB_CONTACT_ADD, 0, 0);
 		::CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName);
 
-		this->SetSettingString(hContact, "sid", sid);
+		::DBWriteContactSettingString(hContact, this->m_szModuleName, "sid", sid);
 		this->SetSettingString(hContact, "Nick", nick);
-		this->SetSettingByte(hContact, "Auth", 1);
-
+		
 		CContact::Ref contact;
-		if (g_skype->GetContact(::mir_u2a(sid), contact))
+		if (g_skype->GetContact(sid, contact))
 		{
 			contact.fetch();
 			bool result;
@@ -588,12 +592,22 @@ HANDLE CSkypeProto::AddContactBySid(const wchar_t* sid, const wchar_t* nick, DWO
 			}
 		}
 
-		this->UpdateContactProfile(hContact, contact);
-
-		if (flags & PALF_TEMPORARY)
+		if (flags & 256)
 		{
-			::DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
-			::DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
+			this->SetSettingByte(hContact, "IsSkypeOut", 1);
+		}
+		else
+		{
+			this->SetSettingByte(hContact, "Auth", 1);
+			::DBDeleteContactSetting(hContact, this->m_szModuleName, "IsSkypeOut");
+
+			this->UpdateContactProfile(hContact, contact);
+
+			if (flags & PALF_TEMPORARY)
+			{
+				::DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
+				::DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
+			}
 		}
 	}
 	else
@@ -676,18 +690,25 @@ void __cdecl CSkypeProto::LoadContactList(void*)
 		SEString data;
 
 		contact->GetPropSkypename(data);
-		wchar_t* sid = ::mir_utf8decodeW((const char*)data);
+		const char *sid = (const char *)data;
 
 		contact->GetPropDisplayname(data);
-		wchar_t* nick = ::mir_utf8decodeW((const char*)data);
+		wchar_t *nick = ::mir_utf8decodeW((const char *)data);
 
 		contact->GetPropFullname(data);
-		wchar_t* name = ::mir_utf8decodeW((const char*)data);
+		wchar_t *name = ::mir_utf8decodeW((const char *)data);
 
 		DWORD flags = 0;
 		CContact::AVAILABILITY availability;
 		contact->GetPropAvailability(availability);
-		if (availability == CContact::PENDINGAUTH)
+
+		if (availability == CContact::SKYPEOUT)
+		{
+			flags |= 256;
+			contact->GetPropPstnnumber(data);
+			sid = (const char *)data;
+		}
+		else if (availability == CContact::PENDINGAUTH)
 			flags = PALF_TEMPORARY;
 
 		HANDLE hContact = this->AddContactBySid(sid, nick, flags);
@@ -722,16 +743,25 @@ void __cdecl CSkypeProto::LoadContactList(void*)
 		contact->GetPropAuthreqTimestamp(newTS);
 
 		contact->GetPropSkypename(data);
-		char* sid = ::mir_utf8decodeA((const char*)data);
+		const char* sid = (const char *)data;
+		
+		CContact::AVAILABILITY availability;
+		contact->GetPropAvailability(availability);
+
+		if (availability == CContact::SKYPEOUT)
+		{
+			contact->GetPropPstnnumber(data);
+			sid = (const char*)data;
+		}
 					
 		contact->GetPropDisplayname(data);
-		char* nick = ::mir_utf8decodeA((const char*)data);
+		char* nick = ::mir_utf8decodeA((const char *)data);
 					
 		contact->GetPropReceivedAuthrequest(data);
-		char* reason = ::mir_utf8decodeA((const char*)data);
+		char* reason = ::mir_utf8decodeA((const char *)data);
 
 		contact->GetPropFullname(data);
-		char* fullname = ::mir_utf8decodeA((const char*)data);
+		char* fullname = ::mir_utf8decodeA((const char *)data);
 
 		char* first = strtok(fullname, " ");
 		char* last = strtok(NULL, " ");
@@ -747,8 +777,11 @@ void CSkypeProto::SetAllContactStatus(int status)
 	while (hContact)
 	{
 		if  (this->IsProtoContact(hContact))
+		{
 			//if ( !this->GetSettingWord(hContact, SKYPE_SETTINGS_STATUS, ID_STATUS_OFFLINE) == status)
+			if( this->GetSettingByte(hContact, "IsSkypeOut", 0) == 0)
 				this->SetSettingWord(hContact, SKYPE_SETTINGS_STATUS, status);
+		}
 		hContact = db_find_next(hContact);
 	}
 }
@@ -790,7 +823,7 @@ void CSkypeProto::OnContactFinded(HANDLE hSearch, CContact::Ref contact)
 
 void __cdecl CSkypeProto::SearchBySidAsync(void* arg)
 {
-	const wchar_t *sid = (wchar_t *)arg;
+	const char *sid = (char *)arg;
 
 	HANDLE hContact = this->GetContactBySid(sid);
 	if (hContact)
@@ -801,7 +834,7 @@ void __cdecl CSkypeProto::SearchBySidAsync(void* arg)
 	}
 
 	CContactSearch::Ref search;
-	g_skype->CreateIdentitySearch(::mir_u2a(sid), search);
+	g_skype->CreateIdentitySearch(sid, search);
 	search.fetch();
 	search->SetProtoInfo(this, (HANDLE)SKYPE_SEARCH_BYSID);
 	search->SetOnContactFindedCallback(
diff --git a/protocols/Skype/src/skype_database.cpp b/protocols/Skype/src/skype_database.cpp
index c303f8b3aa..6c583374a5 100644
--- a/protocols/Skype/src/skype_database.cpp
+++ b/protocols/Skype/src/skype_database.cpp
@@ -27,7 +27,7 @@ void CSkypeProto::RaiseAuthRequestEvent(
 
 	CCSDATA ccs = {0};
 	ccs.szProtoService = PSR_AUTH;
-	ccs.hContact = this->AddContactBySid(::mir_a2u(sid), ::mir_a2u(nick));
+	ccs.hContact = this->AddContactBySid(sid, ::mir_a2u(nick));
 	ccs.wParam = 0;
 	ccs.lParam = (LPARAM)&pre;
 	pre.timestamp = timestamp;
@@ -64,7 +64,7 @@ void CSkypeProto::RaiseMessageReceivedEvent(
 
 	CCSDATA ccs = {0};
 	ccs.szProtoService = PSR_MESSAGE;
-	ccs.hContact = this->AddContactBySid(::mir_a2u(sid), ::mir_a2u(nick));
+	ccs.hContact = this->AddContactBySid(sid, ::mir_a2u(nick));
 	ccs.wParam = 0;
 	ccs.lParam = (LPARAM)&pre;
 	pre.flags = PREF_UTF;
diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp
index f325c549a0..8d4515b9fc 100644
--- a/protocols/Skype/src/skype_proto.cpp
+++ b/protocols/Skype/src/skype_proto.cpp
@@ -44,7 +44,7 @@ CSkypeProto::~CSkypeProto()
 
 HANDLE __cdecl CSkypeProto::AddToList(int flags, PROTOSEARCHRESULT* psr) 
 {
-	return this->AddContactBySid(psr->id, psr->nick, 0);
+	return this->AddContactBySid(::mir_u2a(psr->id), psr->nick, 0);
 }
 
 HANDLE __cdecl CSkypeProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent) 
diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h
index 3e17a5d906..f7a057a306 100644
--- a/protocols/Skype/src/skype_proto.h
+++ b/protocols/Skype/src/skype_proto.h
@@ -203,9 +203,9 @@ protected:
 	void	OnContactListChanged(const ContactRef& contact);
 	
 	bool	IsProtoContact(HANDLE hContact);
-	HANDLE	GetContactBySid(const wchar_t* sid);
+	HANDLE	GetContactBySid(const char* sid);
 	HANDLE	GetContactFromAuthEvent(HANDLE hEvent);
-	HANDLE	AddContactBySid(const wchar_t* skypeName, const wchar_t* nick, DWORD flags = 0);
+	HANDLE	AddContactBySid(const char* skypeName, const wchar_t* nick, DWORD flags = 0);
 
 	int		SkypeToMirandaStatus(CContact::AVAILABILITY availability);
 	CContact::AVAILABILITY MirandaToSkypeStatus(int status);
@@ -250,7 +250,7 @@ protected:
 
 	int SkypeToMirandaLoginError(CAccount::LOGOUTREASON logoutReason);
 
-	void ShowNotification(const wchar_t *sid, const wchar_t *message, int flags = 0);
+	void ShowNotification(const char *sid, const wchar_t *message, int flags = 0);
 
 	// instances
 	static LIST<CSkypeProto> instanceList;
diff --git a/protocols/Skype/src/skype_utils.cpp b/protocols/Skype/src/skype_utils.cpp
index b7006faab0..a43c621769 100644
--- a/protocols/Skype/src/skype_utils.cpp
+++ b/protocols/Skype/src/skype_utils.cpp
@@ -452,7 +452,7 @@ int CSkypeProto::SkypeToMirandaLoginError(CAccount::LOGOUTREASON logoutReason)
 	return loginError;
 }
 
-void CSkypeProto::ShowNotification(const wchar_t *sid, const wchar_t *message, int flags)
+void CSkypeProto::ShowNotification(const char *sid, const wchar_t *message, int flags)
 {
 	if (::Miranda_Terminated()) return;
 
@@ -460,12 +460,12 @@ void CSkypeProto::ShowNotification(const wchar_t *sid, const wchar_t *message, i
 		MessageBoxW(NULL, message, TranslateT("Skype Protocol"), MB_OK);
 	else {
 		if ( !sid)
-			sid = L"";
+			sid = "";
 
 		POPUPDATAT_V2 ppd = {0};
 		ppd.cbSize = sizeof(POPUPDATAT_V2);
 		ppd.lchContact = NULL;
-		lstrcpyn(ppd.lpwzContactName, sid, MAX_CONTACTNAME);
+		lstrcpyn(ppd.lpwzContactName, ::mir_a2u(sid), MAX_CONTACTNAME);
 		lstrcpyn(ppd.lpwzText, message, MAX_SECONDLINE);
 		ppd.lchIcon = Skin_GetIcon("Skype_main");
 		ppd.colorBack = ppd.colorText = 0;
-- 
cgit v1.2.3