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-metadata.c File Reference
#include <gio/gio.h>
#include <string.h>
#include "ev-metadata.h"
#include "ev-file-helpers.h"
+ Include dependency graph for ev-metadata.c:

Go to the source code of this file.

Data Structures

struct  _EvMetadata
 
struct  _EvMetadataClass
 

Macros

#define EV_METADATA_NAMESPACE   "metadata::evince"
 

Functions

static void ev_metadata_finalize (GObject *object)
 
static void ev_metadata_init (EvMetadata *metadata)
 
static void ev_metadata_class_init (EvMetadataClass *klass)
 
static void ev_metadata_load (EvMetadata *metadata)
 
EvMetadataev_metadata_new (GFile *file)
 
gboolean ev_metadata_is_empty (EvMetadata *metadata)
 
gboolean ev_metadata_get_string (EvMetadata *metadata, const gchar *key, gchar **value)
 
static void metadata_set_callback (GObject *file, GAsyncResult *result, EvMetadata *metadata)
 
gboolean ev_metadata_set_string (EvMetadata *metadata, const gchar *key, const gchar *value)
 
gboolean ev_metadata_get_int (EvMetadata *metadata, const gchar *key, gint *value)
 
gboolean ev_metadata_set_int (EvMetadata *metadata, const gchar *key, gint value)
 
gboolean ev_metadata_get_double (EvMetadata *metadata, const gchar *key, gdouble *value)
 
gboolean ev_metadata_set_double (EvMetadata *metadata, const gchar *key, gdouble value)
 
gboolean ev_metadata_get_boolean (EvMetadata *metadata, const gchar *key, gboolean *value)
 
gboolean ev_metadata_set_boolean (EvMetadata *metadata, const gchar *key, gboolean value)
 
gboolean ev_metadata_has_key (EvMetadata *metadata, const gchar *key)
 
gboolean ev_is_metadata_supported_for_file (GFile *file)
 

Macro Definition Documentation

#define EV_METADATA_NAMESPACE   "metadata::evince"

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

Function Documentation

gboolean ev_is_metadata_supported_for_file ( GFile *  file)

Definition at line 305 of file ev-metadata.c.

306 {
307  GFileAttributeInfoList *namespaces;
308  gint i;
309  gboolean retval = FALSE;
310 
311  namespaces = g_file_query_writable_namespaces (file, NULL, NULL);
312  if (!namespaces)
313  return retval;
314 
315  for (i = 0; i < namespaces->n_infos; i++) {
316  if (strcmp (namespaces->infos[i].name, "metadata") == 0) {
317  retval = TRUE;
318  break;
319  }
320  }
321 
322  g_file_attribute_info_list_unref (namespaces);
323 
324  return retval;
325 }

+ Here is the caller graph for this function:

static void ev_metadata_class_init ( EvMetadataClass klass)
static

Definition at line 70 of file ev-metadata.c.

71 {
72  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
73 
74  gobject_class->finalize = ev_metadata_finalize;
75 }
static void ev_metadata_finalize ( GObject *  object)
static

Definition at line 43 of file ev-metadata.c.

44 {
45  EvMetadata *metadata = EV_METADATA (object);
46 
47  if (metadata->items) {
48  g_hash_table_destroy (metadata->items);
49  metadata->items = NULL;
50  }
51 
52  if (metadata->file) {
53  g_object_unref (metadata->file);
54  metadata->file = NULL;
55  }
56 
57  G_OBJECT_CLASS (ev_metadata_parent_class)->finalize (object);
58 }

+ Here is the caller graph for this function:

gboolean ev_metadata_get_boolean ( EvMetadata metadata,
const gchar *  key,
gboolean *  value 
)

Definition at line 276 of file ev-metadata.c.

279 {
280  gint int_value;
281 
282  if (!ev_metadata_get_int (metadata, key, &int_value))
283  return FALSE;
284 
285  *value = int_value;
286  return TRUE;
287 }

+ Here is the caller graph for this function:

gboolean ev_metadata_get_double ( EvMetadata metadata,
const gchar *  key,
gdouble *  value 
)

Definition at line 244 of file ev-metadata.c.

247 {
248  gchar *string_value;
249  gchar *endptr;
250  gdouble double_value;
251 
252  if (!ev_metadata_get_string (metadata, key, &string_value))
253  return FALSE;
254 
255  double_value = g_ascii_strtod (string_value, &endptr);
256  if (double_value == 0. && string_value == endptr)
257  return FALSE;
258 
259  *value = double_value;
260  return TRUE;
261 }

+ Here is the caller graph for this function:

gboolean ev_metadata_get_int ( EvMetadata metadata,
const gchar *  key,
gint *  value 
)

Definition at line 212 of file ev-metadata.c.

215 {
216  gchar *string_value;
217  gchar *endptr;
218  gint int_value;
219 
220  if (!ev_metadata_get_string (metadata, key, &string_value))
221  return FALSE;
222 
223  int_value = g_ascii_strtoull (string_value, &endptr, 0);
224  if (int_value == 0 && string_value == endptr)
225  return FALSE;
226 
227  *value = int_value;
228  return TRUE;
229 }

+ Here is the caller graph for this function:

gboolean ev_metadata_get_string ( EvMetadata metadata,
const gchar *  key,
gchar **  value 
)

Definition at line 148 of file ev-metadata.c.

151 {
152  gchar *v;
153 
154  v = g_hash_table_lookup (metadata->items, key);
155  if (!v)
156  return FALSE;
157 
158  *value = v;
159  return TRUE;
160 }

+ Here is the caller graph for this function:

