[rygel] More style fixes



commit 47cfca14dd461294d5e2649294bff59ca61888f6
Author: Jens Georg <mail jensge org>
Date:   Sun May 3 20:12:05 2009 +0200

    More style fixes
---
 src/plugins/folder/Makefile.am                     |    6 +-
 src/plugins/folder/rygel-folder-container.vala     |  118 ++++++++++++--------
 .../rygel-folder-directory-search-result.vala      |   86 ++++++++------
 .../folder/rygel-folder-gio-media-item.vala        |   38 ++++---
 src/plugins/folder/rygel-folder-plugin.vala        |    6 +-
 ...ainer.vala => rygel-folder-root-container.vala} |   63 ++++++-----
 6 files changed, 182 insertions(+), 135 deletions(-)

diff --git a/src/plugins/folder/Makefile.am b/src/plugins/folder/Makefile.am
index e81d42d..71763b8 100644
--- a/src/plugins/folder/Makefile.am
+++ b/src/plugins/folder/Makefile.am
@@ -11,7 +11,7 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
 	-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 \
@@ -20,8 +20,8 @@ BUILT_SOURCES = rygel-media-folder.stamp \
 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 \
diff --git a/src/plugins/folder/rygel-folder-container.vala b/src/plugins/folder/rygel-folder-container.vala
index 77b49ca..35a0411 100644
--- a/src/plugins/folder/rygel-folder-container.vala
+++ b/src/plugins/folder/rygel-folder-container.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2009 Jens Georg <mail jensge org>.
+ * Copyright (C) 2009 Jens Georg <mail jensge org>.
  *
  * This file is part of Rygel.
  *
@@ -24,14 +24,19 @@ using 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;
 
@@ -43,46 +48,58 @@ public class Rygel.FolderContainer : MediaContainer {
     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;
         }
     }
@@ -93,30 +110,34 @@ public class Rygel.FolderContainer : MediaContainer {
         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;
                     }
@@ -127,29 +148,30 @@ public class Rygel.FolderContainer : MediaContainer {
         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> ();
     }
 }
diff --git a/src/plugins/folder/rygel-folder-directory-search-result.vala b/src/plugins/folder/rygel-folder-directory-search-result.vala
index 184a605..6c6a031 100644
--- a/src/plugins/folder/rygel-folder-directory-search-result.vala
+++ b/src/plugins/folder/rygel-folder-directory-search-result.vala
@@ -22,25 +22,29 @@ using Gee;
 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;
@@ -48,64 +52,72 @@ public class Rygel.FolderDirectorySearchResult : Rygel.SimpleAsyncResult<Gee.Lis
         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;
     }
diff --git a/src/plugins/folder/rygel-folder-gio-media-item.vala b/src/plugins/folder/rygel-folder-gio-media-item.vala
index 6efa240..605cbb3 100644
--- a/src/plugins/folder/rygel-folder-gio-media-item.vala
+++ b/src/plugins/folder/rygel-folder-gio-media-item.vala
@@ -29,14 +29,14 @@ public class Rygel.FolderGioMediaItem : Rygel.MediaItem {
     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;
         }
 
@@ -44,10 +44,15 @@ public class Rygel.FolderGioMediaItem : Rygel.MediaItem {
     }
 
 
-    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;
@@ -58,30 +63,31 @@ public class Rygel.FolderGioMediaItem : Rygel.MediaItem {
                                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;
             }
diff --git a/src/plugins/folder/rygel-folder-plugin.vala b/src/plugins/folder/rygel-folder-plugin.vala
index a6fa350..8b65ad1 100644
--- a/src/plugins/folder/rygel-folder-plugin.vala
+++ b/src/plugins/folder/rygel-folder-plugin.vala
@@ -36,7 +36,7 @@ using GLib;
  */
 [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,
@@ -50,8 +50,6 @@ public Plugin load_plugin() {
 
 public class Rygel.FolderContentDir : ContentDirectory {
     public override MediaContainer? create_root_container () {
-        return new FolderRootContainer();
+        return new FolderRootContainer ();
     }
 }
-
-
diff --git a/src/plugins/folder/rygel-folder-rootcontainer.vala b/src/plugins/folder/rygel-folder-root-container.vala
similarity index 60%
rename from src/plugins/folder/rygel-folder-rootcontainer.vala
rename to src/plugins/folder/rygel-folder-root-container.vala
index 08d89d5..8f91593 100644
--- a/src/plugins/folder/rygel-folder-rootcontainer.vala
+++ b/src/plugins/folder/rygel-folder-root-container.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2009 Jens Georg <mail jensge org>.
+ * Copyright (C) 2009 Jens Georg <mail jensge org>.
  *
  * This file is part of Rygel.
  *
@@ -30,20 +30,23 @@ using GConf;
 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;
     }
@@ -54,14 +57,15 @@ public class Rygel.FolderRootContainer : MediaContainer {
         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;
@@ -69,10 +73,10 @@ public class Rygel.FolderRootContainer : MediaContainer {
         }
 
         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;
                     }
@@ -92,28 +96,33 @@ public class Rygel.FolderRootContainer : MediaContainer {
      * @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));
             }
         }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]