soc.2009.vulture: 02e3ec90: Update UI when our own status changes.

gdick at soc.pidgin.im gdick at soc.pidgin.im
Sat Jun 20 16:30:46 EDT 2009


-----------------------------------------------------------------
Revision: 02e3ec90d8d47fe8e4f88c1e1a12c5bb4333f24b
Ancestor: a1f189e27c45270c1b574bfdae7ca5abbc622508
Author: gdick at soc.pidgin.im
Date: 2009-06-20T20:23:38
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/02e3ec90d8d47fe8e4f88c1e1a12c5bb4333f24b

Modified files:
        vulture/purplemain.c vulture/purplemain.h
        vulture/purplestatus.c vulture/purplestatus.h
        vulture/vulture.c vulture/vultureblist.c

ChangeLog: 

Update UI when our own status changes.

-------------- next part --------------
============================================================
--- vulture/purplemain.c	8c70805ad11da62e4abcc102160ffb566741e046
+++ vulture/purplemain.c	631773457ce7af95135c82e5ce9f2bc7d4ae77a0
@@ -48,6 +48,7 @@
 #include "cmdline.h"
 #include "purpleblist.h"
 #include "purpleconv.h"
+#include "purplestatus.h"
 
 
 static UINT CALLBACK PurpleThread(void *lpvData);
@@ -206,6 +207,8 @@ static void InitUI(void)
 	purple_blist_set_ui_ops(&s_blistuiops);
 	purple_conversations_set_ui_ops(&s_convuiops);
 
+	purple_signal_connect(purple_savedstatuses_get_handle(), "savedstatus-changed", GINT_TO_POINTER(VSH_STATUS), PURPLE_CALLBACK(PurpleStatusChanged), NULL);
+
 	/* Create and load libpurple's buddy-list. */
 	purple_set_blist(purple_blist_new());
 	purple_blist_load();
============================================================
--- vulture/purplemain.h	a94f9bec4167e2d0d45c16e3bf7bea137f26504d
+++ vulture/purplemain.h	396e29f02b1379f64d04cad01a11faa52467db89
@@ -50,8 +50,16 @@ enum ENUM_VULTURE_UI_MESSAGES
 	VUIMSG_WRITECONVERSATION,
 
 	VUIMSG_QUIT,
+
+	/* (VULTURE_SAVED_STATUS*) New status. */
+	VUIMSG_STATUSCHANGED,
 };
 
+/* HandlEs for reigistering signal handlERs. */
+enum ENUM_VULTURE_SIGNAL_HANDLES
+{
+	VSH_STATUS = 1,
+};
 
 void VultureInitLibpurple(HANDLE *lphthread);
 void VultureShutDownLibpurple(void);
============================================================
--- vulture/purplestatus.c	2fafbcd9a4d9a6d2c3ad6c655b3dde0d60e45b98
+++ vulture/purplestatus.c	aa7787cb976a7d529d7c7c6138b5d48ad834f177
@@ -25,12 +25,16 @@
 
 #include "vulture.h"
 #include "purplestatus.h"
+#include "purplemain.h"
 
 
 /* Number of populat saved statuses. */
 #define CPSS_POPULAR	6
 
 
