1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

DataPaths: Use XDG paths + add Cache path

Also drop support for old deprecated config paths.

Closes #1411
This commit is contained in:
David Rosca 2015-09-28 20:39:10 +02:00
parent 7adc31337b
commit 24de161ad1
6 changed files with 42 additions and 44 deletions

View File

@ -100,37 +100,17 @@ void DataPaths::init()
// Config
#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
// Use %LOCALAPPDATA%/qupzilla as Config path on Windows
QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
// Backwards compatibility
if (dataLocation.isEmpty()) {
dataLocation = QDir::homePath() + QLatin1String("/.config/qupzilla");
}
QDir confPath = QDir(dataLocation);
QDir oldConfPath = QDir(QDir::homePath() + QLatin1String("/.qupzilla"));
if (!oldConfPath.exists()) {
oldConfPath = QDir::homePath() + QLatin1String("/.config/qupzilla");
}
m_paths[Config].append(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
#elif defined(Q_OS_MAC)
QDir confPath = QDir(QDir::homePath() + QLatin1String("/Library/Application Support/QupZilla"));
QDir oldConfPath = QDir(QDir::homePath() + QLatin1String("/.config/qupzilla"));
m_paths[Config].append(QDir::homePath() + QLatin1String("/Library/Application Support/QupZilla"));
#else // Unix
QDir confPath = QDir(QDir::homePath() + QLatin1String("/.config/qupzilla"));
QDir oldConfPath = QDir(QDir::homePath() + QLatin1String("/.qupzilla"));
QString configHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
if (configHome.isEmpty())
configHome = QDir::homePath() + QLatin1String("/.config");
configHome.append(QLatin1String("/qupzilla"));
m_paths[Config].append(configHome);
#endif
if (oldConfPath.exists() && !confPath.exists()) {
m_paths[Config].append(oldConfPath.absolutePath());
qWarning() << "WARNING: Using deprecated configuration path" << oldConfPath.absolutePath();
qWarning() << "WARNING: This path may not be supported in future versions!";
qWarning() << "WARNING: Please move your configuration into" << confPath.absolutePath();
}
else {
m_paths[Config].append(confPath.absolutePath());
}
// Profiles
m_paths[Profiles].append(m_paths[Config].first() + QLatin1String("/profiles"));
@ -161,4 +141,16 @@ void DataPaths::init()
void DataPaths::initCurrentProfile(const QString &profilePath)
{
m_paths[CurrentProfile].append(profilePath);
// Cache
#ifdef Q_OS_UNIX
QString cacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
if (!cacheHome.isEmpty())
m_paths[Cache].append(cacheHome + QLatin1String("/qupzilla"));
#endif
if (m_paths[Cache].isEmpty())
m_paths[Cache].append(m_paths[CurrentProfile].first() + QLatin1String("/cache"));
QDir().mkpath(m_paths[Cache].first());
}

View File

@ -30,10 +30,12 @@ public:
Translations = 1, // $AppData/locale
Themes = 2, // $AppData/themes
Plugins = 3, // $AppData/plugins
Config = 4, // ~/.config/qupzilla or %LOCALAPPDATA%/qupzilla or $AppData/data (portable)
Config = 4, // $XDG_CONFIG_HOME/qupzilla or %LOCALAPPDATA%/qupzilla or $AppData/data (portable)
Profiles = 5, // $Config/profiles
CurrentProfile = 6, // $Profiles/current_profile
Temp = 7 // $Config/tmp
Temp = 7, // $Config/tmp
Cache = 8, // $XDG_CACHE_HOME/qupzilla or $CurrentProfile/cache
LastPath = 9
};
explicit DataPaths();
@ -57,7 +59,7 @@ private:
void init();
void initCurrentProfile(const QString &profilePath);
QStringList m_paths[8];
QStringList m_paths[LastPath];
};
#endif // DATAPATHS_H

View File

@ -903,9 +903,10 @@ void MainApplication::loadSettings()
profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
profile->setPersistentStoragePath(DataPaths::currentProfilePath());
const QString defaultBasePath = QSL("%1/networkcache/").arg(DataPaths::currentProfilePath());
const QString basePath = settings.value("Web-Browser-Settings/CachePath", defaultBasePath).toString();
const QString cachePath = QString("%1/QtWebEngine/").arg(basePath);
QString defaultPath = DataPaths::path(DataPaths::Cache);
if (!defaultPath.startsWith(DataPaths::currentProfilePath()))
defaultPath.append(QLatin1Char('/') + ProfileManager::currentProfile());
const QString &cachePath = settings.value("Web-Browser-Settings/CachePath", defaultPath).toString();
profile->setCachePath(cachePath);
if (isPrivate()) {

View File

@ -124,25 +124,29 @@ bool ProfileManager::removeProfile(const QString &profileName)
return true;
}
QString ProfileManager::currentProfile() const
// static
QString ProfileManager::currentProfile()
{
QString path = DataPaths::currentProfilePath();
return path.mid(path.lastIndexOf(QLatin1Char('/')) + 1);
}
QString ProfileManager::startingProfile() const
// static
QString ProfileManager::startingProfile()
{
QSettings settings(DataPaths::path(DataPaths::Profiles) + QLatin1String("/profiles.ini"), QSettings::IniFormat);
return settings.value(QLatin1String("Profiles/startProfile"), QLatin1String("default")).toString();
}
// static
void ProfileManager::setStartingProfile(const QString &profileName)
{
QSettings settings(DataPaths::path(DataPaths::Profiles) + QLatin1String("/profiles.ini"), QSettings::IniFormat);
settings.setValue(QLatin1String("Profiles/startProfile"), profileName);
}
QStringList ProfileManager::availableProfiles() const
// static
QStringList ProfileManager::availableProfiles()
{
QDir dir(DataPaths::path(DataPaths::Profiles));
return dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);

View File

@ -38,14 +38,14 @@ public:
bool removeProfile(const QString &profileName);
// Name of current profile
QString currentProfile() const;
static QString currentProfile();
// Name of starting profile
QString startingProfile() const;
void setStartingProfile(const QString &profileName);
static QString startingProfile();
static void setStartingProfile(const QString &profileName);
// Names of available profiles
QStringList availableProfiles() const;
static QStringList availableProfiles();
private:
void updateCurrentProfile();

View File

@ -198,12 +198,11 @@ Preferences::Preferences(BrowserWindow* window)
}
// PROFILES
ProfileManager profileManager;
QString startingProfile = profileManager.startingProfile();
ui->activeProfile->setText("<b>" + profileManager.currentProfile() + "</b>");
QString startingProfile = ProfileManager::startingProfile();
ui->activeProfile->setText("<b>" + ProfileManager::currentProfile() + "</b>");
ui->startProfile->addItem(startingProfile);
foreach (const QString &name, profileManager.availableProfiles()) {
foreach (const QString &name, ProfileManager::availableProfiles()) {
if (startingProfile != name) {
ui->startProfile->addItem(name);
}