Mercurial > pidgin.yaz
annotate plugins/gevolution/add_buddy_dialog.c @ 11572:7be60d01519f
[gaim-migrate @ 13840]
This should be more robust when dealing with different versions of iconv - we parse out the BOM and explicitly tell iconv what to do. This was lifted from the gtkhtml source. Ethan was concerned that some iconv implementations might be confused with the naming of the explicit charsets (UCS-2LE and UCS-2BE), so we should keep that in mind if people are having problems. This fixes the problem I was having that was caused by the BOM being removed by iconv during the UCS-2 to UTF-8 conversion. There is also some distracting whitespace fixing here to obscure any mistakes that I might have made.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 27 Sep 2005 14:26:11 +0000 |
parents | bc700cc98b82 |
children | 1f70f265cf27 |
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; | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
294 GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells; |
8089 | 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); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
303 novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE); |
8089 | 304 |
305 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
306 msns == NULL && icqs == NULL && novells == NULL) |
8089 | 307 { |
308 GtkTreeIter iter; | |
309 | |
310 gtk_list_store_append(dialog->model, &iter); | |
311 | |
312 gtk_list_store_set(dialog->model, &iter, | |
313 COLUMN_NAME, name, | |
314 COLUMN_DATA, contact, | |
315 -1); | |
316 } | |
317 else | |
318 { | |
319 add_ims(dialog, contact, name, aims, "prpl-oscar"); | |
320 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); | |
321 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); | |
322 add_ims(dialog, contact, name, msns, "prpl-msn"); | |
323 add_ims(dialog, contact, name, icqs, "prpl-oscar"); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
324 add_ims(dialog, contact, name, novells, "prpl-novell"); |
8089 | 325 } |
326 } | |
327 | |
328 dialog->contacts = cards; | |
329 dialog->book = book; | |
330 } | |
331 | |
332 static void | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
333 addrbook_change_cb(GtkComboBox *combo, GevoAddBuddyDialog *dialog) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
334 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
335 GtkTreeIter iter; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
336 const char *esource_uri; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
337 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
338 if (!gtk_combo_box_get_active_iter(combo, &iter)) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
339 return; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
340 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
341 gtk_tree_model_get(GTK_TREE_MODEL(dialog->addrbooks), &iter, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
342 ADDRBOOK_COLUMN_URI, &esource_uri, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
343 -1); |
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 populate_treeview(dialog, esource_uri); |
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 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
348 static void |
8089 | 349 selected_cb(GtkTreeSelection *sel, GevoAddBuddyDialog *dialog) |
350 { | |
351 gtk_widget_set_sensitive(dialog->select_button, TRUE); | |
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; | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
366 GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells; |
8089 | 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); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
381 novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE); |
8089 | 382 |
383 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
384 msns == NULL && icqs == NULL && novells == NULL) |
8089 | 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"); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
402 add_ims(dialog, contact, name, novells, "prpl-novell"); |
8089 | 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(GaimAccount *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; | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
433 GtkCellRenderer *cell; |
8089 | 434 |
435 dialog = g_new0(GevoAddBuddyDialog, 1); | |
436 | |
437 dialog->account = | |
438 (account != NULL | |
439 ? account | |
440 : gaim_connection_get_account(gaim_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_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
448 gtk_widget_set_size_request(dialog->win, -1, 400); | |
449 | |
450 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
451 G_CALLBACK(delete_win_cb), dialog); | |
452 | |
453 /* Setup the vbox */ | |
454 vbox = gtk_vbox_new(FALSE, 12); | |
455 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
456 gtk_widget_show(vbox); | |
457 | |
458 /* Add the label. */ | |
459 label = gtk_label_new(_("Select a person from your address book below, " | |
460 "or add a new person.")); | |
461 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
462 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
463 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
464 gtk_widget_show(label); | |
465 | |
466 /* Add the search hbox */ | |
467 hbox = gtk_hbox_new(FALSE, 6); | |
468 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); | |
469 gtk_widget_show(hbox); | |
470 | |
471 /* "Search" */ | |
472 label = gtk_label_new(_("Search")); | |
473 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
474 gtk_widget_show(label); | |
475 | |
476 /* Addressbooks */ | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
477 dialog->addrbooks = gevo_addrbooks_model_new(); |
8089 | 478 |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
479 dialog->addrbooks_combo = gtk_combo_box_new_with_model( |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
480 dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
481 cell = gtk_cell_renderer_text_new(); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
482 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
483 cell, TRUE); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
484 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
485 cell, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
486 "text", ADDRBOOK_COLUMN_NAME, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
487 NULL); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
488 gtk_box_pack_start(GTK_BOX(hbox), dialog->addrbooks_combo, FALSE, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
489 FALSE, 0); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
490 gtk_widget_show(dialog->addrbooks_combo); |
8089 | 491 |
492 /* Search field */ | |
493 dialog->search_field = gtk_entry_new(); | |
494 gtk_box_pack_start(GTK_BOX(hbox), dialog->search_field, TRUE, TRUE, 0); | |
495 gtk_widget_show(dialog->search_field); | |
496 | |
497 g_signal_connect(G_OBJECT(dialog->search_field), "changed", | |
498 G_CALLBACK(search_changed_cb), dialog); | |
499 | |
500 /* Clear button */ | |
501 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
502 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
503 gtk_widget_show(button); | |
504 | |
505 g_signal_connect(G_OBJECT(button), "clicked", | |
506 G_CALLBACK(clear_cb), dialog); | |
507 | |
508 /* Scrolled Window */ | |
509 sw = gtk_scrolled_window_new(0, 0); | |
510 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
511 GTK_POLICY_AUTOMATIC, | |
512 GTK_POLICY_ALWAYS); | |
513 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
514 GTK_SHADOW_IN); | |
515 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
516 gtk_widget_show(sw); | |
517 | |
518 /* Create the list model for the treeview. */ | |
519 dialog->model = gtk_list_store_new(NUM_COLUMNS, | |
520 G_TYPE_STRING, GDK_TYPE_PIXBUF, | |
521 G_TYPE_STRING, G_TYPE_POINTER); | |
522 | |
523 /* Now for the treeview */ | |
524 dialog->treeview = | |
525 gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
526 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
527 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
528 gtk_widget_show(dialog->treeview); | |
529 | |
530 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
531 | |
532 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
533 | |
534 g_signal_connect(G_OBJECT(selection), "changed", | |
535 G_CALLBACK(selected_cb), dialog); | |
536 | |
537 add_columns(dialog); | |
538 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
539 /* |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
540 * Catch addressbook selection and populate treeview with the first |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
541 * addressbook |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
542 */ |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
543 gevo_addrbooks_model_populate(dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
544 g_signal_connect(G_OBJECT(dialog->addrbooks_combo), "changed", |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
545 G_CALLBACK(addrbook_change_cb), dialog); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
546 gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->addrbooks_combo), 0); |
8089 | 547 |
548 /* Group box */ | |
549 hbox = gtk_hbox_new(FALSE, 6); | |
550 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
551 gtk_widget_show(hbox); | |
552 | |
553 label = gtk_label_new(_("Group:")); | |
554 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
555 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
556 gtk_widget_show(label); | |
557 | |
558 dialog->group_combo = gtk_combo_new(); | |
559 gtk_combo_set_popdown_strings(GTK_COMBO(dialog->group_combo), | |
560 gevo_get_groups()); | |
561 gtk_box_pack_start(GTK_BOX(hbox), dialog->group_combo, TRUE, TRUE, 0); | |
562 gtk_widget_show(dialog->group_combo); | |
563 | |
564 /* Cool. Now we only have a little left... */ | |
565 | |
566 /* Separator. */ | |
567 sep = gtk_hseparator_new(); | |
568 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
569 gtk_widget_show(sep); | |
570 | |
571 /* Button box */ | |
572 bbox = gtk_hbutton_box_new(); | |
573 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
574 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
575 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
576 gtk_widget_show(bbox); | |
577 | |
578 /* "New Person" button */ | |
579 button = gaim_pixbuf_button_from_stock(_("New Person"), GTK_STOCK_NEW, | |
580 GAIM_BUTTON_HORIZONTAL); | |
581 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
582 gtk_widget_show(button); | |
583 | |
584 g_signal_connect(G_OBJECT(button), "clicked", | |
585 G_CALLBACK(new_person_cb), dialog); | |
586 | |
587 /* "Cancel" button */ | |
588 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
589 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
590 gtk_widget_show(button); | |
591 | |
592 g_signal_connect(G_OBJECT(button), "clicked", | |
593 G_CALLBACK(cancel_cb), dialog); | |
594 | |
595 /* "Select Buddy" button */ | |
596 button = gaim_pixbuf_button_from_stock(_("Select Buddy"), GTK_STOCK_APPLY, | |
597 GAIM_BUTTON_HORIZONTAL); | |
598 dialog->select_button = button; | |
599 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
600 gtk_widget_set_sensitive(button, FALSE); | |
601 gtk_widget_show(button); | |
602 | |
603 g_signal_connect(G_OBJECT(button), "clicked", | |
604 G_CALLBACK(select_buddy_cb), dialog); | |
605 | |
606 /* Show it. */ | |
607 gtk_widget_show(dialog->win); | |
608 } | |
609 | |
610 void | |
611 gevo_add_buddy_dialog_add_person(GevoAddBuddyDialog *dialog, | |
612 EContact *contact, const char *name, | |
613 GaimAccount *account, const char *screenname) | |
614 { | |
615 GdkPixbuf *pixbuf, *icon = NULL; | |
616 GtkTreeIter iter; | |
617 | |
10884 | 618 pixbuf = gaim_gtk_create_prpl_icon(account); |
8089 | 619 |
620 if (pixbuf != NULL) | |
621 icon = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
622 | |
623 gtk_list_store_append(dialog->model, &iter); | |
624 | |
625 gtk_list_store_set(dialog->model, &iter, | |
626 COLUMN_NAME, name, | |
627 COLUMN_PRPL_ICON, icon, | |
628 COLUMN_DATA, contact, | |
629 COLUMN_USERNAME, screenname, | |
630 -1); | |
631 | |
632 if (contact != NULL) | |
633 dialog->contacts = g_list_append(dialog->contacts, contact); | |
634 | |
635 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
636 if (icon != NULL) g_object_unref(G_OBJECT(icon)); | |
637 } |