annotate plugins/gevolution/eds-utils.c @ 11588:8cc98a1d5b0f

[gaim-migrate @ 13858] ugh committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 02 Oct 2005 17:53:48 +0000
parents 5a8bc4b1f5b6
children 8d7c99f20e4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10083
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /*
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * Evolution integration plugin for Gaim
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 *
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 * Copyright (C) 2004 Henry Jen.
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 *
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 * published by the Free Software Foundation; either version 2 of the
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 *
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * General Public License for more details.
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 *
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * 02111-1307, USA.
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 */
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 #include "internal.h"
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 #include "gtkblist.h"
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 #include "gtkgaim.h"
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 #include "gtkutils.h"
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 #include "gtkimhtml.h"
10313
455c0830d108 [gaim-migrate @ 11511]
Luke Schierer <lschiere@pidgin.im>
parents: 10083
diff changeset
27 #include "gtkgaim-disclosure.h"
10083
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
28
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
29 #include "debug.h"
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
30 #include "gevolution.h"
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
31
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
32 GtkTreeModel *
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
33 gevo_addrbooks_model_new()
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34 {
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 return GTK_TREE_MODEL(gtk_list_store_new(NUM_ADDRBOOK_COLUMNS,
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36 G_TYPE_STRING, G_TYPE_STRING));
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
37 }
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
38
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
39 void
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40 gevo_addrbooks_model_unref(GtkTreeModel *model)
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
41 {
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
42 GtkTreeIter iter;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
43
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
44 g_return_if_fail(model != NULL);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
45 g_return_if_fail(GTK_IS_LIST_STORE(model));
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
46
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
47 if (!gtk_tree_model_get_iter_first(model, &iter))
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
48 return;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
49
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
50 g_object_unref(model);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51 }
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
52
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
53 void
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
54 gevo_addrbooks_model_populate(GtkTreeModel *model)
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
55 {
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
56 ESourceList *addressbooks;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
57 GError *err;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
58 GSList *groups, *g;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59 GtkTreeIter iter;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60 GtkListStore *list;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
61
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
62 g_return_if_fail(model != NULL);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63 g_return_if_fail(GTK_IS_LIST_STORE(model));
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
65 list = GTK_LIST_STORE(model);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
66
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
67 if (!e_book_get_addressbooks(&addressbooks, &err))
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68 {
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
69 gaim_debug_error("evolution",
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
70 "Unable to fetch list of address books.\n");
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
71
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
72 gtk_list_store_append(list, &iter);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73 gtk_list_store_set(list, &iter,
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
74 ADDRBOOK_COLUMN_NAME, _("None"),
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75 ADDRBOOK_COLUMN_URI, NULL,
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
76 -1);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
77
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
78 return;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
79 }
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
80
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
81 groups = e_source_list_peek_groups(addressbooks);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
82
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
83 if (groups == NULL)
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84 {
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85 gtk_list_store_append(list, &iter);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
86 gtk_list_store_set(list, &iter,
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87 ADDRBOOK_COLUMN_NAME, _("None"),
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
88 ADDRBOOK_COLUMN_URI, NULL,
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89 -1);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91 return;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 }
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
93
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
94 for (g = groups; g != NULL; g = g->next)
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95 {
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
96 GSList *sources, *s;
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
97
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
98 sources = e_source_group_peek_sources(g->data);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
99
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
100 for (s = sources; s != NULL; s = s->next)
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
101 {
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102 ESource *source = E_SOURCE(s->data);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
103
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
104 g_object_ref(source);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
106 gtk_list_store_append(list, &iter);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107 gtk_list_store_set(list, &iter,
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108 ADDRBOOK_COLUMN_NAME, e_source_peek_name(source),
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
109 ADDRBOOK_COLUMN_URI, e_source_get_uri(source),
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
110 -1);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111 }
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
112 }
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
113
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
114 g_object_unref(addressbooks);
b40a9b094f48 [gaim-migrate @ 11079]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
115 }
11117
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
116
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
117 EContact *
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
118 gevo_run_query_in_uri(const gchar *uri, EBookQuery *query)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
119 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
120 EBook *book;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
121 gboolean status;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
122 GList *cards;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
123
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
124 if (!gevo_load_addressbook(uri, &book, NULL))
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
125 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
126 gaim_debug_error("evolution",
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
127 "Error retrieving addressbook\n");
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
128 return NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
129 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
130
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
131 status = e_book_get_contacts(book, query, &cards, NULL);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
132 if (!status)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
133 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
134 gaim_debug_error("evolution", "Error %d in getting card list\n",
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
135 status);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
136 g_object_unref(book);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
137 return NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
138 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
139 g_object_unref(book);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
140
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
141 if (cards != NULL)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
142 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
143 EContact *contact = E_CONTACT(cards->data);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
144 GList *cards2 = cards->next;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
145
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
146 if (cards2 != NULL)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
147 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
148 /* Break off the first contact and free the rest. */
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
149 cards->next = NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
150 cards2->prev = NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
151 g_list_foreach(cards2, (GFunc)g_object_unref, NULL);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
152 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
153
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
154 /* Free the whole list. */
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
155 g_list_free(cards);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
156
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
157 return contact;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
158 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
159
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
160 return NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
161 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
162
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
163 /*
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
164 * Search for a buddy in the Evolution contacts.
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
165 *
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
166 * @param buddy The buddy to search for.
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
167 * @param query An optional query. This function takes ownership of @a query,
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
168 * so callers must e_book_query_ref() it in advance (to obtain a
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
169 * second reference) if they want to reuse @a query.
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
170 */
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
171 EContact *
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
172 gevo_search_buddy_in_contacts(GaimBuddy *buddy, EBookQuery *query)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
173 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
174 ESourceList *addressbooks;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
175 GError *err;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
176 EBookQuery *full_query;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
177 GSList *groups, *g;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
178 EContact *result;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
179 EContactField protocol_field = gevo_prpl_get_field(buddy->account, buddy);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
180
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
181 if (protocol_field == 0)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
182 return NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
183
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
184 if (query != NULL)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
185 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
186 EBookQuery *queries[2];
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
187
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
188 queries[0] = query;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
189 queries[1] = e_book_query_field_test(protocol_field, E_BOOK_QUERY_IS, buddy->name);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
190 if (queries[1] == NULL)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
191 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
192 gaim_debug_error("evolution", "Error in creating protocol query\n");
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
193 e_book_query_unref(query);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
194 return NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
195 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
196
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
197 full_query = e_book_query_and(2, queries, TRUE);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
198 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
199 else
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
200 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
201 full_query = e_book_query_field_test(protocol_field, E_BOOK_QUERY_IS, buddy->name);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
202 if (full_query == NULL)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
203 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
204 gaim_debug_error("evolution", "Error in creating protocol query\n");
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
205 return NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
206 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
207 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
208
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
209 if (!e_book_get_addressbooks(&addressbooks, &err))
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
210 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
211 gaim_debug_error("evolution",
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
212 "Unable to fetch list of address books.\n");
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
213 e_book_query_unref(full_query);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
214 if (err != NULL)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
215 g_error_free(err);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
216 return NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
217 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
218
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
219 groups = e_source_list_peek_groups(addressbooks);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
220 if (groups == NULL)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
221 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
222 g_object_unref(addressbooks);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
223 e_book_query_unref(full_query);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
224 return NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
225 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
226
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
227 for (g = groups; g != NULL; g = g->next)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
228 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
229 GSList *sources, *s;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
230 sources = e_source_group_peek_sources(g->data);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
231 for (s = sources; s != NULL; s = s->next)
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
232 {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
233 result = gevo_run_query_in_uri(e_source_get_uri(E_SOURCE(s->data)), full_query);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
234 if (result != NULL) {
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
235 g_object_unref(addressbooks);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
236 e_book_query_unref(full_query);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
237 return result;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
238 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
239 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
240 }
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
241
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
242 g_object_unref(addressbooks);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
243 e_book_query_unref(full_query);
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
244 return NULL;
5a8bc4b1f5b6 [gaim-migrate @ 13173]
Richard Laager <rlaager@wiktel.com>
parents: 10313
diff changeset
245 }