From 4823393a8348674999657670076cf73a612cfb4a Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 13 Jan 2017 17:49:52 +0100 Subject: Swapping profiles now works --- src/mainwindow.cpp | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1f27652..638ba7f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -8,6 +8,7 @@ #include "browser.h" #include "forms/profiledialog.h" #include +#include MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) : QMainWindow(parent), @@ -20,16 +21,8 @@ MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) : browserInstance = instance; Settings settings; - // 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); - } + // Load profile and connect its signals + loadProfile(settings.value("defaults/profile").toString()); ui->setupUi(this); resize(settings.value("window/width", 800).toInt(), settings.value("window/height", 600).toInt()); @@ -49,9 +42,9 @@ MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) : 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")); + profileMenu->addAction(tr("Load profile"), this, SLOT(handleLoadProfile())); + //profileMenu->addAction(tr("Settings")); + //profileMenu->addAction(tr("Cookies")); this->addToolBar(Qt::TopToolBarArea, navigationToolBar); this->addToolBarBreak(Qt::TopToolBarArea); @@ -76,11 +69,7 @@ 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); + tabBar->addTab(profile, url); } void MainWindow::closeEvent(QCloseEvent *event) @@ -95,6 +84,34 @@ void MainWindow::closeEvent(QCloseEvent *event) QMainWindow::closeEvent(event); } +void MainWindow::loadProfile(const QString &name) +{ + if(profile) { + profile->deleteLater(); + } + + if(name.isEmpty()) { + qDebug("Creating off-the-record profile"); + profileName = tr("Off the record"); + profile = new WebEngineProfile(this); + } else { + profileName = name; + qDebug("Using profile: %s", qUtf8Printable(profileName)); + profile = new WebEngineProfile(profileName, this); + } +} + +void MainWindow::handleLoadProfile() +{ + bool ok; + QString name = QInputDialog::getText(this, tr("Load Profile"), tr("Enter Profile name"), QLineEdit::Normal, QString(""), &ok); + if(ok) { + loadProfile(name); + profileMenu->setTitle(tr("Profile: ") + profileName); + tabBar->setProfile(profile); + } +} + void MainWindow::handleNewWindow(const QUrl &url) { browserInstance->addWindow(new MainWindow(browserInstance, url)); -- cgit v1.2.1