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-file-helpers.h File Reference
#include <glib.h>
#include <gio/gio.h>
+ Include dependency graph for ev-file-helpers.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  EvCompressionType { EV_COMPRESSION_NONE, EV_COMPRESSION_BZIP2, EV_COMPRESSION_GZIP, EV_COMPRESSION_LZMA }
 

Functions

void _ev_file_helpers_init (void)
 
void _ev_file_helpers_shutdown (void)
 
int ev_mkstemp (const char *tmpl, char **file_name, GError **error)
 
GFile * ev_mkstemp_file (const char *tmpl, GError **error)
 
gchar * ev_mkdtemp (const char *tmpl, GError **error)
 
void ev_tmp_filename_unlink (const gchar *filename)
 
void ev_tmp_file_unlink (GFile *file)
 
void ev_tmp_uri_unlink (const gchar *uri)
 
gboolean ev_file_is_temp (GFile *file)
 
gboolean ev_xfer_uri_simple (const char *from, const char *to, GError **error)
 
gboolean ev_file_copy_metadata (const char *from, const char *to, GError **error)
 
gchar * ev_file_get_mime_type (const gchar *uri, gboolean fast, GError **error)
 
gchar * ev_file_uncompress (const gchar *uri, EvCompressionType type, GError **error)
 
gchar * ev_file_compress (const gchar *uri, EvCompressionType type, GError **error)
 

Enumeration Type Documentation

Enumerator
EV_COMPRESSION_NONE 
EV_COMPRESSION_BZIP2 
EV_COMPRESSION_GZIP 
EV_COMPRESSION_LZMA 

Definition at line 32 of file ev-file-helpers.h.

Function Documentation

void _ev_file_helpers_init ( void  )

Definition at line 103 of file ev-file-helpers.c.

104 {
105 }

+ Here is the caller graph for this function:

void _ev_file_helpers_shutdown ( void  )

Definition at line 108 of file ev-file-helpers.c.

109 {
110  if (tmp_dir != NULL)
111  g_rmdir (tmp_dir);
112 
113  g_free (tmp_dir);
114  tmp_dir = NULL;
115 }

+ Here is the caller graph for this function:

gchar* ev_file_compress ( const gchar *  uri,
EvCompressionType  type,
GError **  error 
)

ev_file_compress: : a file URI : the compression type : a #GError location to store an error, or NULL

Compresses the file at .

If is EV_COMPRESSION_NONE, it does nothing and returns NULL.

Otherwise, it returns the filename of a temporary file containing the compressed data from the file at .

On error it returns NULL and fills in .

It is the caller's responsibility to unlink the temp file after use.

Returns: a newly allocated string URI, or NULL on error

Definition at line 735 of file ev-file-helpers.c.

738 {
739  g_return_val_if_fail (uri != NULL, NULL);
740 
741  return compression_run (uri, type, TRUE, error);
742 }

+ Here is the caller graph for this function:

gboolean ev_file_copy_metadata ( const char *  from,
const char *  to,
GError **  error 
)

ev_file_copy_metadata: : the source URI : the target URI : a #GError location to store an error, or NULL

Performs a g_file_copy_attributes() with G_FILE_COPY_ALL_METADATA from to .

Returns: TRUE if the attributes were copied successfully, FALSE otherwise.

Since: 3.4

Definition at line 444 of file ev-file-helpers.c.

447 {
448  GFile *source_file;
449  GFile *target_file;
450  gboolean result;
451 
452  g_return_val_if_fail (from != NULL, FALSE);
453  g_return_val_if_fail (to != NULL, FALSE);
454 
455  source_file = g_file_new_for_uri (from);
456  target_file = g_file_new_for_uri (to);
457 
458  result = g_file_copy_attributes (source_file, target_file,
459  G_FILE_COPY_ALL_METADATA |
460  G_FILE_COPY_TARGET_DEFAULT_PERMS,
461  NULL, error);
462 
463  g_object_unref (target_file);
464  g_object_unref (source_file);
465 
466  return result;
467 }

+ Here is the caller graph for this function:

gchar* ev_file_get_mime_type ( const gchar *  uri,
gboolean  fast,
GError **  error 
)

ev_file_get_mime_type: : the URI : whether to use fast MIME type detection : a #GError location to store an error, or NULL

Returns: a newly allocated string with the MIME type of the file at , or NULL on error or if the MIME type could not be determined

Definition at line 573 of file ev-file-helpers.c.

576 {
577  return fast ? get_mime_type_from_uri (uri, error) : get_mime_type_from_data (uri, error);
578 }

+ Here is the caller graph for this function:

gboolean ev_file_is_temp ( GFile *  file)

Definition at line 374 of file ev-file-helpers.c.

375 {
376  gchar *path;
377  gboolean retval;
378 
379  if (!g_file_is_native (file))
380  return FALSE;
381 
382  path = g_file_get_path (file);
383  if (!path)
384  return FALSE;
385 
386  retval = g_str_has_prefix (path, g_get_tmp_dir ());
387  g_free (path);
388 
389  return retval;
390 }

+ Here is the caller graph for this function:

gchar* ev_file_uncompress ( const gchar *  uri,
EvCompressionType  type,
GError **  error 
)

ev_file_uncompress: : a file URI : the compression type : a #GError location to store an error, or NULL

Uncompresses the file at .

If is EV_COMPRESSION_NONE, it does nothing and returns NULL.

Otherwise, it returns the filename of a temporary file containing the decompressed data from the file at . On error it returns NULL and fills in .

It is the caller's responsibility to unlink the temp file after use.

Returns: a newly allocated string URI, or NULL on error

Definition at line 706 of file ev-file-helpers.c.

