From 99ec0bcf5e38a79c1a5965e5e95b8a839a68bc3e Mon Sep 17 00:00:00 2001 From: Hans Petter Jansson Date: Fri, 4 Jun 2004 03:28:29 +0000 Subject: Fixes #53643 and #26903. 2004-06-03 Hans Petter Jansson Fixes #53643 and #26903. * gui/search/addresstypes.xml: category -> category_list * gui/search/e-addressbook-search-dialog.c (get_widget): Get filter rule from parent view. (eab_search_dialog_set_property): Implement. (eab_search_dialog_get_property): Impleent. (eab_search_dialog_class_init): Set up property methods. (get_query): Get filter rule from parent view. (eab_search_dialog_init): Don't get the filter widget here, wait until parent view property is set. (eab_search_dialog_new): Don't poke the parent view in, set it as a property instead. (eab_search_dialog_dispose): No longer needs to unref rule. * gui/search/e-addressbook-search-dialog.c: EABSearchDialog no longer needs to keep rule internally. * gui/widgets/Makefile.am: Set SEARCH_RULE_DIR define. * gui/widgets/e-addressbook-view.c (eab_view_new): Set up filter rule and context. (eab_view_peek_search_context): Implement. (eab_view_peek_search_rule): Implement. * gui/widgets/e-addressbook-view.h: Keep track of filter rule and context. Add protos for added API. svn path=/trunk/; revision=26207 --- addressbook/gui/search/addresstypes.xml | 8 +- .../gui/search/e-addressbook-search-dialog.c | 108 ++++++++++++++------- .../gui/search/e-addressbook-search-dialog.h | 4 - 3 files changed, 76 insertions(+), 44 deletions(-) (limited to 'addressbook/gui/search') diff --git a/addressbook/gui/search/addresstypes.xml b/addressbook/gui/search/addresstypes.xml index 4ee23af613..4adbfd694b 100644 --- a/addressbook/gui/search/addresstypes.xml +++ b/addressbook/gui/search/addresstypes.xml @@ -58,19 +58,19 @@ diff --git a/addressbook/gui/search/e-addressbook-search-dialog.c b/addressbook/gui/search/e-addressbook-search-dialog.c index 91277ed7c7..857c7a666c 100644 --- a/addressbook/gui/search/e-addressbook-search-dialog.c +++ b/addressbook/gui/search/e-addressbook-search-dialog.c @@ -45,6 +45,67 @@ E_MAKE_TYPE (eab_search_dialog, eab_search_dialog_init, PARENT_TYPE) +enum +{ + PROP_VIEW = 1 +}; + +static GtkWidget * +get_widget (EABSearchDialog *view) +{ + RuleContext *context; + FilterRule *rule; + + context = eab_view_peek_search_context (view->view); + rule = eab_view_peek_search_rule (view->view); + + if (!context || !rule) { + g_warning ("Could not get search context."); + return gtk_entry_new (); + } + + return filter_rule_get_widget (rule, context); +} + +static void +eab_search_dialog_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + EABSearchDialog *search_dialog; + + search_dialog = EAB_SEARCH_DIALOG (object); + + switch (property_id) { + case PROP_VIEW: + search_dialog->view = g_value_get_object (value); + search_dialog->search = get_widget (search_dialog); + gtk_container_set_border_width (GTK_CONTAINER (search_dialog->search), 12); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (search_dialog)->vbox), + search_dialog->search, TRUE, TRUE, 0); + gtk_widget_show (search_dialog->search); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +eab_search_dialog_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + EABSearchDialog *search_dialog; + + search_dialog = EAB_SEARCH_DIALOG (object); + + switch (property_id) { + case PROP_VIEW: + g_value_set_object (value, search_dialog->view); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + static void eab_search_dialog_class_init (EABSearchDialogClass *klass) { @@ -54,37 +115,25 @@ eab_search_dialog_class_init (EABSearchDialogClass *klass) parent_class = g_type_class_ref (PARENT_TYPE); + object_class->set_property = eab_search_dialog_set_property; + object_class->get_property = eab_search_dialog_get_property; object_class->dispose = eab_search_dialog_dispose; -} -static GtkWidget * -get_widget (EABSearchDialog *view) -{ - FilterPart *part; - - view->context = rule_context_new(); - /* FIXME: hide this in a class */ - rule_context_add_part_set(view->context, "partset", filter_part_get_type(), - rule_context_add_part, rule_context_next_part); - rule_context_load(view->context, SEARCH_RULE_DIR "/addresstypes.xml", ""); - view->rule = filter_rule_new(); - part = rule_context_next_part(view->context, NULL); - if (part == NULL) { - g_warning("Problem loading search for addressbook no parts to load"); - return gtk_entry_new(); - } else { - filter_rule_add_part(view->rule, filter_part_clone(part)); - return filter_rule_get_widget(view->rule, view->context); - } + g_object_class_install_property (object_class, PROP_VIEW, + g_param_spec_object ("view", NULL, NULL, E_TYPE_AB_VIEW, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } static char * get_query (EABSearchDialog *view) { + FilterRule *rule; GString *out = g_string_new(""); char *ret; - filter_rule_build_code(view->rule, out); + rule = eab_view_peek_search_rule (view->view); + + filter_rule_build_code(rule, out); ret = out->str; printf("Searching using %s\n", ret); g_string_free(out, FALSE); @@ -119,10 +168,6 @@ eab_search_dialog_init (EABSearchDialog *view) gtk_window_set_default_size (GTK_WINDOW (view), 550, 400); gtk_window_set_title(GTK_WINDOW(view), _("Advanced Search")); - view->search = get_widget(view); - gtk_container_set_border_width (GTK_CONTAINER (view->search), 12); - gtk_box_pack_start(GTK_BOX(dialog->vbox), view->search, TRUE, TRUE, 0); - gtk_widget_show(view->search); gtk_dialog_add_buttons (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, @@ -139,8 +184,8 @@ eab_search_dialog_init (EABSearchDialog *view) GtkWidget * eab_search_dialog_new (EABView *addr_view) { - EABSearchDialog *view = g_object_new (EAB_SEARCH_DIALOG_TYPE, NULL); - view->view = addr_view; + EABSearchDialog *view = g_object_new (EAB_SEARCH_DIALOG_TYPE, "view", addr_view, NULL); + return GTK_WIDGET(view); } @@ -151,14 +196,5 @@ eab_search_dialog_dispose (GObject *object) view = EAB_SEARCH_DIALOG (object); - if (view->context) { - g_object_unref(view->context); - view->context = NULL; - } - if (view->rule) { - g_object_unref(view->rule); - view->rule = NULL; - } - G_OBJECT_CLASS(parent_class)->dispose (object); } diff --git a/addressbook/gui/search/e-addressbook-search-dialog.h b/addressbook/gui/search/e-addressbook-search-dialog.h index 8634074f69..1321409f94 100644 --- a/addressbook/gui/search/e-addressbook-search-dialog.h +++ b/addressbook/gui/search/e-addressbook-search-dialog.h @@ -45,11 +45,7 @@ struct _EABSearchDialog GtkDialog parent; GtkWidget *search; - EABView *view; - - RuleContext *context; - FilterRule *rule; }; struct _EABSearchDialogClass -- cgit v1.2.3