soc.2009.vulture: adb68637: Rudimentary reading-in of saved statuses...

gdick at soc.pidgin.im gdick at soc.pidgin.im
Thu Jun 4 16:32:17 EDT 2009


-----------------------------------------------------------------
Revision: adb686370d8ca5e7687b3287c0744dfbb8697a71
Ancestor: 7f90cb53f8934f8c75f1ab5002540a935ee55e60
Author: gdick at soc.pidgin.im
Date: 2009-06-04T20:24:26
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/adb686370d8ca5e7687b3287c0744dfbb8697a71

Added files:
        vulture/purplestatus.c vulture/purplestatus.h
Modified files:
        vulture/Makefile.mingw vulture/blist.c vulture/cmdline.c
        vulture/purplequeue.c vulture/purplequeue.h
        vulture/vulture.c

ChangeLog: 

Rudimentary reading-in of saved statuses.

-------------- next part --------------
============================================================
--- vulture/purplestatus.c	ffb6e4be54781abf2aad1134ef156532996d83b0
+++ vulture/purplestatus.c	ffb6e4be54781abf2aad1134ef156532996d83b0
@@ -0,0 +1,88 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * purplestatus.c: Saved-status 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 "purplestatus.h"
+
+
+/**
+ * Gets a list of VULTURE_SAVED_STATUS records representing all saved statuses.
+ * Adapted from Finch.
+ *
+ * @param[out]	lplpglistStatuses	List to populate.
+ */
+void PurpleGetAllSavedStatuses(GList **lplpglistStatuses)
+{
+	GList *lpglistPurpleStatuses;
+
+	*lplpglistStatuses = NULL;
+
+	for(lpglistPurpleStatuses = purple_savedstatuses_get_all(); lpglistPurpleStatuses; lpglistPurpleStatuses = lpglistPurpleStatuses->next)
+	{
+		PurpleSavedStatus *lppss = lpglistPurpleStatuses->data;
+		VULTURE_SAVED_STATUS *lpvss;
+		const char *szTitle, *szType, *szMessage;
+
+		lpvss = g_new(VULTURE_SAVED_STATUS, 1);
+
+		szTitle = purple_savedstatus_get_title(lppss);
+		szType = purple_primitive_get_name_from_type(purple_savedstatus_get_type(lppss));
+		szMessage = purple_savedstatus_get_message(lppss);
+
+		lpvss->lppss = lppss;
+		lpvss->szTitle = szTitle ? VultureUTF8ToTCHAR(szTitle) : NULL;
+		lpvss->szType = szType ? VultureUTF8ToTCHAR(szType) : NULL;
+		lpvss->szMessage = szMessage ? VultureUTF8ToTCHAR(szMessage) : NULL;
+
+		*lplpglistStatuses = g_list_prepend(*lplpglistStatuses, lpvss);
+	}
+
+	/* We built the list backwards for efficiency. Fix it. */
+	*lplpglistStatuses = g_list_reverse(*lplpglistStatuses);
+}
+
+
+/**
+ * Frees a list of statuses returned by PurpleGetAllSavedStatuses.
+ *
+ * @param	lpglistStatuses		List to free.
+ */
+void VulturePurpleFreeStatusList(GList *lpglistStatuses)
+{
+	GList *lpglistRover;
+
+	for(lpglistRover = lpglistStatuses; lpglistRover; lpglistRover = lpglistRover->next)
+	{
+		VULTURE_SAVED_STATUS *lpvss = lpglistRover->data;
+		
+		if(lpvss->szTitle) g_free(lpvss->szTitle);
+		if(lpvss->szType) g_free(lpvss->szType);
+		if(lpvss->szMessage) g_free(lpvss->szMessage);
+
+		g_free(lpvss);
+	}
+
+	g_list_free(lpglistStatuses);
+}
============================================================
--- vulture/purplestatus.h	5d23d87b1e25928c07248246a19b0af20d164dd4
+++ vulture/purplestatus.h	5d23d87b1e25928c07248246a19b0af20d164dd4
@@ -0,0 +1,45 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * purplestatus.h: Saved-status 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_PURPLESTATUS_H_
+#define _VULTURE_PURPLESTATUS_H_
+
+
+#include <windows.h>
+
+#include "purple.h"
+
+
+typedef struct _VULTURE_SAVED_STATUS
+{
+	PurpleSavedStatus	*lppss;
+	LPTSTR			szTitle;
+	LPTSTR			szType;
+	LPTSTR			szMessage;
+} VULTURE_SAVED_STATUS;
+
+
+void PurpleGetAllSavedStatuses(GList **lplpglistStatuses);
+void VulturePurpleFreeStatusList(GList *lpglistStatuses);
+
+
+#endif
============================================================
--- vulture/Makefile.mingw	9820fbe787c7eac7ce5868e797348dc9af13ca9b
+++ vulture/Makefile.mingw	30e56f06dbb946d6e447e8509887825218f6cfc1
@@ -56,7 +56,8 @@ VULTURE_C_SRC =	\
 			purplemain.c \
 			purplequeue.c \
 			purpleevloop.c \
