soc.2009.vulture: 2aa76746: Crude display of incoming messages.

gdick at soc.pidgin.im gdick at soc.pidgin.im
Mon Jun 15 17:20:42 EDT 2009


-----------------------------------------------------------------
Revision: 2aa76746edd800cfa0e64e30444ade2efac600f0
Ancestor: e1dd6a103c2334295d082dcaebbd4f7758224a10
Author: gdick at soc.pidgin.im
Date: 2009-06-15T17:14:16
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/2aa76746edd800cfa0e64e30444ade2efac600f0

Modified files:
        vulture/Makefile.mingw vulture/purpleconv.c
        vulture/purpleconv.h vulture/purplemain.c
        vulture/purplemain.h vulture/vulture-res.rc
        vulture/vulture.c vulture/vultureblist.c
        vulture/vultureconv.c vulture/vultureconv.h

ChangeLog: 

Crude display of incoming messages.

-------------- next part --------------
============================================================
--- vulture/Makefile.mingw	6cdb7e7cfb24327a2dd53402a15fb0080f641c5b
+++ vulture/Makefile.mingw	3ae1d65d4d4dac005dc158093ac5bcc1f0310517
@@ -20,6 +20,10 @@ LDFLAGS := $(WINAPP)
 
 LDFLAGS := $(WINAPP)
 
+#ifdef DEBUG
+CFLAGS += -O0
+#endif
+
 DEFINES += -DUNICODE \
 			-D_UNICODE \
 			-D_WIN32_WINNT=0x0400 \
============================================================
--- vulture/purpleconv.c	8200ec4fee1c440e896338dcada0280e9231e1a3
+++ vulture/purpleconv.c	63db9ef121a1e48bb22c6a04e53b38d8a70b7262
@@ -22,6 +22,7 @@
 
 #include <windows.h>
 #include <glib.h>
+#include <time.h>
 
 #include "vulture.h"
 #include "purple.h"
