Commit 1a06864b authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

core, make userData directory in conf (https://phabricator.kde.org/T3852)

parent e1b03a50
......@@ -3,6 +3,9 @@ GCompris.pro.user
.directory
*.aac
*.qrc
*.qmlc
*.jsc
*~
build/*
*.DS_Store
src/activities/activities_out.txt
......
......@@ -60,7 +60,7 @@ var CONTACT = 0x0080;
var baseUrl = "qrc:/gcompris/src/activities/balancebox/resource";
var builtinFile = baseUrl + "/levels-default.json";
var userFile = "file://" + GCompris.ApplicationInfo.getSharedWritablePath()
var userFile = "file://" + GCompris.ApplicationSettings.userDataPath
+ "/balancebox/" + "levels-user.json"
function validateLevels(doc)
......
......@@ -166,12 +166,6 @@ QString ApplicationInfo::getLocaleFilePath(const QString &file)
return filename;
}
QString ApplicationInfo::getSharedWritablePath() const
{
return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ QLatin1String("/GCompris");
}
QStringList ApplicationInfo::getSystemExcludedFonts()
{
return m_excludedFonts;
......
......@@ -211,15 +211,6 @@ public:
*/
Q_INVOKABLE void abandonAudioFocus() const;
/**
* Return the platform specific path for storing data shared between apps
*
* On Android: /storage/emulated/0/GCompris (>= Android 4.2),
* /storage/sdcard0/GCompris (< Android 4.2)
* On Linux: $HOME/local/share/GCompris
*/
Q_INVOKABLE QString getSharedWritablePath() const;
/**
* Compare two strings respecting locale specific sort order.
*
......
......@@ -59,6 +59,7 @@ static const QString ENABLE_AUTOMATIC_DOWNLOADS = QLatin1String("enableAutomatic
static const QString DOWNLOAD_SERVER_URL_KEY = QLatin1String("downloadServerUrl");
static const QString CACHE_PATH_KEY = QLatin1String("cachePath");
static const QString USERDATA_PATH_KEY = QLatin1String("userDataPath");
static const QString RENDERER_KEY = QLatin1String("renderer");
static const QString EXE_COUNT_KEY = QLatin1String("exeCount");
......@@ -152,6 +153,7 @@ ApplicationSettings::ApplicationSettings(const QString &configPath, QObject *par
m_config.beginGroup(ADMIN_GROUP_KEY);
m_downloadServerUrl = m_config.value(DOWNLOAD_SERVER_URL_KEY, QLatin1String("http://gcompris.net")).toString();
m_cachePath = m_config.value(CACHE_PATH_KEY, QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).toString();
m_userDataPath = m_config.value(USERDATA_PATH_KEY, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/GCompris")).toString();
m_renderer = m_config.value(RENDERER_KEY, GRAPHICAL_RENDERER).toString();
m_config.endGroup();
......@@ -183,6 +185,7 @@ ApplicationSettings::ApplicationSettings(const QString &configPath, QObject *par
connect(this, &ApplicationSettings::kioskModeChanged, this, &ApplicationSettings::notifyKioskModeChanged);
connect(this, &ApplicationSettings::downloadServerUrlChanged, this, &ApplicationSettings::notifyDownloadServerUrlChanged);
connect(this, &ApplicationSettings::cachePathChanged, this, &ApplicationSettings::notifyCachePathChanged);
connect(this, &ApplicationSettings::userDataPathChanged, this, &ApplicationSettings::notifyUserDataPathChanged);
connect(this, &ApplicationSettings::rendererChanged, this, &ApplicationSettings::notifyRendererChanged);
connect(this, &ApplicationSettings::exeCountChanged, this, &ApplicationSettings::notifyExeCountChanged);
connect(this, &ApplicationSettings::barHiddenChanged, this, &ApplicationSettings::notifyBarHiddenChanged);
......@@ -222,6 +225,7 @@ ApplicationSettings::~ApplicationSettings()
m_config.beginGroup(ADMIN_GROUP_KEY);
m_config.setValue(DOWNLOAD_SERVER_URL_KEY, m_downloadServerUrl);
m_config.setValue(CACHE_PATH_KEY, m_cachePath);
m_config.setValue(USERDATA_PATH_KEY, m_userDataPath);
m_config.setValue(RENDERER_KEY, m_renderer);
m_config.endGroup();
......@@ -388,6 +392,12 @@ void ApplicationSettings::notifyCachePathChanged()
qDebug() << "cachePath set to: " << m_cachePath;
}
void ApplicationSettings::notifyUserDataPathChanged()
{
updateValueInConfig(ADMIN_GROUP_KEY, USERDATA_PATH_KEY, m_userDataPath);
qDebug() << "userDataPath set to: " << m_userDataPath;
}
void ApplicationSettings::notifyRendererChanged()
{
updateValueInConfig(ADMIN_GROUP_KEY, RENDERER_KEY, m_renderer);
......
......@@ -243,6 +243,15 @@ class ApplicationSettings : public QObject
*/
Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY cachePathChanged)
/**
* Return the platform specific path for storing data shared between apps
*
* On Android: /storage/emulated/0/GCompris (>= Android 4.2),
* /storage/sdcard0/GCompris (< Android 4.2)
* On Linux: $HOME/local/share/GCompris
*/
Q_PROPERTY(QString userDataPath READ userDataPath WRITE setUserDataPath NOTIFY userDataPathChanged)
/**
* Define the renderer used.
* Either openGL or software renderer (only for Qt >= 5.8)
......@@ -441,6 +450,11 @@ public:
emit cachePathChanged();
}
QString userDataPath() const { return m_userDataPath; }
void setUserDataPath(const QString &newUserDataPath) {
m_userDataPath = newUserDataPath;
emit userDataPathChanged();
}
quint32 exeCount() const { return m_exeCount; }
void setExeCount(const quint32 newExeCount) {
m_exeCount = newExeCount;
......@@ -506,7 +520,7 @@ protected slots:
Q_INVOKABLE void notifyDownloadServerUrlChanged();
Q_INVOKABLE void notifyCachePathChanged();
Q_INVOKABLE void notifyUserDataPathChanged();
Q_INVOKABLE void notifyExeCountChanged();
Q_INVOKABLE void notifyLastGCVersionRanChanged();
......@@ -577,6 +591,7 @@ signals:
void downloadServerUrlChanged();
void cachePathChanged();
void userDataPathChanged();
void exeCountChanged();
......@@ -623,6 +638,7 @@ private:
QString m_downloadServerUrl;
QString m_cachePath;
QString m_userDataPath;
quint32 m_exeCount;
......
......@@ -149,7 +149,7 @@ Window {
+ ", ratio=" + ApplicationInfo.ratio
+ ", fontRatio=" + ApplicationInfo.fontRatio
+ ", dpi=" + Math.round(Screen.pixelDensity*25.4)
+ ", sharedWritablePath=" + ApplicationInfo.getSharedWritablePath()
+ ", userDataPath=" + ApplicationSettings.userDataPath
+ ")");
if (ApplicationSettings.exeCount === 1 &&
!ApplicationSettings.isKioskMode &&
......
......@@ -80,6 +80,7 @@ void CoreApplicationSettingsTest::ApplicationSettingsTest_data()
QTest::addColumn<QString>("wordset");
QTest::addColumn<QString>("downloadServerUrl");
QTest::addColumn<QString>("cachePath");
QTest::addColumn<QString>("userDataPath");
QTest::addColumn<quint32>("exeCount");
QTest::addColumn<bool>("isBarHidden");
QTest::addColumn<int>("baseFontSize");
......@@ -87,8 +88,8 @@ void CoreApplicationSettingsTest::ApplicationSettingsTest_data()
QTest::addColumn<bool>("isFullscreen");
QTest::addColumn<QString>("renderer");
QTest::newRow("dummySettings1") << true << true << true << (quint32)21 << (quint32)25 << true << "en_EN" << "font1" << true << (quint32)36 << (qreal)2.532 << true << (quint32)26 << (quint32)84 << true << "codeKey1" << true << true << "wordset1" << "downloadServerUrl1" << "cachePath1" << (quint32)48 << true << 7 << 52 << false << "softwareRenderer";
QTest::newRow("dummySettings2") << false << false << false << (quint32)20 << (quint32)32 << false << "en_US" << "font2" << false << (quint32)34 <<(qreal)2.3 << false << (quint32)24 << (quint32)80 << false << "codekey2" << false << false << "wordset2" << "downloadServerUrl2" << "cachePath2" << (quint32)44 << false << 5 << 64 << false << "openglRenderer";
QTest::newRow("dummySettings1") << true << true << true << (quint32)21 << (quint32)25 << true << "en_EN" << "font1" << true << (quint32)36 << (qreal)2.532 << true << (quint32)26 << (quint32)84 << true << "codeKey1" << true << true << "wordset1" << "downloadServerUrl1" << "cachePath1" << "userDataPath1" << (quint32)48 << true << 7 << 52 << false << "softwareRenderer";
QTest::newRow("dummySettings2") << false << false << false << (quint32)20 << (quint32)32 << false << "en_US" << "font2" << false << (quint32)34 <<(qreal)2.3 << false << (quint32)24 << (quint32)80 << false << "codekey2" << false << false << "wordset2" << "downloadServerUrl2" << "cachePath2" << "userDataPath2" << (quint32)44 << false << 5 << 64 << false << "openglRenderer";
}
void CoreApplicationSettingsTest::ApplicationSettingsTest()
......@@ -117,6 +118,7 @@ void CoreApplicationSettingsTest::ApplicationSettingsTest()
APPLICATION_SETTINGS_TEST_ATTRIBUTE(QString, wordset, setWordset, wordsetChanged);
APPLICATION_SETTINGS_TEST_ATTRIBUTE(QString, downloadServerUrl, setDownloadServerUrl, downloadServerUrlChanged);
APPLICATION_SETTINGS_TEST_ATTRIBUTE(QString, cachePath, setCachePath, cachePathChanged);
APPLICATION_SETTINGS_TEST_ATTRIBUTE(QString, userDataPath, setUserDataPath, userDataPathChanged);
APPLICATION_SETTINGS_TEST_ATTRIBUTE(quint32, exeCount, setExeCount, exeCountChanged);
APPLICATION_SETTINGS_TEST_ATTRIBUTE(bool, isBarHidden, setBarHidden, barHiddenChanged);
APPLICATION_SETTINGS_TEST_ATTRIBUTE(int, baseFontSize, setBaseFontSize, baseFontSizeChanged);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment