static void vfs_file_set_metadata_as_list (NautilusFile *file, const char *key, char **value) { GFile *location; GFileInfo *info; char *gio_key; info = g_file_info_new (); gio_key = g_strconcat ("metadata::", key, NULL); g_file_info_set_attribute_stringv (info, gio_key, value); g_free (gio_key); location = nautilus_file_get_location (file); g_file_set_attributes_async (location, info, 0, G_PRIORITY_DEFAULT, NULL, set_metadata_callback, nautilus_file_ref (file)); g_object_unref (info); g_object_unref (location); }
gboolean nautilus_keyfile_metadata_update_from_keyfile (NautilusFile *file, const char *keyfile_filename, const gchar *name) { gchar **keys, **values; const gchar *actual_values[2]; const gchar *key, *value; gchar *gio_key; gsize length, values_length; GKeyFile *keyfile; GFileInfo *info; gint idx; gboolean res; keyfile = get_keyfile (keyfile_filename); keys = g_key_file_get_keys (keyfile, name, &length, NULL); if (keys == NULL) { return FALSE; } info = g_file_info_new (); for (idx = 0; idx < length; idx++) { key = keys[idx]; values = g_key_file_get_string_list (keyfile, name, key, &values_length, NULL); gio_key = g_strconcat ("metadata::", key, NULL); if (values_length < 1) { continue; } else if (values_length == 1) { g_file_info_set_attribute_string (info, gio_key, values[0]); } else if (values_length == 2) { /* deal with the fact that single-length strv are stored * with an additional terminator in the keyfile string, to differentiate * them from the regular string case. */ value = values[1]; if (g_strcmp0 (value, STRV_TERMINATOR) == 0) { /* if the 2nd value is the terminator, remove it */ actual_values[0] = values[0]; actual_values[1] = NULL; g_file_info_set_attribute_stringv (info, gio_key, (gchar **) actual_values); } else { /* otherwise, set it as a regular strv */ g_file_info_set_attribute_stringv (info, gio_key, values); } } else { g_file_info_set_attribute_stringv (info, gio_key, values); } g_free (gio_key); g_strfreev (values); } res = nautilus_file_update_metadata_from_info (file, info); g_strfreev (keys); g_object_unref (info); return res; }
static void parse_xml_node (GFile *file, xmlNodePtr filenode) { xmlNodePtr node; xmlAttrPtr attr; xmlChar *property; const char *new_key; GHashTable *list_keys; GList *keys, *l; GHashTableIter iter; GFileInfo *info; int i; char **strv; GError *error; info = g_file_info_new (); for (attr = filenode->properties; attr != NULL; attr = attr->next) { if (strcmp ((char *)attr->name, "name") == 0 || strcmp ((char *)attr->name, "timestamp") == 0) { continue; } new_key = convert_key_name (attr->name); if (new_key) { property = xmlGetProp (filenode, attr->name); if (property) { g_file_info_set_attribute_string (info, new_key, property); xmlFree (property); } } } list_keys = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); for (node = filenode->children; node != NULL; node = node->next) { for (attr = node->properties; attr != NULL; attr = attr->next) { new_key = convert_key_name (node->name); if (new_key) { property = xmlGetProp (node, attr->name); if (property) { keys = g_hash_table_lookup (list_keys, new_key); keys = g_list_append (keys, property); g_hash_table_replace (list_keys, (char *)new_key, keys); } } } } g_hash_table_iter_init (&iter, list_keys); while (g_hash_table_iter_next (&iter, (void **)&new_key, (void **)&keys)) { strv = g_new0 (char *, g_list_length (keys) + 1); for (l = keys, i = 0; l != NULL; l = l->next, i++) { strv[i] = l->data; } g_file_info_set_attribute_stringv (info, new_key, strv); g_free (strv); g_list_foreach (keys, (GFunc)xmlFree, NULL); g_list_free (keys); } g_hash_table_destroy (list_keys); if (info) { error = NULL; if (!g_file_set_attributes_from_info (file, info, 0, NULL, &error)) { char *uri; uri = g_file_get_uri (file); if (!quiet) { g_print ("error setting info for %s: %s\n", uri, error->message); } g_free (uri); g_error_free (error); } g_object_unref (info); } }
GFileInfo * gvfs_file_info_demarshal (char *data, gsize size) { guint32 num_attrs, i; GInputStream *memstream; GDataInputStream *in; GFileInfo *info; char *attr, *str, **strv; GFileAttributeType type; GFileAttributeStatus status; GObject *obj; int objtype; memstream = g_memory_input_stream_new_from_data (data, size, NULL); in = g_data_input_stream_new (memstream); g_object_unref (memstream); info = g_file_info_new (); num_attrs = g_data_input_stream_read_uint32 (in, NULL, NULL); for (i = 0; i < num_attrs; i++) { attr = read_string (in); type = g_data_input_stream_read_byte (in, NULL, NULL); status = g_data_input_stream_read_byte (in, NULL, NULL); switch (type) { case G_FILE_ATTRIBUTE_TYPE_STRING: str = read_string (in); g_file_info_set_attribute_string (info, attr, str); g_free (str); break; case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: str = read_string (in); g_file_info_set_attribute_byte_string (info, attr, str); g_free (str); break; case G_FILE_ATTRIBUTE_TYPE_STRINGV: strv = read_stringv (in); g_file_info_set_attribute_stringv (info, attr, strv); g_strfreev (strv); break; case G_FILE_ATTRIBUTE_TYPE_BOOLEAN: g_file_info_set_attribute_boolean (info, attr, g_data_input_stream_read_byte (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_UINT32: g_file_info_set_attribute_uint32 (info, attr, g_data_input_stream_read_uint32 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_INT32: g_file_info_set_attribute_int32 (info, attr, g_data_input_stream_read_int32 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_UINT64: g_file_info_set_attribute_uint64 (info, attr, g_data_input_stream_read_uint64 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_INT64: g_file_info_set_attribute_int64 (info, attr, g_data_input_stream_read_int64 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_OBJECT: objtype = g_data_input_stream_read_byte (in, NULL, NULL); obj = NULL; if (objtype == 1) { char *icon_str; icon_str = read_string (in); obj = (GObject *)g_icon_new_for_string (icon_str, NULL); g_free (icon_str); } else { g_warning ("Unsupported GFileInfo object type %d\n", objtype); g_free (attr); goto out; } g_file_info_set_attribute_object (info, attr, obj); if (obj) g_object_unref (obj); break; case G_FILE_ATTRIBUTE_TYPE_INVALID: break; default: g_warning ("Unsupported GFileInfo attribute type %d\n", type); g_free (attr); goto out; break; } g_file_info_set_attribute_status (info, attr, status); g_free (attr); } out: g_object_unref (in); return info; }
void ss__gth_catalog_write_metadata (GthCatalog *catalog, GthFileData *file_data) { if (g_value_hash_is_set (catalog->attributes, "slideshow::personalize")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::personalize", g_value_hash_get_boolean (catalog->attributes, "slideshow::personalize")); g_file_info_set_attribute_status (file_data->info, "slideshow::personalize", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::automatic")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::automatic", g_value_hash_get_boolean (catalog->attributes, "slideshow::automatic")); g_file_info_set_attribute_status (file_data->info, "slideshow::automatic", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::wrap-around")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::wrap-around", g_value_hash_get_boolean (catalog->attributes, "slideshow::wrap-around")); g_file_info_set_attribute_status (file_data->info, "slideshow::wrap-around", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::random-order")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::random-order", g_value_hash_get_boolean (catalog->attributes, "slideshow::random-order")); g_file_info_set_attribute_status (file_data->info, "slideshow::random-order", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::delay")) { g_file_info_set_attribute_int32 (file_data->info, "slideshow::delay", g_value_hash_get_int (catalog->attributes, "slideshow::delay")); g_file_info_set_attribute_status (file_data->info, "slideshow::delay", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::transition")) { g_file_info_set_attribute_string (file_data->info, "slideshow::transition", g_value_hash_get_string (catalog->attributes, "slideshow::transition")); g_file_info_set_attribute_status (file_data->info, "slideshow::transition", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::playlist")) { g_file_info_set_attribute_stringv (file_data->info, "slideshow::playlist", g_value_hash_get_stringv (catalog->attributes, "slideshow::playlist")); g_file_info_set_attribute_status (file_data->info, "slideshow::playlist", G_FILE_ATTRIBUTE_STATUS_SET); } }