soc.2009.vulture: 91f2a276: - First steps towards buddy-list. Wrong ...

gdick at soc.pidgin.im gdick at soc.pidgin.im
Tue Jun 9 17:35:29 EDT 2009


-----------------------------------------------------------------
Revision: 91f2a27608cc263aa389c646c00940d344b354d1
Ancestor: 7c3d75d94d9caa58805685c6b4d330a1a490c918
Author: gdick at soc.pidgin.im
Date: 2009-06-09T21:31:12
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/91f2a27608cc263aa389c646c00940d344b354d1

Renamed entries:
        vulture/blist.c to vulture/vultureblist.c
        vulture/blist.h to vulture/vultureblist.h
Added files:
        vulture/purpleblist.c vulture/purpleblist.h
Modified files:
        vulture/Makefile.mingw vulture/cmdline.c vulture/cmdline.h
        vulture/purpleevloop.h vulture/purplemain.c
        vulture/purplemain.h vulture/vulture.c
        vulture/vultureblist.c vulture/vultureblist.h

ChangeLog: 

- First steps towards buddy-list. Wrong in many respects.
- Renamed blist.* to vultureblist.* to avoid collision with libpurple.

-------------- next part --------------
============================================================
--- vulture/purpleblist.c	2a1ac2ae2cf87aa64db985177ed0cdd137a044ca
+++ vulture/purpleblist.c	2a1ac2ae2cf87aa64db985177ed0cdd137a044ca
@@ -0,0 +1,95 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * purpleblist.c: libpurple end of buddy-list management.
+ *
+ * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#include <windows.h>
+#include <glib.h>
+
+#include "vulture.h"
+#include "purple.h"
+#include "purpleblist.h"
+#include "vultureblist.h"
+#include "purplemain.h"
+
+
+/**
+ * Callback for when a new buddy-list node is created.
+ *
+ * @param	lpblistnode	Buddy-list node.
+ */
+void PurpleBlistNewNode(PurpleBlistNode *lpblistnode)
+{
+	/* As this is the first time we've seen this node, allocate some state
+	 * data. The UI will free this when it removes the corresponding UI
+	 * node.
+	 */
+
+	VULTURE_BLIST_NODE *lpvbn = (VULTURE_BLIST_NODE*)(lpblistnode->ui_data = g_new(VULTURE_BLIST_NODE, 1));
+
+	lpvbn->szNodeText = NULL;
+	lpvbn->hti = NULL;
+	InitializeCriticalSection(&lpvbn->cs);
+}
+
+
+/**
+ * Callback for when a buddy-list node must be updated.
+ *
+ * @param	lpbuddylist	Buddy-list. Unused.
+ * @param	lpblistnode	Buddy-list node.
+ */
+void PurpleBlistUpdateNode(PurpleBuddyList *lpbuddylist, PurpleBlistNode *lpblistnode)
+{
+	VULTURE_BLIST_NODE *lpvbn;
+
+	UNREFERENCED_PARAMETER(lpbuddylist);
+
+	
+	lpvbn = (VULTURE_BLIST_NODE*)lpblistnode->ui_data;
+
+	EnterCriticalSection(&lpvbn->cs);
+	{
+		const char *szNodeText;
+
+		lpvbn->lpvbnParent = lpblistnode->parent ? (VULTURE_BLIST_NODE*)lpblistnode->parent->ui_data : NULL;
+
+		switch(lpblistnode->type)
+		{
+		case PURPLE_BLIST_GROUP_NODE:
+			szNodeText = ((PurpleGroup*)lpblistnode)->name;
+			break;
+
+		case PURPLE_BLIST_CONTACT_NODE:
+			szNodeText = purple_contact_get_alias((PurpleContact*)lpblistnode);
+			break;
+
+		default:
+			szNodeText = PURPLE_BLIST_NODE_NAME(lpblistnode);
+			break;
+		}
+
+		if(lpvbn->szNodeText) g_free(lpvbn->szNodeText);
+		lpvbn->szNodeText = szNodeText ? VultureUTF8ToTCHAR(szNodeText) : NULL;
+	}
+	LeaveCriticalSection(&lpvbn->cs);
+
+	VulturePostUIMessage(g_hwndMain, VUIMSG_UPDATEBLISTNODE, lpvbn);
+}
============================================================
--- vulture/purpleblist.h	2ff4a612f09bc65fc9326c233080f9e74d9dd97b
+++ vulture/purpleblist.h	2ff4a612f09bc65fc9326c233080f9e74d9dd97b
@@ -0,0 +1,35 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * purpleblist.h: libpurple end of buddy-list management.
+ *
+ * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+
+#ifndef _VULTURE_PURPLEBLIST_H_
+#define _VULTURE_PURPLEBLIST_H_
+
+
+#include "purple.h"
+
+
+void PurpleBlistNewNode(PurpleBlistNode *lpblistnode);
+void PurpleBlistUpdateNode(PurpleBuddyList *lpbuddylist, PurpleBlistNode *lpblistnode);
+
+
+#endif
============================================================
--- vulture/Makefile.mingw	d2d38d1b6d3c00e3f8db7ef69cc80155998ed599
+++ vulture/Makefile.mingw	cad6e8bd69b84b6dd9145566dc52a72d5fdfc26b
@@ -52,14 +52,15 @@ VULTURE_C_SRC =	\
 ##
 VULTURE_C_SRC =	\
 			vulture.c \
