Mercurial > pidgin
annotate plugins/gevolution/add_buddy_dialog.c @ 10022:00a7ccf8ccd7
[gaim-migrate @ 10954]
Don't show "Not Specified" for ICQ info when the gender isn't specified.
oannu@sf pointed out that this is dumb.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Tue, 14 Sep 2004 03:51:36 +0000 |
| parents | c00def44d76a |
| children | ff4be2d1401d |
| 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 g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL); | |
| 48 | |
| 49 if (dialog->contacts != NULL) | |
| 50 g_list_free(dialog->contacts); | |
| 51 | |
| 52 if (dialog->book != NULL) | |
| 53 g_object_unref(dialog->book); | |
| 54 | |
| 55 if (dialog->username != NULL) | |
| 56 g_free(dialog->username); | |
| 57 | |
| 58 g_free(dialog); | |
| 59 | |
| 60 return 0; | |
| 61 } | |
| 62 | |
| 63 static void | |
| 64 new_person_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
| 65 { | |
| 66 const char *group_name; | |
| 67 | |
| 68 group_name = | |
| 69 gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(dialog->group_combo)->entry)); | |
| 70 | |
| 71 gevo_new_person_dialog_show(NULL, dialog->account, NULL, | |
| 72 (*group_name ? group_name : NULL), | |
| 73 NULL, FALSE); | |
| 74 | |
| 75 delete_win_cb(NULL, NULL, dialog); | |
| 76 } | |
| 77 | |
| 78 static void | |
| 79 cancel_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
| 80 { | |
| 81 delete_win_cb(NULL, NULL, dialog); | |
| 82 } | |
| 83 | |
| 84 static void | |
| 85 select_buddy_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
| 86 { | |
| 87 GtkTreeSelection *selection; | |
| 88 GtkTreeIter iter; | |
| 89 const char *group_name; | |
| 90 const char *fullname; | |
| 91 const char *username; | |
| 92 EContact *contact; | |
| 93 | |
| 94 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
| 95 | |
| 96 gtk_tree_selection_get_selected(selection, NULL, &iter); | |
| 97 | |
| 98 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
| 99 COLUMN_NAME, &fullname, | |
| 100 COLUMN_USERNAME, &username, | |
| 101 COLUMN_DATA, &contact, | |
| 102 -1); | |
| 103 | |
| 104 group_name = | |
| 105 gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(dialog->group_combo)->entry)); | |
| 106 | |
| 107 if (username == NULL || *username == '\0') | |
| 108 { | |
| 109 gevo_new_person_dialog_show(NULL, dialog->account, NULL, | |
| 110 (*group_name ? group_name : NULL), | |
| 111 NULL, FALSE); | |
| 112 } | |
| 113 else | |
| 114 { | |
| 115 gevo_add_buddy(dialog->account, group_name, username, fullname); | |
| 116 } | |
| 117 | |
| 118 delete_win_cb(NULL, NULL, dialog); | |
| 119 } | |
| 120 | |
| 121 static void | |
| 122 populate_address_books(GevoAddBuddyDialog *dialog) | |
| 123 { | |
| 124 GtkWidget *item; | |
| 125 GtkWidget *menu; | |
| 126 #if notyet | |
| 127 ESourceList *addressbooks; | |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
128 GSList *groups, *g; |
| 8089 | 129 #endif |
| 130 | |
| 131 menu = | |
| 132 gtk_option_menu_get_menu(GTK_OPTION_MENU(dialog->addressbooks_menu)); | |
| 133 | |
| 134 item = gtk_menu_item_new_with_label(_("Local Addressbook")); | |
| 135 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 136 gtk_widget_show(item); | |
| 137 | |
| 138 #if notyet | |
| 139 if (!e_book_get_addressbooks(&addressbooks, NULL)) | |
| 140 { | |
| 141 gaim_debug_error("evolution", | |
| 142 "Unable to fetch list of address books.\n"); | |
| 143 | |
| 144 item = gtk_menu_item_new_with_label(_("None")); | |
| 145 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 146 gtk_widget_show(item); | |
| 147 | |
| 148 return; | |
| 149 } | |
| 150 | |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
151 groups = e_source_list_peek_groups(addressbooks); |
| 8089 | 152 |
| 153 if (groups == NULL) | |
| 154 { | |
| 155 item = gtk_menu_item_new_with_label(_("None")); | |
| 156 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 157 gtk_widget_show(item); | |
| 158 | |
| 159 return; | |
| 160 } | |
| 161 | |
| 162 for (g = groups; g != NULL; g = g->next) | |
| 163 { | |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
164 GSList *sources, *s; |
| 8089 | 165 |
| 166 sources = e_source_group_peek_sources(g->data); | |
| 167 | |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
168 for (s = sources; s != NULL; s = s->next) |
| 8089 | 169 { |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
170 ESource *source = E_SOURCE(s->data); |
| 8089 | 171 |
| 172 item = gtk_menu_item_new_with_label(e_source_peek_name(source)); | |
| 173 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 174 gtk_widget_show(item); | |
| 175 } | |
| 176 } | |
| 177 #endif | |
| 178 } | |
| 179 | |
| 180 static void | |
| 181 add_columns(GevoAddBuddyDialog *dialog) | |
| 182 { | |
| 183 GtkCellRenderer *renderer; | |
| 184 GtkTreeViewColumn *column; | |
| 185 | |
| 186 /* Name column */ | |
| 187 column = gtk_tree_view_column_new(); | |
| 188 gtk_tree_view_column_set_title(column, _("Name")); | |
| 189 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
| 190 gtk_tree_view_column_set_sort_column_id(column, COLUMN_NAME); | |
| 191 | |
| 192 renderer = gtk_cell_renderer_text_new(); | |
| 193 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
| 194 gtk_tree_view_column_add_attribute(column, renderer, | |
| 195 "text", COLUMN_NAME); | |
| 196 | |
| 197 /* Account column */ | |
| 198 column = gtk_tree_view_column_new(); | |
| 199 gtk_tree_view_column_set_title(column, _("Instant Messaging")); | |
| 200 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
| 201 gtk_tree_view_column_set_sort_column_id(column, COLUMN_USERNAME); | |
| 202 | |
| 203 /* Protocol icon */ | |
| 204 renderer = gtk_cell_renderer_pixbuf_new(); | |
| 205 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
| 206 gtk_tree_view_column_add_attribute(column, renderer, | |
| 207 "pixbuf", COLUMN_PRPL_ICON); | |
| 208 | |
| 209 /* Account name */ | |
| 210 renderer = gtk_cell_renderer_text_new(); | |
| 211 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
| 212 gtk_tree_view_column_add_attribute(column, renderer, | |
| 213 "text", COLUMN_USERNAME); | |
| 214 } | |
| 215 | |
| 216 static void | |
| 217 add_ims(GevoAddBuddyDialog *dialog, EContact *contact, const char *name, | |
| 218 GList *list, const char *id) | |
| 219 { | |
| 220 GaimAccount *account = NULL; | |
| 221 GList *l; | |
| 222 GtkTreeIter iter; | |
| 223 GdkPixbuf *pixbuf, *icon = NULL; | |
| 224 | |
| 225 if (list == NULL) | |
| 226 return; | |
| 227 | |
| 228 for (l = gaim_connections_get_all(); l != NULL; l = l->next) | |
| 229 { | |
| 230 GaimConnection *gc = (GaimConnection *)l->data; | |
| 231 | |
| 232 account = gaim_connection_get_account(gc); | |
| 233 | |
| 234 if (!strcmp(gaim_account_get_protocol_id(account), id)) | |
| 235 break; | |
| 236 | |
| 237 account = NULL; | |
| 238 } | |
| 239 | |
| 240 if (account == NULL) | |
| 241 return; | |
| 242 | |
| 243 pixbuf = create_prpl_icon(account); | |
| 244 | |
| 245 if (pixbuf != NULL) | |
| 246 icon = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
| 247 GDK_INTERP_BILINEAR); | |
| 248 | |
| 249 for (l = list; l != NULL; l = l->next) | |
| 250 { | |
| 251 char *account_name = (char *)l->data; | |
| 252 | |
| 253 if (account_name == NULL) | |
| 254 continue; | |
| 255 | |
| 256 if (gaim_find_buddy(dialog->account, account_name) != NULL) | |
| 257 continue; | |
| 258 | |
| 259 gtk_list_store_append(dialog->model, &iter); | |
| 260 | |
| 261 gtk_list_store_set(dialog->model, &iter, | |
| 262 COLUMN_NAME, name, | |
| 263 COLUMN_PRPL_ICON, icon, | |
| 264 COLUMN_USERNAME, account_name, | |
| 265 COLUMN_DATA, contact, | |
| 266 -1); | |
| 267 | |
| 268 if (!strcmp(gaim_account_get_protocol_id(account), | |
| 269 gaim_account_get_protocol_id(dialog->account)) && | |
| 270 dialog->username != NULL && | |
| 271 !strcmp(account_name, dialog->username)) | |
| 272 { | |
| 273 GtkTreeSelection *selection; | |
| 274 | |
| 275 /* This is it. Select it. */ | |
| 276 selection = gtk_tree_view_get_selection( | |
| 277 GTK_TREE_VIEW(dialog->treeview)); | |
| 278 | |
| 279 gtk_tree_selection_select_iter(selection, &iter); | |
| 280 } | |
| 281 } | |
| 282 | |
| 283 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
| 284 if (icon != NULL) g_object_unref(G_OBJECT(icon)); | |
| 285 | |
| 286 g_list_foreach(list, (GFunc)g_free, NULL); | |
| 287 g_list_free(list); | |
| 288 } | |
| 289 | |
| 290 static void | |
| 291 populate_treeview(GevoAddBuddyDialog *dialog) | |
| 292 { | |
| 293 EBookQuery *query; | |
| 294 EBook *book; | |
| 295 gboolean status; | |
| 296 GList *cards, *c; | |
| 297 | |
| 298 if (!gevo_load_addressbook(&book, NULL)) | |
| 299 { | |
| 300 gaim_debug_error("evolution", | |
| 301 "Error retrieving default addressbook\n"); | |
| 302 | |
| 303 return; | |
| 304 } | |
| 305 | |
| 306 query = e_book_query_field_exists(E_CONTACT_FULL_NAME); | |
| 307 | |
| 308 if (query == NULL) | |
| 309 { | |
| 310 gaim_debug_error("evolution", "Error in creating query\n"); | |
| 311 | |
| 312 g_object_unref(book); | |
| 313 | |
| 314 return; | |
| 315 } | |
| 316 | |
| 317 status = e_book_get_contacts(book, query, &cards, NULL); | |
| 318 | |
| 319 e_book_query_unref(query); | |
| 320 | |
| 321 if (!status) | |
| 322 { | |
| 323 gaim_debug_error("evolution", "Error %d in getting card list\n", | |
| 324 status); | |
| 325 | |
| 326 g_object_unref(book); | |
| 327 | |
| 328 return; | |
| 329 } | |
| 330 | |
| 331 for (c = cards; c != NULL; c = c->next) | |
| 332 { | |
| 333 EContact *contact = E_CONTACT(c->data); | |
| 334 const char *name; | |
| 335 GList *aims, *jabbers, *yahoos, *msns, *icqs; | |
| 336 | |
| 337 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
| 338 | |
| 339 aims = e_contact_get(contact, E_CONTACT_IM_AIM); | |
| 340 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); | |
| 341 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); | |
| 342 msns = e_contact_get(contact, E_CONTACT_IM_MSN); | |
| 343 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); | |
| 344 | |
| 345 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
| 346 msns == NULL && icqs == NULL) | |
| 347 { | |
| 348 GtkTreeIter iter; | |
| 349 | |
| 350 gtk_list_store_append(dialog->model, &iter); | |
| 351 | |
| 352 gtk_list_store_set(dialog->model, &iter, | |
| 353 COLUMN_NAME, name, | |
| 354 COLUMN_DATA, contact, | |
| 355 -1); | |
| 356 } | |
| 357 else | |
| 358 { | |
| 359 add_ims(dialog, contact, name, aims, "prpl-oscar"); | |
| 360 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); | |
| 361 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); | |
| 362 add_ims(dialog, contact, name, msns, "prpl-msn"); | |
| 363 add_ims(dialog, contact, name, icqs, "prpl-oscar"); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 dialog->contacts = cards; | |
| 368 dialog->book = book; | |
| 369 } | |
| 370 | |
| 371 static void | |
| 372 selected_cb(GtkTreeSelection *sel, GevoAddBuddyDialog *dialog) | |
| 373 { | |
| 374 gtk_widget_set_sensitive(dialog->select_button, TRUE); | |
| 375 } | |
| 376 | |
| 377 static void | |
| 378 search_changed_cb(GtkEntry *entry, GevoAddBuddyDialog *dialog) | |
| 379 { | |
| 380 const char *text = gtk_entry_get_text(entry); | |
| 381 GList *l; | |
| 382 | |
| 383 gtk_list_store_clear(dialog->model); | |
| 384 | |
| 385 for (l = dialog->contacts; l != NULL; l = l->next) | |
| 386 { | |
| 387 EContact *contact = E_CONTACT(l->data); | |
| 388 const char *name; | |
| 389 GList *aims, *jabbers, *yahoos, *msns, *icqs; | |
| 390 | |
| 391 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
| 392 | |
| 393 if (text != NULL && *text != '\0' && name != NULL && | |
| 394 g_ascii_strncasecmp(name, text, strlen(text))) | |
| 395 { | |
| 396 continue; | |
| 397 } | |
| 398 | |
| 399 aims = e_contact_get(contact, E_CONTACT_IM_AIM); | |
| 400 jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER); | |
| 401 yahoos = e_contact_get(contact, E_CONTACT_IM_YAHOO); | |
| 402 msns = e_contact_get(contact, E_CONTACT_IM_MSN); | |
| 403 icqs = e_contact_get(contact, E_CONTACT_IM_ICQ); | |
| 404 | |
| 405 if (aims == NULL && jabbers == NULL && yahoos == NULL && | |
| 406 msns == NULL && icqs == NULL) | |
| 407 { | |
| 408 GtkTreeIter iter; | |
| 409 | |
| 410 gtk_list_store_append(dialog->model, &iter); | |
| 411 | |
| 412 gtk_list_store_set(dialog->model, &iter, | |
| 413 COLUMN_NAME, name, | |
| 414 COLUMN_DATA, contact, | |
| 415 -1); | |
| 416 } | |
| 417 else | |
| 418 { | |
| 419 add_ims(dialog, contact, name, aims, "prpl-oscar"); | |
| 420 add_ims(dialog, contact, name, jabbers, "prpl-jabber"); | |
| 421 add_ims(dialog, contact, name, yahoos, "prpl-yahoo"); | |
| 422 add_ims(dialog, contact, name, msns, "prpl-msn"); | |
| 423 add_ims(dialog, contact, name, icqs, "prpl-oscar"); | |
| 424 } | |
| 425 } | |
| 426 } | |
| 427 | |
| 428 static void | |
| 429 clear_cb(GtkWidget *w, GevoAddBuddyDialog *dialog) | |
| 430 { | |
| 431 static gboolean lock = FALSE; | |
| 432 | |
| 433 if (lock) | |
| 434 return; | |
| 435 | |
| 436 lock = TRUE; | |
| 437 gtk_entry_set_text(GTK_ENTRY(dialog->search_field), ""); | |
| 438 lock = FALSE; | |
| 439 } | |
| 440 | |
| 441 void | |
| 442 gevo_add_buddy_dialog_show(GaimAccount *account, const char *username, | |
| 443 const char *group, const char *alias) | |
| 444 { | |
| 445 GevoAddBuddyDialog *dialog; | |
| 446 GtkWidget *button; | |
| 447 GtkWidget *sw; | |
| 448 GtkWidget *label; | |
| 449 GtkWidget *vbox; | |
| 450 GtkWidget *hbox; | |
| 451 GtkWidget *bbox; | |
| 452 GtkWidget *menu; | |
| 453 GtkWidget *sep; | |
| 454 GtkTreeSelection *selection; | |
| 455 | |
| 456 dialog = g_new0(GevoAddBuddyDialog, 1); | |
| 457 | |
| 458 dialog->account = | |
| 459 (account != NULL | |
| 460 ? account | |
| 461 : gaim_connection_get_account(gaim_connections_get_all()->data)); | |
| 462 | |
| 463 if (username != NULL) | |
| 464 dialog->username = g_strdup(username); | |
| 465 | |
| 466 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 467 gtk_window_set_role(GTK_WINDOW(dialog->win), "add_buddy"); | |
| 468 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
| 469 gtk_widget_set_size_request(dialog->win, -1, 400); | |
| 470 | |
| 471 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
| 472 G_CALLBACK(delete_win_cb), dialog); | |
| 473 | |
| 474 /* Setup the vbox */ | |
| 475 vbox = gtk_vbox_new(FALSE, 12); | |
| 476 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
| 477 gtk_widget_show(vbox); | |
| 478 | |
| 479 /* Add the label. */ | |
| 480 label = gtk_label_new(_("Select a person from your address book below, " | |
| 481 "or add a new person.")); | |
| 482 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
| 483 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
| 484 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
| 485 gtk_widget_show(label); | |
| 486 | |
| 487 /* Add the search hbox */ | |
| 488 hbox = gtk_hbox_new(FALSE, 6); | |
| 489 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); | |
| 490 gtk_widget_show(hbox); | |
| 491 | |
| 492 /* "Search" */ | |
| 493 label = gtk_label_new(_("Search")); | |
| 494 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 495 gtk_widget_show(label); | |
| 496 | |
| 497 /* Addressbooks */ | |
| 498 dialog->addressbooks_menu = gtk_option_menu_new(); | |
| 499 menu = gtk_menu_new(); | |
| 500 gtk_option_menu_set_menu(GTK_OPTION_MENU(dialog->addressbooks_menu), menu); | |
| 501 | |
| 502 populate_address_books(dialog); | |
| 503 | |
| 504 gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->addressbooks_menu), 0); | |
| 505 | |
| 506 gtk_box_pack_start(GTK_BOX(hbox), dialog->addressbooks_menu, | |
| 507 FALSE, FALSE, 0); | |
| 508 gtk_widget_show(dialog->addressbooks_menu); | |
| 509 | |
| 510 /* Search field */ | |
| 511 dialog->search_field = gtk_entry_new(); | |
| 512 gtk_box_pack_start(GTK_BOX(hbox), dialog->search_field, TRUE, TRUE, 0); | |
| 513 gtk_widget_show(dialog->search_field); | |
| 514 | |
| 515 g_signal_connect(G_OBJECT(dialog->search_field), "changed", | |
| 516 G_CALLBACK(search_changed_cb), dialog); | |
| 517 | |
| 518 /* Clear button */ | |
| 519 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
| 520 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 521 gtk_widget_show(button); | |
| 522 | |
| 523 g_signal_connect(G_OBJECT(button), "clicked", | |
| 524 G_CALLBACK(clear_cb), dialog); | |
| 525 | |
| 526 /* Scrolled Window */ | |
| 527 sw = gtk_scrolled_window_new(0, 0); | |
| 528 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
| 529 GTK_POLICY_AUTOMATIC, | |
| 530 GTK_POLICY_ALWAYS); | |
| 531 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
| 532 GTK_SHADOW_IN); | |
| 533 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
| 534 gtk_widget_show(sw); | |
| 535 | |
| 536 /* Create the list model for the treeview. */ | |
| 537 dialog->model = gtk_list_store_new(NUM_COLUMNS, | |
| 538 G_TYPE_STRING, GDK_TYPE_PIXBUF, | |
| 539 G_TYPE_STRING, G_TYPE_POINTER); | |
| 540 | |
| 541 /* Now for the treeview */ | |
| 542 dialog->treeview = | |
| 543 gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
| 544 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
| 545 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
| 546 gtk_widget_show(dialog->treeview); | |
| 547 | |
| 548 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
| 549 | |
| 550 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
| 551 | |
| 552 g_signal_connect(G_OBJECT(selection), "changed", | |
| 553 G_CALLBACK(selected_cb), dialog); | |
| 554 | |
| 555 add_columns(dialog); | |
| 556 | |
| 557 populate_treeview(dialog); | |
| 558 | |
| 559 /* Group box */ | |
| 560 hbox = gtk_hbox_new(FALSE, 6); | |
| 561 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
| 562 gtk_widget_show(hbox); | |
| 563 | |
| 564 label = gtk_label_new(_("Group:")); | |
| 565 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 566 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 567 gtk_widget_show(label); | |
| 568 | |
| 569 dialog->group_combo = gtk_combo_new(); | |
| 570 gtk_combo_set_popdown_strings(GTK_COMBO(dialog->group_combo), | |
| 571 gevo_get_groups()); | |
| 572 gtk_box_pack_start(GTK_BOX(hbox), dialog->group_combo, TRUE, TRUE, 0); | |
| 573 gtk_widget_show(dialog->group_combo); | |
| 574 | |
| 575 /* Cool. Now we only have a little left... */ | |
| 576 | |
| 577 /* Separator. */ | |
| 578 sep = gtk_hseparator_new(); | |
| 579 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
| 580 gtk_widget_show(sep); | |
| 581 | |
| 582 /* Button box */ | |
| 583 bbox = gtk_hbutton_box_new(); | |
| 584 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
| 585 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
| 586 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
| 587 gtk_widget_show(bbox); | |
| 588 | |
| 589 /* "New Person" button */ | |
| 590 button = gaim_pixbuf_button_from_stock(_("New Person"), GTK_STOCK_NEW, | |
| 591 GAIM_BUTTON_HORIZONTAL); | |
| 592 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 593 gtk_widget_show(button); | |
| 594 | |
| 595 g_signal_connect(G_OBJECT(button), "clicked", | |
| 596 G_CALLBACK(new_person_cb), dialog); | |
| 597 | |
| 598 /* "Cancel" button */ | |
| 599 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
| 600 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 601 gtk_widget_show(button); | |
| 602 | |
| 603 g_signal_connect(G_OBJECT(button), "clicked", | |
| 604 G_CALLBACK(cancel_cb), dialog); | |
| 605 | |
| 606 /* "Select Buddy" button */ | |
| 607 button = gaim_pixbuf_button_from_stock(_("Select Buddy"), GTK_STOCK_APPLY, | |
| 608 GAIM_BUTTON_HORIZONTAL); | |
| 609 dialog->select_button = button; | |
| 610 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 611 gtk_widget_set_sensitive(button, FALSE); | |
| 612 gtk_widget_show(button); | |
| 613 | |
| 614 g_signal_connect(G_OBJECT(button), "clicked", | |
| 615 G_CALLBACK(select_buddy_cb), dialog); | |
| 616 | |
| 617 /* Show it. */ | |
| 618 gtk_widget_show(dialog->win); | |
| 619 } | |
| 620 | |
| 621 void | |
| 622 gevo_add_buddy_dialog_add_person(GevoAddBuddyDialog *dialog, | |
| 623 EContact *contact, const char *name, | |
| 624 GaimAccount *account, const char *screenname) | |
| 625 { | |
| 626 GdkPixbuf *pixbuf, *icon = NULL; | |
| 627 GtkTreeIter iter; | |
| 628 | |
| 629 pixbuf = create_prpl_icon(account); | |
| 630 | |
| 631 if (pixbuf != NULL) | |
| 632 icon = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
| 633 | |
| 634 gtk_list_store_append(dialog->model, &iter); | |
| 635 | |
| 636 gtk_list_store_set(dialog->model, &iter, | |
| 637 COLUMN_NAME, name, | |
| 638 COLUMN_PRPL_ICON, icon, | |
| 639 COLUMN_DATA, contact, | |
| 640 COLUMN_USERNAME, screenname, | |
| 641 -1); | |
| 642 | |
| 643 if (contact != NULL) | |
| 644 dialog->contacts = g_list_append(dialog->contacts, contact); | |
| 645 | |
| 646 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
| 647 if (icon != NULL) g_object_unref(G_OBJECT(icon)); | |
| 648 } |
