[evolution-data-server] Bisect Gtk+ calls into separate files



commit 432f30d7fad73d9ce3bc5d3f7a14e8a4969f0590
Author: Milan Crha <mcrha redhat com>
Date:   Thu Dec 13 11:46:28 2012 +0100

    Bisect Gtk+ calls into separate files
    
    This way it'll be easier to provide other
    than Gtk+ GUI implementations of the prompts.

 modules/trust-prompt/Makefile.am                   |   20 ++-
 modules/trust-prompt/module-trust-prompt.c         |  183 +---------------
 modules/trust-prompt/trust-prompt-gtk.c            |  225 ++++++++++++++++++++
 modules/trust-prompt/trust-prompt.h                |   44 ++++
 po/POTFILES.in                                     |    3 +-
 services/evolution-user-prompter/Makefile.am       |   16 ++-
 .../evolution-user-prompter.c                      |   93 +--------
 services/evolution-user-prompter/prompt-user-gtk.c |  118 ++++++++++
 services/evolution-user-prompter/prompt-user.h     |   43 ++++
 9 files changed, 478 insertions(+), 267 deletions(-)
---
diff --git a/modules/trust-prompt/Makefile.am b/modules/trust-prompt/Makefile.am
index 859cdd9..2e6d62a 100644
--- a/modules/trust-prompt/Makefile.am
+++ b/modules/trust-prompt/Makefile.am
@@ -1,5 +1,17 @@
 NULL =
 
+#if USE_GTK
+   TRUST_PROMPT_SOURCES = trust-prompt-gtk.c \
+			  certificate-viewer.c \
+			  certificate-viewer.h
+   TRUST_PROMPT_CFLAGS = $(GNOME_PLATFORM_CFLAGS)
+   TRUST_PROMPT_LIBS = $(GNOME_PLATFORM_LIBS)
+#else
+#   TRUST_PROMPT_SOURCES = trust-prompt-.c
+#   TRUST_PROMPT_CFLAGS = $()
+#   TRUST_PROMPT_LIBS = $()
+#endif
+
 module_LTLIBRARIES = module-trust-prompt.la
 
 module_trust_prompt_la_CPPFLAGS = \
@@ -9,15 +21,15 @@ module_trust_prompt_la_CPPFLAGS = \
 	$(E_BACKEND_CFLAGS) \
 	$(E_DATA_SERVER_CFLAGS) \
 	$(CAMEL_CFLAGS) \
-	$(GNOME_PLATFORM_CFLAGS) \
+	$(TRUST_PROMPT_CFLAGS) \
 	$(NULL)
 
 module_trust_prompt_la_SOURCES = \
 	e-asn1-object.c \
 	e-asn1-object.h \
-	certificate-viewer.c \
-	certificate-viewer.h \
 	module-trust-prompt.c \
+	trust-prompt.h \
+	$(TRUST_PROMPT_SOURCES) \
 	$(NULL)
 
 module_trust_prompt_la_LIBADD = \
@@ -27,7 +39,7 @@ module_trust_prompt_la_LIBADD = \
 	$(E_BACKEND_LIBS) \
 	$(E_DATA_SERVER_LIBS) \
 	$(CAMEL_LIBS) \
-	$(GNOME_PLATFORM_LIBS) \
+	$(TRUST_PROMPT_LIBS) \
 	$(NULL)
 
 module_trust_prompt_la_LDFLAGS = \
diff --git a/modules/trust-prompt/module-trust-prompt.c b/modules/trust-prompt/module-trust-prompt.c
index 567bd41..d8db7d8 100644
--- a/modules/trust-prompt/module-trust-prompt.c
+++ b/modules/trust-prompt/module-trust-prompt.c
@@ -20,14 +20,12 @@
 #include <config.h>
 #endif /* HAVE_CONFIG_H */
 
-#include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
 
 #include <cert.h>
 
 #include <libebackend/libebackend.h>
-
-#include "certificate-viewer.h"
+#include "trust-prompt.h"
 
 /* Standard GObject macros */
 #define E_TYPE_TRUST_PROMPT (e_trust_prompt_get_type ())
