Mercurial > pidgin.yaz
annotate plugins/gevolution/add_buddy_dialog.c @ 10964:aae07c7e23a3
[gaim-migrate @ 12771]
By popular demand, double click behavior on the buddy tag has been restored to standard text behavior. Underline the text contained in the tag to provide some indication that you can do something with it.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Thu, 02 Jun 2005 02:15:25 +0000 |
parents | 5cda52915a1f |
children | bc700cc98b82 |
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 #include <bonobo/bonobo-main.h> | |
32 | |
33 enum | |
34 { | |
35 COLUMN_NAME, | |
36 COLUMN_PRPL_ICON, | |
37 COLUMN_USERNAME, | |
38 COLUMN_DATA, | |
39 NUM_COLUMNS | |
40 }; | |
41 | |
42 static gint | |
43 delete_win_cb(GtkWidget *w, GdkEvent *event, GevoAddBuddyDialog *dialog) | |
44 { | |
45 gtk_widget_destroy(dialog->win); | |
46 | |
47 if (dialog->contacts != NULL) | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
48 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
49 g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL); |
8089 | 50 g_list_free(dialog->contacts); |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
51 } |
8089 | 52 |
53 if (dialog->book != NULL) | |
54 g_object_unref(dialog->book); | |
55 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
56 gevo_addrbooks_model_unref(dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
57 |
8089 | 58 if (dialog->username != NULL) |
59 g_free(dialog->username); | |
60 | |
61 g_free(dialog); | |
62 | |
63 return 0; | |
64 } | |
65 | |
66 static void | |
67 new_person_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
68 { | |
69 const char *group_name; | |
70 | |
71 group_name = | |
72 gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(dialog->group_combo)->entry)); | |
73 | |
10830 | 74 gevo_new_person_dialog_show(dialog->book, NULL, dialog->account, dialog->username, |
8089 | 75 (*group_name ? group_name : NULL), |
76 NULL, FALSE); | |
77 | |
78 delete_win_cb(NULL, NULL, dialog); | |
79 } | |
80 | |
81 static void | |
82 cancel_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
83 { | |
84 delete_win_cb(NULL, NULL, dialog); | |
85 } | |
86 | |
87 static void | |
88 select_buddy_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
89 { | |
90 GtkTreeSelection *selection; | |
91 GtkTreeIter iter; | |
92 const char *group_name; | |
93 const char *fullname; | |
94 const char *username; | |
95 EContact *contact; | |
96 | |
97 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
98 | |
99 gtk_tree_selection_get_selected(selection, NULL, &iter); | |
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 { | |
10830 | 112 gevo_new_person_dialog_show(dialog->book, NULL, dialog->account, dialog->username, |
8089 | 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 GaimAccount *account = NULL; | |
165 GList *l; | |
166 GtkTreeIter iter; | |
167 GdkPixbuf *pixbuf, *icon = NULL; | |
168 | |
169 if (list == NULL) | |
170 return; | |
171 | |
172 for (l = gaim_connections_get_all(); l != NULL; l = l->next) | |
173 { | |
174 GaimConnection *gc = (GaimConnection *)l->data; | |
175 | |
176 account = gaim_connection_get_account(gc); | |
177 | |
178 if (!strcmp(gaim_account_get_protocol_id(account), id)) | |
179 break; | |
180 | |
181 account = NULL; | |
182 } | |
183 | |
184 if (account == NULL) | |
185 return; | |
186 | |
10884 | 187 pixbuf = gaim_gtk_create_prpl_icon(account); |
8089 | 188 |
189 if (pixbuf != NULL) | |
190 icon = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
191 GDK_INTERP_BILINEAR); | |
192 | |
193 for (l = list; l != NULL; l = l->next) | |
194 { | |
195 char *account_name = (char *)l->data; | |
196 | |
197 if (account_name == NULL) | |
198 continue; | |
199 | |
200 if (gaim_find_buddy(dialog->account, account_name) != NULL) | |
201 continue; | |
202 | |
203 gtk_list_store_append(dialog->model, &iter); | |
204 | |
205 gtk_list_store_set(dialog->model, &iter, | |
206 COLUMN_NAME, name, | |
207 COLUMN_PRPL_ICON, icon, | |
208 COLUMN_USERNAME, account_name, | |
209 COLUMN_DATA, contact, | |
210 -1); | |
211 | |
212 if (!strcmp(gaim_account_get_protocol_id(account), | |
213 gaim_account_get_protocol_id(dialog->account)) && | |
214 dialog->username != NULL && | |
215 !strcmp(account_name, dialog->username)) | |
216 { | |
217 GtkTreeSelection *selection; | |
218 | |
219 /* This is it. Select it. */ | |
220 selection = gtk_tree_view_get_selection( | |
221 GTK_TREE_VIEW(dialog->treeview)); | |
222 | |
223 gtk_tree_selection_select_iter(selection, &iter); | |
224 } | |
225 } | |
226 | |
227 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
228 if (icon != NULL) g_object_unref(G_OBJECT(icon)); | |
229 | |
230 g_list_foreach(list, (GFunc)g_free, NULL); | |
231 g_list_free(list); | |
232 } | |
233 | |
234 static void | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
235 populate_treeview(GevoAddBuddyDialog *dialog, const gchar *uri) |
8089 | 236 { |
237 EBookQuery *query; | |
238 EBook *book; | |
239 gboolean status; | |
240 GList *cards, *c; | |
241 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
242 if (dialog->book != NULL) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
243 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
244 g_object_unref(dialog->book); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
245 dialog->book = NULL; |
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 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
248 if (dialog->contacts != NULL) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
249 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
250 g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
251 g_list_free(dialog->contacts); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
252 dialog->contacts = NULL; |
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 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
255 gtk_list_store_clear(dialog->model); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
256 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
257 if (!gevo_load_addressbook(uri, &book, NULL)) |
8089 | 258 { |
259 gaim_debug_error("evolution", | |
260 "Error retrieving default addressbook\n"); | |
261 | |
262 return; | |
263 } | |
264 | |
265 query = e_book_query_field_exists(E_CONTACT_FULL_NAME); | |
266 | |
267 if (query == NULL) | |
268 { | |
269 gaim_debug_error("evolution", "Error in creating query\n"); | |
270 | |
271 g_object_unref(book); | |
272 | |
273 return; | |
274 } | |
275 | |
276 status = e_book_get_contacts(book, query, &cards, NULL); | |
277 | |
278 e_book_query_unref(query); | |
279 | |
280 if (!status) | |
281 { | |
282 gaim_debug_error("evolution", "Error %d in getting card list\n", | |
283 status); | |
284 | |
285 g_object_unref(book); | |
286 | |
287 return; | |
288 } | |
289 | |
290 for (c = cards; c != NULL; c = c->next) | |
291 { | |
292 EContact *contact = E_CONTACT(c->data); | |
293 const char *name; | |
294 GList *aims, *jabbers, *yahoos, *msns, *icqs; | |
295 | |
296 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
297 | |
298 aims = e_contact_get(contact, E_CONTACT_IM_AIM); | |
299 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); | |
300 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); | |
301 msns = e_contact_get(contact, E_CONTACT_IM_MSN); | |
302 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); | |
303 | |
304 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
305 msns == NULL && icqs == NULL) | |
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"); | |
323 } | |
324 } | |
325 | |
326 dialog->contacts = cards; | |
327 dialog->book = book; | |
328 } | |
329 | |
330 static void | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
331 addrbook_change_cb(GtkComboBox *combo, GevoAddBuddyDialog *dialog) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
332 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
333 GtkTreeIter iter; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
334 const char *esource_uri; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
335 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
336 if (!gtk_combo_box_get_active_iter(combo, &iter)) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
337 return; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
338 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
339 gtk_tree_model_get(GTK_TREE_MODEL(dialog->addrbooks), &iter, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
340 ADDRBOOK_COLUMN_URI, &esource_uri, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
341 -1); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
342 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
343 populate_treeview(dialog, esource_uri); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
344 } |
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 static void |
8089 | 347 selected_cb(GtkTreeSelection *sel, GevoAddBuddyDialog *dialog) |
348 { | |
349 gtk_widget_set_sensitive(dialog->select_button, TRUE); | |
350 } | |
351 | |
352 static void | |
353 search_changed_cb(GtkEntry *entry, GevoAddBuddyDialog *dialog) | |
354 { | |
355 const char *text = gtk_entry_get_text(entry); | |
356 GList *l; | |
357 | |
358 gtk_list_store_clear(dialog->model); | |
359 | |
360 for (l = dialog->contacts; l != NULL; l = l->next) | |
361 { | |
362 EContact *contact = E_CONTACT(l->data); | |
363 const char *name; | |
364 GList *aims, *jabbers, *yahoos, *msns, *icqs; | |
365 | |
366 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
367 | |
368 if (text != NULL && *text != '\0' && name != NULL && | |
369 g_ascii_strncasecmp(name, text, strlen(text))) | |
370 { | |
371 continue; | |
372 } | |
373 | |
374 aims = e_contact_get(contact, E_CONTACT_IM_AIM); | |
375 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); | |
376 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); | |
377 msns = e_contact_get(contact, E_CONTACT_IM_MSN); | |
378 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); | |
379 | |
380 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
381 msns == NULL && icqs == NULL) | |
382 { | |
383 GtkTreeIter iter; | |
384 | |
385 gtk_list_store_append(dialog->model, &iter); | |
386 | |
387 gtk_list_store_set(dialog->model, &iter, | |
388 COLUMN_NAME, name, | |
389 COLUMN_DATA, contact, | |
390 -1); | |
391 } | |
392 else | |
393 { | |
394 add_ims(dialog, contact, name, aims, "prpl-oscar"); | |
395 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); | |
396 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); | |
397 add_ims(dialog, contact, name, msns, "prpl-msn"); | |
398 add_ims(dialog, contact, name, icqs, "prpl-oscar"); | |
399 } | |
400 } | |
401 } | |
402 | |
403 static void | |
404 clear_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
405 { | |
406 static gboolean lock = FALSE; | |
407 | |
408 if (lock) | |
409 return; | |
410 | |
411 lock = TRUE; | |
412 gtk_entry_set_text(GTK_ENTRY(dialog->search_field), ""); | |
413 lock = FALSE; | |
414 } | |
415 | |
416 void | |
417 gevo_add_buddy_dialog_show(GaimAccount *account, const char *username, | |
418 const char *group, const char *alias) | |
419 { | |
420 GevoAddBuddyDialog *dialog; | |
421 GtkWidget *button; | |
422 GtkWidget *sw; | |
423 GtkWidget *label; | |
424 GtkWidget *vbox; | |
425 GtkWidget *hbox; | |
426 GtkWidget *bbox; | |
427 GtkWidget *sep; | |
428 GtkTreeSelection *selection; | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
429 GtkCellRenderer *cell; |
8089 | 430 |
431 dialog = g_new0(GevoAddBuddyDialog, 1); | |
432 | |
433 dialog->account = | |
434 (account != NULL | |
435 ? account | |
436 : gaim_connection_get_account(gaim_connections_get_all()->data)); | |
437 | |
438 if (username != NULL) | |
439 dialog->username = g_strdup(username); | |
440 | |
441 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
442 gtk_window_set_role(GTK_WINDOW(dialog->win), "add_buddy"); | |
443 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
444 gtk_widget_set_size_request(dialog->win, -1, 400); | |
445 | |
446 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
447 G_CALLBACK(delete_win_cb), dialog); | |
448 | |
449 /* Setup the vbox */ | |
450 vbox = gtk_vbox_new(FALSE, 12); | |
451 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
452 gtk_widget_show(vbox); | |
453 | |
454 /* Add the label. */ | |
455 label = gtk_label_new(_("Select a person from your address book below, " | |
456 "or add a new person.")); | |
457 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
458 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
459 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
460 gtk_widget_show(label); | |
461 | |
462 /* Add the search hbox */ | |
463 hbox = gtk_hbox_new(FALSE, 6); | |
464 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); | |
465 gtk_widget_show(hbox); | |
466 | |
467 /* "Search" */ | |
468 label = gtk_label_new(_("Search")); | |
469 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
470 gtk_widget_show(label); | |
471 | |
472 /* Addressbooks */ | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
473 dialog->addrbooks = gevo_addrbooks_model_new(); |
8089 | 474 |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
475 dialog->addrbooks_combo = gtk_combo_box_new_with_model( |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
476 dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
477 cell = gtk_cell_renderer_text_new(); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
478 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
479 cell, TRUE); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
480 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
481 cell, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
482 "text", ADDRBOOK_COLUMN_NAME, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
483 NULL); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
484 gtk_box_pack_start(GTK_BOX(hbox), dialog->addrbooks_combo, FALSE, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
485 FALSE, 0); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
486 gtk_widget_show(dialog->addrbooks_combo); |
8089 | 487 |
488 /* Search field */ | |
489 dialog->search_field = gtk_entry_new(); | |
490 gtk_box_pack_start(GTK_BOX(hbox), dialog->search_field, TRUE, TRUE, 0); | |
491 gtk_widget_show(dialog->search_field); | |
492 | |
493 g_signal_connect(G_OBJECT(dialog->search_field), "changed", | |
494 G_CALLBACK(search_changed_cb), dialog); | |
495 | |
496 /* Clear button */ | |
497 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
498 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
499 gtk_widget_show(button); | |
500 | |
501 g_signal_connect(G_OBJECT(button), "clicked", | |
502 G_CALLBACK(clear_cb), dialog); | |
503 | |
504 /* Scrolled Window */ | |
505 sw = gtk_scrolled_window_new(0, 0); | |
506 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
507 GTK_POLICY_AUTOMATIC, | |
508 GTK_POLICY_ALWAYS); | |
509 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
510 GTK_SHADOW_IN); | |
511 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
512 gtk_widget_show(sw); | |
513 | |
514 /* Create the list model for the treeview. */ | |
515 dialog->model = gtk_list_store_new(NUM_COLUMNS, | |
516 G_TYPE_STRING, GDK_TYPE_PIXBUF, | |
517 G_TYPE_STRING, G_TYPE_POINTER); | |
518 | |
519 /* Now for the treeview */ | |
520 dialog->treeview = | |
521 gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
522 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
523 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
524 gtk_widget_show(dialog->treeview); | |
525 | |
526 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
527 | |
528 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
529 | |
530 g_signal_connect(G_OBJECT(selection), "changed", | |
531 G_CALLBACK(selected_cb), dialog); | |
532 | |
533 add_columns(dialog); | |
534 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
535 /* |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
536 * Catch addressbook selection and populate treeview with the first |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
537 * addressbook |
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 gevo_addrbooks_model_populate(dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
540 g_signal_connect(G_OBJECT(dialog->addrbooks_combo), "changed", |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
541 G_CALLBACK(addrbook_change_cb), dialog); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
542 gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->addrbooks_combo), 0); |
8089 | 543 |
544 /* Group box */ | |
545 hbox = gtk_hbox_new(FALSE, 6); | |
546 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
547 gtk_widget_show(hbox); | |
548 | |
549 label = gtk_label_new(_("Group:")); | |
550 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
551 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
552 gtk_widget_show(label); | |
553 | |
554 dialog->group_combo = gtk_combo_new(); | |
555 gtk_combo_set_popdown_strings(GTK_COMBO(dialog->group_combo), | |
556 gevo_get_groups()); | |
557 gtk_box_pack_start(GTK_BOX(hbox), dialog->group_combo, TRUE, TRUE, 0); | |
558 gtk_widget_show(dialog->group_combo); | |
559 | |
560 /* Cool. Now we only have a little left... */ | |
561 | |
562 /* Separator. */ | |
563 sep = gtk_hseparator_new(); | |
564 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
565 gtk_widget_show(sep); | |
566 | |
567 /* Button box */ | |
568 bbox = gtk_hbutton_box_new(); | |
569 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
570 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
571 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
572 gtk_widget_show(bbox); | |
573 | |
574 /* "New Person" button */ | |
575 button = gaim_pixbuf_button_from_stock(_("New Person"), GTK_STOCK_NEW, | |
576 GAIM_BUTTON_HORIZONTAL); | |
577 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
578 gtk_widget_show(button); | |
579 | |
580 g_signal_connect(G_OBJECT(button), "clicked", | |
581 G_CALLBACK(new_person_cb), dialog); | |
582 | |
583 /* "Cancel" button */ | |
584 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
585 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
586 gtk_widget_show(button); | |
587 | |
588 g_signal_connect(G_OBJECT(button), "clicked", | |
589 G_CALLBACK(cancel_cb), dialog); | |
590 | |
591 /* "Select Buddy" button */ | |
592 button = gaim_pixbuf_button_from_stock(_("Select Buddy"), GTK_STOCK_APPLY, | |
593 GAIM_BUTTON_HORIZONTAL); | |
594 dialog->select_button = button; | |
595 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
596 gtk_widget_set_sensitive(button, FALSE); | |
597 gtk_widget_show(button); | |
598 | |
599 g_signal_connect(G_OBJECT(button), "clicked", | |
600 G_CALLBACK(select_buddy_cb), dialog); | |
601 | |
602 /* Show it. */ | |
603 gtk_widget_show(dialog->win); | |
604 } | |
605 | |
606 void | |
607 gevo_add_buddy_dialog_add_person(GevoAddBuddyDialog *dialog, | |
608 EContact *contact, const char *name, | |
609 GaimAccount *account, const char *screenname) | |
610 { | |
611 GdkPixbuf *pixbuf, *icon = NULL; | |
612 GtkTreeIter iter; | |
613 | |
10884 | 614 pixbuf = gaim_gtk_create_prpl_icon(account); |
8089 | 615 |
616 if (pixbuf != NULL) | |
617 icon = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
618 | |
619 gtk_list_store_append(dialog->model, &iter); | |
620 | |
621 gtk_list_store_set(dialog->model, &iter, | |
622 COLUMN_NAME, name, | |
623 COLUMN_PRPL_ICON, icon, | |
624 COLUMN_DATA, contact, | |
625 COLUMN_USERNAME, screenname, | |
626 -1); | |
627 | |
628 if (contact != NULL) | |
629 dialog->contacts = g_list_append(dialog->contacts, contact); | |
630 | |
631 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
632 if (icon != NULL) g_object_unref(G_OBJECT(icon)); | |
633 } |