diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-07-03 14:47:24 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-07-03 14:47:24 +0200 |
commit | 089abd62383516eb33cbc1c93b06826a0cba3d7b (patch) | |
tree | ff74a37b5115052a8ea27679b32aef20523d86c9 /src | |
parent | Added homepage button (diff) | |
download | smolbote-089abd62383516eb33cbc1c93b06826a0cba3d7b.tar.xz |
Added homepage and newtab to profile widget
Diffstat (limited to 'src')
-rw-r--r-- | src/browser.cpp | 7 | ||||
-rw-r--r-- | src/forms/profileview.cpp | 18 | ||||
-rw-r--r-- | src/forms/profileview.ui | 116 | ||||
-rw-r--r-- | src/webengine/webengineprofile.cpp | 152 | ||||
-rw-r--r-- | src/webengine/webengineprofile.h | 11 |
5 files changed, 166 insertions, 138 deletions
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 <QDialogButtonBox> +#include <QFormLayout> + 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 @@ <property name="currentIndex"> <number>0</number> </property> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>General</string> + </attribute> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Homepage</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="homepage_lineEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Newtab</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="newtab_lineEdit"/> + </item> + </layout> + </widget> <widget class="QWidget" name="httpTab"> <attribute name="title"> <string>HTTP</string> @@ -86,79 +113,83 @@ <item row="3" column="1"> <widget class="QLineEdit" name="cacheSize"/> </item> - </layout> - </widget> - <widget class="QWidget" name="pathTab"> - <attribute name="title"> - <string>Paths</string> - </attribute> - <layout class="QFormLayout" name="formLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="label_2"> + <item row="6" column="0"> + <widget class="QLabel" name="storagePath_label"> <property name="text"> <string>Storage Path</string> </property> </widget> </item> - <item row="0" column="1"> + <item row="6" column="1"> <widget class="QLineEdit" name="storagePath_lineEdit"> <property name="enabled"> <bool>false</bool> </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_3"> + <item row="4" column="0"> + <widget class="QLabel" name="cachePath_label"> <property name="text"> <string>Cache Path</string> </property> </widget> </item> - <item row="1" column="1"> + <item row="4" column="1"> <widget class="QLineEdit" name="cachePath_lineEdit"> <property name="enabled"> <bool>false</bool> </property> </widget> </item> + <item row="5" column="1"> + <widget class="QPushButton" name="clearCache_pushButton"> + <property name="text"> + <string>Clear Cache</string> + </property> + </widget> + </item> </layout> </widget> <widget class="QWidget" name="policiesTab"> <attribute name="title"> - <string>Policies</string> + <string>Cookies</string> </attribute> - <layout class="QFormLayout" name="formLayout_3"> - <item row="0" column="0"> - <widget class="QLabel" name="label_7"> - <property name="text"> - <string>Cookies</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QComboBox" name="cookiePolicy"> - <item> - <property name="text"> - <string>No Persistent Cookies</string> - </property> - </item> - <item> - <property name="text"> - <string>Allow Persistent Cookies</string> - </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <layout class="QFormLayout" name="cookies_formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_7"> + <property name="text"> + <string>Cookies</string> + </property> + </widget> </item> - <item> - <property name="text"> - <string>Force Persistent Cookies</string> - </property> + <item row="0" column="1"> + <widget class="QComboBox" name="cookiePolicy"> + <item> + <property name="text"> + <string>No Persistent Cookies</string> + </property> + </item> + <item> + <property name="text"> + <string>Allow Persistent Cookies</string> + </property> + </item> + <item> + <property name="text"> + <string>Force Persistent Cookies</string> + </property> + </item> + </widget> </item> - </widget> + </layout> </item> </layout> </widget> <widget class="QWidget" name="actionsTab"> <attribute name="title"> - <string>Actions</string> + <string>History</string> </attribute> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> @@ -169,13 +200,6 @@ </widget> </item> <item> - <widget class="QPushButton" name="clearCache_pushButton"> - <property name="text"> - <string>Clear Cache</string> - </property> - </widget> - </item> - <item> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> 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 <QSettings> #include <QWebEngineSettings> -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; }; |