1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +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 // Config
#if defined(Q_OS_WIN) || defined(Q_OS_OS2) #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
// Use %LOCALAPPDATA%/qupzilla as Config path on Windows // Use %LOCALAPPDATA%/qupzilla as Config path on Windows
QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation); m_paths[Config].append(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
// 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");
}
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
QDir confPath = QDir(QDir::homePath() + QLatin1String("/Library/Application Support/QupZilla")); m_paths[Config].append(QDir::homePath() + QLatin1String("/Library/Application Support/QupZilla"));
QDir oldConfPath = QDir(QDir::homePath() + QLatin1String("/.config/qupzilla"));
#else // Unix #else // Unix
QDir confPath = QDir(QDir::homePath() + QLatin1String("/.config/qupzilla")); QString configHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
QDir oldConfPath = QDir(QDir::homePath() + QLatin1String("/.qupzilla")); if (configHome.isEmpty())
configHome = QDir::homePath() + QLatin1String("/.config");
configHome.append(QLatin1String("/qupzilla"));
m_paths[Config].append(configHome);
#endif #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 // Profiles
m_paths[Profiles].append(m_paths[Config].first() + QLatin1String("/profiles")); m_paths[Profiles].append(m_paths[Config].first() + QLatin1String("/profiles"));
@ -161,4 +141,16 @@ void DataPaths::init()
void DataPaths::initCurrentProfile(const QString &profilePath) void DataPaths::initCurrentProfile(const QString &profilePath)
{ {
m_paths[CurrentProfile].append(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 Translations = 1, // $AppData/locale
Themes = 2, // $AppData/themes Themes = 2, // $AppData/themes
Plugins = 3, // $AppData/plugins 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 Profiles = 5, // $Config/profiles
CurrentProfile = 6, // $Profiles/current_profile 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(); explicit DataPaths();
@ -57,7 +59,7 @@ private:
void init(); void init();
void initCurrentProfile(const QString &profilePath); void initCurrentProfile(const QString &profilePath);
QStringList m_paths[8]; QStringList m_paths[LastPath];
}; };
#endif // DATAPATHS_H #endif // DATAPATHS_H

View File

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

View File

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

View File

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

View File

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