~ubuntu-branches/debian/sid/hipo/sid

« back to all changes in this revision

Viewing changes to src/ImportDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Arthur Loiret
  • Date: 2008-04-02 15:37:34 UTC
  • mfrom: (1.1.3 upstream) (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080402153734-hnz2ia2tj3zox4z8
Tags: 0.6.1-2
* 0001-Remove-deprecated-Encoding-field-from-hipo.desktop.i.patch: Add,
  taken from Ubuntu.
* Let's hope Ubuntu maintainer Miguel Ruiz will send its patches back to
  Debian next time.
* debian/copyright: Rewrite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * This code is totally based on the ProgressDialog from
 
3
 * ipod-sharp-ui by James Willcox  <snorp@snorp.net>
 
4
 *
 
5
 */
 
6
 
 
7
using System;
 
8
using System.Reflection;
 
9
using Mono.Unix;
 
10
using Gtk;
 
11
using GLib;
 
12
using IPod;
 
13
 
 
14
namespace Hipo {
 
15
 
 
16
    public class ImportDialog : Dialog {
 
17
 
 
18
        private TrackDatabase db;
 
19
        private Label label;
 
20
        private ProgressBar bar;
 
21
        private ThreadNotify notify;
 
22
 
 
23
        private bool visible;
 
24
        private double fraction;
 
25
        private string message;
 
26
        
 
27
        public TrackDatabase TrackDatabase {
 
28
            get { return db; }
 
29
            set {
 
30
                if (db != null) {
 
31
                    // disconnect
 
32
                    db.SaveStarted -= OnSaveStarted;
 
33
                    db.SaveProgressChanged -= OnSaveProgressChanged;
 
34
                    db.SaveEnded -= OnSaveEnded;
 
35
                }
 
36
                
 
37
                db = value;
 
38
 
 
39
                if (db != null) {
 
40
                    // connect
 
41
                    db.SaveStarted += OnSaveStarted;
 
42
                    db.SaveProgressChanged += OnSaveProgressChanged;
 
43
                    db.SaveEnded += OnSaveEnded;
 
44
                }
 
45
            }
 
46
        }
 
47
        
 
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;
 
53
            
 
54
            VBox vbox = new VBox (false, 6);
 
55
            vbox.BorderWidth = 6;
 
56
 
 
57
            HBox hbox = new HBox (false, 6);
 
58
 
 
59
            Gdk.PixbufAnimation animation = new Gdk.PixbufAnimation (null, "ipod.gif");
 
60
            hbox.PackStart (new Gtk.Image (animation), false, false, 0);
 
61
 
 
62
            label = new Label ("");
 
63
            label.Xalign = 0.0f;
 
64
            label.UseMarkup = true;
 
65
 
 
66
            SetEllipsize (label);
 
67
            hbox.PackStart (label, true, true, 0);
 
68
 
 
69
            vbox.PackStart (hbox, true, false, 0);
 
70
 
 
71
            bar = new ProgressBar ();
 
72
            vbox.PackStart (bar, true, false, 0);
 
73
 
 
74
            VBox.PackStart (vbox, false, false, 0);
 
75
            VBox.ShowAll ();
 
76
 
 
77
            notify = new ThreadNotify (new ReadyEvent (OnNotify));
 
78
        }
 
79
 
 
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) });
 
84
        }
 
85
 
 
86
        private void OnSaveStarted (object o, EventArgs args) {
 
87
            visible = true;
 
88
            message = Catalog.GetString ("<b>Preparing...</b>");
 
89
            notify.WakeupMain ();
 
90
        }
 
91
 
 
92
        private void OnSaveProgressChanged (object o, TrackSaveProgressArgs args) {
 
93
            lock (this) {
 
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);
 
100
                    
 
101
                    message = String.Format ("<b>{0}: {1}</b>", message, GLib.Markup.EscapeText (args.CurrentTrack.Title));
 
102
                } else {
 
103
                    message = String.Format (Catalog.GetString ("<b>Finishing...</b>"));
 
104
                }
 
105
 
 
106
                fraction = args.TotalProgress;
 
107
                
 
108
                notify.WakeupMain ();
 
109
            }
 
110
        }
 
111
 
 
112
        private void OnSaveEnded (object o, EventArgs args) {
 
113
            visible = false;
 
114
            notify.WakeupMain ();
 
115
        }
 
116
 
 
117
        private void OnNotify () {
 
118
            lock (this) {
 
119
                if (this.visible && !Visible)
 
120
                    Show ();
 
121
                else if (!this.visible && Visible)
 
122
                    Hide ();
 
123
                
 
124
                label.Markup = message;
 
125
                bar.Fraction = fraction;
 
126
            }
 
127
        }
 
128
    }
 
129
}
 
130