summaryrefslogtreecommitdiff
path: root/services/evolution-user-prompter
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2012-12-13 11:46:28 +0100
committerMilan Crha <mcrha@redhat.com>2012-12-13 11:46:28 +0100
commit432f30d7fad73d9ce3bc5d3f7a14e8a4969f0590 (patch)
treee9050fcdac7acc1e90f18ff4b9d6ba02992f05b5 /services/evolution-user-prompter
parent3382817cccc79780d3abf89ebbd117323b5a6703 (diff)
downloadevolution-data-server-432f30d7fad73d9ce3bc5d3f7a14e8a4969f0590.tar.gz
Bisect Gtk+ calls into separate files
This way it'll be easier to provide other than Gtk+ GUI implementations of the prompts.
Diffstat (limited to 'services/evolution-user-prompter')
-rw-r--r--services/evolution-user-prompter/Makefile.am16
-rw-r--r--services/evolution-user-prompter/evolution-user-prompter.c93
-rw-r--r--services/evolution-user-prompter/prompt-user-gtk.c118
-rw-r--r--services/evolution-user-prompter/prompt-user.h43
4 files changed, 179 insertions, 91 deletions
diff --git a/services/evolution-user-prompter/Makefile.am b/services/evolution-user-prompter/Makefile.am
index 906417109..8f865cf85 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 375ced0c5..8a35c3dd6 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 000000000..c49341065
--- /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 000000000..23a840d0a
--- /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 */