From f9ed795730acbc3155990e8d99e24447f808fc7f Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 12 Jan 2017 13:52:45 +0100 Subject: Viewing and editing user agent of default profile --- src/forms/profiledialog.cpp | 25 +++++++++++++++ src/forms/profiledialog.h | 27 ++++++++++++++++ src/forms/profiledialog.ui | 78 +++++++++++++++++++++++++++++++++++++++++++++ src/mainwindow.cpp | 27 ++++++++++++---- src/mainwindow.h | 7 ++++ src/qt-simplebrowser.pro | 9 ++++-- 6 files changed, 163 insertions(+), 10 deletions(-) create mode 100644 src/forms/profiledialog.cpp create mode 100644 src/forms/profiledialog.h create mode 100644 src/forms/profiledialog.ui diff --git a/src/forms/profiledialog.cpp b/src/forms/profiledialog.cpp new file mode 100644 index 0000000..14279c4 --- /dev/null +++ b/src/forms/profiledialog.cpp @@ -0,0 +1,25 @@ +#include "profiledialog.h" +#include "ui_profiledialog.h" + +ProfileDialog::ProfileDialog(QWebEngineProfile *profile, QWidget *parent) : + QDialog(parent), + ui(new Ui::ProfileDialog) +{ + _profile = profile; + + ui->setupUi(this); + ui->userAgent_lineEdit->setText(_profile->httpUserAgent()); + + connect(this, SIGNAL(accepted()), this, SLOT(saveProfile())); +} + +ProfileDialog::~ProfileDialog() +{ + delete ui; +} + +void ProfileDialog::saveProfile() +{ + qDebug("Saving profile..."); + _profile->setHttpUserAgent(ui->userAgent_lineEdit->text()); +} diff --git a/src/forms/profiledialog.h b/src/forms/profiledialog.h new file mode 100644 index 0000000..98426d0 --- /dev/null +++ b/src/forms/profiledialog.h @@ -0,0 +1,27 @@ +#ifndef PROFILEDIALOG_H +#define PROFILEDIALOG_H + +#include +#include + +namespace Ui { +class ProfileDialog; +} + +class ProfileDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ProfileDialog(QWebEngineProfile *profile, QWidget *parent = 0); + ~ProfileDialog(); + +private slots: + void saveProfile(); + +private: + QWebEngineProfile *_profile; + Ui::ProfileDialog *ui; +}; + +#endif // PROFILEDIALOG_H diff --git a/src/forms/profiledialog.ui b/src/forms/profiledialog.ui new file mode 100644 index 0000000..160743b --- /dev/null +++ b/src/forms/profiledialog.ui @@ -0,0 +1,78 @@ + + + ProfileDialog + + + + 0 + 0 + 480 + 640 + + + + Dialog + + + + + + + + User Agent + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close|QDialogButtonBox::Save + + + + + + + + + buttonBox + accepted() + ProfileDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ProfileDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dea9f79..ccf75f3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5,6 +5,8 @@ #include #include #include "browser.h" +#include "forms/profiledialog.h" +#include MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) : QMainWindow(parent), @@ -17,20 +19,25 @@ MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) : browserInstance = instance; Settings settings; + profile = QWebEngineProfile::defaultProfile(); + ui->setupUi(this); resize(settings.value("window/width", 800).toInt(), settings.value("window/height", 600).toInt()); - // Populate the menu bar - // Browser menu - with new window, new tab, open and quit - QMenu *browserMenu = new QMenu(qApp->applicationName(), ui->menuBar); + // Browser menu + browserMenu = new QMenu(qApp->applicationName(), ui->menuBar); + ui->menuBar->addMenu(browserMenu); browserMenu->addAction(tr("New Window"), this, SLOT(handleNewWindow()), QKeySequence(tr("Ctrl+N"))); browserMenu->addAction(tr("New Tab"), this, SLOT(createNewTab()), QKeySequence(tr("Ctrl+T"))); browserMenu->addSeparator(); + browserMenu->addAction(tr("About Qt"), qApp, SLOT(aboutQt())); browserMenu->addAction(tr("Quit"), qApp, SLOT(quit()), QKeySequence(tr("Ctrl+Q"))); - ui->menuBar->addMenu(browserMenu); - // View menu - fullscreen - // Page menu - what page actions? - // Help menu - help contents, about, about qt + + // Profile menu + profileMenu = new QMenu(profile->storageName()); + ui->menuBar->addMenu(profileMenu); + profileMenu->addAction(tr("Edit profile"), this, SLOT(createProfileDialog())); + profileMenu->addAction(tr("Load profile")); this->addToolBar(Qt::TopToolBarArea, navigationToolBar); this->addToolBarBreak(Qt::TopToolBarArea); @@ -103,3 +110,9 @@ void MainWindow::handleTitleUpdated(const QString &title) Settings settings; setWindowTitle(title + settings.value("window/title", "qtwebenginebrowser").toString()); } + +void MainWindow::createProfileDialog() +{ + ProfileDialog *dialog = new ProfileDialog(profile, this); + dialog->exec(); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 7371759..a5709e9 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "widgets/webviewtabbar.h" @@ -34,9 +35,15 @@ private slots: void handleUrlUpdated(const QUrl &url); void handleTitleUpdated(const QString &title); + void createProfileDialog(); + private: Browser *browserInstance; + QWebEngineProfile *profile; + + // ui Ui::MainWindow *ui; + QMenu *browserMenu, *profileMenu; QToolBar *navigationToolBar, *tabToolBar; WebViewTabBar *tabBar; QLineEdit *urlLineEdit; diff --git a/src/qt-simplebrowser.pro b/src/qt-simplebrowser.pro index 33b960f..57886d3 100644 --- a/src/qt-simplebrowser.pro +++ b/src/qt-simplebrowser.pro @@ -15,11 +15,14 @@ SOURCES += main.cpp \ mainwindow.cpp \ browser.cpp \ widgets/webviewtabbar.cpp \ - settings.cpp + settings.cpp \ + forms/profiledialog.cpp HEADERS += mainwindow.h \ browser.h \ widgets/webviewtabbar.h \ - settings.h + settings.h \ + forms/profiledialog.h -FORMS += mainwindow.ui +FORMS += mainwindow.ui \ + forms/profiledialog.ui -- cgit v1.2.1