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)
44 struct gpgmegtk_sig_status_s {
45 GtkWidget *mainwindow;
54 static void do_destroy(GpgmegtkSigStatus hd)
58 gtk_widget_destroy ( hd->mainwindow );
59 hd->mainwindow = NULL;
61 if (hd->timeout_id_valid) {
62 gtk_timeout_remove(hd->timeout_id);
63 hd->timeout_id_valid = 0;
65 if(hd->destroy_pending)
71 static void okay_cb(GtkWidget *widget, gpointer data)
73 GpgmegtkSigStatus hd = data;
80 static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
82 GpgmegtkSigStatus hd = data;
91 static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
93 GpgmegtkSigStatus hd = data;
95 if (event && event->keyval == GDK_Escape) {
102 GpgmegtkSigStatus gpgmegtk_sig_status_create()
109 GtkWidget *okay_area;
110 GpgmegtkSigStatus hd;
112 hd = g_malloc0(sizeof *hd);
115 window = gtk_window_new(GTK_WINDOW_DIALOG);
116 hd->mainwindow = window;
117 gtk_widget_set_usize(window, 400, -1);
118 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
119 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
120 gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE);
121 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
122 GTK_SIGNAL_FUNC(delete_event), hd);
123 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
124 GTK_SIGNAL_FUNC(key_pressed), hd);
126 vbox = gtk_vbox_new(FALSE, 8);
127 gtk_container_add(GTK_CONTAINER(window), vbox);
128 gtk_widget_show(vbox);
130 hbox = gtk_hbox_new(FALSE, 0);
131 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 8);
132 gtk_widget_show(hbox);
134 label = gtk_label_new(_("Checking signature"));
136 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
137 gtk_widget_show(label);
139 gtkut_button_set_create(&okay_area, &okay_btn, _("Okay"),
140 NULL, NULL, NULL, NULL);
141 gtk_box_pack_end(GTK_BOX(vbox), okay_area, FALSE, FALSE, 0);
142 gtk_widget_grab_default(okay_btn);
143 gtk_signal_connect(GTK_OBJECT(okay_btn), "clicked",
144 GTK_SIGNAL_FUNC(okay_cb), hd);
146 gtk_widget_show_all(window);
148 while (gtk_events_pending())
149 gtk_main_iteration();
154 static gint timeout_cb(gpointer data)
156 GpgmegtkSigStatus hd = data;
159 hd->timeout_id_valid = 0;
164 void gpgmegtk_sig_status_destroy(GpgmegtkSigStatus hd)
167 hd->destroy_pending = 1;
168 if (hd->running && !hd->timeout_id_valid) {
169 hd->timeout_id = gtk_timeout_add(MY_TIMEOUT,
171 hd->timeout_id_valid = 1;
178 /* Fixme: remove status and get it from the context */
179 void gpgmegtk_sig_status_update(GpgmegtkSigStatus hd, GpgmeCtx ctx)
186 if (!hd || !hd->running || !ctx)
189 for (idx=0; gpgme_get_sig_status(ctx, idx, &status, &created); idx++ ) {
194 if ( !gpgme_get_sig_key (ctx, idx, &key) ) {
195 userid = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID,
201 tmp = g_strdup_printf ( "%s%s%s from \"%s\"",
204 gpgmegtk_sig_status_to_string(status),
208 gpgme_key_unref (key);
211 gtk_label_set_text(GTK_LABEL(hd->label), text );
214 while (gtk_events_pending())
215 gtk_main_iteration();
219 const char *gpgmegtk_sig_status_to_string(GpgmeSigStat status)
221 const char *result = "?";
224 case GPGME_SIG_STAT_NONE:
225 result = _("Oops: Signature not verified");
227 case GPGME_SIG_STAT_NOSIG:
228 result = _("No signature found");
230 case GPGME_SIG_STAT_GOOD:
231 result = _("Good signature");
233 case GPGME_SIG_STAT_BAD:
234 result = _("BAD signature");
236 case GPGME_SIG_STAT_NOKEY:
237 result = _("No public key to verify the signature");
239 case GPGME_SIG_STAT_ERROR:
240 result = _("Error verifying the signature");
247 #endif /* USE_GPGME */