~voluntatefaber/beat-box/bug952329

« back to all changes in this revision

Viewing changes to src/LibraryManager.vala

  • Committer: Scott Ringwelski
  • Date: 2011-02-16 23:57:19 UTC
  • Revision ID: sgringwe@mtu.edu-20110216235719-f95a1rxa0txk3nxe
in the middle of playlist stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
                progress_notification(message, progress);
123
123
        }
124
124
        
125
 
         public void set_music_folder(string folder) {
126
 
                settings.setMusicFolder(folder);
127
 
                try {
128
 
                        Thread.create<void*>(set_music_thread_function, false);
129
 
                }
130
 
                catch(GLib.Error err) {
131
 
                        stdout.printf("Could not create thread to set music folder: %s\n", err.message);
132
 
                }
133
 
        }
 
125
        public void set_music_folder(string folder) {
 
126
                progress_notification("Importing music from " + folder + ". This may take a while", 0.0);
 
127
                
 
128
                settings.setMusicFolder(folder);
 
129
                try {
 
130
                        Thread.create<void*>(set_music_thread_function, false);
 
131
                }
 
132
                catch(GLib.Error err) {
 
133
                        stdout.printf("Could not create thread to set music folder: %s\n", err.message);
 
134
                }
 
135
        }
134
136
        
135
137
        // i should do the actual file browsing here
136
 
        public void* set_music_thread_function () {
137
 
                var file = GLib.File.new_for_path(settings.getMusicFolder());
138
 
                
139
 
                var items = fo.count_music_files(file);
140
 
                fo.resetProgress(items);
141
 
                
142
 
                var new_songs = new LinkedList<Song>();
143
 
                var not_imported = new LinkedList<string>();
144
 
                fo.get_music_files(file, ref new_songs, ref not_imported);
145
 
                
146
 
                _songs.clear();
147
 
                _queue.clear();
148
 
                //_current.clear();
149
 
                
150
 
                int index = 1;
151
 
                foreach(Song s in new_songs) {
152
 
                                        s.rowid = index++;
153
 
                                        _songs.set(s.rowid, s);
154
 
                }
155
 
                
156
 
                //tell user what songs were not imported.
157
 
                foreach(string s in not_imported) {
158
 
                                        stdout.printf("File %s was not imported\n", s);
159
 
                }
160
 
                
161
 
                Idle.add( () => { music_added(not_imported); return false; });
162
 
                
163
 
                return null;
164
 
        }
165
 
        
166
 
        public void rescan_music_folder() {
167
 
                try {
168
 
                        Thread.create<void*>(rescan_music_thread_function, false);
169
 
                }
170
 
                catch(GLib.Error err) {
171
 
                        stdout.printf("Could not create thread to rescan music folder: %s\n", err.message);
172
 
                }
173
 
        }
174
 
        
175
 
        public void* rescan_music_thread_function () {
176
 
                LinkedList<string> paths = new LinkedList<string>();
177
 
                
178
 
                foreach(Song s in _songs.values) {
179
 
                        paths.add(s.file);
180
 
                }
181
 
                
182
 
                fo.resetProgress(paths.size);
183
 
                
184
 
                var not_imported = new LinkedList<string>();
185
 
                fo.rescan_music(GLib.File.new_for_path(settings.getMusicFolder()), ref paths, ref not_imported);
186
 
                
187
 
                // all songs remaining are no longer in folder hierarchy
188
 
                dbm.remove_songs(paths);
189
 
                
190
 
                //tell user what songs were not imported.
191
 
                foreach(string s in not_imported) {
192
 
                        stdout.printf("File %s was not imported\n", s);
193
 
                }
194
 
                
195
 
                Idle.add( () => { music_rescanned(not_imported); return false; });
196
 
                
197
 
                return null;
198
 
        }
 
138
        public void* set_music_thread_function () {
 
139
                var file = GLib.File.new_for_path(settings.getMusicFolder());
 
140
                
 
141
                var items = fo.count_music_files(file);
 
142
                fo.resetProgress(items);
 
143
                
 
144
                var new_songs = new LinkedList<Song>();
 
145
                var not_imported = new LinkedList<string>();
 
146
                fo.get_music_files(file, ref new_songs, ref not_imported);
 
147
                
 
148
                _songs.clear();
 
149
                _queue.clear();
 
150
                //_current.clear();
 
151
                
 
152
                int index = 1;
 
153
                foreach(Song s in new_songs) {
 
154
                        s.rowid = index++;
 
155
                        _songs.set(s.rowid, s);
 
156
                }
 
157
                
 
158
                //tell user what songs were not imported.
 
159
                foreach(string s in not_imported) {
 
160
                        stdout.printf("File %s was not imported\n", s);
 
161
                }
 
162
                
 
163
                Idle.add( () => { 
 
164
                        music_added(not_imported); 
 
165
                        return false; 
 
166
                });
 
167
                
 
168
                return null;
 
169
        }
 
170
        
 
171
        public void rescan_music_folder() {
 
172
                progress_notification("Rescanning music for changes. This may take a while", 0.0);
 
173
                
 
174
                try {
 
175
                                Thread.create<void*>(rescan_music_thread_function, false);
 
176
                }
 
177
                catch(GLib.Error err) {
 
178
                                stdout.printf("Could not create thread to rescan music folder: %s\n", err.message);
 
179
                }
 
180
        }
 
181
        
 
182
        public void* rescan_music_thread_function () {
 
183
                LinkedList<string> paths = new LinkedList<string>();
 
184
                
 
185
                foreach(Song s in _songs.values) {
 
186
                                paths.add(s.file);
 
187
                }
 
188
                
 
189
                fo.resetProgress(paths.size);
 
190
                
 
191
                var not_imported = new LinkedList<string>();
 
192
                fo.rescan_music(GLib.File.new_for_path(settings.getMusicFolder()), ref paths, ref not_imported);
 
193
                
 
194
                // all songs remaining are no longer in folder hierarchy
 
195
                dbm.remove_songs(paths);
 
196
                
 
197
                //tell user what songs were not imported.
 
198
                foreach(string s in not_imported) {
 
199
                                stdout.printf("File %s was not imported\n", s);
 
200
                }
 
201
                
 
202
                Idle.add( () => { 
 
203
                        music_rescanned(not_imported); 
 
204
                        return false; 
 
205
                });
 
206
                
 
207
                return null;
 
208
        }
199
209
        
200
210
        /******************** Song list columns *******************/
201
211
        public ArrayList<Gtk.TreeViewColumn> columns() {