evolution r36836 - in trunk: addressbook addressbook/gui/widgets calendar calendar/gui e-util filter



Author: mcrha
Date: Fri Dec  5 19:20:28 2008
New Revision: 36836
URL: http://svn.gnome.org/viewvc/evolution?rev=36836&view=rev

Log:
2008-12-05  Milan Crha  <mcrha redhat com>

	** Fix for bug #332629

	* filter/filter-option.h: (struct _filter_option),
	(struct _FilterOption), (filter_option_add):
	* filter/filter-option.c: (filter_option_init), (filter_option_finalise),
	(filter_option_add), (xml_create), (get_widget), (clone):
	Be able to define optionlist with dynamically created list of options.

	* filter/filter-label.c: (fill_options): Adapt.

	* addressbook/gui/widgets/addresstypes.xml:
	* calendar/gui/caltypes.xml:
	* calendar/gui/memotypes.xml:
	* calendar/gui/tasktypes.xml:
	Use dynamically created list of categories in the option's widget.



Modified:
   trunk/addressbook/ChangeLog
   trunk/addressbook/gui/widgets/addresstypes.xml
   trunk/calendar/ChangeLog
   trunk/calendar/gui/caltypes.xml
   trunk/calendar/gui/memotypes.xml
   trunk/calendar/gui/tasktypes.xml
   trunk/e-util/ChangeLog
   trunk/e-util/e-util.c
   trunk/e-util/e-util.h
   trunk/filter/ChangeLog
   trunk/filter/filter-label.c
   trunk/filter/filter-option.c
   trunk/filter/filter-option.h

Modified: trunk/addressbook/gui/widgets/addresstypes.xml
==============================================================================
--- trunk/addressbook/gui/widgets/addresstypes.xml	(original)
+++ trunk/addressbook/gui/widgets/addresstypes.xml	Fri Dec  5 19:20:28 2008
@@ -74,72 +74,7 @@
     </option>
    </input>
    <input type="optionlist" name="category">
-    <option value="Anniversary">
-        <title>Anniversary</title>
-    </option>
-    <option value="Holiday">
-        <title>Holiday</title>
-    </option>
-    <option value="Ideas">
-        <title>Ideas</title>
-    </option>
-    <option value="Status">
-        <title>Status</title>
-    </option>
-    <option value="Holiday Cards">
-        <title>Holiday Cards</title>
-    </option>
-    <option value="Hot Contacts">
-        <title>Hot Contacts</title>
-    </option>
-    <option value="International">
-        <title>International</title>
-    </option>
-    <option value="Birthday">
-        <title>Birthday</title>
-    </option>
-    <option value="VIP">
-        <title>VIP</title>
-    </option>
-    <option value="Gifts">
-        <title>Gifts</title>
-    </option>
-    <option value="Waiting">
-        <title>Waiting</title>
-    </option>
-    <option value="Key Customer">
-        <title>Key Customer</title>
-    </option>
-    <option value="Time &amp; Expenses">
-        <title>Time &amp; Expenses </title>
-    </option>
-    <option value="Miscellaneous">
-        <title>Miscellaneous</title>
-    </option>
-    <option value="Business">
-        <title>Business</title>
-    </option>
-    <option value="Personal">
-        <title>Personal</title>
-    </option>
-    <option value="Suppliers">
-        <title>Suppliers</title>
-    </option>
-    <option value="Goals/Objectives">
-        <title>Goals/Objectives</title>
-    </option>
-    <option value="Strategies">
-        <title>Strategies</title>
-    </option>
-    <option value="Competition">
-        <title>Competition</title>
-    </option>
-    <option value="Favourites">
-        <title>Favourites</title>
-    </option>
-    <option value="Phone Calls">
-        <title>Phone Calls</title>
-    </option>
+      <dynamic func="e_util_get_category_filter_options"/>
    </input>
  </part>
  <part name="sexp">

Modified: trunk/calendar/gui/caltypes.xml
==============================================================================
--- trunk/calendar/gui/caltypes.xml	(original)
+++ trunk/calendar/gui/caltypes.xml	Fri Dec  5 19:20:28 2008
@@ -129,75 +129,7 @@
 	     </option>
 	    </input>
 	   <input type="optionlist" name="category">
