[banshee] [Banshee.Metrics] Record whitelisted config options



commit c805f7534a194380b121877e31ab04032a5d2ac0
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Fri Feb 12 15:43:33 2010 -0800

    [Banshee.Metrics] Record whitelisted config options
    
    This captures everything from window size/position to file/folder name
    patterns, to whether replaygain is enabled.

 .../Banshee.Configuration/SchemaEntry.cs           |   15 ++++
 .../Banshee.Database/BansheeDbConnection.cs        |    4 +
 .../Banshee.Metrics/BansheeMetrics.cs              |   53 ++++++++-----
 .../Banshee.Metrics/Configuration.cs               |   80 ++++++++++++++++++++
 .../Banshee.Preferences/PreferenceService.cs       |    5 -
 src/Core/Banshee.Services/Banshee.Services.csproj  |    1 +
 src/Core/Banshee.Services/Makefile.am              |    1 +
 7 files changed, 135 insertions(+), 24 deletions(-)
---
diff --git a/src/Core/Banshee.Core/Banshee.Configuration/SchemaEntry.cs b/src/Core/Banshee.Core/Banshee.Configuration/SchemaEntry.cs
index 3a30333..c981516 100644
--- a/src/Core/Banshee.Core/Banshee.Configuration/SchemaEntry.cs
+++ b/src/Core/Banshee.Core/Banshee.Configuration/SchemaEntry.cs
@@ -30,6 +30,19 @@ using System;
 
 namespace Banshee.Configuration
 {
+    public static class SchemaEntry
+    {
+        public static event Action<string, string, object> SchemaAdded;
+
+        internal static void OnSchemaAdded (string ns, string key, object value)
+        {
+            var handler = SchemaAdded;
+            if (handler != null) {
+                handler (ns, key, value);
+            }
+        }
+    }
+
     public struct SchemaEntry<T> : IEquatable<SchemaEntry<T>>
     {
         public static SchemaEntry<T> Zero;
@@ -50,6 +63,8 @@ namespace Banshee.Configuration
             MaxValue = maxValue;
             ShortDescription = shortDescription;
             LongDescription = longDescription;
+
+            SchemaEntry.OnSchemaAdded (Namespace, Key, Get ());
         }
 
         public T Get ()
diff --git a/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs b/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
index 8848b86..6c32cd3 100644
--- a/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
+++ b/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
@@ -93,6 +93,10 @@ namespace Banshee.Database
                     RollbackTransaction ();
                 }
             }
+
+            if (Banshee.Metrics.BansheeMetrics.EnableCollection.Get ()) {
+                Banshee.Metrics.BansheeMetrics.Start ();
+            }
         }
 
         private void OptimizeDatabase ()
diff --git a/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs b/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs
index ac8685f..a3fa791 100644
--- a/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs
+++ b/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs
@@ -42,8 +42,7 @@ namespace Banshee.Metrics
     public class BansheeMetrics : IDisposable
     {
         private static BansheeMetrics banshee_metrics;
-
-        public BansheeMetrics Instance { get { return banshee_metrics; } }
+        public static BansheeMetrics Instance { get { return banshee_metrics; } }
 
         public static event System.Action Started;
         public static event System.Action Stopped;
@@ -72,7 +71,6 @@ namespace Banshee.Metrics
 
         private MetricsCollection metrics;
         private string id_key = "AnonymousUsageData.Userid";
-
         private Metric shutdown, duration, source_changed, sqlite_executed;
 
         private BansheeMetrics ()
@@ -88,6 +86,8 @@ namespace Banshee.Metrics
                 ServiceManager.DbConnection, "AnonymousUsageData"
             ));
 
