diff options
-rw-r--r-- | calendar/ChangeLog | 22 | ||||
-rw-r--r-- | calendar/gui/calendar-component.c | 118 | ||||
-rw-r--r-- | calendar/gui/calendar-config-keys.h | 2 | ||||
-rw-r--r-- | calendar/gui/calendar-config.c | 22 | ||||
-rw-r--r-- | calendar/gui/calendar-config.h | 5 | ||||
-rw-r--r-- | e-util/ChangeLog | 11 | ||||
-rw-r--r-- | e-util/e-source-list.c | 44 | ||||
-rw-r--r-- | e-util/e-source-list.h | 10 | ||||
-rw-r--r-- | e-util/test-source-list.c | 45 |
9 files changed, 206 insertions, 73 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index a01392384c..c4f4fb033e 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,25 @@ +2003-11-14 JP Rosevear <jpr@ximian.com> + + * gui/calendar-config.c (calendar_config_get_calendars_selected): + config accessor + (calendar_config_set_calendars_selected): ditto + (calendar_config_add_notification_calendars_selected): config + notification + + * gui/calendar-config.h: add protos + + * gui/calendar-config-keys.h: add new key + + * gui/calendar-component.c (is_in_uids): util function + (update_uris_for_selection): save the selection in the + configuration + (update_selection): update the selection from the config info + (source_selection_changed_cb): only pass one param + (config_selection_changed_cb): listen for config changes + (impl_dispose): remove config notification + (impl_createControls): use bonobo_exception_set; add a config + notification + 2003-11-13 Ettore Perazzoli <ettore@ximian.com> * gui/tasks-component.c (impl__get_userCreatableItems): New. diff --git a/calendar/gui/calendar-component.c b/calendar/gui/calendar-component.c index 4794f3b2ee..24880e98d0 100644 --- a/calendar/gui/calendar-component.c +++ b/calendar/gui/calendar-component.c @@ -27,6 +27,7 @@ #include <string.h> +#include "calendar-config.h" #include "calendar-component.h" #include "calendar-commands.h" #include "gnome-cal.h" @@ -37,6 +38,7 @@ #include <bonobo/bonobo-control.h> #include <bonobo/bonobo-i18n.h> +#include <bonobo/bonobo-exception.h> #include <gtk/gtkimage.h> #include <gtk/gtkimagemenuitem.h> #include <gtk/gtkmessagedialog.h> @@ -65,6 +67,8 @@ struct _CalendarComponentPrivate { GnomeCalendar *calendar; GtkWidget *source_selector; + + guint selected_not; }; @@ -103,16 +107,31 @@ is_in_selection (GSList *selection, ESource *source) return FALSE; } +static gboolean +is_in_uids (GSList *uids, ESource *source) +{ + GSList *l; + + for (l = uids; l; l = l->next) { + const char *uid = l->data; + + if (!strcmp (uid, e_source_peek_uid (source))) + return TRUE; + } + + return FALSE; +} + static void -update_uris_for_selection (ESourceSelector *selector, CalendarComponent *calendar_component) +update_uris_for_selection (CalendarComponent *calendar_component) { CalendarComponentPrivate *priv; - GSList *selection, *l; + GSList *selection, *l, *uids_selected = NULL; - selection = e_source_selector_get_selection (selector); - priv = calendar_component->priv; + selection = e_source_selector_get_selection (E_SOURCE_SELECTOR (priv->source_selector)); + for (l = priv->source_selection; l; l = l->next) { ESource *old_selected_source = l->data; @@ -124,10 +143,52 @@ update_uris_for_selection (ESourceSelector *selector, CalendarComponent *calenda ESource *selected_source = l->data; add_uri_for_source (selected_source, priv->calendar); + uids_selected = g_slist_append (uids_selected, (char *)e_source_peek_uid (selected_source)); } - + e_source_selector_free_selection (priv->source_selection); priv->source_selection = selection; + + /* Save the selection for next time we start up */ + calendar_config_set_calendars_selected (uids_selected); + g_slist_free (uids_selected); +} + +static void +update_selection (CalendarComponent *calendar_component) +{ + CalendarComponentPrivate *priv; + GSList *selection, *uids_selected, *l; + + priv = calendar_component->priv; + + /* Get the selection in gconf */ + uids_selected = calendar_config_get_calendars_selected (); + + /* Remove any that aren't there any more */ + selection = e_source_selector_get_selection (E_SOURCE_SELECTOR (priv->source_selector)); + + for (l = selection; l; l = l->next) { + ESource *source = l->data; + + if (!is_in_uids (uids_selected, source)) + e_source_selector_unselect_source (E_SOURCE_SELECTOR (priv->source_selector), source); + } + + e_source_selector_free_selection (selection); + + /* Make sure the whole selection is there */ + for (l = uids_selected; l; l = l->next) { + char *uid = l->data; + ESource *source; + + source = e_source_list_peek_source_by_uid (priv->source_list, uid); + if (source) + e_source_selector_select_source (E_SOURCE_SELECTOR (priv->source_selector), source); + + g_free (uid); + } + g_slist_free (uids_selected); } /* Callbacks. */ @@ -206,7 +267,7 @@ new_calendar_cb (GtkWidget *widget, ESourceSelector *selector) } static void -fill_popup_menu_callback (ESourceSelector *selector, GtkMenu *menu, CalendarComponent *comp) +fill_popup_menu_cb (ESourceSelector *selector, GtkMenu *menu, CalendarComponent *comp) { add_popup_menu_item (menu, _("New Calendar"), NULL, G_CALLBACK (new_calendar_cb), comp); add_popup_menu_item (menu, _("Delete"), GTK_STOCK_DELETE, G_CALLBACK (delete_calendar_cb), comp); @@ -214,15 +275,15 @@ fill_popup_menu_callback (ESourceSelector *selector, GtkMenu *menu, CalendarComp } static void -source_selection_changed_callback (ESourceSelector *selector, - CalendarComponent *calendar_component) +source_selection_changed_cb (ESourceSelector *selector, + CalendarComponent *calendar_component) { - update_uris_for_selection (selector, calendar_component); + update_uris_for_selection (calendar_component); } static void -primary_source_selection_changed_callback (ESourceSelector *selector, - CalendarComponent *calendar_component) +primary_source_selection_changed_cb (ESourceSelector *selector, + CalendarComponent *calendar_component) { CalendarComponentPrivate *priv; ESource *source; @@ -241,6 +302,12 @@ primary_source_selection_changed_callback (ESourceSelector *selector, } +static void +config_selection_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) +{ + update_selection (data); +} + /* GObject methods. */ static void @@ -263,6 +330,11 @@ impl_dispose (GObject *object) priv->gconf_client = NULL; } + if (priv->selected_not) { + calendar_config_remove_notification (priv->selected_not); + priv->selected_not = 0; + } + (* G_OBJECT_CLASS (parent_class)->dispose) (object); } @@ -305,7 +377,7 @@ impl_createControls (PortableServer_Servant servant, GtkWidget *selector_scrolled_window; BonoboControl *sidebar_control; BonoboControl *view_control; - + priv = calendar_component->priv; /* Create sidebar selector */ @@ -328,9 +400,7 @@ impl_createControls (PortableServer_Servant servant, priv->calendar = GNOME_CALENDAR (gnome_calendar_new ()); if (!priv->calendar) { g_warning (G_STRLOC ": could not create the calendar widget!"); - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Component_Failed, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Component_Failed); return; } @@ -339,9 +409,7 @@ impl_createControls (PortableServer_Servant servant, view_control = bonobo_control_new (GTK_WIDGET (priv->calendar)); if (!view_control) { g_warning (G_STRLOC ": could not create the control!"); - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Component_Failed, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Component_Failed); return; } g_object_set_data (G_OBJECT (priv->calendar), "control", view_control); @@ -349,17 +417,23 @@ impl_createControls (PortableServer_Servant servant, g_signal_connect (view_control, "activate", G_CALLBACK (control_activate_cb), priv->calendar); g_signal_connect_object (priv->source_selector, "selection_changed", - G_CALLBACK (source_selection_changed_callback), + G_CALLBACK (source_selection_changed_cb), G_OBJECT (calendar_component), 0); g_signal_connect_object (priv->source_selector, "primary_selection_changed", - G_CALLBACK (primary_source_selection_changed_callback), + G_CALLBACK (primary_source_selection_changed_cb), G_OBJECT (calendar_component), 0); g_signal_connect_object (priv->source_selector, "fill_popup_menu", - G_CALLBACK (fill_popup_menu_callback), + G_CALLBACK (fill_popup_menu_cb), G_OBJECT (calendar_component), 0); - update_uris_for_selection (E_SOURCE_SELECTOR (priv->source_selector), calendar_component); + /* Load the selection from the last run */ + update_selection (calendar_component); + /* If it gets fiddled with, ie from another evolution window, update it */ + priv->selected_not = calendar_config_add_notification_calendars_selected (config_selection_changed_cb, + calendar_component); + + /* Return the controls */ *corba_sidebar_control = CORBA_Object_duplicate (BONOBO_OBJREF (sidebar_control), ev); *corba_view_control = CORBA_Object_duplicate (BONOBO_OBJREF (view_control), ev); } diff --git a/calendar/gui/calendar-config-keys.h b/calendar/gui/calendar-config-keys.h index f6e7c023c6..6d0754db6f 100644 --- a/calendar/gui/calendar-config-keys.h +++ b/calendar/gui/calendar-config-keys.h @@ -29,6 +29,7 @@ G_BEGIN_DECLS /* Display settings */ #define CALENDAR_CONFIG_TIMEZONE CALENDAR_CONFIG_PREFIX "/display/timezone" +#define CALENDAR_CONFIG_SELECTED_CALENDARS CALENDAR_CONFIG_PREFIX "/display/selected_calendars" #define CALENDAR_CONFIG_24HOUR CALENDAR_CONFIG_PREFIX "/display/use_24hour_format" #define CALENDAR_CONFIG_WEEK_START CALENDAR_CONFIG_PREFIX "/display/week_start_day" #define CALENDAR_CONFIG_DAY_START_HOUR CALENDAR_CONFIG_PREFIX "/display/day_start_hour" @@ -51,6 +52,7 @@ G_BEGIN_DECLS #define CALENDAR_CONFIG_DN_SHOW_WEEK_NUMBERS CALENDAR_CONFIG_PREFIX "/date_navigator/show_week_numbers" /* Task display settings */ +#define CALENDAR_CONFIG_TASKS_SELECTED_TASKS CALENDAR_CONFIG_PREFIX "/tasks/selected_tasks" #define CALENDAR_CONFIG_TASKS_HIDE_COMPLETED CALENDAR_CONFIG_PREFIX "/tasks/hide_completed" #define CALENDAR_CONFIG_TASKS_HIDE_COMPLETED_UNITS CALENDAR_CONFIG_PREFIX "/tasks/hide_completed_units" #define CALENDAR_CONFIG_TASKS_HIDE_COMPLETED_VALUE CALENDAR_CONFIG_PREFIX "/tasks/hide_completed_value" diff --git a/calendar/gui/calendar-config.c b/calendar/gui/calendar-config.c index 250328fa10..45c54a41fb 100644 --- a/calendar/gui/calendar-config.c +++ b/calendar/gui/calendar-config.c @@ -119,6 +119,28 @@ units_to_string (CalUnits units) * Calendar Settings. */ +GSList * +calendar_config_get_calendars_selected (void) +{ + return gconf_client_get_list (config, CALENDAR_CONFIG_SELECTED_CALENDARS, GCONF_VALUE_STRING, NULL); +} + +void +calendar_config_set_calendars_selected (GSList *selected) +{ + gconf_client_set_list (config, CALENDAR_CONFIG_SELECTED_CALENDARS, GCONF_VALUE_STRING, selected, NULL); +} + +guint +calendar_config_add_notification_calendars_selected (GConfClientNotifyFunc func, gpointer data) +{ + guint id; + + id = gconf_client_notify_add (config, CALENDAR_CONFIG_SELECTED_CALENDARS, func, data, NULL, NULL); + + return id; +} + /* The current timezone, e.g. "Europe/London". It may be NULL, in which case you should assume UTC (though Evolution will show the timezone-setting dialog the next time a calendar or task folder is selected). */ diff --git a/calendar/gui/calendar-config.h b/calendar/gui/calendar-config.h index ad9c8531e5..8524334116 100644 --- a/calendar/gui/calendar-config.h +++ b/calendar/gui/calendar-config.h @@ -68,6 +68,11 @@ void calendar_config_remove_notification (guint id); * Calendar Settings. */ +/* The current list of calendars selected */ +GSList *calendar_config_get_calendars_selected (void); +void calendar_config_set_calendars_selected (GSList *selected); +guint calendar_config_add_notification_calendars_selected (GConfClientNotifyFunc func, gpointer data); + /* The current timezone, e.g. "Europe/London". */ gchar* calendar_config_get_timezone (void); void calendar_config_set_timezone (gchar *timezone); diff --git a/e-util/ChangeLog b/e-util/ChangeLog index a14f3b8b9d..5c04768a4e 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,14 @@ +2003-11-14 JP Rosevear <jpr@ximian.com> + + * test-source-list.c (on_idle_do_stuff): we only need the uid to + remove and peek at stuff + + * e-source-list.h: update proto types + + * e-source-list.c (e_source_list_peek_source_by_uid): allow peek + by uid only + (e_source_list_remove_source_by_uid): allow removal by uid only + 2003-11-07 Dan Winship <danw@ximian.com> * ename/*: Removed. No longer used by evolution except via diff --git a/e-util/e-source-list.c b/e-util/e-source-list.c index 565df8977e..abe2c63e04 100644 --- a/e-util/e-source-list.c +++ b/e-util/e-source-list.c @@ -398,20 +398,23 @@ e_source_list_peek_group_by_uid (ESourceList *list, ESource * e_source_list_peek_source_by_uid (ESourceList *list, - const char *group_uid, - const char *source_uid) + const char *uid) { - ESourceGroup *group; + GSList *p; g_return_val_if_fail (E_IS_SOURCE_LIST (list), NULL); - g_return_val_if_fail (group_uid != NULL, NULL); - g_return_val_if_fail (source_uid != NULL, NULL); + g_return_val_if_fail (uid != NULL, NULL); - group = e_source_list_peek_group_by_uid (list, group_uid); - if (group == NULL) - return NULL; + for (p = list->priv->groups; p != NULL; p = p->next) { + ESourceGroup *group = E_SOURCE_GROUP (p->data); + ESource *source; + + source = e_source_group_peek_source_by_uid (group, uid); + if (source) + return source; + } - return e_source_group_peek_source_by_uid (group, source_uid); + return NULL; } @@ -470,20 +473,23 @@ e_source_list_remove_group_by_uid (ESourceList *list, gboolean e_source_list_remove_source_by_uid (ESourceList *list, - const char *group_uid, - const char *source_uid) + const char *uid) { - ESourceGroup *group; - + GSList *p; + g_return_val_if_fail (E_IS_SOURCE_LIST (list), FALSE); - g_return_val_if_fail (group_uid != NULL, FALSE); - g_return_val_if_fail (source_uid != NULL, FALSE); + g_return_val_if_fail (uid != NULL, FALSE); - group = e_source_list_peek_group_by_uid (list, group_uid); - if (group== NULL) - return FALSE; + for (p = list->priv->groups; p != NULL; p = p->next) { + ESourceGroup *group = E_SOURCE_GROUP (p->data); + ESource *source; + + source = e_source_group_peek_source_by_uid (group, uid); + if (source) + return e_source_group_remove_source_by_uid (group, uid); + } - return e_source_group_remove_source_by_uid (group, source_uid); + return FALSE; } diff --git a/e-util/e-source-list.h b/e-util/e-source-list.h index 1985b35d73..219ac7b2fa 100644 --- a/e-util/e-source-list.h +++ b/e-util/e-source-list.h @@ -65,10 +65,9 @@ ESourceList *e_source_list_new_for_gconf (GConfClient *client, GSList *e_source_list_peek_groups (ESourceList *list); ESourceGroup *e_source_list_peek_group_by_uid (ESourceList *list, - const char *source_group); + const char *uid); ESource *e_source_list_peek_source_by_uid (ESourceList *list, - const char *group_name, - const char *source_name); + const char *uid); gboolean e_source_list_add_group (ESourceList *list, ESourceGroup *group, @@ -76,10 +75,9 @@ gboolean e_source_list_add_group (ESourceList *list, gboolean e_source_list_remove_group (ESourceList *list, ESourceGroup *group); gboolean e_source_list_remove_group_by_uid (ESourceList *list, - const char *name); + const char *uid); gboolean e_source_list_remove_source_by_uid (ESourceList *list, - const char *group_name, - const char *source_name); + const char *uidj); gboolean e_source_list_sync (ESourceList *list, GError **error); diff --git a/e-util/test-source-list.c b/e-util/test-source-list.c index 7c38436326..b869df01d7 100644 --- a/e-util/test-source-list.c +++ b/e-util/test-source-list.c @@ -377,36 +377,31 @@ on_idle_do_stuff (void *unused_data) if (remove_source_arg != NULL) { ESource *source; - if (group_arg == NULL) { - fprintf (stderr, "When using --remove-source, you need to specify a group using --group.\n"); - exit (1); - } - - source = e_source_list_peek_source_by_uid (list, group_arg, remove_source_arg); + source = e_source_list_peek_source_by_uid (list, remove_source_arg); if (source == NULL) { - fprintf (stderr, "No such source \"%s\" in group \"%s\".\n", remove_source_arg, group_arg); + fprintf (stderr, "No such source \"%s\".\n", remove_source_arg); exit (1); } - e_source_list_remove_source_by_uid (list, group_arg, remove_source_arg); + e_source_list_remove_source_by_uid (list, remove_source_arg); e_source_list_sync (list, NULL); } if (set_name_arg != NULL) { - if (group_arg == NULL) { + if (group_arg == NULL && source_arg == NULL) { fprintf (stderr, - "When using --set-name, you need to specify a source (using --group and\n" - "--source) or a group (using --group alone).\n"); + "When using --set-name, you need to specify a source (using --source" + "alone) or a group (using --group alone).\n"); exit (1); } if (source_arg != NULL) { - ESource *source = e_source_list_peek_source_by_uid (list, group_arg, source_arg); + ESource *source = e_source_list_peek_source_by_uid (list, source_arg); if (source != NULL) { e_source_set_name (source, set_name_arg); } else { - fprintf (stderr, "No such source \"%s\" in group \"%s\".\n", source_arg, group_arg); + fprintf (stderr, "No such source \"%s\".\n", source_arg); exit (1); } } else { @@ -418,7 +413,7 @@ on_idle_do_stuff (void *unused_data) fprintf (stderr, "No such group \"%s\".\n", group_arg); exit (1); } - } + } e_source_list_sync (list, NULL); } @@ -426,14 +421,14 @@ on_idle_do_stuff (void *unused_data) if (set_relative_uri_arg != NULL && add_source_arg == NULL) { ESource *source; - if (source_arg == NULL || group_arg == NULL) { + if (source_arg == NULL) { fprintf (stderr, - "When using --set-relative-uri, you need to specify a source using --group\n" - "and --source.\n"); + "When using --set-relative-uri, you need to specify a source using " + "--source.\n"); exit (1); } - source = e_source_list_peek_source_by_uid (list, group_arg, source_arg); + source = e_source_list_peek_source_by_uid (list, source_arg); e_source_set_relative_uri (source, set_relative_uri_arg); e_source_list_sync (list, NULL); } @@ -442,17 +437,16 @@ on_idle_do_stuff (void *unused_data) ESource *source; guint32 color; - if (add_source_arg == NULL && (source_arg == NULL || group_arg == NULL)) { + if (add_source_arg == NULL && source_arg == NULL) { fprintf (stderr, - "When using --set-color, you need to specify a source using --group\n" - "and --source.\n"); + "When using --set-color, you need to specify a source using --source\n"); exit (1); } if (add_source_arg != NULL) source = new_source; else - source = e_source_list_peek_source_by_uid (list, group_arg, source_arg); + source = e_source_list_peek_source_by_uid (list, source_arg); sscanf (set_color_arg, "%06x", &color); e_source_set_color (source, color); @@ -462,17 +456,16 @@ on_idle_do_stuff (void *unused_data) if (unset_color) { ESource *source; - if (add_source_arg == NULL && (source_arg == NULL || group_arg == NULL)) { + if (add_source_arg == NULL && source_arg == NULL) { fprintf (stderr, - "When using --unset-color, you need to specify a source using --group\n" - "and --source.\n"); + "When using --unset-color, you need to specify a source using --source\n"); exit (1); } if (add_source_arg != NULL) source = new_source; else - source = e_source_list_peek_source_by_uid (list, group_arg, source_arg); + source = e_source_list_peek_source_by_uid (list, source_arg); e_source_unset_color (source); e_source_list_sync (list, NULL); |