-			cmdline.c
+			cmdline.c \
+			purplestatus.c
 
 VULTURE_RC_SRC = vulture-res.rc
 VULTURE_OBJECTS = $(VULTURE_C_SRC:%.c=%.o) $(VULTURE_RC_SRC:%.rc=%.o)
============================================================
--- vulture/blist.c	56f75bf04a556947f36b9903a757118a13b244e0
+++ vulture/blist.c	59966eb0912f6596beb61f53efec7fb7fa185496
@@ -21,10 +21,14 @@
  */
 
 #include <windows.h>
+#include <commctrl.h>
+#include <glib.h>
 
 #include "vulture.h"
 #include "resource.h"
 #include "blist.h"
+#include "purplequeue.h"
+#include "purplestatus.h"
 
 
 static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
@@ -172,12 +176,17 @@ static INT_PTR CALLBACK StatusDlgProc(HW
  */
 static INT_PTR CALLBACK StatusDlgProc(HWND hwndDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
 {
+	static GList *s_lpglistStatuses = NULL;
+
 	switch(uiMsg)
 	{
 	case WM_INITDIALOG:
 		{
 			RECT rcIcon;
 			POINT ptIcon;
+			GList *lpglistStatusRover;
+			GArray *lpgarrayWaitContext;
+			HWND hwndComboStatus = GetDlgItem(hwndDlg, IDC_CBEX_STATUS);
 
 			GetWindowRect(GetDlgItem(hwndDlg, IDC_BUDDY_ICON), &rcIcon);
 			ptIcon.x = rcIcon.left;
@@ -188,6 +197,26 @@ static INT_PTR CALLBACK StatusDlgProc(HW
 			 * height.
 			 */
 			SetWindowPos(GetDlgItem(hwndDlg, IDC_BUDDY_ICON), NULL, BLIST_MARGIN, ptIcon.y, rcIcon.bottom - rcIcon.top, rcIcon.bottom - rcIcon.top, SWP_NOACTIVATE | SWP_NOZORDER);
+
+			/* Populate list of statuses. */
+			lpgarrayWaitContext = VultureAllocPurpleWaitContext();
+			VultureEnqueueMultiSyncPurpleCall(PC_GETALLSAVEDSTATUSES, (void*)&s_lpglistStatuses, lpgarrayWaitContext);
+			VulturePurpleWait(lpgarrayWaitContext);
+
+			for(lpglistStatusRover = s_lpglistStatuses; lpglistStatusRover; lpglistStatusRover = lpglistStatusRover->next)
+			{
+				VULTURE_SAVED_STATUS *lpvss = lpglistStatusRover->data;
+				COMBOBOXEXITEM cbexitem;
+
+				cbexitem.mask = CBEIF_TEXT | CBEIF_LPARAM;
+				cbexitem.pszText = lpvss->szTitle;
+				cbexitem.lParam = (LPARAM)lpvss;
+
+				/* Add at end of list. */
+				cbexitem.iItem = -1;
+
+				SendMessage(hwndComboStatus, CBEM_INSERTITEM, 0, (LPARAM)&cbexitem);
+			}
 		}
 
 		/* Let the system set the focus. */
@@ -223,6 +252,11 @@ static INT_PTR CALLBACK StatusDlgProc(HW
 		}
 
 		return TRUE;
+
+	case WM_DESTROY:
+		if(s_lpglistStatuses)
+				VulturePurpleFreeStatusList(s_lpglistStatuses);
+		return TRUE;
 	}
 
 	return FALSE;
============================================================
--- vulture/cmdline.c	2d9d341713f2a61529401655cd5e94c22ff2187a
+++ vulture/cmdline.c	bade9f875c029b8d248d2fcfcce3c7c14894702f
@@ -52,14 +52,7 @@ void VultureParseCommandLine(void)
 	gchar **rgszArgv;
 
 	/* Get the command-line in UTF-8. */
-#ifdef UNICODE
-	szCmdLine = g_utf16_to_utf8(szCmdLineT, -1, NULL, NULL, NULL);
-#else
-	{
-		gsize cchWritten;
-		szCmdLine = g_locale_to_utf8(szCmdLineT, -1, NULL, &cchWritten, NULL);
-	}
-#endif
+	szCmdLine = VultureTCHARToUTF8(szCmdLineT);
 
 	g_shell_parse_argv(szCmdLine, &iArgc, &rgszArgv, &lpgerror);
 	
============================================================
--- vulture/purplequeue.c	a78d220e90e5ccd1148a4d43df8ba79876b95b3f
+++ vulture/purplequeue.c	62f199fc87002fc07d07398ab83bf08551ed306f
@@ -26,6 +26,7 @@
 #include "vulture.h"
 #include "purplemain.h"
 #include "purplequeue.h"
+#include "purplestatus.h"
 
 
 /** Queue node representing a libpurple call. */
@@ -168,6 +169,10 @@ static void DispatchPurpleCall(PURPLE_CA
 {
 	switch(lppurplecall->iCallID)
 	{
+	case PC_GETALLSAVEDSTATUSES:
+		PurpleGetAllSavedStatuses((GList**)lppurplecall->lpvParam);
+		break;
+
 	case PC_QUIT:
 		g_main_loop_quit(g_lpgmainloop);
 		break;
============================================================
--- vulture/purplequeue.h	4fdefd735e45f077430d6ea3be7a9416153131e5
+++ vulture/purplequeue.h	d6e427a834b0b61d3ae25d700d8920f58b60404a
@@ -32,11 +32,15 @@
 
 
 /** IDs of calls to libpurple. Used as values for iCallID member of
- * PURPLE_CALL.
+ * PURPLE_CALL. Where the lpvParam element has any significance, it is
+ * documented here.
  */
 enum PURPLE_CALL_ID
 {
 	PC_QUIT,
+
+	/* (GLlist**) Used to return list of statuses. */
+	PC_GETALLSAVEDSTATUSES,
 };
 
 
@@ -57,7 +61,7 @@ void VultureEnqueueMultiSyncPurpleCall(i
  * @return Wait context. Pass this to VultureEnqueueMultiSyncPurpleCall and
  * VulturePurpleWait.
  */
-//static INLINE GArray* VultureAllocPurpleWaitContext(void) { return g_array_new(FALSE, FALSE, sizeof(HANDLE)); }
+static INLINE GArray* VultureAllocPurpleWaitContext(void) { return g_array_new(FALSE, FALSE, sizeof(HANDLE)); }
 
 
 #endif
============================================================
--- vulture/vulture.c	df1be7c4ec6af2d07b91f047323570de020123da
+++ vulture/vulture.c	5dcdfa6be03b02495fa5a3fd692b00bedbbe8e1b
@@ -66,12 +66,6 @@ int WINAPI WinMain(HINSTANCE hinst, HINS
 
 	VultureParseCommandLine();
 
-	if(VultureCreateMainWindow(iCmdShow) != 0)
-	{
-		MessageBoxFromStringTable(NULL, IDS_ERROR_BLIST, MB_ICONERROR);
-		return VEC_ERROR_BLIST;
-	}
-
 	VultureInitLibpurple(&hthreadPurple);
 	if(hthreadPurple == (HANDLE)-1L)
 	{
@@ -79,6 +73,12 @@ int WINAPI WinMain(HINSTANCE hinst, HINS
 		return VEC_ERROR_PURPLEINIT;
 	}
 
+	if(VultureCreateMainWindow(iCmdShow) != 0)
+	{
+		MessageBoxFromStringTable(NULL, IDS_ERROR_BLIST, MB_ICONERROR);
+		return VEC_ERROR_BLIST;
+	}
+
 	while(GetMessage(&msg, NULL, 0, 0))
 	{
 		TranslateMessage(&msg);


More information about the Commits mailing list