@@ -58,6 +56,7 @@ G_DEFINE_DYNAMIC_TYPE (ETrustPrompt, e_trust_prompt, E_TYPE_USER_PROMPTER_SERVER
 static gboolean trust_prompt_show_trust_prompt (EUserPrompterServerExtension *extension,
 						gint prompt_id,
 						const ENamedParameters *parameters);
+
 #define TRUST_PROMPT_DIALOG "ETrustPrompt::trust-prompt"
 
 static void
@@ -227,56 +226,6 @@ cert_errors_to_reason (GTlsCertificateFlags flags)
 }
 
 static void
-trust_prompt_add_info_line (GtkGrid *grid,
-			    const gchar *label_text,
-			    const gchar *value_text,
-			    gboolean ellipsize,
-			    gint *at_row)
-{
-	GtkWidget *widget;
-	PangoAttribute *attr;
-	PangoAttrList *bold;
-
-	g_return_if_fail (grid != NULL);
-	g_return_if_fail (label_text != NULL);
-	g_return_if_fail (at_row != NULL);
-
-	if (!value_text || !*value_text)
-		return;
-
-	bold = pango_attr_list_new ();
-	attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
-	pango_attr_list_insert (bold, attr);
-
-	widget = gtk_label_new (label_text);
-	gtk_misc_set_padding (GTK_MISC (widget), 12, 0);
-	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
-
-	gtk_grid_attach (grid, widget, 1, *at_row, 1, 1);
-
-	widget = gtk_label_new (value_text);
-	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
-	g_object_set (G_OBJECT (widget),
-		"hexpand", TRUE,
-		"halign", GTK_ALIGN_FILL,
-		"justify", GTK_JUSTIFY_LEFT,
-		"attributes", bold,
-		"selectable", TRUE,
-		"ellipsize", ellipsize ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE,
-		NULL);
-
-	gtk_grid_attach (grid, widget, 2, *at_row, 1, 1);
-
-	*at_row = (*at_row) + 1;
-
-	pango_attr_list_unref (bold);
-}
-
-#define TRUST_PROMP_ID_KEY	"ETrustPrompt::prompt-id-key"
-#define TRUST_PROMP_CERT_KEY	"ETrustPrompt::cert-key"
-#define TRUST_PROMP_ISSUERS_KEY	"ETrustPrompt::issuers-key"
-
-static void
 trust_prompt_free_certificate (gpointer cert)
 {
 	if (!cert)
@@ -285,50 +234,6 @@ trust_prompt_free_certificate (gpointer cert)
 	CERT_DestroyCertificate (cert);
 }
 
-static void
-trust_prompt_free_issuers (gpointer issuers)
-{
-	if (!issuers)
-		return;
-
-	g_slist_free_full (issuers, trust_prompt_free_certificate);
-}
-
-static void
-trust_prompt_response_cb (GtkWidget *dialog,
-			  gint response,
-			  EUserPrompterServerExtension *extension)
-{
-	gint prompt_id;
-
-	if (response == GTK_RESPONSE_HELP) {
-		GtkWidget *viewer;
-
-		viewer = certificate_viewer_new (GTK_WINDOW (dialog),
-			g_object_get_data (G_OBJECT (dialog), TRUST_PROMP_CERT_KEY),
-			g_object_get_data (G_OBJECT (dialog), TRUST_PROMP_ISSUERS_KEY));
-
-		gtk_dialog_run (GTK_DIALOG (viewer));
-		gtk_widget_destroy (viewer);
-
-		return;
-	}
-
-	prompt_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), TRUST_PROMP_ID_KEY));
-	gtk_widget_destroy (dialog);
-
-	if (response == GTK_RESPONSE_REJECT)
-		response = 0;
-	else if (response == GTK_RESPONSE_ACCEPT)
-		response = 1;
-	else if (response == GTK_RESPONSE_YES)
-		response = 2;
-	else
-		response = -1;
-
-	e_user_prompter_server_extension_response (extension, prompt_id, response, NULL);
-}
-
 static GSList *
 trust_prompt_get_issuers (CERTCertDBHandle *certdb,
 			  const ENamedParameters *parameters)
