summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2019-09-09 20:08:43 -0400
committerScott Murray <scott.murray@konsulko.com>2019-09-09 20:11:17 -0400
commitd216c5604b7598f120d7d53754ac5a7791d45be5 (patch)
tree3b5fee02c7bfb386b641496690056649acbbd9b7
parentea7649ee08a382c7a2a72351cfe6857bd1394493 (diff)
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 <scott.murray@konsulko.com> Change-Id: I6fd32575c4bd8f42f8575a078f62e64555ba50c2
-rw-r--r--app/main.cpp29
1 files 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 <libhomescreen.hpp>
#include <qlibwindowmanager.h>
#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/stat.h>
#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<QObject*> presetDataList;
int size = pSettings->beginReadArray("fmPresets");
for (int i = 0; i < size; ++i) {