Override config, data and cache location
This commit is contained in:
@@ -39,10 +39,10 @@
|
||||
#include <QSqlDriver>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlError>
|
||||
#include <QStandardPaths>
|
||||
#include <QScopeGuard>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "logging.h"
|
||||
#include "standardpaths.h"
|
||||
#include "taskmanager.h"
|
||||
#include "database.h"
|
||||
#include "sqlquery.h"
|
||||
@@ -78,7 +78,7 @@ Database::Database(SharedPtr<TaskManager> task_manager, QObject *parent, const Q
|
||||
connection_id_ = sNextConnectionId++;
|
||||
}
|
||||
|
||||
directory_ = QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
|
||||
directory_ = QDir::toNativeSeparators(StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation)).replace(u"Strawberry"_s, u"strawberry"_s);
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
Connect();
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
#include <QSize>
|
||||
#include <QStandardPaths>
|
||||
#include <QSettings>
|
||||
|
||||
#include "logging.h"
|
||||
#include "standardpaths.h"
|
||||
#include "settings.h"
|
||||
#include "includes/iconmapper.h"
|
||||
#include "iconloader.h"
|
||||
@@ -51,7 +51,7 @@ void IconLoader::Init() {
|
||||
#endif
|
||||
|
||||
QDir dir;
|
||||
if (dir.exists(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/icons"_s)) {
|
||||
if (dir.exists(StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation) + u"/icons"_s)) {
|
||||
custom_icons_ = true;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ QIcon IconLoader::Load(const QString &name, const bool system_icon, const int fi
|
||||
}
|
||||
|
||||
if (custom_icons_) {
|
||||
QString custom_icon_path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/icons/%1x%2/%3.png"_s;
|
||||
QString custom_icon_path = StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation) + u"/icons/%1x%2/%3.png"_s;
|
||||
for (int s : std::as_const(sizes)) {
|
||||
QString filename(custom_icon_path.arg(s).arg(s).arg(name));
|
||||
if (QFile::exists(filename)) ret.addFile(filename, QSize(s, s));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2024-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -18,13 +18,26 @@
|
||||
*/
|
||||
|
||||
#include <QSettings>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
Settings::Settings(QObject *parent)
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
: QSettings(QCoreApplication::organizationName().toLower(), QCoreApplication::applicationName().toLower(), parent) {}
|
||||
#else
|
||||
: QSettings(parent) {}
|
||||
#endif
|
||||
|
||||
Settings::Settings(const QSettings::Scope scope, QObject *parent)
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
: QSettings(scope, QCoreApplication::organizationName().toLower(), QCoreApplication::applicationName().toLower(), parent) {}
|
||||
#else
|
||||
: QSettings(scope, parent) {}
|
||||
#endif
|
||||
|
||||
Settings::Settings(const QString &filename, const Format format, QObject *parent)
|
||||
: QSettings(filename, format, parent) {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2024-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -21,14 +21,14 @@
|
||||
#define SETTINGS_H
|
||||
|
||||
#include <QSettings>
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
class Settings : public QSettings {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Settings(QObject *parent = nullptr);
|
||||
explicit Settings(const QSettings::Scope scope, QObject *parent = nullptr);
|
||||
explicit Settings(const QString &filename, const Format format, QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
|
||||
@@ -45,11 +45,11 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QUrl>
|
||||
#include <QIcon>
|
||||
#include <QStandardPaths>
|
||||
#include <QSqlRecord>
|
||||
|
||||
#include <taglib/tstring.h>
|
||||
|
||||
#include "core/standardpaths.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/enginemetadata.h"
|
||||
#include "utilities/strutils.h"
|
||||
@@ -1335,24 +1335,24 @@ QString Song::ImageCacheDir(const Source source) {
|
||||
|
||||
switch (source) {
|
||||
case Source::Collection:
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/collectionalbumcovers"_s;
|
||||
return StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation) + u"/collectionalbumcovers"_s;
|
||||
case Source::Subsonic:
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/subsonicalbumcovers"_s;
|
||||
return StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation) + u"/subsonicalbumcovers"_s;
|
||||
case Source::Tidal:
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/tidalalbumcovers"_s;
|
||||
return StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation) + u"/tidalalbumcovers"_s;
|
||||
case Source::Spotify:
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/spotifyalbumcovers"_s;
|
||||
return StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation) + u"/spotifyalbumcovers"_s;
|
||||
case Source::Qobuz:
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/qobuzalbumcovers"_s;
|
||||
return StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation) + u"/qobuzalbumcovers"_s;
|
||||
case Source::Device:
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/devicealbumcovers"_s;
|
||||
return StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation) + u"/devicealbumcovers"_s;
|
||||
case Source::LocalFile:
|
||||
case Source::CDDA:
|
||||
case Source::Stream:
|
||||
case Source::SomaFM:
|
||||
case Source::RadioParadise:
|
||||
case Source::Unknown:
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/albumcovers"_s;
|
||||
return StandardPaths::WritableLocation(StandardPaths::AppLocalDataLocation) + u"/albumcovers"_s;
|
||||
}
|
||||
|
||||
return QString();
|
||||
|
||||
82
src/core/standardpaths.cpp
Normal file
82
src/core/standardpaths.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include "standardpaths.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
void StandardPaths::AppendOrganizationAndApplication(QString &path) {
|
||||
|
||||
const QString organization_name = QCoreApplication::organizationName().toLower();
|
||||
if (!organization_name.isEmpty()) {
|
||||
path += u'/' + organization_name;
|
||||
}
|
||||
const QString application_name = QCoreApplication::applicationName().toLower();
|
||||
if (!application_name.isEmpty()) {
|
||||
path += u'/' + application_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString StandardPaths::WritableLocation(const StandardLocation type) {
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
switch (type) {
|
||||
case CacheLocation:
|
||||
case GenericCacheLocation:{
|
||||
QString cache_location = qEnvironmentVariable("XDG_CACHE_HOME");
|
||||
if (!cache_location.startsWith(u'/')) {
|
||||
cache_location.clear();
|
||||
}
|
||||
if (cache_location.isEmpty()) {
|
||||
cache_location = QDir::homePath() + "/.cache"_L1;
|
||||
}
|
||||
if (type == QStandardPaths::CacheLocation) {
|
||||
AppendOrganizationAndApplication(cache_location);
|
||||
}
|
||||
return cache_location;
|
||||
}
|
||||
case AppDataLocation:
|
||||
case AppLocalDataLocation:
|
||||
case GenericDataLocation:{
|
||||
QString data_location = qEnvironmentVariable("XDG_DATA_HOME");
|
||||
if (!data_location.startsWith(u'/')) {
|
||||
data_location.clear();
|
||||
}
|
||||
if (data_location.isEmpty()) {
|
||||
data_location = QDir::homePath() + "/.local/share"_L1;
|
||||
}
|
||||
if (type == AppDataLocation || type == AppLocalDataLocation) {
|
||||
AppendOrganizationAndApplication(data_location);
|
||||
}
|
||||
return data_location;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return QStandardPaths::writableLocation(type);
|
||||
|
||||
}
|
||||
36
src/core/standardpaths.h
Normal file
36
src/core/standardpaths.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STANDARDPATHS_H
|
||||
#define STANDARDPATHS_H
|
||||
|
||||
#include <QStandardPaths>
|
||||
|
||||
class StandardPaths : public QStandardPaths {
|
||||
Q_GADGET
|
||||
|
||||
public:
|
||||
static QString WritableLocation(const StandardLocation type);
|
||||
static QString writableLocation(const StandardLocation type) = delete;
|
||||
|
||||
private:
|
||||
static void AppendOrganizationAndApplication(QString &path);
|
||||
};
|
||||
|
||||
#endif // STANDARDPATHS_H
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QCoreApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QIODevice>
|
||||
#include <QMutex>
|
||||
#include <QNetworkDiskCache>
|
||||
@@ -32,6 +31,7 @@
|
||||
#include <QAbstractNetworkCache>
|
||||
#include <QUrl>
|
||||
|
||||
#include "standardpaths.h"
|
||||
#include "threadsafenetworkdiskcache.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
@@ -48,9 +48,9 @@ ThreadSafeNetworkDiskCache::ThreadSafeNetworkDiskCache(QObject *parent) : QAbstr
|
||||
if (!sCache) {
|
||||
sCache = new QNetworkDiskCache;
|
||||
#ifdef Q_OS_WIN32
|
||||
sCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + u"/strawberry/networkcache"_s);
|
||||
sCache->setCacheDirectory(StandardPaths::WritableLocation(StandardPaths::TempLocation) + u"/strawberry/networkcache"_s);
|
||||
#else
|
||||
sCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u"/networkcache"_s);
|
||||
sCache->setCacheDirectory(StandardPaths::WritableLocation(StandardPaths::CacheLocation) + u"/networkcache"_s);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user