diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index ab68c51..083d60c 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -125,21 +125,17 @@ HRESULT EndpointSituationCallback::OnDefaultDeviceChanged(EDataFlow flow, ERole nRole = Roles::ROLE_COMMUNICATIONS; break; } - - osh + std::wstring wstringEndpointId = pwstrDeviceId; + osh->changeFrontDefaultsCallback(nRole, wstringEndpointId); return S_OK; } HRESULT EndpointSituationCallback::OnDeviceAdded(LPCWSTR pwstrDeviceId) { - - printf(" -->Added device\n"); return S_OK; }; -HRESULT EndpointSituationCallback::OnDeviceRemoved(LPCWSTR pwstrDeviceId) { - - printf(" -->Removed device\n"); +HRESULT EndpointSituationCallback::OnDeviceRemoved(LPCWSTR pwstrDeviceId) { return S_OK; } @@ -331,11 +327,15 @@ void Endpoint::setRoles(Roles role){ } void Endpoint::assignRoles(uint8_t role){ - //todo: operador virtuoso uint8_t roles = endpointRoles | role; this->endpointRoles = roles; } +void Endpoint::removeRoles(uint8_t role){ + uint8_t roles = endpointRoles ^ role; + this->endpointRoles = roles; +} + Endpoint::~Endpoint(){ log_debugcpp("murio endpoint-san uwu"); properties->Release(); diff --git a/src/back/backlasses.h b/src/back/backlasses.h index db905a4..d8b0d2b 100644 --- a/src/back/backlasses.h +++ b/src/back/backlasses.h @@ -44,6 +44,7 @@ class Endpoint { uint8_t getRoles(); void setRoles(Roles role); void assignRoles(uint8_t role); + void removeRoles(uint8_t role); std::wstring getId(); std::wstring getName(); void setVolumeCallback(EndpointVolumeCallback *epc); diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index da1033c..abedbfd 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -17,6 +17,16 @@ EndpointHandler::EndpointHandler(uint64_t idx) { } } +/* these two, currently unused. If I use them, I should feel bad. + * Endpoint* EndpointHandler::getEndpoint() { + * return this->ep; + * } + * + * EndpointVolumeCallback* EndpointHandler::getEndpointVolumeCallback() { + * return this->epc; + * } + */ + BackEndpointVolumeCallbackInfo* EndpointHandler::getCallbackInfo(){ return &this->callbackInfo; } @@ -50,6 +60,10 @@ std::wstring EndpointHandler::getName(){ return ep->getName(); } +std::wstring EndpointHandler::getId(){ + return ep->getId(); +} + float EndpointHandler::getVolume(int channel){ return ep->getVolume(channel); } @@ -74,6 +88,14 @@ void EndpointHandler::setRoles(Roles newRole){ ep->setRoles(newRole); } +void EndpointHandler::assignRoles(Roles newRole){ + ep->assignRoles((uint8_t)newRole); +} + +void EndpointHandler::removeRoles(Roles newRole){ + ep->removeRoles((uint8_t)newRole); +} + EndpointHandler::~EndpointHandler() { ep->removeVolumeCallback(epc); epc->Release(); @@ -122,10 +144,14 @@ NGuid OverseerHandler::getGuid() { return this->os->getGuid(); } -void setChangeFrontDefaultsFunction(std::function changeFrontDefaults){ +void OverseerHandler::setChangeFrontDefaultsFunction(std::function changeFrontDefaults){ this->changeFrontDefaults = changeFrontDefaults; } +void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpointId) { + this->changeFrontDefaults(role, endpointId); +} + void OverseerHandler::setEndpointHandlers(std::vector ephs){ this->endpointHandlers = ephs; } diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h index 55d33d8..7ea9f6e 100644 --- a/src/cont/contclasses.h +++ b/src/cont/contclasses.h @@ -62,11 +62,11 @@ class EndpointHandler { public: EndpointHandler(uint64_t idx); - //TODO: get(); - Endpoint *ep = nullptr; - EndpointVolumeCallback *epc = nullptr; + //these two, currently unused. If I use them, I should feel bad. + //EndpointVolumeCallback* getEndpointVolumeCallback(); + //Endpoint* getEndpoint(); + //std::wstring epName; - BackEndpointVolumeCallbackInfo* getCallbackInfo(); uint32_t getChannelCount(); @@ -75,11 +75,15 @@ public: void setVolume(int channel, float volume); std::wstring getName(); + std::wstring getId(); + float getVolume(int channel); bool getMute(); uint8_t getState(); uint8_t getRoles(); void setRoles(Roles newRole); + void assignRoles(Roles newRole); + void removeRoles(Roles newRole); void setVolume(NGuid guid, int channel, int value); void setMute(NGuid guid, bool muted); @@ -88,6 +92,8 @@ public: ~EndpointHandler(); private: uint64_t idx; + Endpoint *ep = nullptr; + EndpointVolumeCallback *epc = nullptr; BackEndpointVolumeCallbackInfo callbackInfo; //QSlider *slidy; }; @@ -97,7 +103,9 @@ class OverseerHandler { public: OverseerHandler(); - void setChangeFrontDefaultsFunction(std::function changeFrontDefaults); + void setChangeFrontDefaultsFunction(std::function changeFrontDefaults); + void changeFrontDefaultsCallback(Roles role, std::wstring endpointId); + void setEndpointHandlers(std::vector ephs); std::vector getEndpointHandlers(); std::vector getPlaybackEndpoints(); @@ -108,7 +116,8 @@ public: private: Overseer *os; std::vector endpointHandlers; - std::function changeFrontDefaults; + std::function changeFrontDefaults; + //std::function updateFrontVolumeCallback; //std::function updateFrontMuteCallback; diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 1140fca..2543e1e 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -192,6 +192,10 @@ void EndpointWidget::updateMainVolume(int newValue){ * } */ +EndpointHandler* EndpointWidget::getEndpointHandler(){ + return this->eph; +} + void EndpointWidget::setIndex(uint64_t idx){ this->idx = idx; } @@ -228,8 +232,61 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { trayIcon->show(); trayIcon->setToolTip(STRING_TITLE); trayIcon->setContextMenu(trayIconMenu); + //todo: ayo... QString as = trayIcon->toolTip(); connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated); + + + osh->setChangeFrontDefaultsFunction([this](Roles role, std::wstring endpointId) { + + for (auto epw : this->ews) { + 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->defaultRolesCheckBoxes.at(role)->blockSignals(true); + epw->getEndpointHandler()->assignRoles(role); + epw->defaultRolesCheckBoxes.at(role)->setCheckState(Qt::Checked); + //epw->defaultRolesCheckBoxes.at(role)->setDisabled(true); + epw->defaultRolesCheckBoxes.at(role)->blockSignals(false); + + if (epw->getEndpointHandler()->getRoles() == Roles::ROLE_ALL) { + epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->blockSignals(true); + epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->setCheckState(Qt::Checked); + //epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->setDisabled(true); + epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->blockSignals(false); + } + + /* + * switch (role) { + * case Roles::ROLE_CONSOLE: + * epw->getEndpointHandler()->assignRoles(role); + * break; + * case Roles::ROLE_MULTIMEDIA: + * break; + * case Roles::ROLE_COMMUNICATIONS: + * break; + * + * } + */ + } else { + if (epw->getEndpointHandler()->getRoles() & role) { + epw->defaultRolesCheckBoxes.at(role)->blockSignals(true); + epw->getEndpointHandler()->removeRoles(role); + epw->defaultRolesCheckBoxes.at(role)->setCheckState(Qt::Unchecked); + //epw->defaultRolesCheckBoxes.at(role)->setDisabled(false); + epw->defaultRolesCheckBoxes.at(role)->blockSignals(false); + + if (!epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->isEnabled()) { + epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->blockSignals(true); + //epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->setDisabled(false); + epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->setCheckState(Qt::Unchecked); + epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL)->blockSignals(false); + + } + + } + } + } + }); } void MainWindow::closeEvent(QCloseEvent *event) { diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 4082fc7..062c308 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -62,8 +62,8 @@ class EndpointWidget : public QWidget { public: EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr); - //TODO: get(); - EndpointHandler* eph; + + EndpointHandler* getEndpointHandler(); void setIndex(uint64_t idx); uint64_t getIndex(); @@ -90,6 +90,7 @@ public slots: void updateMute(int checked); private: + EndpointHandler* eph; size_t defaultRolesVectorSize = 4; QTimer* timer = nullptr; uint64_t idx;