aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-12-08 05:30:15 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-06-03 11:00:39 +0800
commitae21bb5e661666159f212d008e0bacd850ec2cab (patch)
treed1813e55f36d9629878950535b3636391f39218e /e-util
parenta1be1eaa01f5f7cb317f868121dcf26e487ef25a (diff)
downloadgsoc2013-evolution-ae21bb5e661666159f212d008e0bacd850ec2cab.tar
gsoc2013-evolution-ae21bb5e661666159f212d008e0bacd850ec2cab.tar.gz
gsoc2013-evolution-ae21bb5e661666159f212d008e0bacd850ec2cab.tar.bz2
gsoc2013-evolution-ae21bb5e661666159f212d008e0bacd850ec2cab.tar.lz
gsoc2013-evolution-ae21bb5e661666159f212d008e0bacd850ec2cab.tar.xz
gsoc2013-evolution-ae21bb5e661666159f212d008e0bacd850ec2cab.tar.zst
gsoc2013-evolution-ae21bb5e661666159f212d008e0bacd850ec2cab.zip
Adapt libeutil to the new ESource API.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/Makefile.am4
-rw-r--r--e-util/e-plugin-util.c497
-rw-r--r--e-util/e-plugin-util.h45
-rw-r--r--e-util/e-source-util.c187
-rw-r--r--e-util/e-source-util.h42
-rw-r--r--e-util/e-util.c46
-rw-r--r--e-util/e-util.h10
7 files changed, 244 insertions, 587 deletions
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index 63fce88fbe..0c7f7b3250 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -38,10 +38,10 @@ eutilinclude_HEADERS = \
e-print.h \
e-plugin.h \
e-plugin-ui.h \
- e-plugin-util.h \
e-selection.h \
e-sorter.h \
e-sorter-array.h \
+ e-source-util.h \
e-stock-request.h \
e-text-event-processor-emacs-like.h \
e-text-event-processor-types.h \
@@ -102,11 +102,11 @@ libeutil_la_SOURCES = \
e-poolv.c \
e-plugin.c \
e-plugin-ui.c \
- e-plugin-util.c \
e-print.c \
e-selection.c \
e-sorter.c \
e-sorter-array.c \
+ e-source-util.c \
e-stock-request.c \
e-text-event-processor-emacs-like.c \
e-text-event-processor.c \
diff --git a/e-util/e-plugin-util.c b/e-util/e-plugin-util.c
deleted file mode 100644
index 7fd343d4b1..0000000000
--- a/e-util/e-plugin-util.c
+++ /dev/null
@@ -1,497 +0,0 @@
-/*
- * 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/>
- *
- *
- * Copyright (C) 1999-2010 Novell, Inc. (www.novell.com)
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-#include <libsoup/soup.h>
-#include <libedataserver/e-source.h>
-#include <string.h>
-
-#include "e-plugin-util.h"
-
-/* name of a property on a widget with corresponding property name for an ESource */
-#define EPU_SP_NAME "e-source-property-name"
-
-#define EPU_CHECK_TRUE "epu-check-true-value"
-#define EPU_CHECK_FALSE "epu-check-false-value"
-
-static gboolean
-epu_is_uri_proto (const gchar *uri,
- const gchar *protocol)
-{
- gboolean res;
-
- g_return_val_if_fail (uri != NULL, FALSE);
- g_return_val_if_fail (protocol != NULL, FALSE);
-
- res = uri && g_ascii_strncasecmp (uri, protocol, strlen (protocol)) == 0;
-
- if (res)
- res = strchr (protocol, ':') != NULL || uri[strlen (protocol)] == ':';
-
- return res;
-}
-
-/**
- * e_plugin_util_is_source_proto:
- * @source: #ESource object
- * @protocol: protocol to check on, like "http", "https", ...
- *
- * Returns whether given source's uri is of the given protocol.
- *
- * Returns: whether given source's uri is of the given protocol.
- **/
-gboolean
-e_plugin_util_is_source_proto (ESource *source,
- const gchar *protocol)
-{
- gchar *uri;
- gboolean res;
-
- g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
- g_return_val_if_fail (protocol != NULL, FALSE);
-
- uri = e_source_get_uri (source);
- res = epu_is_uri_proto (uri, protocol);
- g_free (uri);
-
- return res;
-}
-
-/**
- * e_plugin_util_is_group_proto:
- * @group: #ESourceGroup object
- * @protocol: protocol to check on, like "http", "https", ...
- *
- * Returns whether given groups' base uri is of the given protocol.
- *
- * Returns: whether given groups' base uri is of the given protocol.
- **/
-gboolean
-e_plugin_util_is_group_proto (ESourceGroup *group,
- const gchar *protocol)
-{
- g_return_val_if_fail (E_IS_SOURCE_GROUP (group), FALSE);
- g_return_val_if_fail (protocol != NULL, FALSE);
-
- return epu_is_uri_proto (e_source_group_peek_base_uri (group), protocol);
-}
-
-/**
- * e_plugin_util_replace_at_sign:
- * @str: string to work with
- *
- * Replaces all '@' with '%40' in @str.
- *
- * Returns: a newly-allocated string
- **/
-gchar *
-e_plugin_util_replace_at_sign (const gchar *str)
-{
- gchar *res, *at;
-
- if (!str)
- return NULL;
-
- res = g_strdup (str);
- while (at = strchr (res, '@'), at) {
- gchar *tmp = g_malloc0 (sizeof (gchar) * (1 + strlen (res) + 2));
-
- strncpy (tmp, res, at - res);
- strcat (tmp, "%40");
- strcat (tmp, at + 1);
-
- g_free (res);
- res = tmp;
- }
-
- return res;
-}
-
-/**
- * e_plugin_util_uri_no_proto:
- * @uri: #SoupURI object
- *
- * Returns uri encoded as string, without protocol part.
- * Returned pointer should be freed with g_free.
- *
- * Returns: uri encoded as string, without protocol part.
- **/
-gchar *
-e_plugin_util_uri_no_proto (SoupURI *uri)
-{
- gchar *full_uri, *uri_noproto;
- const gchar *tmp;
-
- g_return_val_if_fail (uri != NULL, NULL);
-
- full_uri = soup_uri_to_string (uri, FALSE);
- g_return_val_if_fail (full_uri != NULL, NULL);
-
- tmp = strstr (full_uri, "://");
- if (tmp && tmp < strchr (full_uri, '/')) {
- uri_noproto = g_strdup (tmp + 3);
- } else {
- uri_noproto = full_uri;
- full_uri = NULL;
- }
-
- g_free (full_uri);
-
- return uri_noproto;
-}
-
-static void
-epu_update_source_property (ESource *source,
- GObject *object,
- const gchar *value)
-{
- const gchar *property_name;
-
- g_return_if_fail (E_IS_SOURCE (source));
- g_return_if_fail (G_IS_OBJECT (object));
-
- property_name = g_object_get_data (object, EPU_SP_NAME);
- g_return_if_fail (property_name != NULL);
-
- e_source_set_property (source, property_name, value);
-}
-
-static void
-epu_entry_changed_cb (GObject *entry,
- ESource *source)
-{
- g_return_if_fail (GTK_IS_ENTRY (entry));
-
- epu_update_source_property (source, entry, gtk_entry_get_text (GTK_ENTRY (entry)));
-}
-
-static void
-epu_check_toggled_cb (GObject *button,
- ESource *source)
-{
- const gchar *true_value, *false_value;
-
- g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
-
- true_value = g_object_get_data (button, EPU_CHECK_TRUE);
- false_value = g_object_get_data (button, EPU_CHECK_FALSE);
-
- epu_update_source_property (source, button, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) ? true_value : false_value);
-}
-
-/**
- * e_plugin_util_add_entry:
- * @parent: two-columns #GtkTable or #GtkContainer, where to add new entry
- * @label: label for the entry; can be NULL for no label
- * @source: #ESource object to which tight the entry change; can be NULL for no property binding
- * @source_property: source's property name to use for a value; can be NULL for no property binding
- *
- * Adds a #GtkEntry to the table at the last row or to the container, with a given label.
- * The entry will be always at the second column of the table.
- * Value of an entry will be prefilled with a property value of the given
- * source, and the source will be updated on any change of the entry automatically.
- * Entry is shown by default.
- *
- * Returns: pointer to newly added #GtkEntry
- **/
-GtkWidget *
-e_plugin_util_add_entry (GtkWidget *parent,
- const gchar *label,
- ESource *source,
- const gchar *source_property)
-{
- GtkWidget *entry, *lbl = NULL;
- const gchar *value;
- gint row = -1;
-
- g_return_val_if_fail (parent != NULL, NULL);
- g_return_val_if_fail (GTK_IS_TABLE (parent) || GTK_IS_CONTAINER (parent), NULL);
-
- if (source || source_property) {
- g_return_val_if_fail (E_IS_SOURCE (source), NULL);
- g_return_val_if_fail (source_property != NULL, NULL);
- g_return_val_if_fail (*source_property != 0, NULL);
- }
-
- if (GTK_IS_TABLE (parent))
- g_object_get (parent, "n-rows", &row, NULL);
-
- if (label) {
- lbl = gtk_label_new_with_mnemonic (label);
- gtk_widget_show (lbl);
- gtk_misc_set_alignment (GTK_MISC (lbl), 0.0, 0.5);
- if (row != -1)
- gtk_table_attach (GTK_TABLE (parent), lbl, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);
- else
- gtk_container_add (GTK_CONTAINER (parent), lbl);
- }
-
- if (source)
- value = e_source_get_property (source, source_property);
- else
- value = NULL;
-
- entry = gtk_entry_new ();
- gtk_widget_show (entry);
- gtk_entry_set_text (GTK_ENTRY (entry), value ? value : "");
- if (row != -1)
- gtk_table_attach (GTK_TABLE (parent), entry, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
- else
- gtk_container_add (GTK_CONTAINER (parent), entry);
-
- if (lbl)
- gtk_label_set_mnemonic_widget (GTK_LABEL (lbl), entry);
-
- if (source) {
- g_object_set_data_full (G_OBJECT (entry), EPU_SP_NAME, g_strdup (source_property), g_free);
- g_signal_connect (
- entry, "changed",
- G_CALLBACK (epu_entry_changed_cb), source);
- }
-
- return entry;
-}
-
-/**
- * e_plugin_util_add_check:
- * @parent: either two-columns #GtkTable or #GtkContainer where to add new check box; or NULL to just create it
- * @label: label for the check; cannot be NULL
- * @source: #ESource object to which tight the check change; can be NULL for no property binding
- * @source_property: source's property name to use for a value; can be NULL for no property binding
- * @true_value: what value use for a checked state in a source
- * @false_value: what value use for an unchecked state in a source
- *
- * Adds a #GtkCheckButton to the parent (if provided) at the last row, with a given label.
- * The check will be always at the second column of the table.
- * Value of a check will be prefilled with a property value of the given
- * source, and the source will be updated on any change of the check automatically.
- * Check is shown by default.
- *
- * Returns: pointer to newly added #GtkCheckButton
- **/
-GtkWidget *
-e_plugin_util_add_check (GtkWidget *parent,
- const gchar *label,
- ESource *source,
- const gchar *source_property,
- const gchar *true_value,
- const gchar *false_value)
-{
- GtkWidget *check;
- const gchar *value;
- guint row;
-
- g_return_val_if_fail (parent == NULL || GTK_IS_TABLE (parent) || GTK_IS_CONTAINER (parent), NULL);
- g_return_val_if_fail (label != NULL, NULL);
-
- if (source || source_property) {
- g_return_val_if_fail (source != NULL, NULL);
- g_return_val_if_fail (E_IS_SOURCE (source), NULL);
- g_return_val_if_fail (source_property != NULL, NULL);
- g_return_val_if_fail (*source_property != 0, NULL);
- }
-
- if (source)
- value = e_source_get_property (source, source_property);
- else
- value = NULL;
-
- check = gtk_check_button_new_with_mnemonic (label);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
- value && (value == true_value ||
- (true_value && g_str_equal (value, true_value)) ||
- (!source && g_str_equal (value, "1"))));
- gtk_widget_show (check);
-
- if (parent && GTK_IS_TABLE (parent)) {
- g_object_get (parent, "n-rows", &row, NULL);
-
- gtk_table_attach (GTK_TABLE (parent), check, 1, 2, row , row + 1, GTK_FILL, 0, 0, 0);
- } else if (parent) {
- gtk_container_add (GTK_CONTAINER (parent), check);
- }
-
- if (source) {
- g_object_set_data_full (G_OBJECT (check), EPU_SP_NAME, g_strdup (source_property), g_free);
- g_object_set_data_full (G_OBJECT (check), EPU_CHECK_TRUE, g_strdup (true_value), g_free);
- g_object_set_data_full (G_OBJECT (check), EPU_CHECK_FALSE, g_strdup (false_value), g_free);
- g_signal_connect (
- check, "toggled",
- G_CALLBACK (epu_check_toggled_cb), source);
- }
-
- return check;
-}
-
-static void
-epu_update_refresh_value (GtkWidget *spin,
- GtkWidget *combobox,
- ESource *source)
-{
- gchar *value;
- gint setting = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin));
- switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combobox))) {
- case 0:
- /* minutes */
- break;
- case 1:
- /* hours */
- setting *= 60;
- break;
- case 2:
- /* days */
- setting *= 1440;
- break;
- case 3:
- /* weeks */
- setting *= 10080;
- break;
- default:
- g_warning ("%s: Time unit out of range", G_STRFUNC);
- break;
- }
-
- value = g_strdup_printf ("%d", setting);
- epu_update_source_property (source, G_OBJECT (spin), value);
- g_free (value);
-}
-
-static void
-epu_refresh_spin_changed_cb (GtkWidget *spin,
- ESource *source)
-{
- g_return_if_fail (spin != NULL);
- g_return_if_fail (GTK_IS_SPIN_BUTTON (spin));
-
- epu_update_refresh_value (spin, g_object_get_data (G_OBJECT (spin), "refresh-combo"), source);
-}
-
-static void
-epu_refresh_combo_changed_cb (GtkWidget *combobox,
- ESource *source)
-{
- g_return_if_fail (combobox != NULL);
- g_return_if_fail (GTK_IS_COMBO_BOX (combobox));
-
- epu_update_refresh_value (g_object_get_data (G_OBJECT (combobox), "refresh-spin"), combobox, source);
-}
-
-/**
- * e_plugin_util_add_refresh:
- * @parent: two-columns #GtkTable where to add new "refresh" setup widgets or NULL to just create an hbox
- * @label: label for the widgets; can be NULL, but for parent == NULL is ignored
- * @source: #ESource object to which tight the refresh change; cannot be NULL
- * @source_property: source's property name to use for a value; cannot be NULL
- *
- * Adds widgets to setup Refresh interval. The stored value is in minutes.
- * Returns pointer to an HBox, which contains two widgets, spin and a combo box.
- * Both can be accessed by g_object_get_data with a name "refresh-spin" and "refresh-combo".
- *
- * Returns: a new refresh control widget
- **/
-GtkWidget *
-e_plugin_util_add_refresh (GtkWidget *parent,
- const gchar *label,
- ESource *source,
- const gchar *source_property)
-{
- GtkWidget *lbl = NULL, *hbox, *spin, *combo;
- const gchar *value;
- gint row = -1, value_num, item_num = 0;
-
- g_return_val_if_fail (parent == NULL || GTK_IS_TABLE (parent), NULL);
- g_return_val_if_fail (E_IS_SOURCE (source), NULL);
- g_return_val_if_fail (source_property != NULL, NULL);
- g_return_val_if_fail (*source_property != 0, NULL);
-
- if (parent)
- g_object_get (parent, "n-rows", &row, NULL);
-
- value = e_source_get_property (source, source_property);
- if (!value) {
- value = "30";
- e_source_set_property (source, source_property, value);
- }
-
- if (label && parent) {
- lbl = gtk_label_new_with_mnemonic (label);
- gtk_widget_show (lbl);
- gtk_misc_set_alignment (GTK_MISC (lbl), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (parent), lbl, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);
- }
-
- hbox = gtk_hbox_new (FALSE, 6);
- gtk_widget_show (hbox);
-
- spin = gtk_spin_button_new_with_range (0, 100, 1);
- gtk_widget_show (spin);
- gtk_box_pack_start (GTK_BOX (hbox), spin, FALSE, TRUE, 0);
-
- combo = gtk_combo_box_text_new ();
- gtk_widget_show (combo);
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("minutes"));
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("hours"));
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("days"));
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("weeks"));
- gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, TRUE, 0);
-
- value_num = value ? atoi (value) : 30;
-
- if (value_num && !(value_num % 10080)) {
- /* weeks */
- item_num = 3;
- value_num /= 10080;
- } else if (value_num && !(value_num % 1440)) {
- /* days */
- item_num = 2;
- value_num /= 1440;
- } else if (value_num && !(value_num % 60)) {
- /* hours */
- item_num = 1;
- value_num /= 60;
- }
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo), item_num);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), value_num);
-
- if (lbl)
- gtk_label_set_mnemonic_widget (GTK_LABEL (lbl), spin);
-
- g_object_set_data_full (G_OBJECT (spin), EPU_SP_NAME, g_strdup (source_property), g_free);
-
- g_object_set_data (G_OBJECT (combo), "refresh-spin", spin);
- g_object_set_data (G_OBJECT (spin), "refresh-combo", combo);
- g_object_set_data (G_OBJECT (hbox), "refresh-spin", spin);
- g_object_set_data (G_OBJECT (hbox), "refresh-combo", combo);
- g_signal_connect (
- combo, "changed",
- G_CALLBACK (epu_refresh_combo_changed_cb), source);
- g_signal_connect (
- spin, "value-changed",
- G_CALLBACK (epu_refresh_spin_changed_cb), source);
-
- if (parent)
- gtk_table_attach (GTK_TABLE (parent), hbox, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
-
- return hbox;
-}
diff --git a/e-util/e-plugin-util.h b/e-util/e-plugin-util.h
deleted file mode 100644
index de1b0b3487..0000000000
--- a/e-util/e-plugin-util.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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/>
- *
- *
- * Authors:
- *
- * Copyright (C) 1999-2010 Novell, Inc. (www.novell.com)
- *
- */
-
-#ifndef _E_PLUGIN_UTIL_H
-#define _E_PLUGIN_UTIL_H
-
-#include <gtk/gtk.h>
-
-#include <libsoup/soup.h>
-
-#include <libedataserver/e-source.h>
-#include <libedataserver/e-source-group.h>
-
-gboolean e_plugin_util_is_source_proto (ESource *source, const gchar *protocol);
-gboolean e_plugin_util_is_group_proto (ESourceGroup *group, const gchar *protocol);
-
-gchar *e_plugin_util_replace_at_sign (const gchar *str);
-gchar *e_plugin_util_uri_no_proto (SoupURI *uri);
-
-/* common widgets used in plugin setup */
-GtkWidget *e_plugin_util_add_entry (GtkWidget *parent, const gchar *label, ESource *source, const gchar *source_property);
-GtkWidget *e_plugin_util_add_check (GtkWidget *parent, const gchar *label, ESource *source, const gchar *source_property, const gchar *true_value, const gchar *false_value);
-
-/* multipack widgets */
-GtkWidget *e_plugin_util_add_refresh (GtkWidget *parent, const gchar *label, ESource *source, const gchar *source_property);
-
-#endif /* _E_PLUGIN_UTIL_H */
diff --git a/e-util/e-source-util.c b/e-util/e-source-util.c
new file mode 100644
index 0000000000..61b7897d32
--- /dev/null
+++ b/e-util/e-source-util.c
@@ -0,0 +1,187 @@
+/*
+ * e-source-util.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-util.h"
+
+typedef struct _AsyncContext AsyncContext;
+
+struct _AsyncContext {
+ EActivity *activity;
+ ESource *source;
+};
+
+static void
+async_context_free (AsyncContext *context)
+{
+ if (context->activity != NULL)
+ g_object_unref (context->activity);
+
+ if (context->source != NULL)
+ g_object_unref (context->source);
+
+ g_slice_free (AsyncContext, context);
+}
+
+static void
+source_util_remove_cb (ESource *source,
+ GAsyncResult *result,
+ AsyncContext *context)
+{
+ EActivity *activity;
+ EAlertSink *alert_sink;
+ GError *error = NULL;
+
+ activity = context->activity;
+ alert_sink = e_activity_get_alert_sink (activity);
+
+ e_source_remove_finish (source, result, &error);
+
+ if (e_activity_handle_cancellation (activity, error)) {
+ g_error_free (error);
+
+ } else if (error != NULL) {
+ e_alert_submit (
+ alert_sink,
+ "source:remove-source-fail",
+ e_source_get_display_name (context->source),
+ error->message, NULL);
+ g_error_free (error);
+
+ } else {
+ e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
+ }
+
+ async_context_free (context);
+}
+
+/**
+ * e_source_util_remove:
+ * @source: the #ESource to be removed
+ * @alert_sink: an #EAlertSink
+ *
+ * Requests the D-Bus service to delete the key files for @source and all of
+ * its descendants and broadcast their removal to all clients. If an error
+ * occurs, an #EAlert will be posted to @alert_sink.
+ *
+ * This function does not block. The returned #EActivity can either be
+ * ignored or passed to something that can display activity status to the
+ * user, such as e_shell_backend_add_activity().
+ *
+ * Returns: an #EActivity to track the operation
+ **/
+EActivity *
+e_source_util_remove (ESource *source,
+ EAlertSink *alert_sink)
+{
+ AsyncContext *context;
+ GCancellable *cancellable;
+
+ g_return_val_if_fail (E_IS_SOURCE (source), NULL);
+ g_return_val_if_fail (E_IS_ALERT_SINK (alert_sink), NULL);
+
+ cancellable = g_cancellable_new ();
+
+ context = g_slice_new0 (AsyncContext);
+ context->activity = e_activity_new ();
+ context->source = g_object_ref (source);
+
+ e_activity_set_alert_sink (context->activity, alert_sink);
+ e_activity_set_cancellable (context->activity, cancellable);
+
+ e_source_remove (
+ source, cancellable, (GAsyncReadyCallback)
+ source_util_remove_cb, context);
+
+ g_object_unref (cancellable);
+
+ return context->activity;
+}
+
+static void
+source_util_write_cb (ESource *source,
+ GAsyncResult *result,
+ AsyncContext *context)
+{
+ EActivity *activity;
+ EAlertSink *alert_sink;
+ GError *error = NULL;
+
+ activity = context->activity;
+ alert_sink = e_activity_get_alert_sink (activity);
+
+ e_source_write_finish (source, result, &error);
+
+ if (e_activity_handle_cancellation (activity, error)) {
+ g_error_free (error);
+
+ } else if (error != NULL) {
+ e_alert_submit (
+ alert_sink,
+ "source:submit-data-fail",
+ error->message, NULL);
+ g_error_free (error);
+
+ } else {
+ e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
+ }
+
+ async_context_free (context);
+}
+
+/**
+ * e_source_util_write:
+ * @source: an #ESource
+ * @alert_sink: an #EAlertSink
+ *
+ * Submits the current contents of @source to the D-Bus service to be
+ * written to disk and broadcast to other clients. If an error occurs,
+ * an #EAlert will be posted to @alert_sink.
+ *
+ * This function does not block. The returned #EActivity can either be
+ * ignored or passed to something that can display activity status to the
+ * user, such as e_shell_backend_add_activity().
+ *
+ * Returns: an #EActivity to track the operation
+ **/
+EActivity *
+e_source_util_write (ESource *source,
+ EAlertSink *alert_sink)
+{
+ AsyncContext *context;
+ GCancellable *cancellable;
+
+ g_return_val_if_fail (E_IS_SOURCE (source), NULL);
+ g_return_val_if_fail (E_IS_ALERT_SINK (alert_sink), NULL);
+
+ cancellable = g_cancellable_new ();
+
+ context = g_slice_new0 (AsyncContext);
+ context->activity = e_activity_new ();
+
+ e_activity_set_alert_sink (context->activity, alert_sink);
+ e_activity_set_cancellable (context->activity, cancellable);
+
+ e_source_write (
+ source, cancellable, (GAsyncReadyCallback)
+ source_util_write_cb, context);
+
+ g_object_unref (cancellable);
+
+ return context->activity;
+}
+
diff --git a/e-util/e-source-util.h b/e-util/e-source-util.h
new file mode 100644
index 0000000000..589e91b13c
--- /dev/null
+++ b/e-util/e-source-util.h
@@ -0,0 +1,42 @@
+/*
+ * e-source-util.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/>
+ *
+ */
+
+/* These functions combine asynchronous ESource and ESourceRegistry methods
+ * with Evolution's EActivity and EAlert facilities to offer an easy-to-use,
+ * "fire-and-forget" API for ESource operations. Use these in situations
+ * where it's sufficient to just display an error message if the operation
+ * fails, and you don't need to operate on the result. */
+
+#ifndef E_SOURCE_UTIL_H
+#define E_SOURCE_UTIL_H
+
+#include <libedataserver/e-source.h>
+
+#include <e-util/e-activity.h>
+#include <libevolution-utils/e-alert-sink.h>
+
+G_BEGIN_DECLS
+
+EActivity * e_source_util_remove (ESource *source,
+ EAlertSink *alert_sink);
+EActivity * e_source_util_write (ESource *source,
+ EAlertSink *alert_sink);
+
+G_END_DECLS
+
+#endif /* E_SOURCE_UTIL_H */
diff --git a/e-util/e-util.c b/e-util/e-util.c
index 715735110c..38c1b85244 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -53,7 +53,6 @@
#include <camel/camel.h>
#include <libedataserver/e-data-server-util.h>
#include <libedataserver/e-categories.h>
-#include <libedataserver/e-source-list.h>
#include "filter/e-filter-option.h"
@@ -1334,31 +1333,6 @@ e_util_get_searchable_categories (void)
}
/**
- * e_util_set_source_combo_box_list:
- * @source_combo_box: an #ESourceComboBox
- * @source_gconf_path: GConf path with sources to use in an #ESourceList
- *
- * Sets an #ESourceList of a given GConf path to an #ESourceComboBox.
- **/
-void
-e_util_set_source_combo_box_list (GtkWidget *source_combo_box,
- const gchar *source_gconf_path)
-{
- ESourceList *source_list;
- GConfClient *gconf_client;
-
- g_return_if_fail (source_combo_box != NULL);
- g_return_if_fail (source_gconf_path != NULL);
-
- gconf_client = gconf_client_get_default ();
- source_list = e_source_list_new_for_gconf (
- gconf_client, source_gconf_path);
- g_object_set (source_combo_box, "source-list", source_list, NULL);
- g_object_unref (source_list);
- g_object_unref (gconf_client);
-}
-
-/**
* e_binding_transform_color_to_string:
* @binding: a #GBinding
* @source_value: a #GValue of type #GDK_TYPE_COLOR
@@ -1435,7 +1409,7 @@ e_binding_transform_string_to_color (GBinding *binding,
* @binding: a #GBinding
* @source_value: a #GValue of type #E_TYPE_SOURCE
* @target_value: a #GValue of type #G_TYPE_STRING
- * @source_list: an #ESourceList
+ * @registry: an #ESourceRegistry
*
* Transforms an #ESource object to its UID string.
*
@@ -1445,14 +1419,14 @@ gboolean
e_binding_transform_source_to_uid (GBinding *binding,
const GValue *source_value,
GValue *target_value,
- ESourceList *source_list)
+ ESourceRegistry *registry)
{
ESource *source;
const gchar *string;
gboolean success = FALSE;
g_return_val_if_fail (G_IS_BINDING (binding), FALSE);
- g_return_val_if_fail (E_IS_SOURCE_LIST (source_list), FALSE);
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
source = g_value_get_object (source_value);
if (E_IS_SOURCE (source)) {
@@ -1469,34 +1443,34 @@ e_binding_transform_source_to_uid (GBinding *binding,
* @binding: a #GBinding
* @source_value: a #GValue of type #G_TYPE_STRING
* @target_value: a #GValue of type #E_TYPE_SOURCe
- * @source_list: an #ESourceList
+ * @registry: an #ESourceRegistry
*
* Transforms an #ESource UID string to the corresponding #ESource object
- * in @source_list.
+ * in @registry.
*
- * Returns: %TRUE if @source_list had an #ESource object with a matching
+ * Returns: %TRUE if @registry had an #ESource object with a matching
* UID string
**/
gboolean
e_binding_transform_uid_to_source (GBinding *binding,
const GValue *source_value,
GValue *target_value,
- ESourceList *source_list)
+ ESourceRegistry *registry)
{
ESource *source;
const gchar *string;
gboolean success = FALSE;
g_return_val_if_fail (G_IS_BINDING (binding), FALSE);
- g_return_val_if_fail (E_IS_SOURCE_LIST (source_list), FALSE);
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
string = g_value_get_string (source_value);
if (string == NULL || *string == '\0')
return FALSE;
- source = e_source_list_peek_source_by_uid (source_list, string);
+ source = e_source_registry_ref_source (registry, string);
if (source != NULL) {
- g_value_set_object (target_value, source);
+ g_value_take_object (target_value, source);
success = TRUE;
}
diff --git a/e-util/e-util.h b/e-util/e-util.h
index bd9ad2dc05..af2232489e 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -32,7 +32,7 @@
#include <e-util/e-marshal.h>
#include <e-util/e-util-enums.h>
-#include <libedataserver/e-source-list.h>
+#include <libedataserver/e-source-registry.h>
/* e_get_user_data_dir() used to live here, so #include its new home
* for backward-compatibility (not that we really care about that). */
@@ -131,10 +131,6 @@ GSList * e_util_get_category_filter_options
(void);
GList * e_util_get_searchable_categories (void);
-void e_util_set_source_combo_box_list
- (GtkWidget *source_combo_box,
- const gchar *source_gconf_path);
-
/* Useful GBinding transform functions */
gboolean e_binding_transform_color_to_string
(GBinding *binding,
@@ -150,12 +146,12 @@ gboolean e_binding_transform_source_to_uid
(GBinding *binding,
const GValue *source_value,
GValue *target_value,
- ESourceList *source_list);
+ ESourceRegistry *registry);
gboolean e_binding_transform_uid_to_source
(GBinding *binding,
const GValue *source_value,
GValue *target_value,
- ESourceList *source_list);
+ ESourceRegistry *registry);
G_END_DECLS