soc.2009.vulture: 7b9ea814: Show current buddy icon in main accounts...

gdick at soc.pidgin.im gdick at soc.pidgin.im
Thu Sep 10 11:20:40 EDT 2009


-----------------------------------------------------------------
Revision: 7b9ea81496080f898cad722c2fd19d0452477e45
Ancestor: 7ba356cc366f1069b60235bdb0537386450bf5e0
Author: gdick at soc.pidgin.im
Date: 2009-09-10T15:13:51
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/7b9ea81496080f898cad722c2fd19d0452477e45

Modified files:
        vulture/acctmanager.c vulture/acctmanager.h
        vulture/purpleacct.c vulture/purplebicon.c
        vulture/purplebicon.h

ChangeLog: 

Show current buddy icon in main accounts property page when path not set.

-------------- next part --------------
============================================================
--- vulture/acctmanager.c	6c3e86ea823742ff08bff91ecd40521806f7e776
+++ vulture/acctmanager.c	26252ebbc4a4f5ca398441f5b3b1ce1cbf9346bf
@@ -351,7 +351,7 @@ static INT_PTR CALLBACK AccountAccountPr
 		if(lpvac->bSupportsBIcon)
 		{
 			if(lpvac->szBIcon) SetDlgItemText(hwndPropPage, IDC_EDIT_BICON, lpvac->szBIcon);
-			CheckRadioButton(hwndPropPage, IDC_RADIO_BICONGLOBAL, IDC_RADIO_BICONNONE, lpvac->bOverrideBIcon ? (lpvac->szBIcon ? IDC_RADIO_BICONOVERRIDE : IDC_RADIO_BICONNONE) : IDC_RADIO_BICONGLOBAL);
+			CheckRadioButton(hwndPropPage, IDC_RADIO_BICONGLOBAL, IDC_RADIO_BICONNONE, lpvac->bOverrideBIcon ? ((lpvac->szBIcon || (lpvac->lpvOrigBIcon && lpvac->bPreserveBIcon)) ? IDC_RADIO_BICONOVERRIDE : IDC_RADIO_BICONNONE) : IDC_RADIO_BICONGLOBAL);
 			UpdateBIconPreview(hwndPropPage);
 		}
 		else
@@ -490,7 +490,11 @@ static INT_PTR CALLBACK AccountAccountPr
 							lpvac->szBIcon = g_new(TCHAR, cch);
 							GetWindowText(hwndEdit, lpvac->szBIcon, cch);
 						}
+
+						lpvac->bPreserveBIcon = TRUE;
 					}
+					else
+						lpvac->bPreserveBIcon = FALSE;
 				}
 			}
 
@@ -542,17 +546,22 @@ static void UpdateBIconPreview(HWND hwnd
 	HWND hwndEdit = GetDlgItem(hwndPropPage, IDC_EDIT_BICON);
 	int cchBIcon = GetWindowTextLength(hwndEdit) + 1;
 	HBITMAP hbitmap = NULL;
+	VULTURE_ACCOUNT *lpvac = (VULTURE_ACCOUNT*)GetWindowLongPtr(hwndPropPage, GWLP_USERDATA);
+	RECT rcBIcon;
 
+	GetWindowRect(GetDlgItem(hwndPropPage, IDC_STATIC_BICON), &rcBIcon);
+
 	if(cchBIcon > 1)
 	{
 		LPTSTR szBIcon = ProcHeapAlloc(cchBIcon * sizeof(TCHAR));
-		RECT rcBIcon;
-
-		GetWindowRect(GetDlgItem(hwndPropPage, IDC_STATIC_BICON), &rcBIcon);
+		
 		GetWindowText(hwndEdit, szBIcon, cchBIcon);
 		hbitmap = VultureLoadBuddyIcon(szBIcon, rcBIcon.right - rcBIcon.left, rcBIcon.bottom - rcBIcon.top);
 		ProcHeapFree(szBIcon);
 	}
+	/* If edit box is empty and we have an original icon, use it. */
+	else if(lpvac->lpvOrigBIcon)
+		hbitmap = VultureGetBuddyIcon(lpvac->lpvOrigBIcon, lpvac->cbOrigBIcon, rcBIcon.right - rcBIcon.left, rcBIcon.bottom - rcBIcon.top);
 
 	hbitmap = (HBITMAP)SendDlgItemMessage(hwndPropPage, IDC_STATIC_BICON, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbitmap);
 
============================================================
--- vulture/acctmanager.h	cb137369907b86ee984b99f8423d5e824dca5e2f
+++ vulture/acctmanager.h	31eeb2594b2c63a3161f11030e19e76111e40564
@@ -43,6 +43,14 @@ typedef struct _VULTURE_ACCOUNT
 	BOOL			bRememberPass;
 	BOOL			bConnected;
 	BOOL			bSupportsBIcon;
+	PurpleStoredImage	*lpstoredimgOrigBIcon;
+	LPCVOID			lpvOrigBIcon;
+	DWORD			cbOrigBIcon;
+
+	/* Indicates that previous buddy icon should be preserved if szBIcon is
+	 * NULL.
+	 */
+	BOOL			bPreserveBIcon;
 } VULTURE_ACCOUNT;
 
 
