~ubuntu-branches/ubuntu/oneiric/pidgin-otr/oneiric-security

« back to all changes in this revision

Viewing changes to gtk-ui.c

  • Committer: Bazaar Package Importer
  • Author(s): Thibaut VARENE
  • Date: 2008-07-10 17:34:32 UTC
  • mfrom: (2.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080710173432-aqx359odj7cp182a
Tags: 3.2.0-2
Make key generation use /dev/urandom (Closes: #489523)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  Off-the-Record Messaging plugin for pidgin
3
 
 *  Copyright (C) 2004-2005  Nikita Borisov and Ian Goldberg
 
3
 *  Copyright (C) 2004-2008  Ian Goldberg, Rob Smits,
 
4
 *                           Chris Alexander, Nikita Borisov
4
5
 *                           <otr@cypherpunks.ca>
5
6
 *
6
7
 *  This program is free software; you can redistribute it and/or modify
17
18
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
 */
19
20
 
 
21
/* config.h */
 
22
#ifdef HAVE_CONFIG_H
 
23
#include "config.h"
 
24
#endif
 
25
 
20
26
/* system headers */
21
27
#include <gtk/gtk.h>
22
28
 
32
38
#include "notify.h"
33
39
#include "gtkutils.h"
34
40
 
 
41
#ifdef ENABLE_NLS
 
42
/* internationalisation header */
 
43
#include <glib/gi18n-lib.h>
 
44
#endif
 
45
 
35
46
/* purple-otr headers */
36
47
#include "dialogs.h"
37
48
#include "ui.h"
38
49
#include "otr-plugin.h"
39
50
 
40
 
struct otroptionsdata {
 
51
struct otrsettingsdata {
41
52
    GtkWidget *enablebox;
42
53
    GtkWidget *automaticbox;
43
54
    GtkWidget *onlyprivatebox;
 
55
    GtkWidget *avoidloggingotrbox;
 
56
};
 
57
 
 
58
struct otroptionsdata {
 
59
    GtkWidget *showotrbutton;
44
60
};
45
61
 
46
62
static struct {
55
71
    GtkWidget *disconnect_button;
56
72
    GtkWidget *forget_button;
57
73
    GtkWidget *verify_button;
 
74
    struct otrsettingsdata os;
58
75
    struct otroptionsdata oo;
59
76
} ui_layout;
60
77
 
61
78
static const gchar *trust_states[] = {
62
 
    "Not private",
63
 
    "Unverified",
64
 
    "Private",
65
 
    "Finished"
 
79
    N_("Not private"),
 
80
    N_("Unverified"),
 
81
    N_("Private"),
 
82
    N_("Finished")
66
83
};
67
84
 
68
85
static void account_menu_changed_cb(GtkWidget *item, PurpleAccount *account,
82
99
                fingerprint_buf, accountname, protocol);
83
100
 
84
101
        if (fingerprint) {
85
 
            sprintf(s, "Fingerprint: %.80s", fingerprint);
 
102
            sprintf(s, _("Fingerprint: %.80s"), fingerprint);
86
103
            if (ui_layout.generate_button)
87
104
                gtk_widget_set_sensitive(ui_layout.generate_button, 0);
88
105
        } else {
89
 
            sprintf(s, "No key present");
 
106
            sprintf(s, _("No key present"));
90
107
            if (ui_layout.generate_button)
91
108
                gtk_widget_set_sensitive(ui_layout.generate_button, 1);
92
109
        }
93
110
    } else {
94
 
        sprintf(s, "No account available");
 
111
        sprintf(s, _("No account available"));
95
112
        if (ui_layout.generate_button)
96
113
            gtk_widget_set_sensitive(ui_layout.generate_button, 0);
97
114
    }
101
118
    }
102
119
}
103
120
 
104
 
static GtkWidget *accountmenu_get_selected_item(void)
105
 
{
106
 
    GtkWidget *menu;
107
 
 
108
 
    if (ui_layout.accountmenu == NULL) return NULL;
109
 
 
110
 
    menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(ui_layout.accountmenu));
111
 
    return gtk_menu_get_active(GTK_MENU(menu));
112
 
}
113
 
 
114
 
static PurpleAccount *item_get_account(GtkWidget *item)
115
 
{
116
 
    if (!item) return NULL;
117
 
    return g_object_get_data(G_OBJECT(item), "account");
118
 
}
119
 
 
120
121
/* Call this function when the DSA key is updated; it will redraw the
121
122
 * UI, if visible. */
122
123
static void otrg_gtk_ui_update_fingerprint(void)
123
124
{
124
 
    GtkWidget *item;
125
 
    PurpleAccount *account;
126
 
    gpointer user_data;
127
 
 
128
 
    item = accountmenu_get_selected_item();
129
 
 
130
 
    if (!item) return;
131
 
 
132
 
    account   = item_get_account(item);
133
 
    user_data = g_object_get_data(G_OBJECT(ui_layout.accountmenu),
134
 
            "user_data");
135
 
 
136
 
    account_menu_changed_cb(item, account, user_data);
 
125
    g_signal_emit_by_name(G_OBJECT(ui_layout.accountmenu), "changed");
137
126
}
138
127
 
139
128
static void account_menu_added_removed_cb(PurpleAccount *account, void *data)
179
168
            titles[0] = context->username;
180
169
            if (context->msgstate == OTRL_MSGSTATE_ENCRYPTED &&
181
170
                    context->active_fingerprint != fingerprint) {
182
 
                titles[1] = "Unused";
 
171
                titles[1] = _("Unused");
183
172
            } else {
184
173
                titles[1] = (gchar *)
185
 
                    trust_states[otrg_plugin_context_to_trust(context)];
 
174
                    _(trust_states[otrg_plugin_context_to_trust(context)]);
186
175
            }
