1 /* sigstatus.h - GTK+ based signature status display
2 * Copyright (C) 2001 Werner Koch (dd9jn)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <gtk/gtkwindow.h>
27 #include <gtk/gtkvbox.h>
28 #include <gtk/gtkhbox.h>
29 #include <gtk/gtklabel.h>
30 #include <gtk/gtkbutton.h>
31 #include <gdk/gdkkeysyms.h>
37 #include "sigstatus.h"
39 /* remove the window after 30 seconds to avoid cluttering the deskop
40 * with too many of them */
41 #define MY_TIMEOUT (30*1000)
43 struct gpgmegtk_sig_status_s
{
44 GtkWidget
*mainwindow
;
49 gint timeout_id_valid
;
53 static void do_destroy(GpgmegtkSigStatus hd
)
57 gtk_widget_destroy ( hd
->mainwindow
);
58 hd
->mainwindow
= NULL
;
60 if (hd
->timeout_id_valid
) {
61 gtk_timeout_remove(hd
->timeout_id
);
62 hd
->timeout_id_valid
= 0;
64 if (hd
->destroy_pending
)
69 static void okay_cb(GtkWidget
*widget
, gpointer data
)
71 GpgmegtkSigStatus hd
= data
;
77 static gint
delete_event(GtkWidget
*widget
, GdkEventAny
*event
, gpointer data
)
79 GpgmegtkSigStatus hd
= data
;
87 static void key_pressed(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
89 GpgmegtkSigStatus hd
= data
;
91 if (event
&& event
->keyval
== GDK_Escape
) {
97 GpgmegtkSigStatus
gpgmegtk_sig_status_create(void)
104 GtkWidget
*okay_area
;
105 GpgmegtkSigStatus hd
;
107 hd
= g_malloc0(sizeof *hd
);
110 window
= gtk_window_new(GTK_WINDOW_DIALOG
);
111 hd
->mainwindow
= window
;
112 gtk_widget_set_usize(window
, 400, -1);
113 gtk_container_set_border_width(GTK_CONTAINER(window
), 8);
114 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
115 gtk_window_set_policy(GTK_WINDOW(window
), FALSE
, FALSE
, FALSE
);
116 gtk_signal_connect(GTK_OBJECT(window
), "delete_event",
117 GTK_SIGNAL_FUNC(delete_event
), hd
);
118 gtk_signal_connect(GTK_OBJECT(window
), "key_press_event",
119 GTK_SIGNAL_FUNC(key_pressed
), hd
);
121 vbox
= gtk_vbox_new(FALSE
, 8);
122 gtk_container_add(GTK_CONTAINER(window
), vbox
);
123 gtk_widget_show(vbox
);
125 hbox
= gtk_hbox_new(FALSE
, 0);
126 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, TRUE
, TRUE
, 8);
127 gtk_widget_show(hbox
);
129 label
= gtk_label_new(_("Checking signature"));
131 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 8);
132 gtk_widget_show(label
);
134 gtkut_button_set_create(&okay_area
, &okay_btn
, _("OK"),
135 NULL
, NULL
, NULL
, NULL
);
136 gtk_box_pack_end(GTK_BOX(vbox
), okay_area
, FALSE
, FALSE
, 0);
137 gtk_widget_grab_default(okay_btn
);
138 gtk_signal_connect(GTK_OBJECT(okay_btn
), "clicked",
139 GTK_SIGNAL_FUNC(okay_cb
), hd
);
141 gtk_widget_show_all(window
);
143 while (gtk_events_pending())
144 gtk_main_iteration();
149 static gint
timeout_cb(gpointer data
)
151 GpgmegtkSigStatus hd
= data
;
154 hd
->timeout_id_valid
= 0;
160 void gpgmegtk_sig_status_destroy(GpgmegtkSigStatus hd
)
163 hd
->destroy_pending
= 1;
164 if (hd
->running
&& !hd
->timeout_id_valid
) {
165 hd
->timeout_id
= gtk_timeout_add(MY_TIMEOUT
,
167 hd
->timeout_id_valid
= 1;
173 /* Fixme: remove status and get it from the context */
174 void gpgmegtk_sig_status_update(GpgmegtkSigStatus hd
, GpgmeCtx ctx
)
181 if (!hd
|| !hd
->running
|| !ctx
)
184 for (idx
= 0; gpgme_get_sig_status(ctx
, idx
, &status
, &created
);
190 if ( !gpgme_get_sig_key (ctx
, idx
, &key
) ) {
191 userid
= gpgme_key_get_string_attr
192 (key
, GPGME_ATTR_USERID
, NULL
, 0);
196 tmp
= g_strdup_printf ( "%s%s%s from \"%s\"",
199 gpgmegtk_sig_status_to_string(status
),
203 gpgme_key_unref (key
);
206 gtk_label_set_text(GTK_LABEL(hd
->label
), text
);
209 while (gtk_events_pending())
210 gtk_main_iteration();
213 const char *gpgmegtk_sig_status_to_string(GpgmeSigStat status
)
215 const char *result
= "?";
218 case GPGME_SIG_STAT_NONE
:
219 result
= _("Oops: Signature not verified");
221 case GPGME_SIG_STAT_NOSIG
:
222 result
= _("No signature found");
224 case GPGME_SIG_STAT_GOOD
:
225 result
= _("Good signature");
227 case GPGME_SIG_STAT_BAD
:
228 result
= _("BAD signature");
230 case GPGME_SIG_STAT_NOKEY
:
231 result
= _("No public key to verify the signature");
233 case GPGME_SIG_STAT_ERROR
:
234 result
= _("Error verifying the signature");
243 #endif /* USE_GPGME */