+            Configuration.Start ();
+
             if (Application.ActiveClient != null && Application.ActiveClient.IsStarted) {
                 Initialize (null);
             } else {
@@ -116,13 +116,13 @@ namespace Banshee.Metrics
 
         private void AddMetrics ()
         {
-            Add ("Client",       () => Application.ActiveClient);
-            Add ("BuildHostCpu", () => Application.BuildHostCpu);
-            Add ("BuildHostOS",  () => Application.BuildHostOperatingSystem);
-            Add ("BuildTime",    () => Application.BuildTime);
-            Add ("BuildVendor",  () => Application.BuildVendor);
-            Add ("Version",      () => Application.Version);
-            Add ("StartedAt",    () => ApplicationContext.StartedAt);
+            Add ("Client",       Application.ActiveClient);
+            Add ("BuildHostCpu", Application.BuildHostCpu);
+            Add ("BuildHostOS",  Application.BuildHostOperatingSystem);
+            Add ("BuildTime",    Application.BuildTime);
+            Add ("BuildVendor",  Application.BuildVendor);
+            Add ("Version",      Application.Version);
+            Add ("StartedAt",    ApplicationContext.StartedAt);
 
             Console.WriteLine ("SourceMgr is null? {0}", ServiceManager.SourceManager == null);
             foreach (var src in ServiceManager.SourceManager.FindSources<PrimarySource> ()) {
@@ -147,32 +147,45 @@ namespace Banshee.Metrics
                 };
 
                 for (int i = 0; i < results.Length; i++) {
-                    metrics.Add (type_name, results[i], () => reader.Get<long> (i));
+                    Add (String.Format ("{0}/{1}", type_name, results[i]), reader.Get<long> (i));
                 }
                 reader.Dispose ();
             }
 
-            source_changed = Add ("ActiveSourceChanged", () => ServiceManager.SourceManager.ActiveSource.TypeName, true);
+            source_changed = Add ("ActiveSourceChanged", () => ServiceManager.SourceManager.ActiveSource.TypeName);
             ServiceManager.SourceManager.ActiveSourceChanged += OnActiveSourceChanged;
 
-            shutdown = Add ("ShutdownAt",  () => DateTime.Now, true);
-            duration = Add ("RunDuration", () => DateTime.Now - ApplicationContext.StartedAt, true);
+            shutdown = Add ("ShutdownAt",  () => DateTime.Now);
+            duration = Add ("RunDuration", () => DateTime.Now - ApplicationContext.StartedAt);
             Application.ShutdownRequested += OnShutdownRequested;
 
-            sqlite_executed = Add ("LongSqliteCommand", null, true);
+            sqlite_executed = Add ("LongSqliteCommand");
             HyenaSqliteCommand.CommandExecuted += OnSqliteCommandExecuted;
             HyenaSqliteCommand.RaiseCommandExecuted = true;
             HyenaSqliteCommand.RaiseCommandExecutedThresholdMs = 400;
+
+            /*ServiceManager.PlaybackController.
+                    public event EventHandler SourceChanged;
+            public event EventHandler NextSourceChanged;
+            public event EventHandler TrackStarted;
+            public event EventHandler Transition;
+            public event EventHandler<EventArgs<PlaybackShuffleMode>> ShuffleModeChanged;
+            public event EventHandler<EventArgs<PlaybackRepeatMode>> RepeatModeChanged;*/
         }
 
-        public Metric Add (string name, Func<object> func)
+        public Metric Add (string name)
         {
-            return Add (name, func, false);
+            return metrics.Add (String.Format ("Banshee/{0}", name));
         }
 
-        public Metric Add (string name, Func<object> func, bool isEventDriven)
+        public Metric Add (string name, object value)
         {
-            return metrics.Add ("Banshee", name, func, isEventDriven);
+            return metrics.Add (String.Format ("Banshee/{0}", name), value);
+        }
+
+        public Metric Add (string name, Func<object> func)
+        {
+            return metrics.Add (String.Format ("Banshee/{0}", name), func);
         }
 
         public void Dispose ()
@@ -182,6 +195,8 @@ namespace Banshee.Metrics
                 handler ();
             }
 
+            Configuration.Stop ();
+
             // Disconnect from events we're listening to
             ServiceManager.SourceManager.ActiveSourceChanged -= OnActiveSourceChanged;
             Application.ShutdownRequested -= OnShutdownRequested;
