1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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;
}
|