Permalink
Browse files

2005-06-21 James Willcox <snorp@snorp.net>

        * src/SongDatabase.cs: add events for save progress, instead of
        using a callback passed into the Save method.
        * ui/*: added a new assembly which contains gtk# widgets that are
        handy for using with ipod-sharp.  Currently it contains a progress
        dialog that shows save progress.
        * ipod-sharp.snk: moved from src/

svn path=/trunk/ipod-sharp/; revision=46318
  • Loading branch information...
2 parents 4821fab + 549743f commit 44458f5e1c2d7bb1d81596afd06a843edf22a5e0 James Willcox committed Jun 21, 2005
Showing with 195 additions and 16 deletions.
  1. +9 −0 ChangeLog
  2. +2 −2 Makefile.am
  3. +2 −0 configure.in
  4. 0 {src → }/ipod-sharp.snk
  5. +5 −1 src/Device.cs
  6. +1 −1 src/Makefile.am
  7. +22 −12 src/SongDatabase.cs
  8. +1 −0 tests/mktest.sh
  9. +29 −0 ui/AssemblyInfo.cs
  10. +21 −0 ui/Makefile.am
  11. +103 −0 ui/ProgressDialog.cs
View
9 ChangeLog
@@ -1,3 +1,12 @@
+2005-06-21 James Willcox <snorp@snorp.net>
+
+ * src/SongDatabase.cs: add events for save progress, instead of using
+ a callback passed into the Save method.
+ * ui/*: added a new assembly which contains gtk# widgets that are
+ handy for using with ipod-sharp. Currently it contains a progress
+ dialog that shows save progress.
+ * ipod-sharp.snk: moved from src/
+
2005-06-18 James Willcox <snorp@snorp.net>
* src/ipod-sharp.dll.config: added
View
4 Makefile.am
@@ -1,8 +1,8 @@
-SUBDIRS = src tools
+SUBDIRS = src ui tools
if BUILD_TESTS
SUBDIRS += tests
endif
pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = ipod-sharp.pc
+pkgconfig_DATA = ipod-sharp.pc ipod-sharp-ui.pc
View
2 configure.in
@@ -60,7 +60,9 @@ fi
AC_OUTPUT([
Makefile
ipod-sharp.pc
+ipod-sharp-ui.pc
src/Makefile
+ui/Makefile
tools/Makefile
tests/Makefile
])
View
0 src/ipod-sharp.snk → ipod-sharp.snk
File renamed without changes.
View
6 src/Device.cs
@@ -37,6 +37,7 @@ public class Device : GLib.Object {
private ArrayList equalizers = new ArrayList ();
private EqualizerContainerRecord eqsrec;
+ private SongDatabase songs;
private string EqDbPath {
get { return this.MountPoint + "/iPod_Control/iTunes/iTunesEQPresets"; }
@@ -123,7 +124,10 @@ public class Device : GLib.Object {
throw new DeviceException (this, "Cannot get song database, as this device is not an iPod");
}
- return new SongDatabase (this);
+ if (songs == null)
+ songs = new SongDatabase (this);
+
+ return songs;
}
}
View
2 src/Makefile.am
@@ -26,7 +26,7 @@ doc_DATA = \
all: $(ASSEMBLY)
$(ASSEMBLY): $(ASSEMBLY_SOURCES)
- $(MCS) $(MCS_FLAGS) -keyfile:$(srcdir)/ipod-sharp.snk -target:library -o $@ $(ASSEMBLY_SOURCES) -r:Mono.Posix -pkg:gtk-sharp-2.0
+ $(MCS) $(MCS_FLAGS) -keyfile:$(top_srcdir)/ipod-sharp.snk -target:library -o $@ $(ASSEMBLY_SOURCES) -r:Mono.Posix -pkg:gtk-sharp-2.0
update-docs: $(ASSEMBLY)
$(DOC_UPDATER) -assembly:$(ASSEMBLY) -path:en
View
34 src/SongDatabase.cs
@@ -838,6 +838,10 @@ public class SongDatabase {
private Device device;
+ public event EventHandler SaveStarted;
+ public event StatusHandler SaveProgressChanged;
+ public event EventHandler SaveEnded;
+
private string SongDbPath {
get { return device.MountPoint + "/iPod_Control/iTunes/iTunesDB"; }
}
@@ -846,6 +850,10 @@ public class SongDatabase {
get { return device.MountPoint + "/iPod_Control/Music/" + MusicFolder; }
}
+ private string PlayCountsPath {
+ get { return device.MountPoint + "/iPod_Control/iTunes/Play Counts"; }
+ }
+
public Song[] Songs {
get {
return (Song[]) songs.ToArray (typeof (Song));
@@ -876,12 +884,10 @@ public class SongDatabase {
}
private void LoadPlayCounts () {
- string path = device.MountPoint + "/iPod_Control/iTunes/Play Counts";
-
- if (!File.Exists (path))
+ if (!File.Exists (PlayCountsPath))
return;
- using (BinaryReader reader = new BinaryReader (File.Open (path, FileMode.Open))) {
+ using (BinaryReader reader = new BinaryReader (File.Open (PlayCountsPath, FileMode.Open))) {
byte[] header = reader.ReadBytes (96);
int entryLength = BitConverter.ToInt32 (header, 8);
@@ -1001,13 +1007,12 @@ public class SongDatabase {
}
public void Save () {
- Save (null);
- }
-
- public void Save (StatusHandler handler) {
CheckFreeSpace ();
+ if (SaveStarted != null)
+ SaveStarted (this, new EventArgs ());
+
// Back up the current song db
File.Copy (SongDbPath, SongDbPath + ".bak", true);
@@ -1028,20 +1033,25 @@ public class SongDatabase {
int completed = 0;
foreach (Song song in songsToAdd) {
- if (handler != null)
- handler (this, song, completed++, songsToAdd.Count);
+ if (SaveProgressChanged != null)
+ SaveProgressChanged (this, song, completed++, songsToAdd.Count);
string dest = GetFilesystemPath (song.Track.GetDetail (DetailType.Location).Value);
File.Copy (song.Filename, dest, true);
}
- if (handler != null)
- handler (this, null, songsToAdd.Count, songsToAdd.Count);
+ // The play count file is invalid now, so we'll remove it (even though the iPod would anyway)
+ if (File.Exists (PlayCountsPath))
+ File.Delete (PlayCountsPath);
+
} catch (Exception e) {
// rollback the song db
File.Copy (SongDbPath + ".bak", SongDbPath, true);
throw e;
+ } finally {
+ if (SaveEnded != null)
+ SaveEnded (this, new EventArgs ());
}
}
View
1 tests/mktest.sh
@@ -17,6 +17,7 @@ fi;
rm -rf ipod-test-db
mkdir -p ipod-test-db/iPod_Control &&
+echo "Making test tarball '$2' from device '$1'" &&
cp -R $1/iPod_Control/iTunes ipod-test-db/iPod_Control &&
cp -R $1/iPod_Control/Device ipod-test-db/iPod_Control &&
tar cvfz $2 ipod-test-db 2>&1 > /dev/null &&
View
29 ui/AssemblyInfo.cs
@@ -0,0 +1,29 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+//
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly: AssemblyTitle("ipod-sharp-ui")]
+[assembly: AssemblyDescription("GTK+ widgets useful with ipod-sharp")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("(C) 2005 James Willcox <snorp@snorp.net>")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("0.0.1")]
View
21 ui/Makefile.am
@@ -0,0 +1,21 @@
+
+MCS_FLAGS = -g
+
+ASSEMBLY = ipod-sharp-ui.dll
+
+ASSEMBLY_SOURCES = \
+ $(srcdir)/AssemblyInfo.cs \
+ $(srcdir)/ProgressDialog.cs
+
+all: $(ASSEMBLY)
+
+$(ASSEMBLY): $(ASSEMBLY_SOURCES)
+ $(MCS) -keyfile:$(top_srcdir)/ipod-sharp.snk -target:library -o $@ $(ASSEMBLY_SOURCES) -r:$(top_srcdir)/src/ipod-sharp.dll -pkg:gtk-sharp-2.0
+
+install-data-hook:
+ $(GACUTIL) /i $(ASSEMBLY) /package $(PACKAGE) /gacdir $(libdir) /root $(DESTDIR)$(libdir)
+
+EXTRA_DIST = \
+ $(ASSEMBLY_SOURCES)
+
+CLEANFILES = $(ASSEMBLY)
View
103 ui/ProgressDialog.cs
@@ -0,0 +1,103 @@
+using System;
+using Gtk;
+using GLib;
+
+namespace IPod {
+
+ public class ProgressDialog : Dialog {
+
+ private SongDatabase db;
+ private Label label;
+ private ProgressBar bar;
+ private ThreadNotify notify;
+
+ private bool visible;
+ private double fraction;
+ private string message;
+
+ public SongDatabase SongDatabase {
+ get { return db; }
+ set {
+ if (db != null) {
+ // disconnect
+ db.SaveStarted -= OnSaveStarted;
+ db.SaveProgressChanged -= OnSaveProgressChanged;
+ db.SaveEnded -= OnSaveEnded;
+ }
+
+ db = value;
+
+ if (db != null) {
+ // connect
+ db.SaveStarted += OnSaveStarted;
+ db.SaveProgressChanged += OnSaveProgressChanged;
+ db.SaveEnded += OnSaveEnded;
+ }
+ }
+ }
+
+ public ProgressDialog (Window parent) : base () {
+ this.Title = "Updating iPod...";
+ this.HasSeparator = false;
+ this.TransientFor = parent;
+ this.DefaultWidth = 400;
+
+ VBox vbox = new VBox (false, 6);
+ vbox.BorderWidth = 6;
+
+ HBox hbox = new HBox (false, 6);
+ hbox.PackStart (new Image (Stock.DialogInfo, IconSize.Dialog), false, false, 0);
+
+ label = new Label ("");
+ label.Xalign = 0.0f;
+ label.UseMarkup = true;
+ label.Ellipsize = Pango.EllipsizeMode.Middle;
+ hbox.PackStart (label, true, true, 0);
+
+ vbox.PackStart (hbox, true, false, 0);
+
+ bar = new ProgressBar ();
+ vbox.PackStart (bar, true, false, 0);
+
+ VBox.PackStart (vbox, false, false, 0);
+ VBox.ShowAll ();
+
+ notify = new ThreadNotify (new ReadyEvent (OnNotify));
+ }
+
+ private void OnSaveStarted (object o, EventArgs args) {
+ visible = true;
+ message = "<b>Preparing...</b>";
+ notify.WakeupMain ();
+ }
+
+ private void OnSaveProgressChanged (SongDatabase db, Song song,
+ int current, int total) {
+ lock (this) {
+ message = String.Format ("<b>Adding '{0}' ({1} of {2})</b>",
+ GLib.Markup.EscapeText (song.Title),
+ current, total);
+ fraction = (double) current / (double) total;
+ notify.WakeupMain ();
+ }
+ }
+
+ private void OnSaveEnded (object o, EventArgs args) {
+ visible = false;
+ notify.WakeupMain ();
+ }
+
+ private void OnNotify () {
+ lock (this) {
+ if (this.visible && !Visible)
+ Show ();
+ else if (!this.visible && Visible)
+ Hide ();
+
+ label.Markup = message;
+ bar.Fraction = fraction;
+ }
+ }
+ }
+}
+

0 comments on commit 44458f5

Please sign in to comment.