@@ -383,16 +288,14 @@ trust_prompt_show_trust_prompt (EUserPrompterServerExtension *extension,
 				const ENamedParameters *parameters)
 {
 	const gchar *host, *base64_cert, *cert_errs_str;
-	gchar *tmp, *reason, *issuer, *subject;
-	gint row = 0;
+	gchar *fingerprint, *reason;
 	gint64 cert_errs;
-	GtkWidget *dialog, *widget;
-	GtkGrid *grid;
 	CERTCertDBHandle *certdb;
 	CERTCertificate *cert;
 	GSList *issuers;
 	SECItem derCert;
 	gsize derCert_len = 0;
+	gboolean success;
 
 	g_return_val_if_fail (extension != NULL, FALSE);
 	g_return_val_if_fail (parameters != NULL, FALSE);
@@ -417,78 +320,16 @@ trust_prompt_show_trust_prompt (EUserPrompterServerExtension *extension,
 	issuers = trust_prompt_get_issuers (certdb, parameters);
 
 	cert_errs = g_ascii_strtoll (cert_errs_str, NULL, 16);
+	reason = cert_errors_to_reason (cert_errs);
+	fingerprint = cert_fingerprint (cert);
 
-	dialog = gtk_dialog_new_with_buttons (_("Certificate trust..."), NULL, 0,
-		_("_View Certificate"), GTK_RESPONSE_HELP,
-		_("_Reject"), GTK_RESPONSE_REJECT,
-		_("Accept _Temporarily"), GTK_RESPONSE_YES,
-		_("_Accept Permanently"), GTK_RESPONSE_ACCEPT,
-		NULL);
-
-	gtk_window_set_icon_name (GTK_WINDOW (dialog), "evolution");
-	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
-
-	grid = g_object_new (GTK_TYPE_GRID,
-		"orientation", GTK_ORIENTATION_HORIZONTAL,
-		"row-homogeneous", FALSE,
-		"row-spacing", 2,
-		"column-homogeneous", FALSE,
-		"column-spacing", 6,
-		"hexpand", TRUE,
-		"halign", GTK_ALIGN_FILL,
-		"vexpand", TRUE,
-		"valign", GTK_ALIGN_FILL,
-		"border-width", 12,
-		NULL);
-
-	widget = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-	gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (grid));
-
-	widget = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
-	g_object_set (G_OBJECT (widget),
-		"vexpand", FALSE,
-		"valign", GTK_ALIGN_START,
-		"xpad", 6,
-		NULL);
-	gtk_grid_attach (grid, widget, 0, row, 1, 3);
-
-	reason = g_strconcat ("<b>", host, "</b>", NULL);
-	tmp = g_strdup_printf (_("SSL Certificate for '%s' is not trusted. Do you wish to accept it?\n\n"
-				    "Detailed information about the certificate:"), reason);
-	g_free (reason);
-	widget = gtk_label_new (NULL);
-	gtk_label_set_markup (GTK_LABEL (widget), tmp);
-	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
-	g_free (tmp);
-
-	gtk_grid_attach (grid, widget, 1, row, 2, 1);
-	row++;
-
-	issuer = CERT_NameToAscii (&cert->issuer);
-	subject = CERT_NameToAscii (&cert->subject);
-	reason = cert_errors_to_reason ((GTlsCertificateFlags) cert_errs);
-	tmp = cert_fingerprint (cert);
-
-	trust_prompt_add_info_line (grid, _("Issuer:"), issuer, TRUE, &row);
-	trust_prompt_add_info_line (grid, _("Subject:"), subject, TRUE, &row);
-	trust_prompt_add_info_line (grid, _("Fingerprint:"), tmp, TRUE, &row);
-	trust_prompt_add_info_line (grid, _("Reason:"), reason, FALSE, &row);
-
-	PORT_Free (issuer);
-	PORT_Free (subject);
-	g_free (reason);
-	g_free (tmp);
-
-	g_object_set_data (G_OBJECT (dialog), TRUST_PROMP_ID_KEY, GINT_TO_POINTER (prompt_id));
-	g_object_set_data_full (G_OBJECT (dialog), TRUST_PROMP_CERT_KEY, cert, trust_prompt_free_certificate);
-	g_object_set_data_full (G_OBJECT (dialog), TRUST_PROMP_ISSUERS_KEY, issuers, trust_prompt_free_issuers);
-
-	g_signal_connect (dialog, "response", G_CALLBACK (trust_prompt_response_cb), extension);
-
-	gtk_widget_show_all (GTK_WIDGET (grid));
-	gtk_widget_show (dialog);
+	success = trust_prompt_show (extension, prompt_id, host, cert, fingerprint, reason, issuers);
 
+	trust_prompt_free_certificate (cert);
+	g_slist_free_full (issuers, trust_prompt_free_certificate);
 	g_free (derCert.data);
+	g_free (fingerprint);
+	g_free (reason);
 
-	return TRUE;
+	return success;
 }
