~vikoadi/noise/fix-getNext

« back to all changes in this revision

Viewing changes to src/IO/DeviceManager.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:
15
15
                vm.mount_changed.connect(mount_changed);
16
16
                vm.mount_pre_unmount.connect(mount_pre_unmount);
17
17
                vm.mount_removed.connect(mount_removed);
18
 
                vm.volume_added.connect(volume_added);
19
 
                vm.volume_changed.connect(volume_changed);
20
 
                vm.volume_removed.connect(volume_removed);
 
18
                
 
19
                /*vmVfs = GnomeVFS.get_volume_monitor();
 
20
                vmVfs.volume_mounted.connect(gvfs_mounted);
 
21
                vmVfs.drive_connected.connect( () => { stdout.printf("drive connected\n"); });
 
22
                vmVfs.drive_disconnected.connect( () => { stdout.printf("drive disconnected\n"); });
 
23
                vmVfs.volume_unmounted.connect(gvfs_unmounted);
 
24
                
 
25
                var monitor = File.new_for_path("/home/scott/.gvfs").monitor_directory(FileMonitorFlags.NONE);
 
26
                
 
27
                monitor.changed.connect( () => { stdout.printf("changed\n"); });
 
28
                
 
29
                // gudev 
 
30
                GUdev.Client client = new GUdev.Client({"usb", null});
 
31
                client.uevent.connect(uevent_cb);*/
21
32
        }
22
33
        
 
34
        /*public void uevent_cb(string action, GUdev.Device device) {
 
35
                stdout.printf("action; %s\n", action);
 
36
                        stdout.printf("device: %s\n", device.get_device_file());
 
37
        }*/
 
38
        
23
39
        public void loadPreExistingMounts() {
24
40
                
25
41
                // this can take time if we have to rev up the cd drive
40
56
                
41
57
                Idle.add( () => {
42
58
                        
43
 
                        foreach(var m in mounts)
 
59
                        foreach(var m in mounts) {
44
60
                                mount_added(m);
 
61
                        }
45
62
                        
46
63
                        return false;
47
64
                });
49
66
                return null;
50
67
        }
51
68
        
 
69
        public void add_mount(string path) {
 
70
                stdout.printf("added mount %s\n", path);
 
71
        }
 
72
        
