2014-03-09 21:51:42 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
#if QT_VERSION < 0x050000
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#else
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#endif
|
|
|
|
|
2014-03-09 21:51:42 +01:00
|
|
|
Q_GLOBAL_STATIC(DataPaths, qz_data_paths)
|
|
|
|
|
|
|
|
DataPaths::DataPaths()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2014-10-03 02:24:37 +02:00
|
|
|
dir.mkpath(d->m_paths[Config].first());
|
|
|
|
dir.mkpath(d->m_paths[Temp].first());
|
2014-03-09 21:51:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
QString DataPaths::path(DataPaths::Path path)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!qz_data_paths()->m_paths[path].isEmpty());
|
|
|
|
|
|
|
|
return qz_data_paths()->m_paths[path].first();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void DataPaths::clearTempData()
|
|
|
|
{
|
|
|
|
QzTools::removeDir(path(Temp));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataPaths::init()
|
|
|
|
{
|
|
|
|
// AppData
|
|
|
|
#if defined(Q_OS_MAC)
|
2014-03-09 22:17:13 +01:00
|
|
|
m_paths[AppData].append(QApplication::applicationDirPath() + QLatin1String("/../Resources"));
|
2014-03-09 21:51:42 +01:00
|
|
|
#elif defined(Q_OS_UNIX) && !defined(NO_SYSTEM_DATAPATH)
|
2014-03-09 22:17:13 +01:00
|
|
|
m_paths[AppData].append(USE_DATADIR);
|
2014-03-09 21:51:42 +01:00
|
|
|
#else
|
2014-03-09 22:17:13 +01:00
|
|
|
m_paths[AppData].append(QApplication::applicationDirPath());
|
2014-03-09 21:51:42 +01:00
|
|
|
#endif
|
|
|
|
|
2014-03-09 22:17:13 +01:00
|
|
|
m_paths[Translations].append(m_paths[AppData].first() + QLatin1String("/locale"));
|
|
|
|
m_paths[Themes].append(m_paths[AppData].first() + QLatin1String("/themes"));
|
|
|
|
m_paths[Plugins].append(m_paths[AppData].first() + QLatin1String("/plugins"));
|
2014-03-09 21:51:42 +01:00
|
|
|
|
|
|
|
// Config
|
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
|
|
|
|
// Use %LOCALAPPDATA%/qupzilla as Config path on Windows
|
|
|
|
#if QT_VERSION < 0x050000
|
|
|
|
QString dataLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
|
|
#else
|
|
|
|
QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
|
|
|
|
#endif
|
|
|
|
// Backwards compatibility
|
|
|
|
if (dataLocation.isEmpty()) {
|
2014-03-09 22:17:13 +01:00
|
|
|
dataLocation = QDir::homePath() + QLatin1String("/.config/qupzilla");
|
2014-03-09 21:51:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QDir confPath = QDir(dataLocation);
|
2014-04-26 12:22:16 +02:00
|
|
|
QDir oldConfPath = QDir(QDir::homePath() + QLatin1String("/.qupzilla"));
|
2014-03-09 21:51:42 +01:00
|
|
|
|
2014-04-26 12:22:16 +02:00
|
|
|
if (!oldConfPath.exists()) {
|
|
|
|
oldConfPath = QDir::homePath() + QLatin1String("/.config/qupzilla");
|
2014-03-09 21:51:42 +01:00
|
|
|
}
|
2014-04-26 12:22:16 +02:00
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
QDir confPath = QDir(QDir::homePath() + QLatin1String("/Library/Application Support/QupZilla"));
|
|
|
|
QDir oldConfPath = QDir(QDir::homePath() + QLatin1String("/.config/qupzilla"));
|
2014-03-09 21:51:42 +01:00
|
|
|
#else // Unix
|
2014-03-09 22:17:13 +01:00
|
|
|
QDir confPath = QDir(QDir::homePath() + QLatin1String("/.config/qupzilla"));
|
2014-04-26 12:22:16 +02:00
|
|
|
QDir oldConfPath = QDir(QDir::homePath() + QLatin1String("/.qupzilla"));
|
2014-03-09 21:51:42 +01:00
|
|
|
#endif
|
|
|
|
|
2014-04-26 12:22:16 +02:00
|
|
|
if (oldConfPath.exists() && !confPath.exists()) {
|
|
|
|
m_paths[Config].append(oldConfPath.absolutePath());
|
2014-03-09 21:51:42 +01:00
|
|
|
|
2014-04-26 12:22:16 +02:00
|
|
|
qWarning() << "WARNING: Using deprecated configuration path" << oldConfPath.absolutePath();
|
2014-03-09 21:51:42 +01:00
|
|
|
qWarning() << "WARNING: This path may not be supported in future versions!";
|
|
|
|
qWarning() << "WARNING: Please move your configuration into" << confPath.absolutePath();
|
|
|
|
}
|
|
|
|
else {
|
2014-03-09 22:17:13 +01:00
|
|
|
m_paths[Config].append(confPath.absolutePath());
|
2014-03-09 21:51:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Profiles
|
2014-03-09 22:17:13 +01:00
|
|
|
m_paths[Profiles].append(m_paths[Config].first() + QLatin1String("/profiles"));
|
2014-03-09 21:51:42 +01:00
|
|
|
|
|
|
|
// Temp
|
|
|
|
#ifdef Q_OS_UNIX
|
2014-08-31 12:52:01 +02:00
|
|
|
const QByteArray &user = qgetenv("USER");
|
|
|
|
const QString &tempPath = QString(QSL("%1/qupzilla-%2/tmp")).arg(QDir::tempPath(), user.constData());
|
|
|
|
m_paths[Temp].append(tempPath);
|
2014-03-09 21:51:42 +01:00
|
|
|
#else
|
2014-03-09 22:17:13 +01:00
|
|
|
m_paths[Temp].append(m_paths[Config].first() + QLatin1String("/tmp"));
|
2014-10-03 02:34:59 +02:00
|
|
|
#endif
|
2014-10-02 23:04:09 +02:00
|
|
|
|
2014-10-03 09:21:40 +02:00
|
|
|
// Make sure the Config and Temp paths exists
|
|
|
|
QDir dir;
|
|
|
|
dir.mkpath(m_paths[Config].first());
|
|
|
|
dir.mkpath(m_paths[Temp].first());
|
|
|
|
|
2014-03-09 21:51:42 +01:00
|
|
|
// We also allow to load data from Config path
|
2014-03-09 22:17:13 +01:00
|
|
|
m_paths[Translations].append(m_paths[Config].first() + QLatin1String("/locale"));
|
|
|
|
m_paths[Themes].append(m_paths[Config].first() + QLatin1String("/themes"));
|
|
|
|
m_paths[Plugins].append(m_paths[Config].first() + QLatin1String("/plugins"));
|
2014-03-09 21:51:42 +01:00
|
|
|
|
|
|
|
#ifdef USE_LIBPATH
|
2014-03-09 22:17:13 +01:00
|
|
|
m_paths[Plugins].append(QLatin1String(USE_LIBPATH "/qupzilla"));
|
2014-03-09 21:51:42 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataPaths::initCurrentProfile(const QString &profilePath)
|
|
|
|
{
|
|
|
|
m_paths[CurrentProfile].append(profilePath);
|
|
|
|
}
|