aboutsummaryrefslogtreecommitdiffstats
path: root/smime/gui/ca-trust-dialog.c
blob: b0dc07001e213e2144d971724040aa546acd4651 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 *  Authors: Chris Toshok <toshok@ximian.com>
 *
 *  Copyright (C) 2004 Novell, Inc. (www.novell.com)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 *
 */


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "ca-trust-dialog.h"
#include "certificate-viewer.h"

#include <gtk/gtk.h>

#include <libgnome/gnome-i18n.h>
#include <glade/glade.h>

#define GLADE_FILE_NAME "smime-ui.glade"

typedef struct {
    GladeXML *gui;
    GtkWidget *dialog;
    GtkWidget *ssl_checkbutton;
    GtkWidget *email_checkbutton;
    GtkWidget *objsign_checkbutton;

    ECert *cert;
} CATrustDialogData;

static void
free_data (gpointer data)
{
    CATrustDialogData *ctd = data;

    g_object_unref (ctd->cert);
    g_object_unref (ctd->gui);
    g_free (ctd);
}

static void
catd_response(GtkWidget *w, guint id, CATrustDialogData *data)
{
    switch (id) {
    case GTK_RESPONSE_ACCEPT: {
        GtkWidget *dialog = certificate_viewer_show (data->cert);

        g_signal_stop_emission_by_name(w, "response");
        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (data->dialog));
        gtk_dialog_run (GTK_DIALOG (dialog));
        gtk_widget_destroy (dialog);
        break; }
    }
}

GtkWidget*
ca_trust_dialog_show (ECert *cert, gboolean importing)
{
    CATrustDialogData *ctd_data;
    GtkWidget *w;
    char *txt;

    ctd_data = g_new0 (CATrustDialogData, 1);
    ctd_data->gui = glade_xml_new (EVOLUTION_GLADEDIR "/" GLADE_FILE_NAME, NULL, NULL);

    ctd_data->dialog = glade_xml_get_widget (ctd_data->gui, "ca-trust-dialog");
    ctd_data->cert = g_object_ref (cert);

    ctd_data->ssl_checkbutton = glade_xml_get_widget (ctd_data->gui, "ssl_trust_checkbutton");
    ctd_data->email_checkbutton = glade_xml_get_widget (ctd_data->gui, "email_trust_checkbutton");
    ctd_data->objsign_checkbutton = glade_xml_get_widget (ctd_data->gui, "objsign_trust_checkbutton");

    w = glade_xml_get_widget(ctd_data->gui, "ca-trust-label");
    txt = g_strdup_printf(_("Certificate '%s' is a CA certificate.\n\nEdit trust settings:"), e_cert_get_cn(cert));
    gtk_label_set_text((GtkLabel *)w, txt);
    g_free(txt);

    g_signal_connect (ctd_data->dialog, "response", G_CALLBACK (catd_response), ctd_data);

    g_object_set_data_full (G_OBJECT (ctd_data->dialog), "CATrustDialogData", ctd_data, free_data);

    return ctd_data->dialog;
}

void
ca_trust_dialog_set_trust (GtkWidget *widget, gboolean ssl, gboolean email, gboolean objsign)
{
    CATrustDialogData *ctd_data;

    ctd_data = g_object_get_data (G_OBJECT (widget), "CATrustDialogData");
    if (!ctd_data)
        return;

    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ctd_data->ssl_checkbutton), ssl);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ctd_data->email_checkbutton), email);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ctd_data->objsign_checkbutton), objsign);
}

void
ca_trust_dialog_get_trust (GtkWidget *widget, gboolean *ssl, gboolean *email, gboolean *objsign)
{
    CATrustDialogData *ctd_data;

    ctd_data = g_object_get_data (G_OBJECT (widget), "CATrustDialogData");
    if (!ctd_data)
        return;

    *ssl = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ctd_data->ssl_checkbutton));
    *email = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ctd_data->email_checkbutton));
    *objsign = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ctd_data->objsign_checkbutton));
}