From 089abd62383516eb33cbc1c93b06826a0cba3d7b Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 3 Jul 2017 14:47:24 +0200 Subject: Added homepage and newtab to profile widget --- data/poi.toml | 2 +- src/browser.cpp | 7 +- src/forms/profileview.cpp | 18 +++-- src/forms/profileview.ui | 116 +++++++++++++++++----------- src/webengine/webengineprofile.cpp | 152 +++++++++++++++++++------------------ src/webengine/webengineprofile.h | 11 +-- 6 files changed, 167 insertions(+), 139 deletions(-) diff --git a/data/poi.toml b/data/poi.toml index 31e1152..fe3a4fc 100644 --- a/data/poi.toml +++ b/data/poi.toml @@ -31,7 +31,7 @@ search="https://duckduckgo.com/?q=$term&kp=-1" # A nameless ("") profile is off-the-record [browser.profile] default="" -path="$cache/Profiles/" +path="$home/.config/smolbote/profiles/" [browser.profile.new] path="$home/.config/smolbote/profiles" diff --git a/src/browser.cpp b/src/browser.cpp index 355c24b..0ea36d8 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -253,12 +253,7 @@ void Browser::removeWindow(MainWindow *window) WebEngineProfile* Browser::profile(const QString name) { if(!m_profiles.contains(name)) { - // name can be empty --> off-the-record profile - if(name.isEmpty()) { - m_profiles.insert(name, new WebEngineProfile(this)); - } else { - m_profiles.insert(name, new WebEngineProfile(name, settings()->value("browser.profile.path").toString(), this)); - } + m_profiles.insert(name, new WebEngineProfile(name, this)); if(!m_urlRequestInterceptor) { m_urlRequestInterceptor = new UrlRequestInterceptor(this); diff --git a/src/forms/profileview.cpp b/src/forms/profileview.cpp index 9d2e9ed..cece4e4 100644 --- a/src/forms/profileview.cpp +++ b/src/forms/profileview.cpp @@ -30,6 +30,8 @@ #include +#include + ProfileView::ProfileView(WebEngineProfile *profile, QWidget *parent) : QWidget(parent), ui(new Ui::ProfileView) @@ -58,16 +60,17 @@ void ProfileView::setProfile(WebEngineProfile *profile) if(!profile) { return; } + //Q_ASSERT(profile); _profile = profile; - if(!_profile->storageName().isEmpty()) { - setWindowTitle(_profile->storageName()); - } else { - setWindowTitle(tr("Off-the-record")); - } + setWindowTitle(_profile->name()); m_cookiesForm = new CookiesForm(_profile->cookieStore(), this); - ui->tabWidget->addTab(m_cookiesForm, m_cookiesForm->windowTitle()); + //ui->tabWidget->addTab(m_cookiesForm, m_cookiesForm->windowTitle()); + + // general + ui->homepage_lineEdit->setText(_profile->homepage().toString()); + ui->newtab_lineEdit->setText(_profile->newtab().toString()); // http ui->userAgent->setPlainText(_profile->httpUserAgent()); @@ -81,6 +84,9 @@ void ProfileView::setProfile(WebEngineProfile *profile) // policy ui->cookiePolicy->setCurrentIndex(_profile->persistentCookiesPolicy()); + + //ui->formLayout_3->addWidget(m_cookiesForm); + ui->verticalLayout_3->addWidget(m_cookiesForm); } void ProfileView::showProfile() diff --git a/src/forms/profileview.ui b/src/forms/profileview.ui index e7bcbae..bed045a 100644 --- a/src/forms/profileview.ui +++ b/src/forms/profileview.ui @@ -25,6 +25,33 @@ 0 + + + General + + + + + + Homepage + + + + + + + + + + Newtab + + + + + + + + HTTP @@ -86,79 +113,83 @@ - - - - - Paths - - - - + + Storage Path - + false - - + + Cache Path - + false + + + + Clear Cache + + + - Policies + Cookies - - - - - Cookies - - - - - - - - No Persistent Cookies - - - - - Allow Persistent Cookies - + + + + + + + Cookies + + - - - Force Persistent Cookies - + + + + + No Persistent Cookies + + + + + Allow Persistent Cookies + + + + + Force Persistent Cookies + + + - + - Actions + History @@ -168,13 +199,6 @@ - - - - Clear Cache - - - diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp index 5d00495..0a16cd5 100644 --- a/src/webengine/webengineprofile.cpp +++ b/src/webengine/webengineprofile.cpp @@ -23,86 +23,83 @@ #include #include -WebEngineProfile::WebEngineProfile(QObject *parent) : +WebEngineProfile::WebEngineProfile(const QString &name, QObject *parent) : QWebEngineProfile(parent) { - // Off-the-record constructor - m_name = tr("Off-the-record"); - m_homepage = QUrl("https://duckduckgo.com"); -} - -WebEngineProfile::WebEngineProfile(const QString &name, const QString &path, QObject *parent) : - QWebEngineProfile(name, parent) -{ - m_name = name; - m_homepage = QUrl("https://duckduckgo.com"); - setPersistentStoragePath(path + name); - setCachePath(path + name); - - QString profilePath = path + "/profile.ini"; - qDebug("Reading profile from [%s]", qUtf8Printable(profilePath)); - QSettings config(profilePath, QSettings::IniFormat); - - config.beginGroup("http"); - setHttpUserAgent(config.value("userAgent").toString()); - setHttpAcceptLanguage(config.value("accept-lang").toString()); - { - QString cacheType = config.value("cacheType").toString(); - if(cacheType == "memory") { - setHttpCacheType(MemoryHttpCache); - } else if(cacheType == "disk") { - setHttpCacheType(DiskHttpCache); - } else if(cacheType == "disabled") { - setHttpCacheType(NoCache); - } + 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); } - setHttpCacheMaximumSize(config.value("cacheSize").toInt()); - config.endGroup(); // http - config.beginGroup("policy"); - { - QString cookies = config.value("cookies").toString(); - if(cookies == "disabled") { - setPersistentCookiesPolicy(NoPersistentCookies); - } else if(cookies == "allow") { - setPersistentCookiesPolicy(AllowPersistentCookies); - } else if(cookies == "force") { - setPersistentCookiesPolicy(ForcePersistentCookies); + QString profilePath = sSettings->value("browser.profile.path").toString() + name + "/profile.ini"; + if(QFile::exists(profilePath)) { + + qDebug("Reading profile from [%s]", qUtf8Printable(profilePath)); + QSettings config(profilePath, QSettings::IniFormat); + + m_homepage = config.value("homepage", m_homepage).toUrl(); + m_newtab = config.value("newtab", m_newtab).toUrl(); + + config.beginGroup("http"); + setHttpUserAgent(config.value("userAgent").toString()); + setHttpAcceptLanguage(config.value("accept-lang").toString()); + { + QString cacheType = config.value("cacheType").toString(); + if(cacheType == "memory") { + setHttpCacheType(MemoryHttpCache); + } else if(cacheType == "disk") { + setHttpCacheType(DiskHttpCache); + } else if(cacheType == "disabled") { + setHttpCacheType(NoCache); + } } - } - config.endGroup(); // policy - - config.beginGroup("attributes"); - settings()->setAttribute(QWebEngineSettings::AutoLoadImages, config.value("autoLoadImages", true).toBool()); - settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, config.value("javascriptEnabled", true).toBool()); - settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, config.value("javascriptCanOpenWindows", true).toBool()); - settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, config.value("javascriptCanAccessClipboard", false).toBool()); - settings()->setAttribute(QWebEngineSettings::LinksIncludedInFocusChain, config.value("linksIncludedInFocusChain", true).toBool()); - settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, config.value("localStorageEnabled", true).toBool()); - settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, config.value("localContentCanAccessRemoteUrls", false).toBool()); - settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, config.value("xssAuditingEnabled", false).toBool()); - settings()->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, config.value("spatialNavigationEnabled", false).toBool()); - settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, config.value("localContentCanAccessFileUrls", true).toBool()); - settings()->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, config.value("hyperlinkAuditingEnabled", false).toBool()); - settings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, config.value("scrollAnimatorEnabled", false).toBool()); - settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, config.value("errorPageEnabled", true).toBool()); -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - settings()->setAttribute(QWebEngineSettings::PluginsEnabled, config.value("pluginsEnabled", false).toBool()); - settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, config.value("fullscreenSupportEnabled", false).toBool()); -#endif -#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) - settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, config.value("screenCaptureEnabled", false).toBool()); - settings()->setAttribute(QWebEngineSettings::WebGLEnabled, config.value("webglEnabled", true).toBool()); - settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, config.value("accelerated2dCanvasEnabled", true).toBool()); - settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, config.value("autoLoadIconsForPage", true).toBool()); - settings()->setAttribute(QWebEngineSettings::TouchIconsEnabled, config.value("touchIconsEnabled", false).toBool()); -#endif -#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) - settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, config.value("focusOnNavigationEnabled", true).toBool()); - settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, config.value("printElementBackgrounds", true).toBool()); - settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, config.value("allowRunningInsecureContent", false).toBool()); -#endif - config.endGroup(); // attributes + setHttpCacheMaximumSize(config.value("cacheSize").toInt()); + config.endGroup(); // http + + config.beginGroup("policy"); + { + QString cookies = config.value("cookies").toString(); + if(cookies == "disabled") { + setPersistentCookiesPolicy(NoPersistentCookies); + } else if(cookies == "allow") { + setPersistentCookiesPolicy(AllowPersistentCookies); + } else if(cookies == "force") { + setPersistentCookiesPolicy(ForcePersistentCookies); + } + } + config.endGroup(); // policy + + config.beginGroup("attributes"); + settings()->setAttribute(QWebEngineSettings::AutoLoadImages, config.value("autoLoadImages", true).toBool()); + settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, config.value("javascriptEnabled", true).toBool()); + settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, config.value("javascriptCanOpenWindows", true).toBool()); + settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, config.value("javascriptCanAccessClipboard", false).toBool()); + settings()->setAttribute(QWebEngineSettings::LinksIncludedInFocusChain, config.value("linksIncludedInFocusChain", true).toBool()); + settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, config.value("localStorageEnabled", true).toBool()); + settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, config.value("localContentCanAccessRemoteUrls", false).toBool()); + settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, config.value("xssAuditingEnabled", false).toBool()); + settings()->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, config.value("spatialNavigationEnabled", false).toBool()); + settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, config.value("localContentCanAccessFileUrls", true).toBool()); + settings()->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, config.value("hyperlinkAuditingEnabled", false).toBool()); + settings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, config.value("scrollAnimatorEnabled", false).toBool()); + settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, config.value("errorPageEnabled", true).toBool()); + settings()->setAttribute(QWebEngineSettings::PluginsEnabled, config.value("pluginsEnabled", false).toBool()); + settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, config.value("fullscreenSupportEnabled", false).toBool()); + settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, config.value("screenCaptureEnabled", false).toBool()); + settings()->setAttribute(QWebEngineSettings::WebGLEnabled, config.value("webglEnabled", true).toBool()); + settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, config.value("accelerated2dCanvasEnabled", true).toBool()); + settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, config.value("autoLoadIconsForPage", true).toBool()); + settings()->setAttribute(QWebEngineSettings::TouchIconsEnabled, config.value("touchIconsEnabled", false).toBool()); + settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, config.value("focusOnNavigationEnabled", true).toBool()); + settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, config.value("printElementBackgrounds", true).toBool()); + settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, config.value("allowRunningInsecureContent", false).toBool()); + config.endGroup(); // attributes + + } // QFile::exists(profilePath) } WebEngineProfile::~WebEngineProfile() @@ -133,6 +130,11 @@ QUrl WebEngineProfile::homepage() const return m_homepage; } +QUrl WebEngineProfile::newtab() const +{ + return m_newtab; +} + void WebEngineProfile::saveProfile() { QSettings config(persistentStoragePath() + "/profile.ini", QSettings::IniFormat); diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h index 8ddf329..e225462 100644 --- a/src/webengine/webengineprofile.h +++ b/src/webengine/webengineprofile.h @@ -29,17 +29,17 @@ class WebEngineProfile : public QWebEngineProfile { Q_OBJECT public: - explicit WebEngineProfile(QObject *parent = Q_NULLPTR); - explicit WebEngineProfile(const QString &name, const QString &path, QObject *parent = Q_NULLPTR); + explicit WebEngineProfile(const QString &name, QObject *parent = Q_NULLPTR); ~WebEngineProfile(); QString name() const; + QUrl homepage() const; + QUrl newtab() const; + // TODO: remove ProfileView *dialog(); - QUrl homepage() const; - signals: public slots: @@ -47,7 +47,8 @@ public slots: private: QString m_name; - QUrl m_homepage; + QUrl m_homepage = QUrl("about:blank"); + QUrl m_newtab = QUrl("about:blank"); ProfileView *m_profileDialog = nullptr; }; -- cgit v1.2.1