예제 #1
0
파일: main.c 프로젝트: GNOME/gthumb
static void
comments__read_metadata_ready_cb (GList      *file_list,
				  const char *attributes)
{
	GSettings *settings;
	gboolean   store_metadata_in_files;
	GList     *scan;
	gboolean   synchronize;

	settings = g_settings_new (GTHUMB_GENERAL_SCHEMA);
	store_metadata_in_files = g_settings_get_boolean (settings, PREF_GENERAL_STORE_METADATA_IN_FILES);
	g_object_unref (settings);

	if (! store_metadata_in_files) {
		/* if PREF_GENERAL_STORE_METADATA_IN_FILES is false, avoid to
		 * synchronize the .comment metadata because the embedded
		 * metadata is likely to be out-of-date.
		 * Give priority to the .comment metadata which, if present,
		 * is the most up-to-date. */

		gboolean can_read_embedded_attributes;

		can_read_embedded_attributes = gth_main_extension_is_active ("exiv2_tools");

		for (scan = file_list; scan; scan = scan->next) {
			GthFileData *file_data = scan->data;

			/* If PREF_GENERAL_STORE_METADATA_IN_FILES is false and
			 * there is no comment file then we are reading
			 * the image metadata for the first time, in this
			 * case update the .comment metadata with the
			 * embedded metadata. */
			if (g_file_info_get_attribute_boolean (file_data->info, "comment::no-comment-file")) {
				if (can_read_embedded_attributes) {
					exiv2_update_general_attributes (file_data->info);
					gth_comment_update_from_general_attributes (file_data);
				}
			}
			else
				gth_comment_update_general_attributes ((GthFileData *) scan->data);
		}
	}
	else {
		/* if PREF_GENERAL_STORE_METADATA_IN_FILES is true, update the .comment
		 * metadata with the embedded metadata.
		 */

		settings = g_settings_new (GTHUMB_COMMENTS_SCHEMA);
		synchronize = g_settings_get_boolean (settings, PREF_COMMENTS_SYNCHRONIZE);
		g_object_unref (settings);

		if (! synchronize)
			return;

		for (scan = file_list; scan; scan = scan->next)
			gth_comment_update_from_general_attributes ((GthFileData *) scan->data);
	}
}
예제 #2
0
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);
}