feat(mpd): Add state-specific formats #524

This commit is contained in:
Vasili Karaev 2017-05-08 20:50:17 +03:00 committed by Michael Carlberg
parent b2f00cc08a
commit 5c41e3d045
2 changed files with 19 additions and 6 deletions

View File

@ -29,6 +29,9 @@ namespace modules {
private: private:
static constexpr const char* FORMAT_ONLINE{"format-online"}; static constexpr const char* FORMAT_ONLINE{"format-online"};
static constexpr const char* FORMAT_PLAYING{"format-playing"};
static constexpr const char* FORMAT_PAUSED{"format-paused"};
static constexpr const char* FORMAT_STOPPED{"format-stopped"};
static constexpr const char* TAG_BAR_PROGRESS{"<bar-progress>"}; static constexpr const char* TAG_BAR_PROGRESS{"<bar-progress>"};
static constexpr const char* TAG_TOGGLE{"<toggle>"}; static constexpr const char* TAG_TOGGLE{"<toggle>"};
static constexpr const char* TAG_TOGGLE_STOP{"<toggle-stop>"}; static constexpr const char* TAG_TOGGLE_STOP{"<toggle-stop>"};

View File

@ -20,11 +20,13 @@ namespace modules {
m_synctime = m_conf.get(name(), "interval", m_synctime); m_synctime = m_conf.get(name(), "interval", m_synctime);
// Add formats and elements {{{ // Add formats and elements {{{
auto format_online = m_conf.get<string>(name(), FORMAT_ONLINE, TAG_LABEL_SONG);
m_formatter->add(FORMAT_ONLINE, TAG_LABEL_SONG, for (auto&& format : {FORMAT_PLAYING, FORMAT_PAUSED, FORMAT_STOPPED}) {
{TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_TOGGLE_STOP, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM, m_formatter->add(format, format_online,
TAG_ICON_REPEAT, TAG_ICON_REPEAT_ONE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY, TAG_ICON_PAUSE, {TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_TOGGLE_STOP, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM,
TAG_ICON_NEXT, TAG_ICON_SEEKB, TAG_ICON_SEEKF}); TAG_ICON_REPEAT, TAG_ICON_REPEAT_ONE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY, TAG_ICON_PAUSE,
TAG_ICON_NEXT, TAG_ICON_SEEKB, TAG_ICON_SEEKF});
}
m_formatter->add(FORMAT_OFFLINE, "", {TAG_LABEL_OFFLINE}); m_formatter->add(FORMAT_OFFLINE, "", {TAG_LABEL_OFFLINE});
@ -243,7 +245,15 @@ namespace modules {
} }
string mpd_module::get_format() const { string mpd_module::get_format() const {
return connected() ? FORMAT_ONLINE : FORMAT_OFFLINE; if (!connected()) {
return FORMAT_OFFLINE;
} else if (m_status->match_state(mpdstate::PLAYING)) {
return FORMAT_PLAYING;
} else if (m_status->match_state(mpdstate::PAUSED)) {
return FORMAT_PAUSED;
} else {
return FORMAT_STOPPED;
}
} }
string mpd_module::get_output() { string mpd_module::get_output() {