aboutsummaryrefslogtreecommitdiffstats
path: root/modules/calendar/e-cal-shell-backend.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-12-23 21:58:10 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-06-03 11:00:40 +0800
commit26e7480340ff1bcdeed3692b5046e4d735f185b1 (patch)
tree81bf81a6e9d7ac39299b847209dd1142b9023bf6 /modules/calendar/e-cal-shell-backend.c
parent7894db49b9a161f7b63d90a98e57ad6a1e1dca54 (diff)
downloadgsoc2013-evolution-26e7480340ff1bcdeed3692b5046e4d735f185b1.tar
gsoc2013-evolution-26e7480340ff1bcdeed3692b5046e4d735f185b1.tar.gz
gsoc2013-evolution-26e7480340ff1bcdeed3692b5046e4d735f185b1.tar.bz2
gsoc2013-evolution-26e7480340ff1bcdeed3692b5046e4d735f185b1.tar.lz
gsoc2013-evolution-26e7480340ff1bcdeed3692b5046e4d735f185b1.tar.xz
gsoc2013-evolution-26e7480340ff1bcdeed3692b5046e4d735f185b1.tar.zst
gsoc2013-evolution-26e7480340ff1bcdeed3692b5046e4d735f185b1.zip
Adapt modules/calendar to the new ESource API.
Diffstat (limited to 'modules/calendar/e-cal-shell-backend.c')
-rw-r--r--modules/calendar/e-cal-shell-backend.c378
1 files changed, 51 insertions, 327 deletions
diff --git a/modules/calendar/e-cal-shell-backend.c b/modules/calendar/e-cal-shell-backend.c
index bcc4ade035..c49ad8a571 100644
--- a/modules/calendar/e-cal-shell-backend.c
+++ b/modules/calendar/e-cal-shell-backend.c
@@ -31,7 +31,7 @@
#include <libecal/e-cal-time-util.h>
#include <libedataserver/e-url.h>
#include <libedataserver/e-source.h>
-#include <libedataserver/e-source-group.h>
+#include <libedataserver/e-source-calendar.h>
#include <libedataserverui/e-client-utils.h>
#include "e-util/e-import.h"
@@ -39,10 +39,11 @@
#include "shell/e-shell-backend.h"
#include "shell/e-shell-window.h"
#include "widgets/misc/e-preferences-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/event-editor.h"
+#include "calendar/gui/e-cal-source-config.h"
#include "calendar/gui/e-calendar-view.h"
#include "calendar/gui/gnome-cal.h"
#include "calendar/importers/evolution-calendar-importer.h"
@@ -60,12 +61,7 @@
((obj), E_TYPE_CAL_SHELL_BACKEND, ECalShellBackendPrivate))
struct _ECalShellBackendPrivate {
- ESourceList *source_list;
-};
-
-enum {
- PROP_0,
- PROP_SOURCE_LIST
+ gint placeholder;
};
G_DEFINE_DYNAMIC_TYPE (
@@ -74,172 +70,6 @@ G_DEFINE_DYNAMIC_TYPE (
E_TYPE_SHELL_BACKEND)
static void
-cal_shell_backend_ensure_sources (EShellBackend *shell_backend)
-{
- /* XXX This is basically the same algorithm across all backends.
- * Maybe we could somehow integrate this into EShellBackend? */
-
- ECalShellBackend *cal_shell_backend;
- ESourceGroup *on_this_computer;
- ESourceGroup *contacts;
- ESourceList *source_list;
- ESource *birthdays;
- ESource *personal;
- EShell *shell;
- EShellSettings *shell_settings;
- GSList *sources, *iter;
- const gchar *name;
- gchar *property;
- gboolean save_list = FALSE;
- GError *error = NULL;
-
- birthdays = NULL;
- personal = NULL;
-
- cal_shell_backend = E_CAL_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 (
- &cal_shell_backend->priv->source_list,
- E_CAL_CLIENT_SOURCE_TYPE_EVENTS, &error);
-
- if (error != NULL) {
- g_warning (
- "%s: Could not get calendar sources: %s",
- G_STRFUNC, error->message);
- g_error_free (error);
- return;
- }
-
- source_list = cal_shell_backend->priv->source_list;
-
- on_this_computer = e_source_list_ensure_group (
- source_list, _("On This Computer"), "local:", TRUE);
- contacts = e_source_list_ensure_group (
- source_list, _("Contacts"), "contacts://", TRUE);
- e_source_list_ensure_group (
- source_list, _("On The Web"), "webcal://", FALSE);
- e_source_list_ensure_group (
- source_list, _("Weather"), "weather://", FALSE);
-
- g_return_if_fail (on_this_computer != NULL);
- g_return_if_fail (contacts != NULL);
-
- 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-calendar");
-
- selected = e_cal_shell_backend_get_selected_calendars (
- cal_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-calendar", uid);
- e_cal_shell_backend_set_selected_calendars (
- cal_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);
- }
-
- sources = e_source_group_peek_sources (contacts);
-
- if (sources != NULL) {
- GSList *trash;
-
- /* There is only one source under Contacts. */
- birthdays = E_SOURCE (sources->data);
- sources = g_slist_next (sources);
-
- /* Delete any other sources in this group.
- * Earlier versions allowed you to create
- * additional sources under Contacts. */
- trash = g_slist_copy (sources);
- while (trash != NULL) {
- ESource *source = trash->data;
- e_source_group_remove_source (contacts, source);
- trash = g_slist_delete_link (trash, trash);
- save_list = TRUE;
- }
- }
-
- /* XXX e_source_group_get_property() returns a newly-allocated
- * string when it could just as easily return a const string.
- * Unfortunately, fixing that would break the API. */
- property = e_source_group_get_property (contacts, "create_source");
- if (property == NULL)
- e_source_group_set_property (contacts, "create_source", "no");
- g_free (property);
-
- name = _("Birthdays & Anniversaries");
-
- if (birthdays == NULL) {
- ESource *source;
-
- source = e_source_new (name, "/");
- e_source_group_add_source (contacts, source, -1);
- g_object_unref (source);
- save_list = TRUE;
-
- /* This is now a borrowed reference. */
- birthdays = source;
- } else if (!e_source_get_property (birthdays, "name-changed")) {
- /* Force the source name to the current locale. */
- e_source_set_name (birthdays, name);
- }
-
- if (e_source_get_property (birthdays, "delete") == NULL)
- e_source_set_property (birthdays, "delete", "no");
-
- if (e_source_peek_color_spec (birthdays) == NULL)
- e_source_set_color_spec (birthdays, "#DDBECE");
-
- g_object_unref (on_this_computer);
- g_object_unref (contacts);
-
- if (save_list)
- e_source_list_sync (source_list, NULL);
-}
-
-static void
cal_shell_backend_new_event (ESource *source,
GAsyncResult *result,
EShell *shell,
@@ -350,12 +180,12 @@ action_event_new_cb (GtkAction *action,
EShell *shell;
EShellView *shell_view;
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;
+
+ shell = e_shell_window_get_shell (shell_window);
action_name = gtk_action_get_name (action);
@@ -397,26 +227,10 @@ action_event_new_cb (GtkAction *action,
source_type = E_CLIENT_SOURCE_TYPE_EVENTS;
- 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, "calendar");
-
- 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-calendar");
-
- 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 = e_source_registry_ref_default_calendar (registry);
+ shell_backend = e_shell_get_backend_by_name (shell, "calendar");
g_object_set (G_OBJECT (shell_backend), "prefer-new-item", action_name, NULL);
/* Use a callback function appropriate for the action.
@@ -424,30 +238,50 @@ action_event_new_cb (GtkAction *action,
if (strcmp (action_name, "event-all-day-new") == 0)
e_client_utils_open_new (
source, source_type, FALSE, NULL,
- e_client_utils_authenticate_handler, GTK_WINDOW (shell_window),
cal_shell_backend_event_all_day_new_cb,
g_object_ref (shell));
else if (strcmp (action_name, "event-meeting-new") == 0)
e_client_utils_open_new (
source, source_type, FALSE, NULL,
- e_client_utils_authenticate_handler, GTK_WINDOW (shell_window),
cal_shell_backend_event_meeting_new_cb,
g_object_ref (shell));
else
e_client_utils_open_new (
source, source_type, FALSE, NULL,
- e_client_utils_authenticate_handler, GTK_WINDOW (shell_window),
cal_shell_backend_event_new_cb,
g_object_ref (shell));
- g_object_unref (source_list);
+ g_object_unref (source);
}
static void
action_calendar_new_cb (GtkAction *action,
EShellWindow *shell_window)
{
- calendar_setup_new_calendar (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_EVENTS;
+ 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 Calendar"));
+
+ gtk_widget_show (dialog);
}
static GtkActionEntry item_entries[] = {
@@ -524,7 +358,7 @@ cal_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;
@@ -621,21 +455,10 @@ cal_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 calendar sources: %s",
- G_STRFUNC, error->message);
- g_error_free (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_warning ("%s: No source for UID '%s'", G_STRFUNC, source_uid);
- g_object_unref (source_list);
+ g_printerr ("No source for UID '%s'\n", source_uid);
goto exit;
}
@@ -649,11 +472,16 @@ cal_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
"%s: Failed to create/open client '%s': %s",
G_STRFUNC, e_source_get_display_name (source),
error->message);
- g_object_unref (source_list);
+ if (client != NULL)
+ g_object_unref (client);
+ g_object_unref (source);
g_error_free (error);
goto exit;
}
+ g_object_unref (source);
+ source = NULL;
+
/* XXX Copied from e_cal_shell_view_open_event().
* Clearly a new utility function is needed. */
@@ -669,7 +497,7 @@ cal_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
g_warning (
"%s: Failed to get object from client: %s",
G_STRFUNC, error->message);
- g_object_unref (source_list);
+ g_object_unref (client);
g_error_free (error);
goto exit;
}
@@ -686,10 +514,10 @@ cal_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
if (icalprop != NULL)
flags |= COMP_EDITOR_MEETING;
- if (itip_organizer_is_user (comp, client))
+ if (itip_organizer_is_user (registry, comp, client))
flags |= COMP_EDITOR_USER_ORG;
- if (itip_sentby_is_user (comp, client))
+ if (itip_sentby_is_user (registry, comp, client))
flags |= COMP_EDITOR_USER_ORG;
if (!e_cal_component_has_attendees (comp))
@@ -703,7 +531,6 @@ cal_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:
@@ -737,40 +564,6 @@ cal_shell_backend_window_added_cb (EShellBackend *shell_backend,
}
static void
-cal_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_cal_shell_backend_get_source_list (
- E_CAL_SHELL_BACKEND (object)));
- return;
- }
-
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
-
-static void
-cal_shell_backend_dispose (GObject *object)
-{
- ECalShellBackendPrivate *priv;
-
- priv = E_CAL_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_cal_shell_backend_parent_class)->dispose (object);
-}
-
-static void
cal_shell_backend_constructed (GObject *object)
{
EShell *shell;
@@ -780,8 +573,6 @@ cal_shell_backend_constructed (GObject *object)
shell_backend = E_SHELL_BACKEND (object);
shell = e_shell_backend_get_shell (shell_backend);
- cal_shell_backend_ensure_sources (shell_backend);
-
g_signal_connect_swapped (
shell, "handle-uri",
G_CALLBACK (cal_shell_backend_handle_uri_cb),
@@ -827,8 +618,6 @@ e_cal_shell_backend_class_init (ECalShellBackendClass *class)
g_type_class_add_private (class, sizeof (ECalShellBackendPrivate));
object_class = G_OBJECT_CLASS (class);
- object_class->get_property = cal_shell_backend_get_property;
- object_class->dispose = cal_shell_backend_dispose;
object_class->constructed = cal_shell_backend_constructed;
shell_backend_class = E_SHELL_BACKEND_CLASS (class);
@@ -841,15 +630,8 @@ e_cal_shell_backend_class_init (ECalShellBackendClass *class)
shell_backend_class->start = NULL;
shell_backend_class->migrate = e_cal_shell_backend_migrate;
- g_object_class_install_property (
- object_class,
- PROP_SOURCE_LIST,
- g_param_spec_object (
- "source-list",
- "Source List",
- "The registry of calendars",
- E_TYPE_SOURCE_LIST,
- G_PARAM_READABLE));
+ /* Register relevant ESource extensions. */
+ E_TYPE_SOURCE_CALENDAR;
}
static void
@@ -899,64 +681,6 @@ e_cal_shell_backend_type_register (GTypeModule *type_module)
e_cal_shell_backend_register_type (type_module);
}
-ESourceList *
-e_cal_shell_backend_get_source_list (ECalShellBackend *cal_shell_backend)
-{
- g_return_val_if_fail (
- E_IS_CAL_SHELL_BACKEND (cal_shell_backend), NULL);
-
- return cal_shell_backend->priv->source_list;
-}
-
-GSList *
-e_cal_shell_backend_get_selected_calendars (ECalShellBackend *cal_shell_backend)
-{
- GSettings *settings;
- GSList *selected_calendars = NULL;
- gchar **strv;
- gint ii;
-
- g_return_val_if_fail (
- E_IS_CAL_SHELL_BACKEND (cal_shell_backend), NULL);
-
- settings = g_settings_new ("org.gnome.evolution.calendar");
- strv = g_settings_get_strv (settings, "selected-calendars");
- g_object_unref (settings);
-
- if (strv != NULL) {
- for (ii = 0; strv[ii] != NULL; ii++)
- selected_calendars = g_slist_append (
- selected_calendars, g_strdup (strv[ii]));
-
- g_strfreev (strv);
- }
-
- return selected_calendars;
-}
-
-void
-e_cal_shell_backend_set_selected_calendars (ECalShellBackend *cal_shell_backend,
- GSList *selected_calendars)
-{
- GSettings *settings;
- GSList *link;
- GPtrArray *array = g_ptr_array_new ();
-
- g_return_if_fail (E_IS_CAL_SHELL_BACKEND (cal_shell_backend));
-
- for (link = selected_calendars; 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-calendars",
- (const gchar *const *) array->pdata);
- g_object_unref (settings);
-
- g_ptr_array_free (array, FALSE);
-}
-
void
e_cal_shell_backend_open_date_range (ECalShellBackend *cal_shell_backend,
const GDate *start_date,