diff options
author | Federico Mena Quintero <federico@ximian.com> | 2001-08-02 07:33:40 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2001-08-02 07:33:40 +0800 |
commit | ddcc505dbf7893735bb02d971a6df1a411cdb646 (patch) | |
tree | 6835d6c9ffeb66ae10cb0e2e4e97857df11ead33 /calendar/gui/e-tasks.c | |
parent | 221856a80b5021398c6248f706b32e56c70c7ae6 (diff) | |
download | gsoc2013-evolution-ddcc505dbf7893735bb02d971a6df1a411cdb646.tar gsoc2013-evolution-ddcc505dbf7893735bb02d971a6df1a411cdb646.tar.gz gsoc2013-evolution-ddcc505dbf7893735bb02d971a6df1a411cdb646.tar.bz2 gsoc2013-evolution-ddcc505dbf7893735bb02d971a6df1a411cdb646.tar.lz gsoc2013-evolution-ddcc505dbf7893735bb02d971a6df1a411cdb646.tar.xz gsoc2013-evolution-ddcc505dbf7893735bb02d971a6df1a411cdb646.tar.zst gsoc2013-evolution-ddcc505dbf7893735bb02d971a6df1a411cdb646.zip |
The calendar search bar widget now includes a drop-down menu of available
2001-08-01 Federico Mena Quintero <federico@ximian.com>
The calendar search bar widget now includes a drop-down menu of
available categories.
* pcs/query.c (func_has_categories): Handle one and only one #f
value as meaning "unfiled", for components that have no categories
at all.
* pcs/cal-backend-file.c (open_cal): Duh, do not notify here about
changed categories since at this point we don't have any clients
bound to us yet.
(create_cal): Likewise.
(cal_backend_file_add_cal): Notify here.
* gui/cal-search-bar.h (CalSearchBarClass): New signal
"category_changed".
* gui/cal-search-bar.c (cal_search_bar_construct): Add a drop-down
menu for the list of categories.
(search_option_items): Removed the "Has category" option, since we
now have the drop-down menu instad and it would be confusing to
have both options.
(regen_query): Likewise. Also, this function is now the old
cal_search_bar_query_changed() and is shared by that very function
and by the callback from the drop-down menu.
(notify_query_contains): Include the sub-sexp for the categories.
(cal_search_bar_set_categories): New function.
(cal_search_bar_get_category): New function.
(categories_selection_done_cb): Emit the "category_changed" signal.
* gui/e-tasks.c (obj_updated_cb): Removed function since it did
not do anything; all updates are handled by the CalendarModel.
(obj_removed_cb): Likewise.
(ETasksPrivate): Removed the fields for the categories option
menu, since now it is in the ESearchBar.
(search_bar_sexp_changed_cb): Use calendar_model_set_query()
directly here, as we do not need to frob the sexp anymore.
(update_query): Removed.
(client_categories_changed_cb): New callback.
(search_bar_category_changed_cb): New callback.
(e_tasks_new_task): Set the default category on the component to
the one that is selected in the search bar.
(e_tasks_on_filter_selected): Removed.
(e_tasks_on_categories_changed): Removed.
(e_tasks_rebuild_categories_menu): Removed.
(e_tasks_add_menu_item): Removed.
(e_tasks_setup_view_menus): Sanitized not to sink objects wildly.
(e_tasks_discard_view_menus): New function.
* gui/calendar-model.h (CalendarModelClass): Removed the
"categories_changed" signal since this is handled in the Wombat
now.
* gui/calendar-model.c (calendar_model_get_categories): Removed.
(calendar_model_set_value_at): Do not collect the categories.
(query_obj_updated_cb): Likewise.
(calendar_model_collect_categories): Removed.
(calendar_model_set_default_category): Constify.
* gui/tasks-control.c (tasks_control_deactivate): Call
e_tasks_discard_view_menus().
* gui/gnome-cal.c (search_bar_category_changed_cb): Set the
default category for the task pad's model.
svn path=/trunk/; revision=11559
Diffstat (limited to 'calendar/gui/e-tasks.c')
-rw-r--r-- | calendar/gui/e-tasks.c | 334 |
1 files changed, 110 insertions, 224 deletions
diff --git a/calendar/gui/e-tasks.c b/calendar/gui/e-tasks.c index e0a0b8ef8f..9ea9bc6e2d 100644 --- a/calendar/gui/e-tasks.c +++ b/calendar/gui/e-tasks.c @@ -51,16 +51,8 @@ struct _ETasksPrivate { /* The ECalendarTable showing the tasks. */ GtkWidget *tasks_view; - /* Search bar for tasks and the current sexp */ + /* Calendar search bar for tasks */ GtkWidget *search_bar; - char *sexp; - - /* The option menu showing the categories, and the popup menu. */ - GtkWidget *categories_option_menu; - GtkWidget *categories_menu; - - /* The category that is currently selected, used to filter out items */ - char *category; /* View collection and the view menus handler */ GalViewCollection *view_collection; @@ -74,20 +66,9 @@ static void setup_widgets (ETasks *tasks); static void e_tasks_destroy (GtkObject *object); static void cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data); -static void obj_updated_cb (CalClient *client, const char *uid, gpointer data); -static void obj_removed_cb (CalClient *client, const char *uid, gpointer data); static char* e_tasks_get_config_filename (ETasks *tasks); -static void e_tasks_on_filter_selected (GtkMenuShell *menu_shell, - ETasks *tasks); -static void e_tasks_on_categories_changed (CalendarModel *model, - ETasks *tasks); -static void e_tasks_rebuild_categories_menu (ETasks *tasks); -static gint e_tasks_add_menu_item (gpointer key, - gpointer value, - gpointer data); - /* Signal IDs */ enum { SELECTION_CHANGED, @@ -139,8 +120,8 @@ e_tasks_init (ETasks *tasks) priv = g_new0 (ETasksPrivate, 1); tasks->priv = priv; - priv->sexp = g_strdup ("#t"); /* Match all */ - priv->category = NULL; + priv->view_collection = NULL; + priv->view_menus = NULL; setup_widgets (tasks); } @@ -159,49 +140,34 @@ table_selection_change_cb (ETable *etable, gpointer data) n_selected); } -/* Updates the query in the table model by composing the currently selected - * category with the current sexp. - */ +/* Callback used when the sexp in the search bar changes */ static void -update_query (ETasks *tasks) +search_bar_sexp_changed_cb (CalSearchBar *cal_search, const char *sexp, gpointer data) { + ETasks *tasks; ETasksPrivate *priv; - char *new_sexp; - gboolean free_new_sexp; CalendarModel *model; + tasks = E_TASKS (data); priv = tasks->priv; - g_assert (priv->sexp != NULL); - - if (priv->category) { - new_sexp = g_strdup_printf ("(and %s (has-categories? \"%s\"))", - priv->sexp, priv->category); - free_new_sexp = TRUE; - } else { - new_sexp = priv->sexp; - free_new_sexp = FALSE; - } - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - calendar_model_set_query (model, new_sexp); - - if (free_new_sexp) - g_free (new_sexp); + calendar_model_set_query (model, sexp); } -/* Callback used when the sexp in the search bar changes */ +/* Callback used when the selected category in the search bar changes */ static void -search_bar_sexp_changed_cb (CalSearchBar *cal_search, const char *sexp, gpointer data) +search_bar_category_changed_cb (CalSearchBar *cal_search, const char *category, gpointer data) { ETasks *tasks; ETasksPrivate *priv; + CalendarModel *model; tasks = E_TASKS (data); priv = tasks->priv; - priv->sexp = g_strdup (sexp); - update_query (tasks); + model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); + calendar_model_set_default_category (model, category); } #define E_TASKS_TABLE_DEFAULT_STATE \ @@ -220,58 +186,49 @@ setup_widgets (ETasks *tasks) { ETasksPrivate *priv; ETable *etable; - GtkWidget *hbox, *menuitem, *categories_label; CalendarModel *model; priv = tasks->priv; - hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); - gtk_widget_show (hbox); - gtk_table_attach (GTK_TABLE (tasks), hbox, 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL, 0, 0, 0); - priv->search_bar = cal_search_bar_new (); gtk_signal_connect (GTK_OBJECT (priv->search_bar), "sexp_changed", GTK_SIGNAL_FUNC (search_bar_sexp_changed_cb), tasks); - gtk_box_pack_start (GTK_BOX (hbox), priv->search_bar, TRUE, TRUE, 0); - gtk_widget_show (priv->search_bar); - - priv->categories_option_menu = gtk_option_menu_new (); - gtk_widget_show (priv->categories_option_menu); - gtk_box_pack_end (GTK_BOX (hbox), priv->categories_option_menu, - FALSE, FALSE, 0); - - priv->categories_menu = gtk_menu_new (); - - menuitem = gtk_menu_item_new_with_label (_("All")); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (priv->categories_menu), menuitem); - - gtk_option_menu_set_menu (GTK_OPTION_MENU (priv->categories_option_menu), priv->categories_menu); - - categories_label = gtk_label_new (_("Category:")); - gtk_widget_show (categories_label); - gtk_box_pack_end (GTK_BOX (hbox), categories_label, FALSE, FALSE, 4); + gtk_signal_connect (GTK_OBJECT (priv->search_bar), "category_changed", + GTK_SIGNAL_FUNC (search_bar_category_changed_cb), tasks); + gtk_table_attach (GTK_TABLE (tasks), priv->search_bar, 0, 1, 0, 1, + GTK_EXPAND | GTK_FILL, 0, 0, 0); + gtk_widget_show (priv->search_bar); priv->tasks_view = e_calendar_table_new (); model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); calendar_model_set_new_comp_vtype (model, CAL_COMPONENT_TODO); - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (E_CALENDAR_TABLE (priv->tasks_view)->etable)); + + etable = e_table_scrolled_get_table ( + E_TABLE_SCROLLED (E_CALENDAR_TABLE (priv->tasks_view)->etable)); e_table_set_state (etable, E_TASKS_TABLE_DEFAULT_STATE); gtk_table_attach (GTK_TABLE (tasks), priv->tasks_view, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); gtk_widget_show (priv->tasks_view); - calendar_config_configure_e_calendar_table (E_CALENDAR_TABLE (priv->tasks_view)); - gtk_signal_connect (GTK_OBJECT (E_CALENDAR_TABLE (priv->tasks_view)->model), - "categories-changed", - GTK_SIGNAL_FUNC (e_tasks_on_categories_changed), tasks); + calendar_config_configure_e_calendar_table (E_CALENDAR_TABLE (priv->tasks_view)); gtk_signal_connect (GTK_OBJECT (etable), "selection_change", GTK_SIGNAL_FUNC (table_selection_change_cb), tasks); } +/* Callback used when the set of categories changes in the calendar client */ +static void +client_categories_changed_cb (CalClient *client, GPtrArray *categories, gpointer data) +{ + ETasks *tasks; + ETasksPrivate *priv; + + tasks = E_TASKS (data); + priv = tasks->priv; + + cal_search_bar_set_categories (CAL_SEARCH_BAR (priv->search_bar), categories); +} GtkWidget * e_tasks_construct (ETasks *tasks) @@ -290,10 +247,8 @@ e_tasks_construct (ETasks *tasks) gtk_signal_connect (GTK_OBJECT (priv->client), "cal_opened", GTK_SIGNAL_FUNC (cal_opened_cb), tasks); - gtk_signal_connect (GTK_OBJECT (priv->client), "obj_updated", - GTK_SIGNAL_FUNC (obj_updated_cb), tasks); - gtk_signal_connect (GTK_OBJECT (priv->client), "obj_removed", - GTK_SIGNAL_FUNC (obj_removed_cb), tasks); + gtk_signal_connect (GTK_OBJECT (priv->client), "categories_changed", + GTK_SIGNAL_FUNC (client_categories_changed_cb), tasks); model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); g_assert (model != NULL); @@ -336,15 +291,6 @@ e_tasks_destroy (GtkObject *object) tasks = E_TASKS (object); priv = tasks->priv; - g_assert (priv->sexp != NULL); - g_free (priv->sexp); - priv->sexp = NULL; - - if (priv->category) { - g_free (priv->category); - priv->category = NULL; - } - /* Save the ETable layout. */ config_filename = e_tasks_get_config_filename (tasks); e_calendar_table_save_state (E_CALENDAR_TABLE (priv->tasks_view), @@ -453,38 +399,6 @@ cal_opened_cb (CalClient *client, } -/* Callback from the calendar client when an object is updated */ -static void -obj_updated_cb (CalClient *client, - const char *uid, - gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - - tasks = E_TASKS (data); - priv = tasks->priv; - - /* FIXME: Do we need to do anything? */ -} - - -/* Callback from the calendar client when an object is removed */ -static void -obj_removed_cb (CalClient *client, - const char *uid, - gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - - tasks = E_TASKS (data); - priv = tasks->priv; - - /* FIXME: Do we need to do anything? */ -} - - static char* e_tasks_get_config_filename (ETasks *tasks) { @@ -533,6 +447,7 @@ e_tasks_new_task (ETasks *tasks) ETasksPrivate *priv; TaskEditor *tedit; CalComponent *comp; + const char *category; g_return_if_fail (E_IS_TASKS (tasks)); @@ -544,6 +459,9 @@ e_tasks_new_task (ETasks *tasks) comp = cal_component_new (); cal_component_set_new_vtype (comp, CAL_COMPONENT_TODO); + category = cal_search_bar_get_category (CAL_SEARCH_BAR (priv->search_bar)); + cal_component_set_categories (comp, category); + comp_editor_edit_comp (COMP_EDITOR (tedit), comp); gtk_object_unref (GTK_OBJECT (comp)); @@ -571,140 +489,108 @@ e_tasks_delete_selected (ETasks *tasks) e_calendar_table_delete_selected (cal_table); } +/* Callback used from the view collection when we need to display a new view */ static void -e_tasks_on_filter_selected (GtkMenuShell *menu_shell, - ETasks *tasks) +display_view_cb (GalViewCollection *collection, GalView *view, gpointer data) { - ETasksPrivate *priv; - ECalendarTable *cal_table; - CalendarModel *model; - GtkWidget *label; - char *category; - - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - label = GTK_BIN (priv->categories_option_menu)->child; - gtk_label_get (GTK_LABEL (label), &category); - - cal_table = E_CALENDAR_TABLE (priv->tasks_view); - model = cal_table->model; + ETasks *tasks; - if (priv->category) - g_free (priv->category); + tasks = E_TASKS (data); - if (!strcmp (category, _("All"))) { - calendar_model_set_default_category (model, NULL); - priv->category = NULL; - } else { - calendar_model_set_default_category (model, category); - priv->category = g_strdup (category); + if (GAL_IS_VIEW_ETABLE (view)) { + e_table_set_state_object (e_table_scrolled_get_table (E_TABLE_SCROLLED (E_CALENDAR_TABLE (tasks->priv->tasks_view)->etable)), + GAL_VIEW_ETABLE (view)->state); } - - update_query (tasks); } - -static void -e_tasks_on_categories_changed (CalendarModel *model, - ETasks *tasks) -{ - e_tasks_rebuild_categories_menu (tasks); -} - - -static void -e_tasks_rebuild_categories_menu (ETasks *tasks) +/** + * e_tasks_setup_view_menus: + * @tasks: A tasks widget. + * @uic: UI controller to use for the menus. + * + * Sets up the #GalView menus for a tasks control. This function should be + * called from the Bonobo control activation callback for this tasks control. + * Also, the menus should be discarded using e_tasks_discard_view_menus(). + **/ +void +e_tasks_setup_view_menus (ETasks *tasks, BonoboUIComponent *uic) { ETasksPrivate *priv; - CalendarModel *model; - GTree *categories; - GtkWidget *menuitem; + GalViewFactory *factory; + ETableSpecification *spec; + char *dir; + + g_return_if_fail (tasks != NULL); + g_return_if_fail (E_IS_TASKS (tasks)); + g_return_if_fail (uic != NULL); + g_return_if_fail (BONOBO_IS_UI_COMPONENT (uic)); priv = tasks->priv; - priv->categories_menu = gtk_menu_new (); + g_return_if_fail (priv->view_collection == NULL); - menuitem = gtk_menu_item_new_with_label (_("All")); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (priv->categories_menu), menuitem); + g_assert (priv->view_collection == NULL); + g_assert (priv->view_menus == NULL); - model = E_CALENDAR_TABLE (priv->tasks_view)->model; - categories = calendar_model_get_categories (model); - g_return_if_fail (categories != NULL); + /* Create the view collection */ - g_tree_traverse (categories, e_tasks_add_menu_item, G_IN_ORDER, - priv->categories_menu); + priv->view_collection = gal_view_collection_new (); - gtk_option_menu_set_menu (GTK_OPTION_MENU (priv->categories_option_menu), priv->categories_menu); + dir = gnome_util_prepend_user_home ("/evolution/views/tasks/"); + gal_view_collection_set_storage_directories (priv->view_collection, + EVOLUTION_DATADIR "/evolution/views/tasks/", + dir); + g_free (dir); - gtk_signal_connect (GTK_OBJECT (priv->categories_menu), "deactivate", - GTK_SIGNAL_FUNC (e_tasks_on_filter_selected), - tasks); -} + /* Create the views */ + spec = e_table_specification_new (); + e_table_specification_load_from_file (spec, + EVOLUTION_ETSPECDIR "/e-calendar-table.etspec"); -static gint -e_tasks_add_menu_item (gpointer key, - gpointer value, - gpointer data) -{ - GtkWidget *menuitem; + factory = gal_view_factory_etable_new (spec); + gtk_object_unref (GTK_OBJECT (spec)); + gal_view_collection_add_factory (priv->view_collection, factory); + gtk_object_unref (GTK_OBJECT (factory)); - menuitem = gtk_menu_item_new_with_label ((char*) key); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (data), menuitem); + /* Load the collection and create the menus */ - return FALSE; -} + gal_view_collection_load (priv->view_collection); -static void -display_view(GalViewCollection *collection, - GalView *view, - gpointer data) -{ - ETasks *tasks = data; - if (GAL_IS_VIEW_ETABLE(view)) { - e_table_set_state_object (e_table_scrolled_get_table (E_TABLE_SCROLLED (E_CALENDAR_TABLE (tasks->priv->tasks_view)->etable)), GAL_VIEW_ETABLE (view)->state); - } + priv->view_menus = gal_view_menus_new (priv->view_collection); + gal_view_menus_apply (priv->view_menus, uic, NULL); + gtk_signal_connect (GTK_OBJECT (priv->view_collection), "display_view", + GTK_SIGNAL_FUNC (display_view_cb), tasks); } +/** + * e_tasks_discard_view_menus: + * @tasks: A tasks widget. + * + * Discards the #GalView menus used by a tasks control. This function should be + * called from the Bonobo control deactivation callback for this tasks control. + * The menus should have been set up with e_tasks_setup_view_menus(). + **/ void -e_tasks_setup_menus (ETasks *tasks, - BonoboUIComponent *uic) +e_tasks_discard_view_menus (ETasks *tasks) { - GalViewCollection *collection; - GalViewMenus *views; - GalViewFactory *factory; - ETableSpecification *spec; - char *dir; - - collection = gal_view_collection_new(); + ETasksPrivate *priv; - dir = gnome_util_prepend_user_home ("/evolution/views/tasks/"); - gal_view_collection_set_storage_directories (collection, - EVOLUTION_DATADIR "/evolution/views/tasks/", - dir); - g_free (dir); + g_return_if_fail (tasks != NULL); + g_return_if_fail (E_IS_TASKS (tasks)); - spec = e_table_specification_new (); - e_table_specification_load_from_file (spec, - EVOLUTION_ETSPECDIR "/e-calendar-table.etspec"); + priv = tasks->priv; - factory = gal_view_factory_etable_new (spec); - gal_view_collection_add_factory (collection, factory); - gtk_object_sink (GTK_OBJECT (factory)); + g_return_if_fail (priv->view_collection != NULL); - gal_view_collection_load (collection); + g_assert (priv->view_collection != NULL); + g_assert (priv->view_menus != NULL); - views = gal_view_menus_new (collection); - gal_view_menus_apply (views, uic, NULL); /* This function probably needs to sink the views object. */ - gtk_signal_connect (GTK_OBJECT (collection), "display_view", - display_view, tasks); - /* gtk_object_sink(GTK_OBJECT(views)); */ + gtk_object_unref (GTK_OBJECT (priv->view_collection)); + priv->view_collection = NULL; - gtk_object_sink (GTK_OBJECT (collection)); + gtk_object_unref (GTK_OBJECT (priv->view_menus)); + priv->view_menus = NULL; } /** |