soc.2009.vulture: aa81614f: Add Chat.

gdick at soc.pidgin.im gdick at soc.pidgin.im
Fri Aug 7 11:50:35 EDT 2009


-----------------------------------------------------------------
Revision: aa81614fd6d530b0fece3cd164cdb3c9fc166f9d
Ancestor: fe8928ced680f02c4d3fd670905c585737a63e1c
Author: gdick at soc.pidgin.im
Date: 2009-08-06T12:16:30
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/aa81614fd6d530b0fece3cd164cdb3c9fc166f9d

Modified files:
        vulture/purpleblist.c vulture/purpleblist.h
        vulture/purplequeue.c vulture/purplequeue.h
        vulture/resource.h vulture/vulture-res.rc
        vulture/vultureblist.c vulture/vulturedlg.c
        vulture/vulturedlg.h

ChangeLog: 

Add Chat.

-------------- next part --------------
============================================================
--- vulture/purpleblist.c	98aa9bf2483610d73ceada0fc871483d160ea61c
+++ vulture/purpleblist.c	091ff8010aaff5882703a34ec62b6fae492cd047
@@ -832,3 +832,24 @@ void PurpleBlistUpdateLeaves(PurpleBlist
 			PurpleBlistUpdateNode(purple_get_blist(), lpblnRover);
 	}
 }
+
+
+/**
+ * Adds a chat.
+ *
+ * @param	lpvjcd	New chat's details.
+ */
+void PurpleAddChat(VULTURE_JOIN_CHAT_DATA *lpvjcd)
+{
+	PurpleChat *lpchat;
+	gchar *szAliasUTF8;
+
+	szAliasUTF8 = lpvjcd->szAlias ? VultureTCHARToUTF8(lpvjcd->szAlias) : NULL;
+
+	lpchat = purple_chat_new(lpvjcd->lppac, szAliasUTF8, lpvjcd->lphashParameters);
+	purple_blist_add_chat(lpchat, lpvjcd->lpvblistnodeGroup ? (PurpleGroup*)lpvjcd->lpvblistnodeGroup->lpblistnode : NULL, NULL);
+
+	PurpleBlistUpdateNode(purple_get_blist(), (PurpleBlistNode*)lpchat);
+
+	if(szAliasUTF8) g_free(szAliasUTF8);
+}
============================================================
--- vulture/purpleblist.h	d91223d2ed13ea091b2a02071a9202adf4f1d6db
+++ vulture/purpleblist.h	6beb850d71dec31ef09be3aeb6ac34c0671443ac
@@ -32,6 +32,16 @@
 
 
 
