~voluntatefaber/beat-box/bug952329

« back to all changes in this revision

Viewing changes to src/Devices/iPodDevice.vala

  • Committer: sgringwe at gmail
  • Date: 2011-11-21 21:51:19 UTC
  • Revision ID: sgringwe@gmail.com-20111121215119-rm3i25j09svrecnz
in the middle of device work, committing for a reference point

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using GPod;
 
2
using Gee;
 
3
 
 
4
public class BeatBox.iPodDevice : GLib.Object, BeatBox.Device {
 
5
        iTunesDB db;
 
6
        Mount mount;
 
7
        GLib.Icon icon;
 
8
        
 
9
        LinkedList<int> songs;
 
10
        
 
11
        public iPodDevice(LibraryManager lm, Mount mount) {
 
12
                this.mount = mount;
 
13
                icon = mount.get_icon();
 
14
        }
 
15
        
 
16
        public bool initialize() {
 
17
                try {
 
18
                        db = iTunesDB.parse(get_path());
 
19
                }
 
20
                catch(Error err) {
 
21
                        stdout.printf("Error parsing db at %s: %s\n", get_path(), err.message);
 
22
                        return false;
 
23
                }
 
24
                
 
25
                var trToSo = new LinkedList<Song>();
 
26
                
 
27
                
 
28
                for(int i = 0; i < db.tracks.length(); ++i) {
 
29
                        trToSo.add(new Song.from_track(db.tracks.nth_data(i)));
 
30
                }
 
31
                
 
32
                lm.add_songs(trToSo, false);
 
33
                
 
34
                foreach(var s in tSongs)
 
35
                        songs.add(s.rowid);
 
36
                        
 
37
                d.device_unmounted.connect( () => {
 
38
                        foreach(Song s in tSongs) {
 
39
                                s.unique_status_image = null;
 
40
                                lm.update_songs(tSongs, false);
 
41
                        }
 
42
                });
 
43
                
 
44
                return true;
 
45
        }
 
46
        
 
47
        public bool isNew() {
 
48
                return mount.get_default_location().get_parse_name().has_prefix("afc://");
 
49
        }
 
50
        
 
51
        public string getContentType() {
 
52
                if(isNew())
 
53
                        return "ipod-new";
 
54
                else
 
55
                        return "ipod-old";
 
56
        }
 
57
        
 
58
        public string getDisplayName() {
 
59
                return mount.get_name();
 
60
        }
 
61
        
 
62
        public void set_mount(Mount mount) {
 
63
                this.mount = mount;
 
64
        }
 
65
        
 
66
        public Mount get_mount() {
 
67
                return mount;
 
68
        }
 
69
        
 
70
        public string get_path() {
 
71
                return mount.get_default_location().get_path();
 
72
        }
 
73
        
 
74
        public void set_icon(GLib.Icon icon) {
 
75
                this.icon = icon;
 
76
        }
 
77
        
 
78
        public GLib.Icon get_icon() {
 
79
                return icon;
 
80
        }
 
81
        
 
82
        public int64 get_capacity() {
 
83
                return (int64)0;
 
84
        }
 
85
        
 
86
        public int64 get_used_space() {
 
87
                return (int64)0;
 
88
        }
 
89
        
 
90
        public int64 get_free_space() {
 
91
                return (int64)0;
 
92
        }
 
93
        
 
94
        public void unmount() {
 
95
                
 
96
        }
 
97
        
 
98
        public void eject() {
 
99
                
 
100
        }
 
101
        
 
102
        public void get_device_type() {
 
103
                
 
104
        }
 
105
}