diff --git a/src/Core/Banshee.Services/Banshee.Metrics/Configuration.cs b/src/Core/Banshee.Services/Banshee.Metrics/Configuration.cs
new file mode 100644
index 0000000..929ddea
--- /dev/null
+++ b/src/Core/Banshee.Services/Banshee.Metrics/Configuration.cs
@@ -0,0 +1,80 @@
+//
+// Configuration.cs
+//
+// Author:
+//   Gabriel Burt <gabriel burt gmail com>
+//
+// Copyright (c) 2010 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+
+using Banshee.Configuration;
+
+namespace Banshee.Metrics
+{
+    public class Configuration
+    {
+        public static void Start ()
+        {
+            SchemaEntry.SchemaAdded += OnSchemaAdded;
+        }
+
+        public static void Stop ()
+        {
+            SchemaEntry.SchemaAdded -= OnSchemaAdded;
+        }
+
+        private static void OnSchemaAdded (string ns, string key, object value)
+        {
+            if (Array.BinarySearch<string> (keys, key) >= 0 ||
+                Array.BinarySearch<string> (ns_keys, String.Format ("{0}/{1}", ns, key)) >= 0)
+            {
+                BansheeMetrics.Instance.Add (
+                    String.Format ("Configuration/{0}/{1}", ns, key), value
+                );
+            }
+        }
+
+        static Configuration ()
+        {
+            // Prep for BinarySearch
+            Array.Sort<string> (keys);
+            Array.Sort<string> (ns_keys);
+        }
+
+        // Whitelists
+        static string [] keys = new string [] {
+            "folder_pattern", "file_pattern", "copy_on_import", "move_on_info_save", "write_metadata", "write_rating",
+            "replay_gain_enabled", "io_provider", "show_context_pane", "last_context_page", "child_sort_id",
+            "separate_by_type", "expanded"
+            //"current_filters", // not useful (yet, at least)
+        };
+
+        static string [] ns_keys = new string [] {
+            "playback/repeat_mode", "playback/shuffle_mode", "player_window/source_view_width", "player_window/show_cover_art",
+            "player_window/width", "player_window/height", "player_window/x_pos", "player_window/y_pos",
+            "player_window/maximized", "player_window/source_view_row_height", "player_window/source_view_row_padding", "browser/visible",
+            "browser/position", "player_engine/equalizer_enabled", "player_engine/equalizer_preset", "plugins.play_queue/clear_on_quit",
+            "plugins.play_queue/populate_mode", "plugins.play_queue/played_songs_number", "plugins.play_queue/upcoming_songs_number",
+            "core/make_default", "core/remember_make_default", "core/ever_asked_make_default"
+        };
+    }
+}
diff --git a/src/Core/Banshee.Services/Banshee.Preferences/PreferenceService.cs b/src/Core/Banshee.Services/Banshee.Preferences/PreferenceService.cs
index bd0e4ee..fdba642 100644
--- a/src/Core/Banshee.Services/Banshee.Preferences/PreferenceService.cs
+++ b/src/Core/Banshee.Services/Banshee.Preferences/PreferenceService.cs
@@ -73,11 +73,6 @@ namespace Banshee.Preferences
                     Banshee.Metrics.BansheeMetrics.Stop ();
                 }
             };
-
-            // TODO this should probably be elsewhere
-            if (Banshee.Metrics.BansheeMetrics.EnableCollection.Get ()) {
-                Banshee.Metrics.BansheeMetrics.Start ();
-            }
         }
 
         public void RequestWidgetAdapters ()
diff --git a/src/Core/Banshee.Services/Banshee.Services.csproj b/src/Core/Banshee.Services/Banshee.Services.csproj
index c19319f..ba9367d 100644
--- a/src/Core/Banshee.Services/Banshee.Services.csproj
+++ b/src/Core/Banshee.Services/Banshee.Services.csproj
@@ -320,6 +320,7 @@
     <Compile Include="Banshee.Collection.Database\ISearchable.cs" />
     <Compile Include="Banshee.Library\MusicFileNamePattern.cs" />
     <Compile Include="Banshee.Metrics\BansheeMetrics.cs" />
+    <Compile Include="Banshee.Metrics\Configuration.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Banshee.Services.addin.xml">
diff --git a/src/Core/Banshee.Services/Makefile.am b/src/Core/Banshee.Services/Makefile.am
index 28f9073..e04afc8 100644
--- a/src/Core/Banshee.Services/Makefile.am
+++ b/src/Core/Banshee.Services/Makefile.am
@@ -123,6 +123,7 @@ SOURCES =  \
 	Banshee.Metadata/SaveTrackMetadataService.cs \
 	Banshee.Metadata/Tests/TaglibReadWriteTests.cs \
 	Banshee.Metrics/BansheeMetrics.cs \
+	Banshee.Metrics/Configuration.cs \
 	Banshee.Networking/INetworkAvailabilityService.cs \
 	Banshee.Networking/Network.cs \
 	Banshee.Networking/NetworkManager.cs \



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