mixer/src/qt/qtclasses.cpp
2024-02-07 16:56:23 +01:00

584 lines
22 KiB
C++

#include "qtclasses.h"
template <typename T>
CustomWidgetEvent<T>::CustomWidgetEvent(QEvent::Type type, T payload) : QEvent(type){
this->payload = payload;
}
void ExtendedCheckBox::customEvent(QEvent* ev) {
QEvent::Type tipo = ev->type();
if (ev->type() == (QEvent::Type)CustomQEvent::EndpointDefaultChange) {
//todo: still prone to bugs; whack-a-mole to come
ev->setAccepted(true);
this->blockSignals(true);
if (this->isEnabled()) {
this->setCheckState(Qt::Checked);
this->setDisabled(true);
} else {
this->setDisabled(false);
this->setCheckState(Qt::Unchecked);
}
this->blockSignals(false);
return;
}
// Make sure the rest of events are handled
QCheckBox::customEvent(ev);
}
SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) : QWidget(parent){
//todo: based on qgridlayout, name+mute should be its own widget, same with channels
this->idx = idx;
this->sh = sh;
layout = new QGridLayout(this);
//this->setLayout(
muteButton = new QCheckBox(this);
mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this);
mainSlider = new QSlider(Qt::Horizontal, this);
mainSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mainSlider->setFocusPolicy(Qt::StrongFocus);
mainSlider->setTickPosition(QSlider::TicksBothSides);
mainSlider->setTickInterval(5);
mainSlider->setSingleStep(1);
mainSlider->setRange(0,100);
muteButton->setCheckState((sh->getMute() == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(sh->getMute() ? STRING_UNMUTE : STRING_MUTE);
float volume = sh->getVolume(AudioChannel::CHANNEL_MAIN) * 100;
mainSlider->setValue((int)volume);
log_debugcpp("SESSION SET WITH VOLUME " + std::to_string(volume));
//tip: would need to be new widget with layout in it
//mainMuteLayout = new QGridLayout();
layout->addWidget(mainLabel, 0, 0, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(muteButton, 0, 1, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(mainSlider, 0, 2, 1, 2);
//TODO:0 = mute and muted, change volume = unmuted are client side tricks = 2 callbacks, one for volume, one for mute state. Implement as an user selectable option?
connect<void(QSlider::*)(int), void(SessionWidget::*)(int)>(mainSlider, &QSlider::valueChanged, this,&SessionWidget::updateMainVolume);
connect<void(QCheckBox::*)(int), void(SessionWidget::*)(int)>(muteButton, &QCheckBox::stateChanged, this, (&SessionWidget::updateMute));
/*
* Session Volume Polling
*/
volumePoller = new QTimer();
connect(volumePoller, &QTimer::timeout, [this, sh](){
//if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; CHECK IF THIS PROGRAM GENERATED THE FUNSIES IS NO LONGER IN USE FOR NOW.
//todo: global + constexpr + ratio
const float roundingFactor = 0.005;
mainSlider->blockSignals(true);
muteButton->blockSignals(true);
mainSlider->setValue((int)((sh->getVolumeInfo()->mainVolume + roundingFactor) * 100));
muteButton->setCheckState((sh->getVolumeInfo()->muted == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(sh->getVolumeInfo()->muted ? STRING_UNMUTE : STRING_MUTE);
//memcpy(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid));
//TODO: el default = objcopy frees?
//Todo: like fr pregunta
sh->getVolumeInfo()->caller = osh->getGuid();
mainSlider->blockSignals(false);
muteButton->blockSignals(false);
});
volumePoller->start(10);
}
void SessionWidget::updateMute(int checked){
bool muted = (checked == 2 ? true : false);
this->sh->setMute(osh->getGuid(), muted);
this->muteButton->setText(this->sh->getMute() ? STRING_UNMUTE : STRING_MUTE);
}
void SessionWidget::updateMainVolume(int newValue){
this->sh->setVolume(osh->getGuid(), AudioChannel::CHANNEL_MAIN, newValue);
}
SessionWidget::~SessionWidget() {
volumePoller->stop();
delete volumePoller;
}
EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent) : QWidget(parent){
//todo: based on qgridlayout, name+mute should be its own widget, same with channels
row = 0;
this->idx = idx;
this->eph = eph;
//todo: sussy
this->eph->setState(EndpointState::ENDPOINT_ACTIVE, idx);
layout = new QGridLayout(this);
//this->setLayout(layout);
log_debugcpp("epw main layout parent: " + std::to_string((intptr_t)(layout->parent())));
if (parent == nullptr) { log_debugcpp("ayooooo?"); }
defaultRolesCheckBoxes = {
{Roles::ROLE_ALL, new ExtendedCheckBox(this)},
{Roles::ROLE_CONSOLE, new ExtendedCheckBox(this)},
{Roles::ROLE_MULTIMEDIA, new ExtendedCheckBox(this)},
{Roles::ROLE_COMMUNICATIONS, new ExtendedCheckBox(this)}
};
/*
* Mute, main slider and label setup
*/
muteButton = new QCheckBox(this);
mainLabel = new QLabel(QString::fromStdWString(eph->getName()), this);
mainSlider = new QSlider(Qt::Horizontal, this);
if (this->eph->getState() != EndpointState::ENDPOINT_ACTIVE) {
layout->addWidget(mainLabel, row, 0);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 1, 0);
return;
}
//muteButton->setStyleSheet("background-color: #A3C1DA; color: red");
mainSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mainSlider->setFocusPolicy(Qt::StrongFocus);
mainSlider->setTickPosition(QSlider::TicksBothSides);
mainSlider->setTickInterval(5);
mainSlider->setSingleStep(1);
mainSlider->setRange(0,100);
muteButton->setCheckState((eph->getMute() == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
float volume = eph->getVolume(AudioChannel::CHANNEL_MAIN) * 100;
mainSlider->setValue((int)volume);
log_debugcpp("ENDPOINT SET WITH VOLUME " + std::to_string(volume));
//tip: would need to be new widget with layout in it
//mainMuteLayout = new QGridLayout();
layout->addWidget(mainLabel, row, 0, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(muteButton, row, 1, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(mainSlider, row, 2, 1, 2);
row++;
//TODO:0 = mute and muted, change volume = unmuted are client side tricks = 2 callbacks, one for volume, one for mute state. Implement as an user selectable option?
connect<void(QSlider::*)(int), void(EndpointWidget::*)(int)>(mainSlider, &QSlider::valueChanged, this,&EndpointWidget::updateMainVolume);
connect<void(QCheckBox::*)(int), void(EndpointWidget::*)(int)>(muteButton, &QCheckBox::stateChanged, this, (&EndpointWidget::updateMute));
/*
* Channel sliders setup
*/
uint32_t epChannelCount = eph->getChannelCount();
for(uint32_t i = 0; i < epChannelCount && epChannelCount > 1; i++){
QSlider* tmp = new QSlider(Qt::Horizontal);
QLabel* tmpLb = new QLabel("");
tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tmp->setTickInterval(5);
tmp->setSingleStep(1);
tmp->setRange(0,100);
volume = eph->getVolume(i) * 100;
tmp->setValue((int) volume);
tmpLb->setText(QString::number(volume));
this->channelSliders.push_back(tmp);
this->channelLabels.push_back(tmpLb);
layout->addWidget(tmp, row + 1, i);
layout->addWidget(tmpLb, row + 2, i);
//TODO: check if there's a need to prevent deadlocks; probably this will eventually turn into its own func
//this causes channel bar desync when back -> front. blocksignals below fix it. huh.
connect(tmp, &QSlider::valueChanged, [this, i](int newValue){
this->eph->setVolume(osh->getGuid(), i, newValue);
this->channelLabels.at(i)->setText(QString::number(newValue));
});
}
row += 3;
/*
* Role ExtendedCheckBoxes setup
*/
uint8_t assignedRoles = eph->getRoles();
defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->setCheckState(assignedRoles == Roles::ROLE_ALL ? Qt::Checked : Qt::Unchecked);
//todo duditas de &
defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->setDisabled(assignedRoles == Roles::ROLE_ALL ? true : false);
defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->setText(STRING_ROLE_ALL);
defaultRolesCheckBoxes.at(Roles::ROLE_CONSOLE)->setCheckState(assignedRoles & Roles::ROLE_CONSOLE ? Qt::Checked : Qt::Unchecked);
defaultRolesCheckBoxes.at(Roles::ROLE_CONSOLE)->setDisabled(assignedRoles & Roles::ROLE_CONSOLE ? true : false);
defaultRolesCheckBoxes.at(Roles::ROLE_CONSOLE)->setText(STRING_ROLE_CONSOLE);
defaultRolesCheckBoxes.at(Roles::ROLE_MULTIMEDIA)->setCheckState(assignedRoles & Roles::ROLE_MULTIMEDIA ? Qt::Checked : Qt::Unchecked);
defaultRolesCheckBoxes.at(Roles::ROLE_MULTIMEDIA)->setDisabled(assignedRoles & Roles::ROLE_MULTIMEDIA ? true : false);
defaultRolesCheckBoxes.at(Roles::ROLE_MULTIMEDIA)->setText(STRING_ROLE_MULTIMEDIA);
defaultRolesCheckBoxes.at(Roles::ROLE_COMMUNICATIONS)->setCheckState(assignedRoles & Roles::ROLE_COMMUNICATIONS ? Qt::Checked : Qt::Unchecked);
defaultRolesCheckBoxes.at(Roles::ROLE_COMMUNICATIONS)->setDisabled(assignedRoles & Roles::ROLE_COMMUNICATIONS ? true : false);
defaultRolesCheckBoxes.at(Roles::ROLE_COMMUNICATIONS)->setText(STRING_ROLE_COMMUNICATIONS);
connect(defaultRolesCheckBoxes.at(Roles::ROLE_ALL), &QCheckBox::stateChanged,[this] {
this->eph->setRoles(Roles::ROLE_ALL);
});
connect(defaultRolesCheckBoxes.at(Roles::ROLE_CONSOLE), &QCheckBox::stateChanged,[this] {
this->eph->setRoles(Roles::ROLE_CONSOLE);
});
connect(defaultRolesCheckBoxes.at(Roles::ROLE_MULTIMEDIA), &QCheckBox::stateChanged,[this] {
this->eph->setRoles(Roles::ROLE_MULTIMEDIA);
});
connect(defaultRolesCheckBoxes.at(Roles::ROLE_COMMUNICATIONS), &QCheckBox::stateChanged,[this] {
this->eph->setRoles(Roles::ROLE_COMMUNICATIONS);
});
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_ALL), row, 0);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_CONSOLE), row, 1);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_MULTIMEDIA), row, 2);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_COMMUNICATIONS), row, 3);
row++;
/* ----------------------------------------------------------- */
/*
* EndpointVolume Polling time
*/
timer = new QTimer();
connect(timer, &QTimer::timeout, [this, eph](){
//if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; CHECK IF THIS PROGRAM GENERATED THE FUNSIES IS NO LONGER IN USE FOR NOW.
//todo: global + constexpr + ratio
const float roundingFactor = 0.005;
mainSlider->blockSignals(true);
muteButton->blockSignals(true);
mainSlider->setValue((int)((eph->getCallbackInfo()->mainVolume + roundingFactor) * 100));
muteButton->setCheckState((eph->getCallbackInfo()->muted == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(eph->getCallbackInfo()->muted ? STRING_UNMUTE : STRING_MUTE);
for(uint32_t i = 0; i < eph->getCallbackInfo()->channels && eph->getChannelCount() > 1; i++){
this->channelSliders.at(i)->blockSignals(true);
this->channelSliders.at(i)->setValue((int)((eph->getCallbackInfo()->channelVolumes[i] + roundingFactor) * 100));
this->channelLabels.at(i)->setText(QString::number((int)((eph->getCallbackInfo()->channelVolumes[i] + roundingFactor) * 100)));
this->channelSliders.at(i)->blockSignals(false);
}
//memcpy(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid));
//TODO: el default = objcopy frees?
//Todo: like fr pregunta
eph->getCallbackInfo()->caller = osh->getGuid();
mainSlider->blockSignals(false);
muteButton->blockSignals(false);
});
timer->start(10);
/* First SessionWidget batch */
for (size_t i = 0; i < eph->getSessionCount(); i++) {
SessionWidget* sessionWidget = new SessionWidget(i, eph->getSessionHandlers().at(i), this);
layout->addWidget(sessionWidget, row, 4);
row++;
sessionWidgets.push_back(sessionWidget);
eph->getSessionHandlers().at(i)->setFrontIndex(i);
}
/* Add/Remove SessionWidget callback */
eph->setAddSessionWidgetFunction([this](SessionHandler* sessionHandler) {
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<SessionHandler*>((QEvent::Type)CustomQEvent::SessionWidgetCreated, sessionHandler));
});
eph->setRemoveSessionWidgetFunction([this](SessionHandler* sessionHandler) {
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<SessionHandler*>((QEvent::Type)CustomQEvent::SessionWidgetObsolete, sessionHandler));
});
//todo parent?
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 1, 0);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 4, 0);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 6, 0);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 6, 1);
log_debugcpp("ENDPOINT_WIDGETED");
}
void EndpointWidget::addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
uint64_t index = this->sessionWidgets.size();
SessionWidget* sw = new SessionWidget(index, ev->payload, this);
ev->payload->setFrontIndex(index);
this->layout->addWidget(sw, row, 4);
row++;
sessionWidgets.push_back(sw);
return;
}
void EndpointWidget::removeSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
uint64_t i = ev->payload->getFrontIndex();
this->sessionWidgets.at(i)->setParent(nullptr);
this->layout->removeWidget(sessionWidgets.at(i));
delete sessionWidgets.at(i);
sessionWidgets.at(i) = nullptr;
ev->payload->setFrontIndex(INT_MAX);
//this->sessionWidgetsUpdateTimer->start();
return;
}
void EndpointWidget::customEvent(QEvent* ev) {
if (ev->type() == (QEvent::Type)CustomQEvent::SessionWidgetCreated) {
ev->setAccepted(true);
this->addSessionWidget((CustomWidgetEvent<SessionHandler*>*) ev);
} else if (ev->type() == (QEvent::Type)CustomQEvent::SessionWidgetObsolete) {
ev->setAccepted(true);
this->removeSessionWidget((CustomWidgetEvent<SessionHandler*>*) ev);
}
QWidget::customEvent(ev);
}
EndpointWidget::~EndpointWidget() {
timer->stop();
delete timer;
this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ALL, INT_MAX);
}
void MainWindow::customEvent(QEvent* ev) {
if (ev->type() == CustomQEvent::EndpointWidgetObsolete) {
ev->setAccepted(true);
this->removeEndpointWidget((CustomWidgetEvent<uint64_t>*)ev);
} else if (ev->type() == (QEvent::Type)CustomQEvent::EndpointWidgetCreated) {
ev->setAccepted(true);
this->addEndpointWidget((CustomWidgetEvent<EndpointHandler*>*)ev);
}
QMainWindow::customEvent(ev);
}
void MainWindow::removeEndpointWidget(CustomWidgetEvent<uint64_t>* ev){
uint64_t i = ev->payload;
this->ews.at(i)->setParent(nullptr);
this->layout->removeWidget(ews.at(i));
//uint64_t saisu = ews.size();
//delete ews.at(index);
delete ews.at(i);
ews.at(i) = nullptr;
this->ewsUpdateTimer->start();
return;
}
void MainWindow::addEndpointWidget(CustomWidgetEvent<EndpointHandler*>* ev){
EndpointWidget* epw = new EndpointWidget(this->ews.size(), ev->payload, widget);
this->layout->addWidget(epw);
ews.push_back(epw);
return;
}
void MainWindow::reorderEndpointWidgetCollection() {
/* Flatten */
size_t firstNullPosition = 0;
size_t ewsSize = ews.size();
bool breakSorting = false;
//todo: is all of gui really atomic by definition? im afraid of cutting through amazing add momentos, but I think I did my homework. Must check back.
for (size_t i = 0; i < ewsSize; i++) {
if (ews.at(i) == nullptr) {
for (size_t j = (i + 1); j < ewsSize; j++) {
if (ews.at(j) != nullptr) {
ews.at(i) = ews.at(j);
ews.at(i)->setIndex(i);
ews.at(j) = nullptr;
break;
}
if (j == ewsSize - 1) {
firstNullPosition = i;
breakSorting = true;
}
}
if (breakSorting) break;
}
}
ews.resize(firstNullPosition + 1);
}
void EndpointWidget::updateMute(int checked){
bool muted = (checked == 2 ? true : false);
this->eph->setMute(osh->getGuid(), muted);
this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
}
void EndpointWidget::updateMainVolume(int newValue){
this->eph->setVolume(osh->getGuid(), AudioChannel::CHANNEL_MAIN, newValue);
}
/*
* void EndpointWidget::updateVolume(uint32_t channel, float newValue){
* //this->blockSignals(true);
* int newVal = newValue * 100;
* if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) {
* //TIP: Above
* //this->mainSlider->blockSignals(true);
*
* if(this->mainSlider->value() != newVal) {
* this->mainSlider->blockSignals(true);
* this->mainSlider->setValue(newVal);
* this->mainSlider->blockSignals(false);
* }
* return;
* }
*
* for (size_t i = 0; i < sizeof(uint32_t) * 8 && i < channelSliders.size(); ++i) {
* if (((channel >> i) & 1) && this->channelSliders.at(i)->value() != newVal) {
* //this->channelSliders.at(i)->blockSignals(true);
*
* this->channelSliders.at(i)->setValue(newVal);
* this->channelLabels.at(i)->setText(QString::number((int)(newValue * 100)));
*
* //this->channelSliders.at(i)->blockSignals(false);
* }
* }
*
* //this->blockSignals(false);
* }
*/
EndpointHandler* EndpointWidget::getEndpointHandler(){
return this->eph;
}
/*
* void EndpointWidget::updateFrontIndex(uint64_t index){
* this->idx = index;
* }
*/
void EndpointWidget::setIndex(uint64_t idx){
this->idx = idx;
this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ACTIVE, this->idx);
}
uint64_t EndpointWidget::getIndex(){
return idx;
}
std::map<Roles, ExtendedCheckBox*> EndpointWidget::getDefaultRolesWidgets() {
return defaultRolesCheckBoxes;
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
// setWindowState(Qt::WindowFullScreen);
// setCentralWidget(centralWidget);
/*
* Registering needed custom events
*/
QEvent::registerEventType(CustomQEvent::EndpointWidgetObsolete);
QEvent::registerEventType(CustomQEvent::EndpointWidgetCreated);
QEvent::registerEventType(CustomQEvent::EndpointDefaultChange);
ewsUpdateTimer = new QTimer(this);
widget = new QWidget();
layout = new QGridLayout();
trayIcon = new QSystemTrayIcon();
trayIconMenu = new QMenu();
trayIconMenuQuit = new QAction(STRING_QUIT);
ewsUpdateTimer->setSingleShot(true);
ewsUpdateTimer->setInterval(ewsUpdateTimerFrequency);
connect(ewsUpdateTimer, &QTimer::timeout, this, &MainWindow::reorderEndpointWidgetCollection);
widget->setLayout(layout);
setCentralWidget(widget);
//layout->addWidget(pintas, 0, 0);
setWindowTitle(STRING_TITLE);
reloadEndpointWidgets();
/*
* Tray Icon code
*/
trayIconMenu->addSeparator();
trayIconMenu->addAction(trayIconMenuQuit);
connect(trayIconMenuQuit, &QAction::triggered, qApp, &QCoreApplication::quit);
trayIcon->setIcon(QIcon(":/assets/notificationAreaIcon.png"));
setWindowIcon(QIcon(":/assets/notificationAreaIcon.png"));
//TODO: Extend qsystemtrayicon to change mouse click?
//show before setting tooltip required; smells like bug to me!
trayIcon->show();
trayIcon->setToolTip(STRING_TITLE);
trayIcon->setContextMenu(trayIconMenu);
connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated);
/*
* Set of function callback definitons for EndpointSituationCallback
*/
osh->setChangeFrontDefaultsFunction([this](Roles role, std::wstring endpointId) {
for (auto epw : this->ews) {
/*
* Is this the new default endpoint?
*/
if (epw->getEndpointHandler()->getId() == endpointId) {
//not necessary to keep endpointState flags up to date right now, but updating it will allow for later config files / profiles
epw->getDefaultRolesWidgets().at(role)->blockSignals(true);
epw->getEndpointHandler()->assignRoles(role);
epw->getDefaultRolesWidgets().at(role)->blockSignals(false);
QCoreApplication::instance()->postEvent(epw->getDefaultRolesWidgets().at(role), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange));
//epw->defaultRolesCheckBoxes.at(role)->postEnableChange();
/*
* And were you THE default?
*/
if (epw->getEndpointHandler()->getRoles() == Roles::ROLE_ALL) {
QCoreApplication::instance()->postEvent(epw->getDefaultRolesWidgets().at(Roles::ROLE_ALL), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange));
}
/*
* Are you the dethroned king?
*/
} else if (epw->getEndpointHandler()->getRoles() & role) {
/*
* And were you THE default up until now?
*/
if (epw->getEndpointHandler()->getRoles() == Roles::ROLE_ALL) {
QCoreApplication::instance()->postEvent(epw->getDefaultRolesWidgets().at(Roles::ROLE_ALL), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange));
}
epw->getDefaultRolesWidgets().at(role)->blockSignals(true);
//Same as before. ini-san will come...
epw->getEndpointHandler()->removeRoles(role);
epw->getDefaultRolesWidgets().at(role)->blockSignals(false);
QCoreApplication::instance()->postEvent(epw->getDefaultRolesWidgets().at(role), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange));
}
}
});
osh->setRemoveEndpointWidgetFunction([this](uint64_t index) {
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<uint64_t>((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index));
});
osh->setAddEndpointWidgetFunction([this](EndpointHandler* eph) {
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<EndpointHandler*>((QEvent::Type)CustomQEvent::EndpointWidgetCreated, eph));
});
}
void MainWindow::closeEvent(QCloseEvent *event) {
if (!event->spontaneous() || !isVisible()) return;
if (trayIcon->isVisible()) {
//todo: would be nice to show this to 1st time users; ini-san will come...
//this->trayIcon->showMessage("ini file calling","tratarte como un gilipollas la primera vez", QSystemTrayIcon::Information);
hide();
event->ignore();
}
}
void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
switch (reason) {
case QSystemTrayIcon::Trigger:
this->showNormal();
break;
default:
break;
}
}
void MainWindow::reloadEndpointWidgets() {
size_t i = 0;
for (size_t epwIndex = 0; i < (osh->getPlaybackEndpointHandlers().size()); i++) {
if (osh->getPlaybackEndpointHandlers().at(i)->getState() == EndpointState::ENDPOINT_ACTIVE){
log_debugcpp("EPWidget creation");
//osh->getPlaybackEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid();
EndpointWidget *epw = new EndpointWidget(epwIndex, osh->getPlaybackEndpointHandlers().at(i), widget);
epwIndex++;
//alfinal estoes solopara inicializarlmao
ews.push_back(epw);
layout->addWidget(epw, i, 0);
}
}
//todo:: tas aqui tirao, no me gustas y probablemente yo a ti tampoco
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), i, 0);
}