soc.2009.vulture: 4948f2cf: Handle primitive and transient statuses.

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


-----------------------------------------------------------------
Revision: 4948f2cf0806846bc43764a48ae49fec59b1c548
Ancestor: 9b72429f61b4380bcf79151ab18dab3eccb5a215
Author: gdick at soc.pidgin.im
Date: 2009-06-20T11:41:18
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/4948f2cf0806846bc43764a48ae49fec59b1c548

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

ChangeLog: 

Handle primitive and transient statuses.

-------------- next part --------------
============================================================
--- vulture/purplequeue.c	ed5c141acc28adef6c4327dbee4d57510c0b1667
+++ vulture/purplequeue.c	d94443796cc2b8814de8dfdad1ab4ddf40a701e5
@@ -173,7 +173,7 @@ static void DispatchPurpleCall(PURPLE_CA
 	switch(lppurplecall->iCallID)
 	{
 	case PC_GETALLSAVEDSTATUSES:
-		PurpleGetAllSavedStatuses((GList**)lppurplecall->lpvParam);
+		PurpleGetBoxSavedStatuses((GList**)lppurplecall->lpvParam);
 		break;
 
 	case PC_GETALLACCOUNTS:
@@ -185,7 +185,7 @@ static void DispatchPurpleCall(PURPLE_CA
 		break;
 
 	case PC_SETSAVEDSTATUS:
-		purple_savedstatus_activate(((VULTURE_SAVED_STATUS*)lppurplecall->lpvParam)->lppss);
+		PurpleSetStatus((VULTURE_SAVED_STATUS*)lppurplecall->lpvParam);
 		break;
 
 	case PC_DESTROYCONVERSATION:
============================================================
--- vulture/purplestatus.c	ffb6e4be54781abf2aad1134ef156532996d83b0
+++ vulture/purplestatus.c	2fafbcd9a4d9a6d2c3ad6c655b3dde0d60e45b98
@@ -27,38 +27,68 @@
 #include "purplestatus.h"
 
 
+/* Number of populat saved statuses. */
+#define CPSS_POPULAR	6
+
+
 /**
- * Gets a list of VULTURE_SAVED_STATUS records representing all saved statuses.
- * Adapted from Finch.
+ * Gets a list of VULTURE_SAVED_STATUS records representing those statuses we
+ * want to show in the buddy-list window. Adapted from Finch.
  *
  * @param[out]	lplpglistStatuses	List to populate.
  */
-void PurpleGetAllSavedStatuses(GList **lplpglistStatuses)
+void PurpleGetBoxSavedStatuses(GList **lplpglistStatuses)
 {
+	const PurpleStatusPrimitive c_rgpsprim[] =
+	{
+		PURPLE_STATUS_AVAILABLE, PURPLE_STATUS_AWAY,
+		PURPLE_STATUS_INVISIBLE, PURPLE_STATUS_OFFLINE
+	};
+
 	GList *lpglistPurpleStatuses;
+	int i;
 
+
 	*lplpglistStatuses = NULL;
 
-	for(lpglistPurpleStatuses = purple_savedstatuses_get_all(); lpglistPurpleStatuses; lpglistPurpleStatuses = lpglistPurpleStatuses->next)
+	/* Primitive statuses first. */
+	for(i = 0; i < NUM_ELEMENTS(c_rgpsprim); i++)
 	{
+		VULTURE_SAVED_STATUS *lpvss = g_new(VULTURE_SAVED_STATUS, 1);
+
+		const char *szTitle = purple_primitive_get_name_from_type(c_rgpsprim[i]);
+
+		lpvss->psprim = c_rgpsprim[i];
+		lpvss->vsstype = VSSTYPE_PRIMITIVE;
+		lpvss->lppss = NULL;
+		lpvss->szTitle = szTitle ? VultureUTF8ToTCHAR(szTitle) : NULL;
+		lpvss->szMessage = NULL;
+
+		*lplpglistStatuses = g_list_prepend(*lplpglistStatuses, lpvss);
+	}
+
+
+	/* Now do popular statuses. */
+	for(lpglistPurpleStatuses = purple_savedstatuses_get_popular(CPSS_POPULAR);
+		lpglistPurpleStatuses;
+		lpglistPurpleStatuses = lpglistPurpleStatuses->next)
+	{
 		PurpleSavedStatus *lppss = lpglistPurpleStatuses->data;
-		VULTURE_SAVED_STATUS *lpvss;
-		const char *szTitle, *szType, *szMessage;
+		VULTURE_SAVED_STATUS *lpvss = g_new(VULTURE_SAVED_STATUS, 1);
 
-		lpvss = g_new(VULTURE_SAVED_STATUS, 1);
+		const char *szTitle = purple_savedstatus_get_title(lppss);
+		const char *szMessage = purple_savedstatus_get_message(lppss);
 
-		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->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->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);
 }
@@ -78,7 +108,6 @@ void VulturePurpleFreeStatusList(GList *
 		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);
@@ -86,3 +115,46 @@ void VulturePurpleFreeStatusList(GList *
 
 	g_list_free(lpglistStatuses);
 }
+
+
+/**
+ * Sets the active status.
+ *
+ * @param	lpvss	New status.
+ */
+void PurpleSetStatus(VULTURE_SAVED_STATUS *lpvss)
+{
+	char *szMessage = NULL;
+	PurpleSavedStatus *lppss;
+
+	switch(lpvss->vsstype)
+	{
+	case VSSTYPE_FIRM:
+		/* This case is easy: we have a PurpleSavedStatus cached, so
+		 * just activate it.
+		 */
+		purple_savedstatus_activate(lpvss->lppss);
+		return;
+
+	case VSSTYPE_TRANSIENT:
+		if(lpvss->szMessage)
+			szMessage = VultureTCHARToUTF8(lpvss->szMessage);
+		break;
+
+	default:
+		break;
+	}
+
+	lppss = purple_savedstatus_find_transient_by_type_and_message(lpvss->psprim, szMessage);
+	if(!lppss)
+	{
+		/* No matching transient status, so make one. */
+		lppss = purple_savedstatus_new(NULL, lpvss->psprim);
+		purple_savedstatus_set_message(lppss, szMessage);
+	}
+
+	purple_savedstatus_activate(lppss);
+
+	if(szMessage)
+		g_free(szMessage);
+}
============================================================
--- vulture/purplestatus.h	5d23d87b1e25928c07248246a19b0af20d164dd4
+++ vulture/purplestatus.h	43696a639f640ce2b320ff3e2a1e9b734763cf83
@@ -29,17 +29,27 @@
 #include "purple.h"
 
 
+typedef enum _VULTURE_SAVED_STATUS_TYPE
+{
+	VSSTYPE_PRIMITIVE,
+	VSSTYPE_TRANSIENT,
+	VSSTYPE_FIRM,
+} VULTURE_SAVED_STATUS_TYPE;
+
+
 typedef struct _VULTURE_SAVED_STATUS
 {
-	PurpleSavedStatus	*lppss;
-	LPTSTR			szTitle;
-	LPTSTR			szType;
-	LPTSTR			szMessage;
+	PurpleSavedStatus		*lppss;
+	LPTSTR				szTitle;
+	LPTSTR				szMessage;
+	PurpleStatusPrimitive		psprim;
+	VULTURE_SAVED_STATUS_TYPE	vsstype;
 } VULTURE_SAVED_STATUS;
 
 
-void PurpleGetAllSavedStatuses(GList **lplpglistStatuses);
+void PurpleGetBoxSavedStatuses(GList **lplpglistStatuses);
 void VulturePurpleFreeStatusList(GList *lpglistStatuses);
+void PurpleSetStatus(VULTURE_SAVED_STATUS *lpvss);
 
 
 #endif
============================================================
--- vulture/vultureblist.c	fb9f46a7d0659bf2ad2d2a041a49e09a02846ad8
+++ vulture/vultureblist.c	c33b472c2c9f28a04ca7c0e12bc1683092cae5ef
@@ -430,7 +430,7 @@ static INT_PTR CALLBACK StatusDlgProc(HW
 					VULTURE_SAVED_STATUS *lpvss = (VULTURE_SAVED_STATUS*)SendDlgItemMessage(hwndDlg, IDC_CBEX_STATUS, CB_GETITEMDATA, iSel, 0);
 					VultureSingleSyncPurpleCall(PC_SETSAVEDSTATUS, lpvss);
 
-					SetDlgItemText(hwndDlg, IDC_EDIT_STATUSMSG, lpvss->szMessage);
+					SetDlgItemText(hwndDlg, IDC_EDIT_STATUSMSG, lpvss->szMessage ? lpvss->szMessage : TEXT(""));
 				}
 
 				return TRUE;
@@ -542,7 +542,7 @@ static void PopulateStatusList(HWND hwnd
 		COMBOBOXEXITEM cbexitem;
 
 		cbexitem.mask = CBEIF_TEXT | CBEIF_LPARAM;
-		cbexitem.pszText = lpvss->szTitle;
+		cbexitem.pszText = lpvss->szTitle ? lpvss->szTitle : TEXT("");
 		cbexitem.lParam = (LPARAM)lpvss;
 
 		/* Add at end of list. */


More information about the Commits mailing list