Merge lp:~voluntatefaber/beat-box/multiple_selection into lp:beat-box/1.x

Proposed by Andrea Basso
Status: Merged
Approved by: Victor Martinez
Approved revision: 546
Merged at revision: 587
Proposed branch: lp:~voluntatefaber/beat-box/multiple_selection
Merge into: lp:beat-box/1.x
Diff against target: 322 lines (+114/-58)
5 files modified
po/sv.po (+1/-1)
src/FileOperator.vala (+18/-3)
src/LibraryManager.vala (+19/-2)
src/LibraryWindow.vala (+23/-11)
src/Widgets/SideTreeView.vala (+53/-41)
To merge this branch: bzr merge lp:~voluntatefaber/beat-box/multiple_selection
Reviewer Review Type Date Requested Status
Victor Martinez (community) Approve
Review via email: mp+93898@code.launchpad.net

Commit message

Multiple directories/playlists/stations can be imported at once. Fixes bug #792759

Description of the change

Multiple directories/playlists/stations can be imported at once.

To post a comment you must log in.
Revision history for this message
Andrea Basso (voluntatefaber) wrote :

To me it's stable, but needs some testing before merging.

Revision history for this message
Victor Martinez (victored) wrote :

Hi Andrea, thanks for your work!

This looks fine to me. However, I don't think it's necessary to use a second array (other_names_list), since you could simply iterate through names[]. Could you please change that? :)

Revision history for this message
Victor Martinez (victored) :
review: Approve
Revision history for this message
Victor Martinez (victored) wrote :