diff --git a/modules/trust-prompt/trust-prompt-gtk.c b/modules/trust-prompt/trust-prompt-gtk.c
new file mode 100644
index 0000000..2c94f11
--- /dev/null
+++ b/modules/trust-prompt/trust-prompt-gtk.c
@@ -0,0 +1,225 @@
+/*
+ * trust-prompt-gtk.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <gtk/gtk.h>
+#include <glib/gi18n-lib.h>
+
+#include <cert.h>
+#include <libebackend/libebackend.h>
+
+#include "trust-prompt.h"
+#include "certificate-viewer.h"
+
+static void
+trust_prompt_add_info_line (GtkGrid *grid,
+			    const gchar *label_text,
+			    const gchar *value_text,
+			    gboolean ellipsize,
+			    gint *at_row)
+{
+	GtkWidget *widget;
+	PangoAttribute *attr;
+	PangoAttrList *bold;
+
+	g_return_if_fail (grid != NULL);
+	g_return_if_fail (label_text != NULL);
+	g_return_if_fail (at_row != NULL);
+
+	if (!value_text || !*value_text)
+		return;
+
+	bold = pango_attr_list_new ();
+	attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
+	pango_attr_list_insert (bold, attr);
+
+	widget = gtk_label_new (label_text);
+	gtk_misc_set_padding (GTK_MISC (widget), 12, 0);
+	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
+
+	gtk_grid_attach (grid, widget, 1, *at_row, 1, 1);
+
+	widget = gtk_label_new (value_text);
+	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
+	g_object_set (G_OBJECT (widget),
+		"hexpand", TRUE,
+		"halign", GTK_ALIGN_FILL,
+		"justify", GTK_JUSTIFY_LEFT,
+		"attributes", bold,
+		"selectable", TRUE,
+		"ellipsize", ellipsize ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE,
+		NULL);
+
+	gtk_grid_attach (grid, widget, 2, *at_row, 1, 1);
+
+	*at_row = (*at_row) + 1;
+
+	pango_attr_list_unref (bold);
+}
+
+static void
+trust_prompt_free_certificate (gpointer cert)
+{
+	if (!cert)
+		return;
+
+	CERT_DestroyCertificate (cert);
+}
+
+static void
+trust_prompt_free_issuers (gpointer issuers)
+{
+	if (!issuers)
+		return;
+
+	g_slist_free_full (issuers, trust_prompt_free_certificate);
+}
+
+#define TRUST_PROMP_ID_KEY	"ETrustPrompt::prompt-id-key"
+#define TRUST_PROMP_CERT_KEY	"ETrustPrompt::cert-key"
+#define TRUST_PROMP_ISSUERS_KEY	"ETrustPrompt::issuers-key"
+
+static void
+trust_prompt_response_cb (GtkWidget *dialog,
+			  gint response,
+			  EUserPrompterServerExtension *extension)
+{
+	gint prompt_id;
+
+	if (response == GTK_RESPONSE_HELP) {
+		GtkWidget *viewer;
+
+		viewer = certificate_viewer_new (GTK_WINDOW (dialog),
+			g_object_get_data (G_OBJECT (dialog), TRUST_PROMP_CERT_KEY),
+			g_object_get_data (G_OBJECT (dialog), TRUST_PROMP_ISSUERS_KEY));
+
+		gtk_dialog_run (GTK_DIALOG (viewer));
+		gtk_widget_destroy (viewer);
+
+		return;
+	}
+
+	prompt_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), TRUST_PROMP_ID_KEY));
+	gtk_widget_destroy (dialog);
+
+	if (response == GTK_RESPONSE_REJECT)
+		response = TRUST_PROMPT_RESPONSE_REJECT;
+	else if (response == GTK_RESPONSE_ACCEPT)
+		response = TRUST_PROMPT_RESPONSE_ACCEPT_PERMANENTLY;
+	else if (response == GTK_RESPONSE_YES)
+		response = TRUST_PROMPT_RESPONSE_ACCEPT_TEMPORARILY;
+	else
+		response = TRUST_PROMPT_RESPONSE_UNKNOWN;
+
+	e_user_prompter_server_extension_response (extension, prompt_id, response, NULL);
+}
+
+gboolean
+trust_prompt_show (EUserPrompterServerExtension *extension,
+		   gint prompt_id,
+		   const gchar *host,
+		   const CERTCertificate *pcert,
+		   const gchar *cert_fingerprint,
+		   const gchar *reason,
+		   const GSList *pissuers)
+{
+	GtkWidget *dialog, *widget;
+	GtkGrid *grid;
+	gchar *tmp, *info, *issuer, *subject;
+	GSList *issuers, *iter;
+	CERTCertificate *cert;
+	gint row = 0;
+
+	cert = CERT_DupCertificate ((CERTCertificate *) pcert);
+	issuers = g_slist_copy ((GSList *) pissuers);
+	for (iter = issuers; iter; iter = g_slist_next (iter)) {
+		if (iter->data)
+			iter->data = CERT_DupCertificate (iter->data);
+	}
+
+	dialog = gtk_dialog_new_with_buttons (_("Certificate trust..."), NULL, 0,
+		_("_View Certificate"), GTK_RESPONSE_HELP,
+		_("_Reject"), GTK_RESPONSE_REJECT,
+		_("Accept _Temporarily"), GTK_RESPONSE_YES,
+		_("_Accept Permanently"), GTK_RESPONSE_ACCEPT,
+		NULL);
+
+	gtk_window_set_icon_name (GTK_WINDOW (dialog), "evolution");
+	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+
+	grid = g_object_new (GTK_TYPE_GRID,
+		"orientation", GTK_ORIENTATION_HORIZONTAL,
+		"row-homogeneous", FALSE,
+		"row-spacing", 2,
+		"column-homogeneous", FALSE,
+		"column-spacing", 6,
+		"hexpand", TRUE,
+		"halign", GTK_ALIGN_FILL,
+		"vexpand", TRUE,
+		"valign", GTK_ALIGN_FILL,
+		"border-width", 12,
+		NULL);
+
+	widget = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+	gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (grid));
+
+	widget = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
+	g_object_set (G_OBJECT (widget),
+		"vexpand", FALSE,
+		"valign", GTK_ALIGN_START,
+		"xpad", 6,
+		NULL);
+	gtk_grid_attach (grid, widget, 0, row, 1, 3);
+
+	info = g_strconcat ("<b>", host, "</b>", NULL);
+	tmp = g_strdup_printf (_("SSL Certificate for '%s' is not trusted. Do you wish to accept it?\n\n"
+				    "Detailed information about the certificate:"), info);
+	g_free (info);
+	widget = gtk_label_new (NULL);
+	gtk_label_set_markup (GTK_LABEL (widget), tmp);
+	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
+	g_free (tmp);
+
+	gtk_grid_attach (grid, widget, 1, row, 2, 1);
+	row++;
+
+	issuer = CERT_NameToAscii (&cert->issuer);
+	subject = CERT_NameToAscii (&cert->subject);
+
+	trust_prompt_add_info_line (grid, _("Issuer:"), issuer, TRUE, &row);
+	trust_prompt_add_info_line (grid, _("Subject:"), subject, TRUE, &row);
+	trust_prompt_add_info_line (grid, _("Fingerprint:"), cert_fingerprint, TRUE, &row);
+	trust_prompt_add_info_line (grid, _("Reason:"), reason, FALSE, &row);
+
+	PORT_Free (issuer);
+	PORT_Free (subject);
+
+	g_object_set_data (G_OBJECT (dialog), TRUST_PROMP_ID_KEY, GINT_TO_POINTER (prompt_id));
+	g_object_set_data_full (G_OBJECT (dialog), TRUST_PROMP_CERT_KEY, cert, trust_prompt_free_certificate);
+	g_object_set_data_full (G_OBJECT (dialog), TRUST_PROMP_ISSUERS_KEY, issuers, trust_prompt_free_issuers);
+
+	g_signal_connect (dialog, "response", G_CALLBACK (trust_prompt_response_cb), extension);
+
+	gtk_widget_show_all (GTK_WIDGET (grid));
+	gtk_widget_show (dialog);
+
+	return TRUE;
+}
diff --git a/modules/trust-prompt/trust-prompt.h b/modules/trust-prompt/trust-prompt.h
new file mode 100644
index 0000000..9966ad6
--- /dev/null
+++ b/modules/trust-prompt/trust-prompt.h
@@ -0,0 +1,44 @@
+/*
+ * trust-prompt.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef TRUST_PROMPT_H
+#define TRUST_PROMPT_H
+
+#include <cert.h>
+#include <libebackend/libebackend.h>
+
+/* This shows a trust-prompt. The function may not block and returns whether
+   showed a dialog or not. It calls e_user_prompter_server_extension_response()
+   when a user responded to the dialog with one of the TRUST_PROMPT_RESPONSE values.
+*/
+
+#define TRUST_PROMPT_RESPONSE_UNKNOWN			-1
+#define TRUST_PROMPT_RESPONSE_REJECT			 0
+#define TRUST_PROMPT_RESPONSE_ACCEPT_PERMANENTLY	 1
+#define TRUST_PROMPT_RESPONSE_ACCEPT_TEMPORARILY	 2
+
+gboolean
+trust_prompt_show (EUserPrompterServerExtension *extension,
+		   gint prompt_id,
+		   const gchar *host,
+		   const CERTCertificate *pcert,
+		   const gchar *cert_fingerprint,
+		   const gchar *reason,
+		   const GSList *pissuers);
+
+#endif /* TRUST_PROMPT_H */
\ No newline at end of file
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a785c87..928e3a3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -219,7 +219,8 @@ modules/google-backend/module-google-backend.c
 modules/trust-prompt/certificate-viewer.c
 modules/trust-prompt/e-asn1-object.c
 modules/trust-prompt/module-trust-prompt.c
