diff options
Diffstat (limited to 'modules/calendar/e-memo-shell-backend.c')
-rw-r--r-- | modules/calendar/e-memo-shell-backend.c | 319 |
1 files changed, 48 insertions, 271 deletions
diff --git a/modules/calendar/e-memo-shell-backend.c b/modules/calendar/e-memo-shell-backend.c index c34808698e..efafe383f0 100644 --- a/modules/calendar/e-memo-shell-backend.c +++ b/modules/calendar/e-memo-shell-backend.c @@ -30,17 +30,17 @@ #include <libecal/e-cal-client.h> #include <libedataserver/e-url.h> #include <libedataserver/e-source.h> -#include <libedataserver/e-source-list.h> -#include <libedataserver/e-source-group.h> +#include <libedataserver/e-source-calendar.h> #include <libedataserverui/e-client-utils.h> #include "shell/e-shell.h" #include "shell/e-shell-backend.h" #include "shell/e-shell-window.h" +#include "widgets/misc/e-source-config-dialog.h" #include "calendar/gui/comp-util.h" -#include "calendar/gui/dialogs/calendar-setup.h" #include "calendar/gui/dialogs/memo-editor.h" +#include "calendar/gui/e-cal-source-config.h" #include "e-memo-shell-migrate.h" #include "e-memo-shell-view.h" @@ -49,20 +49,12 @@ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), E_TYPE_MEMO_SHELL_BACKEND, EMemoShellBackendPrivate)) -#define WEB_BASE_URI "webcal://" -#define PERSONAL_RELATIVE_URI "system" - #define E_MEMO_SHELL_BACKEND_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), E_TYPE_MEMO_SHELL_BACKEND, EMemoShellBackendPrivate)) struct _EMemoShellBackendPrivate { - ESourceList *source_list; -}; - -enum { - PROP_0, - PROP_SOURCE_LIST + gint placeholder; }; G_DEFINE_DYNAMIC_TYPE ( @@ -71,110 +63,6 @@ G_DEFINE_DYNAMIC_TYPE ( E_TYPE_SHELL_BACKEND) static void -memo_shell_backend_ensure_sources (EShellBackend *shell_backend) -{ - /* XXX This is basically the same algorithm across all modules. - * Maybe we could somehow integrate this into EShellBackend? */ - - EMemoShellBackend *memo_shell_backend; - ESourceGroup *on_this_computer; - ESourceList *source_list; - ESource *personal; - EShell *shell; - EShellSettings *shell_settings; - GSList *sources, *iter; - const gchar *name; - gboolean save_list = FALSE; - GError *error = NULL; - - personal = NULL; - - memo_shell_backend = E_MEMO_SHELL_BACKEND (shell_backend); - - shell = e_shell_backend_get_shell (shell_backend); - shell_settings = e_shell_get_shell_settings (shell); - - e_cal_client_get_sources ( - &memo_shell_backend->priv->source_list, - E_CAL_CLIENT_SOURCE_TYPE_MEMOS, &error); - - if (error != NULL) { - g_warning ( - "%s: Could not get memo sources: %s", - G_STRFUNC, error->message); - g_error_free (error); - return; - } - - source_list = memo_shell_backend->priv->source_list; - - on_this_computer = e_source_list_ensure_group ( - source_list, _("On This Computer"), "local:", TRUE); - e_source_list_ensure_group ( - source_list, _("On The Web"), "webcal://", FALSE); - - g_return_if_fail (on_this_computer); - - sources = e_source_group_peek_sources (on_this_computer); - - /* Make sure this group includes a "Personal" source. */ - for (iter = sources; iter != NULL; iter = iter->next) { - ESource *source = iter->data; - const gchar *relative_uri; - - relative_uri = e_source_peek_relative_uri (source); - if (g_strcmp0 (relative_uri, "system") == 0) { - personal = source; - break; - } - } - - name = _("Personal"); - - if (personal == NULL) { - ESource *source; - GSList *selected; - gchar *primary; - - source = e_source_new (name, "system"); - e_source_set_color_spec (source, "#BECEDD"); - e_source_group_add_source (on_this_computer, source, -1); - g_object_unref (source); - save_list = TRUE; - - primary = e_shell_settings_get_string ( - shell_settings, "cal-primary-memo-list"); - - selected = e_memo_shell_backend_get_selected_memo_lists ( - memo_shell_backend); - - if (primary == NULL && selected == NULL) { - const gchar *uid; - - uid = e_source_get_uid (source); - selected = g_slist_prepend (NULL, g_strdup (uid)); - - e_shell_settings_set_string ( - shell_settings, "cal-primary-memo-list", uid); - e_memo_shell_backend_set_selected_memo_lists ( - memo_shell_backend, selected); - } - - g_slist_foreach (selected, (GFunc) g_free, NULL); - g_slist_free (selected); - g_free (primary); - } else if (!e_source_get_property (personal, "name-changed")) { - /* Force the source name to the current locale. */ - e_source_set_name (personal, name); - } - - g_object_unref (on_this_computer); - - if (save_list) - e_source_list_sync (source_list, NULL); -} - -static void memo_shell_backend_new_memo (ESource *source, GAsyncResult *result, EShell *shell, @@ -250,59 +138,64 @@ action_memo_new_cb (GtkAction *action, EShellWindow *shell_window) { EShell *shell; - EShellBackend *shell_backend; - EShellSettings *shell_settings; - ESource *source = NULL; - ESourceList *source_list; + ESource *source; + ESourceRegistry *registry; + EClientSourceType source_type; const gchar *action_name; - gchar *uid; /* This callback is used for both memos and shared memos. */ shell = e_shell_window_get_shell (shell_window); - shell_settings = e_shell_get_shell_settings (shell); - shell_backend = e_shell_get_backend_by_name (shell, "memos"); - - g_object_get (shell_backend, "source-list", &source_list, NULL); - g_return_if_fail (E_IS_SOURCE_LIST (source_list)); - uid = e_shell_settings_get_string ( - shell_settings, "cal-primary-memo-list"); - - if (uid != NULL) { - source = e_source_list_peek_source_by_uid (source_list, uid); - g_free (uid); - } - - if (source == NULL) - source = e_source_list_peek_default_source (source_list); - - g_return_if_fail (E_IS_SOURCE (source)); + registry = e_shell_get_registry (shell); + source_type = E_CLIENT_SOURCE_TYPE_MEMOS; + source = e_source_registry_ref_default_memo_list (registry); /* Use a callback function appropriate for the action. * FIXME Need to obtain a better default time zone. */ action_name = gtk_action_get_name (action); if (g_strcmp0 (action_name, "memo-shared-new") == 0) e_client_utils_open_new ( - source, E_CLIENT_SOURCE_TYPE_MEMOS, FALSE, NULL, - e_client_utils_authenticate_handler, GTK_WINDOW (shell_window), + source, source_type, FALSE, NULL, memo_shell_backend_memo_shared_new_cb, g_object_ref (shell)); else e_client_utils_open_new ( - source, E_CLIENT_SOURCE_TYPE_MEMOS, FALSE, NULL, - e_client_utils_authenticate_handler, GTK_WINDOW (shell_window), + source, source_type, FALSE, NULL, memo_shell_backend_memo_new_cb, g_object_ref (shell)); - g_object_unref (source_list); + g_object_unref (source); } static void action_memo_list_new_cb (GtkAction *action, EShellWindow *shell_window) { - calendar_setup_new_memo_list (GTK_WINDOW (shell_window)); + EShell *shell; + ESourceRegistry *registry; + ECalClientSourceType source_type; + GtkWidget *config; + GtkWidget *dialog; + const gchar *icon_name; + + shell = e_shell_window_get_shell (shell_window); + + registry = e_shell_get_registry (shell); + source_type = E_CAL_CLIENT_SOURCE_TYPE_MEMOS; + config = e_cal_source_config_new (registry, NULL, source_type); + + dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config)); + + gtk_window_set_transient_for ( + GTK_WINDOW (dialog), GTK_WINDOW (shell_window)); + + icon_name = gtk_action_get_icon_name (action); + gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name); + + gtk_window_set_title (GTK_WINDOW (dialog), _("New Memo List")); + + gtk_widget_show (dialog); } static GtkActionEntry item_entries[] = { @@ -342,7 +235,7 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend, ECalClient *client; ECalComponent *comp; ESource *source; - ESourceList *source_list; + ESourceRegistry *registry; ECalClientSourceType source_type; EUri *euri; icalcomponent *icalcomp; @@ -406,31 +299,17 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend, * we successfully open it is another matter... */ handled = TRUE; - e_cal_client_get_sources (&source_list, source_type, &error); - - if (error != NULL) { - g_warning ( - "%s: Could not get memo sources: %s", - G_STRFUNC, error->message); - g_clear_error (&error); - goto exit; - } - - source = e_source_list_peek_source_by_uid (source_list, source_uid); + registry = e_shell_get_registry (shell); + source = e_source_registry_ref_source (registry, source_uid); if (source == NULL) { g_printerr ("No source for UID '%s'\n", source_uid); - g_object_unref (source_list); goto exit; } client = e_cal_client_new (source, source_type, &error); - if (client != NULL) { - g_signal_connect ( - client, "authenticate", - G_CALLBACK (e_client_utils_authenticate_handler), NULL); + if (client != NULL) e_client_open_sync (E_CLIENT (client), TRUE, NULL, &error); - } if (error != NULL) { g_warning ( @@ -438,11 +317,14 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend, G_STRFUNC, error->message); if (client != NULL) g_object_unref (client); - g_object_unref (source_list); + g_object_unref (source); g_error_free (error); goto exit; } + g_object_unref (source); + source = NULL; + /* XXX Copied from e_memo_shell_view_open_memo(). * Clearly a new utility function is needed. */ @@ -458,7 +340,6 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend, g_warning ( "%s: Failed to get object: %s", G_STRFUNC, error->message); - g_object_unref (source_list); g_object_unref (client); g_error_free (error); goto exit; @@ -474,7 +355,7 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend, if (e_cal_component_has_organizer (comp)) flags |= COMP_EDITOR_IS_SHARED; - if (itip_organizer_is_user (comp, client)) + if (itip_organizer_is_user (registry, comp, client)) flags |= COMP_EDITOR_USER_ORG; editor = memo_editor_new (client, shell, flags); @@ -485,7 +366,6 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend, present: gtk_window_present (GTK_WINDOW (editor)); - g_object_unref (source_list); g_object_unref (client); exit: @@ -519,40 +399,6 @@ memo_shell_backend_window_added_cb (EShellBackend *shell_backend, } static void -memo_shell_backend_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_SOURCE_LIST: - g_value_set_object ( - value, - e_memo_shell_backend_get_source_list ( - E_MEMO_SHELL_BACKEND (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -memo_shell_backend_dispose (GObject *object) -{ - EMemoShellBackendPrivate *priv; - - priv = E_MEMO_SHELL_BACKEND_GET_PRIVATE (object); - - if (priv->source_list != NULL) { - g_object_unref (priv->source_list); - priv->source_list = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_memo_shell_backend_parent_class)->dispose (object); -} - -static void memo_shell_backend_constructed (GObject *object) { EShell *shell; @@ -561,8 +407,6 @@ memo_shell_backend_constructed (GObject *object) shell_backend = E_SHELL_BACKEND (object); shell = e_shell_backend_get_shell (shell_backend); - memo_shell_backend_ensure_sources (shell_backend); - g_signal_connect_swapped ( shell, "handle-uri", G_CALLBACK (memo_shell_backend_handle_uri_cb), @@ -586,8 +430,6 @@ e_memo_shell_backend_class_init (EMemoShellBackendClass *class) g_type_class_add_private (class, sizeof (EMemoShellBackendPrivate)); object_class = G_OBJECT_CLASS (class); - object_class->get_property = memo_shell_backend_get_property; - object_class->dispose = memo_shell_backend_dispose; object_class->constructed = memo_shell_backend_constructed; shell_backend_class = E_SHELL_BACKEND_CLASS (class); @@ -600,15 +442,8 @@ e_memo_shell_backend_class_init (EMemoShellBackendClass *class) shell_backend_class->start = NULL; shell_backend_class->migrate = e_memo_shell_backend_migrate; - g_object_class_install_property ( - object_class, - PROP_SOURCE_LIST, - g_param_spec_object ( - "source-list", - "Source List", - "The registry of memo lists", - E_TYPE_SOURCE_LIST, - G_PARAM_READABLE)); + /* Register relevant ESource extensions. */ + E_TYPE_SOURCE_MEMO_LIST; } static void @@ -631,61 +466,3 @@ e_memo_shell_backend_type_register (GTypeModule *type_module) * order to register types from a separate compilation unit. */ e_memo_shell_backend_register_type (type_module); } - -ESourceList * -e_memo_shell_backend_get_source_list (EMemoShellBackend *memo_shell_backend) -{ - g_return_val_if_fail ( - E_IS_MEMO_SHELL_BACKEND (memo_shell_backend), NULL); - - return memo_shell_backend->priv->source_list; -} - -GSList * -e_memo_shell_backend_get_selected_memo_lists (EMemoShellBackend *memo_shell_backend) -{ - GSettings *settings; - GSList *selected_memo_lists = NULL; - gchar **strv; - gint ii; - - g_return_val_if_fail ( - E_IS_MEMO_SHELL_BACKEND (memo_shell_backend), NULL); - - settings = g_settings_new ("org.gnome.evolution.calendar"); - strv = g_settings_get_strv (settings, "selected-memos"); - g_object_unref (settings); - - if (strv != NULL) { - for (ii = 0; strv[ii] != NULL; ii++) - selected_memo_lists = g_slist_append ( - selected_memo_lists, g_strdup (strv[ii])); - - g_strfreev (strv); - } - - return selected_memo_lists; -} - -void -e_memo_shell_backend_set_selected_memo_lists (EMemoShellBackend *memo_shell_backend, - GSList *selected_memo_lists) -{ - GSettings *settings; - GSList *link; - GPtrArray *array = g_ptr_array_new (); - - g_return_if_fail (E_IS_MEMO_SHELL_BACKEND (memo_shell_backend)); - - for (link = selected_memo_lists; link != NULL; link = link->next) - g_ptr_array_add (array, link->data); - g_ptr_array_add (array, NULL); - - settings = g_settings_new ("org.gnome.evolution.calendar"); - g_settings_set_strv ( - settings, "selected-memos", - (const gchar *const *) array->pdata); - g_object_unref (settings); - - g_ptr_array_free (array, FALSE); -} |