+static void MakeVultureStatusFromPurple(PurpleSavedStatus *lppss, VULTURE_SAVED_STATUS *lpvss);
+
+
 /**
  * Gets a list of VULTURE_SAVED_STATUS records representing those statuses we
  * want to show in the buddy-list window. Adapted from Finch.
@@ -76,15 +80,8 @@ void PurpleGetBoxSavedStatuses(GList **l
 		PurpleSavedStatus *lppss = lpglistPurpleStatuses->data;
 		VULTURE_SAVED_STATUS *lpvss = g_new(VULTURE_SAVED_STATUS, 1);
 
-		const char *szTitle = purple_savedstatus_get_title(lppss);
-		const char *szMessage = purple_savedstatus_get_message(lppss);
+		MakeVultureStatusFromPurple(lppss, lpvss);
 
-		lpvss->psprim = purple_savedstatus_get_type(lppss);
-		lpvss->vsstype = purple_savedstatus_is_transient(lppss) ? VSSTYPE_TRANSIENT : VSSTYPE_FIRM;
-		lpvss->lppss = lppss;
-		lpvss->szTitle = szTitle ? VultureUTF8ToTCHAR(szTitle) : NULL;
-		lpvss->szMessage = szMessage ? VultureUTF8ToTCHAR(szMessage) : NULL;
-
 		*lplpglistStatuses = g_list_prepend(*lplpglistStatuses, lpvss);
 	}
 
@@ -104,16 +101,23 @@ void VulturePurpleFreeStatusList(GList *
 	GList *lpglistRover;
 
 	for(lpglistRover = lpglistStatuses; lpglistRover; lpglistRover = lpglistRover->next)
-	{
-		VULTURE_SAVED_STATUS *lpvss = lpglistRover->data;
-		
-		if(lpvss->szTitle) g_free(lpvss->szTitle);
-		if(lpvss->szMessage) g_free(lpvss->szMessage);
+		VultureFreeStatus((VULTURE_SAVED_STATUS*)lpglistRover->data);
 
-		g_free(lpvss);
-	}
+	g_list_free(lpglistStatuses);
+}
 
-	g_list_free(lpglistStatuses);
+
+/**
+ * Frees a VULTURE_SAVED_STATUS.
+ *
+ * @param	lpvss	Status to free.
+ */
+void VultureFreeStatus(VULTURE_SAVED_STATUS *lpvss)
+{
+	if(lpvss->szTitle) g_free(lpvss->szTitle);
+	if(lpvss->szMessage) g_free(lpvss->szMessage);
+
+	g_free(lpvss);
 }
 
 
@@ -158,3 +162,39 @@ void PurpleSetStatus(VULTURE_SAVED_STATU
 	if(szMessage)
 		g_free(szMessage);
 }