187
176
            titles[2] = (fingerprint->trust && fingerprint->trust[0]) ?
188
 
                "Yes" : "No";
 
177
                _("Yes") : _("No");
189
178
            otrl_privkey_hash_to_human(hash, fingerprint->fingerprint);
190
179
            titles[3] = hash;
191
180
            p = purple_find_prpl(context->protocol);
192
 
            proto_name = (p && p->info->name) ? p->info->name : "Unknown";
 
181
            proto_name = (p && p->info->name) ? p->info->name : _("Unknown");
193
182
            titles[4] = g_strdup_printf("%s (%s)", context->accountname,
194
183
                proto_name);
195
184
            i = gtk_clist_append(GTK_CLIST(keylist), titles);
217
206
static void generate(GtkWidget *widget, gpointer data)
218
207
{
219
208
    PurpleAccount *account;
220
 
    account = item_get_account(accountmenu_get_selected_item());
 
209
    account = pidgin_account_option_menu_get_selected(ui_layout.accountmenu);
221
210
        
222
211
    if (account == NULL) return;
223
212
        
239
228
    ui_layout.disconnect_button = NULL;
240
229
    ui_layout.forget_button = NULL;
241
230
    ui_layout.verify_button = NULL;
242
 
    ui_layout.oo.enablebox = NULL;
243
 
    ui_layout.oo.automaticbox = NULL;
244
 
    ui_layout.oo.onlyprivatebox = NULL;
 
231
    ui_layout.os.enablebox = NULL;
 
232
    ui_layout.os.automaticbox = NULL;
 
233
    ui_layout.os.onlyprivatebox = NULL;
245
234
}
246
235
 
247
236
static void clist_selected(GtkWidget *widget, gint row, gint column,
385
374
    otrg_dialog_verify_fingerprint(fingerprint);
386
375
}
387
376
 
388
 
static void otroptions_clicked_cb(GtkButton *button, struct otroptionsdata *oo)
 
377
static void otrsettings_clicked_cb(GtkButton *button,
 
378
        struct otrsettingsdata *os)
389
379
{
390
 
    gtk_widget_set_sensitive(oo->enablebox, TRUE);
 
380
    gtk_widget_set_sensitive(os->enablebox, TRUE);
391
381
    if (gtk_toggle_button_get_active(
392
 
                GTK_TOGGLE_BUTTON(oo->enablebox))) {
393
 
        gtk_widget_set_sensitive(oo->automaticbox, TRUE);
 
382
                GTK_TOGGLE_BUTTON(os->enablebox))) {
 
383
        gtk_widget_set_sensitive(os->automaticbox, TRUE);
394
384
        if (gtk_toggle_button_get_active(
395
 
                    GTK_TOGGLE_BUTTON(oo->automaticbox))) {
396
 
            gtk_widget_set_sensitive(oo->onlyprivatebox, TRUE);
 
385
                    GTK_TOGGLE_BUTTON(os->automaticbox))) {
 
386
            gtk_widget_set_sensitive(os->onlyprivatebox, TRUE);
397
387
        } else {
398
 
            gtk_widget_set_sensitive(oo->onlyprivatebox, FALSE);
 
388
            gtk_widget_set_sensitive(os->onlyprivatebox, FALSE);
399
389
        }
 
390
        gtk_widget_set_sensitive(os->avoidloggingotrbox, TRUE);
400
391
    } else {
401
 
        gtk_widget_set_sensitive(oo->automaticbox, FALSE);
402
 
        gtk_widget_set_sensitive(oo->onlyprivatebox, FALSE);
 
392
        gtk_widget_set_sensitive(os->automaticbox, FALSE);
 
393
        gtk_widget_set_sensitive(os->onlyprivatebox, FALSE);
 
394
        gtk_widget_set_sensitive(os->avoidloggingotrbox, FALSE);
403
395
    }
404
396
}
405
397
 
406
 
static void create_otroption_buttons(struct otroptionsdata *oo,
 
398
static void create_otrsettings_buttons(struct otrsettingsdata *os,
407
399
        GtkWidget *vbox)
408
400
{
409
401
    GtkWidget *tempbox1, *tempbox2;
410
402
 
411
 
    oo->enablebox = gtk_check_button_new_with_label("Enable private "
412
 
            "messaging");
413
 
    oo->automaticbox = gtk_check_button_new_with_label("Automatically "
414
 
            "initiate private messaging");
415
 
    oo->onlyprivatebox = gtk_check_button_new_with_label("Require private "
416
 
            "messaging");
 
403
    os->enablebox = gtk_check_button_new_with_label(_("Enable private "
 
404
            "messaging"));
 
405
    os->automaticbox = gtk_check_button_new_with_label(_("Automatically "
 
406
            "initiate private messaging"));
 
407
    os->onlyprivatebox = gtk_check_button_new_with_label(_("Require private "
 
408
            "messaging"));
 
409
    os->avoidloggingotrbox = gtk_check_button_new_with_label(
 
410
            _("Don't log OTR conversations"));
417
411
 
418
 
    gtk_box_pack_start(GTK_BOX(vbox), oo->enablebox,
 
412
    gtk_box_pack_start(GTK_BOX(vbox), os->enablebox,
419
413
            FALSE, FALSE, 0);
420
414
    tempbox1 = gtk_hbox_new(FALSE, 0);
421
415
    gtk_box_pack_start(GTK_BOX(vbox), tempbox1,
423
417
    tempbox2 = gtk_vbox_new(FALSE, 0);
424
418
    gtk_box_pack_start(GTK_BOX(tempbox1), tempbox2, FALSE, FALSE, 5);
425
419
 
426
 
    gtk_box_pack_start(GTK_BOX(tempbox2), oo->automaticbox,
 
420
    gtk_box_pack_start(GTK_BOX(tempbox2), os->automaticbox,
427
421
            FALSE, FALSE, 0);
428
422
    tempbox1 = gtk_hbox_new(FALSE, 0);
429
423
    gtk_box_pack_start(GTK_BOX(tempbox2), tempbox1, FALSE, FALSE, 0);
430
424
    tempbox2 = gtk_vbox_new(FALSE, 0);
431
425
    gtk_box_pack_start(GTK_BOX(tempbox1), tempbox2, FALSE, FALSE, 5);
432
426
 
433
 
    gtk_box_pack_start(GTK_BOX(tempbox2), oo->onlyprivatebox,
 
427
    gtk_box_pack_start(GTK_BOX(tempbox2), os->onlyprivatebox,
434
428
            FALSE, FALSE, 0);
435
429
 
436
 
    g_signal_connect(G_OBJECT(oo->enablebox), "clicked",
437
 
                     G_CALLBACK(otroptions_clicked_cb), oo);
438
 
    g_signal_connect(G_OBJECT(oo->automaticbox), "clicked",
439
 
                     G_CALLBACK(otroptions_clicked_cb), oo);
440
 
    g_signal_connect(G_OBJECT(oo->onlyprivatebox), "clicked",
 
430
    gtk_box_pack_start(GTK_BOX(vbox), os->avoidloggingotrbox, FALSE, FALSE, 5);
 
431
 
 
432
    g_signal_connect(G_OBJECT(os->enablebox), "clicked",
 
433
                     G_CALLBACK(otrsettings_clicked_cb), os);
 
434
    g_signal_connect(G_OBJECT(os->automaticbox), "clicked",
 
435
                     G_CALLBACK(otrsettings_clicked_cb), os);
 
436
    g_signal_connect(G_OBJECT(os->onlyprivatebox), "clicked",
 
437
                     G_CALLBACK(otrsettings_clicked_cb), os);
 
438
    g_signal_connect(G_OBJECT(os->avoidloggingotrbox), "clicked",
 
439
                     G_CALLBACK(otrsettings_clicked_cb), os);
 
440
}
 
441
 
 
442
static void otroptions_clicked_cb(GtkButton *button,
 
443
        struct otroptionsdata *oo)
 
444
{
 
445
    /* This doesn't really do anything useful right now, but is here for
 
446
     * future expansion purposes. */
 
447
    gtk_widget_set_sensitive(oo->showotrbutton, TRUE);
 
448
}
 
449
 
 
450
static void create_otroptions_buttons(struct otroptionsdata *oo,
 
451
        GtkWidget *vbox)
 
452
{
 
453
#ifdef OLD_OTR_BUTTON
 
454
    oo->showotrbutton = gtk_check_button_new_with_label(_("Show OTR button"));
 
455
#else
 
456
    oo->showotrbutton = gtk_check_button_new_with_label(
 
457
            _("Show OTR button in toolbar"));
 
458
#endif
 
459
 
 
460
    gtk_box_pack_start(GTK_BOX(vbox), oo->showotrbutton, FALSE, FALSE, 0);
 
461
 
 
462
    g_signal_connect(G_OBJECT(oo->showotrbutton), "clicked",
441
463
                     G_CALLBACK(otroptions_clicked_cb), oo);
442
464
}
443
465
 
444
466
/* Load the global OTR prefs */
445
467
static void otrg_gtk_ui_global_prefs_load(gboolean *enabledp,
446
 
        gboolean *automaticp, gboolean *onlyprivatep)
 
468
        gboolean *automaticp, gboolean *onlyprivatep,
 
469
        gboolean *avoidloggingotrp)
447
470
{
448
471
    if (purple_prefs_exists("/OTR/enabled")) {
449
472
        *enabledp = purple_prefs_get_bool("/OTR/enabled");
450
473
        *automaticp = purple_prefs_get_bool("/OTR/automatic");
451
474
        *onlyprivatep = purple_prefs_get_bool("/OTR/onlyprivate");
 
475
        *avoidloggingotrp = purple_prefs_get_bool("/OTR/avoidloggingotr");
452
476
    } else {
453
477
        *enabledp = TRUE;
454
478
        *automaticp = TRUE;
455
479
        *onlyprivatep = FALSE;
 
480
        *avoidloggingotrp = FALSE;
456
481
    }
457
482
}
458
483
 
459
484
/* Save the global OTR prefs */
460
485
static void otrg_gtk_ui_global_prefs_save(gboolean enabled,
461
 
        gboolean automatic, gboolean onlyprivate)
 
486
        gboolean automatic, gboolean onlyprivate, gboolean avoidloggingotr)
462
487
{
463
488
    if (! purple_prefs_exists("/OTR")) {
464
489
        purple_prefs_add_none("/OTR");
466
491
    purple_prefs_set_bool("/OTR/enabled", enabled);
467
492
    purple_prefs_set_bool("/OTR/automatic", automatic);
468
493
    purple_prefs_set_bool("/OTR/onlyprivate", onlyprivate);
 
494
    purple_prefs_set_bool("/OTR/avoidloggingotr", avoidloggingotr);
469
495
}
470
496
 
471
497
/* Load the OTR prefs for a particular buddy */
472
498
static void otrg_gtk_ui_buddy_prefs_load(PurpleBuddy *buddy,
473
499
        gboolean *usedefaultp, gboolean *enabledp, gboolean *automaticp,
474
 
        gboolean *onlyprivatep)
 
500
        gboolean *onlyprivatep, gboolean *avoidloggingotrp)
475
501
{
476
502
    PurpleBlistNode *node = &(buddy->node);
477
503
 
478
504
    *usedefaultp = ! purple_blist_node_get_bool(node, "OTR/overridedefault");
479
505
 
480
506
    if (*usedefaultp) {
481
 
        otrg_gtk_ui_global_prefs_load(enabledp, automaticp, onlyprivatep);
 
507
        otrg_gtk_ui_global_prefs_load(enabledp, automaticp, onlyprivatep,
 
508
                avoidloggingotrp);
482
509
    } else {
483
510
        *enabledp = purple_blist_node_get_bool(node, "OTR/enabled");
484
511
        *automaticp = purple_blist_node_get_bool(node, "OTR/automatic");
485
512
        *onlyprivatep = purple_blist_node_get_bool(node, "OTR/onlyprivate");
 
513
        *avoidloggingotrp =
 
514
            purple_blist_node_get_bool(node, "OTR/avoidloggingotr");
486
515
    }
487
516
}
488
517
 
489
518
/* Save the OTR prefs for a particular buddy */
490
519
static void otrg_gtk_ui_buddy_prefs_save(PurpleBuddy *buddy,
491
520
        gboolean usedefault, gboolean enabled, gboolean automatic,
492
 
        gboolean onlyprivate)
 
521
        gboolean onlyprivate, gboolean avoidloggingotr)
493
522
{
494
523
    PurpleBlistNode *node = &(buddy->node);
495
524
 
497
526
    purple_blist_node_set_bool(node, "OTR/enabled", enabled);
498
527
    purple_blist_node_set_bool(node, "OTR/automatic", automatic);
499
528
    purple_blist_node_set_bool(node, "OTR/onlyprivate", onlyprivate);
 
529
    purple_blist_node_set_bool(node, "OTR/avoidloggingotr", avoidloggingotr);
500
530
}
501
531
 
502
 
static void load_otroptions(struct otroptionsdata *oo)
 
532
static void load_otrsettings(struct otrsettingsdata *os)
503
533
{
504
534
    gboolean otrenabled;
505
535
    gboolean otrautomatic;
506
536
    gboolean otronlyprivate;
507
 
 
508
 
    otrg_gtk_ui_global_prefs_load(&otrenabled, &otrautomatic, &otronlyprivate);
509
 
 
510
 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(oo->enablebox),
 
537
    gboolean otravoidloggingotr;
 
538
 
 
539
    otrg_gtk_ui_global_prefs_load(&otrenabled, &otrautomatic, &otronlyprivate,
 
540
            &otravoidloggingotr);
 
541
 
 
542
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(os->enablebox),
511
543
            otrenabled);
512
 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(oo->automaticbox),
 
544
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(os->automaticbox),
513
545
            otrautomatic);
514
 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(oo->onlyprivatebox),
 
546
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(os->onlyprivatebox),
515
547
            otronlyprivate);
516
 
 
517
 
    otroptions_clicked_cb(GTK_BUTTON(oo->enablebox), oo);
 
548
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(os->avoidloggingotrbox),
 
549
            otravoidloggingotr);
 
