From d3abcc97f6ba86e77aa9c89ecd6091d6f508f5c7 Mon Sep 17 00:00:00 2001 From: Jens Henniges Date: Mon, 4 Dec 2017 20:38:17 +0100 Subject: [PATCH] feat(mpd): Add support for icon-consume (#861) --- include/adapters/mpd.hpp | 3 +++ include/modules/mpd.hpp | 2 ++ src/adapters/mpd.cpp | 15 +++++++++++++++ src/modules/mpd.cpp | 14 ++++++++++++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/adapters/mpd.hpp b/include/adapters/mpd.hpp index 49fb6e02..5e7dbfa8 100644 --- a/include/adapters/mpd.hpp +++ b/include/adapters/mpd.hpp @@ -107,6 +107,7 @@ namespace mpd { void set_repeat(bool mode); void set_random(bool mode); void set_single(bool mode); + void set_consume(bool mode); operator mpd_connection_t::element_type*(); @@ -144,6 +145,7 @@ namespace mpd { bool random() const; bool repeat() const; bool single() const; + bool consume() const; bool match_state(mpdstate state) const; @@ -165,6 +167,7 @@ namespace mpd { bool m_random{false}; bool m_repeat{false}; bool m_single{false}; + bool m_consume{false}; int m_songid{0}; int m_queuelen{0}; diff --git a/include/modules/mpd.hpp b/include/modules/mpd.hpp index 280f63ba..bd010020 100644 --- a/include/modules/mpd.hpp +++ b/include/modules/mpd.hpp @@ -40,6 +40,7 @@ namespace modules { static constexpr const char* TAG_ICON_RANDOM{""}; static constexpr const char* TAG_ICON_REPEAT{""}; static constexpr const char* TAG_ICON_REPEAT_ONE{""}; + static constexpr const char* TAG_ICON_CONSUME{""}; static constexpr const char* TAG_ICON_PREV{""}; static constexpr const char* TAG_ICON_STOP{""}; static constexpr const char* TAG_ICON_PLAY{""}; @@ -59,6 +60,7 @@ namespace modules { static constexpr const char* EVENT_REPEAT{"mpdrepeat"}; static constexpr const char* EVENT_REPEAT_ONE{"mpdrepeatone"}; static constexpr const char* EVENT_RANDOM{"mpdrandom"}; + static constexpr const char* EVENT_CONSUME{"mpdconsume"}; static constexpr const char* EVENT_SEEK{"mpdseek"}; unique_ptr m_mpd; diff --git a/src/adapters/mpd.cpp b/src/adapters/mpd.cpp index 6140064f..c4e2f731 100644 --- a/src/adapters/mpd.cpp +++ b/src/adapters/mpd.cpp @@ -321,6 +321,16 @@ namespace mpd { } } + void mpdconnection::set_consume(bool mode) { + try { + check_prerequisites_commands_list(); + mpd_run_consume(m_connection.get(), mode); + check_errors(m_connection.get()); + } catch (const mpd_exception& e) { + m_log.err("mpdconnection.set_consume: %s", e.what()); + } + } + mpdconnection::operator mpd_connection_t::element_type*() { return m_connection.get(); } @@ -354,6 +364,7 @@ namespace mpd { m_random = mpd_status_get_random(m_status.get()); m_repeat = mpd_status_get_repeat(m_status.get()); m_single = mpd_status_get_single(m_status.get()); + m_consume = mpd_status_get_consume(m_status.get()); m_elapsed_time = mpd_status_get_elapsed_time(m_status.get()); m_total_time = mpd_status_get_total_time(m_status.get()); } @@ -404,6 +415,10 @@ namespace mpd { return m_single; } + bool mpdstatus::consume() const { + return m_consume; + } + bool mpdstatus::match_state(mpdstate state) const { return state == m_state; } diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index d2de604e..155663e7 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -25,7 +25,7 @@ namespace modules { m_formatter->add(format, format_online, {TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_TOGGLE_STOP, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM, 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}); + TAG_ICON_NEXT, TAG_ICON_SEEKB, TAG_ICON_SEEKF, TAG_ICON_CONSUME}); auto mod_format = m_formatter->get(format); mod_format->fg = m_conf.get(name(), FORMAT_ONLINE + "-foreground"s, mod_format->fg); mod_format->bg = m_conf.get(name(), FORMAT_ONLINE + "-background"s, mod_format->bg); @@ -74,6 +74,9 @@ namespace modules { if (m_formatter->has(TAG_ICON_REPEAT_ONE)) { m_icons->add("repeat_one", load_icon(m_conf, name(), TAG_ICON_REPEAT_ONE)); } + if (m_formatter->has(TAG_ICON_CONSUME)) { + m_icons->add("consume", load_icon(m_conf, name(), TAG_ICON_CONSUME)); + } if (m_formatter->has(TAG_LABEL_SONG)) { m_label_song = load_optional_label(m_conf, name(), TAG_LABEL_SONG, "%artist% - %title%"); @@ -82,7 +85,7 @@ namespace modules { m_label_time = load_optional_label(m_conf, name(), TAG_LABEL_TIME, "%elapsed% / %total%"); } if (m_formatter->has(TAG_ICON_RANDOM) || m_formatter->has(TAG_ICON_REPEAT) || - m_formatter->has(TAG_ICON_REPEAT_ONE)) { + m_formatter->has(TAG_ICON_REPEAT_ONE) || m_formatter->has(TAG_ICON_CONSUME)) { m_toggle_on_color = m_conf.get(name(), "toggle-on-foreground", ""s); m_toggle_off_color = m_conf.get(name(), "toggle-off-foreground", ""s); } @@ -252,6 +255,9 @@ namespace modules { m_icons->get("repeat_one")->m_foreground = m_status && m_status->single() ? m_toggle_on_color : m_toggle_off_color; } + if (m_icons->has("consume")) { + m_icons->get("consume")->m_foreground = m_status && m_status->consume() ? m_toggle_on_color : m_toggle_off_color; + } return true; } @@ -296,6 +302,8 @@ namespace modules { builder->cmd(mousebtn::LEFT, EVENT_REPEAT, m_icons->get("repeat")); } else if (tag == TAG_ICON_REPEAT_ONE) { builder->cmd(mousebtn::LEFT, EVENT_REPEAT_ONE, m_icons->get("repeat_one")); + } else if (tag == TAG_ICON_CONSUME) { + builder->cmd(mousebtn::LEFT, EVENT_CONSUME, m_icons->get("consume")); } else if (tag == TAG_ICON_PREV) { builder->cmd(mousebtn::LEFT, EVENT_PREV, m_icons->get("prev")); } else if ((tag == TAG_ICON_STOP || tag == TAG_TOGGLE_STOP) && (is_playing || is_paused)) { @@ -348,6 +356,8 @@ namespace modules { mpd->set_repeat(!status->repeat()); } else if (cmd == EVENT_RANDOM) { mpd->set_random(!status->random()); + } else if (cmd == EVENT_CONSUME) { + mpd->set_consume(!status->consume()); } else if (cmd.compare(0, strlen(EVENT_SEEK), EVENT_SEEK) == 0) { auto s = cmd.substr(strlen(EVENT_SEEK)); int percentage = 0;