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-attachment.c File Reference
#include <config.h>
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include "ev-file-helpers.h"
#include "ev-attachment.h"
+ Include dependency graph for ev-attachment.c:

Go to the source code of this file.

Data Structures

struct  _EvAttachmentPrivate
 

Macros

#define EV_ATTACHMENT_GET_PRIVATE(object)   (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_ATTACHMENT, EvAttachmentPrivate))
 

Enumerations

enum  {
  PROP_0, PROP_NAME, PROP_DESCRIPTION, PROP_MTIME,
  PROP_CTIME, PROP_SIZE, PROP_DATA
}
 

Functions

GQuark ev_attachment_error_quark (void)
 
static void ev_attachment_finalize (GObject *object)
 
static void ev_attachment_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *param_spec)
 
static void ev_attachment_class_init (EvAttachmentClass *klass)
 
static void ev_attachment_init (EvAttachment *attachment)
 
EvAttachmentev_attachment_new (const gchar *name, const gchar *description, GTime mtime, GTime ctime, gsize size, gpointer data)
 
const gchar * ev_attachment_get_name (EvAttachment *attachment)
 
const gchar * ev_attachment_get_description (EvAttachment *attachment)
 
GTime ev_attachment_get_modification_date (EvAttachment *attachment)
 
GTime ev_attachment_get_creation_date (EvAttachment *attachment)
 
const gchar * ev_attachment_get_mime_type (EvAttachment *attachment)
 
gboolean ev_attachment_save (EvAttachment *attachment, GFile *file, GError **error)
 
static gboolean ev_attachment_launch_app (EvAttachment *attachment, GdkScreen *screen, guint32 timestamp, GError **error)
 
gboolean ev_attachment_open (EvAttachment *attachment, GdkScreen *screen, guint32 timestamp, GError **error)
 

Macro Definition Documentation

#define EV_ATTACHMENT_GET_PRIVATE (   object)    (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_ATTACHMENT, EvAttachmentPrivate))

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

Enumeration Type Documentation

anonymous enum
Enumerator
PROP_0 
PROP_NAME 
PROP_DESCRIPTION 
PROP_MTIME 
PROP_CTIME 
PROP_SIZE 
PROP_DATA 

Definition at line 27 of file ev-attachment.c.

28 {
29  PROP_0,
30  PROP_NAME,
32  PROP_MTIME,
33  PROP_CTIME,
34  PROP_SIZE,
35  PROP_DATA
36 };

Function Documentation

static void ev_attachment_class_init ( EvAttachmentClass klass)
static

Definition at line 147 of file ev-attachment.c.

148 {
149  GObjectClass *g_object_class;
150 
151  g_object_class = G_OBJECT_CLASS (klass);
152 
153  g_object_class->set_property = ev_attachment_set_property;
154 
155  g_type_class_add_private (g_object_class, sizeof (EvAttachmentPrivate));
156 
157  /* Properties */
158  g_object_class_install_property (g_object_class,
159  PROP_NAME,
160  g_param_spec_string ("name",
161  "Name",
162  "The attachment name",
163  NULL,
164  G_PARAM_WRITABLE |
165  G_PARAM_CONSTRUCT_ONLY |
166  G_PARAM_STATIC_STRINGS));
167  g_object_class_install_property (g_object_class,
169  g_param_spec_string ("description",
170  "Description",
171  "The attachment description",
172  NULL,
173  G_PARAM_WRITABLE |
174  G_PARAM_CONSTRUCT_ONLY |
175  G_PARAM_STATIC_STRINGS));
176  g_object_class_install_property (g_object_class,
177  PROP_MTIME,
178  g_param_spec_ulong ("mtime",
179  "ModifiedTime",
180  "The attachment modification date",
181  0, G_MAXULONG, 0,
182  G_PARAM_WRITABLE |
183  G_PARAM_CONSTRUCT_ONLY |
184  G_PARAM_STATIC_STRINGS));
185  g_object_class_install_property (g_object_class,
186  PROP_CTIME,
187  g_param_spec_ulong ("ctime",
188  "CreationTime",
189  "The attachment creation date",
190  0, G_MAXULONG, 0,
191  G_PARAM_WRITABLE |
192  G_PARAM_CONSTRUCT_ONLY |
193  G_PARAM_STATIC_STRINGS));
194  g_object_class_install_property (g_object_class,
195  PROP_SIZE,
196  g_param_spec_uint ("size",
197  "Size",
198  "The attachment size",
199  0, G_MAXUINT, 0,
200  G_PARAM_WRITABLE |
201  G_PARAM_CONSTRUCT_ONLY |
202  G_PARAM_STATIC_STRINGS));
203  g_object_class_install_property (g_object_class,
204  PROP_DATA,
205  g_param_spec_pointer ("data",
206  "Data",
207  "The attachment data",
208  G_PARAM_WRITABLE |
209  G_PARAM_CONSTRUCT_ONLY |
210  G_PARAM_STATIC_STRINGS));
211 
212  g_object_class->finalize = ev_attachment_finalize;
213 }
GQuark ev_attachment_error_quark ( void  )

