Make lyrics and last_fm screens lockable and startup screens
This commit is contained in:
@@ -33,7 +33,8 @@ using Global::MainStartY;
|
||||
Lastfm *myLastfm;
|
||||
|
||||
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()
|
||||
@@ -47,13 +48,36 @@ void Lastfm::resize()
|
||||
|
||||
std::wstring Lastfm::title()
|
||||
{
|
||||
return m_title;
|
||||
if (m_title.empty())
|
||||
return L"Last.fm";
|
||||
else
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void Lastfm::update()
|
||||
{
|
||||
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()
|
||||
@@ -67,20 +91,3 @@ void Lastfm::switchTo()
|
||||
else
|
||||
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>();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ struct Lastfm: Screen<NC::Scrollpad>, Tabbable
|
||||
|
||||
virtual void update() override;
|
||||
|
||||
virtual bool isLockable() override { return false; }
|
||||
virtual bool isLockable() override { return true; }
|
||||
virtual bool isMergable() override { return true; }
|
||||
|
||||
template <typename ServiceT>
|
||||
@@ -61,14 +61,13 @@ struct Lastfm: Screen<NC::Scrollpad>, Tabbable
|
||||
|
||||
w.clear();
|
||||
w << "Fetching information...";
|
||||
w.flush();
|
||||
m_refresh_window = true;
|
||||
m_title = ToWString(m_service->name());
|
||||
}
|
||||
|
||||
private:
|
||||
void getResult();
|
||||
|
||||
std::wstring m_title;
|
||||
bool m_refresh_window;
|
||||
|
||||
std::shared_ptr<LastFm::Service> m_service;
|
||||
boost::BOOST_THREAD_FUTURE<LastFm::Service::Result> m_worker;
|
||||
|
||||
@@ -259,13 +259,17 @@ void Lyrics::switchTo()
|
||||
|
||||
std::wstring Lyrics::title()
|
||||
{
|
||||
std::wstring result = L"Lyrics: ";
|
||||
result += Scroller(
|
||||
Format::stringify<wchar_t>(Format::parse(L"{%a - %t}|{%f}"), &m_song),
|
||||
m_scroll_begin,
|
||||
COLS - result.length() - (Config.design == Design::Alternative
|
||||
? 2
|
||||
: Global::VolumeState.length()));
|
||||
std::wstring result = L"Lyrics";
|
||||
if (!m_song.empty())
|
||||
{
|
||||
result += L": ";
|
||||
result += Scroller(
|
||||
Format::stringify<wchar_t>(Format::parse(L"{%a - %t}|{%f}"), &m_song),
|
||||
m_scroll_begin,
|
||||
COLS - result.length() - (Config.design == Design::Alternative
|
||||
? 2
|
||||
: Global::VolumeState.length()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ struct Lyrics: Screen<NC::Scrollpad>, Tabbable
|
||||
|
||||
virtual void update() override;
|
||||
|
||||
virtual bool isLockable() override { return false; }
|
||||
virtual bool isLockable() override { return true; }
|
||||
virtual bool isMergable() override { return true; }
|
||||
|
||||
// other members
|
||||
|
||||
@@ -123,6 +123,10 @@ ScreenType stringtoStartupScreenType(const std::string &s)
|
||||
else if (s == "visualizer")
|
||||
result = ScreenType::Visualizer;
|
||||
# endif // ENABLE_VISUALIZER
|
||||
else if (s == "lyrics")
|
||||
result = ScreenType::Lyrics;
|
||||
else if (s == "last_fm")
|
||||
result = ScreenType::Lastfm;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user