mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-30 11:04:57 +01:00
First tries on a portable version.
This commit is contained in:
parent
fc78a78afc
commit
acb18cdcde
@ -44,6 +44,8 @@
|
||||
# include "moodbar/moodbarloader.h"
|
||||
#endif
|
||||
|
||||
bool Application::kIsPortable = false;
|
||||
|
||||
Application::Application(QObject* parent)
|
||||
: QObject(parent),
|
||||
tag_reader_client_(NULL),
|
||||
|
@ -52,6 +52,8 @@ class Application : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static bool kIsPortable;
|
||||
|
||||
Application(QObject* parent = NULL);
|
||||
~Application();
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QLatin1Literal>
|
||||
@ -258,8 +259,15 @@ qint64 Song::length_nanosec() const { return d->end_ - d->beginning_; }
|
||||
int Song::bitrate() const { return d->bitrate_; }
|
||||
int Song::samplerate() const { return d->samplerate_; }
|
||||
int Song::directory_id() const { return d->directory_id_; }
|
||||
const QUrl& Song::url() const { return d->url_; }
|
||||
const QString& Song::basefilename() const { return d->basefilename_; }
|
||||
const QUrl& Song::url() const {
|
||||
QUrl base = QUrl::fromLocalFile(QCoreApplication::applicationDirPath());
|
||||
qLog(Debug) << "Url" << d->url_.toLocalFile();
|
||||
qLog(Debug) << "base" << base.toString();
|
||||
qLog(Debug) << "absolute" << base.resolved(d->url_).toString();
|
||||
QUrl res = base.resolved(d->url_);
|
||||
return d->url_;
|
||||
}
|
||||
const QString& Song::basefilename() const { return d->basefilename_; }
|
||||
uint Song::mtime() const { return d->mtime_; }
|
||||
uint Song::ctime() const { return d->ctime_; }
|
||||
int Song::filesize() const { return d->filesize_; }
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <QWidget>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/logging.h"
|
||||
#include "timeconstants.h"
|
||||
|
||||
@ -298,6 +299,9 @@ 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() + "/" + QCoreApplication::organizationName();
|
||||
#else
|
||||
@ -307,6 +311,9 @@ QString GetConfigPath(ConfigPath config) {
|
||||
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) {
|
||||
|
@ -190,7 +190,7 @@ void LibraryBackend::UpdateTotalSongCount() {
|
||||
}
|
||||
|
||||
void LibraryBackend::AddDirectory(const QString& path) {
|
||||
QString canonical_path = QFileInfo(path).canonicalFilePath();
|
||||
QString canonical_path = path; //QFileInfo(path).canonicalFilePath();
|
||||
|
||||
QMutexLocker l(db_->Mutex());
|
||||
QSqlDatabase db(db_->Connect());
|
||||
|
@ -68,7 +68,14 @@ void LibrarySettingsPage::Add() {
|
||||
path = QFileDialog::getExistingDirectory(this, tr("Add directory..."), path);
|
||||
|
||||
if (!path.isNull()) {
|
||||
dialog()->library_directory_model()->AddDirectory(path);
|
||||
if (Application::kIsPortable) {
|
||||
QDir appPath(QCoreApplication::applicationDirPath());
|
||||
QString relativePath = appPath.relativeFilePath(path);
|
||||
qLog(Debug) << "Relative Path" << relativePath;
|
||||
dialog()->library_directory_model()->AddDirectory(relativePath);
|
||||
} else {
|
||||
dialog()->library_directory_model()->AddDirectory(path);
|
||||
}
|
||||
}
|
||||
|
||||
settings.setValue("last_path", path);
|
||||
|
14
src/main.cpp
14
src/main.cpp
@ -225,6 +225,18 @@ void ParseAProto() {
|
||||
message.ParseFromArray(data.constData(), data.size());
|
||||
}
|
||||
|
||||
void CheckPortable() {
|
||||
QFile f(QApplication::applicationDirPath() + QDir::separator() + "data");
|
||||
qLog(Debug) << f.fileName();
|
||||
if (f.exists()) {
|
||||
// We are portable. Set the bool and change the qsettings path
|
||||
Application::kIsPortable = true;
|
||||
|
||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, f.fileName());
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (CrashReporting::SendCrashReport(argc, argv)) {
|
||||
return 0;
|
||||
@ -306,6 +318,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
QtSingleApplication a(argc, argv);
|
||||
|
||||
CheckPortable();
|
||||
|
||||
// A bug in Qt means the wheel_scroll_lines setting gets ignored and replaced
|
||||
// with the default value of 3 in QApplicationPrivate::initialize.
|
||||
{
|
||||
|
@ -50,7 +50,6 @@ RemoteClient::RemoteClient(Application* app, QTcpSocket* client)
|
||||
authenticated_ = !use_auth_code_;
|
||||
}
|
||||
|
||||
|
||||
RemoteClient::~RemoteClient() {
|
||||
client_->close();
|
||||
if (client_->state() == QAbstractSocket::ConnectedState)
|
||||
|
Loading…
x
Reference in New Issue
Block a user