[rygel] core,plugins: Add WritableContainer.remove_item()
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core,plugins: Add WritableContainer.remove_item()
- Date: Fri, 29 Oct 2010 12:35:34 +0000 (UTC)
commit 53efd4855cd2ac7d54fc3a61a89d58e0a4ed7c0a
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Wed Oct 27 20:55:23 2010 +0300
core,plugins: Add WritableContainer.remove_item()
Writable containers now support removal of (direct) child item, given its
ID.
.../rygel-media-export-db-container.vala | 5 ++
src/plugins/tracker/Makefile.am | 1 +
.../rygel-tracker-category-all-container.vala | 18 +++++++
.../tracker/rygel-tracker-deletion-query.vala | 54 ++++++++++++++++++++
src/plugins/tracker/rygel-tracker-interfaces.vala | 1 +
src/rygel/rygel-writable-container.vala | 14 +++++-
6 files changed, 92 insertions(+), 1 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-db-container.vala b/src/plugins/media-export/rygel-media-export-db-container.vala
index b145b6f..61f97a9 100644
--- a/src/plugins/media-export/rygel-media-export-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-db-container.vala
@@ -102,4 +102,9 @@ public class Rygel.MediaExport.DBContainer : MediaContainer, WritableContainer {
item.id = MediaCache.get_id (File.new_for_uri (item.uris[0]));
this.media_db.save_item (item);
}
+
+ public async void remove_item (string id, Cancellable? cancellable)
+ throws Error {
+ this.media_db.remove_by_id (id);
+ }
}
diff --git a/src/plugins/tracker/Makefile.am b/src/plugins/tracker/Makefile.am
index a112391..f93b5af 100644
--- a/src/plugins/tracker/Makefile.am
+++ b/src/plugins/tracker/Makefile.am
@@ -26,6 +26,7 @@ librygel_media_tracker_la_SOURCES = rygel-tracker-root-container.vala \
rygel-tracker-category-all-container.vala \
rygel-tracker-query.vala \
rygel-tracker-selection-query.vala \
+ rygel-tracker-deletion-query.vala \
rygel-tracker-insertion-query.vala \
rygel-tracker-query-triplet.vala \
rygel-tracker-query-triplets.vala \
diff --git a/src/plugins/tracker/rygel-tracker-category-all-container.vala b/src/plugins/tracker/rygel-tracker-category-all-container.vala
index 555c885..63db5db 100644
--- a/src/plugins/tracker/rygel-tracker-category-all-container.vala
+++ b/src/plugins/tracker/rygel-tracker-category-all-container.vala
@@ -75,6 +75,18 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer,
this.updated ();
}
+ public async void remove_item (string id, Cancellable? cancellable)
+ throws Error {
+ string parent_id;
+
+ var urn = this.get_item_info (id, out parent_id);
+
+ yield this.remove_entry_from_store (urn);
+
+ this.child_count--;
+ this.updated ();
+ }
+
private async string create_entry_in_store (MediaItem item) throws Error {
var category = this.item_factory.category;
var query = new InsertionQuery (item, category);
@@ -83,5 +95,11 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer,
return query.id;
}
+
+ private async void remove_entry_from_store (string id) throws Error {
+ var query = new DeletionQuery (id);
+
+ yield query.execute (this.resources);
+ }
}
diff --git a/src/plugins/tracker/rygel-tracker-deletion-query.vala b/src/plugins/tracker/rygel-tracker-deletion-query.vala
new file mode 100644
index 0000000..bbcae22
--- /dev/null
+++ b/src/plugins/tracker/rygel-tracker-deletion-query.vala
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 20010 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali <zeenix gmail com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+using Gee;
+
+/**
+ * Represents Tracker SPARQL Deletion query
+ */
+public class Rygel.Tracker.DeletionQuery : Query {
+ private string id;
+
+ public DeletionQuery (string id) {
+ var triplets = new QueryTriplets ();
+ triplets.add (new QueryTriplet ("<" + id + ">", "a", "rdfs:Resource"));
+
+ base (triplets);
+
+ this.id = id;
+ }
+
+ public override async void execute (ResourcesIface resources)
+ throws IOError {
+ var str = this.to_string ();
+
+ debug ("Executing SPARQL query: %s", str);
+
+ yield resources.sparql_update (str);
+
+ debug ("Deleted item '%s' from Tracker store", this.id);
+ }
+
+ public override string to_string () {
+ return "DELETE { " + base.to_string () + " }";
+ }
+}
diff --git a/src/plugins/tracker/rygel-tracker-interfaces.vala b/src/plugins/tracker/rygel-tracker-interfaces.vala
index 8479ed3..30ac613 100644
--- a/src/plugins/tracker/rygel-tracker-interfaces.vala
+++ b/src/plugins/tracker/rygel-tracker-interfaces.vala
@@ -30,6 +30,7 @@ public interface Rygel.Tracker.StatsIface : DBusProxy {
public interface Rygel.Tracker.ResourcesIface: DBusProxy {
public abstract async string[,] sparql_query (string query)
throws IOError;
+ public abstract async void sparql_update (string query) throws IOError;
public abstract async HashTable<string,string>[,] sparql_update_blank (
string query) throws IOError;
}
diff --git a/src/rygel/rygel-writable-container.vala b/src/rygel/rygel-writable-container.vala
index 1c173e7..b020d44 100644
--- a/src/rygel/rygel-writable-container.vala
+++ b/src/rygel/rygel-writable-container.vala
@@ -27,7 +27,7 @@ using Gee;
/**
* Interface to be implemented by 'writable' container: ones that allow
* creation, removal and editing of items directly under them. Currently, only
- * addition is supported.
+ * addition and removal is supported.
*
* In addition to implementing this interface, a writable container must also
* provide one URI that points to a writable folder on a GIO supported
@@ -48,4 +48,16 @@ public interface Rygel.WritableContainer : MediaContainer {
*/
public async abstract void add_item (MediaItem item,
Cancellable? cancellable) throws Error;
+
+ /**
+ * Remove an item directly under this container that has the ID @id.
+ *
+ * @param item The ID of the item to remove from this container
+ * @param cancellable optional cancellable for this operation
+ *
+ * return nothing.
+ *
+ */
+ public async abstract void remove_item (string id, Cancellable? cancellable)
+ throws Error;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]