aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc/e-source-config-dialog.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-12-18 06:45:54 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-06-03 11:00:38 +0800
commit2a2933ec5cdc0d7afd9b8da5f9146c5d7f1630df (patch)
tree6dcf480dbe7a01eaecb1092c7cc4c17b2e733257 /widgets/misc/e-source-config-dialog.c
parentd3498e0ccd853b7e91877e82fd6150ac412294cc (diff)
downloadgsoc2013-evolution-2a2933ec5cdc0d7afd9b8da5f9146c5d7f1630df.tar
gsoc2013-evolution-2a2933ec5cdc0d7afd9b8da5f9146c5d7f1630df.tar.gz
gsoc2013-evolution-2a2933ec5cdc0d7afd9b8da5f9146c5d7f1630df.tar.bz2
gsoc2013-evolution-2a2933ec5cdc0d7afd9b8da5f9146c5d7f1630df.tar.lz
gsoc2013-evolution-2a2933ec5cdc0d7afd9b8da5f9146c5d7f1630df.tar.xz
gsoc2013-evolution-2a2933ec5cdc0d7afd9b8da5f9146c5d7f1630df.tar.zst
gsoc2013-evolution-2a2933ec5cdc0d7afd9b8da5f9146c5d7f1630df.zip
Add ESourceConfig widget.
Base class for building address book and calendar configuration dialogs.
Diffstat (limited to 'widgets/misc/e-source-config-dialog.c')
-rw-r--r--widgets/misc/e-source-config-dialog.c313
1 files changed, 313 insertions, 0 deletions
diff --git a/widgets/misc/e-source-config-dialog.c b/widgets/misc/e-source-config-dialog.c
new file mode 100644
index 0000000000..1174d38d23
--- /dev/null
+++ b/widgets/misc/e-source-config-dialog.c
@@ -0,0 +1,313 @@
+/*
+ * e-source-config-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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-source-config-dialog.h"
+
+#define E_SOURCE_CONFIG_DIALOG_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_SOURCE_CONFIG_DIALOG, ESourceConfigDialogPrivate))
+
+struct _ESourceConfigDialogPrivate {
+ ESourceConfig *config;
+ ESourceRegistry *registry;
+};
+
+enum {
+ PROP_0,
+ PROP_CONFIG
+};
+
+G_DEFINE_TYPE (
+ ESourceConfigDialog,
+ e_source_config_dialog,
+ GTK_TYPE_DIALOG)
+
+static void
+source_config_dialog_commit_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ ESourceConfig *config;
+ ESourceConfigDialog *dialog;
+ GdkWindow *gdk_window;
+ GError *error = NULL;
+
+ config = E_SOURCE_CONFIG (object);
+ dialog = E_SOURCE_CONFIG_DIALOG (user_data);
+
+ /* Set the cursor back to normal. */
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (dialog));
+ gdk_window_set_cursor (gdk_window, NULL);
+
+ /* Allow user interaction with window content. */
+ gtk_widget_set_sensitive (GTK_WIDGET (dialog), TRUE);
+
+ e_source_config_commit_finish (config, result, &error);
+
+ /* Ignore cancellations. */
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ g_object_unref (dialog);
+ g_error_free (error);
+
+ /* FIXME ESourceConfigDialog should implement EAlertSink. */
+ } else if (error != NULL) {
+ g_warning ("%s: %s", G_STRFUNC, error->message);
+ g_object_unref (dialog);
+ g_error_free (error);
+
+ } else {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ }
+}
+
+static void
+source_config_dialog_commit (ESourceConfigDialog *dialog)
+{
+ GdkCursor *gdk_cursor;
+ GdkWindow *gdk_window;
+ ESourceConfig *config;
+
+ config = e_source_config_dialog_get_config (dialog);
+
+ /* Make the cursor appear busy. */
+ gdk_cursor = gdk_cursor_new (GDK_WATCH);
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (dialog));
+ gdk_window_set_cursor (gdk_window, gdk_cursor);
+ g_object_unref (gdk_cursor);
+
+ /* Prevent user interaction with window content. */
+ gtk_widget_set_sensitive (GTK_WIDGET (dialog), FALSE);
+
+ /* XXX This operation is not cancellable. */
+ e_source_config_commit (
+ config, NULL,
+ source_config_dialog_commit_cb,
+ g_object_ref (dialog));
+}
+
+static void
+source_config_dialog_source_removed_cb (ESourceRegistry *registry,
+ ESource *removed_source,
+ ESourceConfigDialog *dialog)
+{
+ ESourceConfig *config;
+ ESource *original_source;
+
+ /* If the ESource being edited is removed, cancel the dialog. */
+
+ config = e_source_config_dialog_get_config (dialog);
+ original_source = e_source_config_get_original_source (config);
+
+ if (original_source == NULL)
+ return;
+
+ if (!e_source_equal (original_source, removed_source))
+ return;
+
+ gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+}
+
+static void
+source_config_dialog_set_config (ESourceConfigDialog *dialog,
+ ESourceConfig *config)
+{
+ ESourceRegistry *registry;
+
+ g_return_if_fail (E_IS_SOURCE_CONFIG (config));
+ g_return_if_fail (dialog->priv->config == NULL);
+
+ dialog->priv->config = g_object_ref (config);
+
+ registry = e_source_config_get_registry (config);
+ dialog->priv->registry = g_object_ref (registry);
+
+ g_signal_connect (
+ registry, "source-removed",
+ G_CALLBACK (source_config_dialog_source_removed_cb), dialog);
+}
+
+static void
+source_config_dialog_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_CONFIG:
+ source_config_dialog_set_config (
+ E_SOURCE_CONFIG_DIALOG (object),
+ g_value_get_object (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_config_dialog_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_CONFIG:
+ g_value_set_object (
+ value,
+ e_source_config_dialog_get_config (
+ E_SOURCE_CONFIG_DIALOG (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_config_dialog_dispose (GObject *object)
+{
+ ESourceConfigDialogPrivate *priv;
+
+ priv = E_SOURCE_CONFIG_DIALOG_GET_PRIVATE (object);
+
+ if (priv->config != NULL) {
+ g_object_unref (priv->config);
+ priv->config = NULL;
+ }
+
+ if (priv->registry != NULL) {
+ g_signal_handlers_disconnect_matched (
+ priv->registry, G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL, object);
+ g_object_unref (priv->registry);
+ priv->registry = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_source_config_dialog_parent_class)->dispose (object);
+}
+
+static void
+source_config_dialog_constructed (GObject *object)
+{
+ ESourceConfigDialogPrivate *priv;
+ GtkWidget *content_area;
+ GtkWidget *config;
+ GtkWidget *widget;
+
+ priv = E_SOURCE_CONFIG_DIALOG_GET_PRIVATE (object);
+
+ config = GTK_WIDGET (priv->config);
+
+ widget = gtk_dialog_get_widget_for_response (
+ GTK_DIALOG (object), GTK_RESPONSE_OK);
+
+ gtk_container_set_border_width (GTK_CONTAINER (object), 5);
+ gtk_container_set_border_width (GTK_CONTAINER (config), 5);
+
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (object));
+ gtk_box_pack_start (GTK_BOX (content_area), config, TRUE, TRUE, 0);
+ gtk_widget_show (config);
+
+ /* Don't use G_BINDING_SYNC_CREATE here. The ESourceConfig widget
+ * is not ready to run check_complete() until after it's realized. */
+ g_object_bind_property (
+ config, "complete",
+ widget, "sensitive",
+ G_BINDING_DEFAULT);
+}
+
+static void
+source_config_dialog_response (GtkDialog *dialog,
+ gint response_id)
+{
+ /* Do not chain up. GtkDialog does not implement this method. */
+
+ switch (response_id) {
+ case GTK_RESPONSE_OK:
+ source_config_dialog_commit (
+ E_SOURCE_CONFIG_DIALOG (dialog));
+ break;
+ case GTK_RESPONSE_CANCEL:
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+e_source_config_dialog_class_init (ESourceConfigDialogClass *class)
+{
+ GObjectClass *object_class;
+ GtkDialogClass *dialog_class;
+
+ g_type_class_add_private (class, sizeof (ESourceConfigDialogPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = source_config_dialog_set_property;
+ object_class->get_property = source_config_dialog_get_property;
+ object_class->dispose = source_config_dialog_dispose;
+ object_class->constructed = source_config_dialog_constructed;
+
+ dialog_class = GTK_DIALOG_CLASS (class);
+ dialog_class->response = source_config_dialog_response;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_CONFIG,
+ g_param_spec_object (
+ "config",
+ "Config",
+ "The ESourceConfig instance",
+ E_TYPE_SOURCE_CONFIG,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+e_source_config_dialog_init (ESourceConfigDialog *dialog)
+{
+ dialog->priv = E_SOURCE_CONFIG_DIALOG_GET_PRIVATE (dialog);
+
+ gtk_dialog_add_buttons (
+ GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (
+ GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+}
+
+GtkWidget *
+e_source_config_dialog_new (ESourceConfig *config)
+{
+ g_return_val_if_fail (E_IS_SOURCE_CONFIG (config), NULL);
+
+ return g_object_new (
+ E_TYPE_SOURCE_CONFIG_DIALOG,
+ "config", config, NULL);
+}
+
+ESourceConfig *
+e_source_config_dialog_get_config (ESourceConfigDialog *dialog)
+{
+ g_return_val_if_fail (E_IS_SOURCE_CONFIG_DIALOG (dialog), NULL);
+
+ return dialog->priv->config;
+}