550
 
 
551
    otrsettings_clicked_cb(GTK_BUTTON(os->enablebox), os);
 
552
}
 
553
 
 
554
/* Load the global OTR UI options */
 
555
static void otrg_gtk_ui_global_options_load(gboolean *showotrbuttonp)
 
556
{
 
557
    if (purple_prefs_exists("/OTR/showotrbutton")) {
 
558
        *showotrbuttonp = purple_prefs_get_bool("/OTR/showotrbutton");
 
559
    } else {
 
560
#ifdef OLD_OTR_BUTTON
 
561
        *showotrbuttonp = FALSE;
 
562
#else
 
563
        *showotrbuttonp = TRUE;
 
564
#endif
 
565
    }
 
566
}
 
567
 
 
568
/* Save the global OTR UI options */
 
569
static void otrg_gtk_ui_global_options_save(gboolean showotrbutton)
 
570
{
 
571
    if (! purple_prefs_exists("/OTR")) {
 
572
        purple_prefs_add_none("/OTR");
 
573
    }
 
574
    if (! purple_prefs_exists("/OTR/showotrbutton")) {
 
575
        purple_prefs_add_bool("/OTR/showotrbutton", showotrbutton);
 
576
    }
 
577
    purple_prefs_set_bool("/OTR/showotrbutton", showotrbutton);
 
578
}
 
579
 
 
580
 
 
581
static void load_otroptions(struct otroptionsdata *oo)
 
582
{
 
583
    gboolean showotrbutton;
 
584
 
 
585
    otrg_gtk_ui_global_options_load(&showotrbutton);
 
586
 
 
587
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(oo->showotrbutton),
 
588
            showotrbutton);
 
589
 
 
590
    otroptions_clicked_cb(GTK_BUTTON(oo->showotrbutton), oo);
518
591
}
519
592
 
520
593
/* Create the privkeys UI, and pack it into the vbox */
525
598
    GtkWidget *label;
526
599
    GtkWidget *frame;
527
600
 
528
 
    frame = gtk_frame_new("My private keys");
 
601
    frame = gtk_frame_new(_("My private keys"));
529
602
    gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
530
603
 
531
604
    fbox = gtk_vbox_new(FALSE, 5);
534
607
 
535
608
    hbox = gtk_hbox_new(FALSE, 5);
536
609
    gtk_box_pack_start(GTK_BOX(fbox), hbox, FALSE, FALSE, 0);
537
 
    label = gtk_label_new("Key for account:");
 
610
    label = gtk_label_new(_("Key for account:"));
538
611
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
539
612
 
540
613
    ui_layout.accountmenu = pidgin_account_option_menu_new(NULL, 1,
559
632
    gtk_signal_connect(GTK_OBJECT(ui_layout.generate_button), "clicked",
560
633
            GTK_SIGNAL_FUNC(generate), NULL);
561
634
 
562
 
    label = gtk_label_new("Generate");
 
635
    label = gtk_label_new(_("Generate"));
563
636
    gtk_container_add(GTK_CONTAINER(ui_layout.generate_button), label);
564
637
 
565
638
    otrg_gtk_ui_update_fingerprint();
568
641
            FALSE, FALSE, 0);
