| 49 } |
49 } |
| 50 |
50 |
| 51 void |
51 void |
| 52 gevo_addrbooks_model_populate(GtkTreeModel *model) |
52 gevo_addrbooks_model_populate(GtkTreeModel *model) |
| 53 { |
53 { |
| 54 ESourceList *addressbooks; |
54 ESourceRegistry *registry; |
| 55 GError *err = NULL; |
55 GError *err = NULL; |
| 56 GSList *groups, *g; |
56 GList *sources, *s; |
| 57 GtkTreeIter iter; |
57 GtkTreeIter iter; |
| 58 GtkListStore *list; |
58 GtkListStore *list; |
| 59 |
59 |
| 60 g_return_if_fail(model != NULL); |
60 g_return_if_fail(model != NULL); |
| 61 g_return_if_fail(GTK_IS_LIST_STORE(model)); |
61 g_return_if_fail(GTK_IS_LIST_STORE(model)); |
| 62 |
62 |
| 63 list = GTK_LIST_STORE(model); |
63 list = GTK_LIST_STORE(model); |
| 64 |
64 |
| 65 if (!e_book_get_addressbooks(&addressbooks, &err)) |
65 registry = e_source_registry_new_sync(NULL, &err); |
| 66 { |
66 |
| |
67 if (!registry) { |
| 67 purple_debug_error("evolution", |
68 purple_debug_error("evolution", |
| 68 "Unable to fetch list of address books.\n"); |
69 "Unable to fetch list of address books."); |
| |
70 |
| |
71 gtk_list_store_append(list, &iter); |
| |
72 gtk_list_store_set(list, &iter, ADDRBOOK_COLUMN_NAME, _("None"), |
| |
73 ADDRBOOK_COLUMN_UID, NULL, -1); |
| |
74 |
| |
75 g_clear_error(&err); |
| |
76 return; |
| |
77 } |
| |
78 |
| |
79 sources = e_source_registry_list_sources(registry, E_SOURCE_EXTENSION_ADDRESS_BOOK); |
| |
80 |
| |
81 if (sources == NULL) { |
| |
82 g_object_unref(registry); |
| |
83 gtk_list_store_append(list, &iter); |
| |
84 gtk_list_store_set(list, &iter, ADDRBOOK_COLUMN_NAME, _("None"), |
| |
85 ADDRBOOK_COLUMN_UID, NULL, -1); |
| |
86 |
| |
87 return; |
| |
88 } |
| |
89 |
| |
90 for (s = sources; s != NULL; s = s->next) { |
| |
91 ESource *source = E_SOURCE(s->data); |
| |
92 |
| |
93 g_object_ref(source); |
| 69 |
94 |
| 70 gtk_list_store_append(list, &iter); |
95 gtk_list_store_append(list, &iter); |
| 71 gtk_list_store_set(list, &iter, |
96 gtk_list_store_set(list, &iter, |
| 72 ADDRBOOK_COLUMN_NAME, _("None"), |
97 ADDRBOOK_COLUMN_NAME, e_source_get_display_name(source), |
| 73 ADDRBOOK_COLUMN_URI, NULL, |
98 ADDRBOOK_COLUMN_UID, e_source_get_uid(source), -1); |
| 74 -1); |
99 } |
| 75 |
100 |
| 76 return; |
101 g_object_unref(registry); |
| 77 } |
102 g_list_free_full(sources, g_object_unref); |
| 78 |
|
| 79 groups = e_source_list_peek_groups(addressbooks); |
|
| 80 |
|
| 81 if (groups == NULL) |
|
| 82 { |
|
| 83 gtk_list_store_append(list, &iter); |
|
| 84 gtk_list_store_set(list, &iter, |
|
| 85 ADDRBOOK_COLUMN_NAME, _("None"), |
|
| 86 ADDRBOOK_COLUMN_URI, NULL, |
|
| 87 -1); |
|
| 88 |
|
| 89 return; |
|
| 90 } |
|
| 91 |
|
| 92 for (g = groups; g != NULL; g = g->next) |
|
| 93 { |
|
| 94 GSList *sources, *s; |
|
| 95 |
|
| 96 sources = e_source_group_peek_sources(g->data); |
|
| 97 |
|
| 98 for (s = sources; s != NULL; s = s->next) |
|
| 99 { |
|
| 100 ESource *source = E_SOURCE(s->data); |
|
| 101 |
|
| 102 g_object_ref(source); |
|
| 103 |
|
| 104 gtk_list_store_append(list, &iter); |
|
| 105 gtk_list_store_set(list, &iter, |
|
| 106 ADDRBOOK_COLUMN_NAME, e_source_peek_name(source), |
|
| 107 ADDRBOOK_COLUMN_URI, e_source_get_uri(source), |
|
| 108 -1); |
|
| 109 } |
|
| 110 } |
|
| 111 |
|
| 112 g_object_unref(addressbooks); |
|
| 113 } |
103 } |
| 114 |
104 |
| 115 static EContact * |
105 static EContact * |
| 116 gevo_run_query_in_uri(const gchar *uri, EBookQuery *query) |
106 gevo_run_query_in_source(ESource *source, EBookQuery *query) |
| 117 { |
107 { |
| 118 EBook *book; |
108 EBook *book; |
| 119 gboolean status; |
109 gboolean status; |
| 120 GList *cards; |
110 GList *cards; |
| 121 GError *err = NULL; |
111 GError *err = NULL; |
| 122 |
112 |
| 123 if (!gevo_load_addressbook(uri, &book, &err)) |
113 if (!gevo_load_addressbook_from_source(source, &book, &err)) { |
| 124 { |
|
| 125 purple_debug_error("evolution", |
114 purple_debug_error("evolution", |
| 126 "Error retrieving addressbook: %s\n", err->message); |
115 "Error retrieving addressbook: %s\n", err->message); |
| 127 g_error_free(err); |
116 g_error_free(err); |
| 128 return NULL; |
117 return NULL; |
| 129 } |
118 } |
| 207 purple_debug_error("evolution", "Error in creating protocol query\n"); |
196 purple_debug_error("evolution", "Error in creating protocol query\n"); |
| 208 return NULL; |
197 return NULL; |
| 209 } |
198 } |
| 210 } |
199 } |
| 211 |
200 |
| 212 if (!e_book_get_addressbooks(&addressbooks, &err)) |
201 registry = e_source_registry_new_sync(NULL, &err); |
| 213 { |
202 |
| |
203 if (!registry) { |
| 214 purple_debug_error("evolution", |
204 purple_debug_error("evolution", |
| 215 "Unable to fetch list of address books.\n"); |
205 "Unable to fetch list of address books.\n"); |
| 216 e_book_query_unref(full_query); |
206 e_book_query_unref(full_query); |
| 217 if (err != NULL) |
207 if (err != NULL) |
| 218 g_error_free(err); |
208 g_error_free(err); |
| 219 return NULL; |
209 return NULL; |
| 220 } |
210 } |
| 221 |
211 |
| 222 groups = e_source_list_peek_groups(addressbooks); |
212 sources = e_source_registry_list_sources(registry, |
| 223 if (groups == NULL) |
213 E_SOURCE_EXTENSION_ADDRESS_BOOK); |
| 224 { |
214 |
| 225 g_object_unref(addressbooks); |
215 for (s = sources; s != NULL; s = s->next) { |
| 226 e_book_query_unref(full_query); |
216 result = gevo_run_query_in_source(E_SOURCE(s->data), |
| 227 return NULL; |
217 full_query); |
| 228 } |
218 if (result != NULL) { |
| 229 |
219 g_object_unref(registry); |
| 230 for (g = groups; g != NULL; g = g->next) |
220 g_list_free_full(sources, g_object_unref); |
| 231 { |
221 e_book_query_unref(full_query); |
| 232 GSList *sources, *s; |
222 return result; |
| 233 sources = e_source_group_peek_sources(g->data); |
223 } |
| 234 for (s = sources; s != NULL; s = s->next) |
224 } |
| 235 { |
225 |
| 236 result = gevo_run_query_in_uri(e_source_get_uri(E_SOURCE(s->data)), full_query); |
226 g_object_unref(registry); |
| 237 if (result != NULL) { |
227 g_list_free_full(sources, g_object_unref); |
| 238 g_object_unref(addressbooks); |
|
| 239 e_book_query_unref(full_query); |
|
| 240 return result; |
|
| 241 } |
|
| 242 } |
|
| 243 } |
|
| 244 |
|
| 245 g_object_unref(addressbooks); |
|
| 246 e_book_query_unref(full_query); |
228 e_book_query_unref(full_query); |
| 247 return NULL; |
229 return NULL; |
| 248 } |
230 } |