use QStandardPaths to get resource locations (#44)

* use QStandardPaths to get resource locations

While this shouldn't change behaviour for windows, it allows installing the resource files seperate from the binary on unix systems

* initialize battery overlay handles to 0
This commit is contained in:
Robin Appelman
2019-01-12 16:34:45 -06:00
committed by ykeara
parent b418c76315
commit e75a4c2353
5 changed files with 43 additions and 34 deletions
+5 -2
View File
@@ -411,8 +411,11 @@ int main( int argc, char* argv[] )
advsettings::OverlayController controller( advsettings::OverlayController controller(
desktopMode, noSound, qmlEngine ); desktopMode, noSound, qmlEngine );
QQmlComponent component( QString path = QStandardPaths::locate(
&qmlEngine, QUrl::fromLocalFile( "res/qml/mainwidget.qml" ) ); QStandardPaths::AppDataLocation,
QStringLiteral( "res/qml/mainwidget.qml" ) );
QQmlComponent component( &qmlEngine, QUrl::fromLocalFile( path ) );
auto errors = component.errors(); auto errors = component.errors();
for ( auto& e : errors ) for ( auto& e : errors )
{ {
+10 -8
View File
@@ -85,8 +85,9 @@ OverlayController::OverlayController( bool desktopMode,
<< focusChangedSoundFile; << focusChangedSoundFile;
} }
QString alarm01SoundFile = QApplication::applicationDirPath().append( QString alarm01SoundFile
"/res/sounds/alarm01.wav" ); = QStandardPaths::locate( QStandardPaths::AppDataLocation,
QStringLiteral( "res/sounds/alarm01.wav" ) );
QFileInfo alarm01SoundFileInfo( alarm01SoundFile ); QFileInfo alarm01SoundFileInfo( alarm01SoundFile );
if ( alarm01SoundFileInfo.exists() && alarm01SoundFileInfo.isFile() ) if ( alarm01SoundFileInfo.exists() && alarm01SoundFileInfo.isFile() )
{ {
@@ -433,13 +434,14 @@ void OverlayController::SetWidget( QQuickItem* quickItem,
m_ulOverlayHandle, vr::VROverlayInputMethod_Mouse ); m_ulOverlayHandle, vr::VROverlayInputMethod_Mouse );
vr::VROverlay()->SetOverlayFlag( vr::VROverlay()->SetOverlayFlag(
m_ulOverlayHandle, vr::VROverlayFlags_SendVRScrollEvents, true ); m_ulOverlayHandle, vr::VROverlayFlags_SendVRScrollEvents, true );
std::string thumbIconPath QString thumbIconPath
= QApplication::applicationDirPath().toStdString() = QStandardPaths::locate( QStandardPaths::AppDataLocation,
+ "\\res\\thumbicon.png"; QStringLiteral( "res/thumbicon.png" ) );
if ( QFile::exists( QString::fromStdString( thumbIconPath ) ) ) if ( QFile::exists( thumbIconPath ) )
{ {
vr::VROverlay()->SetOverlayFromFile( m_ulOverlayThumbnailHandle, vr::VROverlay()->SetOverlayFromFile(
thumbIconPath.c_str() ); m_ulOverlayThumbnailHandle,
thumbIconPath.toStdString().c_str() );
} }
else else
{ {
+7 -6
View File
@@ -70,13 +70,14 @@ void AudioTabController::initStage2( OverlayController* var_parent,
notifKey.c_str(), notifKey.c_str(), &m_ulNotificationOverlayHandle ); notifKey.c_str(), notifKey.c_str(), &m_ulNotificationOverlayHandle );
if ( overlayError == vr::VROverlayError_None ) if ( overlayError == vr::VROverlayError_None )
{ {
std::string notifIconPath QString notifIconPath = QStandardPaths::locate(
= QApplication::applicationDirPath().toStdString() QStandardPaths::AppDataLocation,
+ "/res/qml/ptt_notification.png"; QStringLiteral( "/res/qml/ptt_notification.png" ) );
if ( QFile::exists( QString::fromStdString( notifIconPath ) ) ) if ( QFile::exists( notifIconPath ) )
{ {
vr::VROverlay()->SetOverlayFromFile( m_ulNotificationOverlayHandle, vr::VROverlay()->SetOverlayFromFile(
notifIconPath.c_str() ); m_ulNotificationOverlayHandle,
notifIconPath.toStdString().c_str() );
vr::VROverlay()->SetOverlayWidthInMeters( vr::VROverlay()->SetOverlayWidthInMeters(
m_ulNotificationOverlayHandle, 0.02f ); m_ulNotificationOverlayHandle, 0.02f );
vr::HmdMatrix34_t notificationTransform vr::HmdMatrix34_t notificationTransform
+19 -16
View File
@@ -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 createBatteryOverlay( vr::TrackedDeviceIndex_t index )
{ {
vr::VROverlayHandle_t handle = vr::k_ulOverlayHandleInvalid; 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 ); batteryKey.c_str(), batteryKey.c_str(), &handle );
if ( overlayError == vr::VROverlayError_None ) if ( overlayError == vr::VROverlayError_None )
{ {
std::string batteryIconPath QString batteryIconPath = getBatteryIconPath( 0 );
= QApplication::applicationDirPath().toStdString() if ( QFile::exists( batteryIconPath ) )
+ "/res/battery_0.png";
if ( QFile::exists( QString::fromStdString( batteryIconPath ) ) )
{ {
vr::VROverlay()->SetOverlayFromFile( handle, vr::VROverlay()->SetOverlayFromFile(
batteryIconPath.c_str() ); handle, batteryIconPath.toStdString().c_str() );
vr::VROverlay()->SetOverlayWidthInMeters( handle, 0.05f ); vr::VROverlay()->SetOverlayWidthInMeters( handle, 0.05f );
vr::HmdMatrix34_t notificationTransform vr::HmdMatrix34_t notificationTransform
= { { { 1.0f, 0.0f, 0.0f, 0.00f }, = { { { 1.0f, 0.0f, 0.0f, 0.00f },
@@ -486,8 +492,7 @@ void UtilitiesTabController::eventLoopTick()
if ( deviceClass if ( deviceClass
== vr::ETrackedDeviceClass::TrackedDeviceClass_GenericTracker ) == vr::ETrackedDeviceClass::TrackedDeviceClass_GenericTracker )
{ {
if ( m_batteryOverlayHandles[i] if ( m_batteryOverlayHandles[i] == 0 )
== vr::k_ulOverlayHandleInvalid )
{ {
LOG( INFO ) << "Creating battery overlay for device " << i; LOG( INFO ) << "Creating battery overlay for device " << i;
m_batteryOverlayHandles[i] = createBatteryOverlay( i ); m_batteryOverlayHandles[i] = createBatteryOverlay( i );
@@ -529,17 +534,15 @@ void UtilitiesTabController::eventLoopTick()
{ {
LOG( INFO ) LOG( INFO )
<< "Updating battery overlay for device " << i << "Updating battery overlay for device " << i
<< " to " << batteryState << "(" << battery << ""; << " to " << batteryState << "(" << battery << ")"
std::string batteryIconPath << QString::number( m_batteryOverlayHandles[i] );
= QApplication::applicationDirPath().toStdString() QString batteryIconPath
+ "/res/battery_" + std::to_string( batteryState ) = getBatteryIconPath( batteryState );
+ ".png"; if ( QFile::exists( batteryIconPath ) )
if ( QFile::exists(
QString::fromStdString( batteryIconPath ) ) )
{ {
vr::VROverlay()->SetOverlayFromFile( vr::VROverlay()->SetOverlayFromFile(
m_batteryOverlayHandles[i], m_batteryOverlayHandles[i],
batteryIconPath.c_str() ); batteryIconPath.toStdString().c_str() );
} }
else else
{ {
+2 -2
View File
@@ -44,8 +44,8 @@ private:
QTime m_alarmLastCheckTime; QTime m_alarmLastCheckTime;
bool m_steamDesktopOverlayAvailable = false; bool m_steamDesktopOverlayAvailable = false;
float m_steamDesktopOverlayWidth = 4.0f; float m_steamDesktopOverlayWidth = 4.0f;
vr::VROverlayHandle_t vr::VROverlayHandle_t m_batteryOverlayHandles[vr::k_unMaxTrackedDeviceCount]
m_batteryOverlayHandles[vr::k_unMaxTrackedDeviceCount]; = { 0 };
int m_batteryState[vr::k_unMaxTrackedDeviceCount]; int m_batteryState[vr::k_unMaxTrackedDeviceCount];
bool m_batteryVisible[vr::k_unMaxTrackedDeviceCount]; bool m_batteryVisible[vr::k_unMaxTrackedDeviceCount];