569
642
}
570
643
 
571
 
/* Save the global OTR options whenever they're clicked */
 
644
/* Save the global OTR settings whenever they're clicked */
 
645
static void otrsettings_save_cb(GtkButton *button, struct otrsettingsdata *os)
 
646
{
 
647
    otrg_gtk_ui_global_prefs_save(
 
648
            gtk_toggle_button_get_active(
 
649
                GTK_TOGGLE_BUTTON(os->enablebox)),
 
650
            gtk_toggle_button_get_active(
 
651
                GTK_TOGGLE_BUTTON(os->automaticbox)),
 
652
            gtk_toggle_button_get_active(
 
653
                GTK_TOGGLE_BUTTON(os->onlyprivatebox)),
 
654
            gtk_toggle_button_get_active(
 
655
                GTK_TOGGLE_BUTTON(os->avoidloggingotrbox)));
 
656
 
 
657
    otrg_dialog_resensitize_all();
 
658
}
 
659
 
 
660
/* Save the global OTR UI options whenever they're clicked */
572
661
static void otroptions_save_cb(GtkButton *button, struct otroptionsdata *oo)
573
662
{
574
 
    otrg_gtk_ui_global_prefs_save(
575
 
            gtk_toggle_button_get_active(
576
 
                GTK_TOGGLE_BUTTON(oo->enablebox)),
577
 
            gtk_toggle_button_get_active(
578
 
                GTK_TOGGLE_BUTTON(oo->automaticbox)),
579
 
            gtk_toggle_button_get_active(
580
 
                GTK_TOGGLE_BUTTON(oo->onlyprivatebox)));
 
663
    otrg_gtk_ui_global_options_save(
 
664
            gtk_toggle_button_get_active(
 
665
                GTK_TOGGLE_BUTTON(oo->showotrbutton)));
581
666
 
582
667
    otrg_dialog_resensitize_all();
583
668
}
584
669
 
 
670
/* Make the settings UI, and pack it into the vbox */
 
671
static void make_settings_ui(GtkWidget *vbox)
 
672
{
 
673
    GtkWidget *fbox;
 
674
    GtkWidget *frame;
 
675
 
 
676
    frame = gtk_frame_new(_("Default OTR Settings"));
 
677
    gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
 
678
 
 
679
    fbox = gtk_vbox_new(FALSE, 0);
 
680
    gtk_container_set_border_width(GTK_CONTAINER(fbox), 10);
 
681
    gtk_container_add(GTK_CONTAINER(frame), fbox);
 
682
 
 
683
    create_otrsettings_buttons(&(ui_layout.os), fbox);
 
684
 
 
685
    load_otrsettings(&(ui_layout.os));
 
686
 
 
687
    g_signal_connect(G_OBJECT(ui_layout.os.enablebox), "clicked",
 
688
                     G_CALLBACK(otrsettings_save_cb), &(ui_layout.os));
 
689
    g_signal_connect(G_OBJECT(ui_layout.os.automaticbox), "clicked",
 
690
                     G_CALLBACK(otrsettings_save_cb), &(ui_layout.os));
 
691
    g_signal_connect(G_OBJECT(ui_layout.os.onlyprivatebox), "clicked",
 
692
                     G_CALLBACK(otrsettings_save_cb), &(ui_layout.os));
 
693
    g_signal_connect(G_OBJECT(ui_layout.os.avoidloggingotrbox), "clicked",
 
694
                     G_CALLBACK(otrsettings_save_cb), &(ui_layout.os));
 
695
}
 
696
 
585
697
/* Make the options UI, and pack it into the vbox */
586
698
static void make_options_ui(GtkWidget *vbox)
587
699
{
588
700
    GtkWidget *fbox;
589
701
    GtkWidget *frame;
590
702
 
591
 
    frame = gtk_frame_new("Default OTR Settings");
 
703
    frame = gtk_frame_new(_("OTR UI Options"));
592
704
    gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
593
705
 
594
706
    fbox = gtk_vbox_new(FALSE, 0);
595
707
    gtk_container_set_border_width(GTK_CONTAINER(fbox), 10);
596
708
    gtk_container_add(GTK_CONTAINER(frame), fbox);
597
709
 
598
 
    create_otroption_buttons(&(ui_layout.oo), fbox);
 
710
    create_otroptions_buttons(&(ui_layout.oo), fbox);
599
711
 
600
712
    load_otroptions(&(ui_layout.oo));
601
713
 
602
 
    g_signal_connect(G_OBJECT(ui_layout.oo.enablebox), "clicked",
603
 
                     G_CALLBACK(otroptions_save_cb), &(ui_layout.oo));
604
 
    g_signal_connect(G_OBJECT(ui_layout.oo.automaticbox), "clicked",
605
 
                     G_CALLBACK(otroptions_save_cb), &(ui_layout.oo));
606
 
    g_signal_connect(G_OBJECT(ui_layout.oo.onlyprivatebox), "clicked",
 
714
    g_signal_connect(G_OBJECT(ui_layout.oo.showotrbutton), "clicked",
607
715
                     G_CALLBACK(otroptions_save_cb), &(ui_layout.oo));
608
716
}
609
717
 
613
721
    GtkWidget *hbox;
614
722
    GtkWidget *table;
615
723
    GtkWidget *label;
616
 
    char *titles[5] = { "Screenname", "Status", "Verified",
617
 
        "Fingerprint", "Account" };
 
724
    char *titles[5];
 
725
 
 
726
    titles[0] = _("Screenname");
 
727
    titles[1] = _("Status");
 
728
    titles[2] = _("Verified");
 
729
    titles[3] = _("Fingerprint");
 
730
    titles[4] = _("Account");
618
731
 
619
732
    ui_layout.scrollwin = gtk_scrolled_window_new(0, 0);
620
733
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui_layout.scrollwin), 
650
763
    ui_layout.connect_button = gtk_button_new();
651
764
    gtk_signal_connect(GTK_OBJECT(ui_layout.connect_button), "clicked",
652
765
            GTK_SIGNAL_FUNC(connect_connection), NULL);
653
 
    label = gtk_label_new("Start private connection");
 
766
    label = gtk_label_new(_("Start private connection"));
654
767
    gtk_container_add(GTK_CONTAINER(ui_layout.connect_button), label);
655
768
    gtk_table_attach_defaults(GTK_TABLE(table), ui_layout.connect_button,
656
769
            0, 1, 0, 1);
658
771
    ui_layout.disconnect_button = gtk_button_new();
659
772
    gtk_signal_connect(GTK_OBJECT(ui_layout.disconnect_button), "clicked",
660
773
            GTK_SIGNAL_FUNC(disconnect_connection), NULL);
661
 
    label = gtk_label_new("End private connection");
 
774
    label = gtk_label_new(_("End private connection"));
662
775
    gtk_container_add(GTK_CONTAINER(ui_layout.disconnect_button), label);
663
776
    gtk_table_attach_defaults(GTK_TABLE(table), ui_layout.disconnect_button,
664
777
            0, 1, 1, 2);
666
779
    ui_layout.verify_button = gtk_button_new();
667
780
    gtk_signal_connect(GTK_OBJECT(ui_layout.verify_button), "clicked",
668
781
            GTK_SIGNAL_FUNC(verify_fingerprint), NULL);
669
 
    label = gtk_label_new("Verify fingerprint");
 
782
    label = gtk_label_new(_("Verify fingerprint"));
670
783
    gtk_container_add(GTK_CONTAINER(ui_layout.verify_button), label);
671
784
    gtk_table_attach_defaults(GTK_TABLE(table), ui_layout.verify_button,
672
785
            1, 2, 0, 1);
674
787
    ui_layout.forget_button = gtk_button_new();
675
788
    gtk_signal_connect(GTK_OBJECT(ui_layout.forget_button), "clicked",
676
789
            GTK_SIGNAL_FUNC(forget_fingerprint), NULL);
677
 
    label = gtk_label_new("Forget fingerprint");
 
790
    label = gtk_label_new(_("Forget fingerprint"));
678
791
    gtk_container_add(GTK_CONTAINER(ui_layout.forget_button), label);
679
792
    gtk_table_attach_defaults(GTK_TABLE(table), ui_layout.forget_button,
680
793
            1, 2, 1, 2);
713
826
 
714
827
    make_privkeys_ui(configbox);
715
828
 
 
829
    make_settings_ui(configbox);
 
830
 
716
831
    make_options_ui(configbox);
717
832
 
718
833
    /*
722
837
 
723
838
    make_fingerprints_ui(fingerprintbox);
724
839
 
 
840
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), configbox,
 
841
            gtk_label_new(_("Config")));
725
842
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), fingerprintbox,
726
 
            gtk_label_new("Known fingerprints"));
727
 
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), configbox,
728
 
            gtk_label_new("Config"));
 
843
            gtk_label_new(_("Known fingerprints")));
729
844
 
730
845
    gtk_widget_show_all(vbox);
731
846
 
736
851
    GtkWidget *dialog;
737
852
    PurpleBuddy *buddy;
738
853
    GtkWidget *defaultbox;
739
 
    struct otroptionsdata oo;
 
854
    struct otrsettingsdata os;
740
855
};
741
856
 
742
857
static void default_clicked_cb(GtkButton *button, struct cbdata *data)
744
859
    gboolean defaultset =
745
860
        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->defaultbox));
746
861
    if (defaultset) {
747
 
        gtk_widget_set_sensitive(data->oo.enablebox, FALSE);
748
 
        gtk_widget_set_sensitive(data->oo.automaticbox, FALSE);
749
 
        gtk_widget_set_sensitive(data->oo.onlyprivatebox, FALSE);
 
862
        gtk_widget_set_sensitive(data->os.enablebox, FALSE);
 
863
        gtk_widget_set_sensitive(data->os.automaticbox, FALSE);
 
864
        gtk_widget_set_sensitive(data->os.onlyprivatebox, FALSE);
 
865
        gtk_widget_set_sensitive(data->os.avoidloggingotrbox, FALSE);
750
866
    } else {
751
 
        otroptions_clicked_cb(button, &(data->oo));
 
867
        otrsettings_clicked_cb(button, &(data->os));
752
868
    }
753
869
}
754
870
 
755
871
static void load_buddyprefs(struct cbdata *data)
756
872
{
757
 
    gboolean usedefault, enabled, automatic, onlyprivate;
 
873
    gboolean usedefault, enabled, automatic, onlyprivate, avoidloggingotr;
758
874
 
759
875
    otrg_gtk_ui_buddy_prefs_load(data->buddy, &usedefault, &enabled,
760
 
            &automatic, &onlyprivate);
 
876
            &automatic, &onlyprivate, &avoidloggingotr);
761
877
 
762
878
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->defaultbox),
763
879
            usedefault);
764
880
 
765
881
    if (usedefault) {
766
882
        /* Load the global defaults */
767
 
        load_otroptions(&(data->oo));
 
883
        load_otrsettings(&(data->os));
768
884
    } else {
769
885
        /* We've got buddy-specific prefs */
770
886
        gtk_toggle_button_set_active(
771
 
                GTK_TOGGLE_BUTTON(data->oo.enablebox), enabled);
772
 
        gtk_toggle_button_set_active(
773
 
                GTK_TOGGLE_BUTTON(data->oo.automaticbox), automatic);
774
 
        gtk_toggle_button_set_active(
775
 
                GTK_TOGGLE_BUTTON(data->oo.onlyprivatebox), onlyprivate);
 
887
                GTK_TOGGLE_BUTTON(data->os.enablebox), enabled);
 
