-I$(top_srcdir)/src/rygel -DDATA_DIR='"$(datadir)"'
BUILT_SOURCES = rygel-media-folder.stamp \
- rygel-folder-rootcontainer.c \
+ rygel-folder-root-container.c \
rygel-folder-container.c \
rygel-folder-directory-search-result.c \
rygel-folder-gio-media-item.c \
librygel_media_folder_la_SOURCES = \
rygel-folder-plugin.c \
rygel-folder-plugin.vala \
- rygel-folder-rootcontainer.c \
- rygel-folder-rootcontainer.vala \
+ rygel-folder-root-container.c \
+ rygel-folder-root-container.vala \
rygel-folder-container.c \
rygel-folder-container.vala \
rygel-folder-directory-search-result.c \
/*
- * Copyright (C) 2008-2009 Jens Georg <mail@jensge.org>.
+ * Copyright (C) 2009 Jens Georg <mail@jensge.org>.
*
* This file is part of Rygel.
*
/**
* MediaContainer which exposes the contents of a directory
- * as items
+ * as items.
+ *
+ * The folder contents will be queried on demand and cached afterwards
*/
public class Rygel.FolderContainer : MediaContainer {
+ /**
+ * Number of children to use for crawling the subdir
+ */
private const int MAX_CHILDREN = 10;
/**
- * Flat storage of items found in directory
+ * Cache of items found in directory
*/
private ArrayList<MediaObject> items;
private Gee.List<AsyncResult> results;
// methods overridden from MediaContainer
-
- public override void get_children(uint offset,
- uint max_count,
- Cancellable? cancellable,
- AsyncReadyCallback callback)
- {
+ public override void get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable,
+ AsyncReadyCallback callback) {
+ // if the cache is empty, fill it
if (items.size == 0) {
- var res = new FolderDirectorySearchResult(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,
- null,
- res.enumerate_children_ready);
- this.results.add(res);
+ var res = new FolderDirectorySearchResult (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,
+ null,
+ res.enumerate_children_ready);
+ this.results.add (res);
}
else {
uint stop = offset + max_count;
- stop = stop.clamp(0, this.child_count);
- var children = this.items.slice ((int)offset, (int)stop);
- var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>> (this, callback);
+ stop = stop.clamp (0, this.child_count);
+ var children = this.items.slice ((int) offset, (int) stop);
+ var res =
+ new SimpleAsyncResult<Gee.List<MediaObject>> (
+ this,
+ callback);
res.data = children;
- res.complete_in_idle();
+ res.complete_in_idle ();
}
}
- public override Gee.List<MediaObject>? get_children_finish (AsyncResult res) throws GLib.Error {
+ public override Gee.List<MediaObject>? get_children_finish (
+ AsyncResult res)
+ throws GLib.Error {
if (res is FolderDirectorySearchResult) {
- var dsr = (FolderDirectorySearchResult)res;
+ var dsr = (FolderDirectorySearchResult) res;
+
foreach (var item in dsr.data) {
- this.items.add(item);
+ this.items.add (item);
}
+
this.child_count = this.items.size;
- this.results.remove(res);
- return dsr.get_children();
+ this.results.remove (res);
+ return dsr.get_children ();
}
else {
- var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
+ var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>)
+ res;
return simple_res.data;
}
}
var res = new Rygel.SimpleAsyncResult<string> (this, callback);
res.data = id;
- res.complete_in_idle();
+ res.complete_in_idle ();
}
- public override MediaObject? find_object_finish (AsyncResult res) throws GLib.Error {
- var id = ((Rygel.SimpleAsyncResult<string>)res).data;
+ public override MediaObject? find_object_finish (AsyncResult res)
+ throws GLib.Error {
+ var id = ((Rygel.SimpleAsyncResult<string>) res).data;
- return find_object_sync(id);
+ return find_object_sync (id);
}
- public MediaObject? find_object_sync(string id) {
+ public MediaObject? find_object_sync (string id) {
MediaObject item = null;
- foreach (MediaObject tmp in items) {
+ // check if the searched item is in our cache
+ foreach (var tmp in items) {
if (id == tmp.id) {
item = tmp;
break;
}
}
+ // if not found, do a depth-first search on the child
+ // folders
if (item == null) {
- foreach (MediaObject tmp in items) {
+ foreach (var tmp in items) {
if (tmp is FolderContainer) {
- var folder = (FolderContainer)tmp;
- item = folder.find_object_sync(id);
+ 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);
+ public string strip_parent (File child) {
+ return root_dir.get_relative_path (child);
}
/**
* Create a new root container.
*
- * Schedules an async enumeration of the children of the
- * directory
- *
- * @parameter directory_path, directory you want to expose
+ * @parameter parent, parent container
+ * @parameter file, directory you want to expose
+ * @parameter full, show full path in title
*/
public FolderContainer (MediaContainer parent, File file, bool full) {
- string id = Checksum.compute_for_string(ChecksumType.MD5, file.get_uri());
- base(id, parent, file.get_uri(), 0);
+ string id = Checksum.compute_for_string (ChecksumType.MD5,
+ file.get_uri ());
+
+ base(id, parent, file.get_uri (), 0);
this.root_dir = file;
if (!full && parent is FolderContainer) {
- this.title = ((FolderContainer)parent).strip_parent(root_dir);
+ this.title = ((FolderContainer) parent).strip_parent (root_dir);
}
this.items = new ArrayList<MediaObject> ();
this.child_count = 0;
- this.results = new ArrayList<AsyncResult>();
+ this.results = new ArrayList<AsyncResult> ();
}
}
using Rygel;
using GLib;
-public class Rygel.FolderDirectorySearchResult : Rygel.SimpleAsyncResult<Gee.List<MediaObject>> {
+public class Rygel.FolderDirectorySearchResult :
+ Rygel.SimpleAsyncResult<Gee.List<MediaObject>> {
private uint max_count;
private uint offset;
private File file;
private const int MAX_CHILDREN = 10;
- public FolderDirectorySearchResult(MediaContainer parent, uint offset, uint max_count, AsyncReadyCallback callback) {
- base(parent, callback);
+ public FolderDirectorySearchResult (MediaContainer parent,
+ uint offset,
+ uint max_count,
+ AsyncReadyCallback callback) {
+ base (parent, callback);
this.data = new ArrayList<MediaObject>();
this.offset = offset;
this.max_count = max_count;
}
- public void enumerator_closed(Object obj, AsyncResult res) {
- var enumerator = (FileEnumerator)obj;
+ public void enumerator_closed (Object obj, AsyncResult res) {
+ var enumerator = (FileEnumerator) obj;
try {
- enumerator.close_finish(res);
+ enumerator.close_finish (res);
}
catch (Error e) {
this.error = e;
this.complete();
}
- public void enumerate_next_ready(Object obj, AsyncResult res) {
- var enumerator = (FileEnumerator)obj;
+ public void enumerate_next_ready (Object obj, AsyncResult res) {
+ var enumerator = (FileEnumerator) obj;
try {
var list = enumerator.next_files_finish(res);
if (list != null) {
foreach (FileInfo file_info in list) {
var f = file.get_child(file_info.get_name());
- MediaObject item = null;
- if (file_info.get_file_type() == FileType.DIRECTORY) {
- item = new Rygel.FolderContainer((MediaContainer)source_object,
- f, false);
+ MediaObject item = null;
+ if (file_info.get_file_type () == FileType.DIRECTORY) {
+ item = new Rygel.FolderContainer (
+ (MediaContainer) source_object,
+ f,
+ false);
+ }
+ else {
+ try {
+ item = FolderGioMediaItem.create (
+ (MediaContainer) source_object,
+ f,
+ file_info);
+ }
+ catch (Error error) {
}
- else {
- try {
- item = FolderGioMediaItem.create((MediaContainer)source_object, f, file_info);
- } catch (Error error) {
- }
- }
- if (item != null) {
- data.add(item);
- }
+ }
+
+ if (item != null) {
+ data.add (item);
+ }
}
- enumerator.next_files_async(MAX_CHILDREN,
- Priority.DEFAULT,
- null, enumerate_next_ready);
+ enumerator.next_files_async (MAX_CHILDREN,
+ Priority.DEFAULT,
+ null, enumerate_next_ready);
}
else {
- enumerator.close_async(Priority.DEFAULT,
- null, enumerator_closed);
+ enumerator.close_async (Priority.DEFAULT,
+ null,
+ enumerator_closed);
}
}
catch (Error e) {
this.error = e;
- this.complete();
+ this.complete ();
}
}
public void enumerate_children_ready(Object obj, AsyncResult res) {
- file = (File)obj;
+ file = (File) obj;
try {
- var enumerator = file.enumerate_children_finish(res);
- enumerator.next_files_async(MAX_CHILDREN,
- Priority.DEFAULT,
- null, enumerate_next_ready);
+ var enumerator = file.enumerate_children_finish (res);
+ enumerator.next_files_async (MAX_CHILDREN,
+ Priority.DEFAULT,
+ null,
+ enumerate_next_ready);
}
catch (Error error) {
this.error = error;
- debug("Error %s", error.message);
- this.complete();
+ this.complete ();
}
}
- public Gee.List<MediaItem> get_children() {
+ public Gee.List<MediaItem> get_children () {
uint stop = offset + max_count;
- stop = stop.clamp(0, data.size);
- var children = data.slice ((int)offset, (int)stop);
+ stop = stop.clamp (0, data.size);
+ var children = data.slice ((int) offset, (int) stop);
return children;
}
private bool need_source;
private string raw_uri;
- private static string? get_upnp_class_from_content_type(string content_type) {
- if (content_type.has_prefix("video/")) {
+ private static string? get_upnp_class (string content_type) {
+ if (content_type.has_prefix ("video/")) {
return MediaItem.VIDEO_CLASS;
}
- else if (content_type.has_prefix("audio/")) {
+ else if (content_type.has_prefix ("audio/")) {
return MediaItem.AUDIO_CLASS;
}
- else if (content_type.has_prefix("image/")) {
+ else if (content_type.has_prefix ("image/")) {
return MediaItem.IMAGE_CLASS;
}
}
- public static FolderGioMediaItem? create(MediaContainer parent, File file, FileInfo file_info) {
- var upnp_class = get_upnp_class_from_content_type(file_info.get_content_type());
+ public static FolderGioMediaItem? create(MediaContainer parent,
+ File file,
+ FileInfo file_info) {
+ var upnp_class = get_upnp_class (file_info.get_content_type ());
if (upnp_class != null) {
- return new FolderGioMediaItem(parent, file, upnp_class, file_info);
+ return new FolderGioMediaItem (parent,
+ file,
+ upnp_class,
+ file_info);
}
return null;
string item_class,
FileInfo file_info) {
- base(Checksum.compute_for_string(ChecksumType.MD5, file_info.get_name()),
+ base (Checksum.compute_for_string (ChecksumType.MD5,
+ file_info.get_name ()),
parent,
- file_info.get_name(),
+ file_info.get_name (),
item_class);
- var content_type = file_info.get_content_type();
+ var content_type = file_info.get_content_type ();
need_source = false;
this.mime_type = content_type;
// check if rygel can handle this uri type itself
- if (file.get_uri().has_prefix("file:") ||
- file.get_uri().has_prefix("http:")) {
- this.uris.add(GLib.Markup.escape_text(file.get_uri()));
+ if (file.get_uri ().has_prefix ("file:") ||
+ file.get_uri ().has_prefix ("http:")) {
+ this.uris.add (GLib.Markup.escape_text (file.get_uri ()));
}
else {
need_source = true;
- raw_uri = file.get_uri();
+ raw_uri = file.get_uri ();
}
}
- public override Gst.Element? create_stream_source() {
+ public override Gst.Element? create_stream_source () {
if (need_source) {
- dynamic Element src = ElementFactory.make("giosrc", null);
+ dynamic Element src = ElementFactory.make ("giosrc", null);
if (src != null) {
src.location = raw_uri;
}
*/
[ModuleInit]
public Plugin load_plugin() {
- Plugin plugin = new Plugin("Folder");
+ Plugin plugin = new Plugin ("Folder");
var resource_info = new ResourceInfo (ContentDirectory.UPNP_ID,
ContentDirectory.UPNP_TYPE,
public class Rygel.FolderContentDir : ContentDirectory {
public override MediaContainer? create_root_container () {
- return new FolderRootContainer();
+ return new FolderRootContainer ();
}
}
-
-
/*
- * Copyright (C) 2008-2009 Jens Georg <mail@jensge.org>.
+ * Copyright (C) 2009 Jens Georg <mail@jensge.org>.
*
* This file is part of Rygel.
*
public class Rygel.FolderRootContainer : MediaContainer {
private ArrayList<FolderContainer> items;
- public override void get_children(uint offset,
- uint max_count,
- Cancellable? cancellable,
- AsyncReadyCallback callback)
+ public override void get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable,
+ AsyncReadyCallback callback)
{
uint stop = offset + max_count;
- stop = stop.clamp(0, this.child_count);
- var children = this.items.slice ((int)offset, (int)stop);
- var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>> (this, callback);
+ stop = stop.clamp (0, this.child_count);
+ var children = this.items.slice ((int) offset, (int) stop);
+ var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>> (this,
+ callback);
res.data = children;
- res.complete_in_idle();
+ res.complete_in_idle ();
}
- public override Gee.List<MediaObject>? get_children_finish (AsyncResult res) throws GLib.Error {
+ public override Gee.List<MediaObject>? get_children_finish (
+ AsyncResult res)
+ throws GLib.Error {
var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
return simple_res.data;
}
var res = new Rygel.SimpleAsyncResult<string> (this, callback);
res.data = id;
- res.complete_in_idle();
+ res.complete_in_idle ();
}
- public override MediaObject? find_object_finish (AsyncResult res) throws GLib.Error {
+ public override MediaObject? find_object_finish (AsyncResult res)
+ throws GLib.Error {
MediaObject item = null;
- var id = ((Rygel.SimpleAsyncResult<string>)res).data;
+ var id = ((Rygel.SimpleAsyncResult<string>) res).data;
- foreach (MediaObject tmp in this.items) {
+ foreach (var tmp in this.items) {
if (id == tmp.id) {
item = tmp;
break;
}
if (item == null) {
- foreach (MediaObject tmp in items) {
+ foreach (var tmp in items) {
if (tmp is FolderContainer) {
- var folder = (FolderContainer)tmp;
- item = folder.find_object_sync(id);
+ var folder = (FolderContainer) tmp;
+ item = folder.find_object_sync (id);
if (item != null) {
break;
}
* @parameter directory_path, directory you want to expose
*/
public FolderRootContainer () {
- base.root("FolderRoot", 0);
- GConf.Client client = GConf.Client.get_default();
+ base.root ("FolderRoot", 0);
+ GConf.Client client = GConf.Client.get_default ();
this.items = new ArrayList<FolderContainer> ();
unowned SList<string> dirs = null;
try {
- dirs = client.get_list("/apps/rygel/Folder/folder", GConf.ValueType.STRING);
+ dirs = client.get_list ("/apps/rygel/Folder/folder",
+ GConf.ValueType.STRING);
}
catch (GLib.Error error) {
- message("Error fetching configuration, error was %s", error.message);
+ message("Error fetching configuration, error was %s",
+ error.message);
}
// either an error occured or the gconf key is not set
if (dirs == null) {
- dirs.append(Environment.get_user_special_dir(UserDirectory.MUSIC));
- dirs.append(Environment.get_user_special_dir(UserDirectory.PICTURES));
- dirs.append(Environment.get_user_special_dir(UserDirectory.VIDEOS));
+ dirs.append (Environment.get_user_special_dir (
+ UserDirectory.MUSIC));
+ dirs.append (Environment.get_user_special_dir (
+ UserDirectory.PICTURES));
+ dirs.append (Environment.get_user_special_dir (
+ UserDirectory.VIDEOS));
}
foreach (var dir in dirs) {
- var f = File.new_for_commandline_arg(dir);
- if (f.query_exists(null)) {
- items.add(new FolderContainer(this, f, true));
+ var f = File.new_for_commandline_arg (dir);
+ if (f.query_exists (null)) {
+ items.add (new FolderContainer (this, f, true));
}
}