banshee r2957 - in branches/banshee/stable: . src/Core/Banshee.Base/Gui



Author: abock
Date: Tue Jan  8 23:06:49 2008
New Revision: 2957
URL: http://svn.gnome.org/viewvc/banshee?rev=2957&view=rev

Log:
2008-01-08  Aaron Bockover  <abock gnome org>

    * src/Core/Banshee.Base/Gui/TrackEditor.cs: Parse simple text pastes to
    fill out multiple track titles; e.g. allow pastes from amazon.com to
    populate an entire album automatically



Modified:
   branches/banshee/stable/ChangeLog
   branches/banshee/stable/src/Core/Banshee.Base/Gui/TrackEditor.cs

Modified: branches/banshee/stable/src/Core/Banshee.Base/Gui/TrackEditor.cs
==============================================================================
--- branches/banshee/stable/src/Core/Banshee.Base/Gui/TrackEditor.cs	(original)
+++ branches/banshee/stable/src/Core/Banshee.Base/Gui/TrackEditor.cs	Tue Jan  8 23:06:49 2008
@@ -27,9 +27,11 @@
  */
 
 using System;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+
 using Gtk;
 using Glade;
-using System.Collections.Generic;
 using Mono.Unix;
 
 using Banshee.Base;
@@ -105,6 +107,18 @@
 
     public class TrackEditor : GladeWindow
     {
+        private struct PasteParseItem
+        {
+            public int TrackNumber;
+            public string Title;
+            
+            public PasteParseItem (int trackNumber, string title)
+            {
+                this.TrackNumber = trackNumber;
+                this.Title = title;
+            }
+        }
+    
         [Widget] private Button CancelButton;
         [Widget] private Button SaveButton;
         [Widget] private Button Previous;
@@ -189,6 +203,8 @@
             Genre.Entry.Changed += OnValueEdited;
             rating_entry.Changed += OnValueEdited;
             
+            Title.TextInserted += OnTitleTextInsertedEvent;
+            
             ListStore genre_model = new ListStore(typeof(string));
             Genre.Model = genre_model;
             Genre.TextColumn = 0;
@@ -488,6 +504,27 @@
             }
         }
         
+        private string pasted_text = null;
+        
+        private void OnTitleTextInsertedEvent (object o, TextInsertedArgs args)
+        {
+            if (currentIndex == 0 && args.Text.Length > 2 && (args.Text.Contains ("\n") || 
+                args.Text.Contains ("\t") || args.Text.Contains ("\r"))) {
+                int index = 0;
+                foreach (PasteParseItem item in ParsePaste (args.Text)) {
+                    if (index < TrackSet.Count) {
+                        if (index == 0) {
+                            Title.Text = item.Title;
+                        }
+                        
+                        TrackSet[index].Title = item.Title;
+                        TrackSet[index].TrackNumber = (uint)(item.TrackNumber > 0 ? item.TrackNumber : index + 1);
+                        index++;    
+                    }
+                }
+            }
+        }
+        
         private string last_path = null;
         
         private void OnCoverButtonClicked(object o, EventArgs args)
@@ -572,6 +609,25 @@
             Window.Destroy();
         }
         
+        private static IEnumerable<PasteParseItem> ParsePaste (string input)
+        {
+            foreach (string track in Regex.Split (input, @"[\t\n\r]")) {
+                int track_number = 0;
+                string title = track.Trim ();
+                
+                try {
+                    Match match = Regex.Match (title, @"^([0-9]+)\.(.*)$");
+                    if (match.Groups.Count == 3) {
+                        track_number = Int32.Parse (match.Groups[1].Captures[0].Value);
+                        title = match.Groups[2].Captures[0].Value;
+                    }
+                } catch {
+                }
+                
+                yield return new PasteParseItem (track_number, title.Trim ());
+            }
+        }
+        
         private void SaveTrack(EditorTrack track, bool writeToDatabase)
         {
             track.Save();



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