diff --git a/qtest.pro b/qtest.pro index d867f27..dd5e215 100644 --- a/qtest.pro +++ b/qtest.pro @@ -2,14 +2,14 @@ QMAKE_CXXFLAGS += --target=x86_64-w64-mingw32 -g -gcodeview QMAKE_LFLAGS += --target=x86_64-w64-mingw32 -g -Wl,-pdb= -v LIBS += -LC:/capybara/libclang/x86_64-w64-mingw32/lib -lWinmm -lodbc32 -lodbccp32 -luuid -loleaut32 -lole32 -lshell32 -ladvapi32 -lcomdlg32 -lwinspool -lgdi32 -luser32 -lkernel32 #"kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" -luuid -loleaut32 -lole32 -lshell32 -ladvapi32 -lcomdlg32 -lwinspool -lgdi32 -luser32 -lkernel32 -DEFINES += DEBUG -CONFIG += debug console +DEFINES += DEBUG QT_LOGGING_TO_CONSOLE=1 WIN32_LEAN_AND_MEAN +CONFIG += debug QT += widgets network INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont" DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont" VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont" -SOURCES += qtestmain.cpp qtclasses.cpp backlasses.cpp contclasses.cpp +SOURCES += qtestmain.cpp qtclasses.cpp backlasses.cpp contclasses.cpp HEADERS += qtclasses.h backlasses.h contclasses.h global.h debug.h backfuncs.h ipolicyconfig.h RESOURCES = assets.qrc diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 93122f0..f76b8a1 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -112,7 +112,7 @@ HRESULT EndpointSituationCallback::QueryInterface(REFIID riid, VOID **ppvInterfa HRESULT EndpointSituationCallback::OnDefaultDeviceChanged(EDataFlow flow, ERole role,LPCWSTR pwstrDeviceId) { if (flow == EDataFlow::eCapture) return E_INVALIDARG; - + Roles nRole; switch (role) { case ERole::eConsole: @@ -126,18 +126,19 @@ HRESULT EndpointSituationCallback::OnDefaultDeviceChanged(EDataFlow flow, ERole break; } std::wstring wstringEndpointId = pwstrDeviceId; + log_wdebugcpp(L"we got za defol 4 " + wstringEndpointId); osh->changeFrontDefaultsCallback(nRole, wstringEndpointId); return S_OK; } HRESULT EndpointSituationCallback::OnDeviceAdded(LPCWSTR pwstrDeviceId) { - log_wdebugcpp(L"ayo we eventing za adin" << pwstrDeviceId); + log_wdebugcpp(L"ayo we eventing za adin " + std::wstring(pwstrDeviceId)); return S_OK; }; HRESULT EndpointSituationCallback::OnDeviceRemoved(LPCWSTR pwstrDeviceId) { - log_wdebugcpp(L"ayo we eventing za rmovin" << pwstrDeviceId); + log_wdebugcpp(L"ayo we eventing za rmovin " + std::wstring(pwstrDeviceId)); return S_OK; } @@ -159,13 +160,15 @@ HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, D HRESULT EndpointSituationCallback::OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) { - log_debugcpp(" -->Changed device property " << - key.fmtid.Data1 << key.fmtid.Data2 << key.fmtid.Data3 << "\n" << - key.fmtid.Data4[0]<< key.fmtid.Data4[1]<< "\n"<< - key.fmtid.Data4[2]<< key.fmtid.Data4[3] << "\n"<< - key.fmtid.Data4[4]<< key.fmtid.Data4[5] << "\n"<< - key.fmtid.Data4[6]<< key.fmtid.Data4[7]<< "\n"<< - " pid " << key.pid); + /* + * log_debugcpp(" -->Changed device property " + + * key.fmtid.Data1 + key.fmtid.Data2 + key.fmtid.Data3 + "\n" + + * key.fmtid.Data4[0]+ key.fmtid.Data4[1]+ "\n"+ + * key.fmtid.Data4[2]+ key.fmtid.Data4[3] + "\n"+ + * key.fmtid.Data4[4]+ key.fmtid.Data4[5] + "\n"+ + * key.fmtid.Data4[6]+ key.fmtid.Data4[7]+ "\n"+ + * " pid " + key.pid); + */ return S_OK; } @@ -272,7 +275,7 @@ void Endpoint::removeVolumeCallback(EndpointVolumeCallback *epc){ endpointVolume->UnregisterControlChangeNotify((IAudioEndpointVolumeCallback*)epc); } -uint8_t Endpoint::getRoles(){ +Roles Endpoint::getRoles(){ return this->endpointRoles; } @@ -343,13 +346,13 @@ void Endpoint::setRoles(Roles role){ } } -void Endpoint::assignRoles(uint8_t role){ - uint8_t roles = endpointRoles | role; +void Endpoint::assignRoles(Roles role){ + Roles roles = (Roles)(endpointRoles | role); this->endpointRoles = roles; } -void Endpoint::removeRoles(uint8_t role){ - uint8_t roles = endpointRoles ^ role; +void Endpoint::removeRoles(Roles role){ + Roles roles = (Roles)(endpointRoles ^ role); this->endpointRoles = roles; } @@ -361,6 +364,7 @@ Endpoint::~Endpoint(){ } void Overseer::initCOMLibrary() { + OutputDebugStringW(L"EPWidget creation\n"); if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE))) { log_debugcpp("si"); }; @@ -405,7 +409,7 @@ void Overseer::reloadEndpoints() { Endpoint *endpoint = new Endpoint(temp, i); //endpoint->setIndex(i); this->playbackDevices.push_back(endpoint); - //TODO: le porblemx std::cout << "ola" << std::endl; + //TODO: le porblemx std::cout + "ola" + std::endl; } deviceCollection->Release(); @@ -435,8 +439,8 @@ void Overseer::reloadEndpoints() { temp->GetId(&id); int comparison = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, eptId.c_str(), -987, id, -987, NULL, NULL, 0); if (comparison - 2 == 0) { - log_wdebugcpp("ola defaul de " << i << " es " << id); - playbackDevices.at(j)->assignRoles((1 << i)); + log_wdebugcpp(L"ola defaul de " + std::to_wstring(i) + L" es " + id); + playbackDevices.at(j)->assignRoles((Roles)(1 << i)); } //uint8_t debg = playbackDevices.at(j)->getRoles(); } diff --git a/src/back/backlasses.h b/src/back/backlasses.h index 44407a0..97b52d4 100644 --- a/src/back/backlasses.h +++ b/src/back/backlasses.h @@ -1,5 +1,5 @@ #pragma once -#define WIN32_LEAN_AND_MEAN + #define _WIN32_WINNT 0x0A00 #include @@ -12,6 +12,7 @@ #include #include #include +//#include #include #include @@ -41,10 +42,10 @@ class Endpoint { bool getMute(); void setState(uint8_t state); size_t getState(); - uint8_t getRoles(); + Roles getRoles(); void setRoles(Roles role); - void assignRoles(uint8_t role); - void removeRoles(uint8_t role); + void assignRoles(Roles role); + void removeRoles(Roles role); std::wstring getId(); std::wstring getName(); void setVolumeCallback(EndpointVolumeCallback *epc); @@ -59,7 +60,7 @@ class Endpoint { std::wstring friendlyName; std::wstring endpointId; unsigned long endpointState; - uint8_t endpointRoles = 0; + Roles endpointRoles = (Roles)0; uint64_t idx; }; diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index 0d38d46..ce46d1e 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -104,11 +104,11 @@ void EndpointHandler::setRoles(Roles newRole){ } void EndpointHandler::assignRoles(Roles newRole){ - ep->assignRoles((uint8_t)newRole); + ep->assignRoles(newRole); } void EndpointHandler::removeRoles(Roles newRole){ - ep->removeRoles((uint8_t)newRole); + ep->removeRoles(newRole); } EndpointHandler::~EndpointHandler() { @@ -136,17 +136,17 @@ uint64_t OverseerHandler::getPlaybackEndpointsCount(){ void OverseerHandler::reloadEndpointHandlers(){ //std::vector* ephs = new std::vector; - log_debugcpp(" VSize: " << this->getPlaybackEndpointsCount()); + log_debugcpp(" VSize: " + std::to_string(this->getPlaybackEndpointsCount())); for(uint64_t i = 0; i < this->getPlaybackEndpointsCount(); i++){ - log_debugcpp("Creating handler " << i); + log_debugcpp("Creating handler " + std::to_string(i)); if(i < (this->endpointHandlers.size()) && this->endpointHandlers.at(i) != nullptr) delete endpointHandlers.at(i); EndpointHandler* eph = new EndpointHandler(i); - log_debugcpp("Created handler " << i << ", adding to vector. " << " VSize: " << this->getPlaybackEndpointsCount()); + log_debugcpp("Created handler " + std::to_string(i) + ", adding to vector. " + " VSize: " + std::to_string(this->getPlaybackEndpointsCount())); if (i >= this->endpointHandlers.size()) endpointHandlers.push_back(eph); diff --git a/src/debug.h b/src/debug.h index 8e309cf..da6285c 100644 --- a/src/debug.h +++ b/src/debug.h @@ -7,7 +7,7 @@ std::bitset varToBitset(T info) { std::bitset content(info); return content; } - +#ifndef _WIN32 #define log_debugcpp(str) do { \ std::cout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \ } while (0) @@ -15,6 +15,21 @@ std::bitset varToBitset(T info) { #define log_wdebugcpp(str) do { \ std::wcout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \ } while (0) +#else + +#include +#include +#define WIDE2(x) L##x +#define WIDE1(x) WIDE2(x) +#define WFILE WIDE1(__FILE__) +#define log_debugcpp(str) { \ + OutputDebugStringA(std::string("[DEBUG] (" + std::string(__FILE__) + ":" + std::to_string(__LINE__) + "): " + std::string(str) + "\n").c_str()); \ + } while (0) + +#define log_wdebugcpp(str) do { \ + OutputDebugStringW(std::wstring(L"[DEBUG] (" + std::wstring(WFILE) + L":" + std::to_wstring(__LINE__) + L"): " + std::wstring(str) +L"\n").c_str()); \ + } while (0) +#endif #define print_as_binary(len, type, info) varToBitset(info) @@ -30,5 +45,3 @@ std::bitset varToBitset(T info) { /* typedef void (EndpointWidget::*epwChannelVolumeFunc)(uint32_t channel, float newValue); */ /* typedef void (EndpointWidget::*epwToggleFrontFunc)(bool active); */ - - diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 2ff112c..0e47fc6 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -4,9 +4,11 @@ EndpointWidgetEvent::EndpointWidgetEvent(QEvent::Type type, int idx) : QEvent(ty this->idx = idx; } -bool ExtendedCheckBox::event(QEvent* ev) { - if (ev->type() == QEvent::User) { +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); @@ -16,10 +18,10 @@ bool ExtendedCheckBox::event(QEvent* ev) { this->setCheckState(Qt::Unchecked); } this->blockSignals(false); - return true; + return; } // Make sure the rest of events are handled - return QCheckBox::event(ev); + QCheckBox::customEvent(ev); } EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent) : QWidget(parent){ @@ -29,7 +31,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ACTIVE, idx); layout = new QGridLayout(this); //this->setLayout(layout); - log_debugcpp("epw main layout parent: "<< layout->parent()); + log_debugcpp("epw main layout parent: " + std::to_string((intptr_t)(layout->parent()))); if (parent == nullptr) { log_debugcpp("owo?"); } defaultRolesCheckBoxes = { @@ -64,7 +66,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare 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 " << 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(); @@ -183,11 +185,12 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare void MainWindow::customEvent(QEvent* ev) { if (ev->type() == CustomQEvent::EndpointWidgetObsolete) { + ev->setAccepted(true); this->removeEndpointWidget((EndpointWidgetEvent*)ev); return; } // Make sure the rest of events are handled - return QMainWindow::customEvent(ev); + QMainWindow::customEvent(ev); } void MainWindow::removeEndpointWidget(EndpointWidgetEvent* ev){ @@ -272,6 +275,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { * Registering needed custom events */ QEvent::registerEventType(CustomQEvent::EndpointWidgetObsolete); + QEvent::registerEventType(CustomQEvent::EndpointDefaultChange); widget = new QWidget(); layout = new QGridLayout(); @@ -279,9 +283,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { trayIconMenu = new QMenu(); trayIconMenuQuit = new QAction(STRING_QUIT); - changeDefaultCheckboxEnablement = new QEvent(QEvent::User); - changeDefaultCheckboxEnablement->setAccepted(true); - widget->setLayout(layout); setCentralWidget(widget); //layout->addWidget(pintas, 0, 0); @@ -317,13 +318,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { epw->defaultRolesCheckBoxes.at(role)->blockSignals(true); epw->getEndpointHandler()->assignRoles(role); epw->defaultRolesCheckBoxes.at(role)->blockSignals(false); - QCoreApplication::instance()->postEvent(epw->defaultRolesCheckBoxes.at(role), changeDefaultCheckboxEnablement); + QCoreApplication::instance()->postEvent(epw->defaultRolesCheckBoxes.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->defaultRolesCheckBoxes.at(Roles::ROLE_ALL), changeDefaultCheckboxEnablement); + QCoreApplication::instance()->postEvent(epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange)); } /* * Are you the dethroned king? @@ -333,14 +334,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { * And were you THE default up until now? */ if (epw->getEndpointHandler()->getRoles() == Roles::ROLE_ALL) { - QCoreApplication::instance()->postEvent(epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL), changeDefaultCheckboxEnablement); + QCoreApplication::instance()->postEvent(epw->defaultRolesCheckBoxes.at(Roles::ROLE_ALL), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange)); } epw->defaultRolesCheckBoxes.at(role)->blockSignals(true); //Same as before. ini-san will come... epw->getEndpointHandler()->removeRoles(role); epw->defaultRolesCheckBoxes.at(role)->blockSignals(false); - QCoreApplication::instance()->postEvent(epw->defaultRolesCheckBoxes.at(role), changeDefaultCheckboxEnablement); + QCoreApplication::instance()->postEvent(epw->defaultRolesCheckBoxes.at(role), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange)); } } @@ -348,7 +349,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { osh->setRemoveEndpointWidgetFunction([this](uint64_t index) { EndpointWidgetEvent* removeObsoleteEndpointWidget = new EndpointWidgetEvent((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index); - removeObsoleteEndpointWidget->setAccepted(true); QCoreApplication::instance()->postEvent(this, removeObsoleteEndpointWidget); }); diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index e2a3896..f66b5b3 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -58,6 +58,7 @@ */ enum CustomQEvent { EndpointWidgetObsolete = 1001, + EndpointDefaultChange = 1002, }; class EndpointWidgetEvent : public QEvent { @@ -69,18 +70,20 @@ public: //Q_DECLARE_METATYPE(EndpointWidgetEvent) class ExtendedCheckBox : public QCheckBox { - Q_OBJECT + Q_OBJECT +protected: + void customEvent(QEvent* ev) override; + public: //c++11: this inherits all parent's constructors unconditionally using QCheckBox::QCheckBox; //alternative being calling parent ctor directly after declaring child ctor: //B(int x) : A(x) { } - bool event(QEvent* ev) override; }; class EndpointWidget : public QWidget { - Q_OBJECT +Q_OBJECT public: EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr); @@ -153,8 +156,7 @@ private: QSystemTrayIcon *trayIcon; QMenu *trayIconMenu; QAction *trayIconMenuQuit; - QEvent* changeDefaultCheckboxEnablement; - + //public slots: // void setEndpointHandlers(std::vector *ephs);