[evolution] Add EProxyLinkSelector.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Add EProxyLinkSelector.
- Date: Fri, 25 Oct 2013 17:28:01 +0000 (UTC)
commit 559d4cf8bf8f309b33ae3ff426ebb4f2c6015c79
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Oct 18 19:43:04 2013 -0400
Add EProxyLinkSelector.
.../evolution-util/evolution-util-docs.sgml | 1 +
.../evolution-util/evolution-util-sections.txt | 20 ++
doc/reference/evolution-util/evolution-util.types | 1 +
e-util/Makefile.am | 2 +
e-util/e-proxy-link-selector.c | 290 ++++++++++++++++++++
e-util/e-proxy-link-selector.h | 73 +++++
e-util/e-util.h | 1 +
7 files changed, 388 insertions(+), 0 deletions(-)
---
diff --git a/doc/reference/evolution-util/evolution-util-docs.sgml
b/doc/reference/evolution-util/evolution-util-docs.sgml
index ff09f82..9075c3a 100644
--- a/doc/reference/evolution-util/evolution-util-docs.sgml
+++ b/doc/reference/evolution-util/evolution-util-docs.sgml
@@ -249,6 +249,7 @@
<xi:include href="xml/e-printable.xml"/>
<xi:include href="xml/e-proxy-combo-box.xml"/>
<xi:include href="xml/e-proxy-editor.xml"/>
+ <xi:include href="xml/e-proxy-link-selector.xml"/>
<xi:include href="xml/e-proxy-selector.xml"/>
<xi:include href="xml/e-search-bar.xml"/>
<xi:include href="xml/e-selectable.xml"/>
diff --git a/doc/reference/evolution-util/evolution-util-sections.txt
b/doc/reference/evolution-util/evolution-util-sections.txt
index de416f1..30e92b6 100644
--- a/doc/reference/evolution-util/evolution-util-sections.txt
+++ b/doc/reference/evolution-util/evolution-util-sections.txt
@@ -2795,6 +2795,26 @@ EProxyEditorPrivate
</SECTION>
<SECTION>
+<FILE>e-proxy-link-selector</FILE>
+<TITLE>EProxyLinkSelector</TITLE>
+EProxyLinkSelector
+e_proxy_link_selector_new
+e_proxy_link_selector_ref_target_source
+e_proxy_link_selector_set_target_source
+<SUBSECTION Standard>
+E_PROXY_LINK_SELECTOR
+E_IS_PROXY_LINK_SELECTOR
+E_TYPE_PROXY_LINK_SELECTOR
+E_PROXY_LINK_SELECTOR_CLASS
+E_IS_PROXY_LINK_SELECTOR_CLASS
+E_PROXY_LINK_SELECTOR_GET_CLASS
+EProxyLinkSelectorClass
+e_proxy_link_selector_get_type
+<SUBSECTION Private>
+EProxyLinkSelectorPrivate
+</SECTION>
+
+<SECTION>
<FILE>e-proxy-selector</FILE>
<TITLE>EProxySelector</TITLE>
EProxySelector
diff --git a/doc/reference/evolution-util/evolution-util.types
b/doc/reference/evolution-util/evolution-util.types
index 1116095..778e3b8 100644
--- a/doc/reference/evolution-util/evolution-util.types
+++ b/doc/reference/evolution-util/evolution-util.types
@@ -103,6 +103,7 @@ e_preview_pane_get_type
e_printable_get_type
e_proxy_combo_box_get_type
e_proxy_editor_get_type
+e_proxy_link_selector_get_type
e_proxy_selector_get_type
e_reflow_get_type
e_reflow_model_get_type
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index b54d87f..d3c5800 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -226,6 +226,7 @@ evolution_util_include_HEADERS = \
e-printable.h \
e-proxy-combo-box.h \
e-proxy-editor.h \
+ e-proxy-link-selector.h \
e-proxy-selector.h \
e-reflow-model.h \
e-reflow.h \
@@ -467,6 +468,7 @@ libevolution_util_la_SOURCES = \
e-printable.c \
e-proxy-combo-box.c \
e-proxy-editor.c \
+ e-proxy-link-selector.c \
e-proxy-selector.c \
e-reflow-model.c \
e-reflow.c \
diff --git a/e-util/e-proxy-link-selector.c b/e-util/e-proxy-link-selector.c
new file mode 100644
index 0000000..bb72142
--- /dev/null
+++ b/e-util/e-proxy-link-selector.c
@@ -0,0 +1,290 @@
+/*
+ * e-proxy-link-selector.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-proxy-link-selector.h"
+
+#define E_PROXY_LINK_SELECTOR_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_PROXY_LINK_SELECTOR, EProxyLinkSelectorPrivate))
+
+struct _EProxyLinkSelectorPrivate {
+ ESource *target_source;
+ ESource *fallback_source;
+};
+
+enum {
+ PROP_0,
+ PROP_TARGET_SOURCE
+};
+
+G_DEFINE_TYPE (
+ EProxyLinkSelector,
+ e_proxy_link_selector,
+ E_TYPE_SOURCE_SELECTOR)
+
+static gboolean
+proxy_link_selector_target_source_to_show_toggles (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
+{
+ ESource *target_source;
+ ESource *fallback_source;
+ gboolean show_toggles;
+
+ fallback_source = E_SOURCE (user_data);
+ target_source = g_value_get_object (source_value);
+ show_toggles = !e_source_equal (target_source, fallback_source);
+ g_value_set_boolean (target_value, show_toggles);
+
+ return TRUE;
+}
+
+static void
+proxy_link_selector_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_TARGET_SOURCE:
+ e_proxy_link_selector_set_target_source (
+ E_PROXY_LINK_SELECTOR (object),
+ g_value_get_object (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+proxy_link_selector_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_TARGET_SOURCE:
+ g_value_take_object (
+ value,
+ e_proxy_link_selector_ref_target_source (
+ E_PROXY_LINK_SELECTOR (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+proxy_link_selector_dispose (GObject *object)
+{
+ EProxyLinkSelectorPrivate *priv;
+
+ priv = E_PROXY_LINK_SELECTOR_GET_PRIVATE (object);
+
+ g_clear_object (&priv->target_source);
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_proxy_link_selector_parent_class)->dispose (object);
+}
+
+static void
+proxy_link_selector_constructed (GObject *object)
+{
+ EProxyLinkSelectorPrivate *priv;
+ ESourceSelector *selector;
+ ESourceRegistry *registry;
+ ESource *builtin_proxy;
+
+ priv = E_PROXY_LINK_SELECTOR_GET_PRIVATE (object);
+
+ selector = E_SOURCE_SELECTOR (object);
+ registry = e_source_selector_get_registry (selector);
+
+ /* Set the target and fallback sources before chaining up. */
+
+ builtin_proxy = e_source_registry_ref_builtin_proxy (registry);
+ g_return_if_fail (builtin_proxy != NULL);
+
+ priv->target_source = g_object_ref (builtin_proxy);
+ priv->fallback_source = g_object_ref (builtin_proxy);
+
+ g_object_unref (builtin_proxy);
+
+ /* Hide toggle buttons when the target source is the same as
+ * the fallback source since toggling the buttons would have
+ * no effect in that particular case. */
+ g_object_bind_property_full (
+ selector, "target-source",
+ selector, "show-toggles",
+ G_BINDING_SYNC_CREATE,
+ proxy_link_selector_target_source_to_show_toggles,
+ NULL,
+ g_object_ref (priv->fallback_source),
+ (GDestroyNotify) g_object_unref);
+
+ /* Chain up to parent's constructed() method. */
+ G_OBJECT_CLASS (e_proxy_link_selector_parent_class)->
+ constructed (object);
+
+ /* This triggers a model rebuild, so chain up first. */
+ e_source_selector_set_show_icons (selector, TRUE);
+}
+
+static gboolean
+proxy_link_selector_get_source_selected (ESourceSelector *selector,
+ ESource *source)
+{
+ EProxyLinkSelector *link_selector;
+ ESourceAuthentication *extension;
+ const gchar *extension_name;
+ const gchar *target_uid;
+ gboolean selected = FALSE;
+ gchar *uid;
+
+ link_selector = E_PROXY_LINK_SELECTOR (selector);
+
+ /* Make sure this source has an Authentication extension. */
+ extension_name = e_source_selector_get_extension_name (selector);
+ if (!e_source_has_extension (source, extension_name))
+ return FALSE;
+
+ extension = e_source_get_extension (source, extension_name);
+ g_return_val_if_fail (E_IS_SOURCE_AUTHENTICATION (extension), FALSE);
+
+ uid = e_source_authentication_dup_proxy_uid (extension);
+ target_uid = e_source_get_uid (link_selector->priv->target_source);
+ selected = (g_strcmp0 (uid, target_uid) == 0);
+ g_free (uid);
+
+ return selected;
+}
+
+static void
+proxy_link_selector_set_source_selected (ESourceSelector *selector,
+ ESource *source,
+ gboolean selected)
+{
+ EProxyLinkSelector *link_selector;
+ ESourceAuthentication *extension;
+ ESource *target_source;
+ const gchar *extension_name;
+ const gchar *new_target_uid;
+ const gchar *old_target_uid;
+
+ link_selector = E_PROXY_LINK_SELECTOR (selector);
+
+ /* Make sure this source has an Authentication extension. */
+ extension_name = e_source_selector_get_extension_name (selector);
+ if (!e_source_has_extension (source, extension_name))
+ return;
+
+ extension = e_source_get_extension (source, extension_name);
+ g_return_if_fail (E_IS_SOURCE_AUTHENTICATION (extension));
+
+ if (selected)
+ target_source = link_selector->priv->target_source;
+ else
+ target_source = link_selector->priv->fallback_source;
+
+ new_target_uid = e_source_get_uid (target_source);
+ old_target_uid = e_source_authentication_get_proxy_uid (extension);
+
+ if (g_strcmp0 (new_target_uid, old_target_uid) != 0) {
+ e_source_authentication_set_proxy_uid (
+ extension, new_target_uid);
+ e_source_selector_queue_write (selector, source);
+ }
+}
+
+static void
+e_proxy_link_selector_class_init (EProxyLinkSelectorClass *class)
+{
+ GObjectClass *object_class;
+ ESourceSelectorClass *source_selector_class;
+
+ g_type_class_add_private (class, sizeof (EProxyLinkSelectorPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = proxy_link_selector_set_property;
+ object_class->get_property = proxy_link_selector_get_property;
+ object_class->dispose = proxy_link_selector_dispose;
+ object_class->constructed = proxy_link_selector_constructed;
+
+ source_selector_class = E_SOURCE_SELECTOR_CLASS (class);
+ source_selector_class->get_source_selected =
+ proxy_link_selector_get_source_selected;
+ source_selector_class->set_source_selected =
+ proxy_link_selector_set_source_selected;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_TARGET_SOURCE,
+ g_param_spec_object (
+ "target-source",
+ "Target Source",
+ "The data source to link to "
+ "when the checkbox is active",
+ E_TYPE_SOURCE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+e_proxy_link_selector_init (EProxyLinkSelector *selector)
+{
+ selector->priv = E_PROXY_LINK_SELECTOR_GET_PRIVATE (selector);
+}
+
+GtkWidget *
+e_proxy_link_selector_new (ESourceRegistry *registry)
+{
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
+
+ return g_object_new (
+ E_TYPE_PROXY_LINK_SELECTOR,
+ "extension-name", E_SOURCE_EXTENSION_AUTHENTICATION,
+ "registry", registry, NULL);
+}
+
+ESource *
+e_proxy_link_selector_ref_target_source (EProxyLinkSelector *selector)
+{
+ g_return_val_if_fail (E_IS_PROXY_LINK_SELECTOR (selector), NULL);
+
+ return g_object_ref (selector->priv->target_source);
+}
+
+void
+e_proxy_link_selector_set_target_source (EProxyLinkSelector *selector,
+ ESource *target_source)
+{
+ g_return_if_fail (E_IS_PROXY_LINK_SELECTOR (selector));
+ g_return_if_fail (E_IS_SOURCE (target_source));
+
+ if (target_source == selector->priv->target_source)
+ return;
+
+ g_clear_object (&selector->priv->target_source);
+ selector->priv->target_source = g_object_ref (target_source);
+
+ g_object_notify (G_OBJECT (selector), "target-source");
+
+ e_source_selector_update_all_rows (E_SOURCE_SELECTOR (selector));
+}
+
diff --git a/e-util/e-proxy-link-selector.h b/e-util/e-proxy-link-selector.h
new file mode 100644
index 0000000..a4facd1
--- /dev/null
+++ b/e-util/e-proxy-link-selector.h
@@ -0,0 +1,73 @@
+/*
+ * e-proxy-link-selector.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/>
+ *
+ */
+
+#if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
+#error "Only <e-util/e-util.h> should be included directly."
+#endif
+
+#ifndef E_PROXY_LINK_SELECTOR_H
+#define E_PROXY_LINK_SELECTOR_H
+
+#include <e-util/e-source-selector.h>
+
+/* Standard GObject macros */
+#define E_TYPE_PROXY_LINK_SELECTOR \
+ (e_proxy_link_selector_get_type ())
+#define E_PROXY_LINK_SELECTOR(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_PROXY_LINK_SELECTOR, EProxyLinkSelector))
+#define E_PROXY_LINK_SELECTOR_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_PROXY_LINK_SELECTOR, EProxyLinkSelectorClass))
+#define E_IS_PROXY_LINK_SELECTOR(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_PROXY_LINK_SELECTOR))
+#define E_IS_PROXY_LINK_SELECTOR_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_PROXY_LINK_SELECTOR))
+#define E_PROXY_LINK_SELECTOR_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_PROXY_LINK_SELECTOR, EProxyLinkSelectorClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EProxyLinkSelector EProxyLinkSelector;
+typedef struct _EProxyLinkSelectorClass EProxyLinkSelectorClass;
+typedef struct _EProxyLinkSelectorPrivate EProxyLinkSelectorPrivate;
+
+struct _EProxyLinkSelector {
+ ESourceSelector parent;
+ EProxyLinkSelectorPrivate *priv;
+};
+
+struct _EProxyLinkSelectorClass {
+ ESourceSelectorClass parent_class;
+};
+
+GType e_proxy_link_selector_get_type (void) G_GNUC_CONST;
+GtkWidget * e_proxy_link_selector_new (ESourceRegistry *registry);
+ESource * e_proxy_link_selector_ref_target_source
+ (EProxyLinkSelector *selector);
+void e_proxy_link_selector_set_target_source
+ (EProxyLinkSelector *selector,
+ ESource *target_source);
+
+G_END_DECLS
+
+#endif /* E_PROXY_LINK_SELECTOR_H */
+
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 793a051..494e410 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -145,6 +145,7 @@
#include <e-util/e-printable.h>
#include <e-util/e-proxy-combo-box.h>
#include <e-util/e-proxy-editor.h>
+#include <e-util/e-proxy-link-selector.h>
#include <e-util/e-proxy-selector.h>
#include <e-util/e-reflow-model.h>
#include <e-util/e-reflow.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]