gboolean ev_metadata_has_key ( EvMetadata metadata,
const gchar *  key 
)

Definition at line 298 of file ev-metadata.c.

300 {
301  return g_hash_table_lookup (metadata->items, key) != NULL;
302 }

+ Here is the caller graph for this function:

static void ev_metadata_init ( EvMetadata metadata)
static

Definition at line 61 of file ev-metadata.c.

62 {
63  metadata->items = g_hash_table_new_full (g_str_hash,
64  g_str_equal,
65  g_free,
66  g_free);
67 }
gboolean ev_metadata_is_empty ( EvMetadata metadata)

Definition at line 142 of file ev-metadata.c.

143 {
144  return g_hash_table_size (metadata->items) == 0;
145 }
static void ev_metadata_load ( EvMetadata metadata)
static

Definition at line 78 of file ev-metadata.c.

79 {
80  GFileInfo *info;
81  gchar **attrs;
82  gint i;
83  GError *error = NULL;
84 
85  info = g_file_query_info (metadata->file, "metadata::*", 0, NULL, &error);
86  if (!info) {
87  g_warning ("%s", error->message);
88  g_error_free (error);
89 
90  return;
91  }
92 
93  if (!g_file_info_has_namespace (info, "metadata")) {
94  g_object_unref (info);
95 
96  return;
97  }
98 
99  attrs = g_file_info_list_attributes (info, "metadata");
100  for (i = 0; attrs[i]; i++) {
101  GFileAttributeType type;
102  gpointer value;
103  const gchar *key;
104 
105  if (!g_str_has_prefix (attrs[i], EV_METADATA_NAMESPACE))
106  continue;
107 
108  if (!g_file_info_get_attribute_data (info, attrs[i],
109  &type, &value, NULL)) {
110  continue;
111  }
112 
113  key = attrs[i] + strlen (EV_METADATA_NAMESPACE"::");
114 
115  if (type == G_FILE_ATTRIBUTE_TYPE_STRING) {
116  g_hash_table_insert (metadata->items,
117  g_strdup (key),
118  g_strdup (value));
119  }
120  }
121  g_strfreev (attrs);
122  g_object_unref (info);
123 }

+ Here is the caller graph for this function:

EvMetadata* ev_metadata_new ( GFile *  file)

Definition at line 126 of file ev-metadata.c.

127 {
128  EvMetadata *metadata;
129 
130  g_return_val_if_fail (G_IS_FILE (file), NULL);
131 
132  metadata = EV_METADATA (g_object_new (EV_TYPE_METADATA, NULL));
133  if (!ev_file_is_temp (file)) {
134  metadata->file = g_object_ref (file);
135  ev_metadata_load (metadata);
136  }
137 
138  return metadata;
139 }

+ Here is the caller graph for this function:

gboolean ev_metadata_set_boolean ( EvMetadata metadata,
const gchar *  key,
gboolean  value 
)

Definition at line 290 of file ev-metadata.c.

293 {
294  return ev_metadata_set_string (metadata, key, value ? "1" : "0");
295 }

+ Here is the caller graph for this function:

gboolean ev_metadata_set_double ( EvMetadata metadata,
const gchar *  key,
gdouble  value 
)

Definition at line 264 of file ev-metadata.c.

267 {
268  gchar string_value[G_ASCII_DTOSTR_BUF_SIZE];
269 
270  g_ascii_dtostr (string_value, G_ASCII_DTOSTR_BUF_SIZE, value);
271 
272  return ev_metadata_set_string (metadata, key, string_value);
273 }

+ Here is the caller graph for this function:

gboolean ev_metadata_set_int ( EvMetadata metadata,
const gchar *  key,
gint  value 
)

Definition at line 232 of file ev-metadata.c.

235 {
236  gchar string_value[32];
237 
238  g_snprintf (string_value, sizeof (string_value), "%d", value);
239 
240  return ev_metadata_set_string (metadata, key, string_value);
241 }

+ Here is the caller graph for this function:

gboolean ev_metadata_set_string ( EvMetadata metadata,
const gchar *  key,
const gchar *  value 
)

Definition at line 176 of file ev-metadata.c.

179 {
180  GFileInfo *info;
181  gchar *gio_key;
182 
183  g_hash_table_insert (metadata->items, g_strdup (key), g_strdup (value));
184  if (!metadata->file)
185  return TRUE;
186 
187  info = g_file_info_new ();
188 
189  gio_key = g_strconcat (EV_METADATA_NAMESPACE"::", key, NULL);
190  if (value) {
191  g_file_info_set_attribute_string (info, gio_key, value);
192  } else {
193  g_file_info_set_attribute (info, gio_key,
194  G_FILE_ATTRIBUTE_TYPE_INVALID,
195  NULL);
196  }
197  g_free (gio_key);
198 
199  g_file_set_attributes_async (metadata->file,
200  info,
201  0,
202  G_PRIORITY_DEFAULT,
203  NULL,
204  (GAsyncReadyCallback)metadata_set_callback,
205  metadata);
206  g_object_unref (info);
207 
208  return TRUE;
209 }

+ Here is the caller graph for this function:

static void metadata_set_callback ( GObject *  file,
GAsyncResult *  result,
EvMetadata metadata 
)
static

Definition at line 163 of file ev-metadata.c.

166 {
167  GError *error = NULL;
168 
169  if (!g_file_set_attributes_finish (G_FILE (file), result, NULL, &error)) {
170  g_warning ("%s", error->message);
171  g_error_free (error);
172  }
173 }

+ Here is the caller graph for this function: