40 #define EV_METADATA_NAMESPACE "metadata::evince"
47 if (metadata->
items) {
48 g_hash_table_destroy (metadata->
items);
49 metadata->
items = NULL;
53 g_object_unref (metadata->
file);
54 metadata->
file = NULL;
57 G_OBJECT_CLASS (ev_metadata_parent_class)->finalize (
object);
63 metadata->
items = g_hash_table_new_full (g_str_hash,
72 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
85 info = g_file_query_info (metadata->
file,
"metadata::*", 0, NULL, &error);
87 g_warning (
"%s", error->message);
93 if (!g_file_info_has_namespace (info,
"metadata")) {
94 g_object_unref (info);
99 attrs = g_file_info_list_attributes (info,
"metadata");
100 for (i = 0; attrs[i]; i++) {
101 GFileAttributeType type;
108 if (!g_file_info_get_attribute_data (info, attrs[i],
109 &type, &value, NULL)) {
115 if (type == G_FILE_ATTRIBUTE_TYPE_STRING) {
116 g_hash_table_insert (metadata->
items,
122 g_object_unref (info);
130 g_return_val_if_fail (G_IS_FILE (file), NULL);
134 metadata->
file = g_object_ref (file);
144 return g_hash_table_size (metadata->
items) == 0;
154 v = g_hash_table_lookup (metadata->
items, key);
164 GAsyncResult *result,
167 GError *error = NULL;
169 if (!g_file_set_attributes_finish (G_FILE (file), result, NULL, &error)) {
170 g_warning (
"%s", error->message);
171 g_error_free (error);
183 g_hash_table_insert (metadata->
items, g_strdup (key), g_strdup (value));
187 info = g_file_info_new ();
191 g_file_info_set_attribute_string (info, gio_key, value);
193 g_file_info_set_attribute (info, gio_key,
194 G_FILE_ATTRIBUTE_TYPE_INVALID,
199 g_file_set_attributes_async (metadata->
file,
206 g_object_unref (info);
223 int_value = g_ascii_strtoull (string_value, &endptr, 0);
224 if (int_value == 0 && string_value == endptr)
236 gchar string_value[32];
238 g_snprintf (string_value,
sizeof (string_value),
"%d", value);
250 gdouble double_value;
255 double_value = g_ascii_strtod (string_value, &endptr);
256 if (double_value == 0. && string_value == endptr)
259 *value = double_value;
268 gchar string_value[G_ASCII_DTOSTR_BUF_SIZE];
270 g_ascii_dtostr (string_value, G_ASCII_DTOSTR_BUF_SIZE, value);
301 return g_hash_table_lookup (metadata->
items, key) != NULL;
307 GFileAttributeInfoList *namespaces;
309 gboolean retval =
FALSE;
311 namespaces = g_file_query_writable_namespaces (file, NULL, NULL);
315 for (i = 0; i < namespaces->n_infos; i++) {
316 if (strcmp (namespaces->infos[i].name,
"metadata") == 0) {
322 g_file_attribute_info_list_unref (namespaces);