+modules/trust-prompt/trust-prompt-gtk.c
 modules/yahoo-backend/module-yahoo-backend.c
 services/evolution-addressbook-factory/evolution-addressbook-factory.c
 services/evolution-calendar-factory/evolution-calendar-factory.c
-services/evolution-user-prompter/evolution-user-prompter.c
+services/evolution-user-prompter/prompt-user-gtk.c
diff --git a/services/evolution-user-prompter/Makefile.am b/services/evolution-user-prompter/Makefile.am
index 9064171..8f865cf 100644
--- a/services/evolution-user-prompter/Makefile.am
+++ b/services/evolution-user-prompter/Makefile.am
@@ -8,6 +8,16 @@ service_DATA = $(service_in_files:.service.in=.service)
 CLEANFILES = $(service_DATA)
 EXTRA_DIST = $(service_in_files)
 
+#if USE_GTK
+   PROMPT_USER_SOURCES = prompt-user-gtk.c
+   PROMPT_USER_CFLAGS = $(GNOME_PLATFORM_CFLAGS)
+   PROMPT_USER_LIBS = $(GNOME_PLATFORM_LIBS)
+#else
+#   PROMPT_USER_SOURCES = prompt-user-.c
+#   PROMPT_USER_CFLAGS = $()
+#   PROMPT_USER_LIBS = $()
+#endif
+
 libexec_PROGRAMS = evolution-user-prompter
 
 evolution_user_prompter_CPPFLAGS = \
