banshee r3836 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.SmartPlaylist src/Dap/Banshee.Dap src/Dap/Banshee.Dap/Banshee.Dap src/Libraries/Hyena.Gui src/Libraries/Hyena.Gui/Hyena.Gui src/Libraries/Hyena.Gui/Hyena.Query.Gui



Author: abock
Date: Mon Apr 28 19:39:04 2008
New Revision: 3836
URL: http://svn.gnome.org/viewvc/banshee?rev=3836&view=rev

Log:
2008-04-28  Aaron Bockover  <abock gnome org>

    * src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs:
    Make ConditionSql virtual and add a protected setter; make CanUnmap virtual

    * src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs: Add Music and Video
    group sources; delete all smart playlists and entires associated with
    the primary source when starting and disposing

    * src/Dap/Banshee.Dap/Banshee.Dap/MediaGroupSource.cs: Base source for
    media groups, extends SmartPlaylistSource

    * src/Dap/Banshee.Dap/Banshee.Dap/MusicGroupSource.cs:
    * src/Dap/Banshee.Dap/Banshee.Dap/VideoGroupSource.cs: A source to show
    all music on the device and one for all video

    * src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs: Do not implement
    IDiskUsageReporter - MediaGroupSource does this now

    * src/Libraries/Hyena.Gui/Hyena.Gui/TestModuleAttribute.cs: Attribute
    for flagging UI test modules

    * src/Libraries/Hyena.Gui/Hyena.Gui/TestModuleRunner.cs: Show a list
    of UI test modules and run them when activated

    * src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryDebugger.cs: A UI test
    module for playing with the query parser



Added:
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/MediaGroupSource.cs
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/MusicGroupSource.cs
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/VideoGroupSource.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/TestModuleAttribute.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/TestModuleRunner.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryDebugger.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/Makefile.am
   trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap.mdp
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs
   trunk/banshee/src/Dap/Banshee.Dap/Makefile.am
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp
   trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am

Modified: trunk/banshee/Makefile.am
==============================================================================
--- trunk/banshee/Makefile.am	(original)
+++ trunk/banshee/Makefile.am	Mon Apr 28 19:39:04 2008
@@ -74,6 +74,14 @@
 	make test \
 	popd;
 
+hg:
+	pushd bin; \
+	echo "class Entry { static void Main () { Hyena.Gui.TestModuleRunner.Run (); } }" > tester.cs; \
+	gmcs -r:Hyena.Gui.dll tester.cs; \
+	mono tester.exe; \
+	rm tester.*; \
+	popd; 
+
 clean-local:
 	rm -rf $(top_builddir)/bin
 

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs	Mon Apr 28 19:39:04 2008
@@ -119,8 +119,9 @@
         }
 
         private string condition_sql;
-        public string ConditionSql {
+        public virtual string ConditionSql {
             get { return condition_sql; }
+            protected set { condition_sql = value; }
         }
 
         private string condition_xml;
@@ -352,7 +353,7 @@
             return true;
         }
 
