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

[DataPaths] Added new class DataPaths

This class holds all paths now (instead of MainApplication)
Renamed ProfileUpdater -> ProfileManager
ProfileManager is now responsible for all operations with profiles
This commit is contained in:
nowrep 2014-03-09 21:51:42 +01:00
parent 985db8a35d
commit 214279e3bb
36 changed files with 849 additions and 618 deletions

View File

@ -19,6 +19,7 @@
#include "adblockdialog.h"
#include "adblocksubscription.h"
#include "adblockblockednetworkreply.h"
#include "datapaths.h"
#include "mainapplication.h"
#include "webpage.h"
#include "qztools.h"
@ -149,7 +150,7 @@ AdBlockSubscription* AdBlockManager::addSubscription(const QString &title, const
}
QString fileName = QzTools::filterCharsFromFilename(title.toLower()) + ".txt";
QString filePath = QzTools::ensureUniqueFilename(mApp->currentProfilePath() + "adblock/" + fileName);
QString filePath = QzTools::ensureUniqueFilename(DataPaths::currentProfilePath() + "adblock/" + fileName);
QByteArray data = QString("Title: %1\nUrl: %2\n[Adblock Plus 1.1.1]").arg(title, url).toLatin1();
@ -221,10 +222,10 @@ void AdBlockManager::load()
return;
}
QDir adblockDir(mApp->currentProfilePath() + "adblock");
QDir adblockDir(DataPaths::currentProfilePath() + "adblock");
// Create if neccessary
if (!adblockDir.exists()) {
QDir(mApp->currentProfilePath()).mkdir("adblock");
QDir(DataPaths::currentProfilePath()).mkdir("adblock");
}
foreach (const QString &fileName, adblockDir.entryList(QStringList("*.txt"), QDir::Files)) {
@ -260,7 +261,7 @@ void AdBlockManager::load()
if (m_subscriptions.isEmpty()) {
AdBlockSubscription* easyList = new AdBlockSubscription(tr("EasyList"), this);
easyList->setUrl(QUrl(ADBLOCK_EASYLIST_URL));
easyList->setFilePath(mApp->currentProfilePath() + "adblock/easylist.txt");
easyList->setFilePath(DataPaths::currentProfilePath() + "adblock/easylist.txt");
connect(easyList, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
m_subscriptions.prepend(easyList);

View File

@ -47,6 +47,7 @@
#include "adblocksearchtree.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "datapaths.h"
#include "qztools.h"
#include "followredirectreply.h"
@ -457,7 +458,7 @@ AdBlockSubscription::~AdBlockSubscription()
AdBlockCustomList::AdBlockCustomList(QObject* parent)
: AdBlockSubscription(tr("Custom Rules"), parent)
{
setFilePath(mApp->currentProfilePath() + "adblock/customlist.txt");
setFilePath(DataPaths::currentProfilePath() + "adblock/customlist.txt");
}
void AdBlockCustomList::saveSubscription()

170
src/lib/app/datapaths.cpp Normal file
View File

@ -0,0 +1,170 @@
/* ============================================================
* 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 <QDebug>
#include <QDir>
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];
d->m_paths[Profiles].first().append(QLatin1String("profiles/"));
d->m_paths[CrashLogs] = d->m_paths[Config];
d->m_paths[CrashLogs].first().append(QLatin1String("crashlogs/"));
d->m_paths[Temp] = d->m_paths[Config];
d->m_paths[Temp].first().append(QLatin1String("tmp/"));
}
// 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()
{
m_paths.reserve(5);
// AppData
#if defined(Q_OS_MAC)
m_paths[AppData].append(QApplication::applicationDirPath() + QLatin1String("../Resources/"));
#elif defined(Q_OS_UNIX) && !defined(NO_SYSTEM_DATAPATH)
m_paths[AppData].append(USE_DATADIR "/");
#else
m_paths[AppData].append(QApplication::applicationDirPath() + QLatin1Char('/'));
#endif
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/"));
// 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()) {
dataLocation = QDir::homePath() + QLatin1String("/.config/qupzilla/");
}
QDir confPath = QDir(dataLocation);
QDir homePath = QDir(QDir::homePath() + QLatin1String("/.qupzilla/"));
if (!homePath.exists()) {
homePath = QDir::homePath() + QLatin1String("/.config/qupzilla/");
}
#else // Unix
QDir confPath = QDir(QDir::homePath() + QLatin1String("/.config/qupzilla/"));
QDir homePath = QDir(QDir::homePath() + QLatin1String("/.qupzilla/"));
#endif
if (homePath.exists() && !confPath.exists()) {
m_paths[Config].append(homePath.absolutePath() + QLatin1Char('/'));
qWarning() << "WARNING: Using deprecated configuration path" << homePath.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() + QLatin1Char('/'));
}
// Make sure the Config path exists
QDir dir;
dir.mkpath(m_paths[Config].first());
// Profiles
m_paths[Profiles].append(m_paths[Config].first() + QLatin1String("profiles/"));
// Crashlogs
m_paths[CrashLogs].append(m_paths[Config].first() + QLatin1String("crashlogs/"));
// Temp
#ifdef Q_OS_UNIX
dir.mkpath(QDir::tempPath() + QLatin1String("/qupzilla/tmp"));
m_paths[Temp].append(QDir::tempPath() + QLatin1String("/qupzilla/tmp/"));
#else
m_paths[Temp].append(m_paths[Config].first() + QLatin1String("tmp/"));
#endif
// We also allow to load data from Config path
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/"));
#ifdef USE_LIBPATH
m_paths[Plugins].append(QLatin1String(USE_LIBPATH "/qupzilla/"));
#else
// FIXME: This should use QUPZILLA_PREFIX
m_paths[Plugins].append(QLatin1String("/usr/lib/qupzilla/"));
#endif
}
void DataPaths::initCurrentProfile(const QString &profilePath)
{
Q_ASSERT(profilePath.endsWith('/'));
m_paths[CurrentProfile].append(profilePath);
}

63
src/lib/app/datapaths.h Normal file
View File

@ -0,0 +1,63 @@
/* ============================================================
* 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/>.
* ============================================================ */
#ifndef DATAPATHS_H
#define DATAPATHS_H
#include <QString>
#include <QHash>
class DataPaths
{
public:
enum Path {
AppData, // /usr/share/qupzilla/ or . or ../Resources/
Translations, // $AppData/locale/
Themes, // $AppData/themes/
Plugins, // $AppData/plugins/
Config, // ~/.config/qupzilla/ or %LOCALAPPDATA%/qupzilla/ or $AppData/data (portable)
Profiles, // $Config/profiles/
CurrentProfile, // $Profiles/current_profile/
CrashLogs, // $Config/crashlogs/
Temp // $Config/tmp/
};
explicit DataPaths();
// Set absolute path of current profile
static void setCurrentProfilePath(const QString &profilePath);
// Set Config path to $AppData/data
static void setPortableVersion();
// Returns main path (Themes -> /usr/share/themes)
static QString path(Path type);
// Returns all paths (Themes -> /usr/share/themes, ~/.config/qupzilla/themes)
static QStringList allPaths(Path type);
// Convenience function for getting CurrentProfile
static QString currentProfilePath();
// Remove Temp dir
static void clearTempData();
private:
void init();
void initCurrentProfile(const QString &profilePath);
QHash<Path, QStringList> m_paths;
};
#endif // DATAPATHS_H

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "mainapplication.h"
#include "datapaths.h"
#include "browserwindow.h"
#include "tabwidget.h"
#include "bookmarkstoolbar.h"
@ -38,7 +39,7 @@
#include "mainapplication.h"
#include "webhistoryinterface.h"
#include "qztools.h"
#include "profileupdater.h"
#include "profilemanager.h"
#include "searchenginesmanager.h"
#include "speeddial.h"
#include "webpage.h"
@ -101,8 +102,7 @@ MainApplication::MainApplication(int &argc, char** argv)
, m_isPortable(false)
, m_isClosing(false)
, m_isRestoring(false)
, m_startingAfterCrash(false)
, m_databaseConnected(false)
, m_isStartingAfterCrash(false)
#if defined(Q_OS_WIN) && !defined(Q_OS_OS2)
, m_registerQAppAssociation(0)
#endif
@ -114,18 +114,8 @@ MainApplication::MainApplication(int &argc, char** argv)
setApplicationName("QupZilla");
setApplicationVersion(Qz::VERSION);
setOrganizationDomain("qupzilla");
#if defined(Q_OS_UNIX) && !defined(NO_SYSTEM_DATAPATH)
DATADIR = USE_DATADIR "/";
#else
DATADIR = qApp->applicationDirPath() + "/";
#endif
#ifdef Q_OS_MAC
DATADIR.append(QLatin1String("../Resources/"));
#endif
setWindowIcon(QIcon(":icons/exeicons/qupzilla-window.png"));
bool noAddons = false;
bool newInstance = false;
QUrl startUrl;
@ -190,50 +180,8 @@ MainApplication::MainApplication(int &argc, char** argv)
if (isPortable()) {
std::cout << "QupZilla: Running in Portable Mode." << std::endl;
PROFILEDIR = DATADIR + "profiles/";
DataPaths::setPortableVersion();
}
else {
#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
// Use %LOCALAPPDATA%/qupzilla as PROFILEDIR on Windows
#if QT_VERSION < 0x050000
QString dataLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#else
QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#endif
if (dataLocation.isEmpty()) {
dataLocation = QDir::homePath() + QLatin1String("/.config/qupzilla/");
}
QDir confPath = QDir(dataLocation);
QDir homePath = QDir(QDir::homePath() + QLatin1String("/.qupzilla/"));
if (!homePath.exists()) {
homePath = QDir::homePath() + QLatin1String("/.config/qupzilla/");
}
#else // Unix
QDir confPath = QDir(QDir::homePath() + QLatin1String("/.config/qupzilla/"));
QDir homePath = QDir(QDir::homePath() + QLatin1String("/.qupzilla/"));
#endif
if (homePath.exists() && !confPath.exists()) {
PROFILEDIR = homePath.absolutePath() + QLatin1Char('/');
qWarning() << "WARNING: Using deprecated configuration path" << homePath.absolutePath();
qWarning() << "WARNING: This path may not be supported in future versions!";
qWarning() << "WARNING: Please move your configuration into" << confPath.absolutePath();
}
else {
PROFILEDIR = confPath.absolutePath() + QLatin1Char('/');
}
}
// Make sure the path exists
QDir dir;
dir.mkpath(PROFILEDIR);
TRANSLATIONSDIR = DATADIR + "locale/";
THEMESDIR = DATADIR + "themes/";
// Don't start single application in private browsing
if (!m_isPrivateSession) {
@ -269,30 +217,15 @@ MainApplication::MainApplication(int &argc, char** argv)
setQuitOnLastWindowClosed(true);
#endif
QSettings::setDefaultFormat(QSettings::IniFormat);
QDesktopServices::setUrlHandler("http", this, "addNewTab");
QDesktopServices::setUrlHandler("ftp", this, "addNewTab");
checkSettingsDir();
ProfileManager profileManager;
profileManager.initConfigDir();
profileManager.initCurrentProfile(startProfile);
QSettings::setDefaultFormat(QSettings::IniFormat);
if (startProfile.isEmpty()) {
QSettings settings(PROFILEDIR + "profiles/profiles.ini", QSettings::IniFormat);
if (settings.value("Profiles/startProfile", "default").toString().contains(QLatin1Char('/'))) {
m_activeProfil = PROFILEDIR + "profiles/default/";
}
else {
m_activeProfil = PROFILEDIR + "profiles/" + settings.value("Profiles/startProfile", "default").toString() + "/";
}
}
else {
m_activeProfil = PROFILEDIR + "profiles/" + startProfile + "/";
}
ProfileUpdater u(m_activeProfil);
u.checkProfile();
connectDatabase();
Settings::createSettings(m_activeProfil + "settings.ini");
Settings::createSettings(DataPaths::currentProfilePath() + QLatin1String("settings.ini"));
m_autoSaver = new AutoSaver(this);
connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveStateSlot()));
@ -314,7 +247,7 @@ MainApplication::MainApplication(int &argc, char** argv)
if (!m_isPrivateSession) {
Settings settings;
m_startingAfterCrash = settings.value("SessionRestore/isRunning", false).toBool();
m_isStartingAfterCrash = settings.value("SessionRestore/isRunning", false).toBool();
int afterLaunch = settings.value("Web-URL-Settings/afterLaunch", 3).toInt();
settings.setValue("SessionRestore/isRunning", true);
@ -328,8 +261,8 @@ MainApplication::MainApplication(int &argc, char** argv)
backupSavedSessions();
if (m_startingAfterCrash || afterLaunch == 3) {
m_restoreManager = new RestoreManager(m_activeProfil + "session.dat");
if (m_isStartingAfterCrash || afterLaunch == 3) {
m_restoreManager = new RestoreManager();
if (!m_restoreManager->isValid()) {
destroyRestoreManager();
}
@ -342,6 +275,16 @@ MainApplication::MainApplication(int &argc, char** argv)
#endif
}
MainApplication::~MainApplication()
{
// Delete all classes that are saving data in destructor
delete m_bookmarks;
#ifdef Q_OS_MAC
delete m_macDockMenu;
#endif
}
void MainApplication::postLaunch()
{
if (m_postLaunchActions.contains(OpenDownloadManager)) {
@ -356,7 +299,7 @@ void MainApplication::postLaunch()
getWindow()->toggleFullScreen();
}
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, m_activeProfil);
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, DataPaths::currentProfilePath());
QWebHistoryInterface::setDefaultInterface(new WebHistoryInterface(this));
connect(this, SIGNAL(messageReceived(QString)), this, SLOT(receiveAppMessage(QString)));
@ -388,7 +331,7 @@ void MainApplication::loadSettings()
settings.beginGroup("Web-Browser-Settings");
if (!m_isPrivateSession) {
m_websettings->enablePersistentStorage(m_activeProfil);
m_websettings->enablePersistentStorage(DataPaths::currentProfilePath());
m_websettings->setAttribute(QWebSettings::LocalStorageEnabled, settings.value("HTML5StorageEnabled", true).toBool());
}
@ -535,7 +478,7 @@ bool MainApplication::isPortable() const
bool MainApplication::isStartingAfterCrash() const
{
return m_startingAfterCrash;
return m_isStartingAfterCrash;
}
int MainApplication::windowCount() const
@ -545,12 +488,12 @@ int MainApplication::windowCount() const
QString MainApplication::currentLanguageFile() const
{
return m_activeLanguage;
return m_currentLanguage;
}
QString MainApplication::currentLanguage() const
{
QString lang = m_activeLanguage;
QString lang = m_currentLanguage;
if (lang.isEmpty()) {
return "en_US";
@ -559,11 +502,6 @@ QString MainApplication::currentLanguage() const
return lang.left(lang.length() - 3);
}
QString MainApplication::currentProfilePath() const
{
return m_activeProfil;
}
void MainApplication::receiveAppMessage(QString message)
{
QWidget* actWin = getWindow();
@ -678,61 +616,25 @@ bool MainApplication::event(QEvent* e)
}
#endif
void MainApplication::connectDatabase()
{
if (m_databaseConnected) {
return;
}
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(m_activeProfil + "browsedata.db");
if (!QFile::exists(m_activeProfil + "browsedata.db")) {
QFile(":data/browsedata.db").copy(m_activeProfil + "browsedata.db");
QFile(m_activeProfil + "browsedata.db").setPermissions(QFile::ReadUser | QFile::WriteUser);
db.setDatabaseName(m_activeProfil + "browsedata.db");
qWarning("Cannot find SQLite database file! Copying and using the defaults!");
}
if (m_isPrivateSession) {
db.setConnectOptions("QSQLITE_OPEN_READONLY");
}
if (!db.open()) {
qWarning("Cannot open SQLite database! Continuing without database....");
}
m_databaseConnected = true;
}
void MainApplication::loadTheme(const QString &name)
{
// Themes are loaded from the following directories:
// 1. Directory "themes" in user profile
// 2. Directory "themes" in root profile directory
// 3. System data path
// > /usr/share/qupzilla/themes on Linux
// > $EXECUTABLE_DIR/themes on Windows
QStringList themePaths;
themePaths << m_activeProfil + "themes/"
<< PROFILEDIR + "themes/"
<< THEMESDIR;
QString activeThemePath;
const QStringList themePaths = DataPaths::allPaths(DataPaths::Themes);
foreach (const QString &path, themePaths) {
const QString theme = path + name + "/";
if (QFile::exists(theme + "main.css")) {
m_activeThemePath = theme;
activeThemePath = theme;
break;
}
}
if (m_activeThemePath.isEmpty()) {
qWarning("Cannot load theme '%s'!", qPrintable(name));
m_activeThemePath = THEMESDIR + DEFAULT_THEME_NAME + "/";
if (activeThemePath.isEmpty()) {
qWarning() << "Cannot load theme " << name;
activeThemePath = DataPaths::path(DataPaths::Themes) + DEFAULT_THEME_NAME + QLatin1Char('/');
}
QFile cssFile(m_activeThemePath + "main.css");
QFile cssFile(activeThemePath + "main.css");
cssFile.open(QFile::ReadOnly);
QString css = cssFile.readAll();
cssFile.close();
@ -742,8 +644,8 @@ void MainApplication::loadTheme(const QString &name)
* should be enough instead of loading special stylesheets
*/
#ifdef Q_OS_UNIX
if (QFile(m_activeThemePath + "linux.css").exists()) {
cssFile.setFileName(m_activeThemePath + "linux.css");
if (QFile(activeThemePath + "linux.css").exists()) {
cssFile.setFileName(activeThemePath + "linux.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
@ -751,8 +653,8 @@ void MainApplication::loadTheme(const QString &name)
#endif
#ifdef Q_OS_MAC
if (QFile(m_activeThemePath + "mac.css").exists()) {
cssFile.setFileName(m_activeThemePath + "mac.css");
if (QFile(activeThemePath + "mac.css").exists()) {
cssFile.setFileName(activeThemePath + "mac.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
@ -760,8 +662,8 @@ void MainApplication::loadTheme(const QString &name)
#endif
#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
if (QFile(m_activeThemePath + "windows.css").exists()) {
cssFile.setFileName(m_activeThemePath + "windows.css");
if (QFile(activeThemePath + "windows.css").exists()) {
cssFile.setFileName(activeThemePath + "windows.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
@ -770,14 +672,14 @@ void MainApplication::loadTheme(const QString &name)
// RTL Support
// Loading 'rtl.css' when layout is right to left!
if (isRightToLeft() && QFile(m_activeThemePath + "rtl.css").exists()) {
cssFile.setFileName(m_activeThemePath + "rtl.css");
if (isRightToLeft() && QFile(activeThemePath + "rtl.css").exists()) {
cssFile.setFileName(activeThemePath + "rtl.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
}
QString relativePath = QDir::current().relativeFilePath(m_activeThemePath);
QString relativePath = QDir::current().relativeFilePath(activeThemePath);
css.replace(QzRegExp("url\\s*\\(\\s*([^\\*:\\);]+)\\s*\\)", Qt::CaseSensitive),
QString("url(%1\\1)").arg(relativePath + "/"));
@ -793,26 +695,39 @@ void MainApplication::translateApp()
file.append(".qm");
}
// If "xx_yy" translation doesn't exists, try to use "xx*" translation
// It can only happen when Language is chosen from system locale
QString dir = DataPaths::path(DataPaths::Translations);
if (!file.isEmpty() && !QFile(TRANSLATIONSDIR + QLatin1String("/") + file).exists()) {
QDir translationsDir(TRANSLATIONSDIR);
QString lang = file.left(2) + QLatin1String("*.qm");
if (!file.isEmpty()) {
const QStringList translationsPaths = DataPaths::allPaths(DataPaths::Translations);
const QStringList translations = translationsDir.entryList(QStringList(lang));
foreach (const QString &path, translationsPaths) {
// If "xx_yy" translation doesn't exists, try to use "xx*" translation
// It can only happen when Language is chosen from system locale
// If no translation can be found, default English will be used
file = translations.isEmpty() ? QString() : translations.first();
if (!QFile(path + file).exists()) {
QDir dir(path);
QString lang = file.left(2) + QLatin1String("*.qm");
const QStringList translations = dir.entryList(QStringList(lang));
// If no translation can be found, default English will be used
file = translations.isEmpty() ? QString() : translations.first();
}
if (QFile(path + file).exists()) {
dir = path;
break;
}
}
}
QTranslator* app = new QTranslator(this);
app->load(file, TRANSLATIONSDIR);
app->load(file, dir);
QTranslator* sys = new QTranslator(this);
sys->load("qt_" + file, TRANSLATIONSDIR);
sys->load("qt_" + file, dir);
m_activeLanguage = file;
m_currentLanguage = file;
installTranslator(app);
installTranslator(sys);
@ -824,7 +739,7 @@ void MainApplication::backupSavedSessions()
// session.dat.old - first backup
// session.dat.old1 - second backup
const QString sessionFile = m_activeProfil + "session.dat";
const QString sessionFile = DataPaths::currentProfilePath() + QLatin1String("session.dat");
if (!QFile::exists(sessionFile)) {
return;
@ -895,12 +810,13 @@ void MainApplication::saveSettings()
m_searchEnginesManager->saveSettings();
m_networkmanager->saveSettings();
m_plugins->shutdown();
clearTempPath();
DataPaths::clearTempData();
qzSettings->saveSettings();
AdBlockManager::instance()->save();
IconProvider::instance()->saveIconsToDatabase();
QFile::remove(currentProfilePath() + "WebpageIcons.db");
QFile::remove(DataPaths::currentProfilePath() + QLatin1String("WebpageIcons.db"));
Settings::syncSettings();
}
@ -947,7 +863,7 @@ NetworkManager* MainApplication::networkManager()
CookieJar* MainApplication::cookieJar()
{
if (!m_cookiejar) {
m_cookiejar = new CookieJar(m_isPrivateSession ? QString() : m_activeProfil, this);
m_cookiejar = new CookieJar(this);
}
return m_cookiejar;
}
@ -968,7 +884,7 @@ PluginProxy* MainApplication::plugins()
Bookmarks* MainApplication::bookmarks()
{
if (!m_bookmarks) {
m_bookmarks = new Bookmarks(m_activeProfil, this);
m_bookmarks = new Bookmarks(this);
}
return m_bookmarks;
}
@ -1001,10 +917,10 @@ QNetworkDiskCache* MainApplication::networkCache()
{
if (!m_networkCache) {
Settings settings;
const QString basePath = settings.value("Web-Browser-Settings/CachePath",
QString("%1networkcache/").arg(m_activeProfil)).toString();
const QString defaultBasePath = QString("%1networkcache/").arg(DataPaths::currentProfilePath());
const QString basePath = settings.value("Web-Browser-Settings/CachePath", defaultBasePath).toString();
const QString cachePath = QString("%1/%2-Qt%3/").arg(basePath, qWebKitVersion(), qVersion());
m_networkCache = new QNetworkDiskCache(this);
m_networkCache->setCacheDirectory(cachePath);
}
@ -1193,7 +1109,7 @@ bool MainApplication::saveStateSlot()
qupzilla_->tabWidget()->savePinnedTabs();
}
QFile file(m_activeProfil + QLatin1String("session.dat"));
QFile file(DataPaths::currentProfilePath() + QLatin1String("session.dat"));
file.open(QIODevice::WriteOnly);
file.write(data);
file.close();
@ -1248,58 +1164,6 @@ bool MainApplication::restoreStateSlot(BrowserWindow* window, RestoreData recove
return true;
}
bool MainApplication::checkSettingsDir()
{
/*
$HOMEDIR
|
.config/qupzilla/
|
profiles/---------------------
| |
default/------------- profiles.ini
| |
browsedata.db bookmarks.json
*/
if (QDir(PROFILEDIR).exists() && QFile(PROFILEDIR + "profiles/profiles.ini").exists()) {
return true;
}
std::cout << "QupZilla: Creating new profile directory" << std::endl;
QDir dir(PROFILEDIR);
if (!dir.exists()) {
dir.mkpath(PROFILEDIR);
}
dir.mkdir("profiles");
dir.cd("profiles");
//.config/qupzilla/profiles
QFile(PROFILEDIR + "profiles/profiles.ini").remove();
QFile(":data/profiles.ini").copy(PROFILEDIR + "profiles/profiles.ini");
QFile(PROFILEDIR + "profiles/profiles.ini").setPermissions(QFile::ReadUser | QFile::WriteUser);
dir.mkdir("default");
dir.cd("default");
//.config/qupzilla/profiles/default
QFile(PROFILEDIR + "profiles/default/browsedata.db").remove();
QFile(":data/browsedata.db").copy(PROFILEDIR + "profiles/default/browsedata.db");
QFile(PROFILEDIR + "profiles/default/browsedata.db").setPermissions(QFile::ReadUser | QFile::WriteUser);
QFile(":data/bookmarks.json").copy(PROFILEDIR + "profiles/default/bookmarks.json");
QFile(PROFILEDIR + "profiles/default/bookmarks.json").setPermissions(QFile::ReadUser | QFile::WriteUser);
QFile versionFile(PROFILEDIR + "profiles/default/version");
versionFile.open(QFile::WriteOnly);
versionFile.write(Qz::VERSION.toUtf8());
versionFile.close();
return dir.isReadable();
}
void MainApplication::destroyRestoreManager()
{
delete m_restoreManager;
@ -1322,38 +1186,3 @@ QString MainApplication::currentStyle() const
{
return m_proxyStyle->baseStyle()->objectName();
}
void MainApplication::clearTempPath()
{
QString path = PROFILEDIR + "tmp/";
QDir dir(path);
if (dir.exists()) {
QzTools::removeDir(path);
}
}
QString MainApplication::tempPath() const
{
QString path = PROFILEDIR + "tmp/";
QDir dir(path);
if (!dir.exists()) {
#ifdef Q_OS_UNIX
// Symlink it to standard temporary path /tmp
QDir().mkpath(QDir::tempPath() + "/qupzilla/tmp");
QFile::remove(PROFILEDIR + "tmp");
QFile::link(QDir::tempPath() + "/qupzilla/tmp/", PROFILEDIR + "tmp");
#else
dir.mkdir(path);
#endif
}
return path;
}
MainApplication::~MainApplication()
{
#ifdef Q_OS_MAC
delete m_macDockMenu;
#endif
}

View File

@ -60,11 +60,6 @@ class QUPZILLA_EXPORT MainApplication : public QtSingleApplication
Q_OBJECT
public:
QString DATADIR;
QString PROFILEDIR;
QString TRANSLATIONSDIR;
QString THEMESDIR;
explicit MainApplication(int &argc, char** argv);
~MainApplication();
@ -84,17 +79,13 @@ public:
int windowCount() const;
QString currentLanguageFile() const;
QString currentLanguage() const;
QString currentProfilePath() const;
bool checkSettingsDir();
void destroyRestoreManager();
void clearTempPath();
ProxyStyle* proxyStyle() const;
void setProxyStyle(ProxyStyle* style);
QString currentStyle() const;
QString tempPath() const;
BrowserWindow* getWindow();
CookieManager* cookieManager();
@ -182,17 +173,14 @@ private:
QList<QPointer<BrowserWindow> > m_mainWindows;
QString m_activeProfil;
QString m_activeLanguage;
QString m_activeThemePath;
QString m_currentLanguage;
bool m_isPrivateSession;
bool m_isPortable;
bool m_isClosing;
bool m_isRestoring;
bool m_startingAfterCrash;
bool m_isStartingAfterCrash;
bool m_databaseConnected;
QList<PostLaunchAction> m_postLaunchActions;
#if defined(Q_OS_WIN) && !defined(Q_OS_OS2)

View File

@ -0,0 +1,350 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-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 "profilemanager.h"
#include "mainapplication.h"
#include "datapaths.h"
#include "updater.h"
#include "qztools.h"
#include <QDir>
#include <QSqlQuery>
#include <QMessageBox>
#include <QSettings>
#include <iostream>
ProfileManager::ProfileManager()
: m_databaseConnected(false)
{
}
void ProfileManager::initConfigDir() const
{
QDir dir(DataPaths::path(DataPaths::Config));
if (dir.exists() && QFile(dir.filePath(QLatin1String("profiles/profiles.ini"))).exists()) {
return;
}
std::cout << "QupZilla: Creating new profile directory" << std::endl;
if (!dir.exists()) {
dir.mkpath(dir.absolutePath());
}
dir.mkdir(QLatin1String("profiles"));
dir.cd(QLatin1String("profiles"));
// $Config/profiles
QFile(dir.filePath(QLatin1String("profiles/profiles.ini"))).remove();
QFile(QLatin1String(":data/profiles.ini")).copy(dir.filePath(QLatin1String("profiles/profiles.ini")));
QFile(dir.filePath(QLatin1String("profiles/profiles.ini"))).setPermissions(QFile::ReadUser | QFile::WriteUser);
dir.mkdir(QLatin1String("default"));
dir.cd(QLatin1String("default"));
// $Config/profiles/default
QFile(dir.filePath(QLatin1String("profiles/default/browsedata.db"))).remove();
QFile(QLatin1String(":data/browsedata.db")).copy(dir.filePath(QLatin1String("profiles/default/browsedata.db")));
QFile(dir.filePath(QLatin1String("profiles/default/browsedata.db"))).setPermissions(QFile::ReadUser | QFile::WriteUser);
QFile(QLatin1String(":data/bookmarks.json")).copy(dir.filePath(QLatin1String("profiles/default/bookmarks.json")));
QFile(dir.filePath(QLatin1String("profiles/default/bookmarks.json"))).setPermissions(QFile::ReadUser | QFile::WriteUser);
QFile versionFile(dir.filePath(QLatin1String("profiles/default/version")));
versionFile.open(QFile::WriteOnly);
versionFile.write(Qz::VERSION.toUtf8());
versionFile.close();
}
void ProfileManager::initCurrentProfile(const QString &profileName)
{
QString profilePath = DataPaths::path(DataPaths::Profiles);
if (profileName.isEmpty()) {
profilePath.append(startingProfile());
}
else {
profilePath.append(profileName);
}
DataPaths::setCurrentProfilePath(profilePath + QLatin1Char('/'));
updateCurrentProfile();
connectDatabase();
}
int ProfileManager::createProfile(const QString &profileName)
{
QDir dir(DataPaths::path(DataPaths::Profiles));
if (QDir(dir.absolutePath() + QLatin1Char('/') + profileName).exists()) {
return -1;
}
if (!dir.mkdir(profileName)) {
return -2;
}
dir.mkdir(profileName);
dir.cd(profileName);
QFile(QLatin1String(":data/browsedata.db")).copy(dir.filePath(QLatin1String("/browsedata.db")));
QFile(dir.filePath(QLatin1String("/browsedata.db"))).setPermissions(QFile::ReadUser | QFile::WriteUser);
QFile versionFile(dir.filePath(QLatin1String("/version")));
versionFile.open(QFile::WriteOnly);
versionFile.write(Qz::VERSION.toUtf8());
versionFile.close();
return 0;
}
bool ProfileManager::removeProfile(const QString &profileName)
{
QDir dir(DataPaths::path(DataPaths::Profiles) + profileName);
if (!dir.exists()) {
return false;
}
QzTools::removeDir(dir.absolutePath());
return true;
}
QString ProfileManager::currentProfile() const
{
//const QString path = DataPaths::currentProfilePath();
//return path.mid(path.lastIndexOf(QLatin1Char('/')) + 1);
QString path = DataPaths::currentProfilePath();
path = path.mid(0, path.size() - 1);
return path.mid(path.lastIndexOf(QLatin1Char('/')) + 1);
}
QString ProfileManager::startingProfile() const
{
QSettings settings(DataPaths::path(DataPaths::Profiles) + QLatin1String("profiles.ini"), QSettings::IniFormat);
return settings.value(QLatin1String("Profiles/startProfile"), QLatin1String("default")).toString();
}
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
{
QDir dir(DataPaths::path(DataPaths::Profiles));
return dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
}
void ProfileManager::updateCurrentProfile()
{
QDir profileDir(DataPaths::currentProfilePath());
if (!profileDir.exists()) {
QDir newDir(profileDir.path().remove(profileDir.dirName()));
newDir.mkdir(profileDir.dirName());
}
QFile versionFile(profileDir.filePath(QLatin1String("version")));
// If file exists, just update the profile to current version
if (versionFile.exists()) {
versionFile.open(QFile::ReadOnly);
QString profileVersion = versionFile.readAll();
versionFile.close();
updateProfile(Qz::VERSION, profileVersion.trimmed());
}
else {
copyDataToProfile();
}
versionFile.open(QFile::WriteOnly);
versionFile.write(Qz::VERSION.toUtf8());
versionFile.close();
}
void ProfileManager::updateProfile(const QString &current, const QString &profile)
{
if (current == profile) {
return;
}
Updater::Version prof(profile);
if (prof == Updater::Version("1.0.0")) {
update100();
return;
}
if (prof == Updater::Version("1.1.0") || prof == Updater::Version("1.1.5") || prof == Updater::Version("1.1.8")) {
update118();
return;
}
if (prof == Updater::Version("1.2.0")) {
update120();
return;
}
if (prof == Updater::Version("1.3.0") || prof == Updater::Version("1.3.1")) {
update130();
return;
}
if (prof >= Updater::Version("1.4.0") && prof <= Updater::Version("1.5.0")) {
update140();
return;
}
// 1.7.0 development version
if (prof >= Updater::Version("1.6.0") && prof < Updater::Version("1.8.0")) {
return;
}
std::cout << "QupZilla: Incompatible profile version detected (" << qPrintable(profile) << "), overwriting profile data..." << std::endl;
copyDataToProfile();
}
void ProfileManager::copyDataToProfile()
{
QDir profileDir(DataPaths::currentProfilePath());
QFile browseData(profileDir.filePath(QLatin1String("browsedata.db")));
if (browseData.exists()) {
const QString browseDataBackup = QzTools::ensureUniqueFilename(profileDir.filePath(QLatin1String("browsedata-backup.db")));
browseData.copy(browseDataBackup);
const QString text = "Incompatible profile version has been detected. To avoid losing your profile data, they were "
"backed up in following file:<br/><br/><b>" + browseDataBackup + "<br/></b>";
QMessageBox::warning(0, "QupZilla: Incompatible profile version", text);
}
browseData.remove();
QFile(QLatin1String(":data/browsedata.db")).copy(profileDir.filePath(QLatin1String("browsedata.db")));
QFile(profileDir.filePath(QLatin1String("browsedata.db"))).setPermissions(QFile::ReadUser | QFile::WriteUser);
// Reconnect database
connectDatabase();
}
void ProfileManager::connectDatabase()
{
const QString dbFile = DataPaths::currentProfilePath() + QLatin1String("browsedata.db");
// Reconnect
if (m_databaseConnected) {
QSqlDatabase::removeDatabase(QLatin1String("qt_sql_default_connection"));
}
QSqlDatabase db = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"));
db.setDatabaseName(dbFile);
if (!QFile::exists(dbFile)) {
qWarning("Cannot find SQLite database file! Copying and using the defaults!");
QFile(":data/browsedata.db").copy(dbFile);
QFile(dbFile).setPermissions(QFile::ReadUser | QFile::WriteUser);
db.setDatabaseName(dbFile);
}
if (mApp->isPrivateSession()) {
db.setConnectOptions("QSQLITE_OPEN_READONLY");
}
if (!db.open()) {
qWarning("Cannot open SQLite database! Continuing without database....");
}
m_databaseConnected = true;
}
void ProfileManager::update100()
{
std::cout << "QupZilla: Upgrading profile version from 1.0.0..." << std::endl;
connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE autofill ADD COLUMN last_used NUMERIC");
query.exec("UPDATE autofill SET last_used=0");
update118();
}
void ProfileManager::update118()
{
std::cout << "QupZilla: Upgrading profile version from 1.1.8..." << std::endl;
connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE folders ADD COLUMN parent TEXT");
update120();
}
void ProfileManager::update120()
{
std::cout << "QupZilla: Upgrading profile version from 1.2.0..." << std::endl;
connectDatabase();
QSqlDatabase db = QSqlDatabase::database();
db.transaction();
// This is actually just renaming bookmarks.toolbar_position to bookmarks.position
QSqlQuery query;
query.exec("ALTER TABLE bookmarks RENAME TO tmp_bookmarks");
query.exec("CREATE TABLE bookmarks (icon TEXT, folder TEXT, id INTEGER PRIMARY KEY, title VARCHAR(200), url VARCHAR(200), position NUMERIC)");
query.exec("INSERT INTO bookmarks(icon, folder, id, title, url, position)"
"SELECT icon, folder, id, title, url, toolbar_position FROM tmp_bookmarks");
query.exec("DROP TABLE tmp_bookmarks");
query.exec("CREATE INDEX bookmarksTitle ON bookmarks(title ASC)");
query.exec("CREATE INDEX bookmarksUrl ON bookmarks(url ASC)");
db.commit();
update130();
}
void ProfileManager::update130()
{
std::cout << "QupZilla: Upgrading profile version from 1.3.0..." << std::endl;
connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE bookmarks ADD COLUMN keyword TEXT");
update140();
}
void ProfileManager::update140()
{
std::cout << "QupZilla: Upgrading profile version from 1.4.0..." << std::endl;
connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE search_engines ADD COLUMN postData TEXT");
}

View File

@ -15,30 +15,52 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef PROFILEUPDATER_H
#define PROFILEUPDATER_H
#ifndef PROFILEMANAGER_H
#define PROFILEMANAGER_H
#include <QString>
#include "qzcommon.h"
class ProfileUpdater
class ProfileManager
{
public:
explicit ProfileUpdater(const QString &profilePath);
void checkProfile();
explicit ProfileManager();
// Make sure the config dir exists and have correct structure
void initConfigDir() const;
// Set current profile name (from profiles.ini) and ensure dir exists with correct structure
void initCurrentProfile(const QString &profileName);
// Return 0 on success, -1 profile already exists, -2 cannot create directory
int createProfile(const QString &profileName);
// Return false on error (profile does not exists)
bool removeProfile(const QString &profileName);
// Name of current profile
QString currentProfile() const;
// Name of starting profile
QString startingProfile() const;
void setStartingProfile(const QString &profileName);
// Names of available profiles
QStringList availableProfiles() const;
private:
void updateCurrentProfile();
void updateProfile(const QString &current, const QString &profile);
void copyDataToProfile();
void connectDatabase();
void update100();
void update118();
void update120();
void update130();
void update140();
QString m_profilePath;
bool m_databaseConnected;
};
#endif // PROFILEUPDATER_H
#endif // PROFILEMANAGER_H

View File

@ -1,191 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-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 "profileupdater.h"
#include "browserwindow.h"
#include "updater.h"
#include "qztools.h"
#include "mainapplication.h"
#include <QDir>
#include <QSqlQuery>
#include <QMessageBox>
#include <iostream>
ProfileUpdater::ProfileUpdater(const QString &profilePath)
: m_profilePath(profilePath)
{
}
void ProfileUpdater::checkProfile()
{
QDir profileDir(m_profilePath);
if (!profileDir.exists()) {
QDir newDir(profileDir.path().remove(profileDir.dirName()));
newDir.mkdir(profileDir.dirName());
}
QFile versionFile(m_profilePath + "version");
if (versionFile.exists()) {
versionFile.open(QFile::ReadOnly);
QString profileVersion = versionFile.readAll();
versionFile.close();
versionFile.remove();
updateProfile(Qz::VERSION, profileVersion.trimmed());
}
else {
copyDataToProfile();
}
versionFile.open(QFile::WriteOnly);
versionFile.write(Qz::VERSION.toUtf8());
versionFile.close();
}
void ProfileUpdater::updateProfile(const QString &current, const QString &profile)
{
if (current == profile) {
return;
}
Updater::Version prof(profile);
if (prof == Updater::Version("1.0.0")) {
update100();
return;
}
if (prof == Updater::Version("1.1.0")
|| prof == Updater::Version("1.1.5")
|| prof == Updater::Version("1.1.8")) {
update118();
return;
}
if (prof == Updater::Version("1.2.0")) {
update120();
return;
}
if (prof == Updater::Version("1.3.0")
|| prof == Updater::Version("1.3.1")) {
update130();
return;
}
if (prof >= Updater::Version("1.4.0") && prof <= Updater::Version("1.5.0")) {
update140();
return;
}
// 1.7.0 development version
if (prof >= Updater::Version("1.6.0") && prof < Updater::Version("1.8.0")) {
return;
}
std::cout << "QupZilla: Incompatible profile version detected (" << qPrintable(prof.versionString()) << "), overwriting profile data..." << std::endl;
copyDataToProfile();
}
void ProfileUpdater::copyDataToProfile()
{
QDir profileDir(m_profilePath);
profileDir.mkdir("certificates");
QFile browseData(m_profilePath + "browsedata.db");
if (browseData.exists()) {
const QString browseDataBackup = QzTools::ensureUniqueFilename(m_profilePath + "browsedata-backup.db");
browseData.copy(browseDataBackup);
const QString text = "Incompatible profile version has been detected. To avoid losing your profile data, they were "
"backed up in following file:<br/><br/><b>" + browseDataBackup + "<br/></b>";
QMessageBox::warning(0, "QupZilla: Incompatible profile version", text);
}
browseData.remove();
QFile(":data/browsedata.db").copy(m_profilePath + "browsedata.db");
QFile(m_profilePath + "browsedata.db").setPermissions(QFile::ReadUser | QFile::WriteUser);
}
void ProfileUpdater::update100()
{
std::cout << "QupZilla: Upgrading profile version from 1.0.0..." << std::endl;
mApp->connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE autofill ADD COLUMN last_used NUMERIC");
query.exec("UPDATE autofill SET last_used=0");
update118();
}
void ProfileUpdater::update118()
{
std::cout << "QupZilla: Upgrading profile version from 1.1.8..." << std::endl;
mApp->connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE folders ADD COLUMN parent TEXT");
update120();
}
void ProfileUpdater::update120()
{
std::cout << "QupZilla: Upgrading profile version from 1.2.0..." << std::endl;
mApp->connectDatabase();
QSqlDatabase db = QSqlDatabase::database();
db.transaction();
// This is actually just renaming bookmarks.toolbar_position to bookmarks.position
QSqlQuery query;
query.exec("ALTER TABLE bookmarks RENAME TO tmp_bookmarks");
query.exec("CREATE TABLE bookmarks (icon TEXT, folder TEXT, id INTEGER PRIMARY KEY, title VARCHAR(200), url VARCHAR(200), position NUMERIC)");
query.exec("INSERT INTO bookmarks(icon, folder, id, title, url, position)"
"SELECT icon, folder, id, title, url, toolbar_position FROM tmp_bookmarks");
query.exec("DROP TABLE tmp_bookmarks");
query.exec("CREATE INDEX bookmarksTitle ON bookmarks(title ASC)");
query.exec("CREATE INDEX bookmarksUrl ON bookmarks(url ASC)");
db.commit();
update130();
}
void ProfileUpdater::update130()
{
std::cout << "QupZilla: Upgrading profile version from 1.3.0..." << std::endl;
mApp->connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE bookmarks ADD COLUMN keyword TEXT");
update140();
}
void ProfileUpdater::update140()
{
std::cout << "QupZilla: Upgrading profile version from 1.4.0..." << std::endl;
mApp->connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE search_engines ADD COLUMN postData TEXT");
}

View File

@ -20,6 +20,7 @@
#include "bookmarksmodel.h"
#include "bookmarkstools.h"
#include "autosaver.h"
#include "datapaths.h"
#include "settings.h"
#include "qztools.h"
#include "json.h"
@ -27,16 +28,15 @@
#include <QDebug>
#include <QFile>
Bookmarks::Bookmarks(const QString &profilePath, QObject* parent)
Bookmarks::Bookmarks(QObject* parent)
: QObject(parent)
, m_autoSaver(0)
, m_profilePath(profilePath)
{
init();
loadSettings();
m_autoSaver = new AutoSaver(this);
connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveSettings()));
init();
loadSettings();
}
Bookmarks::~Bookmarks()
@ -209,7 +209,7 @@ void Bookmarks::init()
void Bookmarks::loadBookmarks()
{
const QString bookmarksFile = m_profilePath + QLatin1String("/bookmarks.json");
const QString bookmarksFile = DataPaths::currentProfilePath() + QLatin1String("/bookmarks.json");
const QString backupFile = bookmarksFile + QLatin1String(".old");
QFile file(bookmarksFile);
@ -275,7 +275,7 @@ void Bookmarks::saveBookmarks()
return;
}
QFile file(m_profilePath + QLatin1String("/bookmarks.json"));
QFile file(DataPaths::currentProfilePath() + QLatin1String("/bookmarks.json"));
if (!file.open(QFile::WriteOnly)) {
qWarning() << "Bookmarks::saveBookmarks() Error opening bookmarks file for writing!";

View File

@ -33,7 +33,7 @@ class QUPZILLA_EXPORT Bookmarks : public QObject
{
Q_OBJECT
public:
explicit Bookmarks(const QString &profilePath, QObject* parent = 0);
explicit Bookmarks(QObject* parent = 0);
~Bookmarks();
void loadSettings();
@ -98,7 +98,6 @@ private:
BookmarksModel* m_model;
AutoSaver* m_autoSaver;
QString m_profilePath;
bool m_showOnlyIconsInToolbar;
};

View File

@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "cookiejar.h"
#include "autosaver.h"
#include "mainapplication.h"
#include "datapaths.h"
#include "autosaver.h"
#include "settings.h"
#include "qztools.h"
@ -28,16 +29,15 @@
//#define COOKIE_DEBUG
CookieJar::CookieJar(const QString &profilePath, QObject* parent)
CookieJar::CookieJar(QObject* parent)
: QNetworkCookieJar(parent)
, m_autoSaver(0)
, m_profilePath(profilePath)
{
loadSettings();
restoreCookies();
m_autoSaver = new AutoSaver(this);
connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveCookies()));
loadSettings();
restoreCookies();
}
CookieJar::~CookieJar()
@ -111,11 +111,11 @@ void CookieJar::clearCookies()
void CookieJar::restoreCookies()
{
if (m_profilePath.isEmpty()) {
if (mApp->isPrivateSession()) {
return;
}
const QString cookiesFile = m_profilePath + QLatin1String("cookies.dat");
const QString cookiesFile = DataPaths::currentProfilePath() + QLatin1String("cookies.dat");
QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> restoredCookies;
@ -147,7 +147,7 @@ void CookieJar::restoreCookies()
void CookieJar::saveCookies()
{
if (m_profilePath.isEmpty()) {
if (mApp->isPrivateSession()) {
return;
}
@ -165,7 +165,7 @@ void CookieJar::saveCookies()
}
}
QFile file(m_profilePath + QLatin1String("cookies.dat"));
QFile file(DataPaths::currentProfilePath() + QLatin1String("cookies.dat"));
file.open(QIODevice::WriteOnly);
QDataStream stream(&file);
int count = cookies.count();

View File

@ -31,8 +31,7 @@ class QUPZILLA_EXPORT CookieJar : public QNetworkCookieJar
Q_OBJECT
public:
// Passing empty profilePath will create empty CookieJar (for Private Session)
explicit CookieJar(const QString &profilePath, QObject* parent = 0);
explicit CookieJar(QObject* parent = 0);
~CookieJar();
void loadSettings();
@ -65,7 +64,6 @@ private:
QStringList m_blacklist;
AutoSaver* m_autoSaver;
QString m_profilePath;
};
#endif // COOKIEJAR_H

View File

@ -17,7 +17,7 @@
* ============================================================ */
#include "desktopnotificationsfactory.h"
#include "desktopnotification.h"
#include "mainapplication.h"
#include "datapaths.h"
#include "settings.h"
#include <QFile>
@ -79,7 +79,7 @@ void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QS
break;
case DesktopNative:
#if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS)
QFile tmp(mApp->tempPath() + "/qupzilla_notif.png");
QFile tmp(DataPaths::path(DataPaths::Temp) + QLatin1String("/qupzilla_notif.png"));
tmp.open(QFile::WriteOnly);
icon.save(tmp.fileName());
@ -102,7 +102,7 @@ void DesktopNotificationsFactory::showNotification(const QPixmap &icon, const QS
void DesktopNotificationsFactory::nativeNotificationPreview()
{
#if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS)
QFile tmp(mApp->tempPath() + "/qupzilla_notif.png");
QFile tmp(DataPaths::path(DataPaths::Temp) + "/qupzilla_notif.png");
tmp.open(QFile::WriteOnly);
QPixmap(":icons/preferences/dialog-question.png").save(tmp.fileName());

View File

@ -24,6 +24,7 @@
#include "downloaditem.h"
#include "downloadmanager.h"
#include "qztools.h"
#include "datapaths.h"
#include "settings.h"
#include "qzregexp.h"
@ -71,7 +72,7 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, const Do
m_reply = reply;
QFileInfo fileInfo(m_h_fileName);
QTemporaryFile tempFile(mApp->tempPath() + "/XXXXXX." + fileInfo.suffix());
QTemporaryFile tempFile(DataPaths::path(DataPaths::Temp) + "/XXXXXX." + fileInfo.suffix());
tempFile.open();
tempFile.write(m_reply->peek(1024 * 1024));
QFileInfo tempInfo(tempFile.fileName());
@ -256,7 +257,7 @@ void DownloadFileHelper::optionsDialogAccepted(int finish)
}
}
else {
fileNameChoosed(mApp->tempPath() + QLatin1Char('/') + m_h_fileName, true);
fileNameChoosed(DataPaths::path(DataPaths::Temp) + QLatin1Char('/') + m_h_fileName, true);
}
}
@ -284,7 +285,7 @@ void DownloadFileHelper::fileNameChoosed(const QString &name, bool fileNameAutoG
m_fileName = QzTools::ensureUniqueFilename(m_fileName);
}
if (!m_path.contains(mApp->tempPath())) {
if (!m_path.contains(DataPaths::path(DataPaths::Temp))) {
m_lastDownloadPath = m_path;
}

View File

@ -153,7 +153,6 @@ SOURCES += \
downloads/downloadfilehelper.cpp \
tools/certificateinfowidget.cpp \
webview/webinspectordockwidget.cpp \
app/profileupdater.cpp \
preferences/acceptlanguage.cpp \
opensearch/opensearchreader.cpp \
opensearch/opensearchengine.cpp \
@ -258,7 +257,9 @@ SOURCES += \
bookmarks/bookmarksexport/bookmarksexportdialog.cpp \
bookmarks/bookmarksexport/htmlexporter.cpp \
app/browserwindow.cpp \
history/historymenu.cpp
history/historymenu.cpp \
app/datapaths.cpp \
app/profilemanager.cpp
HEADERS += \
@ -348,7 +349,6 @@ HEADERS += \
tools/certificateinfowidget.h \
webview/webinspectordockwidget.h \
3rdparty/msvc2008.h \
app/profileupdater.h \
preferences/acceptlanguage.h \
opensearch/opensearchreader.h \
opensearch/opensearchengine.h \
@ -457,7 +457,9 @@ HEADERS += \
bookmarks/bookmarksexport/htmlexporter.h \
app/browserwindow.h \
app/qzcommon.h \
history/historymenu.h
history/historymenu.h \
app/datapaths.h \
app/profilemanager.h
FORMS += \
preferences/autofillmanager.ui \

View File

@ -19,6 +19,7 @@
#include "mainapplication.h"
#include "networkmanager.h"
#include "browserwindow.h"
#include "datapaths.h"
#include "qztools.h"
#include <QTimer>
@ -34,9 +35,9 @@ CaBundleUpdater::CaBundleUpdater(NetworkManager* manager, QObject* parent)
, m_reply(0)
, m_latestBundleVersion(0)
{
m_bundleVersionFileName = mApp->PROFILEDIR + "certificates/bundle_version";
m_bundleFileName = mApp->PROFILEDIR + "certificates/ca-bundle.crt";
m_lastUpdateFileName = mApp->PROFILEDIR + "certificates/last_update";
m_bundleVersionFileName = DataPaths::path(DataPaths::Config) + "certificates/bundle_version";
m_bundleFileName = DataPaths::path(DataPaths::Config) + "certificates/ca-bundle.crt";
m_lastUpdateFileName = DataPaths::path(DataPaths::Config) + "certificates/last_update";
int updateTime = 30 * 1000;

View File

@ -30,6 +30,7 @@
#include "acceptlanguage.h"
#include "cabundleupdater.h"
#include "settings.h"
#include "datapaths.h"
#include "passwordmanager.h"
#include "sslerrordialog.h"
#include "schemehandlers/adblockschemehandler.h"
@ -111,13 +112,13 @@ void NetworkManager::loadSettings()
m_acceptLanguage = AcceptLanguage::generateHeader(settings.value("Language/acceptLanguage", AcceptLanguage::defaultLanguage()).toStringList());
#if defined(Q_OS_WIN) || defined(Q_OS_HAIKU) || defined(Q_OS_OS2)
QString certDir = mApp->PROFILEDIR + "certificates";
QString certDir = DataPaths::currentProfilePath() + "certificates";
QString bundlePath = certDir + "/ca-bundle.crt";
QString bundleVersionPath = certDir + "/bundle_version";
if (!QDir(certDir).exists()) {
QDir dir(mApp->PROFILEDIR);
dir.mkdir("certificates");
QDir dir;
dir.mkdir(certDir);
}
if (!QFile::exists(bundlePath)) {
@ -593,7 +594,7 @@ void NetworkManager::removeLocalCertificate(const QSslCertificate &cert)
// Delete cert file from profile
bool deleted = false;
QDirIterator it(mApp->currentProfilePath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
QDirIterator it(DataPaths::currentProfilePath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
while (it.hasNext()) {
const QString filePath = it.next();
const QList<QSslCertificate> &certs = QSslCertificate::fromPath(filePath);
@ -627,13 +628,13 @@ void NetworkManager::addLocalCertificate(const QSslCertificate &cert)
m_localCerts.append(cert);
QSslSocket::addDefaultCaCertificate(cert);
QDir dir(mApp->currentProfilePath());
QDir dir(DataPaths::currentProfilePath());
if (!dir.exists("certificates")) {
dir.mkdir("certificates");
}
QString certFileName = fileNameForCert(cert);
QString fileName = QzTools::ensureUniqueFilename(mApp->currentProfilePath() + "certificates/" + certFileName);
QString fileName = QzTools::ensureUniqueFilename(DataPaths::currentProfilePath() + "certificates/" + certFileName);
QFile file(fileName);
if (file.open(QFile::WriteOnly)) {
@ -725,7 +726,7 @@ void NetworkManager::loadCertificates()
}
// Local Certificates
#ifdef Q_OS_WIN
QDirIterator it_(mApp->currentProfilePath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
QDirIterator it_(DataPaths::currentProfilePath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
while (it_.hasNext()) {
QString filePath = it_.next();
if (!filePath.endsWith(QLatin1String(".crt"))) {
@ -738,7 +739,7 @@ void NetworkManager::loadCertificates()
}
}
#else
m_localCerts = QSslCertificate::fromPath(mApp->currentProfilePath() + "certificates/*.crt", QSsl::Pem, QRegExp::Wildcard);
m_localCerts = QSslCertificate::fromPath(DataPaths::currentProfilePath() + "certificates/*.crt", QSsl::Pem, QRegExp::Wildcard);
#endif
QSslSocket::setDefaultCaCertificates(m_caCerts + m_localCerts);

View File

@ -21,6 +21,7 @@
#include "networkmanager.h"
#include "followredirectreply.h"
#include "settings.h"
#include "datapaths.h"
#include "qztools.h"
#include <QNetworkProxy>
@ -98,7 +99,7 @@ void PacManager::replyFinished()
m_reply->deleteLater();
m_reply = 0;
QFile file(mApp->currentProfilePath() + "proxy.pac");
QFile file(DataPaths::currentProfilePath() + "proxy.pac");
if (!file.open(QFile::WriteOnly)) {
qWarning() << "PacManager: Cannot open PAC file for writing" << file.fileName();
@ -117,7 +118,7 @@ void PacManager::reloadScript()
m_pacrunner = new ProxyAutoConfig(this);
}
QFile file(m_url.scheme() == QLatin1String("file") ? m_url.path() : mApp->currentProfilePath() + "proxy.pac");
QFile file(m_url.scheme() == QLatin1String("file") ? m_url.path() : DataPaths::currentProfilePath() + "proxy.pac");
if (!file.open(QFile::ReadOnly)) {
qWarning() << "PacManager: Cannot open PAC file for reading" << file.fileName();

View File

@ -25,6 +25,7 @@
#include "pluginproxy.h"
#include "plugininterface.h"
#include "settings.h"
#include "datapaths.h"
#include "iconprovider.h"
#include <QTextStream>
@ -395,13 +396,13 @@ QString QupZillaSchemeReply::configPage()
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Platform"), QzTools::operatingSystem()));
cPage.replace(QLatin1String("%PATHS-TEXT%"),
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Profile"), mApp->currentProfilePath()) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Settings"), mApp->currentProfilePath() + "settings.ini") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Saved session"), mApp->currentProfilePath() + "session.dat") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Pinned tabs"), mApp->currentProfilePath() + "pinnedtabs.dat") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Data"), mApp->DATADIR) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Themes"), mApp->THEMESDIR) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Translations"), mApp->TRANSLATIONSDIR));
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Profile"), DataPaths::currentProfilePath()) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Settings"), DataPaths::currentProfilePath() + "settings.ini") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Saved session"), DataPaths::currentProfilePath() + "session.dat") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Pinned tabs"), DataPaths::currentProfilePath() + "pinnedtabs.dat") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Data"), DataPaths::path(DataPaths::AppData)) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Themes"), DataPaths::path(DataPaths::Themes)) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Translations"), DataPaths::path(DataPaths::Translations)));
#ifdef QUPZILLA_DEBUG_BUILD
QString debugBuild = tr("<b>Enabled</b>");

View File

@ -21,6 +21,7 @@
#include "cookiejar.h"
#include "history.h"
#include "settings.h"
#include "datapaths.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "clickablelabel.h"
@ -65,14 +66,14 @@ void ClearPrivateData::historyClicked(bool state)
void ClearPrivateData::clearLocalStorage()
{
const QString profile = mApp->currentProfilePath();
const QString profile = DataPaths::currentProfilePath();
QzTools::removeDir(profile + "LocalStorage");
}
void ClearPrivateData::clearWebDatabases()
{
const QString profile = mApp->currentProfilePath();
const QString profile = DataPaths::currentProfilePath();
QWebDatabase::removeAllDatabases();
QzTools::removeDir(profile + "Databases");
@ -83,7 +84,7 @@ void ClearPrivateData::clearCache()
mApp->networkCache()->clear();
mApp->webSettings()->clearMemoryCaches();
QFile::remove(mApp->currentProfilePath() + "ApplicationCache.db");
QFile::remove(DataPaths::currentProfilePath() + "ApplicationCache.db");
}
void ClearPrivateData::clearIcons()
@ -174,7 +175,7 @@ void ClearPrivateData::optimizeDb()
{
mApp->setOverrideCursor(Qt::WaitCursor);
QString profilePath = mApp->currentProfilePath();
QString profilePath = DataPaths::currentProfilePath();
QString sizeBefore = QzTools::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());
mApp->history()->optimizeHistory();

View File

@ -20,6 +20,7 @@
#include "mainapplication.h"
#include "speeddial.h"
#include "settings.h"
#include "datapaths.h"
#include <iostream>
#include <QPluginLoader>
@ -124,7 +125,7 @@ void Plugins::loadPlugins()
return;
}
QDir settingsDir(mApp->currentProfilePath() + "extensions/");
QDir settingsDir(DataPaths::currentProfilePath() + "extensions/");
if (!settingsDir.exists()) {
settingsDir.mkdir(settingsDir.absolutePath());
}
@ -164,23 +165,14 @@ void Plugins::loadAvailablePlugins()
m_pluginsLoaded = true;
QStringList dirs;
dirs << mApp->DATADIR + "plugins/";
QStringList dirs = DataPaths::allPaths(DataPaths::Plugins);
// Portable build: Load only plugins from DATADIR/plugins/ directory.
// Loaded plugins are saved with relative path, instead of absolute for
// normal build.
if (!mApp->isPortable()) {
dirs
#if defined(Q_OS_UNIX) && !defined(NO_SYSTEM_DATAPATH)
#ifdef USE_LIBPATH
<< USE_LIBPATH "/qupzilla/"
#else
<< "/usr/lib/qupzilla/"
#endif
#endif
<< mApp->PROFILEDIR + "plugins/";
if (mApp->isPortable()) {
dirs = QStringList(DataPaths::path(DataPaths::Plugins));
}
foreach (const QString &dir, dirs) {
@ -221,7 +213,7 @@ PluginInterface* Plugins::initPlugin(PluginInterface::InitState state, PluginInt
return 0;
}
interface->init(state, mApp->currentProfilePath() + "extensions/");
interface->init(state, DataPaths::currentProfilePath() + "extensions/");
if (!interface->testPlugin()) {
interface->unload();

View File

@ -17,10 +17,10 @@
* ============================================================ */
#include "spellcheckdialog.h"
#include "ui_spellcheckdialog.h"
#include "datapaths.h"
#include "settings.h"
#include "speller.h"
#include "qztools.h"
#include "mainapplication.h"
#include <QFile>
#include <QTextStream>
@ -37,7 +37,7 @@ SpellCheckDialog::SpellCheckDialog(QWidget* parent)
ui->dictPath->setText(Speller::instance()->dictionaryPath());
QFile file(mApp->currentProfilePath() + "userdictionary.txt");
QFile file(DataPaths::currentProfilePath() + "userdictionary.txt");
if (!file.open(QFile::ReadOnly)) {
qWarning() << "SpellCheckDialog: Cannot open file" << file.fileName() << "for reading!";
}
@ -114,7 +114,7 @@ void SpellCheckDialog::saveSettings()
return;
}
QFile file(mApp->currentProfilePath() + "userdictionary.txt");
QFile file(DataPaths::currentProfilePath() + "userdictionary.txt");
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
qWarning() << "SpellCheckDialog: Cannot open file" << file.fileName() << "for reading!";
return;

View File

@ -18,6 +18,7 @@
#include "speller.h"
#include "spellcheckdialog.h"
#include "settings.h"
#include "datapaths.h"
#include "mainapplication.h"
#include "qztools.h"
@ -64,7 +65,7 @@ void Speller::loadSettings()
m_language.name = nameForLanguage(m_language.code);
settings.endGroup();
m_userDictionary.setFileName(mApp->currentProfilePath() + "userdictionary.txt");
m_userDictionary.setFileName(DataPaths::currentProfilePath() + "userdictionary.txt");
if (m_enabled) {
initialize();
@ -392,7 +393,7 @@ QString Speller::getDictionaryPath() const
#ifdef Q_OS_UNIX
const QString defaultDicPath = "/usr/share/hunspell/";
#else
const QString defaultDicPath = mApp->DATADIR + "hunspell/";
const QString defaultDicPath = DataPaths::path(DataPaths::AppData) + "hunspell/";
#endif
QString dicPath = QString::fromLocal8Bit(qgetenv("DICPATH")).trimmed();

View File

@ -16,9 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "speeddial.h"
#include "mainapplication.h"
#include "pagethumbnailer.h"
#include "settings.h"
#include "datapaths.h"
#include "qztools.h"
#include <QDir>
@ -63,11 +63,11 @@ void SpeedDial::loadSettings()
}
changed(allPages);
m_thumbnailsDir = mApp->currentProfilePath() + "thumbnails/";
m_thumbnailsDir = DataPaths::currentProfilePath() + "thumbnails/";
// If needed, create thumbnails directory
if (!QDir(m_thumbnailsDir).exists()) {
QDir(mApp->currentProfilePath()).mkdir("thumbnails");
QDir(DataPaths::currentProfilePath()).mkdir("thumbnails");
}
}

View File

@ -119,7 +119,7 @@ void PluginsManager::save()
allowedPlugins.append(plugin.fullPath);
}
else {
allowedPlugins.append(mApp->DATADIR + "plugins/" + plugin.fileName);
allowedPlugins.append(plugin.fileName);
}
}
}

View File

@ -41,10 +41,12 @@
#include "qztools.h"
#include "autofill.h"
#include "settings.h"
#include "datapaths.h"
#include "tabbedwebview.h"
#include "clearprivatedata.h"
#include "useragentdialog.h"
#include "registerqappassociation.h"
#include "profilemanager.h"
#include "html5permissions/html5permissionsdialog.h"
#include "pac/pacmanager.h"
@ -177,31 +179,23 @@ Preferences::Preferences(BrowserWindow* window, QWidget* parent)
ui->useCurrentBut->setEnabled(false);
ui->newTabUseCurrent->setEnabled(false);
}
//PROFILES
m_actProfileName = mApp->currentProfilePath();
m_actProfileName = m_actProfileName.left(m_actProfileName.length() - 1);
m_actProfileName = m_actProfileName.mid(m_actProfileName.lastIndexOf(QLatin1Char('/')));
m_actProfileName.remove(QLatin1Char('/'));
ui->activeProfile->setText("<b>" + m_actProfileName + "</b>");
// PROFILES
ProfileManager profileManager;
QString startingProfile = profileManager.startingProfile();
ui->activeProfile->setText("<b>" + profileManager.currentProfile() + "</b>");
ui->startProfile->addItem(startingProfile);
QSettings profileSettings(mApp->PROFILEDIR + "profiles/profiles.ini", QSettings::IniFormat);
QString actProfileName = profileSettings.value("Profiles/startProfile", "default").toString();
ui->startProfile->addItem(actProfileName);
QDir profilesDir(mApp->PROFILEDIR + "profiles/");
QStringList list_ = profilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach (const QString &name, list_) {
if (actProfileName == name) {
continue;
foreach (const QString &name, profileManager.availableProfiles()) {
if (startingProfile != name) {
ui->startProfile->addItem(name);
}
ui->startProfile->addItem(name);
}
connect(ui->createProfile, SIGNAL(clicked()), this, SLOT(createProfile()));
connect(ui->deleteProfile, SIGNAL(clicked()), this, SLOT(deleteProfile()));
connect(ui->startProfile, SIGNAL(currentIndexChanged(QString)), this, SLOT(startProfileIndexChanged(QString)));
startProfileIndexChanged(ui->startProfile->currentText());
connect(ui->startProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(startProfileIndexChanged(int)));
startProfileIndexChanged(ui->startProfile->currentIndex());
//APPEREANCE
settings.beginGroup("Browser-View-Settings");
@ -296,7 +290,7 @@ Preferences::Preferences(BrowserWindow* window, QWidget* parent)
ui->allowCache->setChecked(settings.value("AllowLocalCache", true).toBool());
ui->cacheMB->setValue(settings.value("LocalCacheSize", 50).toInt());
ui->MBlabel->setText(settings.value("LocalCacheSize", 50).toString() + " MB");
ui->cachePath->setText(settings.value("CachePath", QString("%1networkcache/").arg(mApp->currentProfilePath())).toString());
ui->cachePath->setText(settings.value("CachePath", QString("%1networkcache/").arg(DataPaths::currentProfilePath())).toString());
connect(ui->allowCache, SIGNAL(clicked(bool)), this, SLOT(allowCacheChanged(bool)));
connect(ui->cacheMB, SIGNAL(valueChanged(int)), this, SLOT(cacheValueChanged(int)));
connect(ui->changeCachePath, SIGNAL(clicked()), this, SLOT(changeCachePathClicked()));
@ -409,21 +403,25 @@ Preferences::Preferences(BrowserWindow* window, QWidget* parent)
ui->languages->addItem("English (en_US)");
QDir lanDir(mApp->TRANSLATIONSDIR);
QStringList list = lanDir.entryList(QStringList("*.qm"));
foreach (const QString &name, list) {
if (name.startsWith(QLatin1String("qt_"))) {
continue;
const QStringList translationPaths = DataPaths::allPaths(DataPaths::Translations);
foreach (const QString &path, translationPaths) {
QDir lanDir(path);
QStringList list = lanDir.entryList(QStringList("*.qm"));
foreach (const QString &name, list) {
if (name.startsWith(QLatin1String("qt_"))) {
continue;
}
QString loc = name;
loc.remove(QLatin1String(".qm"));
if (loc == activeLanguage) {
continue;
}
ui->languages->addItem(createLanguageItem(loc), loc);
}
QString loc = name;
loc.remove(QLatin1String(".qm"));
if (loc == activeLanguage) {
continue;
}
ui->languages->addItem(createLanguageItem(loc), loc);
}
// Proxy Configuration
@ -789,30 +787,26 @@ void Preferences::createProfile()
{
QString name = QInputDialog::getText(this, tr("New Profile"), tr("Enter the new profile's name:"));
name = QzTools::filterCharsFromFilename(name);
if (name.isEmpty()) {
return;
}
QDir dir(mApp->PROFILEDIR + "profiles/");
if (QDir(dir.absolutePath() + "/" + name).exists()) {
ProfileManager profileManager;
int res = profileManager.createProfile(name);
if (res == -1) {
QMessageBox::warning(this, tr("Error!"), tr("This profile already exists!"));
return;
}
if (!dir.mkdir(name)) {
if (res != 0) {
QMessageBox::warning(this, tr("Error!"), tr("Cannot create profile directory!"));
return;
}
dir.cd(name);
QFile(":data/browsedata.db").copy(dir.absolutePath() + "/browsedata.db");
QFile(dir.absolutePath() + "/browsedata.db").setPermissions(QFile::ReadUser | QFile::WriteUser);
QFile versionFile(dir.absolutePath() + "/version");
versionFile.open(QFile::WriteOnly);
versionFile.write(Qz::VERSION.toUtf8());
versionFile.close();
ui->startProfile->insertItem(0, name);
ui->startProfile->setCurrentIndex(0);
ui->startProfile->addItem(name);
ui->startProfile->setCurrentIndex(ui->startProfile->count() - 1);
}
void Preferences::deleteProfile()
@ -824,15 +818,19 @@ void Preferences::deleteProfile()
return;
}
QzTools::removeDir(mApp->PROFILEDIR + "profiles/" + name);
ProfileManager profileManager;
profileManager.removeProfile(name);
ui->startProfile->removeItem(ui->startProfile->currentIndex());
}
void Preferences::startProfileIndexChanged(QString index)
void Preferences::startProfileIndexChanged(int index)
{
ui->deleteProfile->setEnabled(m_actProfileName != index);
// Index 0 is current profile
if (m_actProfileName == index) {
ui->deleteProfile->setEnabled(index != 0);
if (index == 0) {
ui->cannotDeleteActiveProfileLabel->setText(tr("Note: You cannot delete active profile."));
}
else {
@ -1071,7 +1069,7 @@ void Preferences::saveSettings()
settings.endGroup();
//Profiles
QSettings profileSettings(mApp->PROFILEDIR + "profiles/profiles.ini", QSettings::IniFormat);
QSettings profileSettings(DataPaths::path(DataPaths::Config) + "profiles/profiles.ini", QSettings::IniFormat);
profileSettings.setValue("Profiles/startProfile", ui->startProfile->currentText());
m_pluginsList->save();

View File

@ -84,7 +84,7 @@ private slots:
void createProfile();
void deleteProfile();
void startProfileIndexChanged(QString index);
void startProfileIndexChanged(int index);
void setProgressBarColorIcon(QColor col = QColor());
void selectCustomProgressBarColor();

View File

@ -17,9 +17,9 @@
* ============================================================ */
#include "thememanager.h"
#include "ui_thememanager.h"
#include "mainapplication.h"
#include "qztools.h"
#include "settings.h"
#include "datapaths.h"
#include "licenseviewer.h"
#include "preferences.h"
#include "qzregexp.h"
@ -41,10 +41,7 @@ ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
m_activeTheme = settings.value("activeTheme", DEFAULT_THEME_NAME).toString();
settings.endGroup();
QStringList themePaths;
themePaths << mApp->currentProfilePath() + "themes/"
<< mApp->PROFILEDIR + "themes/"
<< mApp->THEMESDIR;
const QStringList themePaths = DataPaths::allPaths(DataPaths::Themes);
foreach (const QString &path, themePaths) {
QDir dir(path);

View File

@ -17,12 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "restoremanager.h"
#include "datapaths.h"
#include <QFile>
RestoreManager::RestoreManager(const QString &sessionFile)
RestoreManager::RestoreManager()
{
createFromFile(sessionFile);
createFromFile(DataPaths::currentProfilePath() + QLatin1String("session.dat"));
}
RestoreData RestoreManager::restoreData() const

View File

@ -31,7 +31,7 @@ public:
QVector<WebTab::SavedTab> tabsState;
};
RestoreManager(const QString &sessionFile);
explicit RestoreManager();
QVector<RestoreManager::WindowData> restoreData() const;
bool isValid() const;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "qztools.h"
#include "mainapplication.h"
#include "datapaths.h"
#include "settings.h"
#include <QTextDocument>
@ -422,7 +422,7 @@ QIcon QzTools::iconFromFileName(const QString &fileName)
}
QFileIconProvider iconProvider;
QTemporaryFile tempFile(mApp->tempPath() + "/XXXXXX." + tempInfo.suffix());
QTemporaryFile tempFile(DataPaths::path(DataPaths::Temp) + "/XXXXXX." + tempInfo.suffix());
tempFile.open();
tempInfo.setFile(tempFile.fileName());

View File

@ -30,6 +30,7 @@
#include "locationbar.h"
#include "websearchbar.h"
#include "settings.h"
#include "datapaths.h"
#include "qzsettings.h"
#include "qtwin.h"
@ -900,7 +901,7 @@ void TabWidget::savePinnedTabs()
stream << tabs;
stream << tabsHistory;
QFile file(mApp->currentProfilePath() + "pinnedtabs.dat");
QFile file(DataPaths::currentProfilePath() + "pinnedtabs.dat");
file.open(QIODevice::WriteOnly);
file.write(data);
file.close();
@ -912,7 +913,7 @@ void TabWidget::restorePinnedTabs()
return;
}
QFile file(mApp->currentProfilePath() + "pinnedtabs.dat");
QFile file(DataPaths::currentProfilePath() + "pinnedtabs.dat");
file.open(QIODevice::ReadOnly);
QByteArray sd = file.readAll();
file.close();

View File

@ -17,6 +17,7 @@
* ============================================================ */
#include "mainapplication.h"
#include "proxystyle.h"
#include "datapaths.h"
#include <QMessageBox> // For QT_REQUIRE_VERSION
#include <iostream>
@ -47,7 +48,7 @@ void qupzilla_signal_handler(int s)
}
sigSegvServed = true;
std::cout << "QupZilla: Crashed :( Saving backtrace in " << qPrintable(mApp->PROFILEDIR) << "crashlog ..." << std::endl;
std::cout << "QupZilla: Crashed :( Saving backtrace in " << qPrintable(DataPaths::path(DataPaths::Config)) << "crashlog ..." << std::endl;
void* array[100];
int size = backtrace(array, 100);
@ -58,15 +59,15 @@ void qupzilla_signal_handler(int s)
abort();
}
QDir dir(mApp->PROFILEDIR);
QDir dir(DataPaths::path(DataPaths::Config));
if (!dir.exists()) {
std::cout << qPrintable(mApp->PROFILEDIR) << " does not exist" << std::endl;
std::cout << qPrintable(DataPaths::path(DataPaths::Config)) << " does not exist" << std::endl;
abort();
}
if (!dir.cd("crashlog")) {
if (!dir.mkdir("crashlog")) {
std::cout << "Cannot create " << qPrintable(mApp->PROFILEDIR) << "crashlog directory!" << std::endl;
std::cout << "Cannot create " << qPrintable(DataPaths::path(DataPaths::Config)) << "crashlog directory!" << std::endl;
abort();
}

View File

@ -23,8 +23,9 @@
#include "mainapplication.h"
#include "browserwindow.h"
#include "tabwidget.h"
#include "tabbedwebview.h"
#include "tabwidget.h"
#include "datapaths.h"
#include "qztools.h"
#include <QFile>
@ -66,7 +67,7 @@ void GM_AddScriptDialog::showSource()
return;
}
const QString tmpFileName = QzTools::ensureUniqueFilename(mApp->tempPath() + "/tmp-userscript.js");
const QString tmpFileName = QzTools::ensureUniqueFilename(DataPaths::path(DataPaths::Temp) + "/tmp-userscript.js");
if (QFile::copy(m_script->fileName(), tmpFileName)) {
int index = qz->tabWidget()->addView(QUrl::fromLocalFile(tmpFileName), Qz::NT_SelectedTabAtTheEnd);

View File

@ -19,6 +19,7 @@
#include "sbi_networkproxy.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "datapaths.h"
#include <QSettings>
@ -122,7 +123,7 @@ void SBI_NetworkManager::applyCurrentProxy()
}
// Manually modify settings to apply proxy configuration
QSettings settings(mApp->currentProfilePath() + "settings.ini", QSettings::IniFormat);
QSettings settings(DataPaths::currentProfilePath() + "settings.ini", QSettings::IniFormat);
settings.beginGroup("Web-Proxy");
m_currentProxy->saveToSettings(settings);
settings.endGroup();