[Commits] plugin-init.c 1.3 1.4 xml-plugin.c 1.4 1.5

miras at claws-mail.org miras at claws-mail.org
Tue Oct 4 22:21:42 CEST 2011


Update of /home/claws-mail/contacts/plugins/xml
In directory claws-mail:/tmp/cvs-serv4887/plugins/xml

Modified Files:
	plugin-init.c xml-plugin.c 
Log Message:
2011-10-04 [mir]	0.6.0cvs20

	* dbus-client/client.c
	* plugins/example/example-plugin.c
	* plugins/ldap/ldap-plugin.c
	* plugins/xml/plugin-init.c
	* plugins/xml/xml-plugin.c
	* src/about.c
	* src/callbacks.c
	* src/claws-contacts.c
	* src/contactwindow.c
	* src/gtk-utils.c
	* src/mainwindow.c
	* src/plugin-loader.c
	* src/plugin-loader.h
	* src/plugin.h
	* src/printing.c
	* src/utils.c
	* src/utils.h
	* src/dbus/dbus-service.c
	* src/dbus/server-object.c
	* xmllib/parser.c
	* xmllib/parser.h
	    - Implemented forgotten functionality to reactivate closed
	    address books.
	    - Fix a ton of bugs.
	    - Extended plugin API so that it is possible to get a list
	      of closed address books as well as splitting attributes
	      in mandatory and optional.
	    - Provide plugins a way to have a fixed set of attributes.
	      Eg. LDAP has a finite set of attributes while XML supports
	      an infinite set of attributes. 

Index: plugin-init.c
===================================================================
RCS file: /home/claws-mail/contacts/plugins/xml/plugin-init.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- plugin-init.c	27 Sep 2011 17:13:04 -0000	1.3
+++ plugin-init.c	4 Oct 2011 20:21:40 -0000	1.4
@@ -76,7 +76,7 @@
 	g_file_get_contents(attrib_file, &contents, NULL, &err);
 	if (err) {
 		*error = g_strdup(err->message);
-		g_error_free(err);
+		g_clear_error(&err);
 	}
 	else {
 		if (strlen(contents) > 0) {

Index: xml-plugin.c
===================================================================
RCS file: /home/claws-mail/contacts/plugins/xml/xml-plugin.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- xml-plugin.c	27 Sep 2011 17:13:04 -0000	1.4
+++ xml-plugin.c	4 Oct 2011 20:21:40 -0000	1.5
@@ -64,6 +64,7 @@
 static GHashTable* attribs = NULL;
 static gboolean old_abook = TRUE;
 static GList* abooks = NULL;
+static GList* closed_books = NULL;
 static gchar self_home[] = "xml";
 static gchar configrc[] = "xmlrc";
 static ConfigFile* config = NULL;
@@ -145,7 +146,7 @@
 	
 	dir = g_dir_open(dir_path, 0, &error);
 	if (!dir || error) {
-		g_error_free(error);
+		g_clear_error(&error);
 		if (dir)
 			g_dir_close(dir);
 		return;
@@ -190,7 +191,7 @@
 static void abooks_free() {
 	GList* cur;
 	
-	if (abooks == NULL)
+	if (! abooks && ! closed_books)
 		return;
 		
 	for (cur = abooks; cur; cur = g_list_next(cur)) {
@@ -199,6 +200,13 @@
 	}
 	g_list_free(abooks);
 	abooks = NULL;
+
+	for (cur = closed_books; cur; cur = g_list_next(cur)) {
+		AddressBook* abook = (AddressBook *) cur->data;
+		address_book_free(&abook);
+	}
+	g_list_free(closed_books);
+	closed_books = NULL;
 }
 
 static void open_addr_book(AddressBook* abook, gchar** error) {
@@ -392,7 +400,7 @@
 	g_free(new_path);
 }
 
-static void write_config_file(GSList** books) {
+static void write_config_file(GSList** books, GSList** closed) {
 	GSList *cur, *tmp, *cur_attribs;
 	gchar* error = NULL;
 	gchar* path = NULL;
@@ -420,7 +428,16 @@
 		g_free(book);
 	}
 	gslist_free(books, NULL);
-	*books = NULL;
+
+	config->closed_books->group = g_strdup("closed address books");
+
+	for (cur = *closed; cur; cur = g_slist_next(cur)) {
+		gchar* book = (gchar *) cur->data;
+		config->closed_books->books =
+			g_slist_prepend(config->closed_books->books, g_strdup(book));
+		g_free(book);
+	}
+	gslist_free(closed, NULL);
 	
 	plugin_config_set(config, &error);
 	if (error) {
@@ -468,7 +485,7 @@
 static void write_config() {
 	gchar *basedir, *new_path, *buffer, *path;
 	GList *books, *contacts;
-	GSList *addr_books = NULL, *cur;
+	GSList *addr_books = NULL, *cl_books = NULL, *cur;
 	FILE *file;
 	gboolean backup = TRUE;
 	gboolean append;
@@ -561,7 +578,12 @@
 		}
 	}
 
-	write_config_file(&addr_books);
+	for (books = closed_books; books; books = g_list_next(books)) {
+		AddressBook* book = (AddressBook *) books->data;
+		set_configured_books(&cl_books, book);
+	}
+	
+	write_config_file(&addr_books, &cl_books);
 	
 	g_free(basedir);
 	
@@ -776,6 +798,12 @@
 	}
 }
 
+static void closed_books_remove(AddressBook* book) {
+	GList* found = g_list_find_custom(closed_books, book, address_book_compare);
+	if (found)
+		closed_books = g_list_remove_link(closed_books, found);
+}
+
 gboolean plugin_init(gchar** error) {
 	gchar *basedir, *path;
 	GSList *list = NULL, *cur, *found;
@@ -830,6 +858,27 @@
 						}
 					}
 				}
+				if (cl_books) {
+					g_free(path);
+					path = g_strconcat(basedir, G_DIR_SEPARATOR_S,
+						self_home, G_DIR_SEPARATOR_S, NULL);
+					for (cur = cl_books->books; cur; cur = g_slist_next(cur)) {
+						gchar* book = (gchar *) cur->data;
+						found = g_slist_find_custom(
+							cf_books->books, book, compare_book_names);
+						if (! found) {
+							AddressBook* abook = address_book_new();
+							abook->URL = g_strconcat(path, book, ".xml", NULL);
+							addr_book_set_name(abook, error);
+							if (*error) {
+								show_message(NULL, GTK_UTIL_MESSAGE_ERROR, "%s", *error);
+								g_free(*error);
+								*error = NULL;
+							}
+							closed_books = g_list_prepend(closed_books, abook);
+						}
+					}
+				}
 				config_get_value(config, "supported attributes", "attributes", &list);				
 				attribs = hash_table_new();
 				for (cur = list; cur; cur = g_slist_next(cur)) {
@@ -1092,6 +1141,7 @@
 		attribute_list_free(&books);
 	}
 	else {
+		closed_books_remove(abook);
 		if (abook->dirty) {
 			open_addr_book(abook, error);
 			if (*error) {
@@ -1125,9 +1175,10 @@
 
 gboolean plugin_abook_close(AddressBook* abook, gchar** error) {
 	debug_print("List contains %d elements before\n", g_list_length(abooks));
-	address_book_contacts_free(abook);
 	abooks = g_list_remove(abooks, abook);
+	address_book_contacts_free(abook);
 	debug_print("List contains %d elements after\n", g_list_length(abooks));
+	closed_books = g_list_prepend(closed_books, abook);
 	return TRUE;
 }
 
@@ -1182,4 +1233,15 @@
 
 GSList* plugin_inactive_attribs(void) {
 	return gslist_deep_copy(inactive_attribs, attrib_def_copy);
+}
+
+GList* plugin_closed_books_get(void) {
+	GList *cur, *list = NULL;
+	
+	for (cur = closed_books; cur; cur = g_list_next(cur)) {
+		/* No deep copy since list of contacts will always be NULL */
+		list = g_list_prepend(list, address_book_copy(cur->data, FALSE));
+	}
+	
+	return list;
 }
\ No newline at end of file



More information about the Commits mailing list