[gnome-photos] Add PhotosDeleteItemJob
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Add PhotosDeleteItemJob
- Date: Sun, 14 Apr 2013 21:42:21 +0000 (UTC)
commit 1f297217b6c45a35eba7be2b85092234e404d987
Author: Debarshi Ray <debarshir gnome org>
Date: Sun Apr 14 13:47:56 2013 +0200
Add PhotosDeleteItemJob
src/Makefile.am | 2 +
src/photos-delete-item-job.c | 179 +++++++++++++++++++++++++++++++++++++++++++
src/photos-delete-item-job.h | 81 ++++++++++++++++++++
3 files changed, 262 insertions(+)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 6a16f7d..ac9d861 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,6 +64,8 @@ gnome_photos_SOURCES = \
photos-collection-manager.h \
photos-create-collection-job.c \
photos-create-collection-job.h \
+ photos-delete-item-job.c \
+ photos-delete-item-job.h \
photos-embed.c \
photos-embed.h \
photos-empty-results-box.c \
diff --git a/src/photos-delete-item-job.c b/src/photos-delete-item-job.c
new file mode 100644
index 0000000..912c3ef
--- /dev/null
+++ b/src/photos-delete-item-job.c
@@ -0,0 +1,179 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ * + Documents
+ */
+
+
+#include "config.h"
+
+#include <glib.h>
+#include <tracker-sparql.h>
+
+#include "photos-delete-item-job.h"
+#include "photos-query.h"
+#include "photos-query-builder.h"
+#include "photos-tracker-queue.h"
+
+
+struct _PhotosDeleteItemJobPrivate
+{
+ PhotosDeleteItemJobCallback callback;
+ PhotosTrackerQueue *queue;
+ gchar *urn;
+ gpointer user_data;
+};
+
+enum
+{
+ PROP_0,
+ PROP_URN
+};
+
+
+G_DEFINE_TYPE (PhotosDeleteItemJob, photos_delete_item_job, G_TYPE_OBJECT);
+
+
+static void
+photos_delete_item_job_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosDeleteItemJob *self = PHOTOS_DELETE_ITEM_JOB (user_data);
+ PhotosDeleteItemJobPrivate *priv = self->priv;
+ TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
+ GError *error;
+
+ error = NULL;
+ tracker_sparql_connection_update_finish (connection, res, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to delete item: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ out:
+ if (priv->callback != NULL)
+ (*priv->callback) (priv->user_data);
+}
+
+
+static void
+photos_delete_item_job_dispose (GObject *object)
+{
+ PhotosDeleteItemJob *self = PHOTOS_DELETE_ITEM_JOB (object);
+
+ g_clear_object (&self->priv->queue);
+
+ G_OBJECT_CLASS (photos_delete_item_job_parent_class)->dispose (object);
+}
+
+
+static void
+photos_delete_item_job_finalize (GObject *object)
+{
+ PhotosDeleteItemJob *self = PHOTOS_DELETE_ITEM_JOB (object);
+
+ g_free (self->priv->urn);
+
+ G_OBJECT_CLASS (photos_delete_item_job_parent_class)->finalize (object);
+}
+
+
+static void
+photos_delete_item_job_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ PhotosDeleteItemJob *self = PHOTOS_DELETE_ITEM_JOB (object);
+
+ switch (prop_id)
+ {
+ case PROP_URN:
+ self->priv->urn = g_value_dup_string (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_delete_item_job_init (PhotosDeleteItemJob *self)
+{
+ PhotosDeleteItemJobPrivate *priv;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ PHOTOS_TYPE_DELETE_ITEM_JOB,
+ PhotosDeleteItemJobPrivate);
+ priv = self->priv;
+
+ priv->queue = photos_tracker_queue_new ();
+}
+
+
+static void
+photos_delete_item_job_class_init (PhotosDeleteItemJobClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->dispose = photos_delete_item_job_dispose;
+ object_class->finalize = photos_delete_item_job_finalize;
+ object_class->set_property = photos_delete_item_job_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_URN,
+ g_param_spec_string ("urn",
+ "Uniform Resource Name",
+ "An unique ID associated with this item",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+ g_type_class_add_private (class, sizeof (PhotosDeleteItemJobPrivate));
+}
+
+
+PhotosDeleteItemJob *
+photos_delete_item_job_new (const gchar *urn)
+{
+ return g_object_new (PHOTOS_TYPE_DELETE_ITEM_JOB, "urn", urn, NULL);
+}
+
+
+void
+photos_delete_item_job_run (PhotosDeleteItemJob *self,
+ PhotosDeleteItemJobCallback callback,
+ gpointer user_data)
+{
+ PhotosDeleteItemJobPrivate *priv = self->priv;
+ PhotosQuery *query;
+
+ priv->callback = callback;
+ priv->user_data = user_data;
+
+ query = photos_query_builder_delete_resource_query (priv->urn);
+ photos_tracker_queue_update (priv->queue,
+ query->sparql,
+ NULL,
+ photos_delete_item_job_query_executed,
+ g_object_ref (self),
+ g_object_unref);
+ photos_query_free (query);
+}
diff --git a/src/photos-delete-item-job.h b/src/photos-delete-item-job.h
new file mode 100644
index 0000000..042306d
--- /dev/null
+++ b/src/photos-delete-item-job.h
@@ -0,0 +1,81 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ * + Documents
+ */
+
+#ifndef PHOTOS_DELETE_ITEM_JOB_H
+#define PHOTOS_DELETE_ITEM_JOB_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_DELETE_ITEM_JOB (photos_delete_item_job_get_type ())
+
+#define PHOTOS_DELETE_ITEM_JOB(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_DELETE_ITEM_JOB, PhotosDeleteItemJob))
+
+#define PHOTOS_DELETE_ITEM_JOB_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_DELETE_ITEM_JOB, PhotosDeleteItemJobClass))
+
+#define PHOTOS_IS_DELETE_ITEM_JOB(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_DELETE_ITEM_JOB))
+
+#define PHOTOS_IS_DELETE_ITEM_JOB_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_DELETE_ITEM_JOB))
+
+#define PHOTOS_DELETE_ITEM_JOB_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_DELETE_ITEM_JOB, PhotosDeleteItemJobClass))
+
+typedef void (*PhotosDeleteItemJobCallback) (gpointer);
+
+typedef struct _PhotosDeleteItemJob PhotosDeleteItemJob;
+typedef struct _PhotosDeleteItemJobClass PhotosDeleteItemJobClass;
+typedef struct _PhotosDeleteItemJobPrivate PhotosDeleteItemJobPrivate;
+
+struct _PhotosDeleteItemJob
+{
+ GObject parent_instance;
+ PhotosDeleteItemJobPrivate *priv;
+};
+
+struct _PhotosDeleteItemJobClass
+{
+ GObjectClass parent_class;
+};
+
+GType photos_delete_item_job_get_type (void) G_GNUC_CONST;
+
+PhotosDeleteItemJob *photos_delete_item_job_new (const gchar *urn);
+
+void photos_delete_item_job_run (PhotosDeleteItemJob *self,
+ PhotosDeleteItemJobCallback callback,
+ gpointer user_data);
+
+G_END_DECLS
+
+#endif /* PHOTOS_DELETE_ITEM_JOB_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]