From acabd0188f3bdbd5cc3e36176ab54db761fda05f Mon Sep 17 00:00:00 2001 From: kraxarn Date: Sat, 16 Dec 2023 16:12:11 +0100 Subject: [PATCH] Add option to ignore unavailable tracks, fixes #209 --- lib/include/lib/settings/general.hpp | 5 +++++ lib/src/settings/general.cpp | 2 ++ src/list/tracks.cpp | 28 ++++++++++++++++++++++++++++ src/settingspage/application.cpp | 11 +++++++++++ src/settingspage/application.hpp | 1 + 5 files changed, 47 insertions(+) diff --git a/lib/include/lib/settings/general.hpp b/lib/include/lib/settings/general.hpp index 35377c40..41cd2930 100644 --- a/lib/include/lib/settings/general.hpp +++ b/lib/include/lib/settings/general.hpp @@ -141,6 +141,11 @@ namespace lib #ifdef _WIN32 bool media_hotkeys = true; #endif + + /** + * \brief Ignore index of unavailable tracks + */ + bool ignore_unavailable_index = false; }; void to_json(nlohmann::json &j, const general &g); diff --git a/lib/src/settings/general.cpp b/lib/src/settings/general.cpp index e10f2511..90e247dd 100644 --- a/lib/src/settings/general.cpp +++ b/lib/src/settings/general.cpp @@ -8,6 +8,7 @@ void lib::setting::to_json(nlohmann::json &j, const general &g) {"custom_playlist_order", g.custom_playlist_order}, {"fallback_icons", g.fallback_icons}, {"hidden_song_headers", g.hidden_song_headers}, + {"ignore_unavailable_index", g.ignore_unavailable_index}, {"last_device", g.last_device}, {"last_playlist", g.last_playlist}, {"last_version", g.last_version}, @@ -45,6 +46,7 @@ void lib::setting::from_json(const nlohmann::json &j, general &g) lib::json::get(j, "custom_playlist_order", g.custom_playlist_order); lib::json::get(j, "fallback_icons", g.fallback_icons); lib::json::get(j, "hidden_song_headers", g.hidden_song_headers); + lib::json::get(j, "ignore_unavailable_index", g.ignore_unavailable_index); lib::json::get(j, "last_device", g.last_device); lib::json::get(j, "last_playlist", g.last_playlist); lib::json::get(j, "last_version", g.last_version); diff --git a/src/list/tracks.cpp b/src/list/tracks.cpp index c87fcdca..11ceeb56 100644 --- a/src/list/tracks.cpp +++ b/src/list/tracks.cpp @@ -177,6 +177,34 @@ void List::Tracks::onDoubleClicked(QTreeWidgetItem *item, int /*column*/) return; } + if (settings.general.ignore_unavailable_index) + { + auto modifier = 0; + + for (auto i = 0; i < topLevelItemCount(); i++) + { + const auto *disabledItem = topLevelItem(i); + if (!disabledItem->isDisabled()) + { + continue; + } + + const auto &disabledIndexData = disabledItem->data(0, static_cast(DataRole::Index)); + const auto disabledIndex = disabledIndexData.toInt(); + + if (disabledIndex < trackIndex) + { + modifier++; + } + } + + if (modifier > 0) + { + lib::log::debug("Ignoring {} unavailable tracks", modifier); + trackIndex -= modifier; + } + } + auto callback = [this, mainWindow, item](const std::string &status) { if (!status.empty()) diff --git a/src/settingspage/application.cpp b/src/settingspage/application.cpp index 5888f8d2..fd4c6b2a 100644 --- a/src/settingspage/application.cpp +++ b/src/settingspage/application.cpp @@ -75,6 +75,12 @@ auto SettingsPage::Application::app() -> QWidget * appUpdates->setChecked(settings.general.check_for_updates); layout->addWidget(appUpdates); + ignoreUnavailableIndex = new QCheckBox(QStringLiteral("Ignore index of unavailable songs"), this); + ignoreUnavailableIndex->setToolTip(QStringLiteral("Ignore index of unavailable tracks, " + "required by some clients to properly index playlists with unavailable songs")); + ignoreUnavailableIndex->setChecked(settings.general.ignore_unavailable_index); + layout->addWidget(ignoreUnavailableIndex); + return Widget::layoutToWidget(layout, this); } @@ -156,5 +162,10 @@ auto SettingsPage::Application::save() -> bool settings.general.check_for_updates = appUpdates->isChecked(); } + if (ignoreUnavailableIndex != nullptr) + { + settings.general.ignore_unavailable_index = ignoreUnavailableIndex->isChecked(); + } + return success; } diff --git a/src/settingspage/application.hpp b/src/settingspage/application.hpp index 43db276a..198398ec 100644 --- a/src/settingspage/application.hpp +++ b/src/settingspage/application.hpp @@ -23,6 +23,7 @@ namespace SettingsPage QComboBox *appRefresh = nullptr; QComboBox *appMaxQueue = nullptr; QCheckBox *appUpdates = nullptr; + QCheckBox *ignoreUnavailableIndex = nullptr; static constexpr int minRefreshInterval = 1; static constexpr int maxRefreshInterval = 60;