52
73
        public virtual void mount_added (Mount mount) {
 
74
                stdout.printf("mount added at %s\n", mount.get_default_location().get_path());
53
75
                foreach(var dev in devices) {
54
 
                        if(dev.getMountLocation() == mount.get_default_location().get_parse_name()) {
 
76
                        if(dev.get_path() == mount.get_default_location().get_path()) {
55
77
                                return;
56
78
                        }
57
79
                }
58
80
                
59
 
                /*stdout.printf("mount_added: %s\n", mount.get_name());
60
 
                stdout.printf(" parse_name: %s\n uri: %s\n nice_name: %s\n unix_device: %s\n test: %s\n",
61
 
                                                mount.get_default_location().get_parse_name(),
62
 
                                                mount.get_default_location().get_uri(),
63
 
                                                mount.get_volume().get_identifier(VOLUME_IDENTIFIER_KIND_LABEL),
64
 
                                                mount.get_volume().get_identifier(VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
65
 
                                                new UnixMountEntry(mount.get_default_location().get_path(), 0).get_device_path());*/
66
 
                var device = new Device(mount);
67
 
                
68
 
                //stdout.printf("mount preview icon: %s\n", mount.get_default_location().query_info("*", FileQueryInfoFlags.NONE).get_attribute_string(FILE_ATTRIBUTE_PREVIEW_ICON));
69
 
                
70
 
                if(device.getContentType() == "cdrom" || device.getContentType().contains("ipod") 
71
 
                        || device.getContentType() == "android") {
72
 
                        devices.add(device);
73
 
                        device_added(device);
 
81
                Device added;
 
82
                if(mount.get_default_location().get_path().has_prefix("cdda://")) {
 
83
                        added = new CDRomDevice(mount);
 
84
                }
 
85
                else if(File.new_for_path(mount.get_default_location().get_path() + "/iTunes_Control").query_exists() ||
 
86
                                File.new_for_path(mount.get_default_location().get_path() + "/iPod_Control").query_exists() ||
 
87
                                File.new_for_path(mount.get_default_location().get_path() + "/iTunes/iTunes_Control").query_exists()) {
 
88
                        added = new iPodDevice(mount);  
 
89
                }
 
90
                else if(mount.get_default_location().get_parse_name().has_prefix("afc://")) {
 
91
                        added = new iPodDevice(mount);
 
92
                }
 
93
                else if(File.new_for_path(mount.get_default_location().get_path() + "/Android").query_exists()) {
 
94
                        added = new AndroidDevice(mount);
 
95
                }
 
96
                else { // not a music player, ignore it
 
97
                        return;
 
98
                }
 
99
                
 
100
                if(added == null) {
 
101
                        stdout.printf("added is null. initialization failed, meaning it is invalid. not using it\n");
 
102
                        return;
 
103
                }
 
104
                
 
105
                added.set_mount(mount);
 
106
                
 
107
                devices.add(added);
 
108
                device_added(added);
 
109
                
 
110
                if(!added.initialize()) {
 
111
                        mount_removed(added.get_mount());
74
112
                }
75
113
        }
76
114
        
86
124
                stdout.printf("mount_removed: %s\n", mount.get_default_location().get_parse_name());
87
125
                
88
126
                foreach(var dev in devices) {
89
 
                        if(dev.getMountLocation() == mount.get_default_location().get_parse_name()) {
 
127
                        stdout.printf("comparing %s to %s\n", dev.get_path(), mount.get_default_location().get_path());
 
128
                        if(dev.get_path() == mount.get_default_location().get_path()) {
 
129
                                stdout.printf("removed %s\n", mount.get_default_location().get_path());
90
130
                                devices.remove(dev);
91
131
                                device_removed(dev);
92
132
                                
95
135
                }
96
136
        }
97
137
        
98
 
        public void mountedCallback(Object? source_object, AsyncResult res) {
99
 
                //stdout.printf("mounted %s!\n", (string)current.get_mount().guess_content_type_sync(true, null));
100
 
        }
101
 
        
102
 
        public virtual void volume_added (Volume volume) {
103
 
                //Device d = new Device(volume);
104
 
                
105
 
                //stdout.printf("volume added: %s, %s\n", volume.get_name(), volume.get_mount().guess_content_type_sync(true, null));
106
 
                
107
 
                //Timeout.add(5000, () => { stdout.printf("volume added: %s\n", volume.get_mount().guess_content_type_sync(true, null)); return false; } );
108
 
        }
109
 
        
110
 
        public virtual void volume_changed (Volume volume) {
111
 
                //stdout.printf("volume changed: %s %s\n", volume.get_name(), volume.get_mount().guess_content_type_sync(true, null));
112
 
                
113
 
                //Timeout.add(5000, () => { stdout.printf("volume changed: %s\n", volume.get_mount().guess_content_type_sync(true, null)); return false; } );
114
 
        }
115
 
        
116
 
        public virtual void volume_removed (Volume volume) {
117
 
                //stdout.printf("volume removed: %s, %S\n", volume.get_name(), volume.get_mount().guess_content_type_sync(true, null));
118
 
                
119
 
                //Timeout.add(5000, () => { stdout.printf("volume removed: %s\n", volume.get_mount().guess_content_type_sync(true, null)); return false; } );
 
138
        public void gvfs_mounted(GnomeVFS.Volume volume) {
 
139
                stdout.printf("gvfs mounted\n");
 
140
        }
 
141
        
 
142
        public void gvfs_unmounted(GnomeVFS.Volume volume) {
 
143
                stdout.printf("gvfs unmounted\n");
120
144
        }
121
145
}