| 82 tls_peers_mgmt_repopulate_list(void) |
82 tls_peers_mgmt_repopulate_list(void) |
| 83 { |
83 { |
| 84 GtkTreeView *listview = tpm_dat->listview; |
84 GtkTreeView *listview = tpm_dat->listview; |
| 85 PurpleCertificatePool *tls_peers; |
85 PurpleCertificatePool *tls_peers; |
| 86 GList *idlist, *l; |
86 GList *idlist, *l; |
| 87 |
87 |
| 88 GtkListStore *store = GTK_LIST_STORE( |
88 GtkListStore *store = GTK_LIST_STORE( |
| 89 gtk_tree_view_get_model(GTK_TREE_VIEW(listview))); |
89 gtk_tree_view_get_model(GTK_TREE_VIEW(listview))); |
| 90 |
90 |
| 91 /* First, delete everything in the list */ |
91 /* First, delete everything in the list */ |
| 92 gtk_list_store_clear(store); |
92 gtk_list_store_clear(store); |
| 93 |
93 |
| 94 /* Locate the "tls_peers" pool */ |
94 /* Locate the "tls_peers" pool */ |
| 95 tls_peers = purple_certificate_find_pool("x509", "tls_peers"); |
95 tls_peers = purple_certificate_find_pool("x509", "tls_peers"); |
| 197 _("Cancel"), |
197 _("Cancel"), |
| 198 G_CALLBACK(tls_peers_mgmt_import_cancel2_cb), |
198 G_CALLBACK(tls_peers_mgmt_import_cancel2_cb), |
| 199 NULL, NULL, NULL, /* No account/who/conv*/ |
199 NULL, NULL, NULL, /* No account/who/conv*/ |
| 200 crt /* Pass cert instance to callback*/ |
200 crt /* Pass cert instance to callback*/ |
| 201 ); |
201 ); |
| 202 |
202 |
| 203 g_free(default_hostname); |
203 g_free(default_hostname); |
| 204 } else { |
204 } else { |
| 205 /* Errors! Oh no! */ |
205 /* Errors! Oh no! */ |
| 206 /* TODO: Perhaps find a way to be specific about what just |
206 /* TODO: Perhaps find a way to be specific about what just |
| 207 went wrong? */ |
207 went wrong? */ |
| 258 { |
258 { |
| 259 PurpleCertificate *crt = (PurpleCertificate *) data; |
259 PurpleCertificate *crt = (PurpleCertificate *) data; |
| 260 /* Pressing cancel just frees the duplicated certificate */ |
260 /* Pressing cancel just frees the duplicated certificate */ |
| 261 purple_certificate_destroy(crt); |
261 purple_certificate_destroy(crt); |
| 262 } |
262 } |
| 263 |
263 |
| 264 static void |
264 static void |
| 265 tls_peers_mgmt_export_cb(GtkWidget *button, gpointer data) |
265 tls_peers_mgmt_export_cb(GtkWidget *button, gpointer data) |
| 266 { |
266 { |
| 267 PurpleCertificate *crt; |
267 PurpleCertificate *crt; |
| 268 GtkTreeSelection *select = tpm_dat->listselect; |
268 GtkTreeSelection *select = tpm_dat->listselect; |
| 325 gtk_tree_model_get(model, &iter, TPM_HOSTNAME_COLUMN, &id, -1); |
324 gtk_tree_model_get(model, &iter, TPM_HOSTNAME_COLUMN, &id, -1); |
| 326 |
325 |
| 327 /* Now retrieve the certificate */ |
326 /* Now retrieve the certificate */ |
| 328 crt = purple_certificate_pool_retrieve(tpm_dat->tls_peers, id); |
327 crt = purple_certificate_pool_retrieve(tpm_dat->tls_peers, id); |
| 329 g_return_if_fail(crt); |
328 g_return_if_fail(crt); |
| 330 |
329 |
| 331 /* Fire the notification */ |
330 /* Fire the notification */ |
| 332 purple_certificate_display_x509(crt); |
331 purple_certificate_display_x509(crt); |
| 333 |
332 |
| 334 g_free(id); |
333 g_free(id); |
| 335 purple_certificate_destroy(crt); |
334 purple_certificate_destroy(crt); |
| 336 } |
335 } |
| 337 |
336 |
| 338 static void |
337 static void |
| 368 gtk_tree_model_get(model, &iter, TPM_HOSTNAME_COLUMN, &id, -1); |
367 gtk_tree_model_get(model, &iter, TPM_HOSTNAME_COLUMN, &id, -1); |
| 369 |
368 |
| 370 /* Prompt to confirm deletion */ |
369 /* Prompt to confirm deletion */ |
| 371 primary = g_strdup_printf( |
370 primary = g_strdup_printf( |
| 372 _("Really delete certificate for %s?"), id ); |
371 _("Really delete certificate for %s?"), id ); |
| 373 |
372 |
| 374 purple_request_yes_no(tpm_dat, _("Confirm certificate delete"), |
373 purple_request_yes_no(tpm_dat, _("Confirm certificate delete"), |
| 375 primary, NULL, /* Can this be NULL? */ |
374 primary, NULL, /* Can this be NULL? */ |
| 376 1, /* NO is default action */ |
375 1, /* NO is default action */ |
| 377 NULL, NULL, NULL, |
376 NULL, NULL, NULL, |
| 378 id, /* id ownership passed to callback */ |
377 id, /* id ownership passed to callback */ |
| 379 tls_peers_mgmt_delete_confirm_cb, |
378 tls_peers_mgmt_delete_confirm_cb, |
| 380 tls_peers_mgmt_delete_confirm_cb ); |
379 tls_peers_mgmt_delete_confirm_cb ); |
| 381 |
380 |
| 382 g_free(primary); |
381 g_free(primary); |
| 383 |
382 |
| 384 } else { |
383 } else { |
| 385 purple_debug_warning("gtkcertmgr/tls_peers_mgmt", |
384 purple_debug_warning("gtkcertmgr/tls_peers_mgmt", |
| 386 "Delete clicked with no selection?\n"); |
385 "Delete clicked with no selection?\n"); |
| 387 return; |
386 return; |
| 388 } |
387 } |
| 404 /** Element to return to the Certmgr window to put in the Notebook */ |
403 /** Element to return to the Certmgr window to put in the Notebook */ |
| 405 GtkWidget *mgmt_widget; |
404 GtkWidget *mgmt_widget; |
| 406 |
405 |
| 407 /* Create a struct to store context information about this window */ |
406 /* Create a struct to store context information about this window */ |
| 408 tpm_dat = g_new0(tls_peers_mgmt_data, 1); |
407 tpm_dat = g_new0(tls_peers_mgmt_data, 1); |
| 409 |
408 |
| 410 tpm_dat->mgmt_widget = mgmt_widget = |
409 tpm_dat->mgmt_widget = mgmt_widget = |
| 411 gtk_hbox_new(FALSE, /* Non-homogeneous */ |
410 gtk_hbox_new(FALSE, /* Non-homogeneous */ |
| 412 PIDGIN_HIG_BORDER); |
411 PIDGIN_HIG_BORDER); |
| 413 gtk_widget_show(mgmt_widget); |
412 gtk_widget_show(mgmt_widget); |
| 414 |
413 |
| 417 g_signal_connect(G_OBJECT(mgmt_widget), "destroy", |
416 g_signal_connect(G_OBJECT(mgmt_widget), "destroy", |
| 418 G_CALLBACK(tls_peers_mgmt_destroy), NULL); |
417 G_CALLBACK(tls_peers_mgmt_destroy), NULL); |
| 419 |
418 |
| 420 /* List view */ |
419 /* List view */ |
| 421 store = gtk_list_store_new(TPM_N_COLUMNS, G_TYPE_STRING); |
420 store = gtk_list_store_new(TPM_N_COLUMNS, G_TYPE_STRING); |
| 422 |
421 |
| 423 tpm_dat->listview = listview = |
422 tpm_dat->listview = listview = |
| 424 GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store))); |
423 GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store))); |
| 425 g_object_unref(G_OBJECT(store)); |
424 g_object_unref(G_OBJECT(store)); |
| 426 |
425 |
| 427 { |
426 { |
| 428 GtkCellRenderer *renderer; |
427 GtkCellRenderer *renderer; |
| 429 GtkTreeViewColumn *column; |
428 GtkTreeViewColumn *column; |
| 430 |
429 |
| 431 /* Set up the display columns */ |
430 /* Set up the display columns */ |
| 438 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); |
437 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); |
| 439 |
438 |
| 440 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), |
439 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), |
| 441 TPM_HOSTNAME_COLUMN, GTK_SORT_ASCENDING); |
440 TPM_HOSTNAME_COLUMN, GTK_SORT_ASCENDING); |
| 442 } |
441 } |
| 443 |
442 |
| 444 /* Get the treeview selector into the struct */ |
443 /* Get the treeview selector into the struct */ |
| 445 tpm_dat->listselect = select = |
444 tpm_dat->listselect = select = |
| 446 gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); |
445 gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); |
| 447 |
446 |
| 448 /* Force the selection mode */ |
447 /* Force the selection mode */ |
| 449 gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); |
448 gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); |
| 450 |
449 |
| 451 /* Use a callback to enable/disable the buttons based on whether |
450 /* Use a callback to enable/disable the buttons based on whether |
| 452 something is selected */ |
451 something is selected */ |
| 453 g_signal_connect(G_OBJECT(select), "changed", |
452 g_signal_connect(G_OBJECT(select), "changed", |
| 454 G_CALLBACK(tls_peers_mgmt_select_chg_cb), NULL); |
453 G_CALLBACK(tls_peers_mgmt_select_chg_cb), NULL); |
| 455 |
454 |
| 456 gtk_box_pack_start(GTK_BOX(mgmt_widget), GTK_WIDGET(listview), |
455 gtk_box_pack_start(GTK_BOX(mgmt_widget), GTK_WIDGET(listview), |
| 457 TRUE, TRUE, /* Take up lots of space */ |
456 TRUE, TRUE, /* Take up lots of space */ |
| 458 0); /* TODO: this padding is wrong */ |
457 0); /* TODO: this padding is wrong */ |
| 459 gtk_widget_show(GTK_WIDGET(listview)); |
458 gtk_widget_show(GTK_WIDGET(listview)); |
| 460 |
459 |
| 461 /* Fill the list for the first time */ |
460 /* Fill the list for the first time */ |
| 462 tls_peers_mgmt_repopulate_list(); |
461 tls_peers_mgmt_repopulate_list(); |
| 463 |
462 |
| 464 /* Right-hand side controls box */ |
463 /* Right-hand side controls box */ |
| 465 bbox = gtk_vbutton_box_new(); |
464 bbox = gtk_vbutton_box_new(); |
| 466 gtk_box_pack_end(GTK_BOX(mgmt_widget), bbox, |
465 gtk_box_pack_end(GTK_BOX(mgmt_widget), bbox, |
| 467 FALSE, FALSE, /* Do not take up space */ |
466 FALSE, FALSE, /* Do not take up space */ |
| 468 0); /* TODO: this padding is probably wrong */ |
467 0); /* TODO: this padding is probably wrong */ |
| 511 all the buttons since nothing is selected yet */ |
510 all the buttons since nothing is selected yet */ |
| 512 tls_peers_mgmt_select_chg_cb(select, NULL); |
511 tls_peers_mgmt_select_chg_cb(select, NULL); |
| 513 |
512 |
| 514 /* Bind us to the tls_peers pool */ |
513 /* Bind us to the tls_peers pool */ |
| 515 tpm_dat->tls_peers = purple_certificate_find_pool("x509", "tls_peers"); |
514 tpm_dat->tls_peers = purple_certificate_find_pool("x509", "tls_peers"); |
| 516 |
515 |
| 517 /**** libpurple signals ****/ |
516 /**** libpurple signals ****/ |
| 518 /* Respond to certificate add/remove by just reloading everything */ |
517 /* Respond to certificate add/remove by just reloading everything */ |
| 519 purple_signal_connect(tpm_dat->tls_peers, "certificate-stored", |
518 purple_signal_connect(tpm_dat->tls_peers, "certificate-stored", |
| 520 tpm_dat, PURPLE_CALLBACK(tls_peers_mgmt_mod_cb), |
519 tpm_dat, PURPLE_CALLBACK(tls_peers_mgmt_mod_cb), |
| 521 NULL); |
520 NULL); |
| 522 purple_signal_connect(tpm_dat->tls_peers, "certificate-deleted", |
521 purple_signal_connect(tpm_dat->tls_peers, "certificate-deleted", |
| 523 tpm_dat, PURPLE_CALLBACK(tls_peers_mgmt_mod_cb), |
522 tpm_dat, PURPLE_CALLBACK(tls_peers_mgmt_mod_cb), |
| 524 NULL); |
523 NULL); |
| 525 |
524 |
| 526 return mgmt_widget; |
525 return mgmt_widget; |
| 527 } |
526 } |
| 528 |
527 |
| 529 const PidginCertificateManager tls_peers_mgmt = { |
528 const PidginCertificateManager tls_peers_mgmt = { |
| 530 tls_peers_mgmt_build, /* Widget creation function */ |
529 tls_peers_mgmt_build, /* Widget creation function */ |
| 569 for ( poollist = purple_certificate_get_pools(); |
568 for ( poollist = purple_certificate_get_pools(); |
| 570 poollist; |
569 poollist; |
| 571 poollist = poollist->next ) { |
570 poollist = poollist->next ) { |
| 572 PurpleCertificatePool *pool = poollist->data; |
571 PurpleCertificatePool *pool = poollist->data; |
| 573 GList *l; |
572 GList *l; |
| 574 |
573 |
| 575 purple_debug_info("gtkcertmgr", |
574 purple_debug_info("gtkcertmgr", |
| 576 "Pool %s found for scheme %s -" |
575 "Pool %s found for scheme %s -" |
| 577 "Enumerating certificates:\n", |
576 "Enumerating certificates:\n", |
| 578 pool->name, pool->scheme_name); |
577 pool->name, pool->scheme_name); |
| 579 |
578 |
| 605 "certmgr", /* Role */ |
604 "certmgr", /* Role */ |
| 606 TRUE); /* Allow resizing */ |
605 TRUE); /* Allow resizing */ |
| 607 g_signal_connect(G_OBJECT(win), "delete_event", |
606 g_signal_connect(G_OBJECT(win), "delete_event", |
| 608 G_CALLBACK(certmgr_close_cb), dlg); |
607 G_CALLBACK(certmgr_close_cb), dlg); |
| 609 |
608 |
| 610 |
609 |
| 611 /* TODO: Retrieve the user-set window size and use it */ |
610 /* TODO: Retrieve the user-set window size and use it */ |
| 612 gtk_window_set_default_size(GTK_WINDOW(win), 400, 400); |
611 gtk_window_set_default_size(GTK_WINDOW(win), 400, 400); |
| 613 |
612 |
| 614 /* Main vbox */ |
613 /* Main vbox */ |
| 615 vbox = pidgin_dialog_get_vbox_with_properties(GTK_DIALOG(win), FALSE, PIDGIN_HIG_BORDER); |
614 vbox = pidgin_dialog_get_vbox_with_properties(GTK_DIALOG(win), FALSE, PIDGIN_HIG_BORDER); |