@@ -18,19 +28,21 @@ evolution_user_prompter_CPPFLAGS = \
 	-I$(top_builddir)/private \
 	-DG_LOG_DOMAIN=\"evolution-user-prompter\" \
 	-DLOCALEDIR=\"$(localedir)\" \
-	$(GNOME_PLATFORM_CFLAGS) \
 	$(E_DATA_SERVER_CFLAGS) \
+	$(PROMPT_USER_CFLAGS) \
 	$(NULL)
 
 evolution_user_prompter_SOURCES = \
 	evolution-user-prompter.c \
+	prompt-user.h \
+	$(PROMPT_USER_SOURCES) \
 	$(NULL)
 
 evolution_user_prompter_LDADD = \
 	$(top_builddir)/libebackend/libebackend-1.2.la \
 	$(top_builddir)/libedataserver/libedataserver-1.2.la \
-	$(GNOME_PLATFORM_LIBS) \
 	$(E_DATA_SERVER_LIBS) \
+	$(PROMPT_USER_LIBS) \
 	$(NULL)
 
 -include $(top_srcdir)/git.mk
diff --git a/services/evolution-user-prompter/evolution-user-prompter.c b/services/evolution-user-prompter/evolution-user-prompter.c
index 375ced0..8a35c3d 100644
--- a/services/evolution-user-prompter/evolution-user-prompter.c
+++ b/services/evolution-user-prompter/evolution-user-prompter.c
@@ -21,94 +21,9 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <locale.h>
-#include <stdlib.h>
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
+#include <libintl.h>
 
