From b3b354d00d5ec7abdc7a50be64146b2bdd2af6e8 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Thu, 7 Jun 2018 12:31:05 +1000 Subject: [PATCH] Fix resource paths on MacOS --- sleepyhead/common_gui.cpp | 12 ++++++++++++ sleepyhead/common_gui.h | 1 + sleepyhead/help.cpp | 5 ++--- sleepyhead/sleepyhead.pro | 7 ++++--- sleepyhead/translation.cpp | 14 ++++++-------- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/sleepyhead/common_gui.cpp b/sleepyhead/common_gui.cpp index e0eac07d..d21d5d1a 100644 --- a/sleepyhead/common_gui.cpp +++ b/sleepyhead/common_gui.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "SleepLib/common.h" #include "common_gui.h" @@ -86,6 +88,16 @@ QString getBranchVersion() return version; } +QString appResourcePath() +{ +#ifdef Q_OS_MAC + QString path = QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../Resources"); +#else + // not sure where it goes on Linux yet + QString path = QCoreApplication::applicationDirPath(); +#endif + return path; +} Qt::DayOfWeek firstDayOfWeekFromLocale() { diff --git a/sleepyhead/common_gui.h b/sleepyhead/common_gui.h index 17136da2..e96dead0 100644 --- a/sleepyhead/common_gui.h +++ b/sleepyhead/common_gui.h @@ -18,6 +18,7 @@ Qt::DayOfWeek firstDayOfWeekFromLocale(); QString getBranchVersion(); +QString appResourcePath(); const QString CSTR_GFX_ANGLE = "ANGLE"; const QString CSTR_GFX_OpenGL = "OpenGL"; diff --git a/sleepyhead/help.cpp b/sleepyhead/help.cpp index 9ddfdf90..f0682ae8 100644 --- a/sleepyhead/help.cpp +++ b/sleepyhead/help.cpp @@ -11,6 +11,7 @@ #include #include +#include "common_gui.h" #include "help.h" #include "ui_help.h" @@ -22,11 +23,9 @@ Help::Help(QWidget *parent) : { ui->setupUi(this); - helpEngine = new QHelpEngine(QCoreApplication::applicationDirPath() + "/Help/help.qhc", this); + helpEngine = new QHelpEngine(appResourcePath() + "/Help/help.qhc", this); helpEngine->setupData(); - // QString helpFile = QCoreApplication::applicationDirPath() + "/Help/help_en.qch"; - /*if (!helpEngine->registeredDocumentations().contains(helpFile)) { if (helpEngine->registerDocumentation(helpFile)) { qDebug() << "Registered" << helpFile; diff --git a/sleepyhead/sleepyhead.pro b/sleepyhead/sleepyhead.pro index 4cb7768c..1c9a8dcc 100644 --- a/sleepyhead/sleepyhead.pro +++ b/sleepyhead/sleepyhead.pro @@ -321,14 +321,15 @@ win32 { } -mac { +macx { TransFiles.files = $$files(../Translations/*.qm) TransFiles.path = Contents/Resources/Translations - HelpFiles.files = $$files(../Help/*.qch) - HelpFiles.files += $$files(../Help/help.qhc) + HelpFiles.files = $$files(help/*.qch) + HelpFiles.files += $$files(help/help.qhc) HelpFiles.path = Contents/Resources/Help QMAKE_BUNDLE_DATA += TransFiles QMAKE_BUNDLE_DATA += HelpFiles + message("Setting up Translations & Help Transfers") } #include(../3rdparty/quazip/quazip/quazip.pri) diff --git a/sleepyhead/translation.cpp b/sleepyhead/translation.cpp index e7994a5b..3fcc5536 100644 --- a/sleepyhead/translation.cpp +++ b/sleepyhead/translation.cpp @@ -20,9 +20,11 @@ #include #include -#ifndef nullptr -#define nullptr NULL -#endif +#include "common_gui.h" + +//#ifndef nullptr +//#define nullptr NULL +//#endif #include "translation.h" @@ -42,11 +44,7 @@ void initTranslations(QSettings & settings) { QHash langFiles; -#ifdef Q_OS_MAC - QString transdir = QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../Resources/Translations/"); -#else - const QString transdir = QCoreApplication::applicationDirPath() + "/Translations/"; -#endif + const QString transdir = appResourcePath() +"/Translations"; QDir dir(transdir); qDebug() << "Scanning" << transdir.toLocal8Bit().data();