2
* This code is totally based on the ProgressDialog from
3
* ipod-sharp-ui by James Willcox <snorp@snorp.net>
8
using System.Reflection;
16
public class ImportDialog : Dialog {
18
private TrackDatabase db;
20
private ProgressBar bar;
21
private ThreadNotify notify;
24
private double fraction;
25
private string message;
27
public TrackDatabase TrackDatabase {
32
db.SaveStarted -= OnSaveStarted;
33
db.SaveProgressChanged -= OnSaveProgressChanged;
34
db.SaveEnded -= OnSaveEnded;
41
db.SaveStarted += OnSaveStarted;
42
db.SaveProgressChanged += OnSaveProgressChanged;
43
db.SaveEnded += OnSaveEnded;
48
public ImportDialog (Window parent) : base () {
49
this.Title = Catalog.GetString ("Updating iPod...");
50
this.HasSeparator = false;
51
this.TransientFor = parent;
52
this.DefaultWidth = 400;
54
VBox vbox = new VBox (false, 6);
57
HBox hbox = new HBox (false, 6);
59
Gdk.PixbufAnimation animation = new Gdk.PixbufAnimation (null, "ipod.gif");
60
hbox.PackStart (new Gtk.Image (animation), false, false, 0);
62
label = new Label ("");
64
label.UseMarkup = true;
67
hbox.PackStart (label, true, true, 0);
69
vbox.PackStart (hbox, true, false, 0);
71
bar = new ProgressBar ();
72
vbox.PackStart (bar, true, false, 0);
74
VBox.PackStart (vbox, false, false, 0);
77
notify = new ThreadNotify (new ReadyEvent (OnNotify));
80
private void SetEllipsize (Label label) {
81
MethodInfo method = typeof (GLib.Object).GetMethod ("SetProperty",
82
BindingFlags.Instance | BindingFlags.NonPublic);
83
method.Invoke (label, new object[] { "ellipsize", new GLib.Value (3) });
86
private void OnSaveStarted (object o, EventArgs args) {
88
message = Catalog.GetString ("<b>Preparing...</b>");
92
private void OnSaveProgressChanged (object o, TrackSaveProgressArgs args) {
94
if (args.CurrentTrack != null) {
95
/* number of tracks to add */
96
string padstr = String.Format (Catalog.GetString ("Adding {0} of {0}"), args.TracksTotal);
97
/* the number of tracks completed and the total of tracks */
98
message = String.Format (Catalog.GetString ("Adding {0} of {1}"), args.TracksCompleted + 1, args.TracksTotal);
99
message = message.PadLeft (padstr.Length);
101
message = String.Format ("<b>{0}: {1}</b>", message, GLib.Markup.EscapeText (args.CurrentTrack.Title));
103
message = String.Format (Catalog.GetString ("<b>Finishing...</b>"));
106
fraction = args.TotalProgress;
108
notify.WakeupMain ();
112
private void OnSaveEnded (object o, EventArgs args) {
114
notify.WakeupMain ();
117
private void OnNotify () {
119
if (this.visible && !Visible)
121
else if (!this.visible && Visible)
124
label.Markup = message;
125
bar.Fraction = fraction;