-	    <option value="Anniversary">
-	        <_title>Anniversary</_title>
-	    </option>
-	    <option value="Holiday">
-	        <_title>Holiday</_title>
-	    </option>
-	    <option value="Ideas">
-	        <_title>Ideas</_title>
-	    </option>
-	    <option value="Status">
-	        <_title>Status</_title>
-	    </option>
-	    <option value="Holiday Cards">
-	        <_title>Holiday Cards</_title>
-	    </option>
-	    <option value="Hot Contacts">
-	        <_title>Hot Contacts</_title>
-	    </option>
-	    <option value="International">
-	        <_title>International</_title>
-	    </option>
-	    <option value="Next 7 days">
-	        <_title>Next 7 days</_title>
-	    </option>
-	    <option value="Birthday">
-	        <_title>Birthday</_title>
-	    </option>
-	    <option value="VIP">
-	        <_title>VIP</_title>
-	    </option>
-	    <option value="Gifts">
-	        <_title>Gifts</_title>
-	    </option>
-	    <option value="Waiting">
-	        <_title>Waiting</_title>
-	    </option>
-	    <option value="Key Customer">
-	        <_title>Key Customer</_title>
-	    </option>
-	    <option value="Time &amp; Expenses">
-	        <_title>Time &amp; Expenses </_title>
-	    </option>
-	    <option value="Miscellaneous">
-	        <_title>Miscellaneous</_title>
-	    </option>
-	    <option value="Business">
-	        <_title>Business</_title>
-	    </option>
-	    <option value="Personal">
-	        <_title>Personal</_title>
-	    </option>
-	    <option value="Suppliers">
-        	<_title>Suppliers</_title>
-	    </option>
-	    <option value="Goals/Objectives">
-	        <_title>Goals/Objectives</_title>
-	    </option>
-	    <option value="Strategies">
-	        <_title>Strategies</_title>
-	    </option>
-	    <option value="Competition">
-	        <_title>Competition</_title>
-	    </option>
-	    <option value="Favourites">
-	        <_title>Favourites</_title>
-	    </option>
-	    <option value="Phone Calls">
-	        <_title>Phone Calls</_title>
-	    </option>
+		<dynamic func="e_util_get_category_filter_options"/>
 	   </input>
     </part>
 

Modified: trunk/calendar/gui/memotypes.xml
==============================================================================
--- trunk/calendar/gui/memotypes.xml	(original)
+++ trunk/calendar/gui/memotypes.xml	Fri Dec  5 19:20:28 2008
@@ -99,75 +99,7 @@
      </option>
     </input>
    <input type="optionlist" name="category">
-    <option value="Anniversary">
-        <_title>Anniversary</_title>
-    </option>
-    <option value="Holiday">
-        <_title>Holiday</_title>
-    </option>
-    <option value="Ideas">
-        <_title>Ideas</_title>
-    </option>
-    <option value="Status">
-        <_title>Status</_title>
-    </option>
-    <option value="Holiday Cards">
-        <_title>Holiday Cards</_title>
-    </option>
-    <option value="Hot Contacts">
-        <_title>Hot Contacts</_title>
-    </option>
-    <option value="International">
-        <_title>International</_title>
-    </option>
-    <option value="Next 7 days">
-        <_title>Next 7 Days</_title>
-    </option>
-    <option value="Birthday">
-        <_title>Birthday</_title>
-    </option>
-    <option value="VIP">
-        <_title>VIP</_title>
-    </option>
-    <option value="Gifts">
-        <_title>Gifts</_title>
-    </option>
-    <option value="Waiting">
-        <_title>Waiting</_title>
-    </option>
-    <option value="Key Customer">
-        <_title>Key Customer</_title>
-    </option>
-    <option value="Time &amp; Expenses">
-        <_title>Time &amp; Expenses</_title>
-    </option>
-    <option value="Miscellaneous">
-        <_title>Miscellaneous</_title>
-    </option>
-    <option value="Business">
-        <_title>Business</_title>
-    </option>
-    <option value="Personal">
-        <_title>Personal</_title>
-    </option>
-    <option value="Suppliers">
-        <_title>Suppliers</_title>
-    </option>
-    <option value="Goals/Objectives">
-        <_title>Goals/Objectives</_title>
-    </option>
-    <option value="Strategies">
-        <_title>Strategies</_title>
-    </option>
-    <option value="Competition">
-        <_title>Competition</_title>
-    </option>
-    <option value="Favourites">
-        <_title>Favourites</_title>
-    </option>
-    <option value="Phone Calls">
-        <_title>Phone Calls</_title>
-    </option>
+      <dynamic func="e_util_get_category_filter_options"/>
    </input>
  </part>
 

