2016-05-31 03:58:58 +00:00
|
|
|
#pragma once
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-11-20 22:04:31 +00:00
|
|
|
#include <chrono>
|
2016-10-29 04:52:48 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
#include "adapters/mpd.hpp"
|
2016-11-20 22:04:31 +00:00
|
|
|
#include "modules/meta/event_module.hpp"
|
2020-05-15 17:59:08 +00:00
|
|
|
#include "utils/env.hpp"
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-06-09 11:42:03 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
using namespace mpd;
|
|
|
|
|
|
|
|
namespace modules {
|
2019-12-02 18:14:26 +00:00
|
|
|
class mpd_module : public event_module<mpd_module> {
|
2016-06-15 03:32:35 +00:00
|
|
|
public:
|
2016-12-21 07:00:09 +00:00
|
|
|
explicit mpd_module(const bar_settings&, string);
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
void teardown();
|
|
|
|
inline bool connected() const;
|
|
|
|
void idle();
|
|
|
|
bool has_event();
|
|
|
|
bool update();
|
|
|
|
string get_format() const;
|
2016-11-14 00:21:57 +00:00
|
|
|
string get_output();
|
2016-11-25 12:55:15 +00:00
|
|
|
bool build(builder* builder, const string& tag) const;
|
2016-12-21 07:38:44 +00:00
|
|
|
|
2020-05-15 17:59:08 +00:00
|
|
|
static constexpr auto TYPE = "internal/mpd";
|
|
|
|
|
2020-05-24 16:35:12 +00:00
|
|
|
static constexpr const char* EVENT_PLAY = "play";
|
|
|
|
static constexpr const char* EVENT_PAUSE = "pause";
|
|
|
|
static constexpr const char* EVENT_STOP = "stop";
|
|
|
|
static constexpr const char* EVENT_PREV = "prev";
|
|
|
|
static constexpr const char* EVENT_NEXT = "next";
|
|
|
|
static constexpr const char* EVENT_REPEAT = "repeat";
|
|
|
|
static constexpr const char* EVENT_SINGLE = "single";
|
|
|
|
static constexpr const char* EVENT_RANDOM = "random";
|
|
|
|
static constexpr const char* EVENT_CONSUME = "consume";
|
|
|
|
static constexpr const char* EVENT_SEEK = "seek";
|
|
|
|
|
2016-12-21 07:38:44 +00:00
|
|
|
protected:
|
2020-05-24 16:35:12 +00:00
|
|
|
bool input(string&& action);
|
2016-06-15 03:32:35 +00:00
|
|
|
|
|
|
|
private:
|
2016-12-23 14:54:06 +00:00
|
|
|
static constexpr const char* FORMAT_ONLINE{"format-online"};
|
2017-05-08 17:50:17 +00:00
|
|
|
static constexpr const char* FORMAT_PLAYING{"format-playing"};
|
|
|
|
static constexpr const char* FORMAT_PAUSED{"format-paused"};
|
|
|
|
static constexpr const char* FORMAT_STOPPED{"format-stopped"};
|
2016-12-23 14:54:06 +00:00
|
|
|
static constexpr const char* TAG_BAR_PROGRESS{"<bar-progress>"};
|
|
|
|
static constexpr const char* TAG_TOGGLE{"<toggle>"};
|
|
|
|
static constexpr const char* TAG_TOGGLE_STOP{"<toggle-stop>"};
|
|
|
|
static constexpr const char* TAG_LABEL_SONG{"<label-song>"};
|
|
|
|
static constexpr const char* TAG_LABEL_TIME{"<label-time>"};
|
|
|
|
static constexpr const char* TAG_ICON_RANDOM{"<icon-random>"};
|
|
|
|
static constexpr const char* TAG_ICON_REPEAT{"<icon-repeat>"};
|
2018-06-21 15:00:26 +00:00
|
|
|
/*
|
|
|
|
* Deprecated
|
|
|
|
*/
|
2016-12-23 14:54:06 +00:00
|
|
|
static constexpr const char* TAG_ICON_REPEAT_ONE{"<icon-repeatone>"};
|
2018-06-21 15:00:26 +00:00
|
|
|
/*
|
|
|
|
* Replaces icon-repeatone
|
|
|
|
*
|
|
|
|
* repeatone is misleading, since it doesn't actually affect the repeating behaviour
|
|
|
|
*/
|
|
|
|
static constexpr const char* TAG_ICON_SINGLE{"<icon-single>"};
|
2017-12-04 19:38:17 +00:00
|
|
|
static constexpr const char* TAG_ICON_CONSUME{"<icon-consume>"};
|
2016-12-23 14:54:06 +00:00
|
|
|
static constexpr const char* TAG_ICON_PREV{"<icon-prev>"};
|
|
|
|
static constexpr const char* TAG_ICON_STOP{"<icon-stop>"};
|
|
|
|
static constexpr const char* TAG_ICON_PLAY{"<icon-play>"};
|
|
|
|
static constexpr const char* TAG_ICON_PAUSE{"<icon-pause>"};
|
|
|
|
static constexpr const char* TAG_ICON_NEXT{"<icon-next>"};
|
|
|
|
static constexpr const char* TAG_ICON_SEEKB{"<icon-seekb>"};
|
|
|
|
static constexpr const char* TAG_ICON_SEEKF{"<icon-seekf>"};
|
|
|
|
|
|
|
|
static constexpr const char* FORMAT_OFFLINE{"format-offline"};
|
|
|
|
static constexpr const char* TAG_LABEL_OFFLINE{"<label-offline>"};
|
|
|
|
|
|
|
|
unique_ptr<mpdconnection> m_mpd;
|
2018-01-31 08:45:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stores the mpdstatus instance for the current connection
|
|
|
|
* m_status is not initialized if mpd is not connect, you always have to
|
|
|
|
* make sure that m_status is not NULL before dereferencing it
|
|
|
|
*/
|
2016-12-23 14:54:06 +00:00
|
|
|
unique_ptr<mpdstatus> m_status;
|
|
|
|
|
2018-02-14 09:46:56 +00:00
|
|
|
string m_host{env_util::get("MPD_HOST", "127.0.0.1")};
|
2016-12-23 14:54:06 +00:00
|
|
|
string m_pass;
|
|
|
|
unsigned int m_port{6600U};
|
|
|
|
|
|
|
|
chrono::system_clock::time_point m_lastsync{};
|
|
|
|
float m_synctime{1.0f};
|
|
|
|
|
2017-01-13 12:02:51 +00:00
|
|
|
int m_quick_attempts{0};
|
|
|
|
|
2016-12-23 14:54:06 +00:00
|
|
|
// This flag is used to let thru a broadcast once every time
|
|
|
|
// the connection state changes
|
2017-01-13 12:02:51 +00:00
|
|
|
connection_state m_statebroadcasted{connection_state::NONE};
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
progressbar_t m_bar_progress;
|
|
|
|
iconset_t m_icons;
|
|
|
|
label_t m_label_song;
|
|
|
|
label_t m_label_time;
|
|
|
|
label_t m_label_offline;
|
|
|
|
|
|
|
|
string m_toggle_on_color;
|
|
|
|
string m_toggle_off_color;
|
2016-05-19 14:41:06 +00:00
|
|
|
};
|
2020-05-15 17:59:08 +00:00
|
|
|
} // namespace modules
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|