diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index a30a7bdce..5e94c4484 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -1309,6 +1309,18 @@ bool Playlist::CompareItems(int column, Qt::SortOrder order, return false; } +bool Playlist::ComparePathDepths(Qt::SortOrder order, + shared_ptr _a, + shared_ptr _b) { + shared_ptr a = order == Qt::AscendingOrder ? _a : _b; + shared_ptr b = order == Qt::AscendingOrder ? _b : _a; + + int a_dir_level = a->Url().path().count('/'); + int b_dir_level = b->Url().path().count('/'); + + return a_dir_level < b_dir_level; +} + QString Playlist::column_name(Column column) { switch (column) { case Column_Title: @@ -1410,6 +1422,14 @@ void Playlist::sort(int column, Qt::SortOrder order) { std::bind(&Playlist::CompareItems, Column_Disc, order, _1, _2)); qStableSort(begin, new_items.end(), std::bind(&Playlist::CompareItems, Column_Album, order, _1, _2)); + } else if (column == Column_Filename) { + // When sorting by full paths we also expect a hierarchical order. This + // returns a breath-first ordering of paths. + qStableSort( + begin, new_items.end(), + std::bind(&Playlist::CompareItems, Column_Filename, order, _1, _2)); + qStableSort(begin, new_items.end(), + std::bind(&Playlist::ComparePathDepths, order, _1, _2)); } else { qStableSort(begin, new_items.end(), std::bind(&Playlist::CompareItems, column, order, _1, _2)); diff --git a/src/playlist/playlist.h b/src/playlist/playlist.h index ada4db68d..fefc970e2 100644 --- a/src/playlist/playlist.h +++ b/src/playlist/playlist.h @@ -306,6 +306,9 @@ class Playlist : public QAbstractListModel { bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()); + static bool ComparePathDepths(Qt::SortOrder, PlaylistItemPtr, + PlaylistItemPtr); + public slots: void set_current_row(int index, bool is_stopping = false); void Paused();