poll merge squash
This commit is contained in:
parent
308a0486b6
commit
40bee90610
21 changed files with 2753 additions and 261 deletions
|
|
@ -1,114 +1,584 @@
|
|||
#include "qtclasses.h"
|
||||
|
||||
template <typename T>
|
||||
CustomWidgetEvent<T>::CustomWidgetEvent(QEvent::Type type, T payload) : QEvent(type){
|
||||
this->payload = payload;
|
||||
}
|
||||
|
||||
EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(parent){
|
||||
this->eph = eph;
|
||||
layout = new QGridLayout();
|
||||
this->setLayout(layout);
|
||||
log_debugcpp("olaW");
|
||||
if (parent == nullptr) { log_debugcpp("owo?"); }
|
||||
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);
|
||||
}
|
||||
|
||||
muteButton = new QPushButton();
|
||||
mainLabel = new QLabel(eph->getName());
|
||||
leftChannelLabel = new QLabel("88");
|
||||
rightChannelLabel = new QLabel("77");
|
||||
mainSlider = new QSlider(Qt::Horizontal);
|
||||
leftChannelSlider = new QSlider(Qt::Horizontal);
|
||||
rightChannelSlider = new QSlider(Qt::Horizontal);
|
||||
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);
|
||||
|
||||
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);
|
||||
leftChannelSlider->setTickInterval(5);
|
||||
leftChannelSlider->setSingleStep(1);
|
||||
leftChannelSlider->setRange(0,100);
|
||||
rightChannelSlider->setTickInterval(5);
|
||||
rightChannelSlider->setSingleStep(1);
|
||||
rightChannelSlider->setRange(0,100);
|
||||
|
||||
muteButton->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
|
||||
float volume = eph->getVolume(ENDPOINT_MASTER_VOLUME) * 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);
|
||||
volume = eph->getVolume(ENDPOINT_LEFT_CHANNEL_VOLUME) * 100;
|
||||
leftChannelSlider->setValue((int)volume);
|
||||
leftChannelLabel->setText(QString::number(volume));
|
||||
volume = eph->getVolume(ENDPOINT_RIGHT_CHANNEL_VOLUME) * 100;
|
||||
rightChannelSlider->setValue((int)volume);
|
||||
rightChannelLabel->setText(QString::number(volume));
|
||||
log_debugcpp("ENDPOINT SET WITH VOLUME " << volume);
|
||||
log_debugcpp("SESSION SET WITH VOLUME " + std::to_string(volume));
|
||||
|
||||
mainMuteLayout = new QGridLayout();
|
||||
layout->addLayout(mainMuteLayout, 0, 0);
|
||||
mainMuteLayout->addWidget(mainLabel, 0, 0);
|
||||
mainMuteLayout->addWidget(muteButton, 0, 1);
|
||||
layout->addWidget(mainSlider, 0, 1);
|
||||
layout->addWidget(leftChannelSlider, 1, 0);
|
||||
layout->addWidget(leftChannelLabel, 2, 0);
|
||||
layout->addWidget(rightChannelSlider, 1, 1);
|
||||
layout->addWidget(rightChannelLabel, 2, 1);
|
||||
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 0);
|
||||
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 1);
|
||||
//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++;
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* connect(mainSlider, &QSlider::valueChanged, eph, &EndpointHandler::setValue);
|
||||
* EndpointVolume Polling time
|
||||
*/
|
||||
connect(mainSlider, &QSlider::valueChanged, [this](int newValue){this->eph->setValue(ENDPOINT_MASTER_VOLUME, newValue); });
|
||||
connect(leftChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setValue(ENDPOINT_LEFT_CHANNEL_VOLUME, newValue); this->leftChannelLabel->setText(QString::number(newValue)); });
|
||||
connect(rightChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setValue(ENDPOINT_RIGHT_CHANNEL_VOLUME, newValue); this->rightChannelLabel->setText(QString::number(newValue)); });
|
||||
connect(muteButton, &QPushButton::clicked, [this](bool clicked){ log_debugcpp("cliqui" << clicked << "cloqui"); this->eph->setMute(); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); });
|
||||
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;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(std::vector<EndpointHandler*> *ephs, QWidget *parent) : QMainWindow(parent) {
|
||||
// setWindowState(Qt::WindowFullScreen);
|
||||
// setCentralWidget(centralWidget);
|
||||
widget = new QWidget();
|
||||
layout = new QGridLayout();
|
||||
|
||||
widget->setLayout(layout);
|
||||
setCentralWidget(widget);
|
||||
//layout->addWidget(pintas, 0, 0);
|
||||
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;
|
||||
}
|
||||
|
||||
setWindowTitle("slidea resbala nu c");
|
||||
|
||||
/*s
|
||||
* setEndpointHandlers(ephs);
|
||||
*/
|
||||
unsigned int i = 0;
|
||||
for (; i < ephs->size(); i++) {
|
||||
log_debugcpp("EPWidget creation");
|
||||
EndpointWidget *epw = new EndpointWidget(ephs->at(i), widget);
|
||||
ews.push_back(epw);
|
||||
layout->addWidget(epw, i, 0);
|
||||
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);
|
||||
}
|
||||
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), i, 0);
|
||||
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 MainWindow::setEndpointHandlers(std::vector<EndpointHandler*> *ephs){
|
||||
* this->ephs = ephs;
|
||||
* 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 MainWindow::setPlotButton() {
|
||||
* button = new QPushButton("push"),
|
||||
* button->setCheckable(true);
|
||||
* connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)))
|
||||
* QHBoxLayout *plotsLayout = new QHBoxLayout;
|
||||
* plotsLayout->setSpacing(10);
|
||||
* plotsLayout->addWidget(funPlot);
|
||||
* QHBoxLayout *buttonsLayout = new QHBoxLayout ;
|
||||
* buttonsLayout->addWidget(button);
|
||||
* QVBoxLayout *widgetLayout = new QVBoxLayout;
|
||||
* widgetLayout->addLayout(plotsLayout);
|
||||
* widgetLayout->addLayout(buttonsLayout);
|
||||
* setLayout(widgetLayout);
|
||||
* ...
|
||||
*/
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue