refacor media widget, apply clang format rule
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
#include "widgets/controlCenter/controlCenter.hpp"
|
||||
|
||||
#include "components/button/iconButton.hpp"
|
||||
#include "components/button/tabButton.hpp"
|
||||
|
||||
#include "components/mediaPlayer.hpp"
|
||||
|
||||
ControlCenter::ControlCenter(Icon::Type icon, std::string name)
|
||||
: Popover(icon, name) {
|
||||
this->popover->add_css_class("control-center-popover");
|
||||
this->container.set_orientation(Gtk::Orientation::VERTICAL);
|
||||
this->container.set_spacing(10);
|
||||
|
||||
|
||||
this->scrollview.set_child(this->container);
|
||||
this->scrollview.set_min_content_width(220);
|
||||
this->scrollview.set_max_content_width(220);
|
||||
this->scrollview.set_size_request(220, -1);
|
||||
this->scrollview.set_policy(
|
||||
Gtk::PolicyType::NEVER, Gtk::PolicyType::AUTOMATIC);
|
||||
this->scrollview.set_hexpand(false);
|
||||
@@ -26,84 +24,60 @@ ControlCenter::ControlCenter(Icon::Type icon, std::string name)
|
||||
this->tabRow.set_margin_bottom(4);
|
||||
this->tabRow.add_css_class("control-center-tab-row");
|
||||
|
||||
this->mediaControl = std::make_unique<TabButton>(Icon::PLAY_CIRCLE);
|
||||
this->testTabButton = std::make_unique<TabButton>(Icon::EMPTY_DASHBOARD);
|
||||
this->mediaTabButton = std::make_unique<TabButton>(Icon::PLAY_CIRCLE);
|
||||
this->infoTabButton = std::make_unique<TabButton>(Icon::EMPTY_DASHBOARD);
|
||||
this->timerButton = std::make_unique<TabButton>(Icon::TOKEN);
|
||||
|
||||
this->tabRow.append(*this->mediaControl);
|
||||
this->tabRow.append(*this->testTabButton);
|
||||
this->tabRow.append(*this->mediaTabButton);
|
||||
this->tabRow.append(*this->infoTabButton);
|
||||
this->tabRow.append(*this->timerButton);
|
||||
|
||||
this->container.append(this->tabRow);
|
||||
|
||||
this->contentStack.set_hhomogeneous(true);
|
||||
this->contentStack.set_vhomogeneous(false);
|
||||
this->contentStack.set_transition_type(Gtk::StackTransitionType::CROSSFADE);
|
||||
this->contentStack.set_transition_duration(150);
|
||||
|
||||
this->controlCenterContainer.set_orientation(Gtk::Orientation::VERTICAL);
|
||||
this->controlCenterContainer.set_spacing(4);
|
||||
this->mediaControlWidget = std::make_unique<MediaWidget>();
|
||||
|
||||
this->weatherWidget = std::make_unique<WeatherWidget>();
|
||||
|
||||
this->contentStack.add(*this->mediaControlWidget, "controls", "Controls");
|
||||
this->contentStack.add(*this->weatherWidget, "info", "Info");
|
||||
this->contentStack.add(*Gtk::make_managed<Gtk::Label>("Timer"), "timer", "Timer");
|
||||
|
||||
this->contentStack.add(this->controlCenterContainer, "controls", "Controls");
|
||||
this->contentStack.add(this->weatherWidget, "test", "Test");
|
||||
this->contentStack.set_visible_child("controls");
|
||||
this->setActiveTab("controls");
|
||||
this->setActiveTab("info");
|
||||
|
||||
this->container.append(this->contentStack);
|
||||
|
||||
this->mediaControl->signal_clicked().connect([this]() {
|
||||
this->mediaTabButton->signal_clicked().connect([this]() {
|
||||
this->setActiveTab("controls");
|
||||
});
|
||||
|
||||
this->testTabButton->signal_clicked().connect([this]() {
|
||||
this->setActiveTab("test");
|
||||
this->infoTabButton->signal_clicked().connect([this]() {
|
||||
this->setActiveTab("info");
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
this->timerButton->signal_clicked().connect([this]() {
|
||||
this->setActiveTab("timer");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void ControlCenter::setActiveTab(const std::string &tab_name) {
|
||||
this->contentStack.set_visible_child(tab_name);
|
||||
|
||||
this->mediaControl->setActive(false);
|
||||
this->testTabButton->setActive(false);
|
||||
this->mediaTabButton->setActive(false);
|
||||
this->infoTabButton->setActive(false);
|
||||
this->timerButton->setActive(false);
|
||||
|
||||
if (tab_name == "controls") {
|
||||
this->mediaControl->setActive(true);
|
||||
} else if (tab_name == "test") {
|
||||
this->testTabButton->setActive(true);
|
||||
this->mediaTabButton->setActive(true);
|
||||
} else if (tab_name == "info") {
|
||||
this->infoTabButton->setActive(true);
|
||||
} else if (tab_name == "timer") {
|
||||
this->timerButton->setActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ControlCenter::addPlayerWidget(const std::string &bus_name) {
|
||||
if (this->mediaWidgets.find(bus_name) != this->mediaWidgets.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto controller = MprisController::createForPlayer(bus_name);
|
||||
auto widget = Gtk::make_managed<MediaControlWidget>(controller);
|
||||
this->mediaWidgets.emplace(bus_name, widget);
|
||||
this->controlCenterContainer.append(*widget);
|
||||
}
|
||||
|
||||
void ControlCenter::removePlayerWidget(const std::string &bus_name) {
|
||||
auto it = this->mediaWidgets.find(bus_name);
|
||||
if (it == this->mediaWidgets.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->controlCenterContainer.remove(*it->second);
|
||||
this->mediaWidgets.erase(it);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user