============================================================
--- vulture/purpleacct.c	fa02076800a1870e2d976dd8670b0539a375e8fd
+++ vulture/purpleacct.c	d66e760cb29c00a8cf79e712e29290025b5986c6
@@ -87,6 +87,9 @@ void PurpleGetAccounts(BOOL bOnlineOnly,
 				lpvac->bMail = purple_account_get_check_mail(lpvac->lppac);
 
 			lpvac->szBIcon = NULL;
+			lpvac->lpvOrigBIcon = NULL;
+			lpvac->lpstoredimgOrigBIcon = NULL;
+			lpvac->bPreserveBIcon = FALSE;
 
 			lpvac->bSupportsBIcon = lpprplinfo ? lpprplinfo->icon_spec.format != NULL : FALSE;
 			if(lpvac->bSupportsBIcon)
@@ -97,6 +100,16 @@ void PurpleGetAccounts(BOOL bOnlineOnly,
 					const gchar *szBIcon = purple_account_get_buddy_icon_path(lpvac->lppac);
 					lpvac->szBIcon = szBIcon ? VultureUTF8ToTCHAR(szBIcon) : NULL;
 				}
+
+				/* Get current buddy icon, which may be set
+				 * even if the path isn't.
+				 */
+				if((lpvac->lpstoredimgOrigBIcon = purple_buddy_icons_find_account_icon(lpvac->lppac)))
+				{
+					lpvac->lpvOrigBIcon = purple_imgstore_get_data(lpvac->lpstoredimgOrigBIcon);
+					lpvac->cbOrigBIcon = purple_imgstore_get_size(lpvac->lpstoredimgOrigBIcon);
+					lpvac->bPreserveBIcon = TRUE;
+				}
 			}
 
 			lpvac->bConnected = purple_account_is_connected(lpvac->lppac);
@@ -127,6 +140,7 @@ void VultureFreeAccountList(GList *lpgli
 		g_free(lpvac->szPassword);
 		g_free(lpvac->szAlias);
 		g_free(lpvac->szBIcon);
+		if(lpvac->lpstoredimgOrigBIcon) purple_imgstore_unref(lpvac->lpstoredimgOrigBIcon);
 		g_free(lpvac);
 	}
 
@@ -185,9 +199,12 @@ void PurpleApplyVultureAccount(VULTURE_A
 		{
 			purple_account_set_bool(lpvac->lppac, "use-global-buddyicon", FALSE);
 
-			szUTF8 = lpvac->szBIcon ? VultureTCHARToUTF8(lpvac->szBIcon) : NULL;
-			SetAccountBuddyIcon(lpvac->lppac, szUTF8);
-			g_free(szUTF8);
+			if(lpvac->szBIcon || !lpvac->bPreserveBIcon)
+			{
+				szUTF8 = lpvac->szBIcon ? VultureTCHARToUTF8(lpvac->szBIcon) : NULL;
+				SetAccountBuddyIcon(lpvac->lppac, szUTF8);
+				g_free(szUTF8);
+			}
 		}
 	}
 
============================================================
--- vulture/purplebicon.c	1c47c141cfc1d65738888760aa98c15d79b431e5
+++ vulture/purplebicon.c	4131b6ef2980005aa8aea3c586587d39dd9635fa
@@ -33,7 +33,6 @@
 #include "purplemain.h"
 
 