-        public bool CanUnmap {
+        public virtual bool CanUnmap {
             get { return true; }
         }
 

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap.mdp
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap.mdp	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap.mdp	Mon Apr 28 19:39:04 2008
@@ -14,6 +14,9 @@
     <File name="Banshee.Dap.addin.xml" subtype="Code" buildaction="EmbedAsResource" />
     <File name="Banshee.Dap.Gui/DapPropertiesDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Dap/InvalidDeviceException.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Dap/MediaGroupSource.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Dap/VideoGroupSource.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Dap/MusicGroupSource.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="True" refto="Banshee.Core" />

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs	Mon Apr 28 19:39:04 2008
@@ -33,6 +33,7 @@
 using Mono.Unix;
 
 using Hyena;
+using Hyena.Data.Sqlite;
 using Banshee.Base;
 using Banshee.ServiceStack;
 using Banshee.Sources;
@@ -71,6 +72,20 @@
         {
             PurgeTracks ();
         }
+        
+        protected override void PurgeTracks ()
+        {
+            base.PurgeTracks ();
+            
+            ServiceManager.DbConnection.Execute (new HyenaSqliteCommand (@"
+                BEGIN TRANSACTION;
+                    DELETE FROM CoreSmartPlaylistEntries WHERE SmartPlaylistID IN
+                        (SELECT SmartPlaylistID FROM CoreSmartPlaylists WHERE PrimarySourceID = ?);
+                    DELETE FROM CoreSmartPlaylists WHERE PrimarySourceID = ?;   
+                COMMIT TRANSACTION",
+                DbId, DbId
+            ));
+        }
 
 #region Source
 
@@ -101,7 +116,7 @@
         
         public override void AddChildSource (Source child)
         {
-            if (child is Banshee.Playlist.AbstractPlaylistSource) {
+            if (child is Banshee.Playlist.AbstractPlaylistSource && !(child is MediaGroupSource)) {
                 Log.Information ("Note: playlists added to digital audio players within Banshee are not yet saved to the device.", true);
             }
             
@@ -112,6 +127,10 @@
             get { return true; }
         }
         
+        public override bool CanActivate {
+            get { return false; }
+        }
+
 #endregion
         
 #region Track Management/Syncing   
@@ -128,6 +147,12 @@
             LoadFromDevice ();
             OnTracksAdded ();
             HideStatus ();
+            
+            ThreadAssist.ProxyToMain (delegate {
+                AddChildSource (new MusicGroupSource (this));
+                AddChildSource (new VideoGroupSource (this));
+                Expanded = true;
+            });
         }
 
         protected virtual void LoadFromDevice ()

Added: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/MediaGroupSource.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/MediaGroupSource.cs	Mon Apr 28 19:39:04 2008
@@ -0,0 +1,76 @@
+//
+// MediaGroupSource.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 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 Hyena.Query;
+using Banshee.Query;
+using Banshee.Sources;
+using Banshee.Collection;
+using Banshee.SmartPlaylist;
+
+namespace Banshee.Dap
+{
+    public abstract class MediaGroupSource : SmartPlaylistSource, IDiskUsageReporter
+    {
+        private DapSource parent;
+        
+        public MediaGroupSource (DapSource parent, string name) : base (name, parent.DbId)
+        {
+            this.parent = parent;
+        }
+        
+        public override string ConditionSql {
+            get { return base.ConditionSql; }
+            protected set { 
+                base.ConditionSql = value;
+                Save ();
+            }
+        }
+        
+        public override bool CanRename {
+            get { return false; }
+        }
+        
+        public override bool CanUnmap {
+            get { return false; }
+        }
+        
+        public override bool HasProperties {
+            get { return false; }
+        }
+
+        public long BytesUsed {
+            get { return parent.BytesUsed; }
+        }
+
+        public long BytesCapacity {
+            get { return parent.BytesCapacity; }
+        }
+    }
+}

Added: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/MusicGroupSource.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/MusicGroupSource.cs	Mon Apr 28 19:39:04 2008
@@ -0,0 +1,47 @@
+//
+// VideoGroupSource.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 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 Mono.Unix;
+
+using Banshee.Collection;
+
+namespace Banshee.Dap
+{
+    public class MusicGroupSource : MediaGroupSource
+    {
+        public MusicGroupSource (DapSource parent) : base (parent, Catalog.GetString ("Music"))
+        {
+            Properties.Remove ("Icon.Name");
+            Properties.SetStringList ("Icon.Name", Banshee.ServiceStack.ServiceManager.SourceManager.MusicLibrary.Properties.GetStringList ("Icon.Name"));
+            
+            ConditionSql = String.Format ("(CoreTracks.Attributes & {0}) == {0} And (CoreTracks.Attributes & {1}) == 0",
+                (int)TrackMediaAttributes.AudioStream, (int)TrackMediaAttributes.VideoStream);
+        }
+    }
+}

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs	Mon Apr 28 19:39:04 2008
@@ -42,7 +42,7 @@
 
 namespace Banshee.Dap
 {
-    public abstract class RemovableSource : PrimarySource, IUnmapableSource, IImportSource, IDiskUsageReporter
+    public abstract class RemovableSource : PrimarySource, IUnmapableSource, IImportSource
     {
         protected RemovableSource () : base ()
         {

Added: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/VideoGroupSource.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/VideoGroupSource.cs	Mon Apr 28 19:39:04 2008
@@ -0,0 +1,47 @@
+//
+// VideoGroupSource.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 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 Mono.Unix;
+
+using Banshee.Collection;
+
+namespace Banshee.Dap
+{
+    public class VideoGroupSource : MediaGroupSource
+    {
+        public VideoGroupSource (DapSource parent) : base (parent, Catalog.GetString ("Videos"))
+        {
+            Properties.Remove ("Icon.Name");
+            Properties.SetStringList ("Icon.Name", Banshee.ServiceStack.ServiceManager.SourceManager.VideoLibrary.Properties.GetStringList ("Icon.Name"));
+            
+            ConditionSql = String.Format ("(CoreTracks.Attributes & {0}) == {0}",
+                (int)(TrackMediaAttributes.AudioStream | TrackMediaAttributes.VideoStream));
+        }
+    }
+}

Modified: trunk/banshee/src/Dap/Banshee.Dap/Makefile.am
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Makefile.am	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Makefile.am	Mon Apr 28 19:39:04 2008
@@ -8,7 +8,10 @@
 	Banshee.Dap/DapService.cs \
 	Banshee.Dap/DapSource.cs \
 	Banshee.Dap/InvalidDeviceException.cs \
-	Banshee.Dap/RemovableSource.cs
+	Banshee.Dap/MediaGroupSource.cs \
+	Banshee.Dap/MusicGroupSource.cs \
+	Banshee.Dap/RemovableSource.cs \
+	Banshee.Dap/VideoGroupSource.cs
 
 RESOURCES = Banshee.Dap.addin.xml
 

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp	Mon Apr 28 19:39:04 2008
@@ -69,6 +69,9 @@
     <File name="Hyena.Gui/CompositeUtils.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Gui/TooltipSetter.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Widgets/WrapLabel.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Query.Gui/QueryDebugger.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Gui/TestModuleAttribute.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Gui/TestModuleRunner.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
@@ -78,6 +81,7 @@
     <ProjectReference type="Project" localcopy="False" refto="Hyena" />
     <ProjectReference type="Gac" localcopy="True" refto="pango-sharp, Version=2.8.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
     <ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+    <ProjectReference type="Gac" localcopy="True" refto="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   </References>
   <Deployment.LinuxDeployData generateScript="False" />
   <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am">

Added: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/TestModuleAttribute.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/TestModuleAttribute.cs	Mon Apr 28 19:39:04 2008
@@ -0,0 +1,46 @@
+//
+// TestModuleAttribute.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 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;
+
+namespace Hyena.Gui
+{
+    internal class TestModuleAttribute : Attribute
+    {
+        private string name;
+        public string Name {    
+            get { return name; }
+            set { name = value; }
+        }
+        
+        public TestModuleAttribute (string name) 
+        {
+            this.name = name;
+        }
+    }
+}

Added: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/TestModuleRunner.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/TestModuleRunner.cs	Mon Apr 28 19:39:04 2008
@@ -0,0 +1,101 @@
+//
+// TestModuleRunner.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 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 System.Reflection;
+using Gtk;
+
+namespace Hyena.Gui
+{
+    public class TestModuleRunner : Window
+    {
+        public static void Run ()
+        {
+            Application.Init ();
+            TestModuleRunner runner = new TestModuleRunner ();
+            runner.DeleteEvent += delegate { Application.Quit (); };
+            runner.ShowAll ();
+            Application.Run ();
+        }
+    
+        private TreeStore store;
+    
+        public TestModuleRunner () : base ("Hyena.Gui Module Tester")
+        {
+            SetSizeRequest (-1, 300);
+            Move (100, 100);
+            
+            BuildModuleList ();
+            BuildView ();
+        }
+        
+        private void BuildModuleList ()
+        {
+            store = new TreeStore (typeof (string), typeof (Type));
+            
+            foreach (Type type in Assembly.GetExecutingAssembly ().GetTypes ()) {
+                foreach (TestModuleAttribute attr in type.GetCustomAttributes (typeof (TestModuleAttribute), false)) {
+                    store.AppendValues (attr.Name, type);
+                }
+            }
+        }
+        
+        private void BuildView ()
+        {
+            VBox box = new VBox ();
+            Add (box);
+            
+            ScrolledWindow sw = new ScrolledWindow ();
+            sw.HscrollbarPolicy = PolicyType.Never;
+            
+            TreeView view = new TreeView ();
+            view.RowActivated += delegate (object o, RowActivatedArgs args) {
+                TreeIter iter;
+                if (store.GetIter (out iter, args.Path)) {
+                    Type type = (Type)store.GetValue (iter, 1);
+                    Window window = (Window)Activator.CreateInstance (type);
+                    window.WindowPosition = WindowPosition.Center;
+                    window.DeleteEvent += delegate { window.Destroy (); };
+                    window.Show ();
+                }
+            };
+            view.Model = store;
+            view.AppendColumn ("Module", new CellRendererText (), "text", 0);
+            
+            sw.Add (view);
+            box.PackStart (sw, true, true, 0);
+            sw.ShowAll ();
+            
+            Button button = new Button (Stock.Quit);
+            button.Clicked += delegate { Destroy (); Application.Quit (); };
+            box.PackStart (button, false, false, 0);
+            
+            box.ShowAll ();
+        }
+    }
+}

Added: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryDebugger.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryDebugger.cs	Mon Apr 28 19:39:04 2008
@@ -0,0 +1,139 @@
+//
+// QueryDebugger.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 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 System.IO;
+using System.Xml;
+using System.Reflection;
+using Gtk;
+
+using Hyena.Gui;
+using Hyena.Query;
+
+namespace Hyena.Query.Gui
+{
+    [TestModule ("Query Debugger")]
+    public class QueryDebugger : Window
+    {
+        private TextView input;
+        private TextView sql;
+        private TextView xml;
+        
+        private QueryFieldSet query_field_set;
+    
+        public QueryDebugger () : base ("Hyena.Query Debugger")
+        {
+            SetDefaultSize (800, 600);
+            
+            VBox input_box = new VBox ();
+            input_box.Spacing = 8;
+            ScrolledWindow sw = new ScrolledWindow ();
+            sw.ShadowType = ShadowType.In;
+            sw.HscrollbarPolicy = PolicyType.Never;
+            input = new TextView ();
+            input.AcceptsTab = false;
+            input.KeyReleaseEvent += delegate (object o, KeyReleaseEventArgs args) {
+                if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter) {
+                    input.Buffer.Text = input.Buffer.Text.Trim ();
+                    OnParseUserQuery (null, EventArgs.Empty);
+                }
+            };
+            input.WrapMode = WrapMode.Word;
+            sw.Add (input);
+            input_box.PackStart (sw, true, true, 0);
+            HBox button_box = new HBox ();
+            Button parse = new Button ("Parse as User Query");
+            parse.Clicked += OnParseUserQuery;
+            button_box.PackStart (parse, false, false, 0);
+            input_box.PackStart (button_box, false, false, 0);
+            
+            HBox output_box = new HBox ();
+            output_box.Spacing = 8;
+            sw = new ScrolledWindow ();
+            sw.ShadowType = ShadowType.In;
+            sw.HscrollbarPolicy = PolicyType.Never;
+            sql = new TextView ();
+            sql.WrapMode = WrapMode.Word;
+            sw.Add (sql);
+            output_box.PackStart (sw, true, true, 0);
+            sw = new ScrolledWindow ();
+            sw.ShadowType = ShadowType.In;
+            sw.HscrollbarPolicy = PolicyType.Never;
+            xml = new TextView ();
+            xml.WrapMode = WrapMode.Word;
+            sw.Add (xml);
+            output_box.PackStart (sw, true, true, 0);
+            
+            VPaned pane = new VPaned ();
+            pane.Add1 (input_box);
+            pane.Add2 (output_box);
+            pane.Position = 100;
+            
+            Add (pane);
+            pane.ShowAll ();
+            
+            input.HasFocus = true;
+            
+            LoadQueryFieldSet ();
+        }
+        
+        private void LoadQueryFieldSet ()
+        {
+            Assembly asm = Assembly.LoadFile ("Banshee.Services.dll");
+            Type t = asm.GetType ("Banshee.Query.BansheeQuery");
+            FieldInfo f = t.GetField ("FieldSet", BindingFlags.Public | BindingFlags.Static);
+            query_field_set = (QueryFieldSet)f.GetValue (null);
+        }
+        
+        private StreamReader StringToStream (string s)
+        {
+            return new StreamReader (new MemoryStream (System.Text.Encoding.UTF8.GetBytes (s)));
+        }
+        
+        private void OnParseUserQuery (object o, EventArgs args)
+        {
+            UserQueryParser parser = new UserQueryParser ();
+            parser.InputReader = StringToStream (input.Buffer.Text);
+            QueryNode node = parser.BuildTree (query_field_set);
+            
+            sql.Buffer.Text = node.ToSql (query_field_set) ?? String.Empty;
+            
+            XmlDocument doc = new XmlDocument ();
+            doc.LoadXml (node.ToXml (query_field_set));
+            
+            MemoryStream s = new MemoryStream ();
+            XmlTextWriter w = new XmlTextWriter (s, System.Text.Encoding.UTF8);
+            w.Formatting = Formatting.Indented;
+            doc.WriteContentTo (w);
+            w.Flush ();
+            s.Flush ();
+            s.Position = 0;
+            xml.Buffer.Text = new StreamReader (s).ReadToEnd ();
+        }
+    }
+}

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am	Mon Apr 28 19:39:04 2008
@@ -39,12 +39,15 @@
 	Hyena.Gui/GtkUtilities.cs \
 	Hyena.Gui/PangoCairoHelper.cs \
 	Hyena.Gui/ShadingTestWindow.cs \
+	Hyena.Gui/TestModuleAttribute.cs \
+	Hyena.Gui/TestModuleRunner.cs \
 	Hyena.Gui/TooltipSetter.cs \
 	Hyena.Query.Gui/DateQueryValueEntry.cs \
 	Hyena.Query.Gui/FileSizeQueryValueEntry.cs \
 	Hyena.Query.Gui/IntegerQueryValueEntry.cs \
 	Hyena.Query.Gui/NullQueryValueEntry.cs \
 	Hyena.Query.Gui/QueryBox.cs \
+	Hyena.Query.Gui/QueryDebugger.cs \
 	Hyena.Query.Gui/QueryLimitBox.cs \
 	Hyena.Query.Gui/QueryTermBox.cs \
 	Hyena.Query.Gui/QueryTermsBox.cs \



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