diff --git a/src/main.cpp b/src/main.cpp index 5c72d6b..65eb57a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -411,8 +411,11 @@ int main( int argc, char* argv[] ) advsettings::OverlayController controller( desktopMode, noSound, qmlEngine ); - QQmlComponent component( - &qmlEngine, QUrl::fromLocalFile( "res/qml/mainwidget.qml" ) ); + QString path = QStandardPaths::locate( + QStandardPaths::AppDataLocation, + QStringLiteral( "res/qml/mainwidget.qml" ) ); + + QQmlComponent component( &qmlEngine, QUrl::fromLocalFile( path ) ); auto errors = component.errors(); for ( auto& e : errors ) { diff --git a/src/overlaycontroller.cpp b/src/overlaycontroller.cpp index 1d84ec9..a585437 100644 --- a/src/overlaycontroller.cpp +++ b/src/overlaycontroller.cpp @@ -85,8 +85,9 @@ OverlayController::OverlayController( bool desktopMode, << focusChangedSoundFile; } - QString alarm01SoundFile = QApplication::applicationDirPath().append( - "/res/sounds/alarm01.wav" ); + QString alarm01SoundFile + = QStandardPaths::locate( QStandardPaths::AppDataLocation, + QStringLiteral( "res/sounds/alarm01.wav" ) ); QFileInfo alarm01SoundFileInfo( alarm01SoundFile ); if ( alarm01SoundFileInfo.exists() && alarm01SoundFileInfo.isFile() ) { @@ -433,13 +434,14 @@ void OverlayController::SetWidget( QQuickItem* quickItem, m_ulOverlayHandle, vr::VROverlayInputMethod_Mouse ); vr::VROverlay()->SetOverlayFlag( m_ulOverlayHandle, vr::VROverlayFlags_SendVRScrollEvents, true ); - std::string thumbIconPath - = QApplication::applicationDirPath().toStdString() - + "\\res\\thumbicon.png"; - if ( QFile::exists( QString::fromStdString( thumbIconPath ) ) ) + QString thumbIconPath + = QStandardPaths::locate( QStandardPaths::AppDataLocation, + QStringLiteral( "res/thumbicon.png" ) ); + if ( QFile::exists( thumbIconPath ) ) { - vr::VROverlay()->SetOverlayFromFile( m_ulOverlayThumbnailHandle, - thumbIconPath.c_str() ); + vr::VROverlay()->SetOverlayFromFile( + m_ulOverlayThumbnailHandle, + thumbIconPath.toStdString().c_str() ); } else { diff --git a/src/tabcontrollers/AudioTabController.cpp b/src/tabcontrollers/AudioTabController.cpp index dd0feb8..94e671e 100644 --- a/src/tabcontrollers/AudioTabController.cpp +++ b/src/tabcontrollers/AudioTabController.cpp @@ -70,13 +70,14 @@ void AudioTabController::initStage2( OverlayController* var_parent, notifKey.c_str(), notifKey.c_str(), &m_ulNotificationOverlayHandle ); if ( overlayError == vr::VROverlayError_None ) { - std::string notifIconPath - = QApplication::applicationDirPath().toStdString() - + "/res/qml/ptt_notification.png"; - if ( QFile::exists( QString::fromStdString( notifIconPath ) ) ) + QString notifIconPath = QStandardPaths::locate( + QStandardPaths::AppDataLocation, + QStringLiteral( "/res/qml/ptt_notification.png" ) ); + if ( QFile::exists( notifIconPath ) ) { - vr::VROverlay()->SetOverlayFromFile( m_ulNotificationOverlayHandle, - notifIconPath.c_str() ); + vr::VROverlay()->SetOverlayFromFile( + m_ulNotificationOverlayHandle, + notifIconPath.toStdString().c_str() ); vr::VROverlay()->SetOverlayWidthInMeters( m_ulNotificationOverlayHandle, 0.02f ); vr::HmdMatrix34_t notificationTransform diff --git a/src/tabcontrollers/UtilitiesTabController.cpp b/src/tabcontrollers/UtilitiesTabController.cpp index 49812fa..948492e 100644 --- a/src/tabcontrollers/UtilitiesTabController.cpp +++ b/src/tabcontrollers/UtilitiesTabController.cpp @@ -267,6 +267,14 @@ void UtilitiesTabController::modAlarmTimeMinute( int value, bool notify ) } } +QString getBatteryIconPath( int batteryState ) +{ + QString batteryPrefix = "/res/battery_"; + return QStandardPaths::locate( + QStandardPaths::AppDataLocation, + batteryPrefix + QString::number( batteryState ) + ".png" ); +} + vr::VROverlayHandle_t createBatteryOverlay( vr::TrackedDeviceIndex_t index ) { vr::VROverlayHandle_t handle = vr::k_ulOverlayHandleInvalid; @@ -276,13 +284,11 @@ vr::VROverlayHandle_t createBatteryOverlay( vr::TrackedDeviceIndex_t index ) batteryKey.c_str(), batteryKey.c_str(), &handle ); if ( overlayError == vr::VROverlayError_None ) { - std::string batteryIconPath - = QApplication::applicationDirPath().toStdString() - + "/res/battery_0.png"; - if ( QFile::exists( QString::fromStdString( batteryIconPath ) ) ) + QString batteryIconPath = getBatteryIconPath( 0 ); + if ( QFile::exists( batteryIconPath ) ) { - vr::VROverlay()->SetOverlayFromFile( handle, - batteryIconPath.c_str() ); + vr::VROverlay()->SetOverlayFromFile( + handle, batteryIconPath.toStdString().c_str() ); vr::VROverlay()->SetOverlayWidthInMeters( handle, 0.05f ); vr::HmdMatrix34_t notificationTransform = { { { 1.0f, 0.0f, 0.0f, 0.00f }, @@ -486,8 +492,7 @@ void UtilitiesTabController::eventLoopTick() if ( deviceClass == vr::ETrackedDeviceClass::TrackedDeviceClass_GenericTracker ) { - if ( m_batteryOverlayHandles[i] - == vr::k_ulOverlayHandleInvalid ) + if ( m_batteryOverlayHandles[i] == 0 ) { LOG( INFO ) << "Creating battery overlay for device " << i; m_batteryOverlayHandles[i] = createBatteryOverlay( i ); @@ -529,17 +534,15 @@ void UtilitiesTabController::eventLoopTick() { LOG( INFO ) << "Updating battery overlay for device " << i - << " to " << batteryState << "(" << battery << ""; - std::string batteryIconPath - = QApplication::applicationDirPath().toStdString() - + "/res/battery_" + std::to_string( batteryState ) - + ".png"; - if ( QFile::exists( - QString::fromStdString( batteryIconPath ) ) ) + << " to " << batteryState << "(" << battery << ")" + << QString::number( m_batteryOverlayHandles[i] ); + QString batteryIconPath + = getBatteryIconPath( batteryState ); + if ( QFile::exists( batteryIconPath ) ) { vr::VROverlay()->SetOverlayFromFile( m_batteryOverlayHandles[i], - batteryIconPath.c_str() ); + batteryIconPath.toStdString().c_str() ); } else { diff --git a/src/tabcontrollers/UtilitiesTabController.h b/src/tabcontrollers/UtilitiesTabController.h index 1eb601d..d73f8e8 100644 --- a/src/tabcontrollers/UtilitiesTabController.h +++ b/src/tabcontrollers/UtilitiesTabController.h @@ -44,8 +44,8 @@ private: QTime m_alarmLastCheckTime; bool m_steamDesktopOverlayAvailable = false; float m_steamDesktopOverlayWidth = 4.0f; - vr::VROverlayHandle_t - m_batteryOverlayHandles[vr::k_unMaxTrackedDeviceCount]; + vr::VROverlayHandle_t m_batteryOverlayHandles[vr::k_unMaxTrackedDeviceCount] + = { 0 }; int m_batteryState[vr::k_unMaxTrackedDeviceCount]; bool m_batteryVisible[vr::k_unMaxTrackedDeviceCount];