[Commits] about.c 1.3 1.4 extension-loader.c 1.7 1.8 extension-loader.h 1.3 1.4

miras at claws-mail.org miras at claws-mail.org
Wed Dec 28 01:52:07 CET 2011


Update of /home/claws-mail/contacts/src
In directory claws-mail:/tmp/cvs-serv4479/src

Modified Files:
	about.c extension-loader.c extension-loader.h 
Log Message:
2011-12-28 [mir]	0.6.0cvs59

	* src/about.c
	* src/extension-loader.c
	* src/extension-loader.h
	    Fix bug when inserting a submenu into a context menu
	    A cosmetic change in about.c 

Index: extension-loader.h
===================================================================
RCS file: /home/claws-mail/contacts/src/extension-loader.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- extension-loader.h	14 Dec 2011 08:27:03 -0000	1.3
+++ extension-loader.h	28 Dec 2011 00:52:05 -0000	1.4
@@ -56,6 +56,7 @@
 	const gchar*	parent;
 	const gchar*	sublabel;
 	GtkWidget*		menu;
+	GtkWidget*		widget;
 } UserMenuItem;
 
 void init_hooks(MainWindow* main);

Index: extension-loader.c
===================================================================
RCS file: /home/claws-mail/contacts/src/extension-loader.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- extension-loader.c	21 Dec 2011 22:02:52 -0000	1.7
+++ extension-loader.c	28 Dec 2011 00:52:05 -0000	1.8
@@ -264,7 +264,18 @@
 	else
 		*extension = NULL;
 }
+
+static void user_menu_items_free(gpointer item) {
+	UserMenuItem* menu;
 	
+	if (! item)
+		return;
+		
+	menu = (UserMenuItem *) item;
+	g_free(menu->parent);
+	g_free(menu->sublabel);
+}
+
 void extension_loader_done() {
 	done_hooks();
 	if (extensions) {
@@ -274,7 +285,9 @@
 	mainwindow = NULL;
 	NEXT_ID = 1;
 
-	gslist_free(&user_menu_items, NULL);
+	gslist_free(&user_menu_items, user_menu_items_free);
+	gslist_free(&contact_context, user_menu_items_free);
+	gslist_free(&abook_context, user_menu_items_free);
 }
 
 static GSList* get_extension_path(gchar** error) {
@@ -390,14 +403,25 @@
 }
 
 GSList* get_menu_items(ContactsMenu menu) {
-	GSList* widgets = NULL;
+	GSList *widgets = NULL, *cur;
+	UserMenuItem* item;
 	
 	switch (menu) {
 		case CONTACTS_ADDRESSBOOK_MENU:
-			widgets = abook_context;
+			cur = abook_context;
+			while (cur) {
+				item = (UserMenuItem *) cur->data;
+				widgets = g_slist_prepend(widgets, item->widget);
+				cur = cur->next;
+			}
 			break;
 		case CONTACTS_CONTACT_MENU:
-			widgets = contact_context;
+			cur = contact_context;
+			while (cur) {
+				item = (UserMenuItem *) cur->data;
+				widgets = g_slist_prepend(widgets, item->widget);
+				cur = cur->next;
+			}
 			break;
 		default:
 			break;
@@ -435,8 +459,11 @@
 				if (utf8_collate((gchar *) item->sublabel, (gchar *) menu_item->sublabel) == 0 ||
 					utf8_collate((gchar *) item->parent, (gchar *) item->sublabel) == 0) {
 					menu = item->menu;
-					if (utf8_collate((gchar *) item->parent, (gchar *) item->sublabel) == 0)
+					debug_print("parent: %s sublabel: %s\n", item->parent, item->sublabel);
+					if (utf8_collate((gchar *) item->parent, (gchar *) item->sublabel) == 0) {
 						force = TRUE;
+						debug_print("force\n");
+					}
 				}
 			}
 		}
@@ -448,15 +475,17 @@
 			else
 				menu = create_menu_item(&widget, menu_item->sublabel);
 			user_menu->menu = (force)? tmp : menu;
-			user_menu->sublabel = menu_item->sublabel;
+			user_menu->sublabel = g_strdup(menu_item->sublabel);
 		}
 		if (menu) {
 			if (force) {
 				gtk_menu_shell_append(GTK_MENU_SHELL(menu), widget);
 				widget = NULL;
 			}
-			else
+			else {
 				gtk_menu_shell_append(GTK_MENU_SHELL(menu), GTK_WIDGET(image_menu));
+				//widget = GTK_WIDGET(image_menu);
+			}
 		}
 	}
 	else
@@ -465,6 +494,42 @@
 	return widget;
 }
 
