From 2d8e7c007c3fc384e6dd69684932e34d966a63db Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Mon, 9 Sep 2019 20:08:43 -0400 Subject: Update default presets location Since the changes to run the applications as non-root, the location of the default preset file has not matched with the agl-driver user the application runs as. Since simply changing the install location to /home/1001 would require some post-install SMACK label tinkering, and is perhaps fragile to the application user, the files are now instead installed to /etc/xdg/AGL, with the defaults to be used named radio-presets.conf. Update the QSettings code to first look for /etc/xdg/AGL/radio-presets.conf before trying the appdata directory. Bug-AGL: SPEC-2789 Signed-off-by: Scott Murray Change-Id: I6fd32575c4bd8f42f8575a078f62e64555ba50c2 (cherry picked from commit d216c5604b7598f120d7d53754ac5a7791d45be5) --- app/main.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index f555475..319e1e7 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -27,8 +27,12 @@ #include #include #include +#include +#include #include "PresetDataObject.h" +#define APP_DATA_PRESETS_PATH "/app-data/radio/presets.conf" + int main(int argc, char *argv[]) { QString graphic_role = QString("radio"); @@ -47,9 +51,9 @@ int main(int argc, char *argv[]) // Read presets from configuration file // - // If HOME is set, use $HOME/app-data/radio/presets.conf, else fall back - // to the QSettings default locations with organization "AGL" and a - // file name of radio-presets.conf. See: + // If HOME is set, use $HOME/app-data/radio/presets.conf if it exists, + // else fall back to the QSettings default locations with organization + // "AGL" and a file name of radio-presets.conf. See: // // http://doc.qt.io/qt-5/qsettings.html#platform-specific-notes // @@ -57,13 +61,22 @@ int main(int argc, char *argv[]) // QSettings *pSettings = NULL; char *p = getenv("HOME"); + bool settingsFound = false; if(p) { - QString confPath = p; - confPath.append("/app-data/radio/presets.conf"); - pSettings = new QSettings(confPath, QSettings::NativeFormat); - } else { - pSettings = new QSettings("AGL", "radio-presets"); + struct stat statbuf; + std::string presets(p); + presets += APP_DATA_PRESETS_PATH; + if(stat(presets.c_str(), &statbuf) == 0) { + QString confPath = p; + confPath.append(APP_DATA_PRESETS_PATH); + pSettings = new QSettings(confPath, QSettings::NativeFormat); + settingsFound = true; + } + } + if(!settingsFound) { + pSettings = new QSettings("AGL", "radio-presets"); } + QList presetDataList; int size = pSettings->beginReadArray("fmPresets"); for (int i = 0; i < size; ++i) { -- cgit 1.2.3-korg