No issues found
1 /*
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with the program; if not, see <http://www.gnu.org/licenses/>
15 *
16 *
17 * Authors:
18 * Chris Toshok <toshok@ximian.com>
19 *
20 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
21 *
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "ca-trust-dialog.h"
29 #include "certificate-viewer.h"
30
31 #include <glib/gi18n.h>
32
33 #include "e-util/e-util.h"
34 #include "e-util/e-util-private.h"
35
36 typedef struct {
37 GtkBuilder *builder;
38 GtkWidget *dialog;
39 GtkWidget *ssl_checkbutton;
40 GtkWidget *email_checkbutton;
41 GtkWidget *objsign_checkbutton;
42
43 ECert *cert;
44 } CATrustDialogData;
45
46 static void
47 free_data (gpointer data)
48 {
49 CATrustDialogData *ctd = data;
50
51 g_object_unref (ctd->cert);
52 g_object_unref (ctd->builder);
53 g_free (ctd);
54 }
55
56 static void
57 catd_response (GtkWidget *w,
58 guint id,
59 CATrustDialogData *data)
60 {
61 switch (id) {
62 case GTK_RESPONSE_ACCEPT: {
63 GtkWidget *dialog = certificate_viewer_show (data->cert);
64
65 g_signal_stop_emission_by_name (w, "response");
66 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (data->dialog));
67 gtk_dialog_run (GTK_DIALOG (dialog));
68 gtk_widget_destroy (dialog);
69 break; }
70 }
71 }
72
73 GtkWidget *
74 ca_trust_dialog_show (ECert *cert,
75 gboolean importing)
76 {
77 CATrustDialogData *ctd_data;
78 GtkDialog *dialog;
79 GtkWidget *action_area;
80 GtkWidget *content_area;
81 GtkWidget *w;
82 gchar *txt;
83
84 ctd_data = g_new0 (CATrustDialogData, 1);
85
86 ctd_data->builder = gtk_builder_new ();
87 e_load_ui_builder_definition (ctd_data->builder, "smime-ui.ui");
88
89 ctd_data->dialog = e_builder_get_widget (ctd_data->builder, "ca-trust-dialog");
90
91 gtk_widget_ensure_style (ctd_data->dialog);
92
93 dialog = GTK_DIALOG (ctd_data->dialog);
94 action_area = gtk_dialog_get_action_area (dialog);
95 content_area = gtk_dialog_get_content_area (dialog);
96
97 gtk_container_set_border_width (GTK_CONTAINER (action_area), 12);
98 gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
99
100 ctd_data->cert = g_object_ref (cert);
101
102 ctd_data->ssl_checkbutton = e_builder_get_widget (ctd_data->builder, "ssl_trust_checkbutton");
103 ctd_data->email_checkbutton = e_builder_get_widget (ctd_data->builder, "email_trust_checkbutton");
104 ctd_data->objsign_checkbutton = e_builder_get_widget (ctd_data->builder, "objsign_trust_checkbutton");
105
106 w = e_builder_get_widget (ctd_data->builder, "ca-trust-label");
107 txt = g_strdup_printf (_("Certificate '%s' is a CA certificate.\n\nEdit trust settings:"), e_cert_get_cn (cert));
108 gtk_label_set_text ((GtkLabel *) w, txt);
109 g_free (txt);
110
111 g_signal_connect (
112 ctd_data->dialog, "response",
113 G_CALLBACK (catd_response), ctd_data);
114
115 g_object_set_data_full (G_OBJECT (ctd_data->dialog), "CATrustDialogData", ctd_data, free_data);
116
117 return ctd_data->dialog;
118 }
119
120 void
121 ca_trust_dialog_set_trust (GtkWidget *widget,
122 gboolean ssl,
123 gboolean email,
124 gboolean objsign)
125 {
126 CATrustDialogData *ctd_data;
127
128 ctd_data = g_object_get_data (G_OBJECT (widget), "CATrustDialogData");
129 if (!ctd_data)
130 return;
131
132 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ctd_data->ssl_checkbutton), ssl);
133 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ctd_data->email_checkbutton), email);
134 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ctd_data->objsign_checkbutton), objsign);
135 }
136
137 void
138 ca_trust_dialog_get_trust (GtkWidget *widget,
139 gboolean *ssl,
140 gboolean *email,
141 gboolean *objsign)
142 {
143 CATrustDialogData *ctd_data;
144
145 ctd_data = g_object_get_data (G_OBJECT (widget), "CATrustDialogData");
146 if (!ctd_data)
147 return;
148
149 *ssl = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ctd_data->ssl_checkbutton));
150 *email = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ctd_data->email_checkbutton));
151 *objsign = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ctd_data->objsign_checkbutton));
152 }