+static gboolean insert_context_sub_menu(ContactsMenu menu,
+										  UserMenuItem* menu_item) {
+	GtkWidget* widget = NULL;
+	GSList* cur;
+	UserMenuItem* item;
+	
+	if (menu_item->sublabel) {
+		switch (menu) {
+			case CONTACTS_ADDRESSBOOK_MENU:
+				cur = abook_context;
+				break;
+			case CONTACTS_CONTACT_MENU:
+				cur = contact_context;
+				break;
+			default:
+				cm_return_val_if_fail(TRUE, FALSE);
+		}
+		while (cur) {
+			item = (UserMenuItem *) cur->data;
+			if (item->sublabel) {
+				if (strcmp(item->sublabel, menu_item->sublabel) == 0) {
+					gtk_menu_shell_append(GTK_MENU_SHELL(item->menu),
+						menu_item->widget);
+					return FALSE;
+				}
+			}
+			cur = cur->next;
+		}
+		menu_item->menu = create_menu_item(&widget, menu_item->sublabel);
+		gtk_menu_shell_append(GTK_MENU_SHELL(menu_item->menu), menu_item->widget);
+		menu_item->widget = widget;
+	}
+
+	return TRUE;
+}
+
 MenuItem* menu_item_new(void) {
 	MenuItem* item;
 	
@@ -506,7 +571,7 @@
 		// add to 'File'
 		menu_elem = insert_sub_menu(image_menu, menu_item, menu);
 		if (menu->sublabel && menu_item->parent)
-			menu->parent = menu_item->parent;
+			menu->parent = g_strdup(menu_item->parent);
 		else {
 			g_free(menu);
 			menu = NULL;
@@ -519,7 +584,7 @@
 		// add to 'Tools' 
 		menu_elem = insert_sub_menu(image_menu, menu_item, menu);
 		if (menu->sublabel && menu_item->parent)
-			menu->parent = menu_item->parent;
+			menu->parent = g_strdup(menu_item->parent);
 		else {
 			g_free(menu);
 			menu = NULL;
@@ -530,7 +595,7 @@
 		// add to 'Help' 
 		menu_elem = insert_sub_menu(image_menu, menu_item, menu);
 		if (menu->sublabel && menu_item->parent)
-			menu->parent = menu_item->parent;
+			menu->parent = g_strdup(menu_item->parent);
 		else {
 			g_free(menu);
 			menu = NULL;
@@ -539,12 +604,12 @@
 	}
 	else if (menu_item->menu == CONTACTS_MAIN_MENU) {
 		if (! menu_item->sublabel) {
-			menu_item->sublabel = menu_item->parent;
+			menu_item->sublabel = g_strdup(menu_item->parent);
 			menu_item->submenu = TRUE;
 		}
 		menu_elem = insert_sub_menu(image_menu, menu_item, menu);
 		if (menu->sublabel && menu_item->parent)
-			menu->parent = menu_item->parent;
+			menu->parent = g_strdup(menu_item->parent);
 		else {
 			g_free(menu);
 			menu = NULL;
@@ -557,22 +622,25 @@
 	else {
 		// context menu
 		if (menu_item->menu == CONTACTS_CONTACT_MENU) {
-			menu_elem = insert_sub_menu(image_menu, menu_item, menu);
-			if (menu->sublabel && menu_item->parent)
-				menu->parent = menu_item->parent;
-			if (menu_elem)
-				contact_context = g_slist_append(contact_context, menu_elem);
+			menu->widget = GTK_WIDGET(image_menu);
+			menu->sublabel = g_strdup(menu_item->sublabel);
+			if (insert_context_sub_menu(menu_item->menu, menu))
+				contact_context = g_slist_append(contact_context, menu);
+			else
+				user_menu_items_free(menu);
 		}
 		else if (menu_item->menu == CONTACTS_ADDRESSBOOK_MENU) {
-			menu_elem = insert_sub_menu(image_menu, menu_item, menu);
-			if (menu->sublabel && menu_item->parent)
-				menu->parent = menu_item->parent;
-			if (menu_elem)
-				abook_context = g_slist_append(abook_context, menu_elem);
+			menu->widget = GTK_WIDGET(image_menu);
+			menu->sublabel = g_strdup(menu_item->sublabel);
+			if (insert_context_sub_menu(menu_item->menu, menu))
+				abook_context = g_slist_append(abook_context, menu);
+			else
+				user_menu_items_free(menu);
 		}
 		else {
 			// error!!!!
 		}
+		menu = NULL;
 	}
 
 	if (menu)

Index: about.c
===================================================================
RCS file: /home/claws-mail/contacts/src/about.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- about.c	28 Nov 2011 17:52:14 -0000	1.3
+++ about.c	28 Dec 2011 00:52:05 -0000	1.4
@@ -1,5 +1,5 @@
 /*
- * Id:          $Id$
+ * $Id$
  */
 /* vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: */
 



More information about the Commits mailing list