+typedef struct _VULTURE_JOIN_CHAT_DATA
+{
+	PurpleAccount		*lppac;
+	GHashTable		*lphashParameters;
+	LPTSTR			szAlias;
+	VULTURE_BLIST_NODE	*lpvblistnodeGroup;
+	BOOL			bJoinFieldsOnly;
+} VULTURE_JOIN_CHAT_DATA;
+
+
 typedef struct _VULTURE_ADD_BUDDY_DATA
 {
 	PurpleAccount		*lppac;
@@ -59,6 +69,7 @@ void PurpleBlistUpdateLeaves(PurpleBlist
 void VultureFreeGroupList(GList *lpglistGroups);
 void PurpleAddBuddy(VULTURE_ADD_BUDDY_DATA *lpvabd);
 void PurpleBlistUpdateLeaves(PurpleBlistNode *lpbln);
+void PurpleAddChat(VULTURE_JOIN_CHAT_DATA *lpvjcd);
 
 
 static INLINE void VultureBListNodeAddRef(VULTURE_BLIST_NODE *lpvblnode) { InterlockedIncrement(&lpvblnode->lRefCount); }
============================================================
--- vulture/purplequeue.c	2fd7f3ee0f77e5cc45298587acf4051586f6df99
+++ vulture/purplequeue.c	ea7a36f63513e76af10eab4dbb4a7aff43ec1f20
@@ -430,6 +430,10 @@ static void DispatchPurpleCall(PURPLE_CA
 
 		break;
 
+	case PC_ADDCHAT:
+		PurpleAddChat(lppurplecall->lpvParam);
+		break;
+
 	case PC_QUIT:
 		purple_core_quit();
 		g_main_loop_quit(g_lpgmainloop);
============================================================
--- vulture/purplequeue.h	24840087e08c5e3a0dcde1bdf3ddf3f98e755834
+++ vulture/purplequeue.h	ff807e3379db58b671c5c66c27ecb8bbb1a8fad8
@@ -123,6 +123,9 @@ enum PURPLE_CALL_ID
 
 	/* (VULTURE_ADD_BUDDY_DATA*) Username and account of person to IM. */
 	PC_STARTIM,
+
+	/* (VULTURE_JOIN_CHAT_DATA*) */
+	PC_ADDCHAT,
 };
 
 
============================================================
--- vulture/resource.h	6640dbf2b65bdbc0869b5427721679ab49304fb0
+++ vulture/resource.h	dc4f54bfcacacd7ade09e6779362988272d3c0b4
@@ -34,6 +34,7 @@
 #define IDD_STATUS                              107
 #define IDD_ADDBUDDY                            108
 #define IDD_IMBUDDY                             109
+#define IDD_ADDCHAT                             110
 
 
 #define IDM_BLIST                               1001
@@ -43,6 +44,7 @@
 #define IDM_BLIST_BUDDIES_ADDBUDDY              40003
 #define IDM_BLIST_VIEW_SHOWOFFLINE              40004
 #define IDM_BLIST_BUDDIES_IM                    40005
+#define IDM_BLIST_BUDDIES_ADDCHAT               40006
 
 #define IDM_BLIST_CONTEXT                       1002
 #define IDM_BLIST_CONTEXT_ACTIVATE              40201
============================================================
--- vulture/vulture-res.rc	70b1a3c32c4a1337e3d15ad6e19963857ca9e0b7
+++ vulture/vulture-res.rc	274fd2bb26fc393827c0d5087e4ea3542fff9b9f
@@ -20,6 +20,7 @@ IDM_BLIST MENU
         MENUITEM "&Join Chat...\tCtrl+J", IDM_BLIST_BUDDIES_JOINCHAT
         MENUITEM SEPARATOR
 	MENUITEM "&Add Buddy...\tCtrl+B", IDM_BLIST_BUDDIES_ADDBUDDY
+	MENUITEM "&Add Chat...", IDM_BLIST_BUDDIES_ADDCHAT
 	MENUITEM SEPARATOR
         MENUITEM "&Close", IDM_BLIST_BUDDIES_CLOSE
     }
@@ -157,6 +158,26 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_U
 
 
 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
+IDD_ADDCHAT DIALOG 0, 0, 204, 162
+STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU
+CAPTION "Add Chat"
+FONT 8, "Ms Shell Dlg"
+{
+    DEFPUSHBUTTON   "OK", IDOK, 95, 145, 50, 14, BS_DEFPUSHBUTTON
+    PUSHBUTTON      "Cancel", IDCANCEL, 150, 145, 50, 14, BS_PUSHBUTTON
+    LTEXT           "Please choose an account, and then enter the details of the chat that you wish to add to the buddy list.", IDC_STATIC, 5, 5, 195, 20, SS_LEFT
+    LTEXT           "&Account:", IDC_STATIC, 5, 32, 35, 10, SS_LEFT
+    CONTROL         "", IDC_CBEX_ACCOUNTS, "ComboBoxEx32", 0x50010003, 45, 30, 155, 90
+    GROUPBOX        "Details", IDC_STATIC_DETAILS, 5, 50, 195, 88
+    LTEXT           "&Group:", IDC_STATIC, 15, 62, 50, 10, SS_LEFT
+    CONTROL         "", IDC_CBEX_GROUP, "ComboBoxEx32", 0x50010003, 75, 60, 120, 90
+    LTEXT           "A&lias (optional):", IDC_STATIC, 15, 77, 50, 10, SS_LEFT
+    EDITTEXT        IDC_EDIT_ALIAS, 75, 75, 120, 12
+}
+
+
+
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
 IDD_BLIST DIALOG 0, 0, 186, 95
 STYLE DS_3DLOOK | DS_CENTER | DS_CONTROL | DS_SHELLFONT | WS_VISIBLE | WS_CHILDWINDOW
 FONT 8, "Ms Shell Dlg"
============================================================
--- vulture/vultureblist.c	e23d4f0587903da7e9823a533ba85d4fa5ffcf4d
+++ vulture/vultureblist.c	5cd64e9ac792a62246efcc8c29754c3e9bd4f219
@@ -208,6 +208,8 @@ static LRESULT CALLBACK MainWndProc(HWND
 			{
 				VULTURE_JOIN_CHAT_DATA vjcd;
 
+				vjcd.bJoinFieldsOnly = TRUE;
+
 				if(VultureJoinChatDlg(hwnd, &vjcd))
 					VultureSingleSyncPurpleCall(PC_JOINCHAT, &vjcd);
 			}
@@ -235,6 +237,26 @@ static LRESULT CALLBACK MainWndProc(HWND
 
 			return 0;
 
+		case IDM_BLIST_BUDDIES_ADDCHAT:
+			{
+				VULTURE_JOIN_CHAT_DATA vjcd;
+
+				vjcd.bJoinFieldsOnly = FALSE;
+
+				if(VultureJoinChatDlg(hwnd, &vjcd))
+				{
+					VultureSingleSyncPurpleCall(PC_ADDCHAT, &vjcd);
+
+					if(vjcd.lpvblistnodeGroup)
+						VultureBListNodeRelease(vjcd.lpvblistnodeGroup);
+
+					if(vjcd.szAlias)
+						ProcHeapFree(vjcd.szAlias);
+				}
+			}
+
+			return 0;
+
 		case IDM_BLIST_BUDDIES_CLOSE:
 			SendMessage(hwnd, WM_CLOSE, 0, 0);
 			return 0;
============================================================
--- vulture/vulturedlg.c	5519d48858ed8738b56cacf098fe90bbc661a57a
+++ vulture/vulturedlg.c	858951246d56058caea824676dbccdd32b9bcad7
@@ -53,6 +53,8 @@ typedef struct _JOIN_DLG_FIELD
 #define Y_JC_EDIT_FIRST		60
 #define CY_JC_INCREMENT		15
 
+#define ADD_CHAT_FIXED_FIELDS	2
+
 /* First ID for dynamic join-chat controls. */
 #define IDC_JC_DYNAMIC		2000
 
@@ -69,16 +71,18 @@ static void PopulateGroupsCombo(HWND hwn
 
 
 /**
- * Displays the "Join Chat" dialogue.
+ * Displays either the "Join Chat" or the "Add Chat" dialogue.
  *
- * @param	hwndParent	Parent window handle.
- * @param[out]	lpvjcd		Details of chat to join are returned here.
+ * @param		hwndParent	Parent window handle.
+ * @param[in,out]	lpvjcd		Details of chat to join are returned
+ *					here, and bJoinFieldsOnly determines
+ *					which flavour of dialogue to show.
  *
  * @return TRUE iff OKed.
  */
 BOOL VultureJoinChatDlg(HWND hwndParent, VULTURE_JOIN_CHAT_DATA *lpvjcd)
 {
-	return (BOOL)DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_JOINCHAT), hwndParent, JoinChatDlgProc, (LPARAM)lpvjcd);
+	return (BOOL)DialogBoxParam(g_hInstance, MAKEINTRESOURCE(lpvjcd->bJoinFieldsOnly ? IDD_JOINCHAT : IDD_ADDCHAT), hwndParent, JoinChatDlgProc, (LPARAM)lpvjcd);
 }
 
 
@@ -97,7 +101,7 @@ static INT_PTR CALLBACK JoinChatDlgProc(
 {
 	static int s_cyNonGroup = 0, s_cyButtonMargin = 0;
 	static GList *s_lpglistAccounts = NULL;
-	static VULTURE_JOIN_CHAT_DATA *s_lpvjcd = NULL;
+	static GList *s_lpglistGroups = NULL;
 	static GList *s_lpglistFields = NULL;
 	static int s_iMaxShowFields;
 
@@ -107,6 +111,7 @@ static INT_PTR CALLBACK JoinChatDlgProc(
 		{
 			VULTURE_GET_ACCOUNTS vgetaccounts;
 			RECT rcGroup, rcDlg, rcButton;
+			VULTURE_JOIN_CHAT_DATA *lpvjcd = (VULTURE_JOIN_CHAT_DATA*)lParam;
 
 			/* Get online accounts. */
 			vgetaccounts.bOnlineOnly = TRUE;
@@ -124,16 +129,16 @@ static INT_PTR CALLBACK JoinChatDlgProc(
 			s_cyNonGroup = rcDlg.bottom - rcGroup.bottom + rcGroup.top;
 			s_cyButtonMargin = rcDlg.bottom - rcButton.top;
 
-			/* We return stuff here. */
-			s_lpvjcd = (VULTURE_JOIN_CHAT_DATA*)lParam;
+			/* Remember our parameters. */
+			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lpvjcd);
 
 			/* No fields to start with. */
 			s_lpglistFields = NULL;
 
 			/* The dialogue is initially big enough to show three
-			 * fields.
+			 * fields, plus any fixed fields.
 			 */
-			s_iMaxShowFields = 3;
+			s_iMaxShowFields = 3 + (lpvjcd->bJoinFieldsOnly ? 0 : ADD_CHAT_FIXED_FIELDS);
 
 			/* Populate combo and select first item. */
 			PopulateAccountsCombo(GetDlgItem(hwndDlg, IDC_CBEX_ACCOUNTS), s_lpglistAccounts);
@@ -145,6 +150,17 @@ static INT_PTR CALLBACK JoinChatDlgProc(
 				UpdateJoinChatFields(hwndDlg, &s_lpglistFields, &s_iMaxShowFields);
 			}
 
+			if(!lpvjcd->bJoinFieldsOnly)
+			{
+				/* Get all groups. */
+				VultureSingleSyncPurpleCall(PC_GETGROUPS, &s_lpglistGroups);
+
+				/* Populate combo and select first item. */
+				PopulateGroupsCombo(GetDlgItem(hwndDlg, IDC_CBEX_GROUP), s_lpglistGroups);
+				if(SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_GETCOUNT, 0, 0) > 0)
+					SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_SETCURSEL, 0, 0);
+			}
+
 			AutoEnableJoinDlgOKButton(hwndDlg, s_lpglistFields);
 		}
 
@@ -164,15 +180,16 @@ static INT_PTR CALLBACK JoinChatDlgProc(
 			{
 				GList *lpglistRover;
 				COMBOBOXEXITEM cbexitem;
+				VULTURE_JOIN_CHAT_DATA *lpvjcd = (VULTURE_JOIN_CHAT_DATA*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
 
 				/* Get the selected account. */
 				cbexitem.mask = CBEIF_LPARAM;
 				cbexitem.iItem = SendDlgItemMessage(hwndDlg, IDC_CBEX_ACCOUNTS, CB_GETCURSEL, 0, 0);
 				SendDlgItemMessage(hwndDlg, IDC_CBEX_ACCOUNTS, CBEM_GETITEM, 0, (LPARAM)&cbexitem);
-				s_lpvjcd->lppac = ((VULTURE_ACCOUNT*)cbexitem.lParam)->lppac;
+				lpvjcd->lppac = ((VULTURE_ACCOUNT*)cbexitem.lParam)->lppac;
 
 				/* Build hash table. */
-				s_lpvjcd->lphashParameters = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+				lpvjcd->lphashParameters = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
 
 				for(lpglistRover = s_lpglistFields; lpglistRover; lpglistRover = lpglistRover->next)
 				{
@@ -188,10 +205,33 @@ static INT_PTR CALLBACK JoinChatDlgProc(
 						szFieldUTF8 = VultureTCHARToUTF8(szField);
 						ProcHeapFree(szField);
 
-						g_hash_table_replace(s_lpvjcd->lphashParameters, g_strdup(lpjdf->szID), szFieldUTF8);
+						g_hash_table_replace(lpvjcd->lphashParameters, g_strdup(lpjdf->szID), szFieldUTF8);
 					}
 				}
 
+				if(!lpvjcd->bJoinFieldsOnly)
+				{
+					int cch;
+
+					/* Get the selected group. */
+					cbexitem.mask = CBEIF_LPARAM;
+					cbexitem.iItem = SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_GETCURSEL, 0, 0);
+					SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CBEM_GETITEM, 0, (LPARAM)&cbexitem);
+					lpvjcd->lpvblistnodeGroup = (VULTURE_BLIST_NODE*)cbexitem.lParam;
+
+					if(lpvjcd->lpvblistnodeGroup)
+						VultureBListNodeAddRef(lpvjcd->lpvblistnodeGroup);
+
+					cch = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_EDIT_ALIAS)) + 1;
+					if(cch > 1)
+					{
+						lpvjcd->szAlias = ProcHeapAlloc(cch * sizeof(TCHAR));
+						GetDlgItemText(hwndDlg, IDC_EDIT_ALIAS, lpvjcd->szAlias, cch);
+					}
+					else
+						lpvjcd->szAlias = NULL;
+				}
+
 				EndDialog(hwndDlg, TRUE);
 			}
 
@@ -247,6 +287,7 @@ static INT_PTR CALLBACK JoinChatDlgProc(
 			GList *lpglistRover;
 
 			VultureFreeAccountList(s_lpglistAccounts);
+			VultureFreeGroupList(s_lpglistGroups);
 
 			for(lpglistRover = s_lpglistFields; lpglistRover; lpglistRover = lpglistRover->next)
 				ProcHeapFree(lpglistRover->data);
@@ -394,6 +435,7 @@ static void UpdateJoinChatFields(HWND hw
 	VULTURE_GET_CHAT_FIELDS getchatfields;
 	COMBOBOXEXITEM cbexitem;
 	int iFieldNum;
+	VULTURE_JOIN_CHAT_DATA *lpvjcd = (VULTURE_JOIN_CHAT_DATA*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
 
 	/* Destroy existing fields. */
 	for(lpglistRover = *lplpglistFields; lpglistRover; lpglistRover = lpglistRover->next)
@@ -421,7 +463,7 @@ static void UpdateJoinChatFields(HWND hw
 	*lplpglistFields = NULL;
 
 	/* Create new fields. */
-	for(lpglistRover = getchatfields.lpglistFields, iFieldNum = 0;
+	for(lpglistRover = getchatfields.lpglistFields, iFieldNum = lpvjcd->bJoinFieldsOnly ? 0 : ADD_CHAT_FIXED_FIELDS;
 		lpglistRover;
 		lpglistRover = lpglistRover->next, iFieldNum++)
 	{
@@ -501,7 +543,7 @@ static void AutoEnableJoinDlgOKButton(HW
  * Displays either the "Add Buddy" or the "Send IM" dialogue.
  *
  * @param		hwndParent	Parent window handle.
- * @param[in/out]	lpvabd		Details of buddy to add are returned
+ * @param[in,out]	lpvabd		Details of buddy to add are returned
  *					here, and bIMFieldsOnly determines
  *					which flavour of dialogue to show.
  *
============================================================
--- vulture/vulturedlg.h	5f0e633ff0ff9bbbb50702a6796c1fcfa4e43dd0
+++ vulture/vulturedlg.h	ab03d3af54670d9b3ddff21fd24bbeaa623bd67d
@@ -33,12 +33,6 @@
 #include "purpleblist.h"
 
 
-typedef struct _VULTURE_JOIN_CHAT_DATA
-{
-	PurpleAccount	*lppac;
-	GHashTable	*lphashParameters;
-} VULTURE_JOIN_CHAT_DATA;
-
 typedef struct _VULTURE_GET_CHAT_FIELDS
 {
 	VULTURE_ACCOUNT	*lpvac;


More information about the Commits mailing list