Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-previewer.c File Reference
#include "config.h"
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <evince-document.h>
#include <evince-view.h>
#include "ev-previewer-window.h"
+ Include dependency graph for ev-previewer.c:

Go to the source code of this file.

Functions

static void ev_previewer_unlink_tempfile (const gchar *filename)
 
static void ev_previewer_load_job_finished (EvJob *job, EvDocumentModel *model)
 
static void ev_previewer_load_document (GFile *file, EvDocumentModel *model)
 
static void activate_cb (GApplication *application, gpointer user_data)
 
static void open_cb (GApplication *application, GFile **files, gint n_files, const gchar *hint, gpointer user_data)
 
gint main (gint argc, gchar **argv)
 

Variables

static gboolean unlink_temp_file = FALSE
 
static gchar * print_settings = NULL
 
static EvPreviewerWindowwindow = NULL
 
static const GOptionEntry goption_options []
 

Function Documentation

static void activate_cb ( GApplication *  application,
gpointer  user_data 
)
static

Definition at line 96 of file ev-previewer.c.

98 {
99  if (window) {
100  gtk_window_present (GTK_WINDOW (window));
101  }
102 }

+ Here is the caller graph for this function:

static void ev_previewer_load_document ( GFile *  file,
EvDocumentModel model 
)
static

Definition at line 79 of file ev-previewer.c.

81 {
82  EvJob *job;
83  gchar *uri;
84 
85  uri = g_file_get_uri (file);
86 
87  job = ev_job_load_new (uri);
88  g_signal_connect (job, "finished",
89  G_CALLBACK (ev_previewer_load_job_finished),
90  model);
92  g_free (uri);
93 }

+ Here is the caller graph for this function:

static void ev_previewer_load_job_finished ( EvJob job,
EvDocumentModel model 
)
static

Definition at line 67 of file ev-previewer.c.

69 {
70  if (ev_job_is_failed (job)) {
71  g_object_unref (job);
72  return;
73  }
75  g_object_unref (job);
76 }

+ Here is the caller graph for this function:

static void ev_previewer_unlink_tempfile ( const gchar *  filename)
static

Definition at line 51 of file ev-previewer.c.

52 {
53  GFile *file, *tempdir;
54 
55  file = g_file_new_for_path (filename);
56  tempdir = g_file_new_for_path (g_get_tmp_dir ());
57 
58  if (g_file_has_prefix (file, tempdir)) {
59  g_file_delete (file, NULL, NULL);
60  }
61 
62  g_object_unref (file);
63  g_object_unref (tempdir);
64 }

+ Here is the caller graph for this function:

gint main ( gint  argc,
gchar **  argv 
)

Definition at line 137 of file ev-previewer.c.

138 {
139  GtkApplication *application;
140  GOptionContext *context;
141  GError *error = NULL;
142  gchar *path;
143  int status = 1;
144 
145 #ifdef G_OS_WIN32
146  if (fileno (stdout) != -1 &&
147  _get_osfhandle (fileno (stdout)) != -1)
148  {
149  /* stdout is fine, presumably redirected to a file or pipe */
150  }
151  else
152  {
153  typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
154 
155  AttachConsole_t p_AttachConsole =
156  (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
157 
158  if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
159  {
160  freopen ("CONOUT$", "w", stdout);
161  dup2 (fileno (stdout), 1);
162  freopen ("CONOUT$", "w", stderr);
163  dup2 (fileno (stderr), 2);
164 
165  }
166  }
167 #endif
168 
169 #ifdef ENABLE_NLS
170  /* Initialize the i18n stuff */
171  bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir());
172  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
173  textdomain (GETTEXT_PACKAGE);
174 #endif
175 
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);
179 
180  g_option_context_add_group (context, gtk_get_option_group (TRUE));
181 
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);
186  return 1;
187  }
188  g_option_context_free (context);
189 
190  if (argc < 2) {
191  g_printerr ("File argument is required\n");
192  return 1;
193  } else if (argc > 2) {
194  g_printerr ("Too many files\n");
195  return 1;
196  }
197 
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]);
201  return 1;
202  }
203  g_free (path);
204 
205  if (!ev_init ())
206  return 1;
207 
209 
210  g_set_application_name (_("GNOME Document Previewer"));
211  gtk_window_set_default_icon_name ("evince");
212 
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);
218 
219  status = g_application_run (G_APPLICATION (application), argc, argv);
220 
221  if (unlink_temp_file)
223  if (print_settings)
225 
226  ev_shutdown ();
228 
229  return status;
230 }
static void open_cb ( GApplication *  application,
GFile **  files,
gint  n_files,
const gchar *  hint,
gpointer  user_data 
)
static

Definition at line 105 of file ev-previewer.c.

110 {
111  EvDocumentModel *model;
112  GFile *file;
113  char *path;
114 
115  if (n_files != 1) {
116  g_application_quit (application);
117  return;
118  }
119 
120  file = files[0];
121 
122  model = ev_document_model_new ();
123  ev_previewer_load_document (file, model);
124 
126  g_object_unref (model);
127 
129  path = g_file_get_path (file);
131  g_free (path);
132 
133  gtk_window_present (GTK_WINDOW (window));
134 }

+ Here is the caller graph for this function:

Variable Documentation

const GOptionEntry goption_options[]
static
Initial value:
= {
{ "unlink-tempfile", 'u', 0, G_OPTION_ARG_NONE, &unlink_temp_file, N_("Delete the temporary file"), NULL },
{ "print-settings", 'p', 0, G_OPTION_ARG_FILENAME, &print_settings, N_("Print settings file"), N_("FILE") },
{ NULL }
}

Definition at line 44 of file ev-previewer.c.

gchar* print_settings = NULL
static

Definition at line 41 of file ev-previewer.c.

gboolean unlink_temp_file = FALSE
static

Definition at line 40 of file ev-previewer.c.

EvPreviewerWindow* window = NULL
static

Definition at line 42 of file ev-previewer.c.