[rygel] core: Configuration for (dis)allowing upload



commit daccb8e187f149649ef8cde92e6afd7489895811
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Nov 3 13:45:45 2010 +0200

    core: Configuration for (dis)allowing upload
    
    Enable user to choose if she wants to (dis)allowing media object upload.

 src/rygel/rygel-cmdline-config.vala     |   12 ++++++++++++
 src/rygel/rygel-configuration.vala      |    2 ++
 src/rygel/rygel-environment-config.vala |    5 +++++
 src/rygel/rygel-media-container.vala    |   20 +++++++++++++++-----
 src/rygel/rygel-meta-config.vala        |   19 +++++++++++++++++++
 src/rygel/rygel-user-config.vala        |    9 +++++++++
 6 files changed, 62 insertions(+), 5 deletions(-)
---
diff --git a/src/rygel/rygel-cmdline-config.vala b/src/rygel/rygel-cmdline-config.vala
index e3df816..a4aeca9 100644
--- a/src/rygel/rygel-cmdline-config.vala
+++ b/src/rygel/rygel-cmdline-config.vala
@@ -41,6 +41,8 @@ internal class Rygel.CmdlineConfig : GLib.Object, Configuration {
     private static bool no_lpcm_trans;
     private static bool no_wmv_trans;
 
+    private static bool disallow_upload;
+
     private static LogLevel log_level = LogLevel.INVALID;
 
     private static string plugin_path;
@@ -79,6 +81,8 @@ internal class Rygel.CmdlineConfig : GLib.Object, Configuration {
           "Disable Linear PCM transcoder", null },
         { "disable-wmv-transcoder", 'w', 0, OptionArg.NONE, ref no_wmv_trans,
           "Disable WMV transcoder", null },
+        { "disallow-upload", 'U', 0, OptionArg.NONE,
+          ref disallow_upload, "Disallow upload", null },
         { "log-level", 'g', 0, OptionArg.INT, ref log_level,
           "Log level. 1=critical,2=error,3=warning,4=message/info,5=debug",
           "N" },
@@ -179,6 +183,14 @@ internal class Rygel.CmdlineConfig : GLib.Object, Configuration {
         }
     }
 
