soc.2009.vulture: 0399aa4c: Disentangle initialisation of libpurple ...

gdick at soc.pidgin.im gdick at soc.pidgin.im
Wed Jun 10 17:05:37 EDT 2009


-----------------------------------------------------------------
Revision: 0399aa4c47aacb853572cc6a48e094f78e0ee524
Ancestor: 91f2a27608cc263aa389c646c00940d344b354d1
Author: gdick at soc.pidgin.im
Date: 2009-06-10T12:12:40
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/0399aa4c47aacb853572cc6a48e094f78e0ee524

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

ChangeLog: 

Disentangle initialisation of libpurple and UI.

-------------- next part --------------
============================================================
--- vulture/purplemain.c	7a1b9b6b93525014deacc2ecff2dba7e9f4844e2
+++ vulture/purplemain.c	f61110988de2a0c597d781ae7dd9f57e2516f814
@@ -148,6 +148,8 @@ static int InitLibpurple(void)
 	if(!purple_core_init(VULTURE_ID))
 		return 1;
 
+	VulturePostUIMessage(g_hwndMain, VUIMSG_PURPLEINITCOMPLETE, NULL);
+
 	/* Sign in using specified or remembered state. */
 	if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
 		purple_savedstatus_activate(purple_savedstatus_get_startup());
============================================================
--- vulture/purplemain.h	7c408229afe4099fe6d4e16644b67bb164fa19e6
+++ vulture/purplemain.h	58c9cc8b58772a7c3bf48fd8613ad93768fd8821
@@ -37,6 +37,8 @@ enum ENUM_VULTURE_UI_MESSAGES
 {
 	/* (VULTURE_BLIST_NODE*) Node being updated. */
 	VUIMSG_UPDATEBLISTNODE,
+
+	VUIMSG_PURPLEINITCOMPLETE,
 };
 
 
============================================================
--- vulture/vulture.c	947d403fde64aaa1ad2a86fd0b6b7f488e87cff1
+++ vulture/vulture.c	75bd6f1e9dcef87487b4cb827597312fcae34a7d
@@ -67,6 +67,12 @@ 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)
 	{
@@ -74,12 +80,6 @@ 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;
-	}
-
 	/* For keyboard shortcuts. */
 	haccel = LoadAccelerators(hinst, MAKEINTRESOURCE(IDR_ACCEL_MAIN));
 
============================================================
--- vulture/vultureblist.c	5b9109c9ef5fcaf5782ed08e6d8e415cdfd22b8c
+++ vulture/vultureblist.c	a61778b6a0117d8fbc0d4d3f136fd6f503fa152a
@@ -39,6 +39,7 @@ static void ManageAccounts(HWND hwndPare
 static INT_PTR CALLBACK StatusDlgProc(HWND hwndDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
 static INT_PTR CALLBACK BuddyListDlgProc(HWND hwndDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
 static void ManageAccounts(HWND hwndParent);
+static void PopulateStatusList(HWND hwndComboStatus);
 
 
 #define BLIST_MARGIN 6
@@ -117,14 +118,29 @@ static LRESULT CALLBACK MainWndProc(HWND
 static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
 {
 	static HWND s_hwndStatusDlg = NULL, s_hwndBListDlg = NULL;
+	static HCURSOR s_hCursor;
 
 	switch(uiMsg)
 	{
 	case WM_CREATE:
+		{
+			int i, iCount;
+			HMENU hmenu = GetMenu(hwnd);
 
-		s_hwndStatusDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_STATUS), hwnd, StatusDlgProc);
-		s_hwndBListDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_BLIST), hwnd, BuddyListDlgProc);
+			s_hwndStatusDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_STATUS), hwnd, StatusDlgProc);
+			s_hwndBListDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_BLIST), hwnd, BuddyListDlgProc);
 
+			EnableWindow(s_hwndStatusDlg, FALSE);
+			EnableWindow(s_hwndBListDlg, FALSE);
+
+			s_hCursor = LoadCursor(NULL, IDC_WAIT);
+
+			iCount = GetMenuItemCount(hmenu);
+			for(i = 0; i < iCount; i++)
+				EnableMenuItem(hmenu, i, MF_BYPOSITION | MF_DISABLED);
+			DrawMenuBar(hwnd);
+		}
+
 		return 0;
 
 	case WM_COMMAND:
@@ -162,16 +178,41 @@ static LRESULT CALLBACK MainWndProc(HWND
 		/* Don't erase background: we never see it. Reduces flicker. */
 		return 0;
 
+	case WM_SETCURSOR:
+		if(LOWORD(lParam) == HTCLIENT)
+		{
+			SetCursor(s_hCursor);
+
+			/* Stop processing. */
+			return TRUE;
+		}
+
+		break;
+
 	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).
-			 */
+		case VUIMSG_PURPLEINITCOMPLETE:
+			{
+				int i, iCount;
+				HMENU hmenu = GetMenu(hwnd);
 
+				PopulateStatusList(GetDlgItem(s_hwndStatusDlg, IDC_CBEX_STATUS));
+
+				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);
+
+				s_hCursor = LoadCursor(NULL, IDC_ARROW);
+			}
+
+			break;
+
+		case VUIMSG_UPDATEBLISTNODE:
 			{
 				HWND hwndBlistTree = GetDlgItem(s_hwndBListDlg, IDC_TREE_BLIST);
 				VULTURE_BLIST_NODE *lpvbn = (VULTURE_BLIST_NODE*)lParam;
@@ -243,17 +284,12 @@ 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;
@@ -264,26 +300,6 @@ 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. */
@@ -349,12 +365,6 @@ static INT_PTR CALLBACK StatusDlgProc(HW
 		}
 
 		break;
-
-
-	case WM_DESTROY:
-		if(s_lpglistStatuses)
-				VulturePurpleFreeStatusList(s_lpglistStatuses);
-		return TRUE;
 	}
 
 	return FALSE;
@@ -420,3 +430,40 @@ static void ManageAccounts(HWND hwndPare
 
 	VultureFreeAccountList(lpglistAccounts);
 }
+
+
+/**
+ * Populates a combo-box with all saved statuses.
+ *
+ * @param	hwndComboStatus		Combo-box handle.
+ */
+static void PopulateStatusList(HWND hwndComboStatus)
+{
+	GList *lpglistStatusRover;
+	GArray *lpgarrayWaitContext;
+	GList *lpglistStatuses = NULL;
+	
+
+	/* Get all statuses. */
+	lpgarrayWaitContext = VultureAllocPurpleWaitContext();
+	VultureEnqueueMultiSyncPurpleCall(PC_GETALLSAVEDSTATUSES, (void*)&lpglistStatuses, lpgarrayWaitContext);
+	VulturePurpleWait(lpgarrayWaitContext);
+
+	/* Populate control. */
+	for(lpglistStatusRover = 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);
+	}
+
+	VulturePurpleFreeStatusList(lpglistStatuses);
+}


More information about the Commits mailing list