aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-arg.c
diff options
context:
space:
mode:
authorNotZed <NotZed@HelixCode.com>2000-02-22 18:09:07 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-02-22 18:09:07 +0800
commit7c6897ee95e4346e991185c014bcfce003809fd8 (patch)
treeb34cb809263e9641c3311168c43b8977812e91be /filter/filter-arg.c
parent6b21505b40126e00636603c705b771e5c857beef (diff)
downloadgsoc2013-evolution-7c6897ee95e4346e991185c014bcfce003809fd8.tar
gsoc2013-evolution-7c6897ee95e4346e991185c014bcfce003809fd8.tar.gz
gsoc2013-evolution-7c6897ee95e4346e991185c014bcfce003809fd8.tar.bz2
gsoc2013-evolution-7c6897ee95e4346e991185c014bcfce003809fd8.tar.lz
gsoc2013-evolution-7c6897ee95e4346e991185c014bcfce003809fd8.tar.xz
gsoc2013-evolution-7c6897ee95e4346e991185c014bcfce003809fd8.tar.zst
gsoc2013-evolution-7c6897ee95e4346e991185c014bcfce003809fd8.zip
New utility functions for working with the internal rule format.
2000-02-22 NotZed <NotZed@HelixCode.com> * filter-xml.c (filter_clone_optionrule): (filter_clone_optionrule_free): (filter_optionrule_new_from_rule): New utility functions for working with the internal rule format. * filter-arg.[ch]: Added new callbacks for editing a single value, and a new editor which shows all items in a list, and allows you to edit them via the single-edit method. This needs some cleanup for some unused/unusable virtual methods (edit_values, write_html?). * Makefile: Add the druid for build. * filter-druid.c: A 'druid' widget for editing a single filter rule. svn path=/trunk/; revision=1901
Diffstat (limited to 'filter/filter-arg.c')
-rw-r--r--filter/filter-arg.c251
1 files changed, 251 insertions, 0 deletions
diff --git a/filter/filter-arg.c b/filter/filter-arg.c
index 55bc09c6a0..1d8affaadc 100644
--- a/filter/filter-arg.c
+++ b/filter/filter-arg.c
@@ -20,6 +20,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <gtk/gtk.h>
+#include <gnome.h>
+
#include "filter-arg.h"
@@ -57,6 +60,21 @@ filter_arg_get_type (void)
return type;
}
+static FilterArg *
+clone_default(FilterArg *a)
+{
+ xmlNodePtr values;
+ FilterArg *new = FILTER_ARG ( gtk_type_new (((GtkObject *)a)->klass->type) );
+
+ /* clone values */
+ new->name = g_strdup(a->name);
+ values = filter_arg_values_get_xml(a);
+ filter_arg_values_add_xml(new, values);
+ xmlFreeNodeList(values);
+
+ return new;
+}
+
static void
write_html_nothing(FilterArg *arg, GtkHTML *html, GtkHTMLStreamHandle *stream)
{
@@ -75,6 +93,12 @@ edit_values_nothing(FilterArg *arg)
/* empty */
}
+static void *
+edit_value_nothing(FilterArg *arg, void *v)
+{
+ return v;
+}
+
static void
free_value_nothing(FilterArg *arg, void *v)
{
@@ -98,7 +122,9 @@ filter_arg_class_init (FilterArgClass *class)
class->write_html = write_html_nothing;
class->write_text = write_text_nothing;
class->edit_values = edit_values_nothing;
+ class->edit_value = edit_value_nothing;
class->free_value = free_value_nothing;
+ class->clone = clone_default;
signals[CHANGED] =
gtk_signal_new ("changed",
@@ -132,6 +158,12 @@ filter_arg_new (char *name)
return a;
}
+FilterArg *
+filter_arg_clone (FilterArg *arg)
+{
+ return ((FilterArgClass *)(arg->object.klass))->clone(arg);
+}
+
void
filter_arg_add(FilterArg *arg, void *v)
{
@@ -157,17 +189,46 @@ filter_arg_write_html(FilterArg *arg, GtkHTML *html, GtkHTMLStreamHandle *stream
void
filter_arg_write_text(FilterArg *arg, GString *string)
{
+ int count, i;
+
+ count = filter_arg_get_count(arg);
+ for (i=0;i<count;i++) {
+ g_string_append(string, filter_arg_get_value_as_string(arg, i));
+ if (i<count-1) {
+ g_string_append(string, ", ");
+ }
+ if (i==count-2 && count>1) {
+ g_string_append(string, "or ");
+ }
+ }
+
+#if 0
((FilterArgClass *)(arg->object.klass))->write_text(arg, string);
+#endif
}
void
filter_arg_edit_values(FilterArg *arg)
{
+ void filter_arg_edit_values_1(FilterArg *arg);
+
g_return_if_fail(arg != NULL);
+
+#if 1
+ filter_arg_edit_values_1(arg);
+#else
+
if (((FilterArgClass *)(arg->object.klass))->edit_values)
((FilterArgClass *)(arg->object.klass))->edit_values(arg);
else
g_warning("No implementation of virtual method edit_values");
+#endif
+}
+
+int
+filter_arg_edit_value(FilterArg *arg, int index)
+{
+ ((FilterArgClass *)(arg->object.klass))->edit_value(arg, index);
}
xmlNodePtr
@@ -222,3 +283,193 @@ filter_arg_get_value_as_string(FilterArg *arg, int index)
}
+struct filter_arg_edit {
+ FilterArg *arg;
+ GtkList *list;
+ GList *items;
+ GnomeDialog *dialogue;
+ GtkWidget *add, *remove, *edit;
+ GtkWidget *item_current;
+};
+
+static void
+filter_arg_edit_add(GtkWidget *w, struct filter_arg_edit *edata)
+{
+ GtkListItem *listitem;
+ GList *items = NULL;
+ int i;
+
+ printf("adding new item\n");
+
+ i = filter_arg_edit_value(edata->arg, -1);
+ if (i>=0) {
+ gtk_list_remove_items_no_unref(edata->list, edata->items);
+ listitem = (GtkListItem *)gtk_list_item_new_with_label(filter_arg_get_value_as_string(edata->arg, i));
+ gtk_object_set_data((GtkObject *)listitem, "arg_i", filter_arg_get_value(edata->arg, i));
+ edata->items = g_list_append(edata->items, listitem);
+ gtk_widget_show((GtkWidget *)listitem);
+
+ /* this api is nonsense */
+ gtk_list_append_items(edata->list, g_list_copy(edata->items));
+ }
+}
+
+void dump_list(GList *list)
+{
+ printf("dumping list:\n");
+ for (;list;list = g_list_next(list)) {
+ printf(" %p %p\n", list, list->data);
+ }
+}
+
+static void
+fill_list(struct filter_arg_edit *edata)
+{
+ GList *items = NULL;
+ int i, count;
+ GtkListItem *listitem;
+
+ gtk_list_remove_items(edata->list, edata->items);
+ g_list_free(edata->items);
+
+ count = filter_arg_get_count(edata->arg);
+ for (i=0;i<count;i++) {
+ char *labeltext;
+ labeltext = filter_arg_get_value_as_string(edata->arg, i);
+ listitem = (GtkListItem *)gtk_list_item_new_with_label(labeltext);
+ gtk_object_set_data((GtkObject *)listitem, "arg_i", filter_arg_get_value(edata->arg, i));
+ items = g_list_append(items, listitem);
+ gtk_widget_show(GTK_WIDGET(listitem));
+ printf("adding item %d\n", i);
+ }
+
+ printf("items re-added\n");
+
+ edata->item_current = NULL;
+ edata->items = items;
+
+ gtk_list_append_items(edata->list, g_list_copy(edata->items));
+}
+
+static void
+filter_arg_edit_edit(GtkWidget *w, struct filter_arg_edit *edata)
+{
+ char *name;
+ int i;
+
+ /* yurck */
+ if (edata->item_current
+ && (name = gtk_object_get_data((GtkObject *)edata->item_current, "arg_i"))
+ && (i = g_list_index(edata->arg->values, name)) >= 0
+ && (i = filter_arg_edit_value(edata->arg, i)) >= 0) {
+
+ fill_list(edata);
+ }
+}
+
+static void
+filter_arg_edit_delete(GtkWidget *w, struct filter_arg_edit *edata)
+{
+ GtkListItem *listitem;
+ char *name;
+
+ /* yurck */
+ if (edata->item_current
+ && (name = gtk_object_get_data((GtkObject *)edata->item_current, "arg_i"))) {
+ filter_arg_remove(edata->arg, name);
+ fill_list(edata);
+ }
+}
+
+static void
+edit_sensitise(struct filter_arg_edit *edata)
+{
+ int state = edata->item_current != NULL;
+ gtk_widget_set_sensitive(edata->remove, state);
+ gtk_widget_set_sensitive(edata->edit, state);
+}
+
+static void
+filter_arg_edit_select(GtkWidget *w, GtkListItem *list, struct filter_arg_edit *edata)
+{
+ edata->item_current = list;
+ edit_sensitise(edata);
+
+ printf ("node = %p\n", g_list_find(edata->items, edata->item_current));
+}
+
+static void
+filter_arg_edit_unselect(GtkWidget *w, GtkListItem *list, struct filter_arg_edit *edata)
+{
+ edata->item_current = NULL;
+ edit_sensitise(edata);
+}
+
+void
+filter_arg_edit_values_1(FilterArg *arg)
+{
+ GList *vales;
+ GtkList *list;
+ GtkListItem *listitem;
+ int count, i;
+ GnomeDialog *dialogue;
+ GtkHBox *hbox;
+ GtkVBox *vbox;
+ GtkWidget *button;
+ GtkWidget *scrolled_window, *frame;
+ struct filter_arg_edit edata;
+
+ edata.item_current = NULL;
+ edata.arg = arg;
+
+ dialogue = (GnomeDialog *)gnome_dialog_new("Edit values", "Ok", "Cancel", 0);
+ edata.dialogue = dialogue;
+
+ hbox = (GtkHBox *)gtk_hbox_new(FALSE, 0);
+
+ list = (GtkList *)gtk_list_new();
+ edata.list = list;
+ edata.items = NULL;
+ fill_list(&edata);
+
+ scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+ frame = gtk_frame_new("Option values");
+
+ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), (GtkWidget *)list);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_container_set_focus_vadjustment(GTK_CONTAINER (list), gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
+ gtk_container_add(GTK_CONTAINER(frame), scrolled_window);
+ gtk_widget_set_usize(frame, 200, 300);
+ gtk_box_pack_start((GtkBox *)hbox, frame, TRUE, TRUE, 0);
+
+ /* buttons */
+ vbox = (GtkVBox *)gtk_vbox_new(FALSE, 0);
+
+ button = gtk_button_new_with_label ("Add");
+ gtk_box_pack_start((GtkBox *)vbox, button, FALSE, TRUE, 0);
+ edata.add = button;
+ button = gtk_button_new_with_label ("Remove");
+ gtk_box_pack_start((GtkBox *)vbox, button, FALSE, TRUE, 0);
+ edata.remove = button;
+ button = gtk_button_new_with_label ("Edit");
+ gtk_box_pack_start((GtkBox *)vbox, button, FALSE, TRUE, 0);
+ edata.edit = button;
+
+ gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)vbox, FALSE, FALSE, 0);
+
+ gtk_signal_connect((GtkObject *)edata.add, "clicked", filter_arg_edit_add, &edata);
+ gtk_signal_connect((GtkObject *)edata.edit, "clicked", filter_arg_edit_edit, &edata);
+ gtk_signal_connect((GtkObject *)edata.remove, "clicked", filter_arg_edit_delete, &edata);
+ gtk_signal_connect((GtkObject *)edata.list, "select_child", filter_arg_edit_select, &edata);
+ gtk_signal_connect((GtkObject *)edata.list, "unselect_child", filter_arg_edit_unselect, &edata);
+
+ gtk_widget_show(GTK_WIDGET(list));
+ gtk_widget_show_all(GTK_WIDGET(hbox));
+ gtk_box_pack_start((GtkBox *)dialogue->vbox, (GtkWidget *)hbox, TRUE, TRUE, 0);
+
+ edit_sensitise(&edata);
+
+ gnome_dialog_run_and_close(dialogue);
+}
+
+