From d654567d98a21d9483f55df29cfb046b53300a3b Mon Sep 17 00:00:00 2001 From: Vasily Date: Sun, 17 Mar 2019 16:33:08 +0100 Subject: [PATCH] Convert to new paths system --- src/overlaycontroller.cpp | 35 +++++++++---------- src/tabcontrollers/AudioTabController.cpp | 17 +++++---- src/tabcontrollers/UtilitiesTabController.cpp | 20 ++++++++--- src/utils/paths.cpp | 2 +- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/overlaycontroller.cpp b/src/overlaycontroller.cpp index 41526d8..d74dada 100644 --- a/src/overlaycontroller.cpp +++ b/src/overlaycontroller.cpp @@ -65,20 +65,19 @@ OverlayController::OverlayController( bool desktopMode, << focusChangedSoundFile; } - QString alarm01SoundFile - = QStandardPaths::locate( QStandardPaths::AppDataLocation, - QStringLiteral( "res/sounds/alarm01.wav" ) ); - QFileInfo alarm01SoundFileInfo( alarm01SoundFile ); - if ( alarm01SoundFileInfo.exists() && alarm01SoundFileInfo.isFile() ) + constexpr auto alarmFileName = "res/sounds/alarm01.wav"; + const auto alarm01SoundFile + = paths::binaryDirectoryFindFile( alarmFileName ); + + if ( alarm01SoundFile.has_value() ) { - m_alarm01SoundEffect.setSource( - QUrl::fromLocalFile( alarm01SoundFile ) ); + m_alarm01SoundEffect.setSource( QUrl::fromLocalFile( + QString::fromStdString( ( *alarm01SoundFile ) ) ) ); m_alarm01SoundEffect.setVolume( 1.0 ); } else { - LOG( ERROR ) << "Could not find alarm01 sound file " - << alarm01SoundFile; + LOG( ERROR ) << "Could not find alarm01 sound file " << alarmFileName; } QSurfaceFormat format; @@ -326,19 +325,19 @@ void OverlayController::SetWidget( QQuickItem* quickItem, m_ulOverlayHandle, vr::VROverlayFlags_SendVRSmoothScrollEvents, true ); - QString thumbIconPath = QStandardPaths::locate( - QStandardPaths::AppDataLocation, - QStringLiteral( "res/img/icons/thumbicon.png" ) ); - if ( QFile::exists( thumbIconPath ) ) + + constexpr auto thumbiconFilename = "res/img/icons/thumbicon.png"; + const auto thumbIconPath + = paths::binaryDirectoryFindFile( thumbiconFilename ); + if ( thumbIconPath.has_value() ) { - vr::VROverlay()->SetOverlayFromFile( - m_ulOverlayThumbnailHandle, - thumbIconPath.toStdString().c_str() ); + vr::VROverlay()->SetOverlayFromFile( m_ulOverlayThumbnailHandle, + thumbIconPath->c_str() ); } else { - LOG( ERROR ) << "Could not find thumbnail icon \"" << thumbIconPath - << "\""; + LOG( ERROR ) << "Could not find thumbnail icon \"" + << thumbiconFilename << "\""; } // Too many render calls in too short time overwhelm Qt and an assertion diff --git a/src/tabcontrollers/AudioTabController.cpp b/src/tabcontrollers/AudioTabController.cpp index 1f0ea2c..dd393a7 100644 --- a/src/tabcontrollers/AudioTabController.cpp +++ b/src/tabcontrollers/AudioTabController.cpp @@ -70,15 +70,14 @@ void AudioTabController::initStage2( OverlayController* var_parent, notifKey.c_str(), notifKey.c_str(), &m_ulNotificationOverlayHandle ); if ( overlayError == vr::VROverlayError_None ) { - QString notifIconPath = QStandardPaths::locate( - QStandardPaths::AppDataLocation, - QStringLiteral( - "/res/img/audio/microphone/ptt_notification.png" ) ); - if ( QFile::exists( notifIconPath ) ) + constexpr auto notificationIconFilename + = "/res/img/audio/microphone/ptt_notification.png"; + const auto notifIconPath + = paths::binaryDirectoryFindFile( notificationIconFilename ); + if ( notifIconPath.has_value() ) { - vr::VROverlay()->SetOverlayFromFile( - m_ulNotificationOverlayHandle, - notifIconPath.toStdString().c_str() ); + vr::VROverlay()->SetOverlayFromFile( m_ulNotificationOverlayHandle, + notifIconPath->c_str() ); vr::VROverlay()->SetOverlayWidthInMeters( m_ulNotificationOverlayHandle, 0.02f ); vr::HmdMatrix34_t notificationTransform @@ -93,7 +92,7 @@ void AudioTabController::initStage2( OverlayController* var_parent, else { LOG( ERROR ) << "Could not find notification icon \"" - << notifIconPath << "\""; + << notificationIconFilename << "\""; } } else diff --git a/src/tabcontrollers/UtilitiesTabController.cpp b/src/tabcontrollers/UtilitiesTabController.cpp index 91e85b5..8cec8d4 100644 --- a/src/tabcontrollers/UtilitiesTabController.cpp +++ b/src/tabcontrollers/UtilitiesTabController.cpp @@ -250,10 +250,22 @@ void UtilitiesTabController::modAlarmTimeMinute( int value, bool notify ) QString getBatteryIconPath( int batteryState ) { - QString batteryPrefix = "/res/img/battery/battery_"; - return QStandardPaths::locate( - QStandardPaths::AppDataLocation, - batteryPrefix + QString::number( batteryState ) + ".png" ); + constexpr auto batteryPrefix = "/res/img/battery/battery_"; + + const auto batteryFullPath + = ( batteryPrefix + QString::number( batteryState ) + ".png" ) + .toStdString(); + + const auto batteryPath = paths::binaryDirectoryFindFile( batteryFullPath ); + + if ( !batteryPath.has_value() ) + { + LOG( ERROR ) << "Unable to find battery image number '" << batteryState + << "'."; + return ""; + } + + return QString::fromStdString( *batteryPath ); } vr::VROverlayHandle_t createBatteryOverlay( vr::TrackedDeviceIndex_t index ) diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 7dadca0..1090952 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -35,7 +35,7 @@ optional binaryDirectoryFindFile( const string fileName ) return path.toStdString(); } -optional binaryDirectoryFindDirectory( string directoryName ) +optional binaryDirectoryFindDirectory( const string directoryName ) { const auto path = QStandardPaths::locate( QStandardPaths::AppDataLocation,