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/ChangeLog | 31 ++++++ addressbook/gui/search/addresstypes.xml | 8 +- .../gui/search/e-addressbook-search-dialog.c | 108 ++++++++++++++------- .../gui/search/e-addressbook-search-dialog.h | 4 - addressbook/gui/widgets/Makefile.am | 3 + addressbook/gui/widgets/e-addressbook-view.c | 27 ++++++ addressbook/gui/widgets/e-addressbook-view.h | 10 +- 7 files changed, 144 insertions(+), 47 deletions(-) (limited to 'addressbook') diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 5b70b5ae9f..fde4d317ad 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,34 @@ +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. + 2004-06-03 Jeffrey Stedfast * conduit/address-conduit.c (set_status_cleared): Protect against 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 diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am index ce5cc32275..6842ce14d5 100644 --- a/addressbook/gui/widgets/Makefile.am +++ b/addressbook/gui/widgets/Makefile.am @@ -1,3 +1,5 @@ +ruledir = $(privdatadir) + INCLUDES = \ -DG_LOG_DOMAIN=\"eab-widgets\" \ -DEVOLUTION_ETSPECDIR=\""$(etspecdir)"\" \ @@ -12,6 +14,7 @@ INCLUDES = \ -I$(top_srcdir)/addressbook/gui/component \ -I$(top_srcdir)/widgets/misc \ -I$(top_builddir)/shell \ + -DSEARCH_RULE_DIR=\"$(ruledir)\" \ $(EVOLUTION_ADDRESSBOOK_CFLAGS) CORBA_COMPOSER_SOURCE_H = \ diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c index a842d3040e..44db0a1edd 100644 --- a/addressbook/gui/widgets/e-addressbook-view.c +++ b/addressbook/gui/widgets/e-addressbook-view.c @@ -411,6 +411,7 @@ eab_view_new (void) { GtkWidget *widget = GTK_WIDGET (g_object_new (E_TYPE_AB_VIEW, NULL)); EABView *eav = EAB_VIEW (widget); + FilterPart *part; /* create our model */ eav->model = eab_model_new (); @@ -450,6 +451,20 @@ eab_view_new (void) gtk_widget_show (GTK_WIDGET (eav->search)); gtk_widget_set_sensitive (GTK_WIDGET (eav->search), FALSE); + /* create the search context */ + eav->search_context = rule_context_new (); + rule_context_add_part_set (eav->search_context, "partset", filter_part_get_type (), + rule_context_add_part, rule_context_next_part); + rule_context_load (eav->search_context, SEARCH_RULE_DIR "/addresstypes.xml", ""); + + eav->search_rule = filter_rule_new (); + part = rule_context_next_part (eav->search_context, NULL); + + if (part == NULL) + g_warning ("Could not load addressbook search; no parts."); + else + filter_rule_add_part (eav->search_rule, filter_part_clone (part)); + /* create the paned window and contact display */ eav->paned = gtk_vpaned_new (); gtk_box_pack_start (GTK_BOX (eav), eav->paned, TRUE, TRUE, 0); @@ -488,6 +503,18 @@ eab_view_new (void) return widget; } +RuleContext * +eab_view_peek_search_context (EABView *view) +{ + return view->search_context; +} + +FilterRule * +eab_view_peek_search_rule (EABView *view) +{ + return view->search_rule; +} + static void writable_status (GtkObject *object, gboolean writable, EABView *eav) { diff --git a/addressbook/gui/widgets/e-addressbook-view.h b/addressbook/gui/widgets/e-addressbook-view.h index c90356beee..6f937f4587 100644 --- a/addressbook/gui/widgets/e-addressbook-view.h +++ b/addressbook/gui/widgets/e-addressbook-view.h @@ -92,9 +92,10 @@ struct _EABView BonoboUIComponent *uic; /* the search bar and related machinery */ - ESearchBar *search; - gint ecml_changed_id; - + ESearchBar *search; + gint ecml_changed_id; + RuleContext *search_context; + FilterRule *search_rule; }; struct _EABViewClass @@ -119,6 +120,9 @@ void eab_view_setup_menus (EABView *view, BonoboUIComponent *uic); void eab_view_discard_menus (EABView *view); +RuleContext *eab_view_peek_search_context (EABView *view); +FilterRule *eab_view_peek_search_rule (EABView *view); + void eab_view_save_as (EABView *view); void eab_view_view (EABView *view); void eab_view_send (EABView *view); -- cgit