+
+
+/**
+ * savedstatus-changed signal-handler. Called when the status is changed.
+ *
+ * @param	lppssNew	New status.
+ * @param	lppssOld	Old status.
+ */
+void PurpleStatusChanged(PurpleSavedStatus *lppssNew, PurpleSavedStatus *lppssOld)
+{
+	VULTURE_SAVED_STATUS *lpvss = g_new(VULTURE_SAVED_STATUS, 1);
+
+	MakeVultureStatusFromPurple(lppssNew, lpvss);
+
+	/* The UI will free the status we just allocated. */
+	VulturePostUIMessage(g_hwndMain, VUIMSG_STATUSCHANGED, lpvss);
+}
+
+
+/**
+ * Populate a VULTURE_SAVED_STATUS from a PurpleSavedStatus.
+ *
+ * @param	lppss	Source.
+ * @param[out]	lpvss	Destination.
+ */
+static void MakeVultureStatusFromPurple(PurpleSavedStatus *lppss, VULTURE_SAVED_STATUS *lpvss)
+{
+	const char *szTitle = purple_savedstatus_get_title(lppss);
+	const char *szMessage = purple_savedstatus_get_message(lppss);
+
+	lpvss->psprim = purple_savedstatus_get_type(lppss);
+	lpvss->vsstype = purple_savedstatus_is_transient(lppss) ? VSSTYPE_TRANSIENT : VSSTYPE_FIRM;
+	lpvss->lppss = lppss;
+	lpvss->szTitle = szTitle ? VultureUTF8ToTCHAR(szTitle) : NULL;
+	lpvss->szMessage = szMessage ? VultureUTF8ToTCHAR(szMessage) : NULL;
+}
============================================================
--- vulture/purplestatus.h	43696a639f640ce2b320ff3e2a1e9b734763cf83
+++ vulture/purplestatus.h	4e25a3cb3e6a69999ba40608c9797e441fdefdd9
@@ -49,7 +49,9 @@ void VulturePurpleFreeStatusList(GList *
 
 void PurpleGetBoxSavedStatuses(GList **lplpglistStatuses);
 void VulturePurpleFreeStatusList(GList *lpglistStatuses);
+void VultureFreeStatus(VULTURE_SAVED_STATUS *lpvss);
 void PurpleSetStatus(VULTURE_SAVED_STATUS *lpvss);
+void PurpleStatusChanged(PurpleSavedStatus *lppssNew, PurpleSavedStatus *lppssOld);
 
 
 #endif
============================================================
--- vulture/vulture.c	ad7c69d3fb1d6b6cba0ac576eb30dffef2fa0547
+++ vulture/vulture.c	ea1e2e5c599034a934f3556c9ff8fb86841d479a
============================================================
--- vulture/vultureblist.c	1e1e76c5e8d02cd95cb887581f019194377cece8
+++ vulture/vultureblist.c	1a209e5fe5db116d3b66ba2a90137e53b4d10397
@@ -43,6 +43,7 @@ static void PopulateStatusList(HWND hwnd
 static INT_PTR CALLBACK BuddyListDlgProc(HWND hwndDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
 static void ManageAccounts(HWND hwndParent);
 static void PopulateStatusList(HWND hwndComboStatus);
+static void UpdateStatusUI(VULTURE_SAVED_STATUS *lpvss, HWND hwndStatusDlg);
 
 
 #define BLIST_MARGIN 6
@@ -297,6 +298,11 @@ static LRESULT CALLBACK MainWndProc(HWND
 				VultureFreeConvWrite((VULTURE_CONV_WRITE*)lParam);
 				break;
 
+			case VUIMSG_STATUSCHANGED:
+				UpdateStatusUI((VULTURE_SAVED_STATUS*)lParam, s_hwndStatusDlg);
+				VultureFreeStatus((VULTURE_SAVED_STATUS*)lParam);
+				break;
+
 			case VUIMSG_QUIT:
 				DestroyWindow(hwnd);
 				break;
@@ -551,3 +557,47 @@ static void PopulateStatusList(HWND hwnd
 		SendMessage(hwndComboStatus, CBEM_INSERTITEM, 0, (LPARAM)&cbexitem);
 	}
 }
+
+
+/**
+ * Updates the status combo-box and edit-box to reflect the given status.
+ *
+ * @param	lpvss		Status.
+ * @param	hwndStatusDlg	Status dialogue handle.
+ */
+static void UpdateStatusUI(VULTURE_SAVED_STATUS *lpvss, HWND hwndStatusDlg)
+{
+	HWND hwndCombo = GetDlgItem(hwndStatusDlg, IDC_CBEX_STATUS);
+	int i;
+	int iCount = SendMessage(hwndCombo, CB_GETCOUNT, 0, 0);
+	int iMatch = -1;
+
+	PopulateStatusList(hwndCombo);
+
+	if(lpvss->vsstype == VSSTYPE_FIRM)
+	{
+		/* Search for matching PurpleSavedStatus. */
+		for(i = 0; i < iCount && iMatch < 0; i++)
+		{
+			VULTURE_SAVED_STATUS *lpvssList = (VULTURE_SAVED_STATUS*)SendMessage(hwndCombo, CB_GETITEMDATA, i, 0);
+
+			if(lpvssList->vsstype == VSSTYPE_FIRM && lpvssList->lppss == lpvss->lppss)
+				iMatch = i;
+		}
+	}
+
+	/* Search for matching primitive. */
+	for(i = 0; i < iCount && iMatch < 0; i++)
+	{
+		VULTURE_SAVED_STATUS *lpvssList = (VULTURE_SAVED_STATUS*)SendMessage(hwndCombo, CB_GETITEMDATA, i, 0);
+
+		if(lpvssList->vsstype == VSSTYPE_PRIMITIVE && lpvssList->psprim == lpvss->psprim)
+			iMatch = i;
+	}
+
+	if(iMatch >= 0)
+	{
+		SendMessage(hwndCombo, CB_SETCURSEL, iMatch, 0);
+		SetDlgItemText(hwndStatusDlg, IDC_EDIT_STATUSMSG, lpvss->szMessage);
+	}
+}


More information about the Commits mailing list