-#include <libebackend/libebackend.h>
-
-#define E_USER_PROMPTER_ID_KEY "e-user-prompter-id"
-
-static void
-message_response_cb (GtkWidget *dialog,
-		     gint button,
-		     EUserPrompterServer *server)
-{
-	gint prompt_id;
-
-	prompt_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), E_USER_PROMPTER_ID_KEY));
-
-	gtk_widget_destroy (dialog);
-
-	g_return_if_fail (E_IS_USER_PROMPTER_SERVER (server));
-
-	e_user_prompter_server_response	(server, prompt_id, button, NULL);
-}
-
-static void
-prompt_cb (EUserPrompterServer *server,
-	   gint id,
-	   const gchar *type,
-	   const gchar *title,
-	   const gchar *primary_text,
-	   const gchar *secondary_text,
-	   gboolean use_markup,
-	   const GSList *button_captions)
-{
-	GtkMessageType ntype = GTK_MESSAGE_OTHER;
-	GtkWidget *message;
-	gint index;
-	const GSList *iter;
-
-	g_return_if_fail (server != NULL);
-
-	if (type) {
-		if (g_ascii_strcasecmp (type, "info") == 0)
-			ntype = GTK_MESSAGE_INFO;
-		else if (g_ascii_strcasecmp (type, "warning") == 0)
-			ntype = GTK_MESSAGE_WARNING;
-		else if (g_ascii_strcasecmp (type, "question") == 0)
-			ntype = GTK_MESSAGE_QUESTION;
-		else if (g_ascii_strcasecmp (type, "error") == 0)
-			ntype = GTK_MESSAGE_ERROR;
-	}
-
-	if (use_markup)
-		message = gtk_message_dialog_new_with_markup (NULL, 0, ntype, GTK_BUTTONS_NONE,
-			"%s", primary_text ? primary_text : "");
-	else
-		message = gtk_message_dialog_new (NULL, 0, ntype, GTK_BUTTONS_NONE,
-			"%s", primary_text ? primary_text : "");
-
-	/* To show dialog on a taskbar */
-	gtk_window_set_skip_taskbar_hint (GTK_WINDOW (message), FALSE);
-	gtk_window_set_title (GTK_WINDOW (message), title ? title : "");
-	gtk_window_set_icon_name (GTK_WINDOW (message), "evolution");
-
-	if (secondary_text && *secondary_text) {
-		if (use_markup)
-			gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (message),
-				"%s", secondary_text);
-		else
-			gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
-				"%s", secondary_text);
-	}
-
-	g_object_set (message, "resizable", TRUE, NULL);
-
-	for (index = 0, iter = button_captions; iter; index++, iter = iter->next) {
-		gtk_dialog_add_button (GTK_DIALOG (message), iter->data, index);
-	}
-
-	if (index == 0)
-		gtk_dialog_add_button (GTK_DIALOG (message), _("_Dismiss"), index);
-
-	g_object_set_data (G_OBJECT (message), E_USER_PROMPTER_ID_KEY, GINT_TO_POINTER (id));
-
-	g_signal_connect (message, "response", G_CALLBACK (message_response_cb), server);
-
-	gtk_widget_show (message);
-}
+#include "prompt-user.h"
 
 gint
 main (gint argc,
@@ -120,12 +35,12 @@ main (gint argc,
 	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
-	gtk_init_check (&argc, &argv);
+	prompt_user_init (&argc, &argv);
 
 	e_gdbus_templates_init_main_thread ();
 
 	server = e_user_prompter_server_new ();
-	g_signal_connect (server, "prompt", G_CALLBACK (prompt_cb), NULL);
+	g_signal_connect (server, "prompt", G_CALLBACK (prompt_user_show), NULL);
 
 	g_print ("Prompter is up and running...\n");
 
diff --git a/services/evolution-user-prompter/prompt-user-gtk.c b/services/evolution-user-prompter/prompt-user-gtk.c
new file mode 100644
index 0000000..c493410
--- /dev/null
+++ b/services/evolution-user-prompter/prompt-user-gtk.c
@@ -0,0 +1,118 @@
+/*
+ * prompt-user-gtk.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include <libebackend/libebackend.h>
+
+#include "prompt-user.h"
+
+#define E_USER_PROMPTER_ID_KEY "e-user-prompter-id"
+
+void
+prompt_user_init (gint *argc,
+		  gchar ***argv)
+{
+	gtk_init (argc, argv);
+}
+
+static void
+message_response_cb (GtkWidget *dialog,
+		     gint button,
+		     EUserPrompterServer *server)
+{
+	gint prompt_id;
+
+	prompt_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), E_USER_PROMPTER_ID_KEY));
+
+	gtk_widget_destroy (dialog);
+
+	g_return_if_fail (E_IS_USER_PROMPTER_SERVER (server));
+
+	e_user_prompter_server_response (server, prompt_id, button, NULL);
+}
+
+void
+prompt_user_show (EUserPrompterServer *server,
+		  gint id,
+		  const gchar *type,
+		  const gchar *title,
+		  const gchar *primary_text,
+		  const gchar *secondary_text,
+		  gboolean use_markup,
+		  const GSList *button_captions)
+{
+	GtkMessageType ntype = GTK_MESSAGE_OTHER;
+	GtkWidget *message;
+	gint index;
+	const GSList *iter;
+
+	g_return_if_fail (server != NULL);
+
+	if (type) {
+		if (g_ascii_strcasecmp (type, "info") == 0)
+			ntype = GTK_MESSAGE_INFO;
+		else if (g_ascii_strcasecmp (type, "warning") == 0)
+			ntype = GTK_MESSAGE_WARNING;
+		else if (g_ascii_strcasecmp (type, "question") == 0)
+			ntype = GTK_MESSAGE_QUESTION;
+		else if (g_ascii_strcasecmp (type, "error") == 0)
+			ntype = GTK_MESSAGE_ERROR;
+	}
+
+	if (use_markup)
+		message = gtk_message_dialog_new_with_markup (NULL, 0, ntype, GTK_BUTTONS_NONE,
+			"%s", primary_text ? primary_text : "");
+	else
+		message = gtk_message_dialog_new (NULL, 0, ntype, GTK_BUTTONS_NONE,
+			"%s", primary_text ? primary_text : "");
+
+	/* To show dialog on a taskbar */
+	gtk_window_set_skip_taskbar_hint (GTK_WINDOW (message), FALSE);
+	gtk_window_set_title (GTK_WINDOW (message), title ? title : "");
+	gtk_window_set_icon_name (GTK_WINDOW (message), "evolution");
+
+	if (secondary_text && *secondary_text) {
+		if (use_markup)
+			gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (message),
+				"%s", secondary_text);
+		else
+			gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
+				"%s", secondary_text);
+	}
+
+	g_object_set (message, "resizable", TRUE, NULL);
+
+	for (index = 0, iter = button_captions; iter; index++, iter = iter->next) {
+		gtk_dialog_add_button (GTK_DIALOG (message), iter->data, index);
+	}
+
+	if (index == 0)
+		gtk_dialog_add_button (GTK_DIALOG (message), _("_Dismiss"), index);
+
+	g_object_set_data (G_OBJECT (message), E_USER_PROMPTER_ID_KEY, GINT_TO_POINTER (id));
+
+	g_signal_connect (message, "response", G_CALLBACK (message_response_cb), server);
+
+	gtk_widget_show (message);
+}
diff --git a/services/evolution-user-prompter/prompt-user.h b/services/evolution-user-prompter/prompt-user.h
new file mode 100644
index 0000000..23a840d
--- /dev/null
+++ b/services/evolution-user-prompter/prompt-user.h
@@ -0,0 +1,43 @@
+/*
+ * prompt-user.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef PROMPT_USER_H
+#define PROMPT_USER_H
+
+#include <libebackend/libebackend.h>
+
+/* initialize the GUI subsystem */
+void
+prompt_user_init (gint *argc,
+		  gchar ***argv);
+
+/* This is called when a request is initiated. The callback should not block,
+   and when a user responds, the e_user_prompter_server_response() should be called.
+ */
+
+void
+prompt_user_show (EUserPrompterServer *server,
+		  gint id,
+		  const gchar *type,
+		  const gchar *title,
+		  const gchar *primary_text,
+		  const gchar *secondary_text,
+		  gboolean use_markup,
+		  const GSList *button_captions);
+
+#endif /* PROMPT_USER_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]