50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#include "widgets/controlCenter/mediaWidget.hpp"
|
|
|
|
#include <memory>
|
|
|
|
MediaWidget::MediaWidget() : Gtk::Box(Gtk::Orientation::VERTICAL) {
|
|
this->set_hexpand(true);
|
|
this->set_vexpand(false);
|
|
this->add_css_class("control-center-media-widget");
|
|
this->container.set_orientation(Gtk::Orientation::VERTICAL);
|
|
this->container.set_hexpand(true);
|
|
this->container.set_vexpand(false);
|
|
this->append(this->container);
|
|
|
|
this->mprisController->signal_player_registered().connect(
|
|
[this](const std::string &bus_name) {
|
|
this->addPlayerWidget(bus_name);
|
|
});
|
|
|
|
this->mprisController->signal_player_deregistered().connect(
|
|
[this](const std::string &bus_name) {
|
|
this->removePlayerWidget(bus_name);
|
|
});
|
|
|
|
for (const auto &bus_name : this->mprisController->get_registered_players()) {
|
|
this->addPlayerWidget(bus_name);
|
|
}
|
|
}
|
|
|
|
void MediaWidget::addPlayerWidget(const std::string &bus_name) {
|
|
if (this->mediaWidgets.find(bus_name) != this->mediaWidgets.end()) {
|
|
return;
|
|
}
|
|
|
|
auto controller = MprisController::createForPlayer(bus_name);
|
|
auto widget = std::make_unique<MediaPlayer>(controller);
|
|
|
|
this->mediaWidgets.emplace(bus_name, std::move(widget));
|
|
this->container.append(*this->mediaWidgets[bus_name]);
|
|
}
|
|
|
|
void MediaWidget::removePlayerWidget(const std::string &bus_name) {
|
|
auto it = this->mediaWidgets.find(bus_name);
|
|
|
|
if (it == this->mediaWidgets.end()) {
|
|
return;
|
|
}
|
|
|
|
this->container.remove(*it->second);
|
|
this->mediaWidgets.erase(it);
|
|
} |