Make lyrics and last_fm screens lockable and startup screens

This commit is contained in:
Andrzej Rybczak
2016-12-25 16:06:38 +01:00
parent e9ae99b5f0
commit 4cd94cb4b3
9 changed files with 81 additions and 49 deletions

1
NEWS
View File

@@ -16,6 +16,7 @@ ncmpcpp-0.8 (????-??-??)
* Wide character version of ncurses is now required. * Wide character version of ncurses is now required.
* Added 'statusbar_time_color' and 'player_state_color' configuration variables for further customization of statusbar. * Added 'statusbar_time_color' and 'player_state_color' configuration variables for further customization of statusbar.
* Format information can now be attached to selected color variables in the configuration file. Because of that variable 'progressbar_boldness' is now deprecated in favor of extended 'progressbar_color' and 'progressbar_elapsed_color' (for more information see example configuration file). * Format information can now be attached to selected color variables in the configuration file. Because of that variable 'progressbar_boldness' is now deprecated in favor of extended 'progressbar_color' and 'progressbar_elapsed_color' (for more information see example configuration file).
* Lyrics and last_fm can now be startup screens and are lockable.
ncmpcpp-0.7.7 (2016-10-31) ncmpcpp-0.7.7 (2016-10-31)
* Fixed compilation on 32bit platforms. * Fixed compilation on 32bit platforms.

View File

@@ -392,8 +392,9 @@
## - "previous" - switch between the current and previous screen. ## - "previous" - switch between the current and previous screen.
## - "screen1,...,screenN" - switch between given sequence of screens. ## - "screen1,...,screenN" - switch between given sequence of screens.
## ##
## Screens available for use: help, playlist, browser, search_engine, ## Screens available for use: help, playlist, browser,
## media_library, playlist_editor, tag_editor, outputs, visualizer, clock. ## search_engine, media_library, playlist_editor, tag_editor,
## outputs, visualizer, clock, lyrics, last_fm.
## ##
#screen_switcher_mode = playlist, browser #screen_switcher_mode = playlist, browser
# #

View File

@@ -97,6 +97,22 @@ bool findSelectedRangeAndPrintInfoIfNot(Iterator &first, Iterator &last)
return success; return success;
} }
template <typename Iterator>
Iterator nextScreenTypeInSequence(Iterator first, Iterator last, ScreenType type)
{
auto it = std::find(first, last, type);
if (it == last)
return first;
else
{
++it;
if (it == last)
return first;
else
return it;
}
}
} }
namespace Actions { namespace Actions {
@@ -2393,7 +2409,8 @@ void ShowArtistInfo::run()
if (!artist.empty()) if (!artist.empty())
{ {
myLastfm->queueJob(new LastFm::ArtistInfo(artist, Config.lastfm_preferred_language)); myLastfm->queueJob(new LastFm::ArtistInfo(artist, Config.lastfm_preferred_language));
myLastfm->switchTo(); if (!isVisible(myLastfm))
myLastfm->switchTo();
} }
} }
@@ -2415,7 +2432,8 @@ void ShowLyrics::run()
{ {
if (m_song != nullptr) if (m_song != nullptr)
myLyrics->fetch(*m_song); myLyrics->fetch(*m_song);
myLyrics->switchTo(); if (myScreen == myLyrics || !isVisible(myLyrics))
myLyrics->switchTo();
} }
void Quit::run() void Quit::run()
@@ -2432,12 +2450,11 @@ void NextScreen::run()
} }
else if (!Config.screen_sequence.empty()) else if (!Config.screen_sequence.empty())
{ {
const auto &seq = Config.screen_sequence; auto screen = nextScreenTypeInSequence(
auto screen_type = std::find(seq.begin(), seq.end(), myScreen->type()); Config.screen_sequence.begin(),
if (++screen_type == seq.end()) Config.screen_sequence.end(),
toScreen(seq.front())->switchTo(); myScreen->type());
else toScreen(*screen)->switchTo();
toScreen(*screen_type)->switchTo();
} }
} }
@@ -2450,12 +2467,11 @@ void PreviousScreen::run()
} }
else if (!Config.screen_sequence.empty()) else if (!Config.screen_sequence.empty())
{ {
const auto &seq = Config.screen_sequence; auto screen = nextScreenTypeInSequence(
auto screen_type = std::find(seq.begin(), seq.end(), myScreen->type()); Config.screen_sequence.rbegin(),
if (screen_type == seq.begin()) Config.screen_sequence.rend(),
toScreen(seq.back())->switchTo(); myScreen->type());
else toScreen(*screen)->switchTo();
toScreen(*--screen_type)->switchTo();
} }
} }

View File

@@ -36,7 +36,7 @@ struct Service
typedef std::pair<bool, std::string> Result; typedef std::pair<bool, std::string> Result;
Service(Arguments args) : m_arguments(args) { } Service(Arguments args) : m_arguments(args) { }
virtual const char *name() = 0; virtual const char *name() = 0;
virtual Result fetch(); virtual Result fetch();

