[rygel] Make folder plugin recursive
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Subject: [rygel] Make folder plugin recursive
- Date: Sun, 3 May 2009 15:15:45 -0400 (EDT)
commit bffd77e799b64a9e2379f86a9c25386a4f1c3cbf
Author: Jens Georg <mail jensge org>
Date: Fri May 1 01:27:48 2009 +0200
Make folder plugin recursive
---
.../folder/rygel-folder-directorysearch.vala | 17 +++++++--
.../folder/rygel-folder-foldercontainer.vala | 35 +++++++++++++++++--
src/plugins/folder/rygel-folder-rootcontainer.vala | 12 +++++++
3 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/src/plugins/folder/rygel-folder-directorysearch.vala b/src/plugins/folder/rygel-folder-directorysearch.vala
index 1e00196..1a1ef89 100644
--- a/src/plugins/folder/rygel-folder-directorysearch.vala
+++ b/src/plugins/folder/rygel-folder-directorysearch.vala
@@ -22,14 +22,14 @@ using Gee;
using Rygel;
using GLib;
-public class Folder.DirectorySearchResult : Rygel.SimpleAsyncResult<Gee.List<MediaItem>> {
+public class Folder.DirectorySearchResult : Rygel.SimpleAsyncResult<Gee.List<MediaObject>> {
private uint max_count;
private uint offset;
public DirectorySearchResult(MediaContainer parent, uint offset, uint max_count, AsyncReadyCallback callback) {
base(parent, callback);
- this.data = new ArrayList<MediaItem>();
+ this.data = new ArrayList<MediaObject>();
this.offset = offset;
this.max_count = max_count;
}
@@ -42,9 +42,18 @@ public class Folder.DirectorySearchResult : Rygel.SimpleAsyncResult<Gee.List<Med
while (file_info != null) {
var f = file.get_child(file_info.get_name());
try {
- var item = new FilesystemMediaItem((MediaContainer)source_object, f, file_info);
+ MediaObject item = null;
+ if (file_info.get_file_type() == FileType.DIRECTORY) {
+ item = new FolderContainer((MediaContainer)source_object,
+ Checksum.compute_for_string(ChecksumType.MD5, f.get_path()),
+ f.get_path(), false);
+
+ }
+ else {
+ item = new FilesystemMediaItem((MediaContainer)source_object, f, file_info);
+ }
if (item != null)
- data.add(item);
+ data.add(item);
} catch (MediaItemError err) {
// most likely invalid content type
}
diff --git a/src/plugins/folder/rygel-folder-foldercontainer.vala b/src/plugins/folder/rygel-folder-foldercontainer.vala
index a189d6f..210fb75 100644
--- a/src/plugins/folder/rygel-folder-foldercontainer.vala
+++ b/src/plugins/folder/rygel-folder-foldercontainer.vala
@@ -53,6 +53,7 @@ public class Folder.FolderContainer : MediaContainer {
DirectorySearchResult res = new DirectorySearchResult(this, offset, max_count, callback);
root_dir.enumerate_children_async(FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE + "," +
FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + "," +
+ FILE_ATTRIBUTE_STANDARD_TYPE + "," +
FILE_ATTRIBUTE_STANDARD_NAME,
FileQueryInfoFlags.NONE,
Priority.DEFAULT,
@@ -96,19 +97,40 @@ public class Folder.FolderContainer : MediaContainer {
}
public override MediaObject? find_object_finish (AsyncResult res) throws GLib.Error {
- MediaObject item = null;
var id = ((Rygel.SimpleAsyncResult<string>)res).data;
- foreach (MediaObject tmp in this.items) {
+ return find_object_sync(id);
+ }
+
+ public MediaObject? find_object_sync(string id) {
+ MediaObject item = null;
+
+ foreach (MediaObject tmp in items) {
if (id == tmp.id) {
item = tmp;
break;
}
}
+ if (item == null) {
+ foreach (MediaObject tmp in items) {
+ if (tmp is FolderContainer) {
+ var folder = (FolderContainer)tmp;
+ item = folder.find_object_sync(id);
+ if (item != null) {
+ break;
+ }
+ }
+ }
+ }
+
return item;
}
+ public string strip_parent(File child) {
+ return root_dir.get_relative_path(child);
+ }
+
/**
* Create a new root container.
*
@@ -118,12 +140,17 @@ public class Folder.FolderContainer : MediaContainer {
* @parameter directory_path, directory you want to expose
*/
public FolderContainer (MediaContainer parent, string id, string directory_path, bool full) {
- //base.root(directory_path, 0);
base(id, parent, directory_path, 0);
+ this.root_dir = GLib.File.new_for_path(directory_path);
+
+ if (!full && parent is FolderContainer) {
+ this.title = ((FolderContainer)parent).strip_parent(root_dir);
+ }
+
this.items = new ArrayList<MediaObject> ();
this.child_count = 0;
this.results = new ArrayList<AsyncResult>();
- this.root_dir = GLib.File.new_for_path(directory_path);
+
}
}
diff --git a/src/plugins/folder/rygel-folder-rootcontainer.vala b/src/plugins/folder/rygel-folder-rootcontainer.vala
index f110e9c..1b8287f 100644
--- a/src/plugins/folder/rygel-folder-rootcontainer.vala
+++ b/src/plugins/folder/rygel-folder-rootcontainer.vala
@@ -67,6 +67,18 @@ public class Folder.FolderRootContainer : MediaContainer {
}
}
+ if (item == null) {
+ foreach (MediaObject tmp in items) {
+ if (tmp is FolderContainer) {
+ var folder = (FolderContainer)tmp;
+ item = folder.find_object_sync(id);
+ if (item != null) {
+ break;
+ }
+ }
+ }
+ }
+
return item;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]