[22511] | 1 | /* Configure dialog UI */ |
---|
| 2 | /* Copyright (C) 2001-2003 William Tompkins */ |
---|
| 3 | |
---|
| 4 | /* This plugin is free software, distributed under the GNU General Public */ |
---|
| 5 | /* License. */ |
---|
| 6 | /* Please see the file "COPYING" distributed with the Gaim source code */ |
---|
| 7 | /* for more details */ |
---|
| 8 | /* */ |
---|
| 9 | /* */ |
---|
| 10 | /* This software is distributed in the hope that it will be useful, */ |
---|
| 11 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
---|
| 12 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ |
---|
| 13 | /* General Public License for more details. */ |
---|
| 14 | |
---|
| 15 | /* To compile and use: */ |
---|
| 16 | /* See INSTALL file. */ |
---|
| 17 | |
---|
| 18 | #include <string.h> |
---|
| 19 | |
---|
| 20 | #include <gdk/gdk.h> |
---|
| 21 | #include <gtk/gtk.h> |
---|
| 22 | #include <gtk/gtkplug.h> |
---|
| 23 | |
---|
| 24 | #include <debug.h> |
---|
| 25 | #include <gtkdialogs.h> |
---|
| 26 | #include <gtkprefs.h> |
---|
| 27 | #include <gtkprefs.h> |
---|
| 28 | #include <gaim.h> |
---|
| 29 | |
---|
| 30 | #include "nls.h" |
---|
| 31 | #include "cryptproto.h" |
---|
| 32 | #include "keys.h" |
---|
| 33 | #include "config_ui.h" |
---|
| 34 | |
---|
| 35 | #ifdef _WIN32 |
---|
| 36 | #include "win32dep.h" |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | /*Static vars for the config dialog: */ |
---|
| 40 | static GtkWidget *key_size_entry, *proto_combo; |
---|
| 41 | |
---|
| 42 | /* static GtkListStore *key_list_store = NULL; */ |
---|
| 43 | /* static GtkWidget *key_list_view = NULL; */ |
---|
| 44 | |
---|
| 45 | static GtkWidget *regen_err_label; |
---|
| 46 | static GtkWidget *regen_window = NULL; /* regenerate key popup */ |
---|
| 47 | |
---|
| 48 | static GtkWidget* config_vbox = NULL; /* Our main config pane */ |
---|
| 49 | |
---|
| 50 | /* Callbacks for the Regenerate popup dialog */ |
---|
| 51 | static void config_cancel_regen() { |
---|
| 52 | if (regen_window) { |
---|
| 53 | gtk_widget_destroy(regen_window); |
---|
| 54 | } |
---|
| 55 | regen_window = NULL; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | static void config_do_regen(GtkWidget* hitbutton, GtkWidget *key_list_view) { |
---|
| 59 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(key_list_view)); |
---|
| 60 | GtkListStore *key_list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(key_list_view))); |
---|
| 61 | |
---|
| 62 | const gchar* bits_string = gtk_entry_get_text(GTK_ENTRY(key_size_entry)); |
---|
| 63 | const gchar* proto_string = |
---|
| 64 | gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(proto_combo)->entry)); // should NOT be freed |
---|
| 65 | int bits = 0; |
---|
| 66 | GSList *proto = crypt_proto_list; |
---|
| 67 | gchar *name; |
---|
| 68 | GaimAccount *acct; |
---|
| 69 | gchar key_len[15]; |
---|
| 70 | |
---|
| 71 | GString *key_buf; |
---|
| 72 | GtkTreeIter list_store_iter; |
---|
| 73 | |
---|
| 74 | sscanf(bits_string, "%d", &bits); |
---|
| 75 | |
---|
| 76 | if (bits == 0) { |
---|
| 77 | gtk_label_set_text(GTK_LABEL(regen_err_label), |
---|
| 78 | _("Bad key size")); |
---|
| 79 | return; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if (bits < 512) { |
---|
| 83 | gtk_label_set_text(GTK_LABEL(regen_err_label), |
---|
| 84 | _("Keys < 512 bits are VERY insecure")); |
---|
| 85 | return; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if (bits > 4096) { |
---|
| 89 | gtk_label_set_text(GTK_LABEL(regen_err_label), |
---|
| 90 | _("Keys > 4096 bits will cause extreme\n" |
---|
| 91 | "message bloat, causing problems with\n" |
---|
| 92 | "message transmission")); |
---|
| 93 | return; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | while (proto != NULL && |
---|
| 97 | strcmp(proto_string, ((crypt_proto*)proto->data)->name) != 0) { |
---|
| 98 | proto = proto->next; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | if (proto == NULL) { |
---|
| 102 | gaim_debug(GAIM_DEBUG_ERROR, "gaim-encryption", "Can't find protocol in list! Aigh!\n"); |
---|
| 103 | return; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | if (gtk_tree_selection_get_selected(selection, NULL, &list_store_iter)) { |
---|
| 107 | gtk_tree_model_get(GTK_TREE_MODEL(key_list_store), &list_store_iter, 0, &name, 4, &acct, -1); |
---|
| 108 | gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "regen for name: '%s', acct: %p\n", name, acct); |
---|
| 109 | |
---|
| 110 | GE_make_private_pair((crypt_proto*)proto->data, name, acct, bits); |
---|
| 111 | |
---|
| 112 | snprintf(key_len, sizeof(key_len), "%d", bits); |
---|
| 113 | |
---|
| 114 | key_buf = g_string_new_len(GE_find_key_by_name(GE_my_pub_ring, name, acct)->fingerprint, |
---|
| 115 | KEY_FINGERPRINT_LENGTH); |
---|
| 116 | |
---|
| 117 | gtk_list_store_set(key_list_store, &list_store_iter, |
---|
| 118 | 1, key_len, |
---|
| 119 | 2, key_buf->str, |
---|
| 120 | 3, proto_string, |
---|
| 121 | -1); |
---|
| 122 | |
---|
| 123 | g_string_free(key_buf, TRUE); |
---|
| 124 | g_free(name); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | config_cancel_regen(); |
---|
| 128 | |
---|
| 129 | hitbutton = hitbutton; /* unused */ |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | /* Display the Regenerate Key popup, and set up the above callbacks */ |
---|
| 133 | /* (used as a callback from the main Config dialog, below) */ |
---|
| 134 | static void config_regen_key(GtkWidget* hitbutton, GtkWidget* key_list_view) { |
---|
| 135 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(key_list_view)); |
---|
| 136 | |
---|
| 137 | GtkWidget *vbox, *hbox, *label, *table, *button; |
---|
| 138 | GList *proto_list = NULL; |
---|
| 139 | key_ring* iter; |
---|
| 140 | |
---|
| 141 | if (regen_window != NULL) return; |
---|
| 142 | |
---|
| 143 | GAIM_DIALOG(regen_window); |
---|
| 144 | gtk_widget_set_size_request(regen_window, 300, 150); |
---|
| 145 | gtk_window_set_title(GTK_WINDOW(regen_window), _("Generate Keys")); |
---|
| 146 | g_signal_connect(G_OBJECT(regen_window), "destroy", |
---|
| 147 | GTK_SIGNAL_FUNC(config_cancel_regen), NULL); |
---|
| 148 | |
---|
| 149 | vbox = gtk_vbox_new(0, 2); |
---|
| 150 | gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); |
---|
| 151 | gtk_container_add(GTK_CONTAINER(regen_window), vbox); |
---|
| 152 | gtk_widget_show (vbox); |
---|
| 153 | |
---|
| 154 | if (!gtk_tree_selection_get_selected(selection, NULL, NULL)) { |
---|
| 155 | label = gtk_label_new(_("No key selected to re-generate!")); |
---|
| 156 | gtk_box_pack_start(GTK_BOX(vbox), label, 0, 0, 0); |
---|
| 157 | gtk_widget_show(label); |
---|
| 158 | |
---|
| 159 | hbox = gtk_hbox_new(FALSE, 2); |
---|
| 160 | gtk_box_pack_end(GTK_BOX(vbox), hbox, 0, 0, 0); |
---|
| 161 | gtk_widget_show(hbox); |
---|
| 162 | |
---|
| 163 | button = gtk_button_new_with_label(_("OK")); |
---|
| 164 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 165 | GTK_SIGNAL_FUNC(config_cancel_regen), NULL); |
---|
| 166 | gtk_box_pack_end(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 167 | gtk_widget_set_size_request(button, 100, -1); |
---|
| 168 | gtk_widget_show(button); |
---|
| 169 | gtk_widget_show(regen_window); |
---|
| 170 | return; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | /* Start 2 x 2 table */ |
---|
| 174 | table = gtk_table_new(2, 2, FALSE); |
---|
| 175 | gtk_box_pack_start(GTK_BOX(vbox), table, 0, 0, 0); |
---|
| 176 | gtk_widget_show(table); |
---|
| 177 | |
---|
| 178 | /* First column */ |
---|
| 179 | label = gtk_label_new(_("Encryption protocol:")); |
---|
| 180 | gtk_widget_set_size_request(label, 150, -1); |
---|
| 181 | gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); |
---|
| 182 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, |
---|
| 183 | 0, 0, 0, 0); |
---|
| 184 | gtk_widget_show(label); |
---|
| 185 | |
---|
| 186 | label = gtk_label_new(_("Key size:")); |
---|
| 187 | gtk_widget_set_size_request(label, 150, -1); |
---|
| 188 | gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); |
---|
| 189 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, |
---|
| 190 | 0, 0, 0, 0); |
---|
| 191 | gtk_widget_show(label); |
---|
| 192 | |
---|
| 193 | /* Second column: */ |
---|
| 194 | proto_combo = gtk_combo_new(); |
---|
| 195 | gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(proto_combo)->entry), |
---|
| 196 | ((crypt_proto*)crypt_proto_list->data)->name); |
---|
| 197 | gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(proto_combo)->entry), |
---|
| 198 | FALSE); |
---|
| 199 | for( iter = crypt_proto_list; iter != NULL; iter = iter->next ) { |
---|
| 200 | proto_list = g_list_append(proto_list, |
---|
| 201 | ((crypt_proto *)iter->data)->name); |
---|
| 202 | } |
---|
| 203 | gtk_combo_set_popdown_strings(GTK_COMBO (proto_combo), proto_list); |
---|
| 204 | g_list_free(proto_list); |
---|
| 205 | gtk_table_attach(GTK_TABLE(table), proto_combo, 1, 2, 0, 1, |
---|
| 206 | 0, 0, 0, 0); |
---|
| 207 | |
---|
| 208 | gtk_widget_set_size_request(proto_combo, 85, -1); |
---|
| 209 | gtk_widget_show(proto_combo); |
---|
| 210 | |
---|
| 211 | key_size_entry = gtk_entry_new(); |
---|
| 212 | gtk_entry_set_max_length(GTK_ENTRY(key_size_entry), 5); |
---|
| 213 | gtk_entry_set_text(GTK_ENTRY(key_size_entry), "1024"); |
---|
| 214 | gtk_table_attach(GTK_TABLE(table), key_size_entry, 1, 2, 1, 2, |
---|
| 215 | 0, 0, 0, 0); |
---|
| 216 | gtk_widget_set_size_request(key_size_entry, 85, -1); |
---|
| 217 | gtk_widget_show(key_size_entry); |
---|
| 218 | /* End of 2x2 table */ |
---|
| 219 | |
---|
| 220 | regen_err_label = gtk_label_new(""); |
---|
| 221 | gtk_box_pack_start(GTK_BOX(vbox), regen_err_label, 0, 0, 0); |
---|
| 222 | gtk_widget_show(regen_err_label); |
---|
| 223 | |
---|
| 224 | hbox = gtk_hbox_new(FALSE, 2); |
---|
| 225 | gtk_box_pack_end(GTK_BOX(vbox), hbox, 0, 0, 0); |
---|
| 226 | gtk_widget_show(hbox); |
---|
| 227 | |
---|
| 228 | button = gtk_button_new_with_label(_("Cancel")); |
---|
| 229 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 230 | GTK_SIGNAL_FUNC(config_cancel_regen), NULL); |
---|
| 231 | gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 232 | gtk_widget_set_size_request(button, 100, -1); |
---|
| 233 | gtk_widget_show(button); |
---|
| 234 | |
---|
| 235 | button = gtk_button_new_with_label(_("Ok")); |
---|
| 236 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 237 | GTK_SIGNAL_FUNC(config_do_regen), key_list_view); |
---|
| 238 | gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 239 | gtk_widget_set_size_request(button, 100, -1); |
---|
| 240 | gtk_widget_show(button); |
---|
| 241 | |
---|
| 242 | gtk_widget_show(regen_window); |
---|
| 243 | |
---|
| 244 | hitbutton = hitbutton; /* unused */ |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | /* button handler: */ |
---|
| 248 | static void delete_local_key(GtkWidget* hitbutton, GtkWidget* key_list_view) { |
---|
| 249 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(key_list_view)); |
---|
| 250 | GtkListStore *key_list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(key_list_view))); |
---|
| 251 | GtkTreeIter list_store_iter; |
---|
| 252 | |
---|
| 253 | gchar *name; |
---|
| 254 | GaimAccount *acct; |
---|
| 255 | |
---|
| 256 | gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "delete local key\n"); |
---|
| 257 | |
---|
| 258 | if (regen_window != NULL) return; |
---|
| 259 | |
---|
| 260 | if (gtk_tree_selection_get_selected(selection, NULL, &list_store_iter)) { |
---|
| 261 | |
---|
| 262 | gtk_tree_model_get(GTK_TREE_MODEL(key_list_store), &list_store_iter, 0, &name, 4, &acct, -1); |
---|
| 263 | |
---|
| 264 | { |
---|
| 265 | GtkWidget * confirm_dialog = |
---|
| 266 | gtk_message_dialog_new(0, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, |
---|
| 267 | "%s : %s", _("Delete Key"), name); |
---|
| 268 | |
---|
| 269 | gint confirm_response = gtk_dialog_run( GTK_DIALOG(confirm_dialog) ); |
---|
| 270 | gtk_widget_destroy(confirm_dialog); |
---|
| 271 | |
---|
| 272 | if (confirm_response != GTK_RESPONSE_OK) return; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "deleting '%s' : %p\n", name, acct); |
---|
| 276 | |
---|
| 277 | GE_del_key_from_file(Public_key_file, name, acct); |
---|
| 278 | GE_del_key_from_file(Private_key_file, name, acct); |
---|
| 279 | |
---|
| 280 | GE_del_key_from_ring(GE_my_pub_ring, name, acct); |
---|
| 281 | GE_del_key_from_ring(GE_my_priv_ring, name, acct); |
---|
| 282 | |
---|
| 283 | gtk_list_store_remove(key_list_store, &list_store_iter); |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | hitbutton = hitbutton; /* unused */ |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | /* button handler: */ |
---|
| 290 | static void delete_buddy_key(GtkWidget* hitbutton, GtkWidget* key_list_view) { |
---|
| 291 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(key_list_view)); |
---|
| 292 | GtkListStore *key_list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(key_list_view))); |
---|
| 293 | GtkTreeIter list_store_iter; |
---|
| 294 | |
---|
| 295 | gchar *name; |
---|
| 296 | GaimAccount *acct; |
---|
| 297 | gint num; |
---|
| 298 | |
---|
| 299 | gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "delete buddy key\n"); |
---|
| 300 | |
---|
| 301 | if (regen_window != NULL) return; |
---|
| 302 | |
---|
| 303 | if (gtk_tree_selection_get_selected(selection, NULL, &list_store_iter)) { |
---|
| 304 | |
---|
| 305 | gtk_tree_model_get(GTK_TREE_MODEL(key_list_store), &list_store_iter, 0, |
---|
| 306 | &name, 4, &acct, 5, &num, -1); |
---|
| 307 | |
---|
| 308 | { |
---|
| 309 | GtkWidget * confirm_dialog = |
---|
| 310 | gtk_message_dialog_new(0, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, |
---|
| 311 | "%s %s", _("Delete Key"), name); |
---|
| 312 | |
---|
| 313 | gint confirm_response = gtk_dialog_run( GTK_DIALOG(confirm_dialog) ); |
---|
| 314 | gtk_widget_destroy(confirm_dialog); |
---|
| 315 | |
---|
| 316 | if (confirm_response != GTK_RESPONSE_OK) return; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | /* gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "From file: %d : %s\n", num, name); */ |
---|
| 320 | GE_del_one_key_from_file(Buddy_key_file, num, name); |
---|
| 321 | GE_del_key_from_ring(GE_buddy_ring, name, acct); |
---|
| 322 | |
---|
| 323 | gtk_list_store_remove(key_list_store, &list_store_iter); |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | hitbutton = hitbutton; /* unused */ |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | /* button handler: */ |
---|
| 330 | static void copy_fp_to_clipboard(GtkWidget* hitbutton, GtkWidget* key_list_view) { |
---|
| 331 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(key_list_view)); |
---|
| 332 | GtkListStore *key_list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(key_list_view))); |
---|
| 333 | GtkTreeIter list_store_iter; |
---|
| 334 | |
---|
| 335 | gchar *fptext; |
---|
| 336 | |
---|
| 337 | gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "copy to clipboard\n"); |
---|
| 338 | |
---|
| 339 | if (regen_window != NULL) return; |
---|
| 340 | |
---|
| 341 | if (gtk_tree_selection_get_selected(selection, NULL, &list_store_iter)) { |
---|
| 342 | gtk_tree_model_get(GTK_TREE_MODEL(key_list_store), &list_store_iter, 2, &fptext, -1); |
---|
| 343 | |
---|
| 344 | /* gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "copy :%s:\n", fptext); */ |
---|
| 345 | |
---|
| 346 | gtk_clipboard_set_text( gtk_clipboard_get (GDK_SELECTION_PRIMARY), fptext, strlen(fptext) ); |
---|
| 347 | gtk_clipboard_set_text( gtk_clipboard_get (GDK_SELECTION_CLIPBOARD), fptext, strlen(fptext) ); |
---|
| 348 | g_free(fptext); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | hitbutton = hitbutton; /* unused */ |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | GtkWidget* GE_create_key_vbox(key_ring *ring, gboolean local, GtkWidget** key_list_view) { |
---|
| 355 | GtkWidget *keybox = gtk_vbox_new(FALSE, 10); |
---|
| 356 | GtkWidget *keywin = gtk_scrolled_window_new(0, 0); |
---|
| 357 | |
---|
| 358 | GtkListStore *key_list_store; |
---|
| 359 | GtkTreeIter list_store_iter; |
---|
| 360 | GtkCellRenderer *renderer; |
---|
| 361 | GtkTreeViewColumn *col; |
---|
| 362 | key_ring* iter; |
---|
| 363 | GString* key_buf; |
---|
| 364 | gint num; |
---|
| 365 | |
---|
| 366 | gtk_widget_show(keybox); |
---|
| 367 | gtk_box_pack_start(GTK_BOX(keybox), keywin, 0, 0, 0); |
---|
| 368 | |
---|
| 369 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (keywin), |
---|
| 370 | GTK_POLICY_AUTOMATIC, |
---|
| 371 | GTK_POLICY_ALWAYS); |
---|
| 372 | gtk_widget_set_size_request (keywin, -1, 250); |
---|
| 373 | gtk_widget_show(keywin); |
---|
| 374 | |
---|
| 375 | key_list_store = gtk_list_store_new (6, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, |
---|
| 376 | G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_INT, -1); |
---|
| 377 | |
---|
| 378 | *key_list_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(key_list_store)); |
---|
| 379 | |
---|
| 380 | gtk_container_add(GTK_CONTAINER(keywin), *key_list_view); |
---|
| 381 | gtk_widget_show(*key_list_view); |
---|
| 382 | |
---|
| 383 | g_object_unref (G_OBJECT(key_list_store)); |
---|
| 384 | |
---|
| 385 | renderer = gtk_cell_renderer_text_new(); |
---|
| 386 | |
---|
| 387 | if (local) { |
---|
| 388 | col = gtk_tree_view_column_new_with_attributes(_("Account"), renderer, "text", 0, NULL); |
---|
| 389 | } else { |
---|
| 390 | col = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, "text", 0, NULL); |
---|
| 391 | } |
---|
| 392 | gtk_tree_view_append_column(GTK_TREE_VIEW(*key_list_view), col); |
---|
| 393 | |
---|
| 394 | col = gtk_tree_view_column_new_with_attributes(_("Bits"), renderer, "text", 1, NULL); |
---|
| 395 | gtk_tree_view_append_column(GTK_TREE_VIEW(*key_list_view), col); |
---|
| 396 | |
---|
| 397 | col = gtk_tree_view_column_new_with_attributes(_("Key Fingerprint"), renderer, "text", 2, NULL); |
---|
| 398 | gtk_tree_view_append_column(GTK_TREE_VIEW(*key_list_view), col); |
---|
| 399 | |
---|
| 400 | num = 0; |
---|
| 401 | for( iter = ring; iter != NULL; iter = iter->next ) { |
---|
| 402 | gtk_list_store_append(key_list_store, &list_store_iter); |
---|
| 403 | |
---|
| 404 | key_buf = g_string_new_len(((key_ring_data *)iter->data)->key->fingerprint, |
---|
| 405 | KEY_FINGERPRINT_LENGTH); |
---|
| 406 | |
---|
| 407 | gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "Set List Item: name: '%s', acct: %p, num: %d\n", |
---|
| 408 | ((key_ring_data *)iter->data)->name, ((key_ring_data *)iter->data)->account, num); |
---|
| 409 | |
---|
| 410 | gtk_list_store_set(key_list_store, &list_store_iter, |
---|
| 411 | 0, ((key_ring_data *)iter->data)->name, |
---|
| 412 | 1, ((key_ring_data *)iter->data)->key->length, |
---|
| 413 | 2, key_buf->str, |
---|
| 414 | 3, ((key_ring_data *)iter->data)->key->proto->name, |
---|
| 415 | 4, ((key_ring_data *)iter->data)->account, |
---|
| 416 | 5, num, |
---|
| 417 | -1); |
---|
| 418 | g_string_free(key_buf, TRUE); |
---|
| 419 | ++num; |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(*key_list_view), TRUE); |
---|
| 423 | |
---|
| 424 | return keybox; |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | |
---|
| 428 | /* Todo: */ |
---|
| 429 | /* - Make sure we aren't leaking memory on loose widget references */ |
---|
| 430 | |
---|
| 431 | /* Called when Gaim wants us to show our config dialog */ |
---|
| 432 | |
---|
| 433 | GtkWidget* GE_get_config_frame(GaimPlugin *plugin) { |
---|
| 434 | GtkWidget *keybox; |
---|
| 435 | GtkWidget *hbox; |
---|
| 436 | GtkWidget *button; |
---|
| 437 | GtkWidget *notebook; |
---|
| 438 | GtkWidget *checkbox_vbox; |
---|
| 439 | |
---|
| 440 | GtkWidget *cur_list_view; |
---|
| 441 | |
---|
| 442 | config_vbox = gtk_vbox_new(FALSE, 2); |
---|
| 443 | |
---|
| 444 | gtk_container_set_border_width (GTK_CONTAINER (config_vbox), 12); |
---|
| 445 | |
---|
| 446 | gtk_widget_show (config_vbox); |
---|
| 447 | |
---|
| 448 | g_signal_connect(G_OBJECT(config_vbox), "destroy", |
---|
| 449 | GTK_SIGNAL_FUNC(config_cancel_regen), NULL); |
---|
| 450 | |
---|
| 451 | |
---|
| 452 | notebook = gtk_notebook_new(); |
---|
| 453 | gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP); |
---|
| 454 | gtk_box_pack_start(GTK_BOX(config_vbox), notebook, 0, 0, 0); |
---|
| 455 | gtk_widget_show(notebook); |
---|
| 456 | |
---|
| 457 | |
---|
| 458 | /* Notebook page 1: Config */ |
---|
| 459 | |
---|
| 460 | checkbox_vbox = gtk_vbox_new(FALSE, 2); |
---|
| 461 | gtk_container_set_border_width(GTK_CONTAINER(checkbox_vbox), 2); |
---|
| 462 | gtk_widget_show(checkbox_vbox); |
---|
| 463 | gtk_notebook_append_page (GTK_NOTEBOOK (notebook), checkbox_vbox, |
---|
| 464 | gtk_label_new(_("Config"))); |
---|
| 465 | |
---|
| 466 | gaim_gtk_prefs_checkbox(_("Accept key automatically if no key on file"), |
---|
| 467 | "/plugins/gtk/encrypt/accept_unknown_key", checkbox_vbox); |
---|
| 468 | |
---|
| 469 | gaim_gtk_prefs_checkbox(_("Accept conflicting keys automatically (security risk)"), |
---|
| 470 | "/plugins/gtk/encrypt/accept_conflicting_key", checkbox_vbox); |
---|
| 471 | |
---|
| 472 | gaim_gtk_prefs_checkbox(_("Automatically encrypt if sent an encrypted message"), |
---|
| 473 | "/plugins/gtk/encrypt/encrypt_response", checkbox_vbox); |
---|
| 474 | |
---|
| 475 | gaim_gtk_prefs_checkbox(_("Broadcast encryption capability"), |
---|
| 476 | "/plugins/gtk/encrypt/broadcast_notify", checkbox_vbox); |
---|
| 477 | |
---|
| 478 | gaim_gtk_prefs_checkbox(_("Automatically encrypt if buddy has plugin"), |
---|
| 479 | "/plugins/gtk/encrypt/encrypt_if_notified", checkbox_vbox); |
---|
| 480 | |
---|
| 481 | |
---|
| 482 | /* Notebook page 2: Local keys */ |
---|
| 483 | |
---|
| 484 | keybox = GE_create_key_vbox(GE_my_priv_ring, TRUE, &cur_list_view); |
---|
| 485 | |
---|
| 486 | hbox = gtk_hbox_new(FALSE, 2); |
---|
| 487 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 2); |
---|
| 488 | |
---|
| 489 | gtk_box_pack_start(GTK_BOX(keybox), hbox, 0, 0, 0); |
---|
| 490 | gtk_widget_show(hbox); |
---|
| 491 | |
---|
| 492 | button = gtk_button_new_with_label(_("Delete Key")); |
---|
| 493 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 494 | GTK_SIGNAL_FUNC(delete_local_key), cur_list_view); |
---|
| 495 | gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 496 | |
---|
| 497 | gtk_widget_show(button); |
---|
| 498 | |
---|
| 499 | button = gtk_button_new_with_label(_("Regenerate Key")); |
---|
| 500 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 501 | GTK_SIGNAL_FUNC(config_regen_key), cur_list_view); |
---|
| 502 | gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 503 | |
---|
| 504 | gtk_widget_show(button); |
---|
| 505 | |
---|
| 506 | button = gtk_button_new_with_label(_("Copy Fingerprint to Clipboard")); |
---|
| 507 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 508 | GTK_SIGNAL_FUNC(copy_fp_to_clipboard), cur_list_view); |
---|
| 509 | gtk_box_pack_end(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 510 | |
---|
| 511 | gtk_widget_show(button); |
---|
| 512 | |
---|
| 513 | |
---|
| 514 | gtk_notebook_append_page (GTK_NOTEBOOK (notebook), keybox, gtk_label_new(_("Local Keys"))); |
---|
| 515 | |
---|
| 516 | |
---|
| 517 | /* Notebook page 3: Saved Buddy Keys */ |
---|
| 518 | |
---|
| 519 | keybox = GE_create_key_vbox(GE_saved_buddy_ring, FALSE, &cur_list_view); |
---|
| 520 | |
---|
| 521 | hbox = gtk_hbox_new(FALSE, 2); |
---|
| 522 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 2); |
---|
| 523 | gtk_box_pack_start(GTK_BOX(keybox), hbox, 0, 0, 0); |
---|
| 524 | gtk_widget_show(hbox); |
---|
| 525 | |
---|
| 526 | button = gtk_button_new_with_label(_("Delete Key")); |
---|
| 527 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 528 | GTK_SIGNAL_FUNC(delete_buddy_key), cur_list_view); |
---|
| 529 | gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 530 | |
---|
| 531 | gtk_widget_show(button); |
---|
| 532 | |
---|
| 533 | button = gtk_button_new_with_label(_("Copy Fingerprint to Clipboard")); |
---|
| 534 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 535 | GTK_SIGNAL_FUNC(copy_fp_to_clipboard), cur_list_view); |
---|
| 536 | gtk_box_pack_end(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 537 | |
---|
| 538 | gtk_widget_show(button); |
---|
| 539 | |
---|
| 540 | gtk_notebook_append_page (GTK_NOTEBOOK (notebook), keybox, |
---|
| 541 | gtk_label_new(_("Trusted Buddy Keys"))); |
---|
| 542 | |
---|
| 543 | |
---|
| 544 | /* Notebook page 4: In-Memory Buddy Keys */ |
---|
| 545 | |
---|
| 546 | keybox = GE_create_key_vbox(GE_buddy_ring, FALSE, &cur_list_view); |
---|
| 547 | |
---|
| 548 | hbox = gtk_hbox_new(FALSE, 2); |
---|
| 549 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 2); |
---|
| 550 | gtk_box_pack_start(GTK_BOX(keybox), hbox, 0, 0, 0); |
---|
| 551 | gtk_widget_show(hbox); |
---|
| 552 | |
---|
| 553 | button = gtk_button_new_with_label(_("Delete Key")); |
---|
| 554 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 555 | GTK_SIGNAL_FUNC(delete_buddy_key), cur_list_view); |
---|
| 556 | gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 557 | |
---|
| 558 | gtk_widget_show(button); |
---|
| 559 | |
---|
| 560 | button = gtk_button_new_with_label(_("Copy Fingerprint to Clipboard")); |
---|
| 561 | g_signal_connect(G_OBJECT(button), "clicked", |
---|
| 562 | GTK_SIGNAL_FUNC(copy_fp_to_clipboard), cur_list_view); |
---|
| 563 | gtk_box_pack_end(GTK_BOX(hbox), button, 0, 0, 0); |
---|
| 564 | |
---|
| 565 | gtk_widget_show(button); |
---|
| 566 | |
---|
| 567 | gtk_notebook_append_page (GTK_NOTEBOOK (notebook), keybox, |
---|
| 568 | gtk_label_new(_("Recent Buddy Keys"))); |
---|
| 569 | |
---|
| 570 | |
---|
| 571 | /* make it so that when the config_vbox object is finalized, our pointer to it is nulled out */ |
---|
| 572 | g_object_add_weak_pointer(G_OBJECT(config_vbox), (gpointer*) &config_vbox); |
---|
| 573 | |
---|
| 574 | return config_vbox; |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | void GE_config_unload() { |
---|
| 578 | gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "GE_config_unload: %p\n", config_vbox); |
---|
| 579 | if (config_vbox) { |
---|
| 580 | /* We don't want our internal static functions getting called after the plugin */ |
---|
| 581 | /* has been unloaded, so disconnect the callback that kills the key regen window */ |
---|
| 582 | /* For good measure, kill the key regen window too */ |
---|
| 583 | |
---|
| 584 | g_signal_handlers_disconnect_by_func(GTK_OBJECT(config_vbox), |
---|
| 585 | GTK_SIGNAL_FUNC(config_cancel_regen), NULL); |
---|
| 586 | config_cancel_regen(); |
---|
| 587 | config_vbox = NULL; |
---|
| 588 | } |
---|
| 589 | } |
---|