709 {
710  g_return_val_if_fail (uri != NULL, NULL);
711 
712  return compression_run (uri, type, FALSE, error);
713 }

+ Here is the caller graph for this function:

gchar* ev_mkdtemp ( const char *  tmpl,
GError **  error 
)

ev_mkdtemp: : a template string; must end in 'XXXXXX' : a location to store a #GError

Creates a temp directory in the evince temp directory.

Returns: a newly allocated string with the temp directory name, or NULL on error with filled in

Definition at line 295 of file ev-file-helpers.c.

297 {
298  const char *tmp;
299  char *name;
300 
301  if ((tmp = _ev_tmp_dir (error)) == NULL)
302  return NULL;
303 
304  name = g_build_filename (tmp, tmpl, NULL);
305  if (_ev_g_mkdtemp (name) == NULL) {
306  int errsv = errno;
307 
308  g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
309  _("Failed to create a temporary directory: %s"),
310  g_strerror (errsv));
311 
312  g_free (name);
313  return NULL;
314  }
315 
316  return name;
317 }
int ev_mkstemp ( const char *  tmpl,
char **  file_name,
GError **  error 
)

ev_mkstemp: : a template string; must contain 'XXXXXX', but not necessarily as a suffix : a location to store the filename of the temp file : a location to store a #GError

Creates a temp file in the evince temp directory.

Returns: a file descriptor to the newly created temp file name, or %-1 on error with filled in

Definition at line 129 of file ev-file-helpers.c.

132 {
133  const char *tmp;
134  char *name;
135  int fd;
136 
137  if ((tmp = _ev_tmp_dir (error)) == NULL)
138  return -1;
139 
140  name = g_build_filename (tmp, tmpl, NULL);
141  fd = g_mkstemp (name);
142 
143  if (fd == -1) {
144  int errsv = errno;
145 
146  g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
147  _("Failed to create a temporary file: %s"),
148  g_strerror (errsv));
149 
150  g_free (name);
151  return -1;
152  }
153 
154  if (file_name)
155  *file_name = name;
156 
157  return fd;
158 }

+ Here is the caller graph for this function:

GFile* ev_mkstemp_file ( const char *  tmpl,
GError **  error 
)

ev_mkstemp_file: : a template string; must contain 'XXXXXX', but not necessarily as a suffix : a location to store a #GError

Creates a temp #GFile in the evince temp directory. See ev_mkstemp() for more information.

Returns: (transfer full): a newly allocated #GFile for the newly created temp file name, or NULL on error with filled in

Definition at line 179 of file ev-file-helpers.c.

181 {
182  char *file_name;
183  int fd;
184  GFile *file;
185 
186  fd = ev_mkstemp (tmpl, &file_name, error);
187  if (fd == -1)
188  return NULL;
189 
190  file = g_file_new_for_path (file_name);
191  g_free (file_name);
192 
193  g_object_set_data_full (G_OBJECT (file), "ev-mkstemp-fd",
194  GINT_TO_POINTER (fd), (GDestroyNotify) close_fd_cb);
195 
196  return file;
197 }

+ Here is the caller graph for this function:

void ev_tmp_file_unlink ( GFile *  file)

Definition at line 335 of file ev-file-helpers.c.

336 {
337  gboolean res;
338  GError *error = NULL;
339 
340  if (!file)
341  return;
342 
343  res = g_file_delete (file, NULL, &error);
344  if (!res) {
345  char *uri;
346 
347  uri = g_file_get_uri (file);
348  g_warning ("Unable to delete temp file %s: %s\n", uri, error->message);
349  g_free (uri);
350  g_error_free (error);
351  }
352 }

+ Here is the caller graph for this function:

void ev_tmp_filename_unlink ( const gchar *  filename)

Definition at line 321 of file ev-file-helpers.c.

322 {
323  if (!filename)
324  return;
325 
326  if (!tmp_dir)
327  return;
328 
329  if (g_str_has_prefix (filename, tmp_dir)) {
330  g_unlink (filename);
331  }
332 }

+ Here is the caller graph for this function:

void ev_tmp_uri_unlink ( const gchar *  uri)

Definition at line 355 of file ev-file-helpers.c.

356 {
357  GFile *file;
358 
359  if (!uri)
360  return;
361 
362  file = g_file_new_for_uri (uri);
363  if (!g_file_is_native (file)) {
364  g_warning ("Attempting to delete non native uri: %s\n", uri);
365  g_object_unref (file);
366  return;
367  }
368 
369  ev_tmp_file_unlink (file);
370  g_object_unref (file);
371 }

+ Here is the caller graph for this function:

gboolean ev_xfer_uri_simple ( const char *  from,
const char *  to,
GError **  error 
)

ev_xfer_uri_simple: : the source URI : the target URI : a #GError location to store an error, or NULL

Performs a g_file_copy() from to .

Returns: TRUE on success, or FALSE on error with filled in

Definition at line 403 of file ev-file-helpers.c.

406 {
407  GFile *source_file;
408  GFile *target_file;
409  gboolean result;
410 
411  if (!from)
412  return TRUE;
413 
414  g_return_val_if_fail (to != NULL, TRUE);
415 
416  source_file = g_file_new_for_uri (from);
417  target_file = g_file_new_for_uri (to);
418 
419  result = g_file_copy (source_file, target_file,
420  G_FILE_COPY_TARGET_DEFAULT_PERMS |
421  G_FILE_COPY_OVERWRITE,
422  NULL, NULL, NULL, error);
423 
424  g_object_unref (target_file);
425  g_object_unref (source_file);
426 
427  return result;
428 }

+ Here is the caller graph for this function: