diff --git a/src/lib/app/datapaths.cpp b/src/lib/app/datapaths.cpp index 3cee88282..02cf63b00 100644 --- a/src/lib/app/datapaths.cpp +++ b/src/lib/app/datapaths.cpp @@ -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()); } diff --git a/src/lib/app/datapaths.h b/src/lib/app/datapaths.h index bbafeda4d..d63be0e74 100644 --- a/src/lib/app/datapaths.h +++ b/src/lib/app/datapaths.h @@ -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 diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 62e8732bf..a358b9c70 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -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()) { diff --git a/src/lib/app/profilemanager.cpp b/src/lib/app/profilemanager.cpp index dbeb378ef..8c08735ec 100644 --- a/src/lib/app/profilemanager.cpp +++ b/src/lib/app/profilemanager.cpp @@ -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); diff --git a/src/lib/app/profilemanager.h b/src/lib/app/profilemanager.h index 2594c2674..baac6564e 100644 --- a/src/lib/app/profilemanager.h +++ b/src/lib/app/profilemanager.h @@ -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(); diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 8a522f21d..b5f204f69 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -198,12 +198,11 @@ Preferences::Preferences(BrowserWindow* window) } // PROFILES - ProfileManager profileManager; - QString startingProfile = profileManager.startingProfile(); - ui->activeProfile->setText("" + profileManager.currentProfile() + ""); + QString startingProfile = ProfileManager::startingProfile(); + ui->activeProfile->setText("" + ProfileManager::currentProfile() + ""); ui->startProfile->addItem(startingProfile); - foreach (const QString &name, profileManager.availableProfiles()) { + foreach (const QString &name, ProfileManager::availableProfiles()) { if (startingProfile != name) { ui->startProfile->addItem(name); }