aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-label.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2002-07-16 10:36:20 +0800
committerMichael Zucci <zucchi@src.gnome.org>2002-07-16 10:36:20 +0800
commit09a5b6b00a5ace026bf019e3a6eba905e4312d2d (patch)
tree00317b856d9a7c9ff60b7518c0b16f2593b36cb7 /filter/filter-label.c
parenta86cb9d3a9e97b432cb89b3c2cc8c3408d99de6c (diff)
downloadgsoc2013-evolution-09a5b6b00a5ace026bf019e3a6eba905e4312d2d.tar
gsoc2013-evolution-09a5b6b00a5ace026bf019e3a6eba905e4312d2d.tar.gz
gsoc2013-evolution-09a5b6b00a5ace026bf019e3a6eba905e4312d2d.tar.bz2
gsoc2013-evolution-09a5b6b00a5ace026bf019e3a6eba905e4312d2d.tar.lz
gsoc2013-evolution-09a5b6b00a5ace026bf019e3a6eba905e4312d2d.tar.xz
gsoc2013-evolution-09a5b6b00a5ace026bf019e3a6eba905e4312d2d.tar.zst
gsoc2013-evolution-09a5b6b00a5ace026bf019e3a6eba905e4312d2d.zip
cvs remove.
2002-07-15 Not Zed <NotZed@Ximian.com> * filter-score.[ch]: cvs remove. * filter-element.c: Remove reference to filter-score.h * vfoldertypes.xml: Fix label vfolder rule as below, also add score and size rules from filtertypes.xml. * filtertypes.xml (score): Use (cast-int (user-tag "score")) to get the value directly, rather than (get-score). (label): Use (user-tag "label") to get the value directly, rather than (get-label). The label is now a string too. * filter-label.c (filter_label_get_type): Make filter-label inherit from filter-option. Which makes more sense doesn't it ... surely. (validate): Removed, optionlists are self-validating. (xml_create): Initialise the list of options from our configuration database. If it isn't working, ignore it and set it up anyway. (filter_label_init): Override the xml type. (filter_label_count): (filter_label_label): (filter_label_index): Some helper functions for external interfaces. All of the mail config/etc should use this. * filter-option.c (free_option): (xml_create): (clone): Made the "value" type in glib memory rather than xml memory space. (filter_option_add): Utility function to add a new option to the list. (clone): Use above function to simplify code. (xml_create): Same here. (xml_encode): Allow subclasses to override the type. svn path=/trunk/; revision=17472
Diffstat (limited to 'filter/filter-label.c')
-rw-r--r--filter/filter-label.c131
1 files changed, 51 insertions, 80 deletions
diff --git a/filter/filter-label.c b/filter/filter-label.c
index fb921eef61..f7534a08b1 100644
--- a/filter/filter-label.c
+++ b/filter/filter-label.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Authors: Jeffrey Stedfast <fejj@ximian.com>
+ * Michael Zucchi <notzed@ximian.com>
*
* Copyright 2002 Ximian, Inc. (www.ximian.com)
*
@@ -48,15 +49,12 @@
#define d(x)
-static gboolean validate (FilterElement *fe);
static void xml_create (FilterElement *fe, xmlNodePtr node);
-static GtkWidget *get_widget (FilterElement *fe);
static void filter_label_class_init (FilterLabelClass *klass);
static void filter_label_init (FilterLabel *label);
static void filter_label_finalise (GtkObject *obj);
-
static FilterElementClass *parent_class;
enum {
@@ -65,7 +63,6 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-
GtkType
filter_label_get_type (void)
{
@@ -82,7 +79,7 @@ filter_label_get_type (void)
(GtkArgGetFunc) NULL
};
- type = gtk_type_unique (filter_int_get_type (), &type_info);
+ type = gtk_type_unique (filter_option_get_type (), &type_info);
}
return type;
@@ -94,24 +91,21 @@ filter_label_class_init (FilterLabelClass *klass)
GtkObjectClass *object_class = (GtkObjectClass *) klass;
FilterElementClass *filter_element = (FilterElementClass *) klass;
- parent_class = gtk_type_class (filter_int_get_type ());
+ parent_class = gtk_type_class (filter_option_get_type ());
object_class->finalize = filter_label_finalise;
/* override methods */
- filter_element->validate = validate;
filter_element->xml_create = xml_create;
- filter_element->get_widget = get_widget;
/* signals */
-
gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
}
static void
filter_label_init (FilterLabel *o)
{
-
+ ((FilterOption *)o)->type = "label";
}
static void
@@ -133,94 +127,71 @@ filter_label_new (void)
return (FilterLabel *) gtk_type_new (filter_label_get_type ());
}
-static gboolean
-validate (FilterElement *fe)
+static struct {
+ char *path;
+ char *title;
+ char *value;
+} labels[] = {
+ { "/Mail/Labels/label_0", N_("Important"), "important" },
+ { "/Mail/Labels/label_1", N_("Work"), "work" },
+ { "/Mail/Labels/label_2", N_("Personal"), "personal" },
+ { "/Mail/Labels/label_3", N_("To Do"), "todo" },
+ { "/Mail/Labels/label_4", N_("Later"), "later" },
+};
+
+int filter_label_count(void)
{
- FilterInt *label = (FilterInt *)fe;
- GtkWidget *dialog;
-
- if (label->val < 0 || label->val > 4) {
- dialog = gnome_ok_dialog (_("You must specify a label name"));
-
- gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
- return FALSE;
- }
-
- return TRUE;
+ return sizeof(labels)/sizeof(labels[0]);
}
-static void
-xml_create (FilterElement *fe, xmlNodePtr node)
+const char *filter_label_label(int i)
{
- /* parent implementation */
- ((FilterElementClass *)(parent_class))->xml_create (fe, node);
-
+ if (i<0 || i >= sizeof(labels)/sizeof(labels[0]))
+ return NULL;
+ else
+ return labels[i].value;
}
-static void
-label_selected (GtkWidget *item, gpointer user_data)
+int filter_label_index(const char *label)
{
- FilterInt *label = user_data;
-
- label->val = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (item), "label"));
+ int i;
+
+ for (i=0;i<sizeof(labels)/sizeof(labels[0]);i++) {
+ if (strcmp(labels[i].value, label) == 0)
+ return i;
+ }
+
+ return -1;
}
-static GtkWidget *
-get_widget (FilterElement *fe)
+static void
+xml_create (FilterElement *fe, xmlNodePtr node)
{
- FilterInt *label = (FilterInt *) fe;
- GtkWidget *omenu, *menu, *item;
+ FilterOption *fo = (FilterOption *)fe;
Bonobo_ConfigDatabase db;
CORBA_Environment ev;
- char *path, *num;
int i;
-
- omenu = gtk_option_menu_new ();
- menu = gtk_menu_new ();
- gtk_widget_show (menu);
-
- /* sigh. This is a fucking nightmare... */
-
+
+ ((FilterElementClass *)(parent_class))->xml_create(fe, node);
+
CORBA_exception_init (&ev);
db = bonobo_get_object ("wombat:", "Bonobo/ConfigDatabase", &ev);
- if (BONOBO_EX (&ev) || db == CORBA_OBJECT_NIL) {
- CORBA_exception_free (&ev);
-
- /* I guess we'll have to return an empty menu? */
- gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
- return omenu;
- }
+ if (BONOBO_EX (&ev) || db == CORBA_OBJECT_NIL)
+ db = CORBA_OBJECT_NIL;
CORBA_exception_free (&ev);
-
- path = g_strdup ("/Mail/Labels/label_#");
- num = path + strlen (path) - 1;
-
- for (i = 0; i < 5; i++) {
- char *utf8_label, *native_label;
-
- sprintf (num, "%d", i);
- utf8_label = bonobo_config_get_string (db, path, NULL);
-
- native_label = e_utf8_to_gtk_string (GTK_WIDGET (menu), utf8_label);
- g_free (utf8_label);
-
- item = gtk_menu_item_new_with_label (native_label);
- g_free (native_label);
-
- gtk_object_set_data (GTK_OBJECT (item), "label", GINT_TO_POINTER (i));
- gtk_signal_connect (GTK_OBJECT (item), "activate",
- label_selected, label);
+
+ for (i=0;i<sizeof(labels)/sizeof(labels[0]);i++) {
+ char *title, *btitle;
- gtk_widget_show (item);
- gtk_menu_append (GTK_MENU (menu), item);
+ if (db == CORBA_OBJECT_NIL
+ || (title = btitle = bonobo_config_get_string(db, labels[i].path, NULL)) == NULL) {
+ btitle = NULL;
+ title = labels[i].title;
+ }
+
+ filter_option_add(fo, labels[i].value, title, NULL);
+ g_free(btitle);
}
-
- g_free (path);
-
- gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
- gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), label->val);
-
- return omenu;
}