Mercurial > pidgin.yaz
annotate plugins/gevolution/add_buddy_dialog.c @ 11807:1f70f265cf27
[gaim-migrate @ 14098]
These files don't seem to be using these includes. What's the
deal with the leaked bonobo objects when using the evolution plugin?
I've also had some crashes caused by the evo plugin that I think
are slightly related.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 25 Oct 2005 04:24:26 +0000 |
parents | bc700cc98b82 |
children | 0aa231ebbfd5 |
rev | line source |
---|---|
8089 | 1 /* |
2 * Evolution integration plugin for Gaim | |
3 * | |
4 * Copyright (C) 2003 Christian Hammond. | |
5 * | |
6 * This program is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation; either version 2 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 * 02111-1307, USA. | |
20 */ | |
9825
c00def44d76a
[gaim-migrate @ 10696]
Christian Hammond <chipx86@chipx86.com>
parents:
9824
diff
changeset
|
21 #include "internal.h" |
8089 | 22 #include "gtkblist.h" |
9824 | 23 #include "gtkgaim.h" |
8089 | 24 #include "gtkutils.h" |
25 | |
26 #include "debug.h" | |
27 | |
28 #include "gevolution.h" | |
29 | |
30 #include <stdlib.h> | |
31 | |
32 enum | |
33 { | |
34 COLUMN_NAME, | |
35 COLUMN_PRPL_ICON, | |
36 COLUMN_USERNAME, | |
37 COLUMN_DATA, | |
38 NUM_COLUMNS | |
39 }; | |
40 | |
41 static gint | |
42 delete_win_cb(GtkWidget *w, GdkEvent *event, GevoAddBuddyDialog *dialog) | |
43 { | |
44 gtk_widget_destroy(dialog->win); | |
45 | |
46 if (dialog->contacts != NULL) | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
47 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
48 g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL); |
8089 | 49 g_list_free(dialog->contacts); |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
50 } |
8089 | 51 |
52 if (dialog->book != NULL) | |
53 g_object_unref(dialog->book); | |
54 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
55 gevo_addrbooks_model_unref(dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
56 |
8089 | 57 if (dialog->username != NULL) |
58 g_free(dialog->username); | |
59 | |
60 g_free(dialog); | |
61 | |
62 return 0; | |
63 } | |
64 | |
65 static void | |
66 new_person_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
67 { | |
68 const char *group_name; | |
69 | |
70 group_name = | |
71 gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(dialog->group_combo)->entry)); | |
72 | |
10830 | 73 gevo_new_person_dialog_show(dialog->book, NULL, dialog->account, dialog->username, |
8089 | 74 (*group_name ? group_name : NULL), |
75 NULL, FALSE); | |
76 | |
77 delete_win_cb(NULL, NULL, dialog); | |
78 } | |
79 | |
80 static void | |
81 cancel_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
82 { | |
83 delete_win_cb(NULL, NULL, dialog); | |
84 } | |
85 | |
86 static void | |
87 select_buddy_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
88 { | |
89 GtkTreeSelection *selection; | |
90 GtkTreeIter iter; | |
91 const char *group_name; | |
92 const char *fullname; | |
93 const char *username; | |
94 EContact *contact; | |
95 | |
96 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
97 | |
98 gtk_tree_selection_get_selected(selection, NULL, &iter); | |
99 | |
100 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
101 COLUMN_NAME, &fullname, | |
102 COLUMN_USERNAME, &username, | |
103 COLUMN_DATA, &contact, | |
104 -1); | |
105 | |
106 group_name = | |
107 gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(dialog->group_combo)->entry)); | |
108 | |
109 if (username == NULL || *username == '\0') | |
110 { | |
10830 | 111 gevo_new_person_dialog_show(dialog->book, NULL, dialog->account, dialog->username, |
8089 | 112 (*group_name ? group_name : NULL), |
113 NULL, FALSE); | |
114 } | |
115 else | |
116 { | |
117 gevo_add_buddy(dialog->account, group_name, username, fullname); | |
118 } | |
119 | |
120 delete_win_cb(NULL, NULL, dialog); | |
121 } | |
122 | |
123 static void | |
124 add_columns(GevoAddBuddyDialog *dialog) | |
125 { | |
126 GtkCellRenderer *renderer; | |
127 GtkTreeViewColumn *column; | |
128 | |
129 /* Name column */ | |
130 column = gtk_tree_view_column_new(); | |
131 gtk_tree_view_column_set_title(column, _("Name")); | |
132 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
133 gtk_tree_view_column_set_sort_column_id(column, COLUMN_NAME); | |
134 | |
135 renderer = gtk_cell_renderer_text_new(); | |
136 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
137 gtk_tree_view_column_add_attribute(column, renderer, | |
138 "text", COLUMN_NAME); | |
139 | |
140 /* Account column */ | |
141 column = gtk_tree_view_column_new(); | |
142 gtk_tree_view_column_set_title(column, _("Instant Messaging")); | |
143 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
144 gtk_tree_view_column_set_sort_column_id(column, COLUMN_USERNAME); | |
145 | |
146 /* Protocol icon */ | |
147 renderer = gtk_cell_renderer_pixbuf_new(); | |
148 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
149 gtk_tree_view_column_add_attribute(column, renderer, | |
150 "pixbuf", COLUMN_PRPL_ICON); | |
151 | |
152 /* Account name */ | |
153 renderer = gtk_cell_renderer_text_new(); | |
154 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
155 gtk_tree_view_column_add_attribute(column, renderer, | |
156 "text", COLUMN_USERNAME); | |
157 } | |
158 | |
159 static void | |
160 add_ims(GevoAddBuddyDialog *dialog, EContact *contact, const char *name, | |
161 GList *list, const char *id) | |
162 { | |
163 GaimAccount *account = NULL; | |
164 GList *l; | |
165 GtkTreeIter iter; | |
166 GdkPixbuf *pixbuf, *icon = NULL; | |
167 | |
168 if (list == NULL) | |
169 return; | |
170 | |
171 for (l = gaim_connections_get_all(); l != NULL; l = l->next) | |
172 { | |
173 GaimConnection *gc = (GaimConnection *)l->data; | |
174 | |
175 account = gaim_connection_get_account(gc); | |
176 | |
177 if (!strcmp(gaim_account_get_protocol_id(account), id)) | |
178 break; | |
179 | |
180 account = NULL; | |
181 } | |
182 | |
183 if (account == NULL) | |
184 return; | |
185 | |
10884 | 186 pixbuf = gaim_gtk_create_prpl_icon(account); |
8089 | 187 |
188 if (pixbuf != NULL) | |
189 icon = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
190 GDK_INTERP_BILINEAR); | |
191 | |
192 for (l = list; l != NULL; l = l->next) | |
193 { | |
194 char *account_name = (char *)l->data; | |
195 | |
196 if (account_name == NULL) | |
197 continue; | |
198 | |
199 if (gaim_find_buddy(dialog->account, account_name) != NULL) | |
200 continue; | |
201 | |
202 gtk_list_store_append(dialog->model, &iter); | |
203 | |
204 gtk_list_store_set(dialog->model, &iter, | |
205 COLUMN_NAME, name, | |
206 COLUMN_PRPL_ICON, icon, | |
207 COLUMN_USERNAME, account_name, | |
208 COLUMN_DATA, contact, | |
209 -1); | |
210 | |
211 if (!strcmp(gaim_account_get_protocol_id(account), | |
212 gaim_account_get_protocol_id(dialog->account)) && | |
213 dialog->username != NULL && | |
214 !strcmp(account_name, dialog->username)) | |
215 { | |
216 GtkTreeSelection *selection; | |
217 | |
218 /* This is it. Select it. */ | |
219 selection = gtk_tree_view_get_selection( | |
220 GTK_TREE_VIEW(dialog->treeview)); | |
221 | |
222 gtk_tree_selection_select_iter(selection, &iter); | |
223 } | |
224 } | |
225 | |
226 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
227 if (icon != NULL) g_object_unref(G_OBJECT(icon)); | |
228 | |
229 g_list_foreach(list, (GFunc)g_free, NULL); | |
230 g_list_free(list); | |
231 } | |
232 | |
233 static void | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
234 populate_treeview(GevoAddBuddyDialog *dialog, const gchar *uri) |
8089 | 235 { |
236 EBookQuery *query; | |
237 EBook *book; | |
238 gboolean status; | |
239 GList *cards, *c; | |
240 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
241 if (dialog->book != NULL) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
242 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
243 g_object_unref(dialog->book); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
244 dialog->book = NULL; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
245 } |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
246 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
247 if (dialog->contacts != NULL) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
248 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
249 g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
250 g_list_free(dialog->contacts); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
251 dialog->contacts = NULL; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
252 } |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
253 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
254 gtk_list_store_clear(dialog->model); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
255 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
256 if (!gevo_load_addressbook(uri, &book, NULL)) |
8089 | 257 { |
258 gaim_debug_error("evolution", | |
259 "Error retrieving default addressbook\n"); | |
260 | |
261 return; | |
262 } | |
263 | |
264 query = e_book_query_field_exists(E_CONTACT_FULL_NAME); | |
265 | |
266 if (query == NULL) | |
267 { | |
268 gaim_debug_error("evolution", "Error in creating query\n"); | |
269 | |
270 g_object_unref(book); | |
271 | |
272 return; | |
273 } | |
274 | |
275 status = e_book_get_contacts(book, query, &cards, NULL); | |
276 | |
277 e_book_query_unref(query); | |
278 | |
279 if (!status) | |
280 { | |
281 gaim_debug_error("evolution", "Error %d in getting card list\n", | |
282 status); | |
283 | |
284 g_object_unref(book); | |
285 | |
286 return; | |
287 } | |
288 | |
289 for (c = cards; c != NULL; c = c->next) | |
290 { | |
291 EContact *contact = E_CONTACT(c->data); | |
292 const char *name; | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
293 GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells; |
8089 | 294 |
295 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
296 | |
297 aims = e_contact_get(contact, E_CONTACT_IM_AIM); | |
298 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); | |
299 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); | |
300 msns = e_contact_get(contact, E_CONTACT_IM_MSN); | |
301 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
302 novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE); |
8089 | 303 |
304 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
305 msns == NULL && icqs == NULL && novells == NULL) |
8089 | 306 { |
307 GtkTreeIter iter; | |
308 | |
309 gtk_list_store_append(dialog->model, &iter); | |
310 | |
311 gtk_list_store_set(dialog->model, &iter, | |
312 COLUMN_NAME, name, | |
313 COLUMN_DATA, contact, | |
314 -1); | |
315 } | |
316 else | |
317 { | |
318 add_ims(dialog, contact, name, aims, "prpl-oscar"); | |
319 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); | |
320 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); | |
321 add_ims(dialog, contact, name, msns, "prpl-msn"); | |
322 add_ims(dialog, contact, name, icqs, "prpl-oscar"); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
323 add_ims(dialog, contact, name, novells, "prpl-novell"); |
8089 | 324 } |
325 } | |
326 | |
327 dialog->contacts = cards; | |
328 dialog->book = book; | |
329 } | |
330 | |
331 static void | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
332 addrbook_change_cb(GtkComboBox *combo, GevoAddBuddyDialog *dialog) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
333 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
334 GtkTreeIter iter; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
335 const char *esource_uri; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
336 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
337 if (!gtk_combo_box_get_active_iter(combo, &iter)) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
338 return; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
339 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
340 gtk_tree_model_get(GTK_TREE_MODEL(dialog->addrbooks), &iter, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
341 ADDRBOOK_COLUMN_URI, &esource_uri, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
342 -1); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
343 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
344 populate_treeview(dialog, esource_uri); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
345 } |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
346 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
347 static void |
8089 | 348 selected_cb(GtkTreeSelection *sel, GevoAddBuddyDialog *dialog) |
349 { | |
350 gtk_widget_set_sensitive(dialog->select_button, TRUE); | |
351 } | |
352 | |
353 static void | |
354 search_changed_cb(GtkEntry *entry, GevoAddBuddyDialog *dialog) | |
355 { | |
356 const char *text = gtk_entry_get_text(entry); | |
357 GList *l; | |
358 | |
359 gtk_list_store_clear(dialog->model); | |
360 | |
361 for (l = dialog->contacts; l != NULL; l = l->next) | |
362 { | |
363 EContact *contact = E_CONTACT(l->data); | |
364 const char *name; | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
365 GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells; |
8089 | 366 |
367 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
368 | |
369 if (text != NULL && *text != '\0' && name != NULL && | |
370 g_ascii_strncasecmp(name, text, strlen(text))) | |
371 { | |
372 continue; | |
373 } | |
374 | |
375 aims = e_contact_get(contact, E_CONTACT_IM_AIM); | |
376 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); | |
377 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); | |
378 msns = e_contact_get(contact, E_CONTACT_IM_MSN); | |
379 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
380 novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE); |
8089 | 381 |
382 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
383 msns == NULL && icqs == NULL && novells == NULL) |
8089 | 384 { |
385 GtkTreeIter iter; | |
386 | |
387 gtk_list_store_append(dialog->model, &iter); | |
388 | |
389 gtk_list_store_set(dialog->model, &iter, | |
390 COLUMN_NAME, name, | |
391 COLUMN_DATA, contact, | |
392 -1); | |
393 } | |
394 else | |
395 { | |
396 add_ims(dialog, contact, name, aims, "prpl-oscar"); | |
397 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); | |
398 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); | |
399 add_ims(dialog, contact, name, msns, "prpl-msn"); | |
400 add_ims(dialog, contact, name, icqs, "prpl-oscar"); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
401 add_ims(dialog, contact, name, novells, "prpl-novell"); |
8089 | 402 } |
403 } | |
404 } | |
405 | |
406 static void | |
407 clear_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
408 { | |
409 static gboolean lock = FALSE; | |
410 | |
411 if (lock) | |
412 return; | |
413 | |
414 lock = TRUE; | |
415 gtk_entry_set_text(GTK_ENTRY(dialog->search_field), ""); | |
416 lock = FALSE; | |
417 } | |
418 | |
419 void | |
420 gevo_add_buddy_dialog_show(GaimAccount *account, const char *username, | |
421 const char *group, const char *alias) | |
422 { | |
423 GevoAddBuddyDialog *dialog; | |
424 GtkWidget *button; | |
425 GtkWidget *sw; | |
426 GtkWidget *label; | |
427 GtkWidget *vbox; | |
428 GtkWidget *hbox; | |
429 GtkWidget *bbox; | |
430 GtkWidget *sep; | |
431 GtkTreeSelection *selection; | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
432 GtkCellRenderer *cell; |
8089 | 433 |
434 dialog = g_new0(GevoAddBuddyDialog, 1); | |
435 | |
436 dialog->account = | |
437 (account != NULL | |
438 ? account | |
439 : gaim_connection_get_account(gaim_connections_get_all()->data)); | |
440 | |
441 if (username != NULL) | |
442 dialog->username = g_strdup(username); | |
443 | |
444 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
445 gtk_window_set_role(GTK_WINDOW(dialog->win), "add_buddy"); | |
446 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
447 gtk_widget_set_size_request(dialog->win, -1, 400); | |
448 | |
449 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
450 G_CALLBACK(delete_win_cb), dialog); | |
451 | |
452 /* Setup the vbox */ | |
453 vbox = gtk_vbox_new(FALSE, 12); | |
454 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
455 gtk_widget_show(vbox); | |
456 | |
457 /* Add the label. */ | |
458 label = gtk_label_new(_("Select a person from your address book below, " | |
459 "or add a new person.")); | |
460 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
461 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
462 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
463 gtk_widget_show(label); | |
464 | |
465 /* Add the search hbox */ | |
466 hbox = gtk_hbox_new(FALSE, 6); | |
467 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); | |
468 gtk_widget_show(hbox); | |
469 | |
470 /* "Search" */ | |
471 label = gtk_label_new(_("Search")); | |
472 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
473 gtk_widget_show(label); | |
474 | |
475 /* Addressbooks */ | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
476 dialog->addrbooks = gevo_addrbooks_model_new(); |
8089 | 477 |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
478 dialog->addrbooks_combo = gtk_combo_box_new_with_model( |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
479 dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
480 cell = gtk_cell_renderer_text_new(); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
481 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
482 cell, TRUE); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
483 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
484 cell, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
485 "text", ADDRBOOK_COLUMN_NAME, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
486 NULL); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
487 gtk_box_pack_start(GTK_BOX(hbox), dialog->addrbooks_combo, FALSE, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
488 FALSE, 0); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
489 gtk_widget_show(dialog->addrbooks_combo); |
8089 | 490 |
491 /* Search field */ | |
492 dialog->search_field = gtk_entry_new(); | |
493 gtk_box_pack_start(GTK_BOX(hbox), dialog->search_field, TRUE, TRUE, 0); | |
494 gtk_widget_show(dialog->search_field); | |
495 | |
496 g_signal_connect(G_OBJECT(dialog->search_field), "changed", | |
497 G_CALLBACK(search_changed_cb), dialog); | |
498 | |
499 /* Clear button */ | |
500 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
501 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
502 gtk_widget_show(button); | |
503 | |
504 g_signal_connect(G_OBJECT(button), "clicked", | |
505 G_CALLBACK(clear_cb), dialog); | |
506 | |
507 /* Scrolled Window */ | |
508 sw = gtk_scrolled_window_new(0, 0); | |
509 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
510 GTK_POLICY_AUTOMATIC, | |
511 GTK_POLICY_ALWAYS); | |
512 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
513 GTK_SHADOW_IN); | |
514 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
515 gtk_widget_show(sw); | |
516 | |
517 /* Create the list model for the treeview. */ | |
518 dialog->model = gtk_list_store_new(NUM_COLUMNS, | |
519 G_TYPE_STRING, GDK_TYPE_PIXBUF, | |
520 G_TYPE_STRING, G_TYPE_POINTER); | |
521 | |
522 /* Now for the treeview */ | |
523 dialog->treeview = | |
524 gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
525 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
526 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
527 gtk_widget_show(dialog->treeview); | |
528 | |
529 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
530 | |
531 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
532 | |
533 g_signal_connect(G_OBJECT(selection), "changed", | |
534 G_CALLBACK(selected_cb), dialog); | |
535 | |
536 add_columns(dialog); | |
537 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
538 /* |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
539 * Catch addressbook selection and populate treeview with the first |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
540 * addressbook |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
541 */ |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
542 gevo_addrbooks_model_populate(dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
543 g_signal_connect(G_OBJECT(dialog->addrbooks_combo), "changed", |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
544 G_CALLBACK(addrbook_change_cb), dialog); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
545 gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->addrbooks_combo), 0); |
8089 | 546 |
547 /* Group box */ | |
548 hbox = gtk_hbox_new(FALSE, 6); | |
549 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
550 gtk_widget_show(hbox); | |
551 | |
552 label = gtk_label_new(_("Group:")); | |
553 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
554 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
555 gtk_widget_show(label); | |
556 | |
557 dialog->group_combo = gtk_combo_new(); | |
558 gtk_combo_set_popdown_strings(GTK_COMBO(dialog->group_combo), | |
559 gevo_get_groups()); | |
560 gtk_box_pack_start(GTK_BOX(hbox), dialog->group_combo, TRUE, TRUE, 0); | |
561 gtk_widget_show(dialog->group_combo); | |
562 | |
563 /* Cool. Now we only have a little left... */ | |
564 | |
565 /* Separator. */ | |
566 sep = gtk_hseparator_new(); | |
567 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
568 gtk_widget_show(sep); | |
569 | |
570 /* Button box */ | |
571 bbox = gtk_hbutton_box_new(); | |
572 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
573 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
574 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
575 gtk_widget_show(bbox); | |
576 | |
577 /* "New Person" button */ | |
578 button = gaim_pixbuf_button_from_stock(_("New Person"), GTK_STOCK_NEW, | |
579 GAIM_BUTTON_HORIZONTAL); | |
580 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
581 gtk_widget_show(button); | |
582 | |
583 g_signal_connect(G_OBJECT(button), "clicked", | |
584 G_CALLBACK(new_person_cb), dialog); | |
585 | |
586 /* "Cancel" button */ | |
587 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
588 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
589 gtk_widget_show(button); | |
590 | |
591 g_signal_connect(G_OBJECT(button), "clicked", | |
592 G_CALLBACK(cancel_cb), dialog); | |
593 | |
594 /* "Select Buddy" button */ | |
595 button = gaim_pixbuf_button_from_stock(_("Select Buddy"), GTK_STOCK_APPLY, | |
596 GAIM_BUTTON_HORIZONTAL); | |
597 dialog->select_button = button; | |
598 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
599 gtk_widget_set_sensitive(button, FALSE); | |
600 gtk_widget_show(button); | |
601 | |
602 g_signal_connect(G_OBJECT(button), "clicked", | |
603 G_CALLBACK(select_buddy_cb), dialog); | |
604 | |
605 /* Show it. */ | |
606 gtk_widget_show(dialog->win); | |
607 } | |
608 | |
609 void | |
610 gevo_add_buddy_dialog_add_person(GevoAddBuddyDialog *dialog, | |
611 EContact *contact, const char *name, | |
612 GaimAccount *account, const char *screenname) | |
613 { | |
614 GdkPixbuf *pixbuf, *icon = NULL; | |
615 GtkTreeIter iter; | |
616 | |
10884 | 617 pixbuf = gaim_gtk_create_prpl_icon(account); |
8089 | 618 |
619 if (pixbuf != NULL) | |
620 icon = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
621 | |
622 gtk_list_store_append(dialog->model, &iter); | |
623 | |
624 gtk_list_store_set(dialog->model, &iter, | |
625 COLUMN_NAME, name, | |
626 COLUMN_PRPL_ICON, icon, | |
627 COLUMN_DATA, contact, | |
628 COLUMN_USERNAME, screenname, | |
629 -1); | |
630 | |
631 if (contact != NULL) | |
632 dialog->contacts = g_list_append(dialog->contacts, contact); | |
633 | |
634 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
635 if (icon != NULL) g_object_unref(G_OBJECT(icon)); | |
636 } |