888
        gtk_toggle_button_set_active(
 
889
                GTK_TOGGLE_BUTTON(data->os.automaticbox), automatic);
 
890
        gtk_toggle_button_set_active(
 
891
                GTK_TOGGLE_BUTTON(data->os.onlyprivatebox), onlyprivate);
 
892
        gtk_toggle_button_set_active(
 
893
                GTK_TOGGLE_BUTTON(data->os.avoidloggingotrbox),
 
894
                avoidloggingotr);
776
895
    }
777
896
 
778
897
    default_clicked_cb(GTK_BUTTON(data->defaultbox), data);
786
905
static void config_buddy_clicked_cb(GtkButton *button, struct cbdata *data)
787
906
{
788
907
    gboolean enabled = gtk_toggle_button_get_active(
789
 
                             GTK_TOGGLE_BUTTON(data->oo.enablebox));
 
908
                             GTK_TOGGLE_BUTTON(data->os.enablebox));
790
909
    
791
910
    /* Apply the changes */
792
911
    otrg_gtk_ui_buddy_prefs_save(data->buddy,
794
913
             GTK_TOGGLE_BUTTON(data->defaultbox)),
795
914
         enabled,
796
915
         gtk_toggle_button_get_active(
797
 
             GTK_TOGGLE_BUTTON(data->oo.automaticbox)),
798
 
         gtk_toggle_button_get_active(
799
 
             GTK_TOGGLE_BUTTON(data->oo.onlyprivatebox)));
 
916
             GTK_TOGGLE_BUTTON(data->os.automaticbox)),
 
917
         gtk_toggle_button_get_active(
 
918
             GTK_TOGGLE_BUTTON(data->os.onlyprivatebox)),
 
919
         gtk_toggle_button_get_active(
 
920
             GTK_TOGGLE_BUTTON(data->os.avoidloggingotrbox)));
800
921
 
801
922
    otrg_dialog_resensitize_all();
802
923
}
812
933
    GtkWidget *dialog;
813
934
    GtkWidget *label;
814
935
    char *label_text;
 
936
    char *label_markup;
815
937
    struct cbdata *data = malloc(sizeof(struct cbdata));
816
938
 
817
939
    if (!data) return;
818
940
 
819
 
    dialog = gtk_dialog_new_with_buttons("OTR Settings",
 
941
    dialog = gtk_dialog_new_with_buttons(_("OTR Settings"),
820
942
                                         NULL, 0,
821
943
                                         GTK_STOCK_OK, GTK_RESPONSE_OK,
822
944
                                         NULL);
823
945
    gtk_window_set_accept_focus(GTK_WINDOW(dialog), FALSE);
824
 
    gtk_window_set_role(GTK_WINDOW(dialog), "otr_options");
 
946
    gtk_window_set_role(GTK_WINDOW(dialog), "otr_settings");
825
947
 
826
948
    gtk_container_set_border_width(GTK_CONTAINER(dialog), 6);
827
949
    gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
834
956
 
835
957
    /* Set the title */
836
958
 
837
 
    label_text = g_strdup_printf("<span weight=\"bold\" size=\"larger\">"
838
 
            "OTR Settings for %s</span>", purple_buddy_get_contact_alias(buddy));
 
959
    label_text = g_strdup_printf(_("OTR Settings for %s"),
 
960
            purple_buddy_get_contact_alias(buddy));
 
961
    label_markup = g_strdup_printf("<span weight=\"bold\" size=\"larger\">"
 
962
            "%s</span>", label_text);
839
963
 
840
964
    label = gtk_label_new(NULL);
841
965
 
842
 
    gtk_label_set_markup(GTK_LABEL(label), label_text);
 
966
    gtk_label_set_markup(GTK_LABEL(label), label_markup);
 
967
    g_free(label_markup);
843
968
    g_free(label_text);
844
969
    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
845
970
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
848
973
 
849
974
    /* Make the cascaded checkboxes */
850
975
 
851
 
    data->defaultbox = gtk_check_button_new_with_label("Use default "
852
 
            "OTR settings for this buddy");
 
976
    data->defaultbox = gtk_check_button_new_with_label(_("Use default "
 
977
            "OTR settings for this buddy"));
853
978
 
854
979
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), data->defaultbox,
855
980
            FALSE, FALSE, 0);
857
982
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_hseparator_new(),
858
983
            FALSE, FALSE, 5);
859
984
 
860
 
    create_otroption_buttons(&(data->oo), GTK_DIALOG(dialog)->vbox);
 
985
    create_otrsettings_buttons(&(data->os), GTK_DIALOG(dialog)->vbox);
861
986
 
862
987
    g_signal_connect(G_OBJECT(data->defaultbox), "clicked",
863
988
                     G_CALLBACK(default_clicked_cb), data);
864
989
    g_signal_connect(G_OBJECT(data->defaultbox), "clicked",
865
990
                     G_CALLBACK(config_buddy_clicked_cb), data);
866
 
    g_signal_connect(G_OBJECT(data->oo.enablebox), "clicked",
867
 
                     G_CALLBACK(config_buddy_clicked_cb), data);
868
 
    g_signal_connect(G_OBJECT(data->oo.automaticbox), "clicked",
869
 
                     G_CALLBACK(config_buddy_clicked_cb), data);