Definition at line 57 of file ev-attachment.c.

58 {
59  static GQuark error_quark = 0;
60 
61  if (error_quark == 0)
62  error_quark =
63  g_quark_from_static_string ("ev-attachment-error-quark");
64 
65  return error_quark;
66 }
static void ev_attachment_finalize ( GObject *  object)
static

Definition at line 69 of file ev-attachment.c.

70 {
71  EvAttachment *attachment = EV_ATTACHMENT (object);
72 
73  if (attachment->priv->name) {
74  g_free (attachment->priv->name);
75  attachment->priv->name = NULL;
76  }
77 
78  if (attachment->priv->description) {
79  g_free (attachment->priv->description);
80  attachment->priv->description = NULL;
81  }
82 
83  if (attachment->priv->data) {
84  g_free (attachment->priv->data);
85  attachment->priv->data = NULL;
86  }
87 
88  if (attachment->priv->mime_type) {
89  g_free (attachment->priv->mime_type);
90  attachment->priv->mime_type = NULL;
91  }
92 
93  if (attachment->priv->app) {
94  g_object_unref (attachment->priv->app);
95  attachment->priv->app = NULL;
96  }
97 
98  if (attachment->priv->tmp_file) {
99  ev_tmp_file_unlink (attachment->priv->tmp_file);
100  g_object_unref (attachment->priv->tmp_file);
101  attachment->priv->tmp_file = NULL;
102  }
103 
104  G_OBJECT_CLASS (ev_attachment_parent_class)->finalize (object);
105 }

+ Here is the caller graph for this function:

GTime ev_attachment_get_creation_date ( EvAttachment attachment)

Definition at line 275 of file ev-attachment.c.

276 {
277  g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), 0);
278 
279  return attachment->priv->ctime;
280 }
const gchar* ev_attachment_get_description ( EvAttachment attachment)

Definition at line 259 of file ev-attachment.c.

260 {
261  g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), NULL);
262 
263  return attachment->priv->description;
264 }
const gchar* ev_attachment_get_mime_type ( EvAttachment attachment)

Definition at line 283 of file ev-attachment.c.

284 {
285  g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), NULL);
286 
287  return attachment->priv->mime_type;
288 }

+ Here is the caller graph for this function:

GTime ev_attachment_get_modification_date ( EvAttachment attachment)

Definition at line 267 of file ev-attachment.c.

268 {
269  g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), 0);
270 
271  return attachment->priv->mtime;
272 }
const gchar* ev_attachment_get_name ( EvAttachment attachment)

Definition at line 251 of file ev-attachment.c.

252 {
253  g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), NULL);
254 
255  return attachment->priv->name;
256 }

+ Here is the caller graph for this function:

static void ev_attachment_init ( EvAttachment attachment)
static

Definition at line 216 of file ev-attachment.c.

217 {
218  attachment->priv = EV_ATTACHMENT_GET_PRIVATE (attachment);
219 
220  attachment->priv->name = NULL;
221  attachment->priv->description = NULL;
222  attachment->priv->data = NULL;
223  attachment->priv->mime_type = NULL;
224 
225  attachment->priv->tmp_file = NULL;
226 }
static gboolean ev_attachment_launch_app ( EvAttachment attachment,
GdkScreen *  screen,
guint32  timestamp,
GError **  error 
)
static

Definition at line 349 of file ev-attachment.c.

353 {
354  gboolean result;
355  GList *files = NULL;
356  GdkAppLaunchContext *context;
357  GdkDisplay *display;
358  GError *ioerror = NULL;
359 
360  g_assert (G_IS_FILE (attachment->priv->tmp_file));
361  g_assert (G_IS_APP_INFO (attachment->priv->app));
362 
363  files = g_list_prepend (files, attachment->priv->tmp_file);
364 
365  display = screen ? gdk_screen_get_display (screen) : gdk_display_get_default ();
366  context = gdk_display_get_app_launch_context (display);
367  gdk_app_launch_context_set_screen (context, screen);
368  gdk_app_launch_context_set_timestamp (context, timestamp);
369 
370  result = g_app_info_launch (attachment->priv->app, files,
371  G_APP_LAUNCH_CONTEXT (context),
372  &ioerror);
373  g_object_unref (context);
374 
375  if (!result) {
376  g_set_error (error,
378  (gint) result,
379  _("Couldn’t open attachment “%s”: %s"),
380  attachment->priv->name,
381  ioerror->message);
382 
383  g_list_free (files);
384  g_error_free (ioerror);
385 
386  return FALSE;
387  }
388 
389  g_list_free (files);
390 
391  return TRUE;
392 }

+ Here is the caller graph for this function:

EvAttachment* ev_attachment_new ( const gchar *  name,
const gchar *  description,
GTime  mtime,
GTime  ctime,
gsize  size,
gpointer  data 
)

Definition at line 229 of file ev-attachment.c.

235 {
236  EvAttachment *attachment;
237 
238  attachment = g_object_new (EV_TYPE_ATTACHMENT,
239  "name", name,
240  "description", description,
241  "mtime", mtime,
242  "ctime", ctime,
243  "size", size,
244  "data", data,
245  NULL);
246 
247  return attachment;
248 }

+ Here is the caller graph for this function:

gboolean ev_attachment_open ( EvAttachment attachment,
GdkScreen *  screen,
guint32  timestamp,
GError **  error 
)

Definition at line 395 of file ev-attachment.c.

399 {
400  GAppInfo *app_info;
401  gboolean retval = FALSE;
402 
403  g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), FALSE);
404 
405  if (!attachment->priv->app) {
406  app_info = g_app_info_get_default_for_type (attachment->priv->mime_type, FALSE);
407  attachment->priv->app = app_info;
408  }
409 
410  if (!attachment->priv->app) {
411  g_set_error (error,
413  0,
414  _("Couldn’t open attachment “%s”"),
415  attachment->priv->name);
416 
417  return FALSE;
418  }
419 
420  if (attachment->priv->tmp_file) {
421  retval = ev_attachment_launch_app (attachment, screen,
422  timestamp, error);
423  } else {
424  char *basename;
425  char *template;
426  GFile *file;
427 
428  /* FIXMEchpe: convert to filename encoding first! */
429  basename = g_path_get_basename (ev_attachment_get_name (attachment));
430  template = g_strdup_printf ("%s.XXXXXX", basename);
431  file = ev_mkstemp_file (template, error);
432  g_free (template);
433  g_free (basename);
434 
435  if (file != NULL && ev_attachment_save (attachment, file, error)) {
436  if (attachment->priv->tmp_file)
437  g_object_unref (attachment->priv->tmp_file);
438  attachment->priv->tmp_file = g_object_ref (file);
439 
440  retval = ev_attachment_launch_app (attachment, screen,
441  timestamp, error);
442  }
443 
444  g_object_unref (file);
445  }
446 
447  return retval;
448 }

+ Here is the caller graph for this function:

gboolean ev_attachment_save ( EvAttachment attachment,
GFile *  file,
GError **  error 
)

Definition at line 291 of file ev-attachment.c.

294 {
295  GFileOutputStream *output_stream;
296  GError *ioerror = NULL;
297  gssize written_bytes;
298 
299  g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), FALSE);
300  g_return_val_if_fail (G_IS_FILE (file), FALSE);
301 
302  output_stream = g_file_replace (file, NULL, FALSE, 0, NULL, &ioerror);
303  if (output_stream == NULL) {
304  char *uri;
305 
306  uri = g_file_get_uri (file);
307  g_set_error (error,
309  ioerror->code,
310  _("Couldn’t save attachment “%s”: %s"),
311  uri,
312  ioerror->message);
313 
314  g_error_free (ioerror);
315  g_free (uri);
316 
317  return FALSE;
318  }
319 
320  written_bytes = g_output_stream_write (G_OUTPUT_STREAM (output_stream),
321  attachment->priv->data,
322  attachment->priv->size,
323  NULL, &ioerror);
324  if (written_bytes == -1) {
325  char *uri;
326 
327  uri = g_file_get_uri (file);
328  g_set_error (error,
330  ioerror->code,
331  _("Couldn’t save attachment “%s”: %s"),
332  uri,
333  ioerror->message);
334 
335  g_output_stream_close (G_OUTPUT_STREAM (output_stream), NULL, NULL);
336  g_error_free (ioerror);
337  g_free (uri);
338 
339  return FALSE;
340  }
341 
342  g_output_stream_close (G_OUTPUT_STREAM (output_stream), NULL, NULL);
343 
344  return TRUE;
345 
346 }

+ Here is the caller graph for this function:

static void ev_attachment_set_property ( GObject *  object,
guint  prop_id,
const GValue *  value,
GParamSpec *  param_spec 
)
static

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

112 {
113  EvAttachment *attachment = EV_ATTACHMENT (object);
114 
115  switch (prop_id) {
116  case PROP_NAME:
117  attachment->priv->name = g_value_dup_string (value);
118  break;
119  case PROP_DESCRIPTION:
120  attachment->priv->description = g_value_dup_string (value);
121  break;
122  case PROP_MTIME:
123  attachment->priv->mtime = g_value_get_ulong (value);
124  break;
125  case PROP_CTIME:
126  attachment->priv->ctime = g_value_get_ulong (value);
127  break;
128  case PROP_SIZE:
129  attachment->priv->size = g_value_get_uint (value);
130  break;
131  case PROP_DATA:
132  attachment->priv->data = g_value_get_pointer (value);
133  attachment->priv->mime_type = g_content_type_guess (attachment->priv->name,
134  (guchar *) attachment->priv->data,
135  attachment->priv->size,
136  NULL);
137  break;
138  default:
139  G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
140  prop_id,
141  param_spec);
142  break;
143  }
144 }

+ Here is the caller graph for this function: