[gnome-photos] base-item: Make trash a virtual method and implement it for local items
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] base-item: Make trash a virtual method and implement it for local items
- Date: Thu, 24 Jul 2014 11:32:47 +0000 (UTC)
commit 7396428065feadbeb1d33ab25e5179fc8c748c38
Author: Pranav Kant <pranav913 gmail com>
Date: Mon Jul 21 16:50:37 2014 +0200
base-item: Make trash a virtual method and implement it for local items
One can use can_trash to find out whether a PhotosBaseItem sub-class
implements it or not. As a positive side-effect, can_trash is no longer
TRUE for remote collections.
https://bugzilla.gnome.org/show_bug.cgi?id=720222
src/photos-base-item.c | 9 ++++-----
src/photos-base-item.h | 2 ++
src/photos-local-item.c | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 5 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 5a900de..3121130 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -1,5 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Pranav Kant
* Copyright © 2012, 2013, 2014 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
@@ -1046,7 +1047,7 @@ photos_base_item_filterable_iface_init (PhotosFilterableInterface *iface)
gboolean
photos_base_item_can_trash (PhotosBaseItem *self)
{
- return self->priv->collection;
+ return PHOTOS_BASE_ITEM_GET_CLASS (self)->trash != NULL;
}
@@ -1376,13 +1377,11 @@ photos_base_item_set_favorite (PhotosBaseItem *self, gboolean favorite)
void
photos_base_item_trash (PhotosBaseItem *self)
{
- PhotosBaseItemPrivate *priv = self->priv;
PhotosDeleteItemJob *job;
- if (!priv->collection)
- return;
+ PHOTOS_BASE_ITEM_GET_CLASS (self)->trash (self);
- job = photos_delete_item_job_new (priv->id);
+ job = photos_delete_item_job_new (self->priv->id);
photos_delete_item_job_run (job, NULL, NULL);
g_object_unref (job);
}
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 65d1d44..ba6731c 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -1,5 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Pranav Kant
* Copyright © 2012, 2013, 2014 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
@@ -74,6 +75,7 @@ struct _PhotosBaseItemClass
GtkWidget *(*get_source_widget) (PhotosBaseItem *self);
void (*open) (PhotosBaseItem *self, GdkScreen *screen, guint32 timestamp);
void (*set_favorite) (PhotosBaseItem *self, gboolean favorite);
+ void (*trash) (PhotosBaseItem *self);
void (*update_type_description) (PhotosBaseItem *self);
/* signals */
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index 013c8b4..3af4b5d 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -1,5 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Pranav Kant
* Copyright © 2012, 2013, 2014 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
@@ -41,6 +42,28 @@ G_DEFINE_TYPE_WITH_CODE (PhotosLocalItem, photos_local_item, PHOTOS_TYPE_BASE_IT
0));
+static void
+photos_local_item_delete (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (user_data);
+ GError *error;
+ GFile *file = G_FILE (source_object);
+
+ error = NULL;
+ g_file_delete_finish (file, res, &error);
+ if (error != NULL)
+ {
+ const gchar *uri;
+
+ uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (self));
+ g_warning ("Unable to delete %s: %s", uri, error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (self);
+}
+
+
static gboolean
photos_local_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
{
@@ -109,6 +132,21 @@ photos_local_item_get_source_widget (PhotosBaseItem *item)
static void
+photos_local_item_trash (PhotosBaseItem *item)
+{
+ GFile *file;
+ const gchar *uri;
+
+ uri = photos_base_item_get_uri (item);
+ file = g_file_new_for_uri (uri);
+ g_file_delete_async (file, G_PRIORITY_DEFAULT, NULL, photos_local_item_delete, g_object_ref (item));
+
+ g_object_unref (file);
+
+}
+
+
+static void
photos_local_item_constructed (GObject *object)
{
PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (object);
@@ -149,4 +187,5 @@ photos_local_item_class_init (PhotosLocalItemClass *class)
base_item_class->create_thumbnail = photos_local_item_create_thumbnail;
base_item_class->download = photos_local_item_download;
base_item_class->get_source_widget = photos_local_item_get_source_widget;
+ base_item_class->trash = photos_local_item_trash;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]