Add support for fetching lyrics in background for selected songs

This commit is contained in:
Andrzej Rybczak
2016-11-21 11:47:13 +01:00
parent 5b56c48c4a
commit 00f70e23e6
6 changed files with 35 additions and 0 deletions

View File

@@ -2273,6 +2273,20 @@ void ToggleMediaLibrarySortMode::run()
myLibrary->toggleSortMode();
}
bool FetchLyricsInBackground::canBeRun()
{
m_hs = dynamic_cast<HasSongs *>(myScreen);
return m_hs != nullptr && m_hs->itemAvailable();
}
void FetchLyricsInBackground::run()
{
auto songs = m_hs->getSelectedSongs();
for (const auto &s : songs)
myLyrics->fetchInBackground(s, true);
Statusbar::print("Selected songs queued for lyrics fetching");
}
bool RefetchLyrics::canBeRun()
{
return myScreen == myLyrics;
@@ -2785,6 +2799,7 @@ void populateActions()
insert_action(new Actions::ToggleBrowserSortMode());
insert_action(new Actions::ToggleLibraryTagType());
insert_action(new Actions::ToggleMediaLibrarySortMode());
insert_action(new Actions::FetchLyricsInBackground());
insert_action(new Actions::RefetchLyrics());
insert_action(new Actions::SetSelectedItemsPriority());
insert_action(new Actions::ToggleOutput());

View File

@@ -137,6 +137,7 @@ enum class Type
ToggleBrowserSortMode,
ToggleLibraryTagType,
ToggleMediaLibrarySortMode,
FetchLyricsInBackground,
RefetchLyrics,
SetSelectedItemsPriority,
ToggleOutput,
@@ -1163,6 +1164,18 @@ private:
virtual void run() override;
};
struct FetchLyricsInBackground: BaseAction
{
FetchLyricsInBackground()
: BaseAction(Type::FetchLyricsInBackground, "fetch_lyrics_in_background") { }
private:
virtual bool canBeRun() override;
virtual void run() override;
HasSongs *m_hs;
};
struct RefetchLyrics: BaseAction
{
RefetchLyrics(): BaseAction(Type::RefetchLyrics, "refetch_lyrics") { }

View File

@@ -721,6 +721,8 @@ void BindingsConfiguration::generateDefaults()
if (notBound(k = stringToKey("L")))
bind(k, Actions::Type::ToggleLyricsFetcher);
if (notBound(k = stringToKey("F")))
bind(k, Actions::Type::FetchLyricsInBackground);
if (notBound(k = stringToKey("alt-l")))
bind(k, Actions::Type::ToggleFetchingLyricsInBackground);
if (notBound(k = stringToKey("ctrl-l")))
bind(k, Actions::Type::ToggleScreenLock);

View File

@@ -230,6 +230,7 @@ void write_bindings(NC::Scrollpad &w)
key(w, Type::JumpToPositionInSong, "Jump to given position in playing song (formats: mm:ss, x%)");
key(w, Type::ShowSongInfo, "Show song info");
key(w, Type::ShowArtistInfo, "Show artist info");
key(w, Type::FetchLyricsInBackground, "Fetch lyrics for selected songs");
key(w, Type::ToggleLyricsFetcher, "Toggle lyrics fetcher");
key(w, Type::ToggleFetchingLyricsInBackground, "Toggle fetching lyrics for playing songs in background");
key(w, Type::ShowLyrics, "Show/hide song lyrics");