2014-03-09 21:51:42 +01:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2017-02-10 19:00:58 +01:00
|
|
|
* Copyright (C) 2014-2017 David Rosca <nowrep@gmail.com>
|
2014-03-09 21:51:42 +01:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "datapaths.h"
|
|
|
|
#include "qztools.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDir>
|
|
|
|
|
2014-03-19 12:22:16 +01:00
|
|
|
#include <QStandardPaths>
|
2017-09-18 12:20:28 +02:00
|
|
|
#include <QTemporaryDir>
|
2014-03-19 12:22:16 +01:00
|
|
|
|
2014-03-09 21:51:42 +01:00
|
|
|
Q_GLOBAL_STATIC(DataPaths, qz_data_paths)
|
|
|
|
|
|
|
|
DataPaths::DataPaths()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2017-10-03 09:33:35 +02:00
|
|
|
DataPaths::~DataPaths()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-09 21:51:42 +01:00
|
|
|
// static
|
|
|
|
void DataPaths::setCurrentProfilePath(const QString &profilePath)
|
|
|
|
{
|
|
|
|
qz_data_paths()->initCurrentProfile(profilePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void DataPaths::setPortableVersion()
|
|
|
|
{
|
|
|
|
DataPaths* d = qz_data_paths();
|
|
|
|
d->m_paths[Config] = d->m_paths[AppData];
|
|
|
|
|
|
|
|
d->m_paths[Profiles] = d->m_paths[Config];
|
2014-03-09 22:17:13 +01:00
|
|
|
d->m_paths[Profiles].first().append(QLatin1String("/profiles"));
|
2014-03-09 21:51:42 +01:00
|
|
|
|
|
|
|
d->m_paths[Temp] = d->m_paths[Config];
|
2014-03-09 22:17:13 +01:00
|
|
|
d->m_paths[Temp].first().append(QLatin1String("/tmp"));
|
2014-10-02 23:04:09 +02:00
|
|
|
|
2014-10-03 09:21:40 +02:00
|
|
|
// Make sure the Config and Temp paths exists
|
2014-10-02 23:04:09 +02:00
|
|
|
QDir dir;
|
2015-10-23 11:55:14 +02:00
|
|
|
dir.mkpath(d->m_paths[Config].at(0));
|
|
|
|
dir.mkpath(d->m_paths[Temp].at(0));
|
2014-03-09 21:51:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
QString DataPaths::path(DataPaths::Path path)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!qz_data_paths()->m_paths[path].isEmpty());
|
|
|
|
|
2015-10-23 11:55:14 +02:00
|
|
|
return qz_data_paths()->m_paths[path].at(0);
|
2014-03-09 21:51:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
QStringList DataPaths::allPaths(DataPaths::Path type)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!qz_data_paths()->m_paths[type].isEmpty());
|
|
|
|
|
|
|
|
return qz_data_paths()->m_paths[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
QString DataPaths::currentProfilePath()
|
|
|
|
{
|
|
|
|
return path(CurrentProfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataPaths::init()
|
|
|
|
{
|
2017-09-18 12:20:28 +02:00
|
|
|
#if defined(NO_SYSTEM_DATAPATH)
|
2017-09-09 20:20:57 +02:00
|
|
|
m_paths[AppData].append(QApplication::applicationDirPath());
|
|
|
|
#endif
|
2017-09-18 12:20:28 +02:00
|
|
|
m_paths[AppData].append(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation));
|
2017-09-09 20:20:57 +02:00
|
|
|
|
2017-10-27 14:08:49 +02:00
|
|
|
#if defined(PLUGIN_PATH)
|
|
|
|
m_paths[Plugins].append(QStringLiteral(PLUGIN_PATH));
|
|
|
|
#endif
|
|
|
|
|
2017-09-18 12:20:28 +02:00
|
|
|
for (const QString &location : qAsConst(m_paths[AppData])) {
|
|
|
|
initAssetsIn(location);
|
2017-09-09 20:20:57 +02:00
|
|
|
}
|
2017-08-29 12:35:11 +02:00
|
|
|
|
2017-09-11 14:13:18 +02:00
|
|
|
m_paths[Config].append(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
2015-10-23 11:55:14 +02:00
|
|
|
m_paths[Profiles].append(m_paths[Config].at(0) + QLatin1String("/profiles"));
|
2017-09-18 12:20:28 +02:00
|
|
|
// We also allow to load data from Config path
|
|
|
|
initAssetsIn(m_paths[Config].at(0));
|
2014-03-09 21:51:42 +01:00
|
|
|
|
2017-10-27 14:22:39 +02:00
|
|
|
m_tmpdir.reset(new QTemporaryDir());
|
2017-09-18 12:20:28 +02:00
|
|
|
m_paths[Temp].append(m_tmpdir->path());
|
|
|
|
if (!m_tmpdir->isValid()) {
|
|
|
|
qWarning() << "Failed to create temporary directory" << m_tmpdir->path();
|
|
|
|
}
|
2014-10-02 23:04:09 +02:00
|
|
|
|
2017-09-11 14:13:18 +02:00
|
|
|
m_paths[Cache].append(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
2016-01-25 12:13:43 +01:00
|
|
|
|
2014-10-03 09:21:40 +02:00
|
|
|
// Make sure the Config and Temp paths exists
|
|
|
|
QDir dir;
|
2015-10-23 11:55:14 +02:00
|
|
|
dir.mkpath(m_paths[Config].at(0));
|
|
|
|
dir.mkpath(m_paths[Temp].at(0));
|
2014-03-09 21:51:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataPaths::initCurrentProfile(const QString &profilePath)
|
|
|
|
{
|
|
|
|
m_paths[CurrentProfile].append(profilePath);
|
2015-09-28 20:39:10 +02:00
|
|
|
|
|
|
|
if (m_paths[Cache].isEmpty())
|
2015-10-23 11:55:14 +02:00
|
|
|
m_paths[Cache].append(m_paths[CurrentProfile].at(0) + QLatin1String("/cache"));
|
2015-09-28 20:39:10 +02:00
|
|
|
|
2017-04-07 10:02:27 +02:00
|
|
|
if (m_paths[Sessions].isEmpty())
|
|
|
|
m_paths[Sessions].append(m_paths[CurrentProfile].at(0) + QLatin1String("/sessions"));
|
|
|
|
|
|
|
|
QDir dir;
|
|
|
|
dir.mkpath(m_paths[Cache].at(0));
|
|
|
|
dir.mkpath(m_paths[Sessions].at(0));
|
2014-03-09 21:51:42 +01:00
|
|
|
}
|
2017-09-18 12:20:28 +02:00
|
|
|
|
|
|
|
void DataPaths::initAssetsIn(const QString &path)
|
|
|
|
{
|
|
|
|
m_paths[Translations].append(path + QLatin1String("/locale"));
|
|
|
|
m_paths[Themes].append(path + QLatin1String("/themes"));
|
|
|
|
m_paths[Plugins].append(path + QLatin1String("/plugins"));
|
|
|
|
}
|