diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-01-12 19:57:00 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-01-12 19:57:00 +0100 |
commit | 8c30d0d5f0ab93c44b6957040fd0a2b3b7749faa (patch) | |
tree | 94500815f9734492c3c61d97aca1b0c4bbcddcd3 | |
parent | Minor bugfixes (diff) | |
download | smolbote-8c30d0d5f0ab93c44b6957040fd0a2b3b7749faa.tar.xz |
Profile config loading and saving
-rw-r--r-- | src/forms/profiledialog.cpp | 4 | ||||
-rw-r--r-- | src/forms/profiledialog.ui | 28 | ||||
-rw-r--r-- | src/mainwindow.cpp | 17 | ||||
-rw-r--r-- | src/mainwindow.h | 5 | ||||
-rw-r--r-- | src/qt-simplebrowser.pro | 6 | ||||
-rw-r--r-- | src/webengine/webengineprofile.cpp | 31 | ||||
-rw-r--r-- | src/webengine/webengineprofile.h | 20 | ||||
-rw-r--r-- | test/config.ini | 1 |
8 files changed, 106 insertions, 6 deletions
diff --git a/src/forms/profiledialog.cpp b/src/forms/profiledialog.cpp index 14279c4..b485419 100644 --- a/src/forms/profiledialog.cpp +++ b/src/forms/profiledialog.cpp @@ -1,6 +1,8 @@ #include "profiledialog.h" #include "ui_profiledialog.h" +#include <QLineEdit> + ProfileDialog::ProfileDialog(QWebEngineProfile *profile, QWidget *parent) : QDialog(parent), ui(new Ui::ProfileDialog) @@ -9,6 +11,8 @@ ProfileDialog::ProfileDialog(QWebEngineProfile *profile, QWidget *parent) : ui->setupUi(this); ui->userAgent_lineEdit->setText(_profile->httpUserAgent()); + ui->storagePath_lineEdit->setText(_profile->persistentStoragePath()); + ui->cachePath_lineEdit->setText(_profile->cachePath()); connect(this, SIGNAL(accepted()), this, SLOT(saveProfile())); } diff --git a/src/forms/profiledialog.ui b/src/forms/profiledialog.ui index 160743b..097d9cb 100644 --- a/src/forms/profiledialog.ui +++ b/src/forms/profiledialog.ui @@ -26,6 +26,34 @@ <item row="0" column="1"> <widget class="QLineEdit" name="userAgent_lineEdit"/> </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Storage Path</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="storagePath_lineEdit"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Cache Path</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="cachePath_lineEdit"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> </layout> </item> <item> diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fef3bcc..1f27652 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -20,7 +20,16 @@ MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) : browserInstance = instance;
Settings settings;
- profile = QWebEngineProfile::defaultProfile();
+ // Create the profile
+ profileName = settings.value("defaults/profile").toString();
+ if(profileName.isEmpty()) {
+ qDebug("Creating off-the-record profile");
+ profileName = tr("Off the record");
+ profile = new WebEngineProfile(this);
+ } else {
+ qDebug("Using profile: %s", qUtf8Printable(profileName));
+ profile = new WebEngineProfile(profileName, this);
+ }
ui->setupUi(this);
resize(settings.value("window/width", 800).toInt(), settings.value("window/height", 600).toInt());
@@ -36,11 +45,13 @@ MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) : // Profile menu
QMenuBar *rightBar = new QMenuBar(ui->menuBar);
- profileMenu = new QMenu(tr("Profile: ") + profile->storageName());
+ profileMenu = new QMenu(tr("Profile: ") + profileName);
rightBar->addMenu(profileMenu);
ui->menuBar->setCornerWidget(rightBar);
profileMenu->addAction(tr("Edit profile"), this, SLOT(createProfileDialog()));
profileMenu->addAction(tr("Load profile"));
+ profileMenu->addAction(tr("Settings"));
+ profileMenu->addAction(tr("Cookies"));
this->addToolBar(Qt::TopToolBarArea, navigationToolBar);
this->addToolBarBreak(Qt::TopToolBarArea);
@@ -66,6 +77,8 @@ MainWindow::~MainWindow() void MainWindow::createNewTab(const QUrl &url)
{
QWebEngineView *view = new QWebEngineView(0);
+ QWebEnginePage *page = new QWebEnginePage(profile, view);
+ view->setPage(page);
view->load(url);
tabBar->addTab(view);
}
diff --git a/src/mainwindow.h b/src/mainwindow.h index a5709e9..35d7a1d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -5,7 +5,7 @@ #include <QToolBar>
#include <QLineEdit>
#include <QWebEngineView>
-#include <QWebEngineProfile>
+#include "webengine/webengineprofile.h"
#include <QUrl>
#include "widgets/webviewtabbar.h"
@@ -39,7 +39,8 @@ private slots: private:
Browser *browserInstance;
- QWebEngineProfile *profile;
+ QString profileName;
+ WebEngineProfile *profile;
// ui
Ui::MainWindow *ui;
diff --git a/src/qt-simplebrowser.pro b/src/qt-simplebrowser.pro index 57886d3..b4c98aa 100644 --- a/src/qt-simplebrowser.pro +++ b/src/qt-simplebrowser.pro @@ -16,13 +16,15 @@ SOURCES += main.cpp \ browser.cpp \ widgets/webviewtabbar.cpp \ settings.cpp \ - forms/profiledialog.cpp + forms/profiledialog.cpp \ + webengine/webengineprofile.cpp HEADERS += mainwindow.h \ browser.h \ widgets/webviewtabbar.h \ settings.h \ - forms/profiledialog.h + forms/profiledialog.h \ + webengine/webengineprofile.h FORMS += mainwindow.ui \ forms/profiledialog.ui diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp new file mode 100644 index 0000000..1eb1112 --- /dev/null +++ b/src/webengine/webengineprofile.cpp @@ -0,0 +1,31 @@ +#include "webengineprofile.h" +#include <QSettings> + +WebEngineProfile::WebEngineProfile(QObject *parent) : + QWebEngineProfile(parent) +{ + // Off-the-record constructor +} + +WebEngineProfile::WebEngineProfile(const QString &storageName, QObject *parent) : + QWebEngineProfile(storageName, parent) +{ + qDebug("Reading WebEngineProfile..."); + QSettings config(persistentStoragePath() + "/profile.ini", QSettings::IniFormat); + + config.beginGroup("http"); + setHttpUserAgent(config.value("userAgent").toString()); + config.endGroup(); +} + +WebEngineProfile::~WebEngineProfile() +{ + if(!this->isOffTheRecord()) { + // save settings + QSettings config(persistentStoragePath() + "/profile.ini", QSettings::IniFormat); + config.beginGroup("http"); + config.setValue("userAgent", httpUserAgent()); + config.endGroup(); + config.sync(); + } +} diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h new file mode 100644 index 0000000..ca2fd08 --- /dev/null +++ b/src/webengine/webengineprofile.h @@ -0,0 +1,20 @@ +#ifndef WEBENGINEPROFILE_H +#define WEBENGINEPROFILE_H + +#include <QWebEngineProfile> + +class WebEngineProfile : public QWebEngineProfile +{ + Q_OBJECT +public: + WebEngineProfile(QObject *parent = Q_NULLPTR); + WebEngineProfile(const QString &storageName, QObject *parent = Q_NULLPTR); + + ~WebEngineProfile(); + +signals: + +public slots: +}; + +#endif // WEBENGINEPROFILE_H diff --git a/test/config.ini b/test/config.ini index 0c40a5f..e8087b4 100644 --- a/test/config.ini +++ b/test/config.ini @@ -1,5 +1,6 @@ [defaults] url=https://duckduckgo.com +profile=Default [window] title=" -- QtWebEngine" |