wip: setenabled crash to fix

This commit is contained in:
Hane 2023-09-01 21:36:07 +02:00
commit f620a0575d
6 changed files with 111 additions and 17 deletions

View file

@ -125,21 +125,17 @@ HRESULT EndpointSituationCallback::OnDefaultDeviceChanged(EDataFlow flow, ERole
nRole = Roles::ROLE_COMMUNICATIONS; nRole = Roles::ROLE_COMMUNICATIONS;
break; break;
} }
std::wstring wstringEndpointId = pwstrDeviceId;
osh osh->changeFrontDefaultsCallback(nRole, wstringEndpointId);
return S_OK; return S_OK;
} }
HRESULT EndpointSituationCallback::OnDeviceAdded(LPCWSTR pwstrDeviceId) { HRESULT EndpointSituationCallback::OnDeviceAdded(LPCWSTR pwstrDeviceId) {
printf(" -->Added device\n");
return S_OK; return S_OK;
}; };
HRESULT EndpointSituationCallback::OnDeviceRemoved(LPCWSTR pwstrDeviceId) { HRESULT EndpointSituationCallback::OnDeviceRemoved(LPCWSTR pwstrDeviceId) {
printf(" -->Removed device\n");
return S_OK; return S_OK;
} }
@ -331,11 +327,15 @@ void Endpoint::setRoles(Roles role){
} }
void Endpoint::assignRoles(uint8_t role){ void Endpoint::assignRoles(uint8_t role){
//todo: operador virtuoso
uint8_t roles = endpointRoles | role; uint8_t roles = endpointRoles | role;
this->endpointRoles = roles; this->endpointRoles = roles;
} }
void Endpoint::removeRoles(uint8_t role){
uint8_t roles = endpointRoles ^ role;
this->endpointRoles = roles;
}
Endpoint::~Endpoint(){ Endpoint::~Endpoint(){
log_debugcpp("murio endpoint-san uwu"); log_debugcpp("murio endpoint-san uwu");
properties->Release(); properties->Release();

View file

@ -44,6 +44,7 @@ class Endpoint {
uint8_t getRoles(); uint8_t getRoles();
void setRoles(Roles role); void setRoles(Roles role);
void assignRoles(uint8_t role); void assignRoles(uint8_t role);
void removeRoles(uint8_t role);
std::wstring getId(); std::wstring getId();
std::wstring getName(); std::wstring getName();
void setVolumeCallback(EndpointVolumeCallback *epc); void setVolumeCallback(EndpointVolumeCallback *epc);

View file

@ -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(){ BackEndpointVolumeCallbackInfo* EndpointHandler::getCallbackInfo(){
return &this->callbackInfo; return &this->callbackInfo;
} }
@ -50,6 +60,10 @@ std::wstring EndpointHandler::getName(){
return ep->getName(); return ep->getName();
} }
std::wstring EndpointHandler::getId(){
return ep->getId();
}
float EndpointHandler::getVolume(int channel){ float EndpointHandler::getVolume(int channel){
return ep->getVolume(channel); return ep->getVolume(channel);
} }
@ -74,6 +88,14 @@ void EndpointHandler::setRoles(Roles newRole){
ep->setRoles(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() { EndpointHandler::~EndpointHandler() {
ep->removeVolumeCallback(epc); ep->removeVolumeCallback(epc);
epc->Release(); epc->Release();
@ -122,10 +144,14 @@ NGuid OverseerHandler::getGuid() {
return this->os->getGuid(); return this->os->getGuid();
} }
void setChangeFrontDefaultsFunction(std::function<void(Roles, wchar* endpointId)> changeFrontDefaults){ void OverseerHandler::setChangeFrontDefaultsFunction(std::function<void(Roles, std::wstring)> changeFrontDefaults){
this->changeFrontDefaults = changeFrontDefaults; this->changeFrontDefaults = changeFrontDefaults;
} }
void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpointId) {
this->changeFrontDefaults(role, endpointId);
}
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){ void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){
this->endpointHandlers = ephs; this->endpointHandlers = ephs;
} }

View file

@ -62,11 +62,11 @@ class EndpointHandler {
public: public:
EndpointHandler(uint64_t idx); EndpointHandler(uint64_t idx);
//TODO: get(); //these two, currently unused. If I use them, I should feel bad.
Endpoint *ep = nullptr; //EndpointVolumeCallback* getEndpointVolumeCallback();
EndpointVolumeCallback *epc = nullptr; //Endpoint* getEndpoint();
//std::wstring epName;
//std::wstring epName;
BackEndpointVolumeCallbackInfo* getCallbackInfo(); BackEndpointVolumeCallbackInfo* getCallbackInfo();
uint32_t getChannelCount(); uint32_t getChannelCount();
@ -75,11 +75,15 @@ public:
void setVolume(int channel, float volume); void setVolume(int channel, float volume);
std::wstring getName(); std::wstring getName();
std::wstring getId();
float getVolume(int channel); float getVolume(int channel);
bool getMute(); bool getMute();
uint8_t getState(); uint8_t getState();
uint8_t getRoles(); uint8_t getRoles();
void setRoles(Roles newRole); void setRoles(Roles newRole);
void assignRoles(Roles newRole);
void removeRoles(Roles newRole);
void setVolume(NGuid guid, int channel, int value); void setVolume(NGuid guid, int channel, int value);
void setMute(NGuid guid, bool muted); void setMute(NGuid guid, bool muted);
@ -88,6 +92,8 @@ public:
~EndpointHandler(); ~EndpointHandler();
private: private:
uint64_t idx; uint64_t idx;
Endpoint *ep = nullptr;
EndpointVolumeCallback *epc = nullptr;
BackEndpointVolumeCallbackInfo callbackInfo; BackEndpointVolumeCallbackInfo callbackInfo;
//QSlider *slidy; //QSlider *slidy;
}; };
@ -97,7 +103,9 @@ class OverseerHandler {
public: public:
OverseerHandler(); OverseerHandler();
void setChangeFrontDefaultsFunction(std::function<void(Roles, wchar* endpointId)> changeFrontDefaults); void setChangeFrontDefaultsFunction(std::function<void(Roles, std::wstring)> changeFrontDefaults);
void changeFrontDefaultsCallback(Roles role, std::wstring endpointId);
void setEndpointHandlers(std::vector<EndpointHandler*> ephs); void setEndpointHandlers(std::vector<EndpointHandler*> ephs);
std::vector<EndpointHandler*> getEndpointHandlers(); std::vector<EndpointHandler*> getEndpointHandlers();
std::vector<Endpoint*> getPlaybackEndpoints(); std::vector<Endpoint*> getPlaybackEndpoints();
@ -108,7 +116,8 @@ public:
private: private:
Overseer *os; Overseer *os;
std::vector<EndpointHandler*> endpointHandlers; std::vector<EndpointHandler*> endpointHandlers;
std::function<void(Roles, wchar* endpointId)> changeFrontDefaults; std::function<void(Roles, std::wstring)> changeFrontDefaults;
//std::function<void(uint64_t /* device */, uint32_t /* channel */, float /* value */)> updateFrontVolumeCallback; //std::function<void(uint64_t /* device */, uint32_t /* channel */, float /* value */)> updateFrontVolumeCallback;
//std::function<void(uint64_t /* device */, bool /* mute */)> updateFrontMuteCallback; //std::function<void(uint64_t /* device */, bool /* mute */)> updateFrontMuteCallback;

View file

@ -192,6 +192,10 @@ void EndpointWidget::updateMainVolume(int newValue){
* } * }
*/ */
EndpointHandler* EndpointWidget::getEndpointHandler(){
return this->eph;
}
void EndpointWidget::setIndex(uint64_t idx){ void EndpointWidget::setIndex(uint64_t idx){
this->idx = idx; this->idx = idx;
} }
@ -228,8 +232,61 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
trayIcon->show(); trayIcon->show();
trayIcon->setToolTip(STRING_TITLE); trayIcon->setToolTip(STRING_TITLE);
trayIcon->setContextMenu(trayIconMenu); trayIcon->setContextMenu(trayIconMenu);
//todo: ayo...
QString as = trayIcon->toolTip(); QString as = trayIcon->toolTip();
connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated); 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) { void MainWindow::closeEvent(QCloseEvent *event) {

View file

@ -62,8 +62,8 @@ class EndpointWidget : public QWidget {
public: public:
EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr); EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr);
//TODO: get();
EndpointHandler* eph; EndpointHandler* getEndpointHandler();
void setIndex(uint64_t idx); void setIndex(uint64_t idx);
uint64_t getIndex(); uint64_t getIndex();
@ -90,6 +90,7 @@ public slots:
void updateMute(int checked); void updateMute(int checked);
private: private:
EndpointHandler* eph;
size_t defaultRolesVectorSize = 4; size_t defaultRolesVectorSize = 4;
QTimer* timer = nullptr; QTimer* timer = nullptr;
uint64_t idx; uint64_t idx;