Any idea of why RabbitBot hasn't merged this yet?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'po/sv.po'
2--- po/sv.po 2012-02-11 05:46:22 +0000
3+++ po/sv.po 2012-02-20 20:24:26 +0000
4@@ -14,7 +14,7 @@
5 "MIME-Version: 1.0\n"
6 "Content-Type: text/plain; charset=UTF-8\n"
7 "Content-Transfer-Encoding: 8bit\n"
8-"X-Launchpad-Export-Date: 2012-02-11 05:46+0000\n"
9+"X-Launchpad-Export-Date: 2012-02-12 05:04+0000\n"
10 "X-Generator: Launchpad (build 14771)\n"
11 "X-Poedit-Language: Swedish\n"
12
13
14=== modified file 'src/FileOperator.vala'
15--- src/FileOperator.vala 2012-02-11 02:33:14 +0000
16+++ src/FileOperator.vala 2012-02-20 20:24:26 +0000
17@@ -46,6 +46,9 @@
18 LinkedList<Media> new_imports;
19 LinkedList<Media> all_new_imports;
20 LinkedList<string> import_errors;
21+ private string[] other_names_list = {};
22+ private LinkedList<string>[] other_paths_list;
23+ private int other_playlists_added = 0;
24
25 HashMap<string, string> art_locations = new HashMap<string, string>();
26
27@@ -446,12 +449,18 @@
28 }
29
30 /* should be called from thread */
31- public void import_from_playlist_file_info(string name, LinkedList<string> paths) {
32+ public void import_from_playlist_file_info(string[] names, LinkedList<string>[] paths) {
33 new_playlist = new Playlist();
34+ if (names.length > 1) {
35+ other_names_list = names[1:paths.length];
36+ other_paths_list = paths[1:paths.length];
37+ }
38 var internals = new LinkedList<int>();
39 var externals = new LinkedList<string>();
40
41- foreach(string path in paths) {
42+ lm.start_file_operations("Importing <b>" + names[0] + "</b> to Library...");
43+
44+ foreach(string path in paths[0]) {
45 Media s;
46 if( (s = lm.media_from_file(path)) != null)
47 internals.add(s.rowid);
48@@ -459,7 +468,7 @@
49 externals.add(path);
50 }
51
52- new_playlist.name = name;
53+ new_playlist.name = names[0];
54 foreach(int i in internals)
55 new_playlist.addMedia(i);
56
57@@ -534,6 +543,12 @@
58 lm.music_added(import_type == ImportType.RESCAN ? new LinkedList<string>() : import_errors);
59 lm.finish_file_operations();
60 }
61+ if (other_names_list.length > 0) {
62+ import_from_playlist_file_info({other_names_list[other_playlists_added]}, {other_paths_list[other_playlists_added]});
63+ other_playlists_added++;
64+ if (other_playlists_added == other_names_list.length)
65+ other_names_list = {};
66+ }
67 }
68
69 public void* copy_imports_thread() {
70
71=== modified file 'src/LibraryManager.vala'
72--- src/LibraryManager.vala 2012-02-17 19:00:36 +0000
73+++ src/LibraryManager.vala 2012-02-20 20:24:26 +0000
74@@ -148,6 +148,8 @@
75 }
76
77 private string temp_add_folder;
78+ private string[] temp_add_other_folders;
79+ private int other_folders_added;
80 private LinkedList<string> temp_add_files;
81 bool _doing_file_operations;
82 bool in_fetch_thread;
83@@ -331,6 +333,18 @@
84 catch(GLib.ThreadError err) {
85 warning("Could not create thread to load media pixbuf's: %s \n", err.message);
86 }
87+
88+ other_folders_added = 0;
89+ file_operations_done.connect ( ()=> {
90+ if (temp_add_other_folders != null) {
91+ other_folders_added++;
92+ add_folder_to_library (temp_add_other_folders[other_folders_added-1]);
93+ if (other_folders_added == temp_add_other_folders.length) {
94+ other_folders_added = 0;
95+ temp_add_other_folders = null;
96+ }
97+ }
98+ });
99 }
100
101 /************ Library/Collection management stuff ************/
102@@ -410,7 +424,10 @@
103 return null;
104 }
105
106- public void add_folder_to_library(string folder) {
107+ public void add_folder_to_library(string folder, string[]? other_folders = null) {
108+ if (other_folders != null)
109+ temp_add_other_folders = other_folders;
110+
111 if(start_file_operations("Adding music from <b>" + folder + "</b> to library...")) {
112 temp_add_folder = folder;
113
114@@ -431,7 +448,7 @@
115 fo.resetProgress(items);
116 Timeout.add(100, doProgressNotificationWithTimeout);
117 fo.import_files(files, FileOperator.ImportType.IMPORT);
118-
119+
120 return null;
121 }
122
123
124=== modified file 'src/LibraryWindow.vala'
125--- src/LibraryWindow.vala 2012-02-18 07:31:16 +0000
126+++ src/LibraryWindow.vala 2012-02-20 20:24:26 +0000
127@@ -1021,26 +1021,38 @@
128 return;
129 }*/
130
131- string folder = "";
132+ string folders_list = "";
133+ string[] folders = {};
134+ var _folders = new SList<string> ();
135 var file_chooser = new FileChooserDialog (_("Import Music"), this,
136 FileChooserAction.SELECT_FOLDER,
137 Gtk.Stock.CANCEL, ResponseType.CANCEL,
138 Gtk.Stock.OPEN, ResponseType.ACCEPT);
139+ file_chooser.set_select_multiple (true);
140 file_chooser.set_local_only(true);
141
142 if (file_chooser.run () == ResponseType.ACCEPT) {
143- folder = file_chooser.get_filename();
144+ _folders = file_chooser.get_filenames();
145 }
146 file_chooser.destroy ();
147-
148- if(folder != "" && folder != settings.getMusicFolder()) {
149- if(GLib.File.new_for_path(lm.settings.getMusicFolder()).query_exists()) {
150- topDisplay.set_label_markup(_("<b>Importing</b> music from <b>%s</b> to library.").printf(folder));
151- topDisplay.show_progressbar();
152-
153- lm.add_folder_to_library(folder);
154- updateSensitivities();
155- }
156+
157+ for (int i=0;i< (int)(_folders.length ());i++) {
158+ folders += _folders.nth_data (i);
159+ }
160+
161+ for (int i=0;i<folders.length;i++) {
162+ if(folders[i] == "" || folders[i] != settings.getMusicFolder()) {
163+ folders_list += folders[i];
164+ if (i + 1 != folders.length)
165+ folders_list += ", ";
166+ }
167+ }
168+ if(GLib.File.new_for_path(lm.settings.getMusicFolder()).query_exists()) {
169+ topDisplay.set_label_markup(_("<b>Importing</b> music from <b>%s</b> to library.").printf(folders_list));
170+ topDisplay.show_progressbar();
171+
172+ lm.add_folder_to_library(folders[0], folders[1:folders.length]);
173+ updateSensitivities();
174 }
175 }
176 else {
177
178=== modified file 'src/Widgets/SideTreeView.vala'
179--- src/Widgets/SideTreeView.vala 2012-02-17 01:24:32 +0000
180+++ src/Widgets/SideTreeView.vala 2012-02-20 20:24:26 +0000
181@@ -112,9 +112,9 @@
182 CDMenu.show_all();
183
184 radioMenu = new Gtk.Menu();
185- radioImportStations = new Gtk.MenuItem.with_label(_("Import Station"));
186+ radioImportStations = new Gtk.MenuItem.with_label(_("Import Stations"));
187 radioMenu.append(radioImportStations);
188- radioImportStations.activate.connect(playlistImportClicked);
189+ radioImportStations.activate.connect(()=> {playlistImportClicked ("Station");});
190 radioMenu.show_all();
191
192 //playlist right click menu
193@@ -125,7 +125,7 @@
194 playlistRemove = new Gtk.MenuItem.with_label(_("Remove"));
195 playlistSave = new Gtk.MenuItem.with_label(_("Save as Playlist"));
196 playlistExport = new Gtk.MenuItem.with_label(_("Export..."));
197- playlistImport = new Gtk.MenuItem.with_label(_("Import Playlist"));
198+ playlistImport = new Gtk.MenuItem.with_label(_("Import Playlists"));
199 playlistMenu.append(playlistNew);
200 playlistMenu.append(smartPlaylistNew);
201 playlistMenu.append(playlistEdit);
202@@ -139,7 +139,7 @@
203 playlistRemove.activate.connect(playlistMenuRemoveClicked);
204 playlistSave.activate.connect(playlistSaveClicked);
205 playlistExport.activate.connect(playlistExportClicked);
206- playlistImport.activate.connect(playlistImportClicked);
207+ playlistImport.activate.connect(()=>{playlistImportClicked ();});
208 playlistMenu.show_all();
209
210 this.button_press_event.connect(sideListClick);
211@@ -945,16 +945,24 @@
212 p.name = original_name;
213 }
214
215- void playlistImportClicked() {
216+ void playlistImportClicked(string title = "Playlist") {
217+ var files = new SList<string> ();
218+ string[] names = {};
219+ var path = new LinkedList<string> ();
220+ var stations = new LinkedList<Media> ();
221+ LinkedList<string>[] paths = {};
222+ LinkedList<string>[] filtered_paths = {};
223+ bool success = false;
224+ int i = 0;
225+
226 if(lm.doing_file_operations())
227 return;
228-
229- string file = "";
230- string name = "";
231- var file_chooser = new FileChooserDialog ("Import Playlist", lw,
232+
233+ var file_chooser = new FileChooserDialog ("Import " + title, lw,
234 FileChooserAction.OPEN,
235 Gtk.Stock.CANCEL, ResponseType.CANCEL,
236 Gtk.Stock.OPEN, ResponseType.ACCEPT);
237+ file_chooser.set_select_multiple (true);
238
239 // filters for .m3u and .pls
240 var m3u_filter = new FileFilter();
241@@ -968,45 +976,49 @@
242 file_chooser.add_filter(pls_filter);
243
244 if (file_chooser.run () == ResponseType.ACCEPT) {
245- file = file_chooser.get_filename();
246- name = file.slice(file.last_index_of("/", 0) + 1, file.last_index_of(".", 0));
247+ files = file_chooser.get_filenames();
248+ files.foreach ( (file)=> {
249+ names += file.slice(file.last_index_of("/", 0) + 1, file.last_index_of(".", 0));
250+ });
251 }
252
253 file_chooser.destroy ();
254
255- var paths = new LinkedList<string>();
256- var stations = new LinkedList<Media>();
257- bool success = false;
258+ files.foreach ( (file)=> {
259+ if(file != "") {
260+ path = new LinkedList<string> ();
261+ if(file.has_suffix(".m3u")) {
262+ success = Playlist.parse_paths_from_m3u(lm, file, ref path, ref stations);
263+ paths += path;
264+ }
265+ else if(file.has_suffix(".pls")) {
266+ success = Playlist.parse_paths_from_pls(lm, file, ref path, ref stations);
267+ paths += path;
268+ }
269+ else {
270+ success = false;
271+ lw.doAlert("Invalid Playlist", "Unrecognized playlist file. Import failed.");
272+ return;
273+ }
274+ }
275+ i++;
276+ });
277
278- if(file != "") {
279- if(file.has_suffix(".m3u")) {
280- success = Playlist.parse_paths_from_m3u(lm, file, ref paths, ref stations);
281- }
282- else if(file.has_suffix(".pls")) {
283- success = Playlist.parse_paths_from_pls(lm, file, ref paths, ref stations);
284- }
285- else {
286- success = false;
287- lw.doAlert("Invalid Playlist", "Unrecognized playlist file. Import failed.");
288- return;
289- }
290- }
291+ foreach (LinkedList l in paths)
292+ if (l.size > 0)
293+ filtered_paths += l;
294
295 if(success) {
296- if(paths.size > 0) {
297- stdout.printf("paths size is %d\n", paths.size);
298- lm.start_file_operations("Importing <b>" + name + "</b> to Library...");
299- lm.fo.import_from_playlist_file_info(name, paths);
300- lw.updateSensitivities();
301- }
302- if(stations.size > 0) {
303- stdout.printf("stations size is %d\n", stations.size);
304- lm.add_medias(stations, true);
305-
306- //Widget w = getWidget(network_radio_iter);
307- //((ViewWrapper)w).doUpdate(((ViewWrapper)w).currentView, lm.station_ids(), true, true, false);
308- }
309- }
310+ if(filtered_paths.length > 0) {
311+ print ("I was called");
312+ lm.fo.import_from_playlist_file_info(names, filtered_paths);
313+ lw.updateSensitivities();
314+ }
315+ if(stations.size > 0) {
316+ stdout.printf("stations size is %d\n", stations.size);
317+ lm.add_medias(stations, true);
318+ }
319+ }
320 }
321
322 public virtual void dragReceived(Gdk.DragContext context, int x, int y, Gtk.SelectionData data, uint info, uint timestamp) {

Subscribers

People subscribed via source and target branches

to all changes: