From abfcf1cb5bbfe846f5b61555ddcbf1231d23e78d Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Mon, 1 Jun 2015 21:47:55 +0000 Subject: [PATCH] New static data location for read-only data files Access in CMake via ${WSJT_SHARE_DESTINATION}/${WSJT_DATA_DESTINATION} Access in wsjtx.exe using Configuration::data_dir() git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5487 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- CMakeLists.txt | 3 +++ Configuration.cpp | 28 ++++++++++++++++++++++++---- Configuration.hpp | 1 + wsjtx_config.h.in | 1 + 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee438a1f1..7b0950f3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,7 @@ set (WSJT_BIN_DESTINATION bin) set (WSJT_LIB_DESTINATION lib) set (WSJT_SHARE_DESTINATION share) set (WSJT_DOC_DESTINATION doc/${CMAKE_PROJECT_NAME}) +set (WSJT_DATA_DESTINATION ${CMAKE_PROJECT_NAME}) set (WSJT_MANPAGE_DESTINATION share) set (WSJT_PLUGIN_DESTINATION lib/plugins) set (WSJT_QT_CONF_DESTINATION bin) @@ -159,6 +160,7 @@ set (WSJT_QT_CONF_DESTINATION bin) if (WIN32) set (WSJT_SHARE_DESTINATION bin) set (WSJT_DOC_DESTINATION doc) + set (WSJT_DATA_DESTINATION data) set (WSJT_PLUGIN_DESTINATION plugins) endif (WIN32) @@ -167,6 +169,7 @@ if (APPLE) set (WSJT_SHARE_DESTINATION ${CMAKE_PROJECT_NAME}.app/Contents/Resources) set (WSJT_MANPAGE_DESTINATION ${CMAKE_PROJECT_NAME}.app/Contents/Resources) set (WSJT_DOC_DESTINATION doc) + set (WSJT_DATA_DESTINATION data) set (WSJT_PLUGIN_DESTINATION ${CMAKE_PROJECT_NAME}.app/Contents/PlugIns) set (WSJT_QT_CONF_DESTINATION ${CMAKE_PROJECT_NAME}.app/Contents/Resources) endif (APPLE) diff --git a/Configuration.cpp b/Configuration.cpp index 5e215daae..1ce678b5c 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -442,6 +442,7 @@ private: QSettings * settings_; QDir doc_dir_; + QDir data_dir_; QDir temp_dir_; QDir default_save_directory_; QDir save_directory_; @@ -569,6 +570,7 @@ Configuration::~Configuration () } QDir Configuration::doc_dir () const {return m_->doc_dir_;} +QDir Configuration::data_dir () const {return m_->data_dir_;} QDir Configuration::temp_dir () const {return m_->temp_dir_;} int Configuration::exec () {return m_->exec ();} @@ -700,6 +702,7 @@ Configuration::impl::impl (Configuration * self, QSettings * settings, QWidget * , ui_ {new Ui::configuration_dialog} , settings_ {settings} , doc_dir_ {QApplication::applicationDirPath ()} + , data_dir_ {QApplication::applicationDirPath ()} , frequencies_ {&bands_} , next_frequencies_ {&bands_} , stations_ {&bands_} @@ -719,15 +722,15 @@ Configuration::impl::impl (Configuration * self, QSettings * settings, QWidget * { ui_->setupUi (this); - #if !defined (CMAKE_BUILD) #define WSJT_SHARE_DESTINATION "." #define WSJT_DOC_DESTINATION "." +#define WSJT_DATA_DESTINATION "." #endif #if !defined (Q_OS_WIN) || QT_VERSION >= 0x050300 - auto path = QStandardPaths::locate (QStandardPaths::DataLocation, WSJT_DOC_DESTINATION, QStandardPaths::LocateDirectory); - if (path.isEmpty ()) + auto doc_path = QStandardPaths::locate (QStandardPaths::DataLocation, WSJT_DOC_DESTINATION, QStandardPaths::LocateDirectory); + if (doc_path.isEmpty ()) { doc_dir_.cdUp (); #if defined (Q_OS_MAC) @@ -739,10 +742,27 @@ Configuration::impl::impl (Configuration * self, QSettings * settings, QWidget * } else { - doc_dir_.cd (path); + doc_dir_.cd (doc_path); + } + + auto data_path = QStandardPaths::locate (QStandardPaths::DataLocation, WSJT_DATA_DESTINATION, QStandardPaths::LocateDirectory); + if (data_path.isEmpty ()) + { + data_dir_.cdUp (); +#if defined (Q_OS_MAC) + data_dir_.cdUp (); + data_dir_.cdUp (); +#endif + data_dir_.cd (WSJT_SHARE_DESTINATION); + data_dir_.cd (WSJT_DATA_DESTINATION); + } + else + { + data_dir_.cd (data_path); } #else doc_dir_.cd (WSJT_DOC_DESTINATION); + data_dir_.cd (WSJT_DATA_DESTINATION); #endif { diff --git a/Configuration.hpp b/Configuration.hpp index 4bd6304ce..e79cd627e 100644 --- a/Configuration.hpp +++ b/Configuration.hpp @@ -73,6 +73,7 @@ public: QDir temp_dir () const; QDir doc_dir () const; + QDir data_dir () const; QAudioDeviceInfo const& audio_input_device () const; AudioDevice::Channel audio_input_channel () const; diff --git a/wsjtx_config.h.in b/wsjtx_config.h.in index 4a564e2d6..9d4ec1212 100644 --- a/wsjtx_config.h.in +++ b/wsjtx_config.h.in @@ -13,6 +13,7 @@ #cmakedefine WSJT_SHARE_DESTINATION "@WSJT_SHARE_DESTINATION@" #cmakedefine WSJT_LIB_DESTINATION "@WSJT_LIB_DESTINATION@" #cmakedefine WSJT_DOC_DESTINATION "@WSJT_DOC_DESTINATION@" +#cmakedefine WSJT_DATA_DESTINATION "@WSJT_DATA_DESTINATION@" #cmakedefine PROJECT_MANUAL "@PROJECT_MANUAL@" #cmakedefine PROJECT_MANUAL_DIRECTORY_URL "@PROJECT_MANUAL_DIRECTORY_URL@"