Modified: trunk/calendar/gui/tasktypes.xml
==============================================================================
--- trunk/calendar/gui/tasktypes.xml	(original)
+++ trunk/calendar/gui/tasktypes.xml	Fri Dec  5 19:20:28 2008
@@ -165,76 +165,7 @@
                 </option>
             </input>
             <input type="optionlist" name="category">
-                <option value="Anniversary">
-                    <_title>Anniversary</_title>
-                </option>
-                <option value="Holiday">
-                    <_title>Holiday</_title>
-                </option>
-                <option value="Ideas">
-                    <_title>Ideas</_title>ke
-                </option>
-                <option value="Status">
-                    <_title>Status</_title>
-                </option>
-                <option value="Holiday Cards">
-                    <_title>Holiday Cards</_title>
-                </option>
-                <option value="Hot Contacts">
-                    <_title>Hot Contacts</_title>
-                </option>
-                <option value="International">
-                    <_title>International</_title>
-                </option>
-                <option value="Next 7 days">
-                    <_title>Next 7 days</_title>
-                </option>
-                <option value="Birthday">
-                    <_title>Birthday</_title>
-                </option>
-                <option value="VIP">
-                    <_title>VIP</_title>
-                </option>
-                <option value="Gifts">
-                    <_title>Gifts</_title>
-                </option>
-                <option value="Waiting">
-                    <_title>Waiting</_title>
-                </option>
-                <option value="Key Customer">
-                    <_title>Key Customer</_title>
-                </option>
-                <option value="Time &amp; Expenses">
-                    <_title>Time &amp; Expenses </_title>
-                </option>
-                <option value="Miscellaneous">
-                    <_title>Miscellaneous</_title>
-                </option>
-                <option value="Business">
-                    <_title>Business</_title>
-                </option>
-                <option value="Personal">
-                    ke
-                    <_title>Personal</_title>
-                </option>
-                <option value="Suppliers">
-                    <_title>Suppliers</_title>
-                </option>
-                <option value="Goals/Objectives">
-                    <_title>Goals/Objectives</_title>
-                </option>
-                <option value="Strategies">
-                    <_title>Strategies</_title>
-                </option>
-                <option value="Competition">
-                    <_title>Competition</_title>
-                </option>
-                <option value="Favourites">
-                    <_title>Favourites</_title>
-                </option>
-                <option value="Phone Calls">
-                    <_title>Phone Calls</_title>
-                </option>
+		<dynamic func="e_util_get_category_filter_options"/>
             </input>
         </part>
 

Modified: trunk/e-util/e-util.c
==============================================================================
--- trunk/e-util/e-util.c	(original)
+++ trunk/e-util/e-util.c	Fri Dec  5 19:20:28 2008
@@ -46,6 +46,8 @@
 #endif
 
 #include <libedataserver/e-data-server-util.h>
+#include <libedataserver/e-categories.h>
+#include "filter/filter-option.h"
 #include "e-util.h"
 #include "e-util-private.h"
 
@@ -1224,3 +1226,23 @@
 	return res;
 }
 
+GSList *
+e_util_get_category_filter_options (void)
+{
+	GSList *res = NULL;
+	GList *clist, *l;
+
+	clist = e_categories_get_list ();
+	for (l = clist; l; l = l->next) {
+		const char *cname = l->data;
+		struct _filter_option *fo = g_new0 (struct _filter_option, 1);
+
+		fo->title = g_strdup (cname);
+		fo->value = g_strdup (cname);
+		res = g_slist_prepend (res, fo);
+	}
+
+	g_list_free (clist);
+
+	return g_slist_reverse (res);
+}

Modified: trunk/e-util/e-util.h
==============================================================================
--- trunk/e-util/e-util.h	(original)
+++ trunk/e-util/e-util.h	Fri Dec  5 19:20:28 2008
@@ -125,6 +125,8 @@
 						 gsize *read,
 						 GError **error);
 
+GSList *e_util_get_category_filter_options      (void);
+
 G_END_DECLS
 
 #endif /* _E_UTIL_H_ */

Modified: trunk/filter/filter-label.c
==============================================================================
--- trunk/filter/filter-label.c	(original)
+++ trunk/filter/filter-label.c	Fri Dec  5 19:20:28 2008
@@ -192,7 +192,7 @@
 		if (tag && strncmp (tag, "$Label", 6) == 0)
 			tag += 6;
 
-		filter_option_add (fo, tag, title, NULL);
+		filter_option_add (fo, tag, title, NULL, FALSE);
 
 		g_free (title);
 	}

Modified: trunk/filter/filter-option.c
==============================================================================
--- trunk/filter/filter-option.c	(original)
+++ trunk/filter/filter-option.c	Fri Dec  5 19:20:28 2008
@@ -29,6 +29,7 @@
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
+#include <dlfcn.h>
 
 #include "filter-option.h"
 #include "filter-part.h"
@@ -102,6 +103,7 @@
 filter_option_init (FilterOption *fo)
 {
 	fo->type = "option";
+	fo->dynamic_func = NULL;
 }
 
 static void
@@ -120,6 +122,7 @@
 
 	g_list_foreach (fo->options, (GFunc)free_option, NULL);
 	g_list_free (fo->options);
+	g_free (fo->dynamic_func);
 
         G_OBJECT_CLASS (parent_class)->finalize (obj);
 }
@@ -164,7 +167,7 @@
 
 /* used by implementers to add additional options */
 struct _filter_option *
-filter_option_add(FilterOption *fo, const char *value, const char *title, const char *code)
+filter_option_add(FilterOption *fo, const char *value, const char *title, const char *code, gboolean is_dynamic)
 {
 	struct _filter_option *op;
 
@@ -175,6 +178,7 @@
 	op->title = g_strdup(title);
 	op->value = g_strdup(value);
 	op->code = g_strdup(code);
+	op->is_dynamic = is_dynamic;
 
 	fo->options = g_list_append(fo->options, op);
 	if (fo->current == NULL)
@@ -253,10 +257,34 @@
 				work = work->next;
 			}
 
-			filter_option_add (fo, value, title, code);
+			filter_option_add (fo, value, title, code, FALSE);
 			xmlFree (value);
 			g_free (title);
 			g_free (code);
+		} else if (g_str_equal ((char *)n->name, "dynamic")) {
+			if (fo->dynamic_func) {
+				g_warning ("Only one 'dynamic' node is acceptable in the optionlist '%s'", fe->name);
+			} else {
+				/* Expecting only one <dynamic func="cb" /> in the option list,
+				   The 'cb' should be of this prototype:
+				   GSList *cb (void);
+				   returning GSList of struct _filter_option, all newly allocated, because it'll
+				   be freed with g_free and g_slist_free. 'is_dynamic' member is ignored here.
+				*/
+				xmlChar *fn;
+
+				fn = xmlGetProp (n, (const unsigned char *)"func");
+				if (fn && *fn) {
+					fo->dynamic_func = g_strdup ((const char *)fn);
+
+					/* to remember where to place them */
+					filter_option_add (fo, "fake_dynamic", "fake_dynamic", NULL, TRUE);
+				} else {
+					g_warning ("Missing 'func' attribute within '%s' node in optionlist '%s'", n->name, fe->name);
+				}
+
+				xmlFree (fn);
+			}
 		} else if (n->type == XML_ELEMENT_NODE) {
 			g_warning ("Unknown xml node within optionlist: %s\n", n->name);
 		}
