Mercurial > pidgin
annotate plugins/gevolution/assoc-buddy.c @ 10261:d4e9ff2edc4e
[gaim-migrate @ 11405]
This should fix segfault bug 1072604. Oops.
committer: Tailor Script <tailor@pidgin.im>
| author | Tim Ringenbach <marv@pidgin.im> |
|---|---|
| date | Thu, 25 Nov 2004 18:35:26 +0000 |
| parents | ff4be2d1401d |
| children | 455c0830d108 |
| 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 #include "gtkimhtml.h" | |
| 26 #include "gaim-disclosure.h" | |
| 27 | |
| 28 #include "debug.h" | |
| 29 | |
| 30 #include "gevolution.h" | |
| 31 | |
| 32 #include <stdlib.h> | |
| 33 #include <bonobo/bonobo-main.h> | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
34 #include <gtk/gtk.h> |
| 8089 | 35 |
| 36 enum | |
| 37 { | |
| 38 COLUMN_NAME, | |
| 39 COLUMN_DATA, | |
| 40 NUM_COLUMNS | |
| 41 }; | |
| 42 | |
| 43 static gint | |
| 44 delete_win_cb(GtkWidget *w, GdkEvent *event, GevoAssociateBuddyDialog *dialog) | |
| 45 { | |
| 46 gtk_widget_destroy(dialog->win); | |
| 47 | |
| 48 if (dialog->contacts != NULL) | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
49 { |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
50 g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL); |
| 8089 | 51 g_list_free(dialog->contacts); |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
52 } |
| 8089 | 53 |
| 54 g_object_unref(dialog->book); | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
55 gevo_addrbooks_model_unref(dialog->addrbooks); |
| 8089 | 56 |
| 57 g_free(dialog); | |
| 58 | |
| 59 return 0; | |
| 60 } | |
| 61 | |
| 62 static void | |
| 63 search_changed_cb(GtkEntry *entry, GevoAssociateBuddyDialog *dialog) | |
| 64 { | |
| 65 const char *text = gtk_entry_get_text(entry); | |
| 66 GList *l; | |
| 67 | |
| 68 gtk_list_store_clear(dialog->model); | |
| 69 | |
| 70 for (l = dialog->contacts; l != NULL; l = l->next) | |
| 71 { | |
| 72 EContact *contact = E_CONTACT(l->data); | |
| 73 const char *name; | |
| 74 GtkTreeIter iter; | |
| 75 | |
| 76 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
| 77 | |
| 78 if (text != NULL && *text != '\0' && name != NULL && | |
| 79 g_ascii_strncasecmp(name, text, strlen(text))) | |
| 80 { | |
| 81 continue; | |
| 82 } | |
| 83 | |
| 84 gtk_list_store_append(dialog->model, &iter); | |
| 85 | |
| 86 gtk_list_store_set(dialog->model, &iter, | |
| 87 COLUMN_NAME, name, | |
| 88 COLUMN_DATA, contact, | |
| 89 -1); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 static void | |
| 94 clear_cb(GtkWidget *w, GevoAssociateBuddyDialog *dialog) | |
| 95 { | |
| 96 static gboolean lock = FALSE; | |
| 97 | |
| 98 if (lock) | |
| 99 return; | |
| 100 | |
| 101 lock = TRUE; | |
| 102 gtk_entry_set_text(GTK_ENTRY(dialog->search_field), ""); | |
| 103 lock = FALSE; | |
| 104 } | |
| 105 | |
| 106 static void | |
| 107 selected_cb(GtkTreeSelection *sel, GevoAssociateBuddyDialog *dialog) | |
| 108 { | |
| 109 gtk_widget_set_sensitive(dialog->assoc_button, TRUE); | |
| 110 } | |
| 111 | |
| 112 static void | |
| 113 add_columns(GevoAssociateBuddyDialog *dialog) | |
| 114 { | |
| 115 GtkCellRenderer *renderer; | |
| 116 GtkTreeViewColumn *column; | |
| 117 | |
| 118 /* Name column */ | |
| 119 column = gtk_tree_view_column_new(); | |
| 120 gtk_tree_view_column_set_title(column, _("Name")); | |
| 121 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
| 122 gtk_tree_view_column_set_sort_column_id(column, COLUMN_NAME); | |
| 123 | |
| 124 renderer = gtk_cell_renderer_text_new(); | |
| 125 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
| 126 gtk_tree_view_column_add_attribute(column, renderer, | |
| 127 "text", COLUMN_NAME); | |
| 128 } | |
| 129 | |
| 130 static void | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
131 populate_treeview(GevoAssociateBuddyDialog *dialog, const gchar *uri) |
| 8089 | 132 { |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
133 EBook *book; |
| 8089 | 134 EBookQuery *query; |
| 135 const char *prpl_id; | |
| 136 gboolean status; | |
| 137 GList *cards, *c; | |
| 138 | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
139 if (dialog->book != NULL) |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
140 { |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
141 g_object_unref(dialog->book); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
142 dialog->book = NULL; |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
143 } |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
144 |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
145 if (dialog->contacts != NULL) |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
146 { |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
147 g_list_foreach(dialog->contacts, (GFunc) g_object_unref, NULL); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
148 g_list_free(dialog->contacts); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
149 dialog->contacts = NULL; |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
150 } |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
151 |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
152 gtk_list_store_clear(dialog->model); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
153 |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
154 if (!gevo_load_addressbook(uri, &book, NULL)) |
| 8089 | 155 { |
| 156 gaim_debug_error("evolution", | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
157 "Error retrieving addressbook\n"); |
| 8089 | 158 |
| 159 return; | |
| 160 } | |
| 161 | |
| 162 query = e_book_query_field_exists(E_CONTACT_FULL_NAME); | |
| 163 | |
| 164 if (query == NULL) | |
| 165 { | |
| 166 gaim_debug_error("evolution", "Error in creating query\n"); | |
| 167 | |
| 168 g_object_unref(book); | |
| 169 | |
| 170 return; | |
| 171 } | |
| 172 | |
| 173 status = e_book_get_contacts(book, query, &cards, NULL); | |
| 174 | |
| 175 e_book_query_unref(query); | |
| 176 | |
| 177 if (!status) | |
| 178 { | |
| 179 gaim_debug_error("evolution", "Error %d in getting card list\n", | |
| 180 status); | |
| 181 | |
| 182 g_object_unref(book); | |
| 183 | |
| 184 return; | |
| 185 } | |
| 186 | |
| 187 prpl_id = gaim_account_get_protocol_id(dialog->buddy->account); | |
| 188 | |
| 189 for (c = cards; c != NULL; c = c->next) | |
| 190 { | |
| 191 EContact *contact = E_CONTACT(c->data); | |
| 192 const char *name; | |
| 193 GtkTreeIter iter; | |
| 194 EContactField protocol_field = 0; | |
| 195 | |
| 196 name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
| 197 | |
| 198 gtk_list_store_append(dialog->model, &iter); | |
| 199 | |
| 200 gtk_list_store_set(dialog->model, &iter, | |
| 201 COLUMN_NAME, name, | |
| 202 COLUMN_DATA, contact, | |
| 203 -1); | |
| 204 | |
| 205 /* See if this user has the buddy in its list. */ | |
| 206 protocol_field = gevo_prpl_get_field(dialog->buddy->account, | |
| 207 dialog->buddy); | |
| 208 | |
| 209 if (protocol_field > 0) | |
| 210 { | |
| 211 GList *ims, *l; | |
| 212 | |
| 213 ims = e_contact_get(contact, protocol_field); | |
| 214 | |
| 215 for (l = ims; l != NULL; l = l->next) | |
| 216 { | |
| 217 if (!strcmp(l->data, dialog->buddy->name)) | |
| 218 { | |
| 219 GtkTreeSelection *selection; | |
| 220 | |
| 221 /* This is it. Select it. */ | |
| 222 selection = gtk_tree_view_get_selection( | |
| 223 GTK_TREE_VIEW(dialog->treeview)); | |
| 224 | |
| 225 gtk_tree_selection_select_iter(selection, &iter); | |
| 226 break; | |
| 227 } | |
| 228 } | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 dialog->contacts = cards; | |
| 233 dialog->book = book; | |
| 234 } | |
| 235 | |
| 236 static void | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
237 addrbook_change_cb(GtkComboBox *combo, GevoAssociateBuddyDialog *dialog) |
|
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 GtkTreeIter iter; |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
240 const char *esource_uri; |
|
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 if (!gtk_combo_box_get_active_iter(combo, &iter)) |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
243 return; |
|
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 gtk_tree_model_get(GTK_TREE_MODEL(dialog->addrbooks), &iter, |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
246 ADDRBOOK_COLUMN_URI, &esource_uri, |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
247 -1); |
|
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 populate_treeview(dialog, esource_uri); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
250 } |
|
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 static void |
| 8089 | 253 new_person_cb(GtkWidget *w, GevoAssociateBuddyDialog *dialog) |
| 254 { | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
255 gevo_new_person_dialog_show(dialog->book, NULL, dialog->buddy->account, |
| 8089 | 256 dialog->buddy->name, NULL, dialog->buddy, |
| 257 TRUE); | |
| 258 | |
| 259 delete_win_cb(NULL, NULL, dialog); | |
| 260 } | |
| 261 | |
| 262 static void | |
| 263 cancel_cb(GtkWidget *w, GevoAssociateBuddyDialog *dialog) | |
| 264 { | |
| 265 delete_win_cb(NULL, NULL, dialog); | |
| 266 } | |
| 267 | |
| 268 static void | |
| 269 assoc_buddy_cb(GtkWidget *w, GevoAssociateBuddyDialog *dialog) | |
| 270 { | |
| 271 GtkTreeSelection *selection; | |
| 272 GtkTreeIter iter; | |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
273 GList *list; |
| 8089 | 274 const char *fullname; |
| 275 EContactField protocol_field; | |
| 276 EContact *contact; | |
| 277 | |
| 278 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
| 279 | |
| 280 gtk_tree_selection_get_selected(selection, NULL, &iter); | |
| 281 | |
| 282 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
| 283 COLUMN_NAME, &fullname, | |
| 284 COLUMN_DATA, &contact, | |
| 285 -1); | |
| 286 | |
| 287 protocol_field = gevo_prpl_get_field(dialog->buddy->account, dialog->buddy); | |
| 288 | |
| 289 if (protocol_field == 0) | |
| 290 return; /* XXX */ | |
| 291 | |
| 292 list = e_contact_get(contact, protocol_field); | |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
293 list = g_list_append(list, g_strdup(dialog->buddy->name)); |
| 8089 | 294 |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
295 e_contact_set(contact, protocol_field, list); |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
296 |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
297 if (!e_book_commit_contact(dialog->book, contact, NULL)) |
|
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
298 gaim_debug_error("evolution", "Error adding contact to book\n"); |
| 8089 | 299 |
| 300 /* Free the list. */ | |
|
9566
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
301 g_list_foreach(list, (GFunc)g_free, NULL); |
|
7a149eac59a3
[gaim-migrate @ 10409]
Christian Hammond <chipx86@chipx86.com>
parents:
9354
diff
changeset
|
302 g_list_free(list); |
| 8089 | 303 |
| 304 delete_win_cb(NULL, NULL, dialog); | |
| 305 } | |
| 306 | |
| 307 GevoAssociateBuddyDialog * | |
| 308 gevo_associate_buddy_dialog_new(GaimBuddy *buddy) | |
| 309 { | |
| 310 GevoAssociateBuddyDialog *dialog; | |
| 311 GtkWidget *button; | |
| 312 GtkWidget *sw; | |
| 313 GtkWidget *label; | |
| 314 GtkWidget *vbox; | |
| 315 GtkWidget *hbox; | |
| 316 GtkWidget *bbox; | |
| 317 GtkWidget *sep; | |
| 318 GtkWidget *disclosure; | |
| 319 GtkTreeSelection *selection; | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
320 GtkCellRenderer *cell; |
| 8089 | 321 |
| 322 g_return_val_if_fail(buddy != NULL, NULL); | |
| 323 | |
| 324 dialog = g_new0(GevoAssociateBuddyDialog, 1); | |
| 325 | |
| 326 dialog->buddy = buddy; | |
| 327 | |
| 328 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 329 gtk_window_set_role(GTK_WINDOW(dialog->win), "assoc_buddy"); | |
| 330 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
| 331 | |
| 332 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
| 333 G_CALLBACK(delete_win_cb), dialog); | |
| 334 | |
| 335 /* Setup the vbox */ | |
| 336 vbox = gtk_vbox_new(FALSE, 12); | |
| 337 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
| 338 gtk_widget_show(vbox); | |
| 339 | |
| 340 /* Add the label. */ | |
| 341 label = gtk_label_new(_("Select a person from your address book to " | |
| 342 "add this buddy to, or create a new person.")); | |
| 343 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
| 344 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
| 345 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
| 346 gtk_widget_show(label); | |
| 347 | |
| 348 /* Add the search hbox */ | |
| 349 hbox = gtk_hbox_new(FALSE, 6); | |
| 350 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); | |
| 351 gtk_widget_show(hbox); | |
| 352 | |
| 353 /* "Search" */ | |
| 354 label = gtk_label_new(_("Search")); | |
| 355 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 356 gtk_widget_show(label); | |
| 357 | |
| 358 /* Addressbooks */ | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
359 dialog->addrbooks = gevo_addrbooks_model_new(); |
| 8089 | 360 |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
361 dialog->addrbooks_combo = gtk_combo_box_new_with_model(dialog->addrbooks); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
362 cell = gtk_cell_renderer_text_new(); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
363 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
364 cell, TRUE); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
365 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dialog->addrbooks_combo), |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
366 cell, |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
367 "text", ADDRBOOK_COLUMN_NAME, |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
368 NULL); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
369 gtk_box_pack_start(GTK_BOX(hbox), dialog->addrbooks_combo, FALSE, FALSE, 0); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
370 gtk_widget_show(dialog->addrbooks_combo); |
| 8089 | 371 |
| 372 | |
| 373 /* Search field */ | |
| 374 dialog->search_field = gtk_entry_new(); | |
| 375 gtk_box_pack_start(GTK_BOX(hbox), dialog->search_field, TRUE, TRUE, 0); | |
| 376 gtk_widget_show(dialog->search_field); | |
| 377 | |
| 378 g_signal_connect(G_OBJECT(dialog->search_field), "changed", | |
| 379 G_CALLBACK(search_changed_cb), dialog); | |
| 380 | |
| 381 /* Clear button */ | |
| 382 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
| 383 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 384 gtk_widget_show(button); | |
| 385 | |
| 386 g_signal_connect(G_OBJECT(button), "clicked", | |
| 387 G_CALLBACK(clear_cb), dialog); | |
| 388 | |
| 389 /* Scrolled Window */ | |
| 390 sw = gtk_scrolled_window_new(0, 0); | |
| 391 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
| 392 GTK_POLICY_AUTOMATIC, | |
| 393 GTK_POLICY_ALWAYS); | |
| 394 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
| 395 GTK_SHADOW_IN); | |
| 396 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
| 397 gtk_widget_show(sw); | |
| 398 | |
| 399 /* Create the list model for the treeview. */ | |
| 400 dialog->model = gtk_list_store_new(NUM_COLUMNS, | |
| 401 G_TYPE_STRING, G_TYPE_POINTER); | |
| 402 | |
| 403 /* Now for the treeview */ | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
404 dialog->treeview = gtk_tree_view_new_with_model( |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
405 GTK_TREE_MODEL(dialog->model)); |
| 8089 | 406 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); |
| 407 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
| 408 gtk_widget_show(dialog->treeview); | |
| 409 | |
| 410 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
| 411 | |
| 412 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
| 413 | |
| 414 g_signal_connect(G_OBJECT(selection), "changed", | |
| 415 G_CALLBACK(selected_cb), dialog); | |
| 416 | |
| 417 add_columns(dialog); | |
| 418 | |
|
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
419 /* |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
420 * Catch addressbook selection and populate treeview with the first |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
421 * addressbook |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
422 */ |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
423 gevo_addrbooks_model_populate( dialog->addrbooks ); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
424 g_signal_connect(G_OBJECT(dialog->addrbooks_combo), "changed", |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
425 G_CALLBACK(addrbook_change_cb), dialog); |
|
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
426 gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->addrbooks_combo), 0); |
| 8089 | 427 |
| 428 /* Add the disclosure */ | |
| 429 disclosure = gaim_disclosure_new(_("Show user details"), | |
| 430 _("Hide user details")); | |
| 431 gtk_box_pack_start(GTK_BOX(vbox), disclosure, FALSE, FALSE, 0); | |
| 432 gtk_widget_show(disclosure); | |
| 433 | |
| 434 /* | |
| 435 * User details | |
| 436 */ | |
| 437 | |
| 438 /* Scrolled Window */ | |
| 439 sw = gtk_scrolled_window_new(0, 0); | |
| 440 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
| 441 GTK_POLICY_NEVER, | |
| 442 GTK_POLICY_ALWAYS); | |
| 443 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
| 444 GTK_SHADOW_IN); | |
| 445 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
| 446 gaim_disclosure_set_container(GAIM_DISCLOSURE(disclosure), sw); | |
| 447 | |
| 448 /* Textview */ | |
| 449 dialog->imhtml = gtk_imhtml_new(NULL, NULL); | |
| 450 gtk_container_add(GTK_CONTAINER(sw), dialog->imhtml); | |
| 451 gtk_widget_show(dialog->imhtml); | |
| 452 | |
| 453 /* Separator. */ | |
| 454 sep = gtk_hseparator_new(); | |
| 455 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
| 456 gtk_widget_show(sep); | |
| 457 | |
| 458 /* Button box */ | |
| 459 bbox = gtk_hbutton_box_new(); | |
| 460 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
| 461 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
| 462 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
| 463 gtk_widget_show(bbox); | |
| 464 | |
| 465 /* "New Person" button */ | |
| 466 button = gaim_pixbuf_button_from_stock(_("New Person"), GTK_STOCK_NEW, | |
| 467 GAIM_BUTTON_HORIZONTAL); | |
| 468 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 469 gtk_widget_show(button); | |
| 470 | |
| 471 g_signal_connect(G_OBJECT(button), "clicked", | |
| 472 G_CALLBACK(new_person_cb), dialog); | |
| 473 | |
| 474 /* "Cancel" button */ | |
| 475 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
| 476 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 477 gtk_widget_show(button); | |
| 478 | |
| 479 g_signal_connect(G_OBJECT(button), "clicked", | |
| 480 G_CALLBACK(cancel_cb), dialog); | |
| 481 | |
| 482 /* "Associate Buddy" button */ | |
| 483 button = gaim_pixbuf_button_from_stock(_("_Associate Buddy"), | |
| 484 GTK_STOCK_APPLY, | |
| 485 GAIM_BUTTON_HORIZONTAL); | |
| 486 dialog->assoc_button = button; | |
| 487 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 488 gtk_widget_set_sensitive(button, FALSE); | |
| 489 gtk_widget_show(button); | |
| 490 | |
| 491 g_signal_connect(G_OBJECT(button), "clicked", | |
| 492 G_CALLBACK(assoc_buddy_cb), dialog); | |
| 493 | |
| 494 /* Show it. */ | |
| 495 gtk_widget_show(dialog->win); | |
| 496 | |
| 497 return dialog; | |
| 498 } |
