[rygel] core,plugins: Don't create files for new items
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core,plugins: Don't create files for new items
- Date: Tue, 26 Oct 2010 13:39:54 +0000 (UTC)
commit 812ff1dc3baceb3b327f57e9b521be999742b895
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Oct 19 17:54:22 2010 +0300
core,plugins: Don't create files for new items
There is no need to actually create the file for new items. The file will
automatically be created when/if contents are copied to the new empy item. This
change also turns MediaContainer.add_item() into an abstract method.
src/plugins/external/rygel-external-container.vala | 8 +++
.../external/rygel-external-dummy-container.vala | 8 +++
.../rygel-media-export-db-container.vala | 2 -
.../rygel-media-export-null-container.vala | 8 +++
.../rygel-tracker-category-all-container.vala | 38 +--------------
src/plugins/tracker/rygel-tracker-interfaces.vala | 6 --
.../tracker/rygel-tracker-search-container.vala | 8 +++
src/rygel/rygel-item-creator.vala | 21 ++++++++
src/rygel/rygel-media-container.vala | 53 +++++---------------
src/rygel/rygel-media-object.vala | 10 +++-
src/rygel/rygel-simple-container.vala | 8 +++
11 files changed, 82 insertions(+), 88 deletions(-)
---
diff --git a/src/plugins/external/rygel-external-container.vala b/src/plugins/external/rygel-external-container.vala
index 9e20ff0..0e002f6 100644
--- a/src/plugins/external/rygel-external-container.vala
+++ b/src/plugins/external/rygel-external-container.vala
@@ -175,6 +175,14 @@ public class Rygel.External.Container : Rygel.MediaContainer {
return media_object;
}
+ public override async void add_item (MediaItem item,
+ Cancellable? cancellable)
+ throws Error {
+ throw new ContentDirectoryError.RESTRICTED_PARENT (
+ _("Object creation in %s not allowed"),
+ this.id);
+ }
+
private async MediaObjects create_media_objects (
HashTable<string,Variant>[] all_props,
MediaContainer? parent
diff --git a/src/plugins/external/rygel-external-dummy-container.vala b/src/plugins/external/rygel-external-dummy-container.vala
index 40b6095..f8d2b3b 100644
--- a/src/plugins/external/rygel-external-dummy-container.vala
+++ b/src/plugins/external/rygel-external-dummy-container.vala
@@ -44,4 +44,12 @@ internal class Rygel.External.DummyContainer : MediaContainer {
throws Error {
return new MediaObjects ();
}
+
+ public override async void add_item (MediaItem item,
+ Cancellable? cancellable)
+ throws Error {
+ throw new ContentDirectoryError.RESTRICTED_PARENT (
+ _("Object creation in %s not allowed"),
+ this.id);
+ }
}
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 31025a5..68f0a57 100644
--- a/src/plugins/media-export/rygel-media-export-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-db-container.vala
@@ -89,8 +89,6 @@ public class Rygel.MediaExport.DBContainer : MediaContainer {
public override async void add_item (Rygel.MediaItem item,
Cancellable? cancellable)
throws Error {
- yield base.add_item (item, cancellable);
-
item.parent = this;
item.id = MediaCache.get_id (File.new_for_uri (item.uris[0]));
this.media_db.save_item (item);
diff --git a/src/plugins/media-export/rygel-media-export-null-container.vala b/src/plugins/media-export/rygel-media-export-null-container.vala
index 1be8b7c..25c1054 100644
--- a/src/plugins/media-export/rygel-media-export-null-container.vala
+++ b/src/plugins/media-export/rygel-media-export-null-container.vala
@@ -36,4 +36,12 @@ internal class Rygel.NullContainer : MediaContainer {
throws Error {
return new MediaObjects ();
}
+
+ public override async void add_item (MediaItem item,
+ Cancellable? cancellable)
+ throws Error {
+ throw new ContentDirectoryError.RESTRICTED_PARENT (
+ _("Object creation in %s not allowed"),
+ this.id);
+ }
}
diff --git a/src/plugins/tracker/rygel-tracker-category-all-container.vala b/src/plugins/tracker/rygel-tracker-category-all-container.vala
index 0d12f77..3101390 100644
--- a/src/plugins/tracker/rygel-tracker-category-all-container.vala
+++ b/src/plugins/tracker/rygel-tracker-category-all-container.vala
@@ -35,7 +35,6 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer {
private const string MINER_PATH = "/org/freedesktop/Tracker1/Miner/Files";
private ResourcesIface resources;
- private MinerIface miner;
public CategoryAllContainer (CategoryContainer parent) {
base ("All" + parent.id, parent, "All", parent.item_factory);
@@ -44,9 +43,6 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer {
this.resources = Bus.get_proxy_sync (BusType.SESSION,
TRACKER_SERVICE,
RESOURCES_PATH);
- this.miner = Bus.get_proxy_sync (BusType.SESSION,
- MINER_SERVICE,
- MINER_PATH);
} catch (IOError io_error) {
critical (_("Failed to create D-Bus proxies: %s"),
io_error.message);
@@ -68,44 +64,12 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer {
public async override void add_item (MediaItem item,
Cancellable? cancellable)
throws Error {
- assert (this.uris.size > 0);
-
- string urn;
-
- if (item.uris.size == 0) {
- var file = yield this.prepare_file (item, cancellable);
-
- urn = yield this.create_entry_in_store (item);
-
- var uris = new string[] { item.uris[0] };
- yield this.miner.ignore_next_update (uris);
- yield file.create_async (FileCreateFlags.NONE,
- Priority.DEFAULT,
- cancellable);
- } else {
- urn = yield this.create_entry_in_store (item);
- }
+ var urn = yield this.create_entry_in_store (item);
item.id = this.create_child_id_for_urn (urn);
item.parent = this;
}
- private async File prepare_file (MediaItem item,
- Cancellable? cancellable) throws Error {
- var dir = yield this.get_writable (cancellable);
- if (dir == null) {
- throw new ContentDirectoryError.RESTRICTED_PARENT (
- _("Object creation in %s not allowed"),
- this.id);
- }
-
- var file = dir.get_child_for_display_name (item.title);
-
- item.uris.add (file.get_uri ());
-
- return file;
- }
-
private async string create_entry_in_store (MediaItem item) throws Error {
var category = this.item_factory.category;
var query = new InsertionQuery (item, category);
diff --git a/src/plugins/tracker/rygel-tracker-interfaces.vala b/src/plugins/tracker/rygel-tracker-interfaces.vala
index 972a342..8479ed3 100644
--- a/src/plugins/tracker/rygel-tracker-interfaces.vala
+++ b/src/plugins/tracker/rygel-tracker-interfaces.vala
@@ -42,12 +42,6 @@ public interface Rygel.Tracker.ResourcesClassIface: DBusProxy {
string[] after);
}
-[DBus (name = "org.freedesktop.Tracker1.Miner")]
-public interface Rygel.Tracker.MinerIface : DBusProxy {
- public abstract async void ignore_next_update (string[] urls)
- throws IOError;
-}
-
namespace Rygel {
public const string RESOURCES_CLASS_PATH = "/org/freedesktop/Tracker1/" +
"Resources/Classes/";
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index 507d636..bfde002 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -169,6 +169,14 @@ public class Rygel.Tracker.SearchContainer : Rygel.MediaContainer {
}
}
+ public override async void add_item (MediaItem item,
+ Cancellable? cancellable)
+ throws Error {
+ throw new ContentDirectoryError.RESTRICTED_PARENT (
+ _("Object creation in %s not allowed"),
+ this.id);
+ }
+
public string create_child_id_for_urn (string urn) {
return this.id + "," + urn;
}
diff --git a/src/rygel/rygel-item-creator.vala b/src/rygel/rygel-item-creator.vala
index 485ed8d..2fcfc57 100644
--- a/src/rygel/rygel-item-creator.vala
+++ b/src/rygel/rygel-item-creator.vala
@@ -108,6 +108,13 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
this.item.size = 0;
}
+ if (this.item.uris.size == 0) {
+ var uri = yield this.create_uri (container, this.item.title);
+ this.item.uris.add (uri);
+ }
+
+ this.item.id = this.item.uris[0];
+
yield container.add_item (this.item, this.cancellable);
this.item.serialize (didl_writer, this.content_dir.http_server);
@@ -249,5 +256,19 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
return true;
}
+
+ public async string create_uri (MediaContainer container, string title)
+ throws Error {
+ var dir = yield container.get_writable (this.cancellable);
+ if (dir == null) {
+ throw new ContentDirectoryError.RESTRICTED_PARENT (
+ _("Object creation in %s not allowed"),
+ container.id);
+ }
+
+ var file = dir.get_child_for_display_name (title);
+
+ return file.get_uri ();
+ }
}
diff --git a/src/rygel/rygel-media-container.vala b/src/rygel/rygel-media-container.vala
index 06ff8c0..6710ae2 100644
--- a/src/rygel/rygel-media-container.vala
+++ b/src/rygel/rygel-media-container.vala
@@ -84,6 +84,18 @@ public abstract class Rygel.MediaContainer : MediaObject {
throws Error;
/**
+ * Add a new item directly under this container.
+ *
+ * @param item The item to add to this container
+ * @param cancellable optional cancellable for this operation
+ *
+ * return nothing.
+ *
+ */
+ public async abstract void add_item (MediaItem item, Cancellable? cancellable)
+ throws Error;
+
+ /**
* Recursively searches for all media objects the satisfy the given search
* expression in this container.
*
@@ -198,30 +210,6 @@ public abstract class Rygel.MediaContainer : MediaObject {
}
/**
- * Add a new item directly under this container.
- *
- * @param didl_item The item to add to this container.
- *
- * return nothing.
- *
- * This implementation is very basic: If no URI is provided for the item,
- * it creates the file under the first writable URI it can find for this
- * container. It also sets the ID of the item to that of the URI of the
- * item. If your subclass doesn't ID the items by their original URIs, you
- * definitely want to override this method.
- */
- public async virtual void add_item (MediaItem item,
- Cancellable? cancellable)
- throws Error {
- if (item.uris.size == 0) {
- var file = yield create_child (item.title, cancellable);
- item.uris.add (file.get_uri ());
- }
-
- item.id = item.uris[0];
- }
-
- /**
* Method to be be called each time this container is updated (metadata
* changes for this container, items under it gets removed/added or their
* metadata changes etc).
@@ -330,22 +318,5 @@ public abstract class Rygel.MediaContainer : MediaObject {
this.parent.container_updated (updated_container);
}
}
-
- private async File create_child (string title, Cancellable? cancellable)
- throws Error {
- var dir = yield this.get_writable (cancellable);
- if (dir == null) {
- throw new ContentDirectoryError.RESTRICTED_PARENT (
- _("Object creation in %s not allowed"),
- this.id);
- }
-
- var file = dir.get_child_for_display_name (title);
- yield file.create_async (FileCreateFlags.NONE,
- Priority.DEFAULT,
- cancellable);
-
- return file;
- }
}
diff --git a/src/rygel/rygel-media-object.vala b/src/rygel/rygel-media-object.vala
index f6cea25..6eb651d 100644
--- a/src/rygel/rygel-media-object.vala
+++ b/src/rygel/rygel-media-object.vala
@@ -109,12 +109,18 @@ public abstract class Rygel.MediaObject : GLib.Object {
foreach (var uri in this.uris) {
var file = File.new_for_uri (uri);
- var info = yield file.query_info_async (
+ try {
+ var info = yield file.query_info_async (
FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
FileQueryInfoFlags.NONE,
Priority.DEFAULT,
cancellable);
- if (info.get_attribute_boolean (FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
+
+ if (info.get_attribute_boolean (
+ FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
+ return file;
+ }
+ } catch (IOError.NOT_FOUND error) {
return file;
}
}
diff --git a/src/rygel/rygel-simple-container.vala b/src/rygel/rygel-simple-container.vala
index 18f0542..da51bf9 100644
--- a/src/rygel/rygel-simple-container.vala
+++ b/src/rygel/rygel-simple-container.vala
@@ -94,4 +94,12 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
return media_object;
}
+
+ public override async void add_item (MediaItem item,
+ Cancellable? cancellable)
+ throws Error {
+ throw new ContentDirectoryError.RESTRICTED_PARENT (
+ _("Object creation in %s not allowed"),
+ this.id);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]