diff options
-rw-r--r-- | src/mainwindow.cpp | 53 | ||||
-rw-r--r-- | src/mainwindow.h | 5 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.cpp | 17 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.h | 4 |
4 files changed, 58 insertions, 21 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));
diff --git a/src/mainwindow.h b/src/mainwindow.h index 35d7a1d..2eedebf 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -29,6 +29,9 @@ protected: void closeEvent(QCloseEvent *event) override;
private slots:
+ void loadProfile(const QString &name);
+ void handleLoadProfile();
+
void handleNewWindow(const QUrl &url = QUrl(""));
void handleTabChanged(QWebEngineView *view);
void handleUrlChanged();
@@ -40,7 +43,7 @@ private slots: private:
Browser *browserInstance;
QString profileName;
- WebEngineProfile *profile;
+ WebEngineProfile *profile = nullptr;
// ui
Ui::MainWindow *ui;
diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp index efc8fef..666c610 100644 --- a/src/widgets/webviewtabbar.cpp +++ b/src/widgets/webviewtabbar.cpp @@ -15,9 +15,14 @@ WebViewTabBar::~WebViewTabBar() m_views.clear(); } -int WebViewTabBar::addTab(QWebEngineView *view) +int WebViewTabBar::addTab(QWebEngineProfile *profile, const QUrl &url) { + QWebEngineView *view = new QWebEngineView(0); + QWebEnginePage *page = new QWebEnginePage(profile); + view->setPage(page); + page->load(url); m_views.append(view); + //connect(view, SIGNAL(titleChanged()), this, SLOT(updateTabText())); connect(view, &QWebEngineView::titleChanged, [this, view](const QString &title) { int index = m_views.indexOf(view); @@ -27,9 +32,19 @@ int WebViewTabBar::addTab(QWebEngineView *view) int index = m_views.indexOf(view); setTabIcon(index, icon); }); + return QTabBar::addTab("New Tab"); } +void WebViewTabBar::setProfile(QWebEngineProfile *profile) +{ + for(QWebEngineView *view : m_views) { + QWebEnginePage *page = new QWebEnginePage(profile); + page->load(view->url()); + view->setPage(page); + } +} + QWebEngineView *WebViewTabBar::currentView() { return m_views.at(currentIndex()); diff --git a/src/widgets/webviewtabbar.h b/src/widgets/webviewtabbar.h index 28a9a18..f4fc6e4 100644 --- a/src/widgets/webviewtabbar.h +++ b/src/widgets/webviewtabbar.h @@ -12,7 +12,9 @@ public: WebViewTabBar(QWidget *parent = 0); ~WebViewTabBar(); - int addTab(QWebEngineView *view); + int addTab(QWebEngineProfile *profile, const QUrl &url); + void setProfile(QWebEngineProfile *profile); + QWebEngineView *currentView(); signals: |