-static HBITMAP GetBuddyIcon(gconstpointer lpvBuddyIconData, size_t cbBuddyIconData, int cxMax, int cyMax);
 static gpointer ConvertAndScaleBuddyIcon(const gchar *szFilename, PurplePlugin *lpplugin, gsize *lpcbImage);
 static void SetGlobalBuddyIcon(const gchar *szFilename);
 
@@ -50,7 +49,7 @@ static void SetGlobalBuddyIcon(const gch
  *
  * @return Bitmap handle, or NULL on error.
  */
-static HBITMAP GetBuddyIcon(gconstpointer lpvBuddyIconData, size_t cbBuddyIconData, int cxMax, int cyMax)
+HBITMAP VultureGetBuddyIcon(gconstpointer lpvBuddyIconData, size_t cbBuddyIconData, int cxMax, int cyMax)
 {
 	GdkPixbuf *lppixbuf;
 	GdkPixbufLoader *lppbloader;
@@ -218,7 +217,7 @@ HBITMAP PurpleGetIMBuddyIcon(PurpleConve
 
 
 	if(lpvBuddyIconData)
-		hbitmap = GetBuddyIcon(lpvBuddyIconData, cbBuddyIconData, cxMax, cyMax);
+		hbitmap = VultureGetBuddyIcon(lpvBuddyIconData, cbBuddyIconData, cxMax, cyMax);
 
 	/* These are safe even when their arguments are NULL. */
 	purple_imgstore_unref(lpstoredimg);
@@ -272,7 +271,7 @@ HBITMAP PurpleGetBlistNodeIcon(PurpleBli
 	}
 
 	if(lpvBuddyIconData)
-		hbitmap = GetBuddyIcon(lpvBuddyIconData, cbBuddyIconData, cxMax, cyMax);
+		hbitmap = VultureGetBuddyIcon(lpvBuddyIconData, cbBuddyIconData, cxMax, cyMax);
 
 	/* These are safe even when their arguments are NULL. */
 	purple_imgstore_unref(lpstoredimg);
@@ -480,7 +479,7 @@ void PurpleRefreshBuddyIcon(const gchar 
 		/* Make an HBITMAP and send it back to the UI for display in
 		 * the main window.
 		 */
-		HBITMAP hbmIcon = GetBuddyIcon(purple_imgstore_get_data(lpstoredimg), purple_imgstore_get_size(lpstoredimg), 0, 0);
+		HBITMAP hbmIcon = VultureGetBuddyIcon(purple_imgstore_get_data(lpstoredimg), purple_imgstore_get_size(lpstoredimg), 0, 0);
 		VulturePostUIMessage(VUIMSG_NEWGLOBALBICON, hbmIcon);
 		purple_imgstore_unref(lpstoredimg);
 	}
@@ -544,7 +543,7 @@ HBITMAP VultureLoadBuddyIcon(LPCTSTR szF
 			DWORD cbRead;
 
 			ReadFile(hFile, lpvData, cbFile, &cbRead, NULL);
-			hbitmap = GetBuddyIcon(lpvData, cbRead, cxMax, cyMax);
+			hbitmap = VultureGetBuddyIcon(lpvData, cbRead, cxMax, cyMax);
 
 			ProcHeapFree(lpvData);
 
============================================================
--- vulture/purplebicon.h	8fbf5be9362e08158997bfba1acc3214b5d4af04
+++ vulture/purplebicon.h	710cc9af5cc69a2450491ce3f775eb231b30a91b
@@ -29,6 +29,7 @@
 #include "purple.h"
 
 
+HBITMAP VultureGetBuddyIcon(gconstpointer lpvBuddyIconData, size_t cbBuddyIconData, int cxMax, int cyMax);
 HBITMAP PurpleGetIMBuddyIcon(PurpleConversation *lpconv, int cxMax, int cyMax);
 HBITMAP PurpleGetBlistNodeIcon(PurpleBlistNode *lpblistnode, int cxMax, int cyMax);
 void PurpleGlobalBuddyIconPrefChanged(const char *szName, PurplePrefType preftype, gconstpointer lpvValue, gpointer lpvData);


More information about the Commits mailing list