870
 
    g_signal_connect(G_OBJECT(data->oo.onlyprivatebox), "clicked",
 
991
    g_signal_connect(G_OBJECT(data->os.enablebox), "clicked",
 
992
                     G_CALLBACK(config_buddy_clicked_cb), data);
 
993
    g_signal_connect(G_OBJECT(data->os.automaticbox), "clicked",
 
994
                     G_CALLBACK(config_buddy_clicked_cb), data);
 
995
    g_signal_connect(G_OBJECT(data->os.onlyprivatebox), "clicked",
 
996
                     G_CALLBACK(config_buddy_clicked_cb), data);
 
997
    g_signal_connect(G_OBJECT(data->os.avoidloggingotrbox), "clicked",
871
998
                     G_CALLBACK(config_buddy_clicked_cb), data);
872
999
 
873
1000
    /* Set the inital states of the buttons */
881
1008
    gtk_widget_show_all(dialog);
882
1009
}
883
1010
 
884
 
/* Calculate the policy for a particular account / username */
885
 
static OtrlPolicy otrg_gtk_ui_find_policy(PurpleAccount *account,
 
1011
/* Load the preferences for a particular account / username */
 
1012
static void otrg_gtk_ui_get_prefs(OtrgUiPrefs *prefsp, PurpleAccount *account,
886
1013
        const char *name)
887
1014
{
888
1015
    PurpleBuddy *buddy;
889
 
    gboolean otrenabled, otrautomatic, otronlyprivate;
890
 
    gboolean buddyusedefault, buddyenabled, buddyautomatic, buddyonlyprivate;
891
 
    OtrlPolicy policy = OTRL_POLICY_DEFAULT;
 
1016
    gboolean otrenabled, otrautomatic, otronlyprivate, otravoidloggingotr;
 
1017
    gboolean buddyusedefault, buddyenabled, buddyautomatic, buddyonlyprivate,
 
1018
             buddyavoidloggingotr;
 
1019
 
 
1020
    prefsp->policy = OTRL_POLICY_DEFAULT;
 
1021
    prefsp->avoid_logging_otr = FALSE;
 
1022
    prefsp->show_otr_button = FALSE;
892
1023
    
893
1024
    /* Get the default policy */
894
 
    otrg_gtk_ui_global_prefs_load(&otrenabled, &otrautomatic, &otronlyprivate);
 
1025
    otrg_gtk_ui_global_prefs_load(&otrenabled, &otrautomatic, &otronlyprivate,
 
1026
            &otravoidloggingotr);
 
1027
    otrg_gtk_ui_global_options_load(&(prefsp->show_otr_button));
895
1028
 
896
1029
    if (otrenabled) {
897
1030
        if (otrautomatic) {
898
1031
            if (otronlyprivate) {
899
 
                policy = OTRL_POLICY_ALWAYS;
 
1032
                prefsp->policy = OTRL_POLICY_ALWAYS;
900
1033
            } else {
901
 
                policy = OTRL_POLICY_OPPORTUNISTIC;
 
1034
                prefsp->policy = OTRL_POLICY_OPPORTUNISTIC;
902
1035
            }
903
1036
        } else {
904
 
            policy = OTRL_POLICY_MANUAL;
 
1037
            prefsp->policy = OTRL_POLICY_MANUAL;
905
1038
        }
 
1039
        prefsp->avoid_logging_otr = otravoidloggingotr;
906
1040
    } else {
907
 
        policy = OTRL_POLICY_NEVER;
 
1041
        prefsp->policy = OTRL_POLICY_NEVER;
908
1042
    }
909
1043
 
910
1044
    buddy = purple_find_buddy(account, name);
911
 
    if (!buddy) return policy;
 
1045
    if (!buddy) return;
912
1046
 
913
1047
    /* Get the buddy-specific policy, if present */
914
1048
    otrg_gtk_ui_buddy_prefs_load(buddy, &buddyusedefault, &buddyenabled,
915
 
            &buddyautomatic, &buddyonlyprivate);
 
1049
            &buddyautomatic, &buddyonlyprivate, &buddyavoidloggingotr);
916
1050
 
917
 
    if (buddyusedefault) return policy;
 
1051
    if (buddyusedefault) return;
918
1052
 
919
1053
    if (buddyenabled) {
920
1054
        if (buddyautomatic) {
921
1055
            if (buddyonlyprivate) {
922
 
                policy = OTRL_POLICY_ALWAYS;
 
1056
                prefsp->policy = OTRL_POLICY_ALWAYS;
923
1057
            } else {
924
 
                policy = OTRL_POLICY_OPPORTUNISTIC;
 
1058
                prefsp->policy = OTRL_POLICY_OPPORTUNISTIC;
925
1059
            }
926
1060
        } else {
927
 
            policy = OTRL_POLICY_MANUAL;
 
1061
            prefsp->policy = OTRL_POLICY_MANUAL;
928
1062
        }
 
1063
        prefsp->avoid_logging_otr = buddyavoidloggingotr;
929
1064
    } else {
930
 
        policy = OTRL_POLICY_NEVER;
 
1065
        prefsp->policy = OTRL_POLICY_NEVER;
931
1066
    }
932
 
 
933
 
    return policy;
 
1067
}
 
1068
 
 
1069
/* Initialize the OTR UI subsystem */
 
1070
static void otrg_gtk_ui_init(void)
 
1071
{
 
1072
    /* Nothing to do */
 
1073
}
 
1074
 
 
1075
/* Deinitialize the OTR UI subsystem */
 
1076
static void otrg_gtk_ui_cleanup(void)
 
1077
{
 
1078
    /* Nothing to do */
934
1079
}
935
1080
 
936
1081
static const OtrgUiUiOps gtk_ui_ui_ops = {
 
1082
    otrg_gtk_ui_init,
 
1083
    otrg_gtk_ui_cleanup,
937
1084
    otrg_gtk_ui_update_fingerprint,
938
1085
    otrg_gtk_ui_update_keylist,
939
1086
    otrg_gtk_ui_config_buddy,
940
 
    otrg_gtk_ui_find_policy
 
1087
    otrg_gtk_ui_get_prefs
941
1088
};
942
1089
 
943
1090
/* Get the GTK UI ops */