X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=previewer%2Fev-previewer.c;h=50290798575cf0e2f09cf4fc40673d768e9bac55;hb=212d9a536bc60e711b779feb5e8aa33db654997d;hp=e66a043811328e1109ab03300825302ffbe22466;hpb=faace27fc6850ac153a41d47e51dfbd589dc1411;p=evince.git diff --git a/previewer/ev-previewer.c b/previewer/ev-previewer.c index e66a0438..50290798 100644 --- a/previewer/ev-previewer.c +++ b/previewer/ev-previewer.c @@ -15,7 +15,7 @@ * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include @@ -24,10 +24,18 @@ #include #include #include -#include "ev-stock-icons.h" #include "ev-previewer-window.h" +#ifdef G_OS_WIN32 +#include +#include +#if !(_WIN32_WINNT >= 0x0500) +#error "_WIN32_WINNT must be defined >= 0x0500" +#endif +#include +#endif + static gboolean unlink_temp_file = FALSE; static const gchar *print_settings; static const gchar **filenames; @@ -43,9 +51,6 @@ static void ev_previewer_unlink_tempfile (const gchar *filename) { GFile *file, *tempdir; - - if (!unlink_temp_file) - return; file = g_file_new_for_path (filename); tempdir = g_file_new_for_path (g_get_tmp_dir ()); @@ -59,8 +64,8 @@ ev_previewer_unlink_tempfile (const gchar *filename) } static void -ev_previewer_load_job_finished (EvJob *job, - EvPreviewerWindow *window) +ev_previewer_load_job_finished (EvJob *job, + EvDocumentModel *model) { if (ev_job_is_failed (job)) { g_warning ("%s", job->error->message); @@ -68,23 +73,26 @@ ev_previewer_load_job_finished (EvJob *job, return; } - - ev_previewer_window_set_document (window, job->document); + ev_document_model_set_document (model, job->document); g_object_unref (job); } static void -ev_previewer_load_document (const gchar *filename, - EvPreviewerWindow *window) +ev_previewer_load_document (const gchar *filename, + EvDocumentModel *model) { EvJob *job; gchar *uri; + GFile *file; + + file = g_file_new_for_commandline_arg (filename); + uri = g_file_get_uri (file); + g_object_unref (file); - uri = g_filename_to_uri (filename, NULL, NULL); job = ev_job_load_new (uri); g_signal_connect (job, "finished", G_CALLBACK (ev_previewer_load_job_finished), - window); + model); ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE); g_free (uri); } @@ -92,10 +100,35 @@ ev_previewer_load_document (const gchar *filename, gint main (gint argc, gchar **argv) { - GtkWidget *window; - GOptionContext *context; - const gchar *filename; - GError *error = NULL; + GtkWidget *window; + GOptionContext *context; + const gchar *filename; + EvDocumentModel *model; + GError *error = NULL; + +#ifdef G_OS_WIN32 + if (fileno (stdout) != -1 && + _get_osfhandle (fileno (stdout)) != -1) + { + /* stdout is fine, presumably redirected to a file or pipe */ + } + else + { + typedef BOOL (* WINAPI AttachConsole_t) (DWORD); + + AttachConsole_t p_AttachConsole = + (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole"); + + if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS)) + { + freopen ("CONOUT$", "w", stdout); + dup2 (fileno (stdout), 1); + freopen ("CONOUT$", "w", stderr); + dup2 (fileno (stderr), 2); + + } + } +#endif /* Init glib threads asap */ if (!g_thread_supported ()) @@ -103,7 +136,7 @@ main (gint argc, gchar **argv) #ifdef ENABLE_NLS /* Initialize the i18n stuff */ - bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir()); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif @@ -145,7 +178,8 @@ main (gint argc, gchar **argv) g_set_application_name (_("GNOME Document Previewer")); gtk_window_set_default_icon_name ("evince"); - window = ev_previewer_window_new (); + model = ev_document_model_new (); + window = ev_previewer_window_new (model); ev_previewer_window_set_source_file (EV_PREVIEWER_WINDOW (window), filename); ev_previewer_window_set_print_settings (EV_PREVIEWER_WINDOW (window), print_settings); g_signal_connect (window, "delete-event", @@ -154,14 +188,18 @@ main (gint argc, gchar **argv) G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show (window); - ev_previewer_load_document (filename, EV_PREVIEWER_WINDOW (window)); + ev_previewer_load_document (filename, model); gtk_main (); - ev_previewer_unlink_tempfile (filename); + if (unlink_temp_file) + ev_previewer_unlink_tempfile (filename); + if (print_settings) + ev_previewer_unlink_tempfile (print_settings); ev_shutdown (); ev_stock_icons_shutdown (); + g_object_unref (model); return 0; }