[gnome-photos] local-item: Use g_auto*
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] local-item: Use g_auto*
- Date: Fri, 8 Dec 2017 17:12:18 +0000 (UTC)
commit fc76790d6918a3144bb2dfb012f0657b2997e81f
Author: Debarshi Ray <debarshir gnome org>
Date: Sun Dec 3 15:07:46 2017 +0100
local-item: Use g_auto*
Some changes by Debarshi Ray.
https://bugzilla.gnome.org/show_bug.cgi?id=788174
src/photos-local-item.c | 158 ++++++++++++++++++++---------------------------
1 files changed, 68 insertions(+), 90 deletions(-)
---
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index a3cc3f3..654e404 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -78,7 +78,7 @@ photos_local_item_get_pipeline_path (PhotosLocalItem *self)
{
const gchar *data_dir;
const gchar *uri;
- gchar *md5;
+ g_autofree gchar *md5 = NULL;
gchar *path;
uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (self));
@@ -87,7 +87,6 @@ photos_local_item_get_pipeline_path (PhotosLocalItem *self)
path = g_build_filename (data_dir, PACKAGE_TARNAME, "local", md5, NULL);
- g_free (md5);
return path;
}
@@ -97,13 +96,12 @@ photos_local_item_create_pipeline_path (PhotosBaseItem *item)
{
PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (item);
gchar *path;
- gchar *pipeline_dir;
+ g_autofree gchar *pipeline_dir = NULL;
path = photos_local_item_get_pipeline_path (self);
pipeline_dir = g_path_get_dirname (path);
g_mkdir_with_parents (pipeline_dir, 0700);
- g_free (pipeline_dir);
return path;
}
@@ -112,13 +110,13 @@ static gboolean
photos_local_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
{
PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (item);
- GFile *file = NULL;
+ g_autoptr (GFile) file = NULL;
GQuark orientation;
gboolean ret_val = FALSE;
const gchar *mime_type;
const gchar *uri;
- gchar *pipeline_path = NULL;
- gchar *pipeline_uri = NULL;
+ g_autofree gchar *pipeline_path = NULL;
+ g_autofree gchar *pipeline_uri = NULL;
gint64 height;
gint64 mtime;
gint64 width;
@@ -148,9 +146,6 @@ photos_local_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancella
ret_val = TRUE;
out:
- g_clear_object (&file);
- g_free (pipeline_path);
- g_free (pipeline_uri);
return ret_val;
}
@@ -179,12 +174,12 @@ photos_local_item_get_source_widget (PhotosBaseItem *item)
}
else
{
- GFile *file;
- GFile *source_link;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) source_link = NULL;
GtkWidget *label;
const gchar *uri;
- gchar *source_path = NULL;
- gchar *source_uri = NULL;
+ g_autofree gchar *source_path = NULL;
+ g_autofree gchar *source_uri = NULL;
uri = photos_base_item_get_uri (item);
file = g_file_new_for_uri (uri);
@@ -198,11 +193,6 @@ photos_local_item_get_source_widget (PhotosBaseItem *item)
label = gtk_bin_get_child (GTK_BIN (source_widget));
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
-
- g_free (source_path);
- g_free (source_uri);
- g_object_unref (source_link);
- g_object_unref (file);
}
return source_widget;
@@ -217,21 +207,19 @@ photos_local_item_metadata_add_shared (PhotosBaseItem *item,
GCancellable *cancellable,
GError **error)
{
- GVariant *shared_variant = NULL;
- GVariantBuilder builder;
+ g_autoptr (GVariant) shared_variant = NULL;
const GVariantType *tuple_items[] = {G_VARIANT_TYPE_STRING, /* provider-type */
G_VARIANT_TYPE_STRING, /* account-identity */
G_VARIANT_TYPE_STRING}; /* shared-id */
- GVariantType *array_type = NULL;
- GVariantType *tuple_type = NULL;
- GExiv2Metadata *metadata = NULL;
+ g_autoptr (GVariantType) array_type = NULL;
+ g_autoptr (GVariantType) tuple_type = NULL;
+ GExiv2Metadata *metadata = NULL; /* TODO: Use g_autoptr */
gboolean ret_val = FALSE;
const gchar *mime_type;
const gchar *shared_tag = "Xmp.gnome.photos-shared";
const gchar *version_tag = "Xmp.gnome.photos-xmp-version";
- gchar *path = NULL;
- gchar *shared_string = NULL;
- gchar *tuple_type_format = NULL;
+ g_autofree gchar *path = NULL;
+ g_autofree gchar *tuple_type_format = NULL;
mime_type = photos_base_item_get_mime_type (item);
if (g_strcmp0 (mime_type, "image/png") != 0
@@ -262,45 +250,46 @@ photos_local_item_metadata_add_shared (PhotosBaseItem *item,
array_type = g_variant_type_new_array (tuple_type);
- g_variant_builder_init (&builder, array_type);
- g_variant_builder_add (&builder, tuple_type_format, provider_type, account_identity, shared_id);
+ {
+ g_auto (GVariantBuilder) builder = G_VARIANT_BUILDER_INIT (array_type);
+ g_autofree gchar *shared_string = NULL;
- shared_string = gexiv2_metadata_get_tag_string (metadata, shared_tag);
- if (shared_string != NULL)
- {
- GVariant *old_shared_variant = NULL;
- GVariant *child = NULL;
- GVariantIter iter;
-
- old_shared_variant = g_variant_parse (array_type, shared_string, NULL, NULL, error);
- if (old_shared_variant == NULL)
- {
- g_variant_builder_clear (&builder);
- goto out;
- }
-
- g_variant_iter_init (&iter, old_shared_variant);
- child = g_variant_iter_next_value (&iter);
- while (child != NULL)
- {
- g_variant_builder_add_value (&builder, child);
- g_variant_unref (child);
- child = g_variant_iter_next_value (&iter);
- }
-
- g_variant_unref (old_shared_variant);
- }
+ g_variant_builder_add (&builder, tuple_type_format, provider_type, account_identity, shared_id);
- shared_variant = g_variant_builder_end (&builder);
+ shared_string = gexiv2_metadata_get_tag_string (metadata, shared_tag);
+ if (shared_string != NULL)
+ {
+ g_autoptr (GVariant) old_shared_variant = NULL;
+ GVariant *child = NULL;
+ GVariantIter iter;
- g_free (shared_string);
- shared_string = g_variant_print (shared_variant, TRUE);
+ old_shared_variant = g_variant_parse (array_type, shared_string, NULL, NULL, error);
+ if (old_shared_variant == NULL)
+ goto out;
- if (!gexiv2_metadata_set_tag_string (metadata, shared_tag, shared_string))
- {
- g_set_error (error, PHOTOS_ERROR, 0, "Failed to update %s", shared_tag);
- goto out;
- }
+ g_variant_iter_init (&iter, old_shared_variant);
+ child = g_variant_iter_next_value (&iter);
+ while (child != NULL)
+ {
+ g_variant_builder_add_value (&builder, child);
+ g_variant_unref (child);
+ child = g_variant_iter_next_value (&iter);
+ }
+ }
+
+ shared_variant = g_variant_builder_end (&builder);
+ }
+
+ {
+ g_autofree gchar *shared_string = NULL;
+
+ shared_string = g_variant_print (shared_variant, TRUE);
+ if (!gexiv2_metadata_set_tag_string (metadata, shared_tag, shared_string))
+ {
+ g_set_error (error, PHOTOS_ERROR, 0, "Failed to update %s", shared_tag);
+ goto out;
+ }
+ }
if (!gexiv2_metadata_save_file (metadata, path, error))
goto out;
@@ -309,12 +298,6 @@ photos_local_item_metadata_add_shared (PhotosBaseItem *item,
out:
g_clear_object (&metadata);
- g_clear_pointer (&array_type, (GDestroyNotify) g_variant_type_free);
- g_clear_pointer (&tuple_type, (GDestroyNotify) g_variant_type_free);
- g_clear_pointer (&shared_variant, (GDestroyNotify) g_variant_unref);
- g_free (path);
- g_free (shared_string);
- g_free (tuple_type_format);
return ret_val;
}
@@ -322,31 +305,30 @@ photos_local_item_metadata_add_shared (PhotosBaseItem *item,
static void
photos_local_item_trash_finish (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
- GError *error;
GFile *file = G_FILE (source_object);
- error = NULL;
- g_file_trash_finish (file, res, &error);
- if (error != NULL)
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- {
- PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (user_data);
- const gchar *uri;
-
- uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (self));
- g_warning ("Unable to trash %s: %s", uri, error->message);
- }
-
- g_error_free (error);
- }
+ {
+ g_autoptr (GError) error = NULL;
+
+ if (!g_file_trash_finish (file, res, &error))
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ {
+ PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (user_data);
+ const gchar *uri;
+
+ uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (self));
+ g_warning ("Unable to trash %s: %s", uri, error->message);
+ }
+ }
+ }
}
static void
photos_local_item_trash (PhotosBaseItem *item)
{
- GFile *file;
+ g_autoptr (GFile) file = NULL;
const gchar *uri;
PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (item);
@@ -356,9 +338,6 @@ photos_local_item_trash (PhotosBaseItem *item)
uri = photos_base_item_get_uri (item);
file = g_file_new_for_uri (uri);
g_file_trash_async (file, G_PRIORITY_DEFAULT, self->cancellable, photos_local_item_trash_finish, self);
-
- g_object_unref (file);
-
}
@@ -366,7 +345,7 @@ static void
photos_local_item_constructed (GObject *object)
{
PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (object);
- GAppInfo *default_app = NULL;
+ g_autoptr (GAppInfo) default_app = NULL;
const gchar *mime_type;
G_OBJECT_CLASS (photos_local_item_parent_class)->constructed (object);
@@ -380,7 +359,6 @@ photos_local_item_constructed (GObject *object)
return;
photos_base_item_set_default_app (PHOTOS_BASE_ITEM (self), default_app);
- g_object_unref (default_app);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]