@@ -315,11 +343,75 @@
 	GtkWidget *omenu;
 	GtkWidget *item;
 	GtkWidget *first = NULL;
-	GList *l = fo->options;
+	GList *l;
 	struct _filter_option *op;
 	int index = 0, current = 0;
 
+	if (fo->dynamic_func) {
+		/* it is dynamically filled, thus remove all dynamics and put there the fresh ones */
+		GList *old_ops;
+		struct _filter_option *old_cur;
+		void *module;
+		GSList *(*get_func)(void);
+
+		old_ops = fo->options;
+		old_cur = fo->current;
+		l = old_ops;
+
+		/* start with an empty list */
+		fo->current = NULL;
+		fo->options = NULL;
+
+		for (l = fo->options; l; l = l->next) {
+			op = l->data;
+
+			if (op->is_dynamic) {
+				break;
+			} else {
+				filter_option_add (fo, op->value, op->title, op->code, FALSE);
+			}
+		}
+
+		module = dlopen (NULL, RTLD_LAZY);
+
+		get_func = dlsym (module, fo->dynamic_func);
+		if (get_func) {
+			GSList *items, *i;
+
+			items = get_func ();
+			for (i = items; i; i = i->next) {
+				op = i->data;
+
+				if (op) {
+					filter_option_add (fo, op->value, op->title, op->code, TRUE);
+					free_option (op, NULL);
+				}
+			}
+
+			g_slist_free (items);
+		} else
+			g_warning ("optionlist dynamic fill function '%s' not found", fo->dynamic_func);
+
+		dlclose (module);
+
+		/* maybe some static left after those dynamic, add them too */
+		for (; l; l = l->next) {
+			op = l->data;
+
+			if (!op->is_dynamic)
+				filter_option_add (fo, op->value, op->title, op->code, FALSE);
+		}
+
+		if (old_cur)
+			filter_option_set_current (fo, old_cur->value);
+
+		/* free old list */
+		g_list_foreach (old_ops, (GFunc)free_option, NULL);
+		g_list_free (old_ops);
+	}
+
 	menu = gtk_menu_new ();
+	l = fo->options;
 	while (l) {
 		op = l->data;
 		item = gtk_menu_item_new_with_label (_(op->title));
@@ -382,12 +474,14 @@
 	l = fo->options;
 	while (l) {
 		op = l->data;
-		newop = filter_option_add (new, op->value, op->title, op->code);
+		newop = filter_option_add (new, op->value, op->title, op->code, op->is_dynamic);
 		if (fo->current == op)
 			new->current = newop;
 		l = l->next;
 	}
 
+	new->dynamic_func = g_strdup (fo->dynamic_func);
+
 	d(printf ("cloning option code %p, current = %p\n", new, new->current));
 
 	return (FilterElement *) new;

Modified: trunk/filter/filter-option.h
==============================================================================
--- trunk/filter/filter-option.h	(original)
+++ trunk/filter/filter-option.h	Fri Dec  5 19:20:28 2008
@@ -40,6 +40,8 @@
 	char *title;		/* button title */
 	char *value;		/* value, if it has one */
 	char *code;		/* used to string code segments together */
+
+	gboolean is_dynamic;	/* whether is the option dynamic, FALSE if static */
 };
 
 struct _FilterOption {
@@ -49,6 +51,7 @@
 
 	GList *options;
 	struct _filter_option *current;
+	char *dynamic_func;	/* name of the dynamic fill func, called in get_widget */
 };
 
 struct _FilterOptionClass {
@@ -66,7 +69,7 @@
 void filter_option_set_current (FilterOption *option, const char *name);
 const char *filter_option_get_current (FilterOption *option);
 
-struct _filter_option *filter_option_add (FilterOption *fo, const char *name, const char *title, const char *code);
+struct _filter_option *filter_option_add (FilterOption *fo, const char *name, const char *title, const char *code, gboolean is_dynamic);
 void filter_option_remove_all (FilterOption *fo);
 
 #endif /* ! _FILTER_OPTION_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]