View File

@@ -33,7 +33,8 @@ using Global::MainStartY;
Lastfm *myLastfm; Lastfm *myLastfm;
Lastfm::Lastfm() Lastfm::Lastfm()
: Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border())) : Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
, m_refresh_window(false)
{ } { }
void Lastfm::resize() void Lastfm::resize()
@@ -47,13 +48,36 @@ void Lastfm::resize()
std::wstring Lastfm::title() std::wstring Lastfm::title()
{ {
return m_title; if (m_title.empty())
return L"Last.fm";
else
return m_title;
} }
void Lastfm::update() void Lastfm::update()
{ {
if (m_worker.valid() && m_worker.is_ready()) if (m_worker.valid() && m_worker.is_ready())
getResult(); {
auto result = m_worker.get();
if (result.first)
{
w.clear();
w << Charset::utf8ToLocale(result.second);
m_service->beautifyOutput(w);
}
else
w << " " << NC::Color::Red << result.second << NC::Color::End;
// reset m_worker so it's no longer valid
m_worker = boost::BOOST_THREAD_FUTURE<LastFm::Service::Result>();
m_refresh_window = true;
}
if (m_refresh_window)
{
m_refresh_window = false;
w.flush();
w.refresh();
}
} }
void Lastfm::switchTo() void Lastfm::switchTo()
@@ -67,20 +91,3 @@ void Lastfm::switchTo()
else else
switchToPreviousScreen(); switchToPreviousScreen();
} }
void Lastfm::getResult()
{
auto result = m_worker.get();
if (result.first)
{
w.clear();
w << Charset::utf8ToLocale(result.second);
m_service->beautifyOutput(w);
}
else
w << " " << NC::Color::Red << result.second << NC::Color::End;
w.flush();
w.refresh();
// reset m_worker so it's no longer valid
m_worker = boost::BOOST_THREAD_FUTURE<LastFm::Service::Result>();
}

View File

@@ -43,7 +43,7 @@ struct Lastfm: Screen<NC::Scrollpad>, Tabbable
virtual void update() override; virtual void update() override;
virtual bool isLockable() override { return false; } virtual bool isLockable() override { return true; }
virtual bool isMergable() override { return true; } virtual bool isMergable() override { return true; }
template <typename ServiceT> template <typename ServiceT>
@@ -61,14 +61,13 @@ struct Lastfm: Screen<NC::Scrollpad>, Tabbable
w.clear(); w.clear();
w << "Fetching information..."; w << "Fetching information...";
w.flush(); m_refresh_window = true;
m_title = ToWString(m_service->name()); m_title = ToWString(m_service->name());
} }
private: private:
void getResult();
std::wstring m_title; std::wstring m_title;
bool m_refresh_window;
std::shared_ptr<LastFm::Service> m_service; std::shared_ptr<LastFm::Service> m_service;
boost::BOOST_THREAD_FUTURE<LastFm::Service::Result> m_worker; boost::BOOST_THREAD_FUTURE<LastFm::Service::Result> m_worker;

View File

@@ -259,13 +259,17 @@ void Lyrics::switchTo()
std::wstring Lyrics::title() std::wstring Lyrics::title()
{ {
std::wstring result = L"Lyrics: "; std::wstring result = L"Lyrics";
result += Scroller( if (!m_song.empty())
Format::stringify<wchar_t>(Format::parse(L"{%a - %t}|{%f}"), &m_song), {
m_scroll_begin, result += L": ";
COLS - result.length() - (Config.design == Design::Alternative result += Scroller(
? 2 Format::stringify<wchar_t>(Format::parse(L"{%a - %t}|{%f}"), &m_song),
: Global::VolumeState.length())); m_scroll_begin,
COLS - result.length() - (Config.design == Design::Alternative
? 2
: Global::VolumeState.length()));
}
return result; return result;
} }

View File

@@ -46,7 +46,7 @@ struct Lyrics: Screen<NC::Scrollpad>, Tabbable
virtual void update() override; virtual void update() override;
virtual bool isLockable() override { return false; } virtual bool isLockable() override { return true; }
virtual bool isMergable() override { return true; } virtual bool isMergable() override { return true; }
// other members // other members

View File

@@ -123,6 +123,10 @@ ScreenType stringtoStartupScreenType(const std::string &s)
else if (s == "visualizer") else if (s == "visualizer")
result = ScreenType::Visualizer; result = ScreenType::Visualizer;
# endif // ENABLE_VISUALIZER # endif // ENABLE_VISUALIZER
else if (s == "lyrics")
result = ScreenType::Lyrics;
else if (s == "last_fm")
result = ScreenType::Lastfm;
return result; return result;
} }