| |
1 /* |
| |
2 * Evolution integration plugin for Purple |
| |
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 */ |
| |
21 #include "internal.h" |
| |
22 #include "gtkblist.h" |
| |
23 #include "pidgin.h" |
| |
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) |
| |
47 { |
| |
48 g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL); |
| |
49 g_list_free(dialog->contacts); |
| |
50 } |
| |
51 |
| |
52 if (dialog->book != NULL) |
| |
53 g_object_unref(dialog->book); |
| |
54 |
| |
55 gevo_addrbooks_model_unref(dialog->addrbooks); |
| |
56 |
| |
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 |
| |
73 gevo_new_person_dialog_show(dialog->book, NULL, dialog->account, dialog->username, |
| |
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 if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) |
| |
99 return; |
| |
100 |
| |
101 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, |
| |
102 COLUMN_NAME, &fullname, |
| |
103 COLUMN_USERNAME, &username, |
| |
104 COLUMN_DATA, &contact, |
| |
105 -1); |
| |
106 |
| |
107 group_name = |
| |
108 gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(dialog->group_combo)->entry)); |
| |
109 |
| |
110 if (username == NULL || *username == '\0') |
| |
111 { |
| |
112 gevo_new_person_dialog_show(dialog->book, NULL, dialog->account, dialog->username, |
| |
113 (*group_name ? group_name : NULL), |
| |
114 NULL, FALSE); |
| |
115 } |
| |
116 else |
| |
117 { |
| |
118 gevo_add_buddy(dialog->account, group_name, username, fullname); |
| |
119 } |
| |
120 |
| |
121 delete_win_cb(NULL, NULL, dialog); |
| |
122 } |
| |
123 |
| |
124 static void |
| |
125 add_columns(GevoAddBuddyDialog *dialog) |
| |
126 { |
| |
127 GtkCellRenderer *renderer; |
| |
128 GtkTreeViewColumn *column; |
| |
129 |
| |
130 /* Name column */ |
| |
131 column = gtk_tree_view_column_new(); |
| |
132 gtk_tree_view_column_set_title(column, _("Name")); |
| |
133 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); |
| |
134 gtk_tree_view_column_set_sort_column_id(column, COLUMN_NAME); |
| |
135 |
| |
136 renderer = gtk_cell_renderer_text_new(); |
| |
137 gtk_tree_view_column_pack_start(column, renderer, TRUE); |
| |
138 gtk_tree_view_column_add_attribute(column, renderer, |
| |
139 "text", COLUMN_NAME); |
| |
140 |
| |
141 /* Account column */ |
| |
142 column = gtk_tree_view_column_new(); |
| |
143 gtk_tree_view_column_set_title(column, _("Instant Messaging")); |
| |
144 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); |
| |
145 gtk_tree_view_column_set_sort_column_id(column, COLUMN_USERNAME); |
| |
146 |
| |
147 /* Protocol icon */ |
| |
148 renderer = gtk_cell_renderer_pixbuf_new(); |
| |
149 gtk_tree_view_column_pack_start(column, renderer, FALSE); |
| |
150 gtk_tree_view_column_add_attribute(column, renderer, |
| |
151 "pixbuf", COLUMN_PRPL_ICON); |
| |
152 |
| |
153 /* Account name */ |
| |
154 renderer = gtk_cell_renderer_text_new(); |
| |
155 gtk_tree_view_column_pack_start(column, renderer, TRUE); |
| |
156 gtk_tree_view_column_add_attribute(column, renderer, |
| |
157 "text", COLUMN_USERNAME); |
| |
158 } |
| |
159 |
| |
160 static void |
| |
161 add_ims(GevoAddBuddyDialog *dialog, EContact *contact, const char *name, |
| |
162 GList *list, const char *id) |
| |
163 { |
| |
164 PurpleAccount *account = NULL; |
| |
165 GList *l; |
| |
166 GtkTreeIter iter; |
| |
167 GdkPixbuf *pixbuf; |
| |
168 |
| |
169 if (list == NULL) |
| |
170 return; |
| |
171 |
| |
172 for (l = purple_connections_get_all(); l != NULL; l = l->next) |
| |
173 { |
| |
174 PurpleConnection *gc = (PurpleConnection *)l->data; |
| |
175 |
| |
176 account = purple_connection_get_account(gc); |
| |
177 |
| |
178 if (!strcmp(purple_account_get_protocol_id(account), id)) |
| |
179 break; |
| |
180 |
| |
181 account = NULL; |
| |
182 } |
| |
183 |
| |
184 if (account == NULL) |
| |
185 return; |
| |
186 |
| |
187 pixbuf = pidgin_create_prpl_icon(account, 0.5); |
| |
188 |
| |
189 for (l = list; l != NULL; l = l->next) |
| |
190 { |
| |
191 char *account_name = (char *)l->data; |
| |
192 |
| |
193 if (account_name == NULL) |
| |
194 continue; |
| |
195 |
| |
196 if (purple_find_buddy(dialog->account, account_name) != NULL) |
| |
197 continue; |
| |
198 |
| |
199 gtk_list_store_append(dialog->model, &iter); |
| |
200 |
| |
201 gtk_list_store_set(dialog->model, &iter, |
| |
202 COLUMN_NAME, name, |
| |
203 COLUMN_PRPL_ICON, pixbuf, |
| |
204 COLUMN_USERNAME, account_name, |
| |
205 COLUMN_DATA, contact, |
| |
206 -1); |
| |
207 |
| |
208 if (!strcmp(purple_account_get_protocol_id(account), |
| |
209 purple_account_get_protocol_id(dialog->account)) && |
| |
210 dialog->username != NULL && |
| |
211 !strcmp(account_name, dialog->username)) |
| |
212 { |
| |
213 GtkTreeSelection *selection; |
| |
214 |
| |
215 /* This is it. Select it. */ |
| |
216 selection = gtk_tree_view_get_selection( |
| |
217 GTK_TREE_VIEW(dialog->treeview)); |
| |
218 |
| |
219 gtk_tree_selection_select_iter(selection, &iter); |
| |
220 } |
| |
221 } |
| |
222 |
| |
223 if (pixbuf != NULL) |
| |
224 g_object_unref(G_OBJECT(pixbuf)); |
| |
225 |
| |
226 g_list_foreach(list, (GFunc)g_free, NULL); |
| |
227 g_list_free(list); |
| |
228 } |
| |
229 |
| |
230 static void |
| |
231 populate_treeview(GevoAddBuddyDialog *dialog, const gchar *uri) |
| |
232 { |
| |
233 EBookQuery *query; |
| |
234 EBook *book; |
| |
235 gboolean status; |
| |
236 GList *cards, *c; |
| |
237 |
| |
238 if (dialog->book != NULL) |
| |
239 { |
| |
240 g_object_unref(dialog->book); |
| |
241 dialog->book = NULL; |
| |
242 } |
| |
243 |
| |
244 if (dialog->contacts != NULL) |
| |
245 { |
| |
246 g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL); |
| |
247 g_list_free(dialog->contacts); |
| |
248 dialog->contacts = NULL; |
| |
249 } |
| |
250 |
| |
251 gtk_list_store_clear(dialog->model); |
| |
252 |
| |
253 if (!gevo_load_addressbook(uri, &book, NULL)) |
| |
254 { |
| |
255 purple_debug_error("evolution", |
| |
256 "Error retrieving default addressbook\n"); |
| |
257 |
| |
258 return; |
| |
259 } |
| |
260 |
| |
261 query = e_book_query_field_exists(E_CONTACT_FULL_NAME); |
| |
262 |
| |
263 if (query == NULL) |
| |
264 { |
| |
265 purple_debug_error("evolution", "Error in creating query\n"); |
| |
266 |
| |
267 g_object_unref(book); |
| |
268 |
| |
269 return; |
| |
270 } |
| |
271 |
| |
272 status = e_book_get_contacts(book, query, &cards, NULL); |
| |
273 |
| |
274 e_book_query_unref(query); |
| |
275 |
| |
276 if (!status) |
| |
277 { |
| |
278 purple_debug_error("evolution", "Error %d in getting card list\n", |
| |
279 status); |
| |
280 |
| |
281 g_object_unref(book); |
| |
282 |
| |
283 return; |
| |
284 } |
| |
285 |
| |
286 for (c = cards; c != NULL; c = c->next) |
| |
287 { |
| |
288 EContact *contact = E_CONTACT(c->data); |
| |
289 const char *name; |
| |
290 GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells; |
| |
291 |
| |
292 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); |
| |
293 |
| |
294 aims = e_contact_get(contact, E_CONTACT_IM_AIM); |
| |
295 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); |
| |
296 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); |
| |
297 msns = e_contact_get(contact, E_CONTACT_IM_MSN); |
| |
298 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); |
| |
299 novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE); |
| |
300 |
| |
301 if (aims == NULL && jabbers == NULL && yahoos == NULL && |
| |
302 msns == NULL && icqs == NULL && novells == NULL) |
| |
303 { |
| |
304 GtkTreeIter iter; |
| |
305 |
| |
306 gtk_list_store_append(dialog->model, &iter); |
| |
307 |
| |
308 gtk_list_store_set(dialog->model, &iter, |
| |
309 COLUMN_NAME, name, |
| |
310 COLUMN_DATA, contact, |
| |
311 -1); |
| |
312 } |
| |
313 else |
| |
314 { |
| |
315 add_ims(dialog, contact, name, aims, "prpl-oscar"); |
| |
316 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); |
| |
317 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); |
| |
318 add_ims(dialog, contact, name, msns, "prpl-msn"); |
| |
319 add_ims(dialog, contact, name, icqs, "prpl-oscar"); |
| |
320 add_ims(dialog, contact, name, novells, "prpl-novell"); |
| |
321 } |
| |
322 } |
| |
323 |
| |
324 dialog->contacts = cards; |
| |
325 dialog->book = book; |
| |
326 } |
| |
327 |
| |
328 static void |
| |
329 addrbook_change_cb(GtkComboBox *combo, GevoAddBuddyDialog *dialog) |
| |
330 { |
| |
331 GtkTreeIter iter; |
| |
332 const char *esource_uri; |
| |
333 |
| |
334 if (!gtk_combo_box_get_active_iter(combo, &iter)) |
| |
335 return; |
| |
336 |
| |
337 gtk_tree_model_get(GTK_TREE_MODEL(dialog->addrbooks), &iter, |
| |
338 ADDRBOOK_COLUMN_URI, &esource_uri, |
| |
339 -1); |
| |
340 |
| |
341 populate_treeview(dialog, esource_uri); |
| |
342 } |
| |
343 |
| |
344 static void |
| |
345 selected_cb(GtkTreeSelection *sel, GevoAddBuddyDialog *dialog) |
| |
346 { |
| |
347 GtkTreeSelection *selection; |
| |
348 |
| |
349 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); |
| |
350 gtk_widget_set_sensitive(dialog->select_button, |
| |
351 gtk_tree_selection_get_selected(selection, NULL, NULL)); |
| |
352 } |
| |
353 |
| |
354 static void |
| |
355 search_changed_cb(GtkEntry *entry, GevoAddBuddyDialog *dialog) |
| |
356 { |
| |
357 const char *text = gtk_entry_get_text(entry); |
| |
358 GList *l; |
| |
359 |
| |
360 gtk_list_store_clear(dialog->model); |
| |
361 |
| |
362 for (l = dialog->contacts; l != NULL; l = l->next) |
| |
363 { |
| |
364 EContact *contact = E_CONTACT(l->data); |
| |
365 const char *name; |
| |
366 GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells; |
| |
367 |
| |
368 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); |
| |
369 |
| |
370 if (text != NULL && *text != '\0' && name != NULL && |
| |
371 g_ascii_strncasecmp(name, text, strlen(text))) |
| |
372 { |
| |
373 continue; |
| |
374 } |
| |
375 |
| |
376 aims = e_contact_get(contact, E_CONTACT_IM_AIM); |
| |
377 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); |
| |
378 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); |
| |
379 msns = e_contact_get(contact, E_CONTACT_IM_MSN); |
| |
380 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); |
| |
381 novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE); |
| |
382 |
| |
383 if (aims == NULL && jabbers == NULL && yahoos == NULL && |
| |
384 msns == NULL && icqs == NULL && novells == NULL) |
| |
385 { |
| |
386 GtkTreeIter iter; |
| |
387 |
| |
388 gtk_list_store_append(dialog->model, &iter); |
| |
389 |
| |
390 gtk_list_store_set(dialog->model, &iter, |
| |
391 COLUMN_NAME, name, |
| |
392 COLUMN_DATA, contact, |
| |
393 -1); |
| |
394 } |
| |
395 else |
| |
396 { |
| |
397 add_ims(dialog, contact, name, aims, "prpl-oscar"); |
| |
398 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); |
| |
399 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); |
| |
400 add_ims(dialog, contact, name, msns, "prpl-msn"); |
| |
401 add_ims(dialog, contact, name, icqs, "prpl-oscar"); |
| |
402 add_ims(dialog, contact, name, novells, "prpl-novell"); |
| |
403 } |
| |
404 } |
| |
405 } |
| |
406 |
| |
407 static void |
| |
408 clear_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) |
| |
409 { |
| |
410 static gboolean lock = FALSE; |
| |
411 |
| |
412 if (lock) |
| |
413 return; |
| |
414 |
| |
415 lock = TRUE; |
| |
416 gtk_entry_set_text(GTK_ENTRY(dialog->search_field), ""); |
| |
417 lock = FALSE; |
| |
418 } |
| |
419 |
| |
420 void |
| |
421 gevo_add_buddy_dialog_show(PurpleAccount *account, const char *username, |
| |
422 const char *group, const char *alias) |
| |
423 { |
| |
424 GevoAddBuddyDialog *dialog; |
| |
425 GtkWidget *button; |
| |
426 GtkWidget *sw; |
| |
427 GtkWidget *label; |
| |
428 GtkWidget *vbox; |
| |
429 GtkWidget *hbox; |
| |
430 GtkWidget *bbox; |
| |
431 GtkWidget *sep; |
| |
432 GtkTreeSelection *selection; |
| |
433 GtkCellRenderer *cell; |
| |
434 |
| |
435 dialog = g_new0(GevoAddBuddyDialog, 1); |
| |
436 |
| |
437 dialog->account = |
| |
438 (account != NULL |
| |
439 ? account |
| |
440 : purple_connection_get_account(purple_connections_get_all()->data)); |
| |
441 |
| |
442 if (username != NULL) |
| |
443 dialog->username = g_strdup(username); |
| |
444 |
| |
445 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| |
446 gtk_window_set_role(GTK_WINDOW(dialog->win), "add_buddy"); |
| |
447 gtk_window_set_title(GTK_WINDOW(dialog->win), _("Add Buddy")); |
| |
448 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); |
| |
449 gtk_widget_set_size_request(dialog->win, -1, 400); |
| |
450 |
| |
451 g_signal_connect(G_OBJECT(dialog->win), "delete_event", |
| |
452 G_CALLBACK(delete_win_cb), dialog); |
| |
453 |
| |
454 /* Setup the vbox */ |
| |
455 vbox = gtk_vbox_new(FALSE, 12); |
| |
456 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); |
| |
457 gtk_widget_show(vbox); |
| |
458 |
| |
459 /* Add the label. */ |
| |
460 label = gtk_label_new(_("Select a person from your address book below, " |
| |
461 "or add a new person.")); |
| |
462 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
| |
463 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
| |
464 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); |
| |
465 gtk_widget_show(label); |
| |
466 |
| |
467 /* Add the search hbox */ |
| |
468 hbox = gtk_hbox_new(FALSE, 6); |
| |
469 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); |
| |
470 gtk_widget_show(hbox); |
| |
471 |
| |
472 /* "Search" */ |
| |
473 label = gtk_label_new(_("Search")); |
| |
474 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
| |
475 gtk_widget_show(label); |
| |
476 |
| |
477 /* Addressbooks */ |
| |
478 dialog->addrbooks = gevo_addrbooks_model_new(); |
| |
479 |
| |
480 dialog->addrbooks_combo = gtk_combo_box_new_with_model( |
| |
481 dialog->addrbooks); |
| |
482 cell = gtk_cell_renderer_text_new(); |
| |
483 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
| |
484 cell, TRUE); |
| |
485 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
| |
486 cell, |
| |
487 "text", ADDRBOOK_COLUMN_NAME, |
| |
488 NULL); |
| |
489 gtk_box_pack_start(GTK_BOX(hbox), dialog->addrbooks_combo, FALSE, |
| |
490 FALSE, 0); |
| |
491 gtk_widget_show(dialog->addrbooks_combo); |
| |
492 |
| |
493 /* Search field */ |
| |
494 dialog->search_field = gtk_entry_new(); |
| |
495 gtk_box_pack_start(GTK_BOX(hbox), dialog->search_field, TRUE, TRUE, 0); |
| |
496 gtk_widget_show(dialog->search_field); |
| |
497 |
| |
498 g_signal_connect(G_OBJECT(dialog->search_field), "changed", |
| |
499 G_CALLBACK(search_changed_cb), dialog); |
| |
500 |
| |
501 /* Clear button */ |
| |
502 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); |
| |
503 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
| |
504 gtk_widget_show(button); |
| |
505 |
| |
506 g_signal_connect(G_OBJECT(button), "clicked", |
| |
507 G_CALLBACK(clear_cb), dialog); |
| |
508 |
| |
509 /* Scrolled Window */ |
| |
510 sw = gtk_scrolled_window_new(0, 0); |
| |
511 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), |
| |
512 GTK_POLICY_AUTOMATIC, |
| |
513 GTK_POLICY_ALWAYS); |
| |
514 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), |
| |
515 GTK_SHADOW_IN); |
| |
516 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); |
| |
517 gtk_widget_show(sw); |
| |
518 |
| |
519 /* Create the list model for the treeview. */ |
| |
520 dialog->model = gtk_list_store_new(NUM_COLUMNS, |
| |
521 G_TYPE_STRING, GDK_TYPE_PIXBUF, |
| |
522 G_TYPE_STRING, G_TYPE_POINTER); |
| |
523 |
| |
524 /* Now for the treeview */ |
| |
525 dialog->treeview = |
| |
526 gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); |
| |
527 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); |
| |
528 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); |
| |
529 gtk_widget_show(dialog->treeview); |
| |
530 |
| |
531 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); |
| |
532 |
| |
533 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); |
| |
534 |
| |
535 g_signal_connect(G_OBJECT(selection), "changed", |
| |
536 G_CALLBACK(selected_cb), dialog); |
| |
537 |
| |
538 add_columns(dialog); |
| |
539 |
| |
540 /* |
| |
541 * Catch addressbook selection and populate treeview with the first |
| |
542 * addressbook |
| |
543 */ |
| |
544 gevo_addrbooks_model_populate(dialog->addrbooks); |
| |
545 g_signal_connect(G_OBJECT(dialog->addrbooks_combo), "changed", |
| |
546 G_CALLBACK(addrbook_change_cb), dialog); |
| |
547 gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->addrbooks_combo), 0); |
| |
548 |
| |
549 /* Group box */ |
| |
550 hbox = gtk_hbox_new(FALSE, 6); |
| |
551 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
| |
552 gtk_widget_show(hbox); |
| |
553 |
| |
554 label = gtk_label_new(_("Group:")); |
| |
555 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
| |
556 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
| |
557 gtk_widget_show(label); |
| |
558 |
| |
559 dialog->group_combo = gtk_combo_new(); |
| |
560 gtk_combo_set_popdown_strings(GTK_COMBO(dialog->group_combo), |
| |
561 gevo_get_groups()); |
| |
562 gtk_box_pack_start(GTK_BOX(hbox), dialog->group_combo, TRUE, TRUE, 0); |
| |
563 gtk_widget_show(dialog->group_combo); |
| |
564 |
| |
565 /* Cool. Now we only have a little left... */ |
| |
566 |
| |
567 /* Separator. */ |
| |
568 sep = gtk_hseparator_new(); |
| |
569 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); |
| |
570 gtk_widget_show(sep); |
| |
571 |
| |
572 /* Button box */ |
| |
573 bbox = gtk_hbutton_box_new(); |
| |
574 gtk_box_set_spacing(GTK_BOX(bbox), 6); |
| |
575 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
| |
576 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); |
| |
577 gtk_widget_show(bbox); |
| |
578 |
| |
579 /* "New Person" button */ |
| |
580 button = pidgin_pixbuf_button_from_stock(_("New Person"), GTK_STOCK_NEW, |
| |
581 PIDGIN_BUTTON_HORIZONTAL); |
| |
582 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
| |
583 gtk_widget_show(button); |
| |
584 |
| |
585 g_signal_connect(G_OBJECT(button), "clicked", |
| |
586 G_CALLBACK(new_person_cb), dialog); |
| |
587 |
| |
588 /* "Cancel" button */ |
| |
589 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); |
| |
590 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
| |
591 gtk_widget_show(button); |
| |
592 |
| |
593 g_signal_connect(G_OBJECT(button), "clicked", |
| |
594 G_CALLBACK(cancel_cb), dialog); |
| |
595 |
| |
596 /* "Select Buddy" button */ |
| |
597 button = pidgin_pixbuf_button_from_stock(_("Select Buddy"), GTK_STOCK_APPLY, |
| |
598 PIDGIN_BUTTON_HORIZONTAL); |
| |
599 dialog->select_button = button; |
| |
600 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
| |
601 gtk_widget_set_sensitive(button, FALSE); |
| |
602 gtk_widget_show(button); |
| |
603 |
| |
604 g_signal_connect(G_OBJECT(button), "clicked", |
| |
605 G_CALLBACK(select_buddy_cb), dialog); |
| |
606 |
| |
607 /* Show it. */ |
| |
608 gtk_widget_show(dialog->win); |
| |
609 } |
| |
610 |
| |
611 void |
| |
612 gevo_add_buddy_dialog_add_person(GevoAddBuddyDialog *dialog, |
| |
613 EContact *contact, const char *name, |
| |
614 PurpleAccount *account, const char *screenname) |
| |
615 { |
| |
616 GdkPixbuf *pixbuf; |
| |
617 GtkTreeIter iter; |
| |
618 |
| |
619 pixbuf = pidgin_create_prpl_icon(account, 0.5); |
| |
620 |
| |
621 gtk_list_store_append(dialog->model, &iter); |
| |
622 |
| |
623 gtk_list_store_set(dialog->model, &iter, |
| |
624 COLUMN_NAME, name, |
| |
625 COLUMN_PRPL_ICON, pixbuf, |
| |
626 COLUMN_DATA, contact, |
| |
627 COLUMN_USERNAME, screenname, |
| |
628 -1); |
| |
629 |
| |
630 if (contact != NULL) |
| |
631 dialog->contacts = g_list_append(dialog->contacts, contact); |
| |
632 |
| |
633 if (pixbuf != NULL) |
| |
634 g_object_unref(G_OBJECT(pixbuf)); |
| |
635 } |