aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-01-13 17:49:52 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-01-13 17:49:52 +0100
commit4823393a8348674999657670076cf73a612cfb4a (patch)
tree973fa57a66ed42e3419453888edff8e054b62a5f /src/mainwindow.cpp
parentAdded all QtWebEngineProfile options to ProfileDialog (diff)
downloadsmolbote-4823393a8348674999657670076cf73a612cfb4a.tar.xz
Swapping profiles now works
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp53
1 files changed, 35 insertions, 18 deletions
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 <QApplication>
+#include <QInputDialog>
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));