fix(mpd): Hide module on empty playlist

Closes #149
This commit is contained in:
Michael Carlberg 2016-11-14 01:21:57 +01:00
parent 4b0e648cb8
commit 04fac96d78
4 changed files with 18 additions and 4 deletions

View File

@ -139,6 +139,7 @@ namespace mpd {
bool match_state(mpdstate state) const; bool match_state(mpdstate state) const;
int get_songid() const; int get_songid() const;
int get_queuelen() const;
unsigned get_total_time() const; unsigned get_total_time() const;
unsigned get_elapsed_time() const; unsigned get_elapsed_time() const;
unsigned get_elapsed_percentage(); unsigned get_elapsed_percentage();
@ -157,6 +158,7 @@ namespace mpd {
bool m_single = false; bool m_single = false;
int m_songid; int m_songid;
int m_queuelen;
unsigned long m_total_time; unsigned long m_total_time;
unsigned long m_elapsed_time; unsigned long m_elapsed_time;

View File

@ -25,14 +25,12 @@ namespace modules {
bool has_event(); bool has_event();
bool update(); bool update();
string get_format() const; string get_format() const;
string get_output();
bool build(builder* builder, string tag) const; bool build(builder* builder, string tag) const;
bool handle_event(string cmd); bool handle_event(string cmd);
bool receive_events() const; bool receive_events() const;
private: private:
// static const int PROGRESSBAR_THREAD_SYNC_COUNT = 10;
// const chrono::duration<double> PROGRESSBAR_THREAD_INTERVAL = 1s;
static constexpr auto FORMAT_ONLINE = "format-online"; static constexpr auto FORMAT_ONLINE = "format-online";
static constexpr auto TAG_BAR_PROGRESS = "<bar-progress>"; static constexpr auto TAG_BAR_PROGRESS = "<bar-progress>";
static constexpr auto TAG_TOGGLE = "<toggle>"; static constexpr auto TAG_TOGGLE = "<toggle>";

View File

@ -315,6 +315,7 @@ namespace mpd {
m_status.reset(mpd_run_status(*conn)); m_status.reset(mpd_run_status(*conn));
m_updated_at = chrono::system_clock::now(); m_updated_at = chrono::system_clock::now();
m_songid = mpd_status_get_song_id(m_status.get()); m_songid = mpd_status_get_song_id(m_status.get());
m_queuelen = mpd_status_get_queue_length(m_status.get());
m_random = mpd_status_get_random(m_status.get()); m_random = mpd_status_get_random(m_status.get());
m_repeat = mpd_status_get_repeat(m_status.get()); m_repeat = mpd_status_get_repeat(m_status.get());
m_single = mpd_status_get_single(m_status.get()); m_single = mpd_status_get_single(m_status.get());
@ -323,7 +324,7 @@ namespace mpd {
} }
void mpdstatus::update(int event, mpdconnection* connection) { void mpdstatus::update(int event, mpdconnection* connection) {
if (connection == nullptr || (event & (MPD_IDLE_PLAYER | MPD_IDLE_OPTIONS)) == false) if (connection == nullptr || (event & (MPD_IDLE_PLAYER | MPD_IDLE_OPTIONS | MPD_IDLE_PLAYLIST)) == false)
return; return;
fetch_data(connection); fetch_data(connection);
@ -375,6 +376,10 @@ namespace mpd {
return m_songid; return m_songid;
} }
int mpdstatus::get_queuelen() const {
return m_queuelen;
}
unsigned mpdstatus::get_total_time() const { unsigned mpdstatus::get_total_time() const {
return m_total_time; return m_total_time;
} }

View File

@ -215,6 +215,15 @@ namespace modules {
return connected() ? FORMAT_ONLINE : FORMAT_OFFLINE; return connected() ? FORMAT_ONLINE : FORMAT_OFFLINE;
} }
string mpd_module::get_output() {
if (m_status && m_status->get_queuelen() == 0) {
m_log.info("%s: Hiding module since queue is empty", name());
return "";
} else {
return event_module::get_output();
}
}
bool mpd_module::build(builder* builder, string tag) const { bool mpd_module::build(builder* builder, string tag) const {
bool is_playing = false; bool is_playing = false;
bool is_paused = false; bool is_paused = false;