summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--test/Makefile.am5
-rw-r--r--test/previewer-plug.c92
-rw-r--r--test/previewer.c116
4 files changed, 130 insertions, 84 deletions
diff --git a/.gitignore b/.gitignore
index 817f7dd..43c1393 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,5 +24,6 @@ stamp-h1
ChangeLog
test/previewer
+test/previewer-plug
test/mime
test/firefox.sh
diff --git a/test/Makefile.am b/test/Makefile.am
index 7b65dd4..2f5bc40 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,4 +1,5 @@
-AM_CFLAGS = -I$(top_srcdir)/src $(MOZILLA_CFLAGS) $(EVINCE_CFLAGS) $(E_CFLAGS)
+AM_CFLAGS = -I$(top_srcdir)/src $(MOZILLA_CFLAGS) $(EVINCE_CFLAGS) \
+ $(E_CFLAGS) -DPLUG_PROCESS=\"$(abs_builddir)/previewer-plug$(EXEEXT)\"
LDADD = $(top_builddir)/src/libevbp-viewer.la
-noinst_PROGRAMS = mime previewer
+noinst_PROGRAMS = mime previewer previewer-plug
diff --git a/test/previewer-plug.c b/test/previewer-plug.c
new file mode 100644
index 0000000..239a611
--- /dev/null
+++ b/test/previewer-plug.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2011, 2012 Dan Nicholson <dbn.lists@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+
+ * 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
+ * General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#if GTK_MAJOR_VERSION > 2
+#include <gtk/gtkx.h>
+#endif
+#include <gdk/gdkx.h>
+#include "evbp-viewer.h"
+
+static inline void
+no_debug(const gchar *domain, GLogLevelFlags level,
+ const gchar *message, gpointer data)
+{
+}
+
+int
+main(int argc, char *argv[])
+{
+ Window win;
+ GFile *file;
+ gchar *uri;
+ GtkWidget *plug;
+ GtkWidget *box, *button;
+ GtkWidget *viewer;
+ GError *error = NULL;
+
+ gtk_init(&argc, &argv);
+
+ if (!getenv("EVBP_DEBUG"))
+ g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, no_debug, NULL);
+
+ if (argc < 3) {
+ g_printerr("No socket ID or filename supplied\n");
+ exit(EXIT_FAILURE);
+ }
+ win = (Window)strtoul(argv[1], NULL, 10);
+ g_debug("Received socket window ID %lu\n", (unsigned long)win);
+ file = g_file_new_for_commandline_arg(argv[2]);
+ uri = g_file_get_uri(file);
+ g_object_unref(file);
+
+ if (!ev_init()) {
+ g_printerr("No evince backends found\n");
+ exit(EXIT_FAILURE);
+ }
+ ev_stock_icons_init();
+
+ /* create a plug and add our widget with a quit button */
+ plug = gtk_plug_new(win);
+ box = gtk_vbox_new(FALSE, 10);
+ gtk_container_add(GTK_CONTAINER(plug), box);
+ button = gtk_button_new_with_label("Quit");
+ g_signal_connect(button, "clicked", G_CALLBACK(gtk_main_quit), NULL);
+ gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0);
+ viewer = evbp_viewer_new();
+ gtk_box_pack_start(GTK_BOX(box), viewer, TRUE, TRUE, 0);
+ gtk_widget_show_all(plug);
+
+ /* load the file */
+ if (!evbp_viewer_load_uri(EVBP_VIEWER(viewer), uri, &error)) {
+ g_printerr("could not open '%s': %s\n", uri, error->message);
+ g_error_free(error);
+ exit(EXIT_FAILURE);
+ }
+ g_free(uri);
+
+ gtk_main();
+
+ ev_shutdown();
+ ev_stock_icons_shutdown();
+
+ return 0;
+}
diff --git a/test/previewer.c b/test/previewer.c
index ea748eb..bc78b57 100644
--- a/test/previewer.c
+++ b/test/previewer.c
@@ -19,14 +19,16 @@
#include <config.h>
#include <stdlib.h>
-#include <locale.h>
#include <glib.h>
-#include <gio/gio.h>
#include <gtk/gtk.h>
-#include "evbp-viewer.h"
+#if GTK_MAJOR_VERSION > 2
+#include <gtk/gtkx.h>
+#endif
+#include <gdk/gdkx.h>
-static gboolean print_version;
-static gchar **filenames;
+#ifndef PLUG_PROCESS
+#define PLUG_PROCESS "./previewer-plug"
+#endif
static inline void
no_debug(const gchar *domain, GLogLevelFlags level,
@@ -34,104 +36,54 @@ no_debug(const gchar *domain, GLogLevelFlags level,
{
}
-static GOptionEntry opt_entries[] = {
- { "version", 'V', 0, G_OPTION_ARG_NONE, &print_version,
- "Print version", NULL },
- { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames,
- NULL, "FILE" },
- { NULL }
-};
-
int
main(int argc, char *argv[])
{
- GOptionContext *opt;
- GError *error = NULL;
- guint n_files;
- GFile *file;
- gchar *uri;
GtkWidget *window;
- GtkWidget *viewer;
+ GtkWidget *socket;
+ Window win;
+ gchar *cmd;
+ GError *error = NULL;
- g_type_init();
- setlocale(LC_ALL, "");
+ gtk_init(&argc, &argv);
if (!getenv("EVBP_DEBUG"))
g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, no_debug, NULL);
- opt = g_option_context_new(NULL);
- g_option_context_set_summary(opt, "Test app for the Evince libraries");
- g_option_context_add_main_entries(opt, opt_entries, GETTEXT_PACKAGE);
- g_option_context_add_group(opt, gtk_get_option_group(FALSE));
- if (!g_option_context_parse(opt, &argc, &argv, &error)) {
- g_printerr("failed to parse arguments: %s\n", error->message);
- exit(1);
+ if (argc < 2) {
+ g_printerr("No file supplied to open\n");
+ exit(EXIT_FAILURE);
}
- g_option_context_free(opt);
- if (print_version) {
- g_print("%s\n", PACKAGE_VERSION);
- exit(0);
- }
-
- if (filenames)
- n_files = g_strv_length(filenames);
- else
- n_files = 0;
- if (n_files == 0) {
- g_printerr("no file specified\n");
- exit(1);
- }
- if (n_files > 1)
- g_printerr("only one file can be processed, others are ignored\n");
-
- g_debug("converting file \"%s\" to uri", filenames[0]);
- file = g_file_new_for_commandline_arg(filenames[0]);
- uri = g_file_get_uri(file);
- g_strfreev(filenames);
- filenames = NULL;
-
- if (!g_file_query_exists(file, NULL)) {
- g_printerr("file '%s' does not exist\n", uri);
- exit(1);
- }
- if (g_file_query_file_type(file, 0, NULL) != G_FILE_TYPE_REGULAR) {
- g_printerr("file '%s' is not a regular file\n", uri);
- exit(1);
- }
- g_object_unref(file);
-
- gtk_init(&argc, &argv);
- if (!ev_init()) {
- g_printerr("no evince backends found\n");
- exit(1);
- }
- ev_stock_icons_init();
-
- g_set_application_name("Evince Previewer Test");
+ g_set_application_name("Evince Previewer Socket Test");
gtk_window_set_default_icon_name("evince");
- viewer = evbp_viewer_new();
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 800, 800);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
- gtk_container_add(GTK_CONTAINER(window), viewer);
+
+ /* create a socket to embed the viewer in */
+ socket = gtk_socket_new();
+ g_signal_connect(socket, "plug-removed", G_CALLBACK(gtk_main_quit), NULL);
+ gtk_container_add(GTK_CONTAINER(window), socket);
gtk_widget_show_all(window);
- if (!evbp_viewer_load_uri(EVBP_VIEWER(viewer), uri, &error)) {
- if (error) {
- g_printerr("could not open '%s': %s\n", uri, error->message);
- g_error_free(error);
- } else
- g_printerr("could not open '%s'\n", uri);
- exit(1);
+ /* get the socket window ID to pass to the plug process */
+ win = gtk_socket_get_id(GTK_SOCKET(socket));
+ g_debug("The ID of the socket window is %lu\n", (unsigned long)win);
+
+ /* spawn the plug process with the file */
+ cmd = g_strdup_printf("\"%s\" %lu \"%s\"", PLUG_PROCESS,
+ (unsigned long)win, argv[1]);
+ if (!g_spawn_command_line_async(cmd, &error)) {
+ g_printerr("Failed to spawn plug process '%s': %s\n", cmd,
+ error->message);
+ g_error_free(error);
+ exit(EXIT_FAILURE);
}
- g_free(uri);
+ g_free(cmd);
gtk_main();
- ev_shutdown();
- ev_stock_icons_shutdown();
-
return 0;
}