aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui
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 /addressbook/gui
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 'addressbook/gui')
-rw-r--r--addressbook/gui/widgets/Makefile.am2
-rw-r--r--addressbook/gui/widgets/e-book-source-config.c254
-rw-r--r--addressbook/gui/widgets/e-book-source-config.h67
3 files changed, 323 insertions, 0 deletions
diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am
index 19c9c4f72b..a580be000b 100644
--- a/addressbook/gui/widgets/Makefile.am
+++ b/addressbook/gui/widgets/Makefile.am
@@ -55,6 +55,8 @@ libeabwidgets_la_SOURCES = \
e-addressbook-selector.h \
e-addressbook-view.c \
e-addressbook-view.h \
+ e-book-source-config.c \
+ e-book-source-config.h \
gal-view-minicard.c \
gal-view-minicard.h \
gal-view-factory-minicard.c \
diff --git a/addressbook/gui/widgets/e-book-source-config.c b/addressbook/gui/widgets/e-book-source-config.c
new file mode 100644
index 0000000000..8b9ed62b30
--- /dev/null
+++ b/addressbook/gui/widgets/e-book-source-config.c
@@ -0,0 +1,254 @@
+/*
+ * e-book-source-config.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-book-source-config.h"
+
+#include <config.h>
+#include <glib/gi18n-lib.h>
+
+#include <libedataserver/e-source-address-book.h>
+#include <libedataserver/e-source-autocomplete.h>
+#include <libedataserver/e-source-offline.h>
+
+#define E_BOOK_SOURCE_CONFIG_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_BOOK_SOURCE_CONFIG, EBookSourceConfigPrivate))
+
+struct _EBookSourceConfigPrivate {
+ GtkWidget *default_button;
+ GtkWidget *autocomplete_button;
+};
+
+G_DEFINE_TYPE (
+ EBookSourceConfig,
+ e_book_source_config,
+ E_TYPE_SOURCE_CONFIG)
+
+static ESource *
+book_source_config_get_default (ESourceConfig *config)
+{
+ ESourceRegistry *registry;
+
+ registry = e_source_config_get_registry (config);
+
+ return e_source_registry_get_default_address_book (registry);
+}
+
+static void
+book_source_config_set_default (ESourceConfig *config,
+ ESource *source)
+{
+ ESourceRegistry *registry;
+
+ registry = e_source_config_get_registry (config);
+
+ e_source_registry_set_default_address_book (registry, source);
+}
+
+static void
+book_source_config_dispose (GObject *object)
+{
+ EBookSourceConfigPrivate *priv;
+
+ priv = E_BOOK_SOURCE_CONFIG_GET_PRIVATE (object);
+
+ if (priv->default_button != NULL) {
+ g_object_unref (priv->default_button);
+ priv->default_button = NULL;
+ }
+
+ if (priv->autocomplete_button != NULL) {
+ g_object_unref (priv->autocomplete_button);
+ priv->autocomplete_button = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_book_source_config_parent_class)->dispose (object);
+}
+
+static void
+book_source_config_constructed (GObject *object)
+{
+ EBookSourceConfigPrivate *priv;
+ ESource *default_source;
+ ESource *original_source;
+ ESourceConfig *config;
+ GObjectClass *class;
+ GtkWidget *widget;
+ const gchar *label;
+
+ /* Chain up to parent's constructed() method. */
+ class = G_OBJECT_CLASS (e_book_source_config_parent_class);
+ class->constructed (object);
+
+ config = E_SOURCE_CONFIG (object);
+ priv = E_BOOK_SOURCE_CONFIG_GET_PRIVATE (object);
+
+ label = _("Mark as default address book");
+ widget = gtk_check_button_new_with_label (label);
+ priv->default_button = g_object_ref_sink (widget);
+ gtk_widget_show (widget);
+
+ label = _("Autocomplete with this address book");
+ widget = gtk_check_button_new_with_label (label);
+ priv->autocomplete_button = g_object_ref_sink (widget);
+ gtk_widget_show (widget);
+
+ default_source = book_source_config_get_default (config);
+ original_source = e_source_config_get_original_source (config);
+
+ if (original_source != NULL) {
+ gboolean active;
+
+ active = e_source_equal (original_source, default_source);
+ g_object_set (priv->default_button, "active", active, NULL);
+ }
+
+ e_source_config_insert_widget (
+ config, NULL, NULL, priv->default_button);
+
+ e_source_config_insert_widget (
+ config, NULL, NULL, priv->autocomplete_button);
+}
+
+static const gchar *
+book_source_config_get_backend_extension_name (ESourceConfig *config)
+{
+ return E_SOURCE_EXTENSION_ADDRESS_BOOK;
+}
+
+static void
+book_source_config_init_candidate (ESourceConfig *config,
+ ESource *scratch_source)
+{
+ EBookSourceConfigPrivate *priv;
+ ESourceConfigClass *class;
+ ESourceExtension *extension;
+ const gchar *extension_name;
+
+ /* Chain up to parent's init_candidate() method. */
+ class = E_SOURCE_CONFIG_CLASS (e_book_source_config_parent_class);
+ class->init_candidate (config, scratch_source);
+
+ priv = E_BOOK_SOURCE_CONFIG_GET_PRIVATE (config);
+
+ extension_name = E_SOURCE_EXTENSION_AUTOCOMPLETE;
+ extension = e_source_get_extension (scratch_source, extension_name);
+
+ g_object_bind_property (
+ extension, "include-me",
+ priv->autocomplete_button, "active",
+ G_BINDING_BIDIRECTIONAL |
+ G_BINDING_SYNC_CREATE);
+}
+
+static void
+book_source_config_commit_changes (ESourceConfig *config,
+ ESource *scratch_source)
+{
+ EBookSourceConfigPrivate *priv;
+ ESourceConfigClass *class;
+ ESource *default_source;
+ GtkToggleButton *toggle_button;
+
+ priv = E_BOOK_SOURCE_CONFIG_GET_PRIVATE (config);
+ toggle_button = GTK_TOGGLE_BUTTON (priv->default_button);
+
+ /* Chain up to parent's commit_changes() method. */
+ class = E_SOURCE_CONFIG_CLASS (e_book_source_config_parent_class);
+ class->commit_changes (config, scratch_source);
+
+ default_source = book_source_config_get_default (config);
+
+ /* The default setting is a little tricky to get right. If
+ * the toggle button is active, this ESource is now the default.
+ * That much is simple. But if the toggle button is NOT active,
+ * then we have to inspect the old default. If this ESource WAS
+ * the default, reset the default to 'system'. If this ESource
+ * WAS NOT the old default, leave it alone. */
+ if (gtk_toggle_button_get_active (toggle_button))
+ book_source_config_set_default (config, scratch_source);
+ else if (e_source_equal (scratch_source, default_source))
+ book_source_config_set_default (config, NULL);
+}
+
+static void
+e_book_source_config_class_init (EBookSourceConfigClass *class)
+{
+ GObjectClass *object_class;
+ ESourceConfigClass *source_config_class;
+
+ g_type_class_add_private (class, sizeof (EBookSourceConfigPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->dispose = book_source_config_dispose;
+ object_class->constructed = book_source_config_constructed;
+
+ source_config_class = E_SOURCE_CONFIG_CLASS (class);
+ source_config_class->get_backend_extension_name =
+ book_source_config_get_backend_extension_name;
+ source_config_class->init_candidate = book_source_config_init_candidate;
+ source_config_class->commit_changes = book_source_config_commit_changes;
+}
+
+static void
+e_book_source_config_init (EBookSourceConfig *config)
+{
+ config->priv = E_BOOK_SOURCE_CONFIG_GET_PRIVATE (config);
+}
+
+GtkWidget *
+e_book_source_config_new (ESourceRegistry *registry,
+ ESource *original_source)
+{
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
+
+ if (original_source != NULL)
+ g_return_val_if_fail (E_IS_SOURCE (original_source), NULL);
+
+ return g_object_new (
+ E_TYPE_BOOK_SOURCE_CONFIG, "registry", registry,
+ "original-source", original_source, NULL);
+}
+
+void
+e_book_source_config_add_offline_toggle (EBookSourceConfig *config,
+ ESource *scratch_source)
+{
+ GtkWidget *widget;
+ ESourceExtension *extension;
+ const gchar *extension_name;
+
+ g_return_if_fail (E_IS_BOOK_SOURCE_CONFIG (config));
+ g_return_if_fail (E_IS_SOURCE (scratch_source));
+
+ extension_name = E_SOURCE_EXTENSION_OFFLINE;
+ extension = e_source_get_extension (scratch_source, extension_name);
+
+ widget = gtk_check_button_new_with_label (
+ _("Copy book content locally for offline operation"));
+ e_source_config_insert_widget (
+ E_SOURCE_CONFIG (config), scratch_source, NULL, widget);
+ gtk_widget_show (widget);
+
+ g_object_bind_property (
+ extension, "stay-synchronized",
+ widget, "active",
+ G_BINDING_BIDIRECTIONAL |
+ G_BINDING_SYNC_CREATE);
+}
diff --git a/addressbook/gui/widgets/e-book-source-config.h b/addressbook/gui/widgets/e-book-source-config.h
new file mode 100644
index 0000000000..18e075511e
--- /dev/null
+++ b/addressbook/gui/widgets/e-book-source-config.h
@@ -0,0 +1,67 @@
+/*
+ * e-book-source-config.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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_BOOK_SOURCE_CONFIG_H
+#define E_BOOK_SOURCE_CONFIG_H
+
+#include <misc/e-source-config.h>
+
+/* Standard GObject macros */
+#define E_TYPE_BOOK_SOURCE_CONFIG \
+ (e_book_source_config_get_type ())
+#define E_BOOK_SOURCE_CONFIG(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_BOOK_SOURCE_CONFIG, EBookSourceConfig))
+#define E_BOOK_SOURCE_CONFIG_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_BOOK_SOURCE_CONFIG, EBookSourceConfigClass))
+#define E_IS_BOOK_SOURCE_CONFIG(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_BOOK_SOURCE_CONFIG))
+#define E_IS_BOOK_SOURCE_CONFIG_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_BOOK_SOURCE_CONFIG))
+#define E_BOOK_SOURCE_CONFIG_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_BOOK_SOURCE_CONFIG, EBookSourceConfigClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EBookSourceConfig EBookSourceConfig;
+typedef struct _EBookSourceConfigClass EBookSourceConfigClass;
+typedef struct _EBookSourceConfigPrivate EBookSourceConfigPrivate;
+
+struct _EBookSourceConfig {
+ ESourceConfig parent;
+ EBookSourceConfigPrivate *priv;
+};
+
+struct _EBookSourceConfigClass {
+ ESourceConfigClass parent_class;
+};
+
+GType e_book_source_config_get_type (void) G_GNUC_CONST;
+GtkWidget * e_book_source_config_new (ESourceRegistry *registry,
+ ESource *original_source);
+void e_book_source_config_add_offline_toggle
+ (EBookSourceConfig *config,
+ ESource *scratch_source);
+
+G_END_DECLS
+
+#endif /* E_BOOK_SOURCE_CONFIG_H */