2020-10-04 05:01:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
2020-10-19 18:54:36 +00:00
|
|
|
#include <mpd/client.h>
|
2020-10-04 05:01:51 +00:00
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <thread>
|
|
|
|
|
2022-11-24 11:28:52 +00:00
|
|
|
#include "ALabel.hpp"
|
2020-10-04 05:01:51 +00:00
|
|
|
#include "modules/mpd/state.hpp"
|
|
|
|
|
|
|
|
namespace waybar::modules {
|
|
|
|
|
2022-11-24 11:28:52 +00:00
|
|
|
class MPD : public ALabel {
|
2020-10-04 05:01:51 +00:00
|
|
|
friend class detail::Context;
|
|
|
|
|
|
|
|
// State machine
|
|
|
|
detail::Context context_{this};
|
|
|
|
|
|
|
|
const std::string module_name_;
|
|
|
|
|
|
|
|
// Not using unique_ptr since we don't manage the pointer
|
|
|
|
// (It's either nullptr, or from the config)
|
2022-04-06 06:37:19 +00:00
|
|
|
const char* server_;
|
|
|
|
const unsigned port_;
|
2020-10-19 18:54:36 +00:00
|
|
|
const std::string password_;
|
2020-10-04 05:01:51 +00:00
|
|
|
|
|
|
|
unsigned timeout_;
|
|
|
|
|
|
|
|
detail::unique_connection connection_;
|
|
|
|
|
|
|
|
detail::unique_status status_;
|
2022-04-06 06:37:19 +00:00
|
|
|
mpd_state state_;
|
|
|
|
detail::unique_song song_;
|
2020-10-04 05:01:51 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
MPD(const std::string&, const Json::Value&);
|
|
|
|
virtual ~MPD() noexcept = default;
|
2023-03-02 13:57:07 +00:00
|
|
|
auto update() -> void override;
|
2020-10-04 05:01:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string getTag(mpd_tag_type type, unsigned idx = 0) const;
|
2023-06-22 07:02:15 +00:00
|
|
|
Glib::ustring getArtistTitleOrFilename() const;
|
2022-07-22 10:09:09 +00:00
|
|
|
std::string getFilename() const;
|
2022-04-06 06:37:19 +00:00
|
|
|
void setLabel();
|
2020-10-04 05:01:51 +00:00
|
|
|
std::string getStateIcon() const;
|
|
|
|
std::string getOptionIcon(std::string optionName, bool activated) const;
|
|
|
|
|
|
|
|
// GUI-side methods
|
|
|
|
bool handlePlayPause(GdkEventButton* const&);
|
|
|
|
void emit() { dp.emit(); }
|
|
|
|
|
|
|
|
// MPD-side, Non-GUI methods.
|
|
|
|
void tryConnect();
|
|
|
|
void checkErrors(mpd_connection* conn);
|
|
|
|
void fetchState();
|
|
|
|
void queryMPD();
|
|
|
|
|
|
|
|
inline bool stopped() const { return connection_ && state_ == MPD_STATE_STOP; }
|
|
|
|
inline bool playing() const { return connection_ && state_ == MPD_STATE_PLAY; }
|
|
|
|
inline bool paused() const { return connection_ && state_ == MPD_STATE_PAUSE; }
|
|
|
|
};
|
|
|
|
|
|
|
|
#if !defined(MPD_NOINLINE)
|
|
|
|
#include "modules/mpd/state.inl.hpp"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace waybar::modules
|