From cd3ab10b3fb0774f057b1ae4e8f6af7efc85bf60 Mon Sep 17 00:00:00 2001
From: Alexander Lantsev <aunsane@gmail.com>
Date: Thu, 2 Oct 2014 20:33:07 +0000
Subject: Tox: added ability to chage contact dns name

git-svn-id: http://svn.miranda-ng.org/main/trunk@10672 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
---
 protocols/Tox/res/resource.rc      | 19 +++++++-
 protocols/Tox/src/resource.h       |  8 +++-
 protocols/Tox/src/tox_account.cpp  |  3 +-
 protocols/Tox/src/tox_contacts.cpp | 92 ++++++++++++++++++++++++++++++++++++++
 protocols/Tox/src/tox_proto.h      |  4 ++
 5 files changed, 122 insertions(+), 4 deletions(-)

(limited to 'protocols/Tox')

diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc
index 7b8fbe3ec8..5164fbea0e 100644
--- a/protocols/Tox/res/resource.rc
+++ b/protocols/Tox/res/resource.rc
@@ -7,7 +7,7 @@
 //
 // Generated from the TEXTINCLUDE 2 resource.
 //
-#include "afxres.h"
+#include "winres.h"
 
 /////////////////////////////////////////////////////////////////////////////
 #undef APSTUDIO_READONLY_SYMBOLS
@@ -51,7 +51,7 @@ END
 
 2 TEXTINCLUDE 
 BEGIN
-    "#include ""afxres.h""\r\n"
+    "#include ""winres.h""\r\n"
     "\0"
 END
 
@@ -138,6 +138,15 @@ BEGIN
     LTEXT           "If this field contains tox address (76 hex characters), you will be prompted to add it in your friend list. Otherwise, Miranda will search this query via tox dns discovery.",IDC_STATIC,0,20,109,93
 END
 
+IDD_USER_INFO DIALOGEX 0, 0, 221, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+EXSTYLE WS_EX_CONTROLPARENT
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
+BEGIN
+    LTEXT           "Dns name:",IDC_STATIC,2,3,217,8
+    EDITTEXT        IDC_DNS_ID,2,13,217,14,ES_AUTOHSCROLL
+END
+
 
 /////////////////////////////////////////////////////////////////////////////
 //
@@ -186,6 +195,12 @@ BEGIN
     IDD_SEARCH, DIALOG
     BEGIN
     END
+
+    IDD_USER_INFO, DIALOG
+    BEGIN
+        VERTGUIDE, 2
+        VERTGUIDE, 219
+    END
 END
 #endif    // APSTUDIO_INVOKED
 
diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h
index 3d68c6c90a..16a0f30593 100644
--- a/protocols/Tox/src/resource.h
+++ b/protocols/Tox/src/resource.h
@@ -2,6 +2,9 @@
 // Microsoft Visual C++ generated include file.
 // Used by e:\Projects\C++\MirandaNG\protocols\Tox\res\resource.rc
 //
+#define IDD_INFO_JABBER                 103
+#define IDD_ACCOUNT_INFO                103
+#define IDD_USER_INFO                   103
 #define IDI_TOX                         1000
 #define IDD_PROFILE_MANAGER             1001
 #define IDD_PROFILE_IMPORT              1001
@@ -18,6 +21,9 @@
 #define IDC_DISABLE_UDP                 1013
 #define IDC_DISABLE_IPV6                1014
 #define IDD_SEARCH                      1015
+#define IDC_EDIT1                       1016
+#define IDC_DNS_ID                      1016
+#define IDC_TV_INFO                     1276
 
 // Next default values for new objects
 // 
@@ -25,7 +31,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        102
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1016
+#define _APS_NEXT_CONTROL_VALUE         1017
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif
diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp
index 5cd08f59b7..6a40a14526 100644
--- a/protocols/Tox/src/tox_account.cpp
+++ b/protocols/Tox/src/tox_account.cpp
@@ -9,9 +9,10 @@ bool CToxProto::IsOnline()
 int CToxProto::OnAccountLoaded(WPARAM, LPARAM)
 {
 	HookProtoEvent(ME_OPT_INITIALISE, &CToxProto::OnOptionsInit);
+	HookProtoEvent(ME_USERINFO_INITIALISE, &CToxProto::OnUserInfoInit);
 	HookProtoEvent(ME_PROTO_ACCLISTCHANGED, &CToxProto::OnAccountListChanged);
 	HookProtoEvent(ME_DB_CONTACT_SETTINGCHANGED, &CToxProto::OnSettingsChanged);
-	HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage);
+	HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage);	
 
 	InitNetlib();
 
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index c474b0a89a..02549f4abb 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -268,4 +268,96 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, const int number, const uint
 			proto->delSetting(hContact, "Auth");
 		}
 	}
+}
+
+int CToxProto::OnUserInfoInit(WPARAM wParam, LPARAM lParam)
+{
+	if (!CallService(MS_PROTO_ISPROTOCOLLOADED, 0, (LPARAM)m_szModuleName))
+	{
+		return 0;
+	}
+
+	MCONTACT hContact = lParam;
+	char *szProto = GetContactProto(hContact);
+	if (szProto != NULL && !strcmp(szProto, m_szModuleName))
+	{
+		OPTIONSDIALOGPAGE odp = { sizeof(odp) };
+		odp.flags = ODPF_TCHAR | ODPF_DONTTRANSLATE;
+		odp.hInstance = g_hInstance;
+		odp.dwInitParam = (LPARAM)this;
+		odp.ptszTitle = m_tszUserName;
+
+		odp.pfnDlgProc = UserInfoProc;
+		odp.position = -2000000000;
+		odp.pszTemplate = MAKEINTRESOURCEA(IDD_USER_INFO);
+		UserInfo_AddPage(wParam, &odp);
+	}
+
+	return 0;
+}
+
+INT_PTR CToxProto::UserInfoProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+	CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+
+	switch (uMsg)
+	{
+	case WM_INITDIALOG:
+		TranslateDialogDefault(hwnd);
+		{
+			proto = (CToxProto*)lParam;
+			SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
+		}
+		break;
+
+	case WM_NOTIFY:
+		switch (((LPNMHDR)lParam)->idFrom)
+		{
+		case 0:
+			switch (((LPNMHDR)lParam)->code)
+			{
+			case PSN_INFOCHANGED:
+			{
+				MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
+				char *szProto = (hContact == NULL) ? szProto = proto->m_szModuleName : (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, hContact, 0);
+				if (szProto == NULL)
+				{
+					break;
+				}
+
+				SetDlgItemText(hwnd, IDC_DNS_ID, ptrT(proto->getTStringA(hContact, TOX_SETTINGS_DNS)));
+			}
+				break;
+
+			case PSN_PARAMCHANGED:
+				SetWindowLongPtr(hwnd, GWLP_USERDATA, ((PSHNOTIFY*)lParam)->lParam);
+				break;
+
+			case PSN_APPLY:
+				MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
+				char *szProto = (hContact == NULL) ? szProto = proto->m_szModuleName : (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, hContact, 0);
+				if (szProto == NULL)
+				{
+					break;
+				}
+				TCHAR dnsId[MAX_PATH];
+				GetDlgItemText(hwnd, IDC_DNS_ID, dnsId, MAX_PATH);
+				proto->setTString(hContact, TOX_SETTINGS_DNS, dnsId);
+				break;
+			}
+			break;
+		}
+		break;
+
+	case WM_COMMAND:
+		if ((HWND)lParam == GetFocus() && HIWORD(wParam) == EN_CHANGE)
+		{
+			SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+		}
+		break;
+
+		break;
+	}
+
+	return FALSE;
 }
\ No newline at end of file
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index 901344a933..608f439365 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -156,6 +156,10 @@ private:
 
 	INT_PTR __cdecl OnAccountManagerInit(WPARAM, LPARAM);
 
+	// userinfo
+	static INT_PTR CALLBACK UserInfoProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+	int __cdecl OnUserInfoInit(WPARAM wParam, LPARAM lParam);
+
 	// contacts
 	WORD GetContactStatus(MCONTACT hContact);
 	void SetContactStatus(MCONTACT hContact, WORD status);
-- 
cgit v1.2.3