Mercurial > pidgin.yaz
annotate plugins/gevolution/add_buddy_dialog.c @ 13216:0ce20e0a1396
[gaim-migrate @ 15580]
Bj??rn Voigt noticed there was no more check for setlocale:
"Do you know, why HAVE_SETLOCALE is not available any more? Probably this has something to do with the intltool patch."
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 10 Feb 2006 21:22:09 +0000 |
parents | 0aa231ebbfd5 |
children | d2e5a9f2c174 |
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; | |
13090 | 166 GdkPixbuf *pixbuf; |
8089 | 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 | |
13090 | 186 pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); |
8089 | 187 |
188 for (l = list; l != NULL; l = l->next) | |
189 { | |
190 char *account_name = (char *)l->data; | |
191 | |
192 if (account_name == NULL) | |
193 continue; | |
194 | |
195 if (gaim_find_buddy(dialog->account, account_name) != NULL) | |
196 continue; | |
197 | |
198 gtk_list_store_append(dialog->model, &iter); | |
199 | |
200 gtk_list_store_set(dialog->model, &iter, | |
201 COLUMN_NAME, name, | |
13090 | 202 COLUMN_PRPL_ICON, pixbuf, |
8089 | 203 COLUMN_USERNAME, account_name, |
204 COLUMN_DATA, contact, | |
205 -1); | |
206 | |
207 if (!strcmp(gaim_account_get_protocol_id(account), | |
208 gaim_account_get_protocol_id(dialog->account)) && | |
209 dialog->username != NULL && | |
210 !strcmp(account_name, dialog->username)) | |
211 { | |
212 GtkTreeSelection *selection; | |
213 | |
214 /* This is it. Select it. */ | |
215 selection = gtk_tree_view_get_selection( | |
216 GTK_TREE_VIEW(dialog->treeview)); | |
217 | |
218 gtk_tree_selection_select_iter(selection, &iter); | |
219 } | |
220 } | |
221 | |
13090 | 222 if (pixbuf != NULL) |
223 g_object_unref(G_OBJECT(pixbuf)); | |
8089 | 224 |
225 g_list_foreach(list, (GFunc)g_free, NULL); | |
226 g_list_free(list); | |
227 } | |
228 | |
229 static void | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
230 populate_treeview(GevoAddBuddyDialog *dialog, const gchar *uri) |
8089 | 231 { |
232 EBookQuery *query; | |
233 EBook *book; | |
234 gboolean status; | |
235 GList *cards, *c; | |
236 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
237 if (dialog->book != NULL) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
238 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
239 g_object_unref(dialog->book); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
240 dialog->book = NULL; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
241 } |
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 if (dialog->contacts != NULL) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
244 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
245 g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
246 g_list_free(dialog->contacts); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
247 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 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
250 gtk_list_store_clear(dialog->model); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
251 |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
252 if (!gevo_load_addressbook(uri, &book, NULL)) |
8089 | 253 { |
254 gaim_debug_error("evolution", | |
255 "Error retrieving default addressbook\n"); | |
256 | |
257 return; | |
258 } | |
259 | |
260 query = e_book_query_field_exists(E_CONTACT_FULL_NAME); | |
261 | |
262 if (query == NULL) | |
263 { | |
264 gaim_debug_error("evolution", "Error in creating query\n"); | |
265 | |
266 g_object_unref(book); | |
267 | |
268 return; | |
269 } | |
270 | |
271 status = e_book_get_contacts(book, query, &cards, NULL); | |
272 | |
273 e_book_query_unref(query); | |
274 | |
275 if (!status) | |
276 { | |
277 gaim_debug_error("evolution", "Error %d in getting card list\n", | |
278 status); | |
279 | |
280 g_object_unref(book); | |
281 | |
282 return; | |
283 } | |
284 | |
285 for (c = cards; c != NULL; c = c->next) | |
286 { | |
287 EContact *contact = E_CONTACT(c->data); | |
288 const char *name; | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
289 GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells; |
8089 | 290 |
291 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
292 | |
293 aims = e_contact_get(contact, E_CONTACT_IM_AIM); | |
294 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); | |
295 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); | |
296 msns = e_contact_get(contact, E_CONTACT_IM_MSN); | |
297 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
298 novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE); |
8089 | 299 |
300 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
301 msns == NULL && icqs == NULL && novells == NULL) |
8089 | 302 { |
303 GtkTreeIter iter; | |
304 | |
305 gtk_list_store_append(dialog->model, &iter); | |
306 | |
307 gtk_list_store_set(dialog->model, &iter, | |
308 COLUMN_NAME, name, | |
309 COLUMN_DATA, contact, | |
310 -1); | |
311 } | |
312 else | |
313 { | |
314 add_ims(dialog, contact, name, aims, "prpl-oscar"); | |
315 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); | |
316 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); | |
317 add_ims(dialog, contact, name, msns, "prpl-msn"); | |
318 add_ims(dialog, contact, name, icqs, "prpl-oscar"); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
319 add_ims(dialog, contact, name, novells, "prpl-novell"); |
8089 | 320 } |
321 } | |
322 | |
323 dialog->contacts = cards; | |
324 dialog->book = book; | |
325 } | |
326 | |
327 static void | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
328 addrbook_change_cb(GtkComboBox *combo, GevoAddBuddyDialog *dialog) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
329 { |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
330 GtkTreeIter iter; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
331 const char *esource_uri; |
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 if (!gtk_combo_box_get_active_iter(combo, &iter)) |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
334 return; |
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 gtk_tree_model_get(GTK_TREE_MODEL(dialog->addrbooks), &iter, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
337 ADDRBOOK_COLUMN_URI, &esource_uri, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
338 -1); |
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 populate_treeview(dialog, esource_uri); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
341 } |
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 static void |
8089 | 344 selected_cb(GtkTreeSelection *sel, GevoAddBuddyDialog *dialog) |
345 { | |
346 gtk_widget_set_sensitive(dialog->select_button, TRUE); | |
347 } | |
348 | |
349 static void | |
350 search_changed_cb(GtkEntry *entry, GevoAddBuddyDialog *dialog) | |
351 { | |
352 const char *text = gtk_entry_get_text(entry); | |
353 GList *l; | |
354 | |
355 gtk_list_store_clear(dialog->model); | |
356 | |
357 for (l = dialog->contacts; l != NULL; l = l->next) | |
358 { | |
359 EContact *contact = E_CONTACT(l->data); | |
360 const char *name; | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
361 GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells; |
8089 | 362 |
363 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
364 | |
365 if (text != NULL && *text != '\0' && name != NULL && | |
366 g_ascii_strncasecmp(name, text, strlen(text))) | |
367 { | |
368 continue; | |
369 } | |
370 | |
371 aims = e_contact_get(contact, E_CONTACT_IM_AIM); | |
372 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); | |
373 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); | |
374 msns = e_contact_get(contact, E_CONTACT_IM_MSN); | |
375 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
376 novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE); |
8089 | 377 |
378 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
379 msns == NULL && icqs == NULL && novells == NULL) |
8089 | 380 { |
381 GtkTreeIter iter; | |
382 | |
383 gtk_list_store_append(dialog->model, &iter); | |
384 | |
385 gtk_list_store_set(dialog->model, &iter, | |
386 COLUMN_NAME, name, | |
387 COLUMN_DATA, contact, | |
388 -1); | |
389 } | |
390 else | |
391 { | |
392 add_ims(dialog, contact, name, aims, "prpl-oscar"); | |
393 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); | |
394 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); | |
395 add_ims(dialog, contact, name, msns, "prpl-msn"); | |
396 add_ims(dialog, contact, name, icqs, "prpl-oscar"); | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10884
diff
changeset
|
397 add_ims(dialog, contact, name, novells, "prpl-novell"); |
8089 | 398 } |
399 } | |
400 } | |
401 | |
402 static void | |
403 clear_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
404 { | |
405 static gboolean lock = FALSE; | |
406 | |
407 if (lock) | |
408 return; | |
409 | |
410 lock = TRUE; | |
411 gtk_entry_set_text(GTK_ENTRY(dialog->search_field), ""); | |
412 lock = FALSE; | |
413 } | |
414 | |
415 void | |
416 gevo_add_buddy_dialog_show(GaimAccount *account, const char *username, | |
417 const char *group, const char *alias) | |
418 { | |
419 GevoAddBuddyDialog *dialog; | |
420 GtkWidget *button; | |
421 GtkWidget *sw; | |
422 GtkWidget *label; | |
423 GtkWidget *vbox; | |
424 GtkWidget *hbox; | |
425 GtkWidget *bbox; | |
426 GtkWidget *sep; | |
427 GtkTreeSelection *selection; | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
428 GtkCellRenderer *cell; |
8089 | 429 |
430 dialog = g_new0(GevoAddBuddyDialog, 1); | |
431 | |
432 dialog->account = | |
433 (account != NULL | |
434 ? account | |
435 : gaim_connection_get_account(gaim_connections_get_all()->data)); | |
436 | |
437 if (username != NULL) | |
438 dialog->username = g_strdup(username); | |
439 | |
440 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
441 gtk_window_set_role(GTK_WINDOW(dialog->win), "add_buddy"); | |
442 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
443 gtk_widget_set_size_request(dialog->win, -1, 400); | |
444 | |
445 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
446 G_CALLBACK(delete_win_cb), dialog); | |
447 | |
448 /* Setup the vbox */ | |
449 vbox = gtk_vbox_new(FALSE, 12); | |
450 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
451 gtk_widget_show(vbox); | |
452 | |
453 /* Add the label. */ | |
454 label = gtk_label_new(_("Select a person from your address book below, " | |
455 "or add a new person.")); | |
456 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
457 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
458 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
459 gtk_widget_show(label); | |
460 | |
461 /* Add the search hbox */ | |
462 hbox = gtk_hbox_new(FALSE, 6); | |
463 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); | |
464 gtk_widget_show(hbox); | |
465 | |
466 /* "Search" */ | |
467 label = gtk_label_new(_("Search")); | |
468 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
469 gtk_widget_show(label); | |
470 | |
471 /* Addressbooks */ | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
472 dialog->addrbooks = gevo_addrbooks_model_new(); |
8089 | 473 |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
474 dialog->addrbooks_combo = gtk_combo_box_new_with_model( |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
475 dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
476 cell = gtk_cell_renderer_text_new(); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
477 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
478 cell, TRUE); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
479 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
480 cell, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
481 "text", ADDRBOOK_COLUMN_NAME, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
482 NULL); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
483 gtk_box_pack_start(GTK_BOX(hbox), dialog->addrbooks_combo, FALSE, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
484 FALSE, 0); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
485 gtk_widget_show(dialog->addrbooks_combo); |
8089 | 486 |
487 /* Search field */ | |
488 dialog->search_field = gtk_entry_new(); | |
489 gtk_box_pack_start(GTK_BOX(hbox), dialog->search_field, TRUE, TRUE, 0); | |
490 gtk_widget_show(dialog->search_field); | |
491 | |
492 g_signal_connect(G_OBJECT(dialog->search_field), "changed", | |
493 G_CALLBACK(search_changed_cb), dialog); | |
494 | |
495 /* Clear button */ | |
496 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
497 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
498 gtk_widget_show(button); | |
499 | |
500 g_signal_connect(G_OBJECT(button), "clicked", | |
501 G_CALLBACK(clear_cb), dialog); | |
502 | |
503 /* Scrolled Window */ | |
504 sw = gtk_scrolled_window_new(0, 0); | |
505 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
506 GTK_POLICY_AUTOMATIC, | |
507 GTK_POLICY_ALWAYS); | |
508 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
509 GTK_SHADOW_IN); | |
510 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
511 gtk_widget_show(sw); | |
512 | |
513 /* Create the list model for the treeview. */ | |
514 dialog->model = gtk_list_store_new(NUM_COLUMNS, | |
515 G_TYPE_STRING, GDK_TYPE_PIXBUF, | |
516 G_TYPE_STRING, G_TYPE_POINTER); | |
517 | |
518 /* Now for the treeview */ | |
519 dialog->treeview = | |
520 gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
521 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
522 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
523 gtk_widget_show(dialog->treeview); | |
524 | |
525 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
526 | |
527 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
528 | |
529 g_signal_connect(G_OBJECT(selection), "changed", | |
530 G_CALLBACK(selected_cb), dialog); | |
531 | |
532 add_columns(dialog); | |
533 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
534 /* |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
535 * Catch addressbook selection and populate treeview with the first |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
536 * addressbook |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
537 */ |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
538 gevo_addrbooks_model_populate(dialog->addrbooks); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
539 g_signal_connect(G_OBJECT(dialog->addrbooks_combo), "changed", |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
540 G_CALLBACK(addrbook_change_cb), dialog); |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
541 gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->addrbooks_combo), 0); |
8089 | 542 |
543 /* Group box */ | |
544 hbox = gtk_hbox_new(FALSE, 6); | |
545 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
546 gtk_widget_show(hbox); | |
547 | |
548 label = gtk_label_new(_("Group:")); | |
549 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
550 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
551 gtk_widget_show(label); | |
552 | |
553 dialog->group_combo = gtk_combo_new(); | |
554 gtk_combo_set_popdown_strings(GTK_COMBO(dialog->group_combo), | |
555 gevo_get_groups()); | |
556 gtk_box_pack_start(GTK_BOX(hbox), dialog->group_combo, TRUE, TRUE, 0); | |
557 gtk_widget_show(dialog->group_combo); | |
558 | |
559 /* Cool. Now we only have a little left... */ | |
560 | |
561 /* Separator. */ | |
562 sep = gtk_hseparator_new(); | |
563 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
564 gtk_widget_show(sep); | |
565 | |
566 /* Button box */ | |
567 bbox = gtk_hbutton_box_new(); | |
568 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
569 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
570 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
571 gtk_widget_show(bbox); | |
572 | |
573 /* "New Person" button */ | |
574 button = gaim_pixbuf_button_from_stock(_("New Person"), GTK_STOCK_NEW, | |
575 GAIM_BUTTON_HORIZONTAL); | |
576 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
577 gtk_widget_show(button); | |
578 | |
579 g_signal_connect(G_OBJECT(button), "clicked", | |
580 G_CALLBACK(new_person_cb), dialog); | |
581 | |
582 /* "Cancel" button */ | |
583 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
584 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
585 gtk_widget_show(button); | |
586 | |
587 g_signal_connect(G_OBJECT(button), "clicked", | |
588 G_CALLBACK(cancel_cb), dialog); | |
589 | |
590 /* "Select Buddy" button */ | |
591 button = gaim_pixbuf_button_from_stock(_("Select Buddy"), GTK_STOCK_APPLY, | |
592 GAIM_BUTTON_HORIZONTAL); | |
593 dialog->select_button = button; | |
594 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
595 gtk_widget_set_sensitive(button, FALSE); | |
596 gtk_widget_show(button); | |
597 | |
598 g_signal_connect(G_OBJECT(button), "clicked", | |
599 G_CALLBACK(select_buddy_cb), dialog); | |
600 | |
601 /* Show it. */ | |
602 gtk_widget_show(dialog->win); | |
603 } | |
604 | |
605 void | |
606 gevo_add_buddy_dialog_add_person(GevoAddBuddyDialog *dialog, | |
607 EContact *contact, const char *name, | |
608 GaimAccount *account, const char *screenname) | |
609 { | |
13090 | 610 GdkPixbuf *pixbuf; |
8089 | 611 GtkTreeIter iter; |
612 | |
13090 | 613 pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); |
8089 | 614 |
615 gtk_list_store_append(dialog->model, &iter); | |
616 | |
617 gtk_list_store_set(dialog->model, &iter, | |
618 COLUMN_NAME, name, | |
13090 | 619 COLUMN_PRPL_ICON, pixbuf, |
8089 | 620 COLUMN_DATA, contact, |
621 COLUMN_USERNAME, screenname, | |
622 -1); | |
623 | |
624 if (contact != NULL) | |
625 dialog->contacts = g_list_append(dialog->contacts, contact); | |
626 | |
13090 | 627 if (pixbuf != NULL) |
628 g_object_unref(G_OBJECT(pixbuf)); | |
8089 | 629 } |