From a85dc7d9133c3cf4c94a2ef37db4f53a3d0e4c91 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 4 Aug 2017 13:12:32 +0200 Subject: Profile window fixes --- src/webengine/webengineprofile.cpp | 60 +++++++++++++++++++++++++------------- src/webengine/webengineprofile.h | 8 +++-- 2 files changed, 45 insertions(+), 23 deletions(-) (limited to 'src/webengine') diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp index 0a16cd5..583be3e 100644 --- a/src/webengine/webengineprofile.cpp +++ b/src/webengine/webengineprofile.cpp @@ -23,23 +23,38 @@ #include #include -WebEngineProfile::WebEngineProfile(const QString &name, QObject *parent) : +WebEngineProfile::WebEngineProfile(QObject *parent) : QWebEngineProfile(parent) { - if(name.isEmpty()) { - m_name = tr("Off-the-record"); - // off-the-record should have no storage or cache - } else { - m_name = name; - setPersistentStoragePath(sSettings->value("browser.profile.path").toString() + name); - setCachePath(sSettings->value("browser.profile.path").toString() + name); - } + m_name = tr("Off-the-record"); - QString profilePath = sSettings->value("browser.profile.path").toString() + name + "/profile.ini"; - if(QFile::exists(profilePath)) { + // Off-the-record profiles have no persistent path - qDebug("Reading profile from [%s]", qUtf8Printable(profilePath)); - QSettings config(profilePath, QSettings::IniFormat); + m_homepage = sSettings->value("browser.profile.new.homepage").toUrl(); + m_newtab = sSettings->value("browser.profile.new.newtab").toUrl(); +} + +WebEngineProfile::WebEngineProfile(const QString &name, QObject *parent) : + QWebEngineProfile(name, parent) +{ + m_name = name; + setPersistentStoragePath(sSettings->value("browser.profile.storagePath").toString() + name); + setCachePath(sSettings->value("browser.profile.cachePath").toString() + name); + + // Read profile settings + QString profileIniPath = sSettings->value("browser.profile.path").toString() + name + "/profile.ini"; + + // If none exist, use the defaults + if(!QFile::exists(profileIniPath)) { + qDebug("Creating new profile..."); + m_homepage = sSettings->value("browser.profile.new.homepage").toUrl(); + m_newtab = sSettings->value("browser.profile.new.newtab").toUrl(); + + // Else read them + } else { + + qDebug("Reading profile from [%s]", qUtf8Printable(profileIniPath)); + QSettings config(profileIniPath, QSettings::IniFormat); m_homepage = config.value("homepage", m_homepage).toUrl(); m_newtab = config.value("newtab", m_newtab).toUrl(); @@ -117,17 +132,14 @@ QString WebEngineProfile::name() const return m_name; } -ProfileView *WebEngineProfile::dialog() +QUrl WebEngineProfile::homepage() const { - if(m_profileDialog == nullptr) { - m_profileDialog = new ProfileView(this); - } - return m_profileDialog; + return m_homepage; } -QUrl WebEngineProfile::homepage() const +void WebEngineProfile::setHomepage(const QUrl &url) { - return m_homepage; + m_homepage = url; } QUrl WebEngineProfile::newtab() const @@ -135,10 +147,18 @@ QUrl WebEngineProfile::newtab() const return m_newtab; } +void WebEngineProfile::setNewtab(const QUrl &url) +{ + m_newtab = url; +} + void WebEngineProfile::saveProfile() { QSettings config(persistentStoragePath() + "/profile.ini", QSettings::IniFormat); + config.setValue("homepage", homepage().toString()); + config.setValue("newtab", newtab().toString()); + config.beginGroup("http"); config.setValue("userAgent", httpUserAgent()); config.setValue("accept-lang", httpAcceptLanguage()); diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h index e225462..f457f53 100644 --- a/src/webengine/webengineprofile.h +++ b/src/webengine/webengineprofile.h @@ -29,16 +29,18 @@ class WebEngineProfile : public QWebEngineProfile { Q_OBJECT public: + explicit WebEngineProfile(QObject *parent = Q_NULLPTR); explicit WebEngineProfile(const QString &name, QObject *parent = Q_NULLPTR); ~WebEngineProfile(); QString name() const; + QUrl homepage() const; - QUrl newtab() const; + void setHomepage(const QUrl &url); - // TODO: remove - ProfileView *dialog(); + QUrl newtab() const; + void setNewtab(const QUrl &url); signals: -- cgit v1.2.1