-			blist.c \
+			vultureblist.c \
 			purplemain.c \
 			purplequeue.c \
 			purpleevloop.c \
 			cmdline.c \
 			purplestatus.c \
 			acctmanager.c \
-			purpleacct.c
+			purpleacct.c \
+			purpleblist.c
 
 VULTURE_RC_SRC = vulture-res.rc
 VULTURE_OBJECTS = $(VULTURE_C_SRC:%.c=%.o) $(VULTURE_RC_SRC:%.rc=%.o)
============================================================
--- vulture/cmdline.c	bade9f875c029b8d248d2fcfcce3c7c14894702f
+++ vulture/cmdline.c	f17833e467dffed9116d2e323fdeae389c187b5f
============================================================
--- vulture/cmdline.h	d3f43991b0f21608e9d694cf67013e999494e915
+++ vulture/cmdline.h	288d6762e77b8ccb8c131b3836fbfdba4b3caaa5
============================================================
--- vulture/purpleevloop.h	e56b55cbfe258c8afc5f18cc7ff0f2ba1dab08cb
+++ vulture/purpleevloop.h	781b50612b69bf3436dfbb71441944860930c0e8
============================================================
--- vulture/purplemain.c	a342a00149c16e1b4e274d4492f41e0daa5c07b2
+++ vulture/purplemain.c	7a1b9b6b93525014deacc2ecff2dba7e9f4844e2
@@ -46,6 +46,7 @@
 #include "purplequeue.h"
 #include "purpleevloop.h"
 #include "cmdline.h"
+#include "purpleblist.h"
 
 
 static UINT CALLBACK PurpleThread(void *lpvData);
@@ -128,7 +129,7 @@ static int InitLibpurple(void)
  */
 static int InitLibpurple(void)
 {
-	static PurpleCoreUiOps coreuiops = 
+	static PurpleCoreUiOps s_coreuiops = 
 	{
 		NULL, NULL, InitUI, NULL,
 		/* padding */
@@ -141,7 +142,7 @@ static int InitLibpurple(void)
 		purple_util_set_user_dir(szCustomUserDir);
 
 	VulturePurpleEventLoopSetUIOps();
-	purple_core_set_ui_ops(&coreuiops);
+	purple_core_set_ui_ops(&s_coreuiops);
 
 	/* Init the core, which will eventually call InitUI. */
 	if(!purple_core_init(VULTURE_ID))
@@ -163,6 +164,15 @@ static void InitUI(void)
  */
 static void InitUI(void)
 {
+	static PurpleBlistUiOps s_blistuiops =
+	{
+		NULL, PurpleBlistNewNode, NULL, PurpleBlistUpdateNode, NULL, NULL, NULL,
+		NULL, NULL, NULL,
+		NULL, NULL, NULL, NULL
+	};
+
+	purple_blist_set_ui_ops(&s_blistuiops);
+
 	/* Create and load libpurple's buddy-list. */
 	purple_set_blist(purple_blist_new());
 	purple_blist_load();
============================================================
--- vulture/purplemain.h	b1e574134ccb2954c14aa7528fa5173224e8ac97
+++ vulture/purplemain.h	7c408229afe4099fe6d4e16644b67bb164fa19e6
@@ -28,9 +28,37 @@
 #include <windows.h>
 #include <glib.h>
 
+#include "vulture.h"
+#include "vultureblist.h"
+
+
+/* The significance of lpvParam is given for each message. */
+enum ENUM_VULTURE_UI_MESSAGES
+{
+	/* (VULTURE_BLIST_NODE*) Node being updated. */
+	VUIMSG_UPDATEBLISTNODE,
+};
+
+
 void VultureInitLibpurple(HANDLE *lphthread);
 void VultureShutDownLibpurple(void);
 
 extern GMainLoop *g_lpgmainloop;
 
+
+/**
+ * Posts a message from libpurple to the Windows message queue of the specified
+ * window.
+ *
+ * @param	hwnd		Window.
+ * @param	iCallID		ID of the message.
+ * @param	lpvParam	Message-specific data.
+ */
+static INLINE void VulturePostUIMessage(HWND hwnd, int iMsg, void *lpvParam)
+{
+	if(IsWindow(hwnd))
+		PostMessage(hwnd, WM_PURPLEUIMSG, iMsg, (LPARAM)lpvParam);
+}
+
+
 #endif
============================================================
--- vulture/vulture.c	6eaf80abbba4e0068791a3316a75a76ef62ad1b0
+++ vulture/vulture.c	947d403fde64aaa1ad2a86fd0b6b7f488e87cff1
@@ -27,7 +27,7 @@
 
 #include "vulture.h"
 #include "resource.h"
-#include "blist.h"
+#include "vultureblist.h"
 #include "purplemain.h"
 #include "purplequeue.h"
 #include "cmdline.h"
============================================================
--- vulture/blist.c	d27ac2b10ff5537468bcb9bb8c53f9852b534213
+++ vulture/vultureblist.c	5b9109c9ef5fcaf5782ed08e6d8e415cdfd22b8c
@@ -1,7 +1,7 @@
 /*
  * Vulture - Win32 libpurple client
  *
- * blist.c: Buddy list.
+ * vultureblist.c: Buddy list.
  *
  * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
  *
@@ -26,11 +26,13 @@
 
 #include "vulture.h"
 #include "resource.h"
-#include "blist.h"
+#include "purple.h"
+#include "vultureblist.h"
 #include "purplequeue.h"
 #include "purplestatus.h"
 #include "acctmanager.h"
 #include "purpleacct.h"
+#include "purplemain.h"
 
 
 static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
@@ -160,6 +162,63 @@ static LRESULT CALLBACK MainWndProc(HWND
 		/* Don't erase background: we never see it. Reduces flicker. */
 		return 0;
 
+	case WM_PURPLEUIMSG:
+		switch(wParam)
+		{
+		case VUIMSG_UPDATEBLISTNODE:
+			/* This message is SENT for convenience, so we're
+			 * allowed to use the libpurple data directly, but not
+			 * to make any libpurple calls at all (or otherwise to
+			 * wait for the libpurple thread).
+			 */
+
+			{
+				HWND hwndBlistTree = GetDlgItem(s_hwndBListDlg, IDC_TREE_BLIST);
+				VULTURE_BLIST_NODE *lpvbn = (VULTURE_BLIST_NODE*)lParam;
+
+				EnterCriticalSection(&lpvbn->cs);
+				{
+					TVITEM tvitem;
+					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;
+
+						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);
+					}
+
+					/* Set text. */
+					tvitem.mask = TVIF_TEXT | TVIF_HANDLE;
+					tvitem.hItem = lpvbn->hti;
+					tvitem.pszText = lpvbn->szNodeText;
+					TreeView_SetItem(hwndBlistTree, &tvitem);
+				}
+				LeaveCriticalSection(&lpvbn->cs);
+			}
+
+			break;
+		}
+
+		return 0;
+
 	case WM_DESTROY:
 		DestroyWindow(s_hwndBListDlg);
 		DestroyWindow(s_hwndStatusDlg);
============================================================
--- vulture/blist.h	866f3cdb00421b86035a6abb8a2aee8cb6f11d92
+++ vulture/vultureblist.h	be90fd23547bdeaea7f70fbd864627b7c48a2c32
@@ -1,7 +1,7 @@
 /*
  * Vulture - Win32 libpurple client
  *
- * blist.h: Buddy list.
+ * vultureblist.h: Buddy list.
  *
  * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
  *
@@ -20,11 +20,30 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
-#ifndef _VULTURE_BLIST_H_
-#define _VULTURE_BLIST_H_
+#ifndef _VULTURE_VULTUREBLIST_H_
+#define _VULTURE_VULTUREBLIST_H_
 
+
+#include <windows.h>
+#include <commctrl.h>
+
+
+typedef struct _VULTURE_BLIST_NODE
+{
+	LPTSTR				szNodeText;
+	HTREEITEM			hti;
+	struct _VULTURE_BLIST_NODE	*lpvbnParent;
+	CRITICAL_SECTION		cs;
+} VULTURE_BLIST_NODE;
+
+
+#define WM_PURPLEUIMSG	WM_APP
+
+
 extern HWND g_hwndMain;
 
+
 int VultureCreateMainWindow(int iCmdShow);
 
+
 #endif


More information about the Commits mailing list