Fix paths

- Use QStandardPaths
- Load settings in StatusView widget
- Update about
- Remove redundant code
- Temporary hide missing audiopanorama error as workaround for windows build
This commit is contained in:
Jonas Kvinge
2018-04-06 22:13:11 +02:00
parent 43bf7e3ca8
commit 917b9c39b8
21 changed files with 88 additions and 167 deletions

View File

@@ -22,7 +22,6 @@
#include "database.h"
#include "scopedtransaction.h"
#include "utilities.h"
#include "core/application.h"
#include "core/logging.h"
#include "core/taskmanager.h"
@@ -32,6 +31,7 @@
#include <sqlite3.h>
#include <QCoreApplication>
#include <QStandardPaths>
#include <QDir>
#include <QLibrary>
#include <QLibraryInfo>
@@ -225,7 +225,7 @@ Database::Database(Application *app, QObject *parent, const QString &database_na
connection_id_ = sNextConnectionId++;
}
directory_ = QDir::toNativeSeparators(Utilities::GetConfigPath(Utilities::Path_Root));
directory_ = QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
QMutexLocker l(&mutex_);
Connect();

View File

@@ -120,8 +120,8 @@ int main(int argc, char* argv[]) {
QCoreApplication::setOrganizationDomain("strawbs.org");
// This makes us show up nicely in gnome-volume-control
#if !GLIB_CHECK_VERSION(2, 36, 0)
g_type_init(); // Deprecated in glib 2.36.0
#if !GLIB_CHECK_VERSION(2, 36, 0) // Deprecated in glib 2.36.0
g_type_init();
#endif
g_set_application_name(QCoreApplication::applicationName().toLocal8Bit());
@@ -156,7 +156,7 @@ int main(int argc, char* argv[]) {
#ifdef Q_OS_DARWIN
// Must happen after QCoreApplication::setOrganizationName().
setenv("XDG_CONFIG_HOME", Utilities::GetConfigPath(Utilities::Path_Root).toLocal8Bit().constData(), 1);
setenv("XDG_CONFIG_HOME", QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation).toLocal8Bit().constData(), 1);
#endif
// Output the version, so when people attach log output to bug reports they don't have to tell us which version they're using.

View File

@@ -23,13 +23,14 @@
#include "network.h"
#include <QCoreApplication>
#include <QStandardPaths>
#include <QDir>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>
#include <QNetworkReply>
#include "core/closure.h"
#include "utilities.h"
#include "core/logging.h"
QMutex ThreadSafeNetworkDiskCache::sMutex;
QNetworkDiskCache *ThreadSafeNetworkDiskCache::sCache = nullptr;
@@ -39,7 +40,11 @@ ThreadSafeNetworkDiskCache::ThreadSafeNetworkDiskCache(QObject *parent)
QMutexLocker l(&sMutex);
if (!sCache) {
sCache = new QNetworkDiskCache;
sCache->setCacheDirectory(Utilities::GetConfigPath(Utilities::Path_NetworkCache));
#ifdef Q_OS_WIN32
sCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/strawberry/networkcache");
#else
sCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/networkcache");
#endif
}
}
@@ -93,18 +98,15 @@ QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkR
QByteArray user_agent = QString("%1 %2").arg(QCoreApplication::applicationName(), QCoreApplication::applicationVersion()).toUtf8();
if (request.hasRawHeader("User-Agent")) {
// Append the existing user-agent set by a client collection (such as
// libmygpo-qt).
// Append the existing user-agent set by a client collection (such as libmygpo-qt).
user_agent += " " + request.rawHeader("User-Agent");
}
QNetworkRequest new_request(request);
new_request.setRawHeader("User-Agent", user_agent);
if (op == QNetworkAccessManager::PostOperation &&
!new_request.header(QNetworkRequest::ContentTypeHeader).isValid()) {
new_request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
if (op == QNetworkAccessManager::PostOperation && !new_request.header(QNetworkRequest::ContentTypeHeader).isValid()) {
new_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
}
// Prefer the cache unless the caller has changed the setting already

View File

@@ -87,8 +87,7 @@ QString PrettyTimeDelta(int seconds) {
QString PrettyTime(int seconds) {
// last.fm sometimes gets the track length wrong, so you end up with
// negative times.
// last.fm sometimes gets the track length wrong, so you end up with negative times.
seconds = qAbs(seconds);
int hours = seconds / (60 * 60);
@@ -181,9 +180,7 @@ quint64 FileSystemCapacity(const QString &path) {
return quint64(fs_info.f_blocks) * quint64(fs_info.f_bsize);
#elif defined(Q_OS_WIN32)
_ULARGE_INTEGER ret;
if (GetDiskFreeSpaceEx(
QDir::toNativeSeparators(path).toLocal8Bit().constData(), nullptr,
&ret, nullptr) != 0)
if (GetDiskFreeSpaceEx(QDir::toNativeSeparators(path).toLocal8Bit().constData(), nullptr,&ret, nullptr) != 0)
return ret.QuadPart;
#endif
@@ -199,9 +196,7 @@ quint64 FileSystemFreeSpace(const QString &path) {
return quint64(fs_info.f_bavail) * quint64(fs_info.f_bsize);
#elif defined(Q_OS_WIN32)
_ULARGE_INTEGER ret;
if (GetDiskFreeSpaceEx(
QDir::toNativeSeparators(path).toLocal8Bit().constData(), &ret,
nullptr, nullptr) != 0)
if (GetDiskFreeSpaceEx(QDir::toNativeSeparators(path).toLocal8Bit().constData(), &ret, nullptr, nullptr) != 0)
return ret.QuadPart;
#endif
@@ -346,66 +341,6 @@ QString ColorToRgba(const QColor &c) {
}
QString GetConfigPath(ConfigPath config) {
switch (config) {
case Path_Root: {
if (Application::kIsPortable) {
return QString("%1/data").arg(QCoreApplication::applicationDirPath());
}
#ifdef Q_OS_DARWIN
return mac::GetApplicationSupportPath() + "/strawberry";
#else
return QString("%1/.config/strawberry").arg(QDir::homePath());
#endif
}
break;
case Path_CacheRoot: {
if (Application::kIsPortable) {
return GetConfigPath(Path_Root) + "/cache";
}
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
char *xdg = getenv("XDG_CACHE_HOME");
if (!xdg || !*xdg) {
return QString("%1/.cache/strawberry").arg(QDir::homePath());
}
else {
return QString("%1/strawberry").arg(xdg);
}
#else
return GetConfigPath(Path_Root);
#endif
}
break;
case Path_Icons:
return GetConfigPath(Path_Root) + "/customiconset";
case Path_AlbumCovers:
return GetConfigPath(Path_Root) + "/albumcovers";
case Path_NetworkCache:
return GetConfigPath(Path_CacheRoot) + "/networkcache";
case Path_GstreamerRegistry:
return GetConfigPath(Path_Root) + QString("/gst-registry-%1-bin").arg(QCoreApplication::applicationVersion());
case Path_DefaultMusicCollection:
#ifdef Q_OS_DARWIN
return mac::GetMusicDirectory();
#else
return QDir::homePath();
#endif
default:
qFatal("%s", Q_FUNC_INFO);
return QString::null;
}
}
#ifdef Q_OS_DARWIN
qint32 GetMacVersion() {
@@ -801,8 +736,7 @@ void SetEnv(const char *key, const QString &value) {
void IncreaseFDLimit() {
#ifdef Q_OS_DARWIN
// Bump the soft limit for the number of file descriptors from the default of 256 to
// the maximum (usually 10240).
// Bump the soft limit for the number of file descriptors from the default of 256 to the maximum (usually 10240).
struct rlimit limit;
getrlimit(RLIMIT_NOFILE, &limit);

View File

@@ -126,19 +126,6 @@ void SetEnv(const char *key, const QString &value);
void IncreaseFDLimit();
void CheckPortable();
enum ConfigPath {
Path_Root,
Path_Icons,
Path_AlbumCovers,
Path_NetworkCache,
Path_GstreamerRegistry,
Path_DefaultMusicCollection,
Path_LocalSpotifyBlob,
Path_MoodbarCache,
Path_CacheRoot,
};
QString GetConfigPath(ConfigPath config);
// Returns the minor version of OS X (ie. 6 for Snow Leopard, 7 for Lion).
qint32 GetMacVersion();