+    public bool get_allow_upload () throws GLib.Error {
+        if (!disallow_upload) {
+            throw new ConfigurationError.NO_VALUE_SET (_("No value available"));
+        } else {
+            return false;
+        }
+    }
+
     public LogLevel get_log_level () throws GLib.Error {
         if (this.log_level == LogLevel.INVALID) {
             throw new ConfigurationError.NO_VALUE_SET (_("No value available"));
diff --git a/src/rygel/rygel-configuration.vala b/src/rygel/rygel-configuration.vala
index 5795580..2d1f05e 100644
--- a/src/rygel/rygel-configuration.vala
+++ b/src/rygel/rygel-configuration.vala
@@ -47,6 +47,8 @@ public interface Rygel.Configuration : GLib.Object {
 
     public abstract bool get_wmv_transcoder () throws GLib.Error;
 
+    public abstract bool get_allow_upload () throws GLib.Error;
+
     public abstract LogLevel get_log_level () throws GLib.Error;
 
     public abstract string get_plugin_path () throws GLib.Error;
diff --git a/src/rygel/rygel-environment-config.vala b/src/rygel/rygel-environment-config.vala
index c1e8fb7..e24cb28 100644
--- a/src/rygel/rygel-environment-config.vala
+++ b/src/rygel/rygel-environment-config.vala
@@ -38,6 +38,7 @@ internal class Rygel.EnvironmentConfig : GLib.Object, Configuration {
     private static string LPCM_TRANSCODING_ENV = RYGEL_PREFIX + "_LPCM_TRANS";
     private static string MP2TS_TRANSCODING_ENV = RYGEL_PREFIX + "_MP2TS_TRANS";
     private static string WMV_TRANSCODING_ENV = RYGEL_PREFIX + "_WMV_TRANS";
+    private static string ALLOW_UPLOAD_ENV = RYGEL_PREFIX + "_ALLOW_UPLOAD";
     private static string LOG_LEVEL_ENV = RYGEL_PREFIX + "_LOG";
     private static string PLUGIN_PATH_ENV = RYGEL_PREFIX + "_PLUGIN_PATH";
 
@@ -85,6 +86,10 @@ internal class Rygel.EnvironmentConfig : GLib.Object, Configuration {
         return this.get_bool_variable (LPCM_TRANSCODING_ENV);
     }
 
+    public bool get_allow_upload () throws GLib.Error {
+        return this.get_bool_variable (ALLOW_UPLOAD_ENV);
+    }
+
     public LogLevel get_log_level () throws GLib.Error {
         return (LogLevel) this.get_int_variable (LOG_LEVEL_ENV,
                                                 LogLevel.CRITICAL,
diff --git a/src/rygel/rygel-media-container.vala b/src/rygel/rygel-media-container.vala
index a1c687f..788fdf9 100644
--- a/src/rygel/rygel-media-container.vala
+++ b/src/rygel/rygel-media-container.vala
@@ -48,13 +48,23 @@ public abstract class Rygel.MediaContainer : MediaObject {
 
     internal override OCMFlags ocm_flags {
         get {
-            if (this is WritableContainer && this.uris.size > 0) {
-                return OCMFlags.UPLOAD |
-                       OCMFlags.DESTROYABLE |
-                       OCMFlags.UPLOAD_DESTROYABLE;
-            } else {
+            if (!(this is WritableContainer) || this.uris.size == 0) {
                 return OCMFlags.NONE;
             }
+
+            var flags = OCMFlags.DESTROYABLE;
+
+            var allow_upload = true;
+            var config = MetaConfig.get_default ();
+            try {
+                allow_upload = config.get_allow_upload ();
+            } catch (Error error) {}
+
+            if (allow_upload) {
+                flags |= OCMFlags.UPLOAD | OCMFlags.UPLOAD_DESTROYABLE;
+            }
+
+            return flags;
         }
     }
 
diff --git a/src/rygel/rygel-meta-config.vala b/src/rygel/rygel-meta-config.vala
index ba6b0c4..50aeeae 100644
--- a/src/rygel/rygel-meta-config.vala
+++ b/src/rygel/rygel-meta-config.vala
@@ -210,6 +210,25 @@ public class Rygel.MetaConfig : GLib.Object, Configuration {
         return val;
     }
 
+    public bool get_allow_upload () throws GLib.Error {
+        bool val = true;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_allow_upload ();
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET (_("No value available"));
+        }
+
+        return val;
+    }
+
     public LogLevel get_log_level () throws GLib.Error {
         LogLevel val = LogLevel.DEFAULT;
         bool unavailable = true;
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala
index 528a36d..545ab9d 100644
--- a/src/rygel/rygel-user-config.vala
+++ b/src/rygel/rygel-user-config.vala
@@ -38,6 +38,7 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
     public static const string MP2TS_TRANSCODER_KEY = "enable-mp2ts-transcoder";
     public static const string LPCM_TRANSCODER_KEY = "enable-lpcm-transcoder";
     public static const string WMV_TRANSCODER_KEY = "enable-wmv-transcoder";
+    public static const string ALLOW_UPLOAD_KEY = "allow-upload";
     public static const string LOG_LEVEL_KEY = "log-level";
     public static const string PLUGIN_PATH_KEY = "plugin-path";
 
@@ -123,6 +124,14 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
         this.set_bool ("general", WMV_TRANSCODER_KEY, value);
     }
 
+    public bool get_allow_upload () throws GLib.Error {
+        return this.get_bool ("general", ALLOW_UPLOAD_KEY);
+    }
+
+    public void set_allow_upload (bool value) throws GLib.Error {
+        this.set_bool ("general", ALLOW_UPLOAD_KEY, value);
+    }
+
     public LogLevel get_log_level () throws GLib.Error {
         return (LogLevel) this.get_int ("general",
                                         LOG_LEVEL_KEY,



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