d6c367b0c705b939367c605467a0455393279328
[claws.git] / src / plugins / pgpmime / prefs_gpg.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2004 Hiroyuki Yamamoto & the Sylpheed-Claws team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include <gtk/gtk.h>
21
22 #include "defs.h"
23 #include "intl.h"
24 #include "utils.h"
25 #include "prefs.h"
26 #include "prefs_gtk.h"
27 #include "prefs_gpg.h"
28
29 struct GPGConfig prefs_gpg;
30
31 static PrefParam param[] = {
32         /* Privacy */
33         {"auto_check_signatures", "TRUE",
34          &prefs_gpg.auto_check_signatures, P_BOOL,
35          NULL, NULL, NULL},
36         {"store_passphrase", "FALSE", &prefs_gpg.store_passphrase, P_BOOL,
37          NULL, NULL, NULL},
38         {"store_passphrase_timeout", "0",
39          &prefs_gpg.store_passphrase_timeout, P_INT,
40          NULL, NULL, NULL},
41 #ifndef __MINGW32__
42         {"passphrase_grab", "FALSE", &prefs_gpg.passphrase_grab, P_BOOL,
43          NULL, NULL, NULL},
44 #endif /* __MINGW32__ */
45         {"gpg_warning", "TRUE", &prefs_gpg.gpg_warning, P_BOOL,
46          NULL, NULL, NULL},
47
48         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
49 };
50
51 static void prefs_privacy_create(void)
52 {
53         GtkWidget *vbox1;
54         GtkWidget *vbox2;
55         GtkWidget *vbox3;
56         GtkWidget *hbox1;
57         GtkWidget *hbox_spc;
58         GtkWidget *label;
59         GtkWidget *checkbtn_auto_check_signatures;
60         GtkWidget *checkbtn_store_passphrase;
61         GtkObject *spinbtn_store_passphrase_adj;
62         GtkWidget *spinbtn_store_passphrase;
63         GtkTooltips *store_tooltip;
64         GtkWidget *checkbtn_passphrase_grab;
65         GtkWidget *checkbtn_gpg_warning;
66
67         vbox1 = gtk_vbox_new (FALSE, VSPACING);
68         gtk_widget_show (vbox1);
69         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
70
71         vbox2 = gtk_vbox_new (FALSE, 0);
72         gtk_widget_show (vbox2);
73         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
74
75         PACK_CHECK_BUTTON (vbox2, checkbtn_auto_check_signatures,
76                            _("Automatically check signatures"));
77
78         PACK_CHECK_BUTTON (vbox2, checkbtn_store_passphrase,
79                            _("Store passphrase in memory temporarily"));
80
81         vbox3 = gtk_vbox_new (FALSE, 0);
82         gtk_widget_show (vbox3);
83         gtk_box_pack_start (GTK_BOX (vbox2), vbox3, FALSE, FALSE, 0);
84
85         hbox1 = gtk_hbox_new (FALSE, 8);
86         gtk_widget_show (hbox1);
87         gtk_box_pack_start (GTK_BOX (vbox3), hbox1, FALSE, FALSE, 0);
88
89         hbox_spc = gtk_hbox_new (FALSE, 0);
90         gtk_widget_show (hbox_spc);
91         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
92         gtk_widget_set_usize (hbox_spc, 12, -1);
93
94         label = gtk_label_new (_("Expire after"));
95         gtk_widget_show (label);
96         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
97
98         store_tooltip = gtk_tooltips_new();
99
100         spinbtn_store_passphrase_adj = gtk_adjustment_new (0, 0, 1440, 1, 5, 5);
101         spinbtn_store_passphrase = gtk_spin_button_new
102                 (GTK_ADJUSTMENT (spinbtn_store_passphrase_adj), 1, 0);
103         gtk_widget_show (spinbtn_store_passphrase);
104         gtk_tooltips_set_tip(GTK_TOOLTIPS(store_tooltip), spinbtn_store_passphrase,
105                              _("Setting to '0' will store the passphrase"
106                                " for the whole session"),
107                              NULL);
108         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_store_passphrase, FALSE, FALSE, 0);
109         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_store_passphrase),
110                                      TRUE);
111         gtk_widget_set_usize (spinbtn_store_passphrase, 64, -1);
112
113         label = gtk_label_new (_("minute(s) "));
114         gtk_widget_show (label);
115         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
116
117         hbox1 = gtk_hbox_new (FALSE, 8);
118         gtk_widget_show (hbox1);
119         gtk_box_pack_start (GTK_BOX (vbox3), hbox1, FALSE, FALSE, 0);
120
121         hbox_spc = gtk_hbox_new (FALSE, 0);
122         gtk_widget_show (hbox_spc);
123         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
124         gtk_widget_set_usize (hbox_spc, 12, -1);
125
126         SET_TOGGLE_SENSITIVITY (checkbtn_store_passphrase, vbox3);
127
128 #ifndef __MINGW32__
129         PACK_CHECK_BUTTON (vbox2, checkbtn_passphrase_grab,
130                            _("Grab input while entering a passphrase"));
131 #endif
132
133         PACK_CHECK_BUTTON
134                 (vbox2, checkbtn_gpg_warning,
135                  _("Display warning on startup if GnuPG doesn't work"));
136
137         hbox1 = gtk_hbox_new (FALSE, 8);
138         gtk_widget_show (hbox1);
139         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
140
141 /*
142         privacy.checkbtn_auto_check_signatures
143                                              = checkbtn_auto_check_signatures;
144         privacy.checkbtn_store_passphrase    = checkbtn_store_passphrase;
145         privacy.spinbtn_store_passphrase     = spinbtn_store_passphrase;
146         privacy.spinbtn_store_passphrase_adj = spinbtn_store_passphrase_adj;
147         privacy.checkbtn_passphrase_grab     = checkbtn_passphrase_grab;
148         privacy.checkbtn_gpg_warning         = checkbtn_gpg_warning;
149 */
150 }
151
152 GPGConfig *prefs_gpg_get_config(void)
153 {
154         return &prefs_gpg;
155 }
156
157 void prefs_gpg_save_config(void)
158 {
159         PrefFile *pfile;
160         gchar *rcpath;
161
162         debug_print("Saving GPGME config\n");
163
164         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
165         pfile = prefs_write_open(rcpath);
166         g_free(rcpath);
167         if (!pfile || (prefs_set_block_label(pfile, "GPGME") < 0))
168                 return;
169
170         if (prefs_write_param(param, pfile->fp) < 0) {
171                 g_warning("failed to write GPGME configuration to file\n");
172                 prefs_file_close_revert(pfile);
173                 return;
174         }
175         fprintf(pfile->fp, "\n");
176
177         prefs_file_close(pfile);
178 }
179
180 void prefs_gpg_init()
181 {
182         prefs_set_default(param);
183         prefs_read_config(param, "GPGME", COMMON_RC);
184 }
185
186 void prefs_gpg_done()
187 {
188 }