core: Add MediaContainer.get_writable()
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Tue, 26 Jan 2010 15:36:00 +0000 (17:36 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 3 Feb 2010 13:38:48 +0000 (15:38 +0200)
A new method that fetches a GLib.File object for any writable URI
available for the container.

src/rygel/rygel-media-container.vala

index edbde2d..8ce6519 100644 (file)
@@ -246,5 +246,27 @@ public abstract class Rygel.MediaContainer : MediaObject {
             this.parent.container_updated (updated_container);
         }
     }
+
+    /**
+     * Fetches a File object for any writable URI available for this container.
+     *
+     * @param cancellable A GLib.Cancellable
+     */
+    private async File? get_writable (Cancellable? cancellable) throws Error {
+        foreach (var uri in this.uris) {
+            var file = File.new_for_uri (uri);
+
+            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)) {
+                return file;
+            }
+        }
+
+        return null;
+    }
 }