Skip to content

Commit

Permalink
Handle dropped folder (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Wootten authored Feb 9, 2023
1 parent 067bdab commit 9b7da47
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
18 changes: 10 additions & 8 deletions data/music.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
<update_contact>contact_at_elementary.io</update_contact>

<releases>
<release version="7.1.0" date="2023-02-09" urgency="medium">
<description>
<p>Improvements:</p>
<ul>
<li>Drag and drop whole folders into the queue</li>
</ul>
</description>
</release>

<release version="7.0.1" date="2022-12-05" urgency="medium">
<description>
<p>Improvements:</p>
Expand Down Expand Up @@ -89,13 +98,6 @@
</description>
</release>

<release version="5.0.5" date="2020-03-04" urgency="medium">
<description>
<p>Fix removing items from the queue</p>
<p>Fix equalizer sliders not properly disabled sometimes</p>
<p>Updated translations</p>
<p>Performance improvements</p>
</description>
</release>
<release version="5.0.5" date="2020-03-04" urgency="medium"/>
</releases>
</component>
35 changes: 34 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,19 @@ public class Music.MainWindow : Gtk.ApplicationWindow {

drop_target.on_drop.connect ((target, value, x, y) => {
if (value.type () == typeof (Gdk.FileList)) {

File[] files;
SList<File> file_list = null;
foreach (unowned var file in (SList<File>) value.get_boxed ()) {
var file_type = file.query_file_type (FileQueryInfoFlags.NONE);
if (file_type == FileType.DIRECTORY) {
prepend_directory_files (file, ref file_list);
} else {
file_list.prepend (file);
}
}

file_list.reverse ();
foreach (unowned var file in file_list) {
files += file;
}

Expand Down Expand Up @@ -151,6 +161,29 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
});
}

//Array concatenation not permitted for parameters so use a list instead
private void prepend_directory_files (GLib.File dir, ref SList<File> file_list) {
try {
var enumerator = dir.enumerate_children (
"standard::*",
FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
null
);

FileInfo info = null;
while ((info = enumerator.next_file (null)) != null) {
var child = dir.resolve_relative_path (info.get_name ());
if (info.get_file_type () == FileType.DIRECTORY) {
prepend_directory_files (child, ref file_list);
} else {
file_list.prepend (child);
}
}
} catch (Error e) {
warning ("Error while enumerating children of %s: %s", dir.get_uri (), e.message);
}
}

private void update_repeat_button () {
switch (settings.get_string ("repeat-mode")) {
case "disabled":
Expand Down

0 comments on commit 9b7da47

Please sign in to comment.