diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-05-17 04:01:51 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-05-17 04:01:51 +0800 |
commit | 7cd27bf6a49c4b63bf95716a07c47f5cd9ce71df (patch) | |
tree | 16c18778dcc62dffa678fb5a2db949db2485ee14 | |
parent | 9d5f54f176d09cf81adeb02b4cfb0553100d4a1b (diff) | |
download | gsoc2013-evolution-7cd27bf6a49c4b63bf95716a07c47f5cd9ce71df.tar gsoc2013-evolution-7cd27bf6a49c4b63bf95716a07c47f5cd9ce71df.tar.gz gsoc2013-evolution-7cd27bf6a49c4b63bf95716a07c47f5cd9ce71df.tar.bz2 gsoc2013-evolution-7cd27bf6a49c4b63bf95716a07c47f5cd9ce71df.tar.lz gsoc2013-evolution-7cd27bf6a49c4b63bf95716a07c47f5cd9ce71df.tar.xz gsoc2013-evolution-7cd27bf6a49c4b63bf95716a07c47f5cd9ce71df.tar.zst gsoc2013-evolution-7cd27bf6a49c4b63bf95716a07c47f5cd9ce71df.zip |
Added a label definition.
2002-05-16 Jeffrey Stedfast <fejj@ximian.com>
* vfoldertypes.xml: Added a label definition.
* filtertypes.xml: Added a label definition.
* filter-label.c: New filter widget for labels.
* filter-element.c (filter_element_new_type_name): Add support for
the new label widget.
* filter-int.c (format_sexp): Fixed a memory leak.
svn path=/trunk/; revision=16936
-rw-r--r-- | filter/ChangeLog | 13 | ||||
-rw-r--r-- | filter/Makefile.am | 2 | ||||
-rw-r--r-- | filter/filter-element.c | 3 | ||||
-rw-r--r-- | filter/filter-file.c | 3 | ||||
-rw-r--r-- | filter/filter-file.h | 15 | ||||
-rw-r--r-- | filter/filter-int.c | 5 | ||||
-rw-r--r-- | filter/filter-label.c | 305 | ||||
-rw-r--r-- | filter/filter-label.h | 65 | ||||
-rw-r--r-- | filter/filter-source.c | 2 | ||||
-rw-r--r-- | filter/filtertypes.xml | 19 | ||||
-rw-r--r-- | filter/libfilter-i18n.h | 1 | ||||
-rw-r--r-- | filter/vfoldertypes.xml | 19 |
12 files changed, 445 insertions, 7 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index 6a4f792b07..e625f41965 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,16 @@ +2002-05-16 Jeffrey Stedfast <fejj@ximian.com> + + * vfoldertypes.xml: Added a label definition. + + * filtertypes.xml: Added a label definition. + + * filter-label.c: New filter widget for labels. + + * filter-element.c (filter_element_new_type_name): Add support for + the new label widget. + + * filter-int.c (format_sexp): Fixed a memory leak. + 2002-05-09 Jeffrey Stedfast <fejj@ximian.com> * filter-file.c (get_widget): Set the path in the entry widget. diff --git a/filter/Makefile.am b/filter/Makefile.am index 7576a1f169..1a3e5d2d74 100644 --- a/filter/Makefile.am +++ b/filter/Makefile.am @@ -40,6 +40,8 @@ libfilter_la_SOURCES = \ filter-input.h \ filter-int.c \ filter-int.h \ + filter-label.c \ + filter-label.h \ filter-option.c \ filter-option.h \ filter-part.c \ diff --git a/filter/filter-element.c b/filter/filter-element.c index 1d22da1839..db50013a39 100644 --- a/filter/filter-element.c +++ b/filter/filter-element.c @@ -37,6 +37,7 @@ #include "filter-folder.h" #include "filter-source.h" #include "filter-file.h" +#include "filter-label.h" static gboolean validate (FilterElement *fe); @@ -276,6 +277,8 @@ filter_element_new_type_name (const char *type) return (FilterElement *)filter_source_new (); } else if (!strcmp (type, "command")) { return (FilterElement *) filter_file_new_type_name (type); + } else if (!strcmp (type, "label")) { + return (FilterElement *) filter_label_new (); } else { g_warning("Unknown filter type '%s'", type); return 0; diff --git a/filter/filter-file.c b/filter/filter-file.c index 0ca8e31902..87a6328ec0 100644 --- a/filter/filter-file.c +++ b/filter/filter-file.c @@ -28,7 +28,6 @@ #include <string.h> #include <sys/types.h> #include <sys/stat.h> -#include <regex.h> #include <gtk/gtkobject.h> #include <gtk/gtkwidget.h> @@ -289,7 +288,7 @@ get_widget (FilterElement *fe) gnome_file_entry_set_modal (GNOME_FILE_ENTRY (fileentry), TRUE); entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (fileentry)); - e_utf8_gtk_entry_set_text (entry, file->path); + e_utf8_gtk_entry_set_text (GTK_ENTRY (entry), file->path); gtk_signal_connect (GTK_OBJECT (entry), "changed", entry_changed, fe); diff --git a/filter/filter-file.h b/filter/filter-file.h index fa772f7bd2..173e35c5fb 100644 --- a/filter/filter-file.h +++ b/filter/filter-file.h @@ -21,8 +21,13 @@ */ -#ifndef _FILTER_FILE_H -#define _FILTER_FILE_H +#ifndef __FILTER_FILE_H__ +#define __FILTER_FILE_H__ + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ #include "filter-element.h" @@ -58,4 +63,8 @@ FilterFile *filter_file_new_type_name (const char *type); /* methods */ void filter_file_set_path (FilterFile *file, const char *path); -#endif /* ! _FILTER_FILE_H */ +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* ! __FILTER_FILE_H__ */ diff --git a/filter/filter-int.c b/filter/filter-int.c index 0fb0685aec..25d70e43e2 100644 --- a/filter/filter-int.c +++ b/filter/filter-int.c @@ -221,6 +221,9 @@ static void format_sexp (FilterElement *fe, GString *out) { FilterInt *fs = (FilterInt *)fe; + char *str; - g_string_append(out, g_strdup_printf("%d", fs->val)); + str = g_strdup_printf ("%d", fs->val); + g_string_append (out, str); + g_free (str); } diff --git a/filter/filter-label.c b/filter/filter-label.c new file mode 100644 index 0000000000..0262c3d5f8 --- /dev/null +++ b/filter/filter-label.c @@ -0,0 +1,305 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast <fejj@ximian.com> + * + * Copyright 2002 Ximian, Inc. (www.ximian.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include <gtk/gtkobject.h> +#include <gtk/gtkwidget.h> + +#include <libgnome/gnome-defs.h> +#include <libgnome/gnome-i18n.h> +#include <libgnomeui/gnome-dialog.h> +#include <libgnomeui/gnome-dialog-util.h> +#include <libgnomeui/gnome-file-entry.h> +#include <gal/widgets/e-unicode.h> + +#include <bonobo/bonobo-object.h> +#include <bonobo/bonobo-generic-factory.h> +#include <bonobo/bonobo-context.h> +#include <bonobo/bonobo-moniker-util.h> +#include <bonobo/bonobo-exception.h> +#include <bonobo-conf/bonobo-config-database.h> + +#include "filter-label.h" +#include "e-util/e-sexp.h" + +#define d(x) + +static gboolean validate (FilterElement *fe); +static void xml_create (FilterElement *fe, xmlNodePtr node); +static xmlNodePtr xml_encode (FilterElement *fe); +static int xml_decode (FilterElement *fe, xmlNodePtr node); +static GtkWidget *get_widget (FilterElement *fe); +static void build_code (FilterElement *fe, GString *out, struct _FilterPart *ff); +static void format_sexp (FilterElement *fe, GString *out); + +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 { + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + + +GtkType +filter_label_get_type (void) +{ + static GtkType type = 0; + + if (!type) { + GtkTypeInfo type_info = { + "FilterLabel", + sizeof (FilterLabel), + sizeof (FilterLabelClass), + (GtkClassInitFunc) filter_label_class_init, + (GtkObjectInitFunc) filter_label_init, + (GtkArgSetFunc) NULL, + (GtkArgGetFunc) NULL + }; + + type = gtk_type_unique (filter_element_get_type (), &type_info); + } + + return type; +} + +static void +filter_label_class_init (FilterLabelClass *klass) +{ + GtkObjectClass *object_class = (GtkObjectClass *) klass; + FilterElementClass *filter_element = (FilterElementClass *) klass; + + parent_class = gtk_type_class (filter_element_get_type ()); + + object_class->finalize = filter_label_finalise; + + /* override methods */ + filter_element->validate = validate; + filter_element->xml_create = xml_create; + filter_element->xml_encode = xml_encode; + filter_element->xml_decode = xml_decode; + filter_element->get_widget = get_widget; + filter_element->build_code = build_code; + filter_element->format_sexp = format_sexp; + + /* signals */ + + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); +} + +static void +filter_label_init (FilterLabel *o) +{ + +} + +static void +filter_label_finalise (GtkObject *obj) +{ + ((GtkObjectClass *)(parent_class))->finalize (obj); +} + +/** + * filter_label_new: + * + * Create a new FilterLabel object. + * + * Return value: A new #FilterLabel object. + **/ +FilterLabel * +filter_label_new (void) +{ + return (FilterLabel *) gtk_type_new (filter_label_get_type ()); +} + + +void +filter_label_set_label (FilterLabel *filter, int label) +{ + filter->label = label; +} + +static gboolean +validate (FilterElement *fe) +{ + FilterLabel *label = (FilterLabel *) fe; + GtkWidget *dialog; + + if (label->label < 0 || label->label > 4) { + dialog = gnome_ok_dialog (_("You must specify a label name")); + + gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); + return FALSE; + } + + return TRUE; +} + +static void +xml_create (FilterElement *fe, xmlNodePtr node) +{ + /* parent implementation */ + ((FilterElementClass *)(parent_class))->xml_create (fe, node); + +} + +static xmlNodePtr +xml_encode (FilterElement *fe) +{ + FilterLabel *label = (FilterLabel *) fe; + xmlNodePtr value; + char *encstr; + + d(printf ("Encoding label as xml\n")); + + encstr = g_strdup_printf ("%d", label->label); + + value = xmlNewNode (NULL, "value"); + xmlSetProp (value, "name", fe->name); + xmlSetProp (value, "type", "label"); + xmlSetProp (value, "label", encstr); + g_free (encstr); + + return value; +} + +static int +xml_decode (FilterElement *fe, xmlNodePtr node) +{ + FilterLabel *label = (FilterLabel *) fe; + char *name, *str, *type; + + type = xmlGetProp (node, "type"); + if (strcmp (type, "label") != 0) { + xmlFree (type); + return -1; + } + + xmlFree (type); + + d(printf("Decoding label from xml %p\n", fe)); + + name = xmlGetProp (node, "name"); + xmlFree (fe->name); + fe->name = name; + + str = xmlGetProp (node, "label"); + label->label = atoi (str); + xmlFree (str); + + return 0; +} + +static void +label_selected (GtkWidget *item, gpointer user_data) +{ + FilterLabel *label = user_data; + + label->label = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (item), "label")); +} + +static GtkWidget * +get_widget (FilterElement *fe) +{ + FilterLabel *label = (FilterLabel *) fe; + GtkWidget *omenu, *menu, *item; + 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... */ + + 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; + } + + 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); + + gtk_widget_show (item); + gtk_menu_append (GTK_MENU (menu), item); + } + + g_free (path); + + gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); + gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), label->label); + + return omenu; +} + +static void +build_code (FilterElement *fe, GString *out, struct _FilterPart *ff) +{ + return; +} + +static void +format_sexp (FilterElement *fe, GString *out) +{ + FilterLabel *label = (FilterLabel *) fe; + char *str; + + str = g_strdup_printf ("%d", label->label); + g_string_append (out, str); + g_free (str); +} diff --git a/filter/filter-label.h b/filter/filter-label.h new file mode 100644 index 0000000000..384e0864aa --- /dev/null +++ b/filter/filter-label.h @@ -0,0 +1,65 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast <fejj@ximian.com> + * + * Copyright 2002 Ximian, Inc. (www.ximian.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef __FILTER_LABEL__ +#define __FILTER_LABEL__ + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#include "filter-element.h" + +#define FILTER_LABEL(obj) GTK_CHECK_CAST (obj, filter_label_get_type (), FilterLabel) +#define FILTER_LABEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_label_get_type (), FilterLabelClass) +#define IS_FILTER_LABEL(obj) GTK_CHECK_TYPE (obj, filter_label_get_type ()) + +typedef struct _FilterLabel FilterLabel; +typedef struct _FilterLabelClass FilterLabelClass; + +struct _FilterLabel { + FilterElement parent; + + int label; +}; + +struct _FilterLabelClass { + FilterElementClass parent_class; + + /* virtual methods */ + + /* signals */ +}; + +GtkType filter_label_get_type (void); + +FilterLabel *filter_label_new (void); + +void filter_label_set_label (FilterLabel *filter, int label); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __FILTER_LABEL__ */ diff --git a/filter/filter-source.c b/filter/filter-source.c index 8279a358e5..fee37f5ad1 100644 --- a/filter/filter-source.c +++ b/filter/filter-source.c @@ -358,7 +358,7 @@ filter_source_get_sources (FilterSource *fs) len = bonobo_config_get_long_with_default (db, "/Mail/Accounts/num", 0, NULL); - for (i = 0; i < len; ++i) { + for (i = 0; i < len; i++) { char *path, *account_name, *name, *addr, *uri; CamelURL *url; diff --git a/filter/filtertypes.xml b/filter/filtertypes.xml index 2ef34da1c5..65fdb292e0 100644 --- a/filter/filtertypes.xml +++ b/filter/filtertypes.xml @@ -383,6 +383,25 @@ <input type="datespec" name="versus"/> </part> + <part name="label"> + <title>Label</title> + <input type="optionlist" name="label-type"> + <option value="is"> + <title>is</title> + <code> + (match-all (= (get-label) ${versus})) + </code> + </option> + <option value="is-not"> + <title>is not</title> + <code> + (match-all (not (= (get-label) ${versus}))) + </code> + </option> + </input> + <input type="label" name="versus"/> + </part> + <part name="score"> <title>Score</title> <input type="optionlist" name="score-type"> diff --git a/filter/libfilter-i18n.h b/filter/libfilter-i18n.h index 82aab705d2..9d930d930b 100644 --- a/filter/libfilter-i18n.h +++ b/filter/libfilter-i18n.h @@ -33,6 +33,7 @@ char *s = N_("is greater than"); char *s = N_("is less than"); char *s = N_("is not"); char *s = N_("is not Flagged"); +char *s = N_("Label"); char *s = N_("Mailing list"); char *s = N_("Message Body"); char *s = N_("Message Header"); diff --git a/filter/vfoldertypes.xml b/filter/vfoldertypes.xml index 176cc94464..34353e46c6 100644 --- a/filter/vfoldertypes.xml +++ b/filter/vfoldertypes.xml @@ -254,6 +254,25 @@ <input type="datespec" name="versus"/> </part> + <part name="label"> + <title>Label</title> + <input type="optionlist" name="label-type"> + <option value="is"> + <title>is</title> + <code> + (match-all (= (get-label) ${versus})) + </code> + </option> + <option value="is-not"> + <title>is not</title> + <code> + (match-all (not (= (get-label) ${versus}))) + </code> + </option> + </input> + <input type="label" name="versus"/> + </part> + <part name="status"> <title>Status</title> <input type="optionlist" name="match-type"> |