25 #include <glib/gstdio.h>
26 #include <glib/gi18n.h>
39 #if !(_WIN32_WINNT >= 0x0500)
40 #error "_WIN32_WINNT must be defined >= 0x0500"
63 g_print (
"%s %s\n",
_(
"GNOME Document Viewer"), VERSION);
71 {
"page-label",
'p', 0, G_OPTION_ARG_STRING, &
ev_page_label, N_(
"The page label of the document to display."), N_(
"PAGE")},
72 {
"page-index",
'i', 0, G_OPTION_ARG_INT, &
ev_page_index, N_(
"The page number of the document to display."), N_(
"NUMBER")},
73 {
"named-dest",
'n', 0, G_OPTION_ARG_STRING, &
ev_named_dest, N_(
"Named destination to display."), N_(
"DEST")},
74 {
"fullscreen",
'f', 0, G_OPTION_ARG_NONE, &
fullscreen_mode, N_(
"Run evince in fullscreen mode"), NULL },
75 {
"presentation",
's', 0, G_OPTION_ARG_NONE, &
presentation_mode, N_(
"Run evince in presentation mode"), NULL },
76 {
"preview",
'w', 0, G_OPTION_ARG_NONE, &
preview_mode, N_(
"Run evince as a previewer"), NULL },
77 {
"find",
'l', 0, G_OPTION_ARG_STRING, &
ev_find_string, N_(
"The word or phrase to find in the document"), N_(
"STRING")},
78 {
"unlink-tempfile",
'u', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &
unlink_temp_file, NULL, NULL },
79 {
"print-settings",
't', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &
print_settings, NULL, NULL },
80 {
"version", 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK,
option_version_cb, NULL, NULL },
81 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &
file_arguments, NULL, N_(
"[FILEā¦]") },
90 gboolean retval =
FALSE;
97 cmd_str = g_string_new (
"evince-previewer");
103 g_string_append_printf (cmd_str,
" --print-settings %s", quoted);
108 g_string_append (cmd_str,
" --unlink-tempfile");
114 g_string_append_printf (cmd_str,
" %s", quoted);
118 cmd = g_string_free (cmd_str,
FALSE);
123 app = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
126 retval = g_app_info_launch (app, NULL, NULL, &error);
127 g_object_unref (app);
132 g_warning (
"Error launching previewer: %s\n", error->message);
133 g_error_free (error);
148 label = g_strrstr (filename,
"#");
156 file = g_file_new_for_commandline_arg (filename);
157 exists = g_file_query_exists (file, NULL);
158 g_object_unref (file);
160 return exists ? NULL :
label;
166 GdkScreen *screen = gdk_screen_get_default ();
189 for (i = 0; files[i]; i++) {
190 const gchar *filename;
195 const gchar *app_uri;
203 }
else if (global_dest) {
204 dest = g_object_ref (global_dest);
207 file = g_file_new_for_commandline_arg (filename);
208 uri = g_file_get_uri (file);
209 g_object_unref (file);
212 if (app_uri && strcmp (app_uri, uri) == 0) {
224 g_object_unref (dest);
233 GOptionContext *context;
234 GError *error = NULL;
239 if (fileno (stdout) != -1 &&
240 _get_osfhandle (fileno (stdout)) != -1)
246 typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
248 AttachConsole_t p_AttachConsole =
249 (AttachConsole_t) GetProcAddress (GetModuleHandle (
"kernel32.dll"),
"AttachConsole");
251 if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
253 freopen (
"CONOUT$",
"w", stdout);
254 dup2 (fileno (stdout), 1);
255 freopen (
"CONOUT$",
"w", stderr);
256 dup2 (fileno (stderr), 2);
265 bind_textdomain_codeset (GETTEXT_PACKAGE,
"UTF-8");
266 textdomain (GETTEXT_PACKAGE);
269 context = g_option_context_new (N_(
"GNOME Document Viewer"));
270 g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
271 g_option_context_add_main_entries (context,
goption_options, GETTEXT_PACKAGE);
273 g_option_context_add_group (context, gtk_get_option_group (
TRUE));
275 if (!g_option_context_parse (context, &argc, &argv, &error)) {
276 g_printerr (
"Cannot parse arguments: %s\n", error->message);
277 g_error_free (error);
278 g_option_context_free (context);
282 g_option_context_free (context);
289 return retval ? 0 : 1;
298 g_set_application_name (
_(
"Document Viewer"));
299 gtk_window_set_default_icon_name (
"evince");
302 if (!g_application_register (G_APPLICATION (application), NULL, &error)) {
303 g_printerr (
"Failed to register: %s\n", error->message);
304 g_error_free (error);
314 g_chdir (g_get_home_dir ());
316 status = g_application_run (G_APPLICATION (application), 0, NULL);
322 g_object_unref (application);