From c030e2f0a57ee68c5a512df0cd0cea06346a50bc Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 4 Feb 2011 08:52:28 -0500 Subject: Add 'cal-config-google' module. Registers the "Google" backend in ECalSourceConfig widgets. Replaces the 'google-account-setup' plugin. --- modules/Makefile.am | 1 + modules/cal-config-google/Makefile.am | 32 ++ .../cal-config-google/e-google-chooser-button.c | 244 ++++++++ .../cal-config-google/e-google-chooser-button.h | 67 +++ .../cal-config-google/e-google-chooser-dialog.c | 387 +++++++++++++ .../cal-config-google/e-google-chooser-dialog.h | 68 +++ modules/cal-config-google/e-google-chooser.c | 623 +++++++++++++++++++++ modules/cal-config-google/e-google-chooser.h | 76 +++ .../evolution-cal-config-google.c | 194 +++++++ 9 files changed, 1692 insertions(+) create mode 100644 modules/cal-config-google/Makefile.am create mode 100644 modules/cal-config-google/e-google-chooser-button.c create mode 100644 modules/cal-config-google/e-google-chooser-button.h create mode 100644 modules/cal-config-google/e-google-chooser-dialog.c create mode 100644 modules/cal-config-google/e-google-chooser-dialog.h create mode 100644 modules/cal-config-google/e-google-chooser.c create mode 100644 modules/cal-config-google/e-google-chooser.h create mode 100644 modules/cal-config-google/evolution-cal-config-google.c (limited to 'modules') diff --git a/modules/Makefile.am b/modules/Makefile.am index ecfeae7f4e..00754d8491 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -26,6 +26,7 @@ SUBDIRS = \ book-config-webdav \ cal-config-caldav \ cal-config-contacts \ + cal-config-google \ cal-config-local \ composer-autosave \ mailto-handler \ diff --git a/modules/cal-config-google/Makefile.am b/modules/cal-config-google/Makefile.am new file mode 100644 index 0000000000..f79565a5cc --- /dev/null +++ b/modules/cal-config-google/Makefile.am @@ -0,0 +1,32 @@ +module_LTLIBRARIES = module-cal-config-google.la + +module_cal_config_google_la_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/widgets \ + -DG_LOG_DOMAIN=\"evolution-cal-config-google\" \ + $(EVOLUTION_DATA_SERVER_CFLAGS) \ + $(GNOME_PLATFORM_CFLAGS) \ + $(GDATA_CFLAGS) + +module_cal_config_google_la_SOURCES = \ + evolution-cal-config-google.c \ + e-google-chooser-button.c \ + e-google-chooser-button.h \ + e-google-chooser-dialog.c \ + e-google-chooser-dialog.h \ + e-google-chooser.c \ + e-google-chooser.h + +module_cal_config_google_la_LIBADD = \ + $(top_builddir)/e-util/libeutil.la \ + $(top_builddir)/widgets/misc/libemiscwidgets.la \ + $(top_builddir)/calendar/gui/libevolution-calendar.la \ + $(EVOLUTION_DATA_SERVER_LIBS) \ + $(GNOME_PLATFORM_LIBS) \ + $(GDATA_LIBS) + +module_cal_config_google_la_LDFLAGS = \ + -module -avoid-version $(NO_UNDEFINED) + +-include $(top_srcdir)/git.mk diff --git a/modules/cal-config-google/e-google-chooser-button.c b/modules/cal-config-google/e-google-chooser-button.c new file mode 100644 index 0000000000..700760811d --- /dev/null +++ b/modules/cal-config-google/e-google-chooser-button.c @@ -0,0 +1,244 @@ +/* + * e-google-chooser-button.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + */ + +#include "e-google-chooser-button.h" + +#include +#include + +#include + +#include "e-google-chooser-dialog.h" + +#define E_GOOGLE_CHOOSER_BUTTON_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_GOOGLE_CHOOSER_BUTTON, EGoogleChooserButtonPrivate)) + +struct _EGoogleChooserButtonPrivate { + ESource *source; + GtkWidget *label; +}; + +enum { + PROP_0, + PROP_DISPLAY_NAME, + PROP_SOURCE +}; + +G_DEFINE_DYNAMIC_TYPE ( + EGoogleChooserButton, + e_google_chooser_button, + GTK_TYPE_BUTTON) + +static void +google_chooser_button_set_source (EGoogleChooserButton *button, + ESource *source) +{ + g_return_if_fail (E_IS_SOURCE (source)); + g_return_if_fail (button->priv->source == NULL); + + button->priv->source = g_object_ref (source); +} + +static void +google_chooser_button_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_SOURCE: + google_chooser_button_set_source ( + E_GOOGLE_CHOOSER_BUTTON (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +google_chooser_button_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_SOURCE: + g_value_set_object ( + value, + e_google_chooser_button_get_source ( + E_GOOGLE_CHOOSER_BUTTON (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +google_chooser_button_dispose (GObject *object) +{ + EGoogleChooserButtonPrivate *priv; + + priv = E_GOOGLE_CHOOSER_BUTTON_GET_PRIVATE (object); + + if (priv->source != NULL) { + g_object_unref (priv->source); + priv->source = NULL; + } + + if (priv->label != NULL) { + g_object_unref (priv->label); + priv->label = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (e_google_chooser_button_parent_class)->dispose (object); +} + +static void +google_chooser_button_constructed (GObject *object) +{ + EGoogleChooserButton *button; + ESourceWebdav *webdav_extension; + GBindingFlags binding_flags; + GtkWidget *widget; + const gchar *display_name; + + button = E_GOOGLE_CHOOSER_BUTTON (object); + + /* Chain up to parent's constructed() method. */ + G_OBJECT_CLASS (e_google_chooser_button_parent_class)-> + constructed (object); + + widget = gtk_label_new (_("Default User Calendar")); + gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); + gtk_container_add (GTK_CONTAINER (button), widget); + button->priv->label = g_object_ref (widget); + gtk_widget_show (widget); + + webdav_extension = e_source_get_extension ( + button->priv->source, E_SOURCE_EXTENSION_WEBDAV_BACKEND); + display_name = e_source_webdav_get_display_name (webdav_extension); + + binding_flags = G_BINDING_DEFAULT; + if (display_name != NULL && *display_name != '\0') + binding_flags |= G_BINDING_SYNC_CREATE; + + g_object_bind_property ( + webdav_extension, "display-name", + button->priv->label, "label", + binding_flags); +} + +static void +google_chooser_button_clicked (GtkButton *button) +{ + EGoogleChooserButtonPrivate *priv; + GtkWidget *chooser; + GtkWidget *dialog; + gpointer parent; + + priv = E_GOOGLE_CHOOSER_BUTTON_GET_PRIVATE (button); + + parent = gtk_widget_get_toplevel (GTK_WIDGET (button)); + parent = gtk_widget_is_toplevel (parent) ? parent : NULL; + + chooser = e_google_chooser_new (priv->source); + + dialog = e_google_chooser_dialog_new ( + E_GOOGLE_CHOOSER (chooser), parent); + + if (parent != NULL) + g_object_bind_property ( + parent, "icon-name", + dialog, "icon-name", + G_BINDING_SYNC_CREATE); + + gtk_dialog_run (GTK_DIALOG (dialog)); + + gtk_widget_destroy (dialog); +} + +static void +e_google_chooser_button_class_init (EGoogleChooserButtonClass *class) +{ + GObjectClass *object_class; + GtkButtonClass *button_class; + + g_type_class_add_private (class, sizeof (EGoogleChooserButtonPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = google_chooser_button_set_property; + object_class->get_property = google_chooser_button_get_property; + object_class->dispose = google_chooser_button_dispose; + object_class->constructed = google_chooser_button_constructed; + + button_class = GTK_BUTTON_CLASS (class); + button_class->clicked = google_chooser_button_clicked; + + g_object_class_install_property ( + object_class, + PROP_SOURCE, + g_param_spec_object ( + "source", + NULL, + NULL, + E_TYPE_SOURCE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); +} + +static void +e_google_chooser_button_class_finalize (EGoogleChooserButtonClass *class) +{ +} + +static void +e_google_chooser_button_init (EGoogleChooserButton *button) +{ + button->priv = E_GOOGLE_CHOOSER_BUTTON_GET_PRIVATE (button); +} + +void +e_google_chooser_button_type_register (GTypeModule *type_module) +{ + /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration + * function, so we have to wrap it with a public function in + * order to register types from a separate compilation unit. */ + e_google_chooser_button_register_type (type_module); +} + +GtkWidget * +e_google_chooser_button_new (ESource *source) +{ + g_return_val_if_fail (E_IS_SOURCE (source), NULL); + + return g_object_new ( + E_TYPE_GOOGLE_CHOOSER_BUTTON, + "source", source, NULL); +} + +ESource * +e_google_chooser_button_get_source (EGoogleChooserButton *button) +{ + g_return_val_if_fail (E_IS_GOOGLE_CHOOSER_BUTTON (button), NULL); + + return button->priv->source; +} + diff --git a/modules/cal-config-google/e-google-chooser-button.h b/modules/cal-config-google/e-google-chooser-button.h new file mode 100644 index 0000000000..29d2db098b --- /dev/null +++ b/modules/cal-config-google/e-google-chooser-button.h @@ -0,0 +1,67 @@ +/* + * e-google-chooser-button.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + */ + +#ifndef E_GOOGLE_CHOOSER_BUTTON_H +#define E_GOOGLE_CHOOSER_BUTTON_H + +#include "e-google-chooser.h" + +/* Standard GObject macros */ +#define E_TYPE_GOOGLE_CHOOSER_BUTTON \ + (e_google_chooser_button_get_type ()) +#define E_GOOGLE_CHOOSER_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_GOOGLE_CHOOSER_BUTTON, EGoogleChooserButton)) +#define E_GOOGLE_CHOOSER_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_GOOGLE_CHOOSER_BUTTON, EGoogleChooserButtonClass)) +#define E_IS_GOOGLE_CHOOSER_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_GOOGLE_CHOOSER_BUTTON)) +#define E_IS_GOOGLE_CHOOSER_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_GOOGLE_CHOOSER_BUTTON)) +#define E_GOOGLE_CHOOSER_BUTTON_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_GOOGLE_CHOOSER_BUTTON, EGoogleChooserButtonClass)) + +G_BEGIN_DECLS + +typedef struct _EGoogleChooserButton EGoogleChooserButton; +typedef struct _EGoogleChooserButtonClass EGoogleChooserButtonClass; +typedef struct _EGoogleChooserButtonPrivate EGoogleChooserButtonPrivate; + +struct _EGoogleChooserButton { + GtkButton parent; + EGoogleChooserButtonPrivate *priv; +}; + +struct _EGoogleChooserButtonClass { + GtkButtonClass parent_class; +}; + +GType e_google_chooser_button_get_type (void); +void e_google_chooser_button_type_register + (GTypeModule *type_module); +GtkWidget * e_google_chooser_button_new (ESource *source); +ESource * e_google_chooser_button_get_source + (EGoogleChooserButton *button); + +G_END_DECLS + +#endif /* E_GOOGLE_CHOOSER_BUTTON_H */ diff --git a/modules/cal-config-google/e-google-chooser-dialog.c b/modules/cal-config-google/e-google-chooser-dialog.c new file mode 100644 index 0000000000..acf11f2a9d --- /dev/null +++ b/modules/cal-config-google/e-google-chooser-dialog.c @@ -0,0 +1,387 @@ +/* + * e-google-chooser-dialog.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + */ + +#include "e-google-chooser-dialog.h" + +#include +#include + +#define E_GOOGLE_CHOOSER_DIALOG_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_GOOGLE_CHOOSER_DIALOG, EGoogleChooserDialogPrivate)) + +struct _EGoogleChooserDialogPrivate { + EGoogleChooser *chooser; + GCancellable *cancellable; + + GtkWidget *info_bar; /* not referenced */ + GtkWidget *info_bar_label; /* not referenced */ +}; + +enum { + PROP_0, + PROP_CHOOSER +}; + +G_DEFINE_DYNAMIC_TYPE ( + EGoogleChooserDialog, + e_google_chooser_dialog, + GTK_TYPE_DIALOG) + +static void +google_chooser_dialog_populated_cb (EGoogleChooser *chooser, + GAsyncResult *result, + EGoogleChooserDialog *dialog) +{ + GdkWindow *window; + GError *error = NULL; + + e_google_chooser_populate_finish (chooser, result, &error); + + /* Ignore cancellations, and leave the mouse cursor alone + * since the GdkWindow may have already been destroyed. */ + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + goto exit; + + /* Reset the mouse cursor to normal. */ + window = gtk_widget_get_window (GTK_WIDGET (dialog)); + gdk_window_set_cursor (window, NULL); + + if (error != NULL) { + GtkLabel *label; + + label = GTK_LABEL (dialog->priv->info_bar_label); + gtk_label_set_text (label, error->message); + gtk_widget_show (dialog->priv->info_bar); + + g_error_free (error); + goto exit; + } + +exit: + g_object_unref (dialog); +} + +static void +google_chooser_dialog_row_activated_cb (GtkTreeView *tree_view, + GtkTreePath *path, + GtkTreeViewColumn *column, + GtkDialog *dialog) +{ + gtk_dialog_response (dialog, GTK_RESPONSE_APPLY); +} + +static void +google_chooser_dialog_selection_changed_cb (GtkTreeSelection *selection, + GtkDialog *dialog) +{ + gboolean sensitive; + + sensitive = (gtk_tree_selection_count_selected_rows (selection) > 0); + + gtk_dialog_set_response_sensitive ( + dialog, GTK_RESPONSE_APPLY, sensitive); +} + +static void +google_chooser_dialog_set_chooser (EGoogleChooserDialog *dialog, + EGoogleChooser *chooser) +{ + g_return_if_fail (E_IS_GOOGLE_CHOOSER (chooser)); + g_return_if_fail (dialog->priv->chooser == NULL); + + dialog->priv->chooser = g_object_ref_sink (chooser); +} + +static void +google_chooser_dialog_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_CHOOSER: + google_chooser_dialog_set_chooser ( + E_GOOGLE_CHOOSER_DIALOG (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +google_chooser_dialog_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_CHOOSER: + g_value_set_object ( + value, + e_google_chooser_dialog_get_chooser ( + E_GOOGLE_CHOOSER_DIALOG (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +google_chooser_dialog_dispose (GObject *object) +{ + EGoogleChooserDialogPrivate *priv; + + priv = E_GOOGLE_CHOOSER_DIALOG_GET_PRIVATE (object); + + if (priv->chooser != NULL) { + g_signal_handlers_disconnect_by_func ( + priv->chooser, google_chooser_dialog_row_activated_cb, + object); + g_object_unref (priv->chooser); + priv->chooser = NULL; + } + + if (priv->cancellable != NULL) { + g_cancellable_cancel (priv->cancellable); + g_object_unref (priv->cancellable); + priv->cancellable = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (e_google_chooser_dialog_parent_class)->dispose (object); +} + +static void +google_chooser_dialog_constructed (GObject *object) +{ + EGoogleChooserDialog *dialog; + GtkTreeSelection *selection; + GtkWidget *container; + GtkWidget *widget; + GtkWidget *vbox; + const gchar *title; + + dialog = E_GOOGLE_CHOOSER_DIALOG (object); + + /* Chain up to parent's constructed() method. */ + G_OBJECT_CLASS (e_google_chooser_dialog_parent_class)-> + constructed (object); + + gtk_dialog_add_button ( + GTK_DIALOG (dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + + gtk_dialog_add_button ( + GTK_DIALOG (dialog), + GTK_STOCK_APPLY, GTK_RESPONSE_APPLY); + + gtk_dialog_set_default_response ( + GTK_DIALOG (dialog), GTK_RESPONSE_APPLY); + gtk_dialog_set_response_sensitive ( + GTK_DIALOG (dialog), GTK_RESPONSE_APPLY, FALSE); + + title = _("Choose a Calendar"); + gtk_window_set_title (GTK_WINDOW (dialog), title); + gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 400); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + + container = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + + widget = gtk_vbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (widget), 5); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + gtk_widget_show (widget); + + container = vbox = widget; + + widget = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy ( + GTK_SCROLLED_WINDOW (widget), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type ( + GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + gtk_widget_show (widget); + + container = widget; + + widget = GTK_WIDGET (dialog->priv->chooser); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); + + g_signal_connect ( + widget, "row-activated", + G_CALLBACK (google_chooser_dialog_row_activated_cb), dialog); + + /* Build the info bar, but hide it initially. */ + + container = vbox; + + widget = gtk_info_bar_new (); + gtk_info_bar_set_message_type ( + GTK_INFO_BAR (widget), GTK_MESSAGE_WARNING); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + dialog->priv->info_bar = widget; /* do not reference */ + gtk_widget_hide (widget); + + container = gtk_info_bar_get_content_area (GTK_INFO_BAR (widget)); + + widget = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + gtk_widget_show (widget); + + container = widget; + + widget = gtk_image_new_from_stock ( + GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + widget = gtk_label_new (""); + gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + dialog->priv->info_bar_label = widget; /* do not reference */ + gtk_widget_show (widget); + + /* Listen for tree view selection changes. */ + + selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (dialog->priv->chooser)); + + g_signal_connect ( + selection, "changed", + G_CALLBACK (google_chooser_dialog_selection_changed_cb), + dialog); +} + +static void +google_chooser_dialog_realize (GtkWidget *widget) +{ + EGoogleChooserDialogPrivate *priv; + GdkCursor *cursor; + GdkWindow *window; + GdkDisplay *display; + + priv = E_GOOGLE_CHOOSER_DIALOG_GET_PRIVATE (widget); + + /* Chain up to parent's realize() method. */ + GTK_WIDGET_CLASS (e_google_chooser_dialog_parent_class)-> + realize (widget); + + g_return_if_fail (priv->cancellable == NULL); + priv->cancellable = g_cancellable_new (); + + /* Show a busy mouse cursor while populating. */ + window = gtk_widget_get_window (widget); + display = gtk_widget_get_display (widget); + cursor = gdk_cursor_new_for_display (display, GDK_WATCH); + gdk_window_set_cursor (window, cursor); + gdk_cursor_unref (cursor); + + e_google_chooser_populate ( + priv->chooser, priv->cancellable, (GAsyncReadyCallback) + google_chooser_dialog_populated_cb, g_object_ref (widget)); +} + +static void +google_chooser_dialog_response (GtkDialog *dialog, + gint response_id) +{ + EGoogleChooserDialogPrivate *priv; + + priv = E_GOOGLE_CHOOSER_DIALOG_GET_PRIVATE (dialog); + + if (response_id == GTK_RESPONSE_APPLY) + e_google_chooser_apply_selected (priv->chooser); +} + +static void +e_google_chooser_dialog_class_init (EGoogleChooserDialogClass *class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + GtkDialogClass *dialog_class; + + g_type_class_add_private (class, sizeof (EGoogleChooserDialogPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = google_chooser_dialog_set_property; + object_class->get_property = google_chooser_dialog_get_property; + object_class->dispose = google_chooser_dialog_dispose; + object_class->constructed = google_chooser_dialog_constructed; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->realize = google_chooser_dialog_realize; + + dialog_class = GTK_DIALOG_CLASS (class); + dialog_class->response = google_chooser_dialog_response; + + g_object_class_install_property ( + object_class, + PROP_CHOOSER, + g_param_spec_object ( + "chooser", + NULL, + NULL, + E_TYPE_GOOGLE_CHOOSER, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); +} + +static void +e_google_chooser_dialog_class_finalize (EGoogleChooserDialogClass *class) +{ +} + +static void +e_google_chooser_dialog_init (EGoogleChooserDialog *dialog) +{ + dialog->priv = E_GOOGLE_CHOOSER_DIALOG_GET_PRIVATE (dialog); +} + +void +e_google_chooser_dialog_type_register (GTypeModule *type_module) +{ + /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration + * function, so we have to wrap it with a public function in + * order to register types from a separate compilation unit. */ + e_google_chooser_dialog_register_type (type_module); +} + +GtkWidget * +e_google_chooser_dialog_new (EGoogleChooser *chooser, + GtkWindow *parent) +{ + g_return_val_if_fail (E_IS_GOOGLE_CHOOSER (chooser), NULL); + g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL); + + return g_object_new ( + E_TYPE_GOOGLE_CHOOSER_DIALOG, + "chooser", chooser, "transient-for", parent, NULL); +} + +EGoogleChooser * +e_google_chooser_dialog_get_chooser (EGoogleChooserDialog *dialog) +{ + g_return_val_if_fail (E_IS_GOOGLE_CHOOSER_DIALOG (dialog), NULL); + + return dialog->priv->chooser; +} + diff --git a/modules/cal-config-google/e-google-chooser-dialog.h b/modules/cal-config-google/e-google-chooser-dialog.h new file mode 100644 index 0000000000..d7e3e375d9 --- /dev/null +++ b/modules/cal-config-google/e-google-chooser-dialog.h @@ -0,0 +1,68 @@ +/* + * e-google-chooser-dialog.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + */ + +#ifndef E_GOOGLE_CHOOSER_DIALOG_H +#define E_GOOGLE_CHOOSER_DIALOG_H + +#include "e-google-chooser.h" + +/* Standard GObject macros */ +#define E_TYPE_GOOGLE_CHOOSER_DIALOG \ + (e_google_chooser_dialog_get_type ()) +#define E_GOOGLE_CHOOSER_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_GOOGLE_CHOOSER_DIALOG, EGoogleChooserDialog)) +#define E_GOOGLE_CHOOSER_DIALOG_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_GOOGLE_CHOOSER_DIALOG, EGoogleChooserDialogClass)) +#define E_IS_GOOGLE_CHOOSER_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_GOOGLE_CHOOSER_DIALOG)) +#define E_IS_GOOGLE_CHOOSER_DIALOG_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_GOOGLE_CHOOSER_DIALOG)) +#define E_GOOGLE_CHOOSER_DIALOG_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_GOOGLE_CHOOSER_DIALOG, EGoogleChooserDialogClass)) + +G_BEGIN_DECLS + +typedef struct _EGoogleChooserDialog EGoogleChooserDialog; +typedef struct _EGoogleChooserDialogClass EGoogleChooserDialogClass; +typedef struct _EGoogleChooserDialogPrivate EGoogleChooserDialogPrivate; + +struct _EGoogleChooserDialog { + GtkDialog parent; + EGoogleChooserDialogPrivate *priv; +}; + +struct _EGoogleChooserDialogClass { + GtkDialogClass parent_class; +}; + +GType e_google_chooser_dialog_get_type (void); +void e_google_chooser_dialog_type_register + (GTypeModule *type_module); +GtkWidget * e_google_chooser_dialog_new (EGoogleChooser *chooser, + GtkWindow *parent); +EGoogleChooser *e_google_chooser_dialog_get_chooser + (EGoogleChooserDialog *dialog); + +G_END_DECLS + +#endif /* E_GOOGLE_CHOOSER_DIALOG_H */ diff --git a/modules/cal-config-google/e-google-chooser.c b/modules/cal-config-google/e-google-chooser.c new file mode 100644 index 0000000000..d5a4064b0f --- /dev/null +++ b/modules/cal-config-google/e-google-chooser.c @@ -0,0 +1,623 @@ +/* + * e-google-chooser.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + */ + +#include "e-google-chooser.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define E_GOOGLE_CHOOSER_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_GOOGLE_CHOOSER, EGoogleChooserPrivate)) + +#define CALDAV_EVENTS_PATH_FORMAT "/calendar/dav/%s/events" + +typedef struct _Context Context; + +struct _EGoogleChooserPrivate { + ESource *source; +}; + +struct _Context { + GCancellable *cancellable; + GDataCalendarService *service; + GDataClientLoginAuthorizer *authorizer; + ESource *source; +}; + +enum { + PROP_0, + PROP_SOURCE +}; + +enum { + COLUMN_COLOR, + COLUMN_PATH, + COLUMN_TITLE, + COLUMN_WRITABLE, + NUM_COLUMNS +}; + +G_DEFINE_DYNAMIC_TYPE ( + EGoogleChooser, + e_google_chooser, + GTK_TYPE_TREE_VIEW) + +static void +context_free (Context *context) +{ + if (context->cancellable != NULL) + g_object_unref (context->cancellable); + + if (context->service != NULL) + g_object_unref (context->service); + + if (context->authorizer != NULL) + g_object_unref (context->authorizer); + + if (context->source != NULL) + g_object_unref (context->source); + + g_slice_free (Context, context); +} + +static gchar * +google_chooser_extract_caldav_events_path (const gchar *uri) +{ + SoupURI *soup_uri; + gchar *resource_name; + gchar *path; + gchar *cp; + + soup_uri = soup_uri_new (uri); + g_return_val_if_fail (soup_uri != NULL, NULL); + + /* Isolate the resource name in the "feeds" URI. */ + + cp = strstr (soup_uri->path, "/feeds/"); + g_return_val_if_fail (cp != NULL, NULL); + + /* strlen("/feeds/) == 7 */ + resource_name = g_strdup (cp + 7); + cp = strchr (resource_name, '/'); + if (cp != NULL) + *cp = '\0'; + + /* Decode any encoded 'at' symbols ('%40' -> '@'). */ + if (strstr (resource_name, "%40") != NULL) { + gchar **segments; + + segments = g_strsplit (resource_name, "%40", 0); + g_free (resource_name); + resource_name = g_strjoinv ("@", segments); + g_strfreev (segments); + } + + /* Use the decoded resource name in the CalDAV events path. */ + path = g_strdup_printf (CALDAV_EVENTS_PATH_FORMAT, resource_name); + + g_free (resource_name); + + soup_uri_free (soup_uri); + + return path; +} + +static void +google_chooser_set_source (EGoogleChooser *chooser, + ESource *source) +{ + g_return_if_fail (E_IS_SOURCE (source)); + g_return_if_fail (chooser->priv->source == NULL); + + chooser->priv->source = g_object_ref (source); +} + +static void +google_chooser_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_SOURCE: + google_chooser_set_source ( + E_GOOGLE_CHOOSER (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +google_chooser_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_SOURCE: + g_value_set_object ( + value, e_google_chooser_get_source ( + E_GOOGLE_CHOOSER (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +google_chooser_dispose (GObject *object) +{ + EGoogleChooserPrivate *priv; + + priv = E_GOOGLE_CHOOSER_GET_PRIVATE (object); + + if (priv->source != NULL) { + g_object_unref (priv->source); + priv->source = NULL; + } + + /* Chain up parent's dispose() method. */ + G_OBJECT_CLASS (e_google_chooser_parent_class)->dispose (object); +} + +static void +google_chooser_constructed (GObject *object) +{ + GtkTreeView *tree_view; + GtkListStore *list_store; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + + tree_view = GTK_TREE_VIEW (object); + + /* Chain up to parent's constructed() method. */ + G_OBJECT_CLASS (e_google_chooser_parent_class)->constructed (object); + + list_store = gtk_list_store_new ( + NUM_COLUMNS, + GDK_TYPE_COLOR, /* COLUMN_COLOR */ + G_TYPE_STRING, /* COLUMN_PATH */ + G_TYPE_STRING, /* COLUMN_TITLE */ + G_TYPE_BOOLEAN); /* COLUMN_WRITABLE */ + + gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store)); + + column = gtk_tree_view_column_new (); + gtk_tree_view_column_set_expand (column, TRUE); + gtk_tree_view_column_set_title (column, _("Name")); + gtk_tree_view_insert_column (tree_view, column, -1); + + renderer = e_cell_renderer_color_new (); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_add_attribute ( + column, renderer, "color", COLUMN_COLOR); + + renderer = gtk_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_tree_view_column_add_attribute ( + column, renderer, "text", COLUMN_TITLE); +} + +static void +e_google_chooser_class_init (EGoogleChooserClass *class) +{ + GObjectClass *object_class; + + g_type_class_add_private (class, sizeof (EGoogleChooserPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = google_chooser_set_property; + object_class->get_property = google_chooser_get_property; + object_class->dispose = google_chooser_dispose; + object_class->constructed = google_chooser_constructed; + + g_object_class_install_property ( + object_class, + PROP_SOURCE, + g_param_spec_object ( + "source", + "Source", + "Google data source", + E_TYPE_SOURCE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); +} + +static void +e_google_chooser_class_finalize (EGoogleChooserClass *class) +{ +} + +static void +e_google_chooser_init (EGoogleChooser *chooser) +{ + chooser->priv = E_GOOGLE_CHOOSER_GET_PRIVATE (chooser); +} + +void +e_google_chooser_type_register (GTypeModule *type_module) +{ + /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration + * function, so we have to wrap it with a public function in + * order to register types from a separate compilation unit. */ + e_google_chooser_register_type (type_module); +} + +GtkWidget * +e_google_chooser_new (ESource *source) +{ + g_return_val_if_fail (E_IS_SOURCE (source), NULL); + + return g_object_new (E_TYPE_GOOGLE_CHOOSER, "source", source, NULL); +} + +ESource * +e_google_chooser_get_source (EGoogleChooser *chooser) +{ + g_return_val_if_fail (E_IS_GOOGLE_CHOOSER (chooser), NULL); + + return chooser->priv->source; +} + +gchar * +e_google_chooser_get_decoded_user (EGoogleChooser *chooser) +{ + ESource *source; + ESourceAuthentication *authentication_extension; + const gchar *user; + gchar *decoded_user; + + g_return_val_if_fail (E_IS_GOOGLE_CHOOSER (chooser), NULL); + + source = e_google_chooser_get_source (chooser); + + authentication_extension = e_source_get_extension ( + source, E_SOURCE_EXTENSION_AUTHENTICATION); + + user = e_source_authentication_get_user (authentication_extension); + if (user == NULL || *user == '\0') + return NULL; + + /* Decode any encoded 'at' symbols ('%40' -> '@'). */ + if (strstr (user, "%40") != NULL) { + gchar **segments; + + segments = g_strsplit (user, "%40", 0); + decoded_user = g_strjoinv ("@", segments); + g_strfreev (segments); + + /* If no domain is given, append "@gmail.com". */ + } else if (strstr (user, "@") == NULL) { + decoded_user = g_strconcat (user, "@gmail.com", NULL); + + /* Otherwise the user name should be fine as is. */ + } else { + decoded_user = g_strdup (user); + } + + return decoded_user; +} + +static void +google_chooser_query_cb (GDataService *service, + GAsyncResult *result, + GSimpleAsyncResult *simple) +{ + GObject *object; + GDataFeed *feed; + GList *list, *link; + GtkTreeView *tree_view; + GtkListStore *list_store; + GtkTreeModel *tree_model; + GError *error = NULL; + + feed = gdata_service_query_finish (service, result, &error); + + if (error != NULL) { + g_warn_if_fail (feed == NULL); + g_simple_async_result_set_from_error (simple, error); + g_simple_async_result_complete (simple); + g_object_unref (simple); + return; + } + + g_return_if_fail (GDATA_IS_FEED (feed)); + + list = gdata_feed_get_entries (feed); + + /* This returns a new reference, for reasons passing understanding. */ + object = g_async_result_get_source_object (G_ASYNC_RESULT (simple)); + + tree_view = GTK_TREE_VIEW (object); + tree_model = gtk_tree_view_get_model (tree_view); + list_store = GTK_LIST_STORE (tree_model); + + gtk_list_store_clear (list_store); + + for (link = list; link != NULL; link = g_list_next (link)) { + GDataCalendarCalendar *calendar; + GDataEntry *entry; + GDataLink *alt; + GDataColor color; + GdkColor gdkcolor; + GtkTreeIter iter; + const gchar *uri; + const gchar *title; + const gchar *access; + gboolean writable; + gchar *path; + + entry = GDATA_ENTRY (link->data); + calendar = GDATA_CALENDAR_CALENDAR (entry); + + /* Skip hidden entries. */ + if (gdata_calendar_calendar_is_hidden (calendar)) + continue; + + /* Look up the alternate link, skip if there is none. */ + alt = gdata_entry_look_up_link (entry, GDATA_LINK_ALTERNATE); + if (alt == NULL) + continue; + + uri = gdata_link_get_uri (alt); + title = gdata_entry_get_title (entry); + gdata_calendar_calendar_get_color (calendar, &color); + access = gdata_calendar_calendar_get_access_level (calendar); + + if (uri == NULL || *uri == '\0') + continue; + + if (title == NULL || *title == '\0') + continue; + + path = google_chooser_extract_caldav_events_path (uri); + + gdkcolor.pixel = 0; + gdkcolor.red = color.red * 256; + gdkcolor.green = color.green * 256; + gdkcolor.blue = color.blue * 256; + + if (access == NULL) + writable = TRUE; + else if (g_ascii_strcasecmp (access, "owner") == 0) + writable = TRUE; + else if (g_ascii_strcasecmp (access, "contributor") == 0) + writable = TRUE; + else + writable = FALSE; + + gtk_list_store_append (list_store, &iter); + + gtk_list_store_set ( + list_store, &iter, + COLUMN_COLOR, &gdkcolor, + COLUMN_PATH, path, + COLUMN_TITLE, title, + COLUMN_WRITABLE, writable, + -1); + + g_free (path); + } + + g_object_unref (object); + g_object_unref (feed); + + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +static void +google_chooser_authenticate_cb (GDataClientLoginAuthorizer *authorizer, + GAsyncResult *result, + GSimpleAsyncResult *simple) +{ + Context *context; + GError *error = NULL; + + context = g_simple_async_result_get_op_res_gpointer (simple); + + gdata_client_login_authorizer_authenticate_finish ( + authorizer, result, &error); + + if (error != NULL) { + g_simple_async_result_set_from_error (simple, error); + g_simple_async_result_complete (simple); + g_object_unref (simple); + return; + } + + /* We're authenticated, now query for all calendars. */ + + gdata_calendar_service_query_all_calendars_async ( + context->service, NULL, context->cancellable, + NULL, NULL, NULL, (GAsyncReadyCallback) + google_chooser_query_cb, simple); +} + +void +e_google_chooser_populate (EGoogleChooser *chooser, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GDataClientLoginAuthorizer *authorizer; + GDataCalendarService *service; + GSimpleAsyncResult *simple; + Context *context; + ESource *source; + gpointer parent; + gchar *password; + gchar *prompt; + gchar *user; + + g_return_if_fail (E_IS_GOOGLE_CHOOSER (chooser)); + + source = e_google_chooser_get_source (chooser); + + authorizer = gdata_client_login_authorizer_new ( + PACKAGE_NAME, GDATA_TYPE_CALENDAR_SERVICE); + + service = gdata_calendar_service_new (GDATA_AUTHORIZER (authorizer)); + + context = g_slice_new0 (Context); + context->service = service; /* takes ownership */ + context->source = g_object_ref (source); + + if (G_IS_CANCELLABLE (cancellable)) + context->cancellable = g_object_ref (cancellable); + else + context->cancellable = g_cancellable_new (); + + simple = g_simple_async_result_new ( + G_OBJECT (chooser), callback, + user_data, e_google_chooser_populate); + + g_simple_async_result_set_op_res_gpointer ( + simple, context, (GDestroyNotify) context_free); + + /* Prompt for a password. */ + + user = e_google_chooser_get_decoded_user (chooser); + + parent = gtk_widget_get_toplevel (GTK_WIDGET (chooser)); + parent = gtk_widget_is_toplevel (parent) ? parent : NULL; + + prompt = g_strdup_printf ( + _("Enter Google password for user '%s'."), user); + + /* XXX The 'key' (3rd) argument doesn't matter since we're + * passing E_PASSWORDS_REMEMBER_NEVER, it just needs to + * be non-NULL. This API is degenerating rapidly. */ + password = e_passwords_ask_password ( + "", NULL, "bogus key", prompt, + E_PASSWORDS_REMEMBER_NEVER | + E_PASSWORDS_DISABLE_REMEMBER | + E_PASSWORDS_SECRET, NULL, parent); + + g_free (prompt); + + if (password == NULL) { + g_cancellable_cancel (context->cancellable); + g_simple_async_result_set_error ( + simple, G_IO_ERROR, G_IO_ERROR_CANCELLED, + "%s", _("User declined to provide a password")); + g_simple_async_result_complete (simple); + g_object_unref (authorizer); + g_object_unref (simple); + g_free (user); + return; + } + + /* Try authenticating. */ + + gdata_client_login_authorizer_authenticate_async ( + authorizer, user, password, + context->cancellable, (GAsyncReadyCallback) + google_chooser_authenticate_cb, simple); + + g_free (password); + g_free (user); + + g_object_unref (authorizer); +} + +gboolean +e_google_chooser_populate_finish (EGoogleChooser *chooser, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple; + + g_return_val_if_fail ( + g_simple_async_result_is_valid ( + result, G_OBJECT (chooser), + e_google_chooser_populate), FALSE); + + simple = G_SIMPLE_ASYNC_RESULT (result); + + /* Assume success unless a GError is set. */ + return !g_simple_async_result_propagate_error (simple, error); +} + +gboolean +e_google_chooser_apply_selected (EGoogleChooser *chooser) +{ + ESourceSelectable *selectable_extension; + ESourceWebdav *webdav_extension; + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + ESource *source; + GdkColor *color; + SoupURI *soup_uri; + gchar *color_spec; + gchar *title; + gchar *path; + + g_return_val_if_fail (E_IS_GOOGLE_CHOOSER (chooser), FALSE); + + source = e_google_chooser_get_source (chooser); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (chooser)); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return FALSE; + + gtk_tree_model_get ( + model, &iter, + COLUMN_COLOR, &color, + COLUMN_PATH, &path, + COLUMN_TITLE, &title, + -1); + + selectable_extension = e_source_get_extension ( + source, E_SOURCE_EXTENSION_CALENDAR); + + webdav_extension = e_source_get_extension ( + source, E_SOURCE_EXTENSION_WEBDAV_BACKEND); + + e_source_set_display_name (source, title); + + e_source_webdav_set_display_name (webdav_extension, title); + + /* XXX Might be easier to expose get/set_path functions? */ + soup_uri = e_source_webdav_dup_soup_uri (webdav_extension); + soup_uri_set_path (soup_uri, path); + e_source_webdav_set_soup_uri (webdav_extension, soup_uri); + soup_uri_free (soup_uri); + + color_spec = gdk_color_to_string (color); + e_source_selectable_set_color (selectable_extension, color_spec); + g_free (color_spec); + + gdk_color_free (color); + g_free (title); + g_free (path); + + return TRUE; +} diff --git a/modules/cal-config-google/e-google-chooser.h b/modules/cal-config-google/e-google-chooser.h new file mode 100644 index 0000000000..f2cd28a6c5 --- /dev/null +++ b/modules/cal-config-google/e-google-chooser.h @@ -0,0 +1,76 @@ +/* + * e-google-chooser.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + */ + +#ifndef E_GOOGLE_CHOOSER_H +#define E_GOOGLE_CHOOSER_H + +#include +#include + +/* Standard GObject macros */ +#define E_TYPE_GOOGLE_CHOOSER \ + (e_google_chooser_get_type ()) +#define E_GOOGLE_CHOOSER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_GOOGLE_CHOOSER, EGoogleChooser)) +#define E_GOOGLE_CHOOSER_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_GOOGLE_CHOOSER, EGoogleChooserClass)) +#define E_IS_GOOGLE_CHOOSER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_GOOGLE_CHOOSER)) +#define E_IS_GOOGLE_CHOOSER_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_GOOGLE_CHOOSER)) +#define E_GOOGLE_CHOOSER_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_GOOGLE_CHOOSER, EGoogleChooserClass)) + +G_BEGIN_DECLS + +typedef struct _EGoogleChooser EGoogleChooser; +typedef struct _EGoogleChooserClass EGoogleChooserClass; +typedef struct _EGoogleChooserPrivate EGoogleChooserPrivate; + +struct _EGoogleChooser { + GtkTreeView parent; + EGoogleChooserPrivate *priv; +}; + +struct _EGoogleChooserClass { + GtkTreeViewClass parent_class; +}; + +GType e_google_chooser_get_type (void); +void e_google_chooser_type_register + (GTypeModule *type_module); +GtkWidget * e_google_chooser_new (ESource *source); +ESource * e_google_chooser_get_source (EGoogleChooser *chooser); +gchar * e_google_chooser_get_decoded_user + (EGoogleChooser *chooser); +void e_google_chooser_populate (EGoogleChooser *chooser, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean e_google_chooser_populate_finish + (EGoogleChooser *chooser, + GAsyncResult *result, + GError **error); +gboolean e_google_chooser_apply_selected (EGoogleChooser *chooser); + +#endif /* E_GOOGLE_CHOOSER_H */ diff --git a/modules/cal-config-google/evolution-cal-config-google.c b/modules/cal-config-google/evolution-cal-config-google.c new file mode 100644 index 0000000000..589adf5aec --- /dev/null +++ b/modules/cal-config-google/evolution-cal-config-google.c @@ -0,0 +1,194 @@ +/* + * evolution-cal-config-google.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + */ + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "e-google-chooser-button.h" +#include "e-google-chooser-dialog.h" + +typedef ESourceConfigBackend ECalConfigGoogle; +typedef ESourceConfigBackendClass ECalConfigGoogleClass; + +typedef struct _Context Context; + +struct _Context { + GtkWidget *google_button; +}; + +/* Module Entry Points */ +void e_module_load (GTypeModule *type_module); +void e_module_unload (GTypeModule *type_module); + +/* Forward Declarations */ +GType e_cal_config_google_get_type (void); + +G_DEFINE_DYNAMIC_TYPE ( + ECalConfigGoogle, + e_cal_config_google, + E_TYPE_SOURCE_CONFIG_BACKEND) + +static void +cal_config_google_context_free (Context *context) +{ + g_object_unref (context->google_button); + + g_slice_free (Context, context); +} + +static gboolean +cal_config_google_allow_creation (ESourceConfigBackend *backend) +{ + ESourceConfig *config; + ECalClientSourceType source_type; + + config = e_source_config_backend_get_config (backend); + + source_type = e_cal_source_config_get_source_type ( + E_CAL_SOURCE_CONFIG (config)); + + /* XXX Google's CalDAV interface doesn't support tasks. */ + return (source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS); +} + +static void +cal_config_google_insert_widgets (ESourceConfigBackend *backend, + ESource *scratch_source) +{ + ESourceConfig *config; + GtkWidget *widget; + Context *context; + const gchar *uid; + + context = g_slice_new0 (Context); + uid = e_source_get_uid (scratch_source); + config = e_source_config_backend_get_config (backend); + + g_object_set_data_full ( + G_OBJECT (backend), uid, context, + (GDestroyNotify) cal_config_google_context_free); + + e_cal_source_config_add_offline_toggle ( + E_CAL_SOURCE_CONFIG (config), scratch_source); + + e_source_config_add_user_entry (config, scratch_source); + + widget = e_google_chooser_button_new (scratch_source); + e_source_config_insert_widget ( + config, scratch_source, _("Calendar:"), widget); + context->google_button = g_object_ref (widget); + gtk_widget_show (widget); + + e_source_config_add_refresh_interval (config, scratch_source); +} + +static void +cal_config_google_commit_changes (ESourceConfigBackend *backend, + ESource *scratch_source) +{ + ESourceBackend *calendar_extension; + ESourceWebdav *webdav_extension; + SoupURI *soup_uri; + + /* We need to hard-code a few settings. */ + + calendar_extension = e_source_get_extension ( + scratch_source, E_SOURCE_EXTENSION_CALENDAR); + + webdav_extension = e_source_get_extension ( + scratch_source, E_SOURCE_EXTENSION_WEBDAV_BACKEND); + + /* The backend name is actually "caldav" even though the + * ESource is a child of the built-in "Google" source. */ + e_source_backend_set_backend_name (calendar_extension, "caldav"); + + soup_uri = e_source_webdav_dup_soup_uri (webdav_extension); + + /* The host name is fixed, obviously. */ + soup_uri_set_host (soup_uri, "www.google.com"); + + /* Google's CalDAV interface requires a secure connection. */ + soup_uri_set_scheme (soup_uri, SOUP_URI_SCHEME_HTTPS); + + e_source_webdav_set_soup_uri (webdav_extension, soup_uri); + + soup_uri_free (soup_uri); +} + +static gboolean +cal_config_google_check_complete (ESourceConfigBackend *backend, + ESource *scratch_source) +{ + ESourceAuthentication *extension; + const gchar *extension_name; + const gchar *user; + + extension_name = E_SOURCE_EXTENSION_AUTHENTICATION; + extension = e_source_get_extension (scratch_source, extension_name); + user = e_source_authentication_get_user (extension); + + return (user != NULL); +} + +static void +e_cal_config_google_class_init (ESourceConfigBackendClass *class) +{ + EExtensionClass *extension_class; + + extension_class = E_EXTENSION_CLASS (class); + extension_class->extensible_type = E_TYPE_CAL_SOURCE_CONFIG; + + class->parent_uid = "google-stub"; + class->backend_name = "google"; + class->allow_creation = cal_config_google_allow_creation; + class->insert_widgets = cal_config_google_insert_widgets; + class->check_complete = cal_config_google_check_complete; + class->commit_changes = cal_config_google_commit_changes; +} + +static void +e_cal_config_google_class_finalize (ESourceConfigBackendClass *class) +{ +} + +static void +e_cal_config_google_init (ESourceConfigBackend *backend) +{ +} + +G_MODULE_EXPORT void +e_module_load (GTypeModule *type_module) +{ + e_google_chooser_type_register (type_module); + e_google_chooser_button_type_register (type_module); + e_google_chooser_dialog_type_register (type_module); + e_cal_config_google_register_type (type_module); +} + +G_MODULE_EXPORT void +e_module_unload (GTypeModule *type_module) +{ +} -- cgit v1.2.3