Skip to content

Commit

Permalink
Add option to ignore unavailable tracks, fixes #209
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed Dec 16, 2023
1 parent 02ebc69 commit acabd01
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/include/lib/settings/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/settings/general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/list/tracks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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())
Expand Down
11 changes: 11 additions & 0 deletions src/settingspage/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/settingspage/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit acabd01

Please sign in to comment.