/** * gedit_document_set_metadata: * @doc: a #GeditDocument * @first_key: name of the first key to set * @...: (allow-none): value for the first key, followed optionally by more key/value pairs, * followed by %NULL. * * Sets metadata on a document. */ void gedit_document_set_metadata (GeditDocument *doc, const gchar *first_key, ...) { const gchar *key; const gchar *value; va_list var_args; GFileInfo *info; GFile *location; g_return_if_fail (GEDIT_IS_DOCUMENT (doc)); g_return_if_fail (first_key != NULL); info = g_file_info_new (); va_start (var_args, first_key); for (key = first_key; key; key = va_arg (var_args, const gchar *)) { value = va_arg (var_args, const gchar *); if (value != NULL) { g_file_info_set_attribute_string (info, key, value); } else { /* Unset the key */ g_file_info_remove_attribute (info, key); } } va_end (var_args); if (doc->priv->metadata_info != NULL) { g_file_info_copy_into (info, doc->priv->metadata_info); } location = gtk_source_file_get_location (doc->priv->file); if (location != NULL) { g_file_set_attributes_async (location, info, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, NULL, (GAsyncReadyCallback) set_attributes_cb, NULL); } g_object_unref (info); }
static void gth_metadata_provider_comment_read (GthMetadataProvider *self, GthFileData *file_data, const char *attributes, GCancellable *cancellable) { GthComment *comment; const char *value; GPtrArray *categories; char *comment_time; comment = gth_comment_new_for_file (file_data->file, cancellable, NULL); g_file_info_set_attribute_boolean (file_data->info, "comment::no-comment-file", (comment == NULL)); if (comment == NULL) return; value = gth_comment_get_note (comment); if (value != NULL) g_file_info_set_attribute_string (file_data->info, "comment::note", value); value = gth_comment_get_caption (comment); if (value != NULL) g_file_info_set_attribute_string (file_data->info, "comment::caption", value); value = gth_comment_get_place (comment); if (value != NULL) g_file_info_set_attribute_string (file_data->info, "comment::place", value); if (gth_comment_get_rating (comment) > 0) g_file_info_set_attribute_int32 (file_data->info, "comment::rating", gth_comment_get_rating (comment)); else g_file_info_remove_attribute (file_data->info, "comment::rating"); categories = gth_comment_get_categories (comment); if (categories->len > 0) { GthStringList *list; GthMetadata *metadata; list = gth_string_list_new_from_ptr_array (categories); metadata = gth_metadata_new_for_string_list (list); g_file_info_set_attribute_object (file_data->info, "comment::categories", G_OBJECT (metadata)); g_object_unref (metadata); g_object_unref (list); } else g_file_info_remove_attribute (file_data->info, "comment::categories"); comment_time = gth_comment_get_time_as_exif_format (comment); if (comment_time != NULL) { GTimeVal time_; char *formatted; if (_g_time_val_from_exif_date (comment_time, &time_)) formatted = _g_time_val_strftime (&time_, "%x %X"); else formatted = g_strdup (comment_time); set_attribute_from_string (file_data->info, "comment::time", comment_time, formatted); g_free (formatted); g_free (comment_time); } else g_file_info_remove_attribute (file_data->info, "comment::time"); gth_comment_update_general_attributes (file_data); g_object_unref (comment); }