@@ -81,3 +82,42 @@ void PurpleDestroyConversation(PurpleCon
 {
 	VulturePostUIMessage(g_hwndMain, VUIMSG_DESTROYEDCONVERSATION, (VULTURE_CONVERSATION*)lpconv->ui_data);
 }
+
+
+
+/**
+ * PurpleConversationUiOps::write_conv callback. Called when a message is to be
+ * displayed in a conversation.
+ *
+ * @param	lpconv		Conversation.
+ * @param	szName		Username.
+ * @param	szAlias		Alias.
+ * @param	szMessage	Message.
+ * @param	pmflags		Message flags.
+ * @param	timeMsg		Time of message.
+ */
+void PurpleWriteConversation(PurpleConversation *lpconv, const char *szName, const char *szAlias, const char *szMessage, PurpleMessageFlags pmflags, time_t timeMsg)
+{
+	VULTURE_CONV_WRITE *lpvcwrite = g_new(VULTURE_CONV_WRITE, 1);
+
+	lpvcwrite->lpvconv = lpconv->ui_data;
+	lpvcwrite->szName = VultureUTF8ToTCHAR(szAlias ? szAlias : szName);
+	lpvcwrite->szMessage = VultureUTF8ToTCHAR(szMessage);
+	VultureTimetToSystemTime(timeMsg, &lpvcwrite->systimeMsg);
+
+	VulturePostUIMessage(g_hwndMain, VUIMSG_WRITECONVERSATION, lpvcwrite);
+} 
+
+
+/**
+ * Called by the UI to free the data allocated by PurpleWriteConversation when
+ * the UI is done with it.
+ *
+ * @param	lpvcwrite	Data to free.
+ */
+void VultureFreeConvWrite(VULTURE_CONV_WRITE *lpvcwrite)
+{
+	g_free(lpvcwrite->szMessage);
+	g_free(lpvcwrite->szName);
+	g_free(lpvcwrite);
+}
============================================================
--- vulture/purpleconv.h	07e0efebaf293bbdbe5b9d539c5483915e3002df
+++ vulture/purpleconv.h	179fbac52e7e65785d3c2bbc8615d6e05183c69b
@@ -23,12 +23,15 @@
 #ifndef _VULTURE_PURPLECONV_H_
 #define _VULTURE_PURPLECONV_H_
 
+
 #include "purple.h"
 #include "vultureconv.h"
 
 void PurpleNewConversation(PurpleConversation *lpconv);
 void VultureFreeConversation(VULTURE_CONVERSATION *lpvconv);
 void PurpleDestroyConversation(PurpleConversation *lpconv);
+void PurpleWriteConversation(PurpleConversation *lpconv, const char *szName, const char *szAlias, const char *szMessage, PurpleMessageFlags pmflags, time_t timeMsg);
+void VultureFreeConvWrite(VULTURE_CONV_WRITE *lpvcwrite);
 
 
 #endif
============================================================
--- vulture/purplemain.c	84021b5f5116b47535b389fcf6dd81ea49b35df3
+++ vulture/purplemain.c	8f535b86254b27654616cbcce9f28a9bdf90f05d
@@ -186,7 +186,7 @@ static void InitUI(void)
 		PurpleDestroyConversation,	/* destroy_conversation	*/
 		NULL,				/* write_chat		*/
 		NULL,				/* write_im		*/
-		NULL,				/* write_conv		*/
+		PurpleWriteConversation,	/* write_conv		*/
 		NULL,				/* chat_add_users	*/
 		NULL,				/* chat_rename_user	*/
 		NULL,				/* chat_remove_users	*/
============================================================
--- vulture/purplemain.h	316f5581e87d3f0a41943b45096a2aeaaf98527b
+++ vulture/purplemain.h	a94f9bec4167e2d0d45c16e3bf7bea137f26504d
@@ -46,6 +46,9 @@ enum ENUM_VULTURE_UI_MESSAGES
 	/* (VULTURE_CONVERSATION*) */
 	VUIMSG_DESTROYEDCONVERSATION,
 
+	/* (VULTURE_CONV_WRITE*) */
+	VUIMSG_WRITECONVERSATION,
+
 	VUIMSG_QUIT,
 };
 
============================================================
--- vulture/vulture-res.rc	70ce7ab95b472375ade589844dfb705c9fd551ff
+++ vulture/vulture-res.rc	44e88df5ff1abfae1d5322dbeab45ac11348e084
@@ -85,8 +85,8 @@ FONT 8, "Ms Shell Dlg"
 STYLE DS_3DLOOK | DS_CENTER | DS_SHELLFONT | WS_VISIBLE | WS_CHILDWINDOW
 FONT 8, "Ms Shell Dlg"
 {
-    CONTROL         "", IDC_RICHEDIT_CONV, RICHEDIT_CLASS, WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL | ES_READONLY, 5, 35, 310, 150
-    CONTROL         "", IDC_RICHEDIT_INPUT, RICHEDIT_CLASS, WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL, 5, 190, 310, 40
+    CONTROL         "", IDC_RICHEDIT_CONV, RICHEDIT_CLASS, WS_TABSTOP | WS_VSCROLL | WS_BORDER | ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY, 5, 35, 310, 150
+    CONTROL         "", IDC_RICHEDIT_INPUT, RICHEDIT_CLASS, WS_TABSTOP | WS_BORDER | ES_MULTILINE | ES_WANTRETURN, 5, 190, 310, 40
     CONTROL         "", IDC_STATIC, WC_STATIC, SS_BITMAP, 5, 5, 20, 17
     LTEXT           "", IDC_STATIC_NAME, 40, 5, 275, 8, SS_LEFT
     LTEXT           "", IDC_STATIC_STATUS, 40, 15, 275, 8, SS_LEFT
============================================================
--- vulture/vulture.c	e57fb7b45650012c7e434f91ba04ff44c06decf8
+++ vulture/vulture.c	ad7c69d3fb1d6b6cba0ac576eb30dffef2fa0547
@@ -24,6 +24,7 @@
 #include <windows.h>
 #include <commctrl.h>
 #include <glib.h>
+#include <time.h>
 
 #include "vulture.h"
 #include "resource.h"
@@ -172,3 +173,22 @@ int MessageBoxFromStringTable(HWND hwnd,
 
 	return iRet;
 }
+
+
+/**
+ * Converts a time_t to a SYSTEMTIME. Adapted from "Converting a time_t Value
+ * to a File Time" from the Windows SDK.
+ *
+ * @param	t		Time to convert.
+ * @param[out]	lpsystime	Converted time.
+ */
+void VultureTimetToSystemTime(time_t t, LPSYSTEMTIME lpsystime)
+{
+	FILETIME filetime;
+	LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000LL;
+
+	filetime.dwLowDateTime = (DWORD)ll;
+	filetime.dwHighDateTime = ll >> 32;
+
+	FileTimeToSystemTime(&filetime, lpsystime);
+}
============================================================
--- vulture/vultureblist.c	09f38cce5acccfd86f57f6d311360421bb1e290a
+++ vulture/vultureblist.c	6fb0ed72925e6bab795504ea97433758306001d6
@@ -34,6 +34,7 @@
 #include "purpleacct.h"
 #include "purplemain.h"
 #include "vultureconv.h"
+#include "purpleconv.h"
 
 
 static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
@@ -194,92 +195,104 @@ static LRESULT CALLBACK MainWndProc(HWND
 		break;
 
 	case WM_PURPLEUIMSG:
-		switch(wParam)
 		{
-		case VUIMSG_PURPLEINITCOMPLETE:
+			HWND hwndForward = NULL;
+
+			switch(wParam)
 			{
-				int i, iCount;
-				HMENU hmenu = GetMenu(hwnd);
+			case VUIMSG_PURPLEINITCOMPLETE:
+				{
+					int i, iCount;
+					HMENU hmenu = GetMenu(hwnd);
 
-				PopulateStatusList(GetDlgItem(s_hwndStatusDlg, IDC_CBEX_STATUS));
+					PopulateStatusList(GetDlgItem(s_hwndStatusDlg, IDC_CBEX_STATUS));
 
-				EnableWindow(s_hwndStatusDlg, TRUE);
-				EnableWindow(s_hwndBListDlg, TRUE);
+					EnableWindow(s_hwndStatusDlg, TRUE);
+					EnableWindow(s_hwndBListDlg, TRUE);
 
-				iCount = GetMenuItemCount(hmenu);
-				for(i = 0; i < iCount; i++)
-					EnableMenuItem(hmenu, i, MF_BYPOSITION | MF_ENABLED);
-				DrawMenuBar(hwnd);
+					iCount = GetMenuItemCount(hmenu);
+					for(i = 0; i < iCount; i++)
+						EnableMenuItem(hmenu, i, MF_BYPOSITION | MF_ENABLED);
+					DrawMenuBar(hwnd);
 
-				s_hCursor = LoadCursor(NULL, IDC_ARROW);
-			}
+					s_hCursor = LoadCursor(NULL, IDC_ARROW);
+				}
 
-			break;
+				break;
 
-		case VUIMSG_UPDATEBLISTNODE:
-			{
-				HWND hwndBlistTree = GetDlgItem(s_hwndBListDlg, IDC_TREE_BLIST);
-				VULTURE_BLIST_NODE *lpvbn = (VULTURE_BLIST_NODE*)lParam;
-
-				EnterCriticalSection(&lpvbn->cs);
+			case VUIMSG_UPDATEBLISTNODE:
 				{
-					TVITEM tvitem;
+					HWND hwndBlistTree = GetDlgItem(s_hwndBListDlg, IDC_TREE_BLIST);
+					VULTURE_BLIST_NODE *lpvbn = (VULTURE_BLIST_NODE*)lParam;
 
-					if(lpvbn->hti)
+					EnterCriticalSection(&lpvbn->cs);
 					{
-						HTREEITEM htiParent = TreeView_GetParent(hwndBlistTree, lpvbn->hti);
+						TVITEM tvitem;
 
-						/* If the parent doesn't match, we need
-						 * to recreate.
-						 */
-						if((lpvbn->lpvbnParent && lpvbn->lpvbnParent->hti != htiParent) ||
-							(!lpvbn->lpvbnParent && htiParent))
+						if(lpvbn->hti)
 						{
-							TreeView_DeleteItem(hwndBlistTree, lpvbn->hti);
-							lpvbn->hti = NULL;
+							HTREEITEM htiParent = TreeView_GetParent(hwndBlistTree, lpvbn->hti);
+
+							/* If the parent doesn't match, we need
+							 * to recreate.
+							 */
+							if((lpvbn->lpvbnParent && lpvbn->lpvbnParent->hti != htiParent) ||
+								(!lpvbn->lpvbnParent && htiParent))
+							{
+								TreeView_DeleteItem(hwndBlistTree, lpvbn->hti);
+								lpvbn->hti = NULL;
+							}
 						}
-					}
 
 
-					/* New node? */
-					if(!lpvbn->hti)
-					{
-						TVINSERTSTRUCT tvis;
+						/* New node? */
+						if(!lpvbn->hti)
+						{
+							TVINSERTSTRUCT tvis;
 
-						tvis.hParent = lpvbn->lpvbnParent ? lpvbn->lpvbnParent->hti : TVI_ROOT;
-						tvis.hInsertAfter = TVI_SORT;
-						tvis.itemex.mask = TVIF_PARAM;
-						tvis.itemex.lParam = lParam;
+							tvis.hParent = lpvbn->lpvbnParent ? lpvbn->lpvbnParent->hti : TVI_ROOT;
+							tvis.hInsertAfter = TVI_SORT;
+							tvis.itemex.mask = TVIF_PARAM;
+							tvis.itemex.lParam = lParam;
 
-						lpvbn->hti = TreeView_InsertItem(hwndBlistTree, &tvis);
+							lpvbn->hti = TreeView_InsertItem(hwndBlistTree, &tvis);
+						}
+
+						/* Set text. */
+						tvitem.mask = TVIF_TEXT | TVIF_HANDLE;
+						tvitem.hItem = lpvbn->hti;
+						tvitem.pszText = lpvbn->szNodeText;
+						TreeView_SetItem(hwndBlistTree, &tvitem);
 					}
+					LeaveCriticalSection(&lpvbn->cs);
+				}
 
-					/* Set text. */
-					tvitem.mask = TVIF_TEXT | TVIF_HANDLE;
-					tvitem.hItem = lpvbn->hti;
-					tvitem.pszText = lpvbn->szNodeText;
-					TreeView_SetItem(hwndBlistTree, &tvitem);
-				}
-				LeaveCriticalSection(&lpvbn->cs);
-			}
+				break;
 
-			break;
+			case VUIMSG_NEWCONVERSATION:
+				if(!g_lpglistConvContainers)
+					g_lpglistConvContainers = g_list_prepend(g_lpglistConvContainers, VultureCreateConvContainer());
 
-		case VUIMSG_NEWCONVERSATION:
-			if(!g_lpglistConvContainers)
-				g_lpglistConvContainers = g_list_prepend(g_lpglistConvContainers, VultureCreateConvContainer());
+				/* Fall through. */
+				
+			case VUIMSG_DESTROYEDCONVERSATION:
+				/* Forward the message to the first container. */
+				hwndForward = (HWND)g_lpglistConvContainers->data;
+				break;
 
-			/* Fall through. */
-			
-		case VUIMSG_DESTROYEDCONVERSATION:
-			/* Forward the message to the first container. */
-			SendMessage((HWND)g_lpglistConvContainers->data, uiMsg, wParam, lParam);
+			case VUIMSG_WRITECONVERSATION:
+				VultureWriteConversation((VULTURE_CONV_WRITE*)lParam);
+				VultureFreeConvWrite((VULTURE_CONV_WRITE*)lParam);
+				break;
 
-			break;
+			case VUIMSG_QUIT:
+				DestroyWindow(hwnd);
+				break;
+			}
 
-		case VUIMSG_QUIT:
-			DestroyWindow(hwnd);
-			break;
+			/* If we specified a window, forward the message. */
+			if(hwndForward)
+				SendMessage(hwndForward, uiMsg, wParam, lParam);
 		}
 
 		return 0;
============================================================
--- vulture/vultureconv.c	98651fdbac3dcd67b7a633cbcc6bd4245e9ffcba
+++ vulture/vultureconv.c	65e7a7555078218abbde90f2e9594d434e3ff725
@@ -22,6 +22,7 @@
 
 #include <windows.h>
 #include <commctrl.h>
+#include <richedit.h>
 #include <glib.h>
 
 #include "vulture.h"
@@ -453,3 +454,33 @@ static void RepositionConvControls(HWND 
 
 	EndDeferWindowPos(hdwp);
 }
+
+
+/**
+ * Displays a received message in a conversation window.
+ *
+ * @param	lpvcwrite	Conversation message data structure.
+ */
+void VultureWriteConversation(VULTURE_CONV_WRITE *lpvcwrite)
+{
+	CHARRANGE charrange;
+	int cchTime;
+	LPTSTR szTime;
+	HWND hwndRichEdit = GetDlgItem(lpvcwrite->lpvconv->hwndConv, IDC_RICHEDIT_CONV);
+
+	charrange.cpMin = charrange.cpMax = -1;
+	SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM)&charrange);
+
+	/* Build the timestamp. */
+	cchTime = GetTimeFormat(LOCALE_USER_DEFAULT, 0, &lpvcwrite->systimeMsg, NULL, NULL, 0);
+	szTime = ProcHeapAlloc(cchTime * sizeof(TCHAR));
+	GetTimeFormat(LOCALE_USER_DEFAULT, 0, &lpvcwrite->systimeMsg, NULL, szTime, cchTime);
+	SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)szTime);
+	ProcHeapFree(szTime);
+
+	SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)TEXT(" "));
+	SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)lpvcwrite->szName);
+	SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)TEXT(": "));
+	SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)lpvcwrite->szMessage);
+	SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)TEXT("\n"));
+}
============================================================
--- vulture/vultureconv.h	f192aa9fab088f18d858207c6c9d17b88c3a4ae8
+++ vulture/vultureconv.h	b925a4754761ef46f695dfc2b837f09b772340da
@@ -23,6 +23,7 @@
 #ifndef _VULTURE_VULTURECONV_H_
 #define _VULTURE_VULTURECONV_H_
 
+
 #include <windows.h>
 
 #include "purple.h"
@@ -44,7 +45,18 @@ typedef struct _VULTURE_CONVERSATION
 } VULTURE_CONVERSATION;
 
 
+typedef struct _VULTURE_CONV_WRITE
+{
+	VULTURE_CONVERSATION	*lpvconv;
+	LPTSTR			szName;
+	LPTSTR			szMessage;
+	SYSTEMTIME		systimeMsg;
+} VULTURE_CONV_WRITE;
+
+
 int VultureRegisterConvContainerWindowClass(void);
 HWND VultureCreateConvContainer(void);
+void VultureWriteConversation(VULTURE_CONV_WRITE *lpvcwrite);
 
+
 #endif


More information about the Commits mailing list