mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
mpd: add filename formatter
This commit is contained in:
parent
7b115913de
commit
11239a4900
@ -41,6 +41,7 @@ class MPD : public ALabel {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string getTag(mpd_tag_type type, unsigned idx = 0) const;
|
std::string getTag(mpd_tag_type type, unsigned idx = 0) const;
|
||||||
|
std::string getFilename() const;
|
||||||
void setLabel();
|
void setLabel();
|
||||||
std::string getStateIcon() const;
|
std::string getStateIcon() const;
|
||||||
std::string getOptionIcon(std::string optionName, bool activated) const;
|
std::string getOptionIcon(std::string optionName, bool activated) const;
|
||||||
|
@ -73,6 +73,16 @@ std::string waybar::modules::MPD::getTag(mpd_tag_type type, unsigned idx) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string waybar::modules::MPD::getFilename() const {
|
||||||
|
std::string path = mpd_song_get_uri(song_.get());
|
||||||
|
size_t position = path.find_last_of("/");
|
||||||
|
if (position == std::string::npos) {
|
||||||
|
return path;
|
||||||
|
} else {
|
||||||
|
return path.substr(position + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void waybar::modules::MPD::setLabel() {
|
void waybar::modules::MPD::setLabel() {
|
||||||
if (connection_ == nullptr) {
|
if (connection_ == nullptr) {
|
||||||
label_.get_style_context()->add_class("disconnected");
|
label_.get_style_context()->add_class("disconnected");
|
||||||
@ -100,7 +110,7 @@ void waybar::modules::MPD::setLabel() {
|
|||||||
|
|
||||||
auto format = format_;
|
auto format = format_;
|
||||||
Glib::ustring artist, album_artist, album, title;
|
Glib::ustring artist, album_artist, album, title;
|
||||||
std::string date;
|
std::string date, filename;
|
||||||
int song_pos = 0, queue_length = 0, volume = 0;
|
int song_pos = 0, queue_length = 0, volume = 0;
|
||||||
std::chrono::seconds elapsedTime, totalTime;
|
std::chrono::seconds elapsedTime, totalTime;
|
||||||
|
|
||||||
@ -130,6 +140,7 @@ void waybar::modules::MPD::setLabel() {
|
|||||||
album = getTag(MPD_TAG_ALBUM);
|
album = getTag(MPD_TAG_ALBUM);
|
||||||
title = getTag(MPD_TAG_TITLE);
|
title = getTag(MPD_TAG_TITLE);
|
||||||
date = getTag(MPD_TAG_DATE);
|
date = getTag(MPD_TAG_DATE);
|
||||||
|
filename = getFilename();
|
||||||
song_pos = mpd_status_get_song_pos(status_.get()) + 1;
|
song_pos = mpd_status_get_song_pos(status_.get()) + 1;
|
||||||
volume = mpd_status_get_volume(status_.get());
|
volume = mpd_status_get_volume(status_.get());
|
||||||
if (volume < 0) {
|
if (volume < 0) {
|
||||||
@ -165,7 +176,8 @@ void waybar::modules::MPD::setLabel() {
|
|||||||
fmt::arg("totalTime", totalTime), fmt::arg("songPosition", song_pos),
|
fmt::arg("totalTime", totalTime), fmt::arg("songPosition", song_pos),
|
||||||
fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon),
|
fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon),
|
||||||
fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon),
|
fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon),
|
||||||
fmt::arg("repeatIcon", repeatIcon), fmt::arg("singleIcon", singleIcon)));
|
fmt::arg("repeatIcon", repeatIcon), fmt::arg("singleIcon", singleIcon),
|
||||||
|
fmt::arg("filename", filename)));
|
||||||
} catch (fmt::format_error const& e) {
|
} catch (fmt::format_error const& e) {
|
||||||
spdlog::warn("mpd: format error: {}", e.what());
|
spdlog::warn("mpd: format error: {}", e.what());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user