[evolution/account-mgmt: 13/33] Adapt addressbook/tools to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/account-mgmt: 13/33] Adapt addressbook/tools to the new ESource API.
- Date: Wed, 2 Mar 2011 03:46:44 +0000 (UTC)
commit 601cd41ff141b3caf37fc0bd65680f0b35b59779
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Dec 8 00:17:41 2010 -0500
Adapt addressbook/tools to the new ESource API.
.../evolution-addressbook-export-list-cards.c | 34 +++++--
.../evolution-addressbook-export-list-folders.c | 99 +++++++++++---------
addressbook/tools/evolution-addressbook-export.c | 17 ++--
addressbook/tools/evolution-addressbook-export.h | 2 +-
4 files changed, 90 insertions(+), 62 deletions(-)
---
diff --git a/addressbook/tools/evolution-addressbook-export-list-cards.c b/addressbook/tools/evolution-addressbook-export-list-cards.c
index ea3eb7a..172c1ee 100644
--- a/addressbook/tools/evolution-addressbook-export-list-cards.c
+++ b/addressbook/tools/evolution-addressbook-export-list-cards.c
@@ -22,6 +22,7 @@
#include <config.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
@@ -32,6 +33,8 @@
#include <libebook/e-book.h>
#include <libebook/e-contact.h>
+#include <libebook/e-source-address-book.h>
+#include <libedataserver/e-source-registry.h>
#include "evolution-addressbook-export.h"
@@ -628,8 +631,8 @@ action_list_cards (GList *contacts, ActionContext * p_actctx)
length = g_list_length (contacts);
if (length <= 0) {
- g_warning ("Couldn't load addressbook correctly!!!! %s####", p_actctx->action_list_cards.addressbook_folder_uri ?
- p_actctx->action_list_cards.addressbook_folder_uri : "NULL");
+ g_warning ("Couldn't load addressbook correctly!!!! %s####", p_actctx->action_list_cards.addressbook_source_uid ?
+ p_actctx->action_list_cards.addressbook_source_uid : "NULL");
exit (-1);
}
@@ -760,20 +763,33 @@ set_pre_defined_field (GSList ** pre_defined_fields)
guint
action_list_cards_init (ActionContext * p_actctx)
{
+ ESourceRegistry *registry;
+ ESource *source;
EBook *book;
EBookQuery *query;
GList *contacts;
+ const gchar *uid;
- if (p_actctx->action_list_cards.addressbook_folder_uri != NULL) {
- book = e_book_new_from_uri (p_actctx->action_list_cards.addressbook_folder_uri, NULL);
- } else {
- book = e_book_new_default_addressbook (NULL);
- }
+ /* Register the "Address Book" extension. */
+ E_TYPE_SOURCE_ADDRESS_BOOK;
+
+ registry = e_source_registry_get_default ();
+
+ e_source_registry_load_sources (registry, NULL);
+
+ uid = p_actctx->action_list_cards.addressbook_source_uid;
+
+ if (uid != NULL)
+ source = e_source_registry_lookup_by_uid (registry, uid);
+ else
+ source = e_source_registry_get_default_address_book (registry);
+
+ book = e_book_new (source, NULL);
if (!book
|| !e_book_open (book, TRUE, NULL)) {
- g_warning ("Couldn't load addressbook %s", p_actctx->action_list_cards.addressbook_folder_uri ?
- p_actctx->action_list_cards.addressbook_folder_uri : "NULL");
+ g_warning ("Couldn't load addressbook %s", p_actctx->action_list_cards.addressbook_source_uid ?
+ p_actctx->action_list_cards.addressbook_source_uid : "NULL");
exit (-1);
}
diff --git a/addressbook/tools/evolution-addressbook-export-list-folders.c b/addressbook/tools/evolution-addressbook-export-list-folders.c
index 1f18686..832a581 100644
--- a/addressbook/tools/evolution-addressbook-export-list-folders.c
+++ b/addressbook/tools/evolution-addressbook-export-list-folders.c
@@ -22,26 +22,32 @@
*/
#include <config.h>
+#include <stdlib.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <libebook/e-book.h>
+#include <libebook/e-source-address-book.h>
+#include <libedataserver/e-source-registry.h>
#include "evolution-addressbook-export.h"
guint
-action_list_folders_init (ActionContext * p_actctx)
+action_list_folders_init (ActionContext *p_actctx)
{
- ESourceList *addressbooks = NULL;
- GSList *groups, *group;
+ ESourceRegistry *registry;
+ GList *list, *iter;
FILE *outputfile = NULL;
+ const gchar *extension_name;
- if (!e_book_get_addressbooks (&addressbooks, NULL)) {
- g_warning (_("Couldn't get list of address books"));
- exit (-1);
- }
+ /* Register the "Address Book" extension. */
+ E_TYPE_SOURCE_ADDRESS_BOOK;
+
+ registry = e_source_registry_get_default ();
+
+ e_source_registry_load_sources (registry, NULL);
if (p_actctx->action_list_folders.output_file != NULL) {
if (!(outputfile = g_fopen (p_actctx->action_list_folders.output_file, "w"))) {
@@ -50,47 +56,50 @@ action_list_folders_init (ActionContext * p_actctx)
}
}
- groups = e_source_list_peek_groups (addressbooks);
- for (group = groups; group; group = group->next) {
- ESourceGroup *g = group->data;
- GSList *sources, *source;
-
- sources = e_source_group_peek_sources (g);
- for (source = sources; source; source = source->next) {
- ESource *s = source->data;
- EBook *book;
- EBookQuery *query;
- GList *contacts;
- gchar *uri;
- const gchar *name;
-
- book = e_book_new (s, NULL);
- if (!book
- || !e_book_open (book, TRUE, NULL)) {
- g_warning (_("failed to open book"));
- continue;
- }
-
- query = e_book_query_any_field_contains ("");
- e_book_get_contacts (book, query, &contacts, NULL);
- e_book_query_unref (query);
-
- uri = e_source_get_uri (s);
- name = e_source_peek_name (s);
-
- if (outputfile)
- fprintf (outputfile, "\"%s\",\"%s\",%d\n", uri, name, g_list_length (contacts));
- else
- printf ("\"%s\",\"%s\",%d\n", uri, name, g_list_length (contacts));
-
- g_free (uri);
- g_list_foreach (contacts, (GFunc)g_object_unref, NULL);
- g_list_free (contacts);
-
- g_object_unref (book);
+ extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+ list = e_source_registry_list_sources (registry, extension_name);
+
+ for (iter = list; iter != NULL; iter = g_list_next (iter)) {
+ ESource *source;
+ EBook *book;
+ EBookQuery *query;
+ GList *contacts;
+ const gchar *display_name;
+ const gchar *uid;
+
+ source = E_SOURCE (iter->data);
+
+ book = e_book_new (source, NULL);
+ if (!book
+ || !e_book_open (book, TRUE, NULL)) {
+ g_warning (_("failed to open book"));
+ continue;
}
+
+ query = e_book_query_any_field_contains ("");
+ e_book_get_contacts (book, query, &contacts, NULL);
+ e_book_query_unref (query);
+
+ display_name = e_source_get_display_name (source);
+ uid = e_source_get_uid (source);
+
+ if (outputfile)
+ fprintf (
+ outputfile, "\"%s\",\"%s\",%d\n",
+ uid, display_name, g_list_length (contacts));
+ else
+ printf (
+ "\"%s\",\"%s\",%d\n",
+ uid, display_name, g_list_length (contacts));
+
+ g_list_foreach (contacts, (GFunc)g_object_unref, NULL);
+ g_list_free (contacts);
+
+ g_object_unref (book);
}
+ g_list_free (list);
+
if (outputfile)
fclose (outputfile);
diff --git a/addressbook/tools/evolution-addressbook-export.c b/addressbook/tools/evolution-addressbook-export.c
index 9c495e5..5605446 100644
--- a/addressbook/tools/evolution-addressbook-export.c
+++ b/addressbook/tools/evolution-addressbook-export.c
@@ -21,8 +21,9 @@
*/
#include <config.h>
-
+#include <stdlib.h>
#include <string.h>
+
#include <glib.h>
#include <glib/gi18n.h>
@@ -48,7 +49,7 @@
static gchar *opt_output_file = NULL;
static gboolean opt_list_folders_mode = FALSE;
static gchar *opt_output_format = NULL;
-static gchar *opt_addressbook_folder_uri = NULL;
+static gchar *opt_addressbook_source_uid = NULL;
static gboolean opt_async_mode = FALSE;
static gint opt_file_size = 0;
static gchar **opt_remaining = NULL;
@@ -128,12 +129,13 @@ main (gint argc, gchar **argv)
/* Parsing Parameter */
if (opt_remaining && g_strv_length (opt_remaining) > 0)
- opt_addressbook_folder_uri = g_strdup (opt_remaining[0]);
+ opt_addressbook_source_uid = g_strdup (opt_remaining[0]);
if (opt_list_folders_mode != FALSE) {
current_action = ACTION_LIST_FOLDERS;
- /* check there should not be addressbook-folder-uri , and async and size , output_format */
- if (opt_addressbook_folder_uri != NULL || opt_async_mode != FALSE || opt_output_format != NULL || opt_file_size != 0) {
+ /* check there should not be addressbook-source-uid,
+ * and async and size, output_format */
+ if (opt_addressbook_source_uid != NULL || opt_async_mode != FALSE || opt_output_format != NULL || opt_file_size != 0) {
g_warning (_("Command line arguments error, please use --help option to see the usage."));
exit (-1);
}
@@ -189,7 +191,8 @@ main (gint argc, gchar **argv)
}
actctx.action_list_cards.IsCSV = IsCSV;
actctx.action_list_cards.IsVCard = IsVCard;
- actctx.action_list_cards.addressbook_folder_uri = g_strdup (opt_addressbook_folder_uri);
+ actctx.action_list_cards.addressbook_source_uid =
+ g_strdup (opt_addressbook_source_uid);
actctx.action_list_cards.async_mode = opt_async_mode;
actctx.action_list_cards.file_size = opt_file_size;
@@ -202,5 +205,5 @@ main (gint argc, gchar **argv)
/*FIXME:should free actctx's some gchar * field, such as output_file! but since the program will end, so that will not cause mem leak. */
- exit (0);
+ return 0;
}
diff --git a/addressbook/tools/evolution-addressbook-export.h b/addressbook/tools/evolution-addressbook-export.h
index 804bd50..3739dd6 100644
--- a/addressbook/tools/evolution-addressbook-export.h
+++ b/addressbook/tools/evolution-addressbook-export.h
@@ -55,7 +55,7 @@ union _ActionContext
gchar *output_file;
gint IsCSV;
gint IsVCard;
- gchar *addressbook_folder_uri;
+ gchar *addressbook_source_uid;
gint async_mode;
gint file_size;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]