139 GtkApplication *application;
140 GOptionContext *context;
141 GError *error = NULL;
146 if (fileno (stdout) != -1 &&
147 _get_osfhandle (fileno (stdout)) != -1)
153 typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
155 AttachConsole_t p_AttachConsole =
156 (AttachConsole_t) GetProcAddress (GetModuleHandle (
"kernel32.dll"),
"AttachConsole");
158 if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
160 freopen (
"CONOUT$",
"w", stdout);
161 dup2 (fileno (stdout), 1);
162 freopen (
"CONOUT$",
"w", stderr);
163 dup2 (fileno (stderr), 2);
172 bind_textdomain_codeset (GETTEXT_PACKAGE,
"UTF-8");
173 textdomain (GETTEXT_PACKAGE);
176 context = g_option_context_new (
_(
"GNOME Document Previewer"));
177 g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
178 g_option_context_add_main_entries (context,
goption_options, GETTEXT_PACKAGE);
180 g_option_context_add_group (context, gtk_get_option_group (
TRUE));
182 if (!g_option_context_parse (context, &argc, &argv, &error)) {
183 g_printerr (
"Error parsing command line arguments: %s\n", error->message);
184 g_error_free (error);
185 g_option_context_free (context);
188 g_option_context_free (context);
191 g_printerr (
"File argument is required\n");
193 }
else if (argc > 2) {
194 g_printerr (
"Too many files\n");
198 path = g_filename_from_uri (argv[1], NULL, NULL);
199 if (!g_file_test (argv[1], G_FILE_TEST_IS_REGULAR) && !g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
200 g_printerr (
"Filename \"%s\" does not exist or is not a regular file\n", argv[1]);
210 g_set_application_name (
_(
"GNOME Document Previewer"));
211 gtk_window_set_default_icon_name (
"evince");
213 application = gtk_application_new (NULL,
214 G_APPLICATION_NON_UNIQUE |
215 G_APPLICATION_HANDLES_OPEN);
216 g_signal_connect (application,
"activate", G_CALLBACK (
activate_cb), NULL);
217 g_signal_connect (application,
"open", G_CALLBACK (
open_cb), NULL);
219 status = g_application_run (G_APPLICATION (application), argc, argv);