aboutsummaryrefslogtreecommitdiff
path: root/src/subwindow/tabwidget.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-03 11:04:05 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-03 11:04:05 +0200
commit9ba76d7ccdaafcbc7c25b9c4737bd22a2a87d1dd (patch)
treea142ebe02397d1a54283f9ff264e29fc3adb715e /src/subwindow/tabwidget.cpp
parentUpdate PKGBUILD (diff)
downloadsmolbote-9ba76d7ccdaafcbc7c25b9c4737bd22a2a87d1dd.tar.xz
Subwindow: only keep tab history for restore tab action
Diffstat (limited to 'src/subwindow/tabwidget.cpp')
-rw-r--r--src/subwindow/tabwidget.cpp49
1 files changed, 30 insertions, 19 deletions
diff --git a/src/subwindow/tabwidget.cpp b/src/subwindow/tabwidget.cpp
index 6189b2c..25e27cf 100644
--- a/src/subwindow/tabwidget.cpp
+++ b/src/subwindow/tabwidget.cpp
@@ -14,6 +14,16 @@
#include <QMenu>
#include <QTabBar>
#include <web/webprofile.h>
+#include <QWebEngineHistory>
+
+inline WebView *createViewFromInfo(TabWidget::TabInformation &tab, QWidget *parent)
+{
+ auto *view = new WebView(tab.profile, parent);
+ QDataStream stream(&tab.historyBuffer, QIODevice::ReadOnly);
+ stream >> *view->history();
+ view->history()->goToItem(view->history()->itemAt(tab.historyIndex));
+ return view;
+}
TabWidget::TabWidget(QWidget *parent)
: QTabWidget(parent)
@@ -72,31 +82,28 @@ QMenu *TabWidget::createTabMenu(QWidget *parent)
auto *reopenTabAction = menu->addAction(tr("Reopen last tab"));
connect(reopenTabAction, &QAction::triggered, this, [this]() {
if(!m_closedTabs.isEmpty()) {
- QWebEnginePage *page = m_closedTabs.takeLast();
- auto *view = new WebView(qobject_cast<WebProfile *>(page->profile()), this);
- view->setPage(page);
- addTab(view);
+ TabInformation tab = m_closedTabs.takeLast();
+ addTab(createViewFromInfo(tab, this));
}
});
auto *tabHistoryMenu = menu->addMenu(tr("Tab History"));
connect(tabHistoryMenu, &QMenu::aboutToShow, this, [this, tabHistoryMenu]() {
tabHistoryMenu->clear();
- for(QWebEnginePage *page : m_closedTabs) {
- auto *openAction = tabHistoryMenu->addAction(page->title());
- connect(openAction, &QAction::triggered, this, [page, this]() {
- auto *view = new WebView(qobject_cast<WebProfile *>(page->profile()), this);
- view->setPage(page);
- this->addTab(view);
- m_closedTabs.removeOne(page);
+ for(int i = 0; i < m_closedTabs.count(); ++i) {
+ auto *openAction = tabHistoryMenu->addAction(m_closedTabs.at(i).title);
+
+ connect(openAction, &QAction::triggered, this, [this, i]() {
+ TabInformation tab = m_closedTabs.takeAt(i);
+ addTab(createViewFromInfo(tab, this));
});
}
+
tabHistoryMenu->addSeparator();
+
auto *clearTabHistory = tabHistoryMenu->addAction(tr("Clear"));
connect(clearTabHistory, &QAction::triggered, this, [this]() {
- while(!m_closedTabs.isEmpty()) {
- delete m_closedTabs.dequeue();
- }
+ m_closedTabs.clear();
});
});
@@ -137,14 +144,18 @@ int TabWidget::addTab(WebView *view)
void TabWidget::deleteTab(int index)
{
// deleting the widget automatically removes the tab?
- auto *w = widget(index);
+ WebView *w = qobject_cast<WebView *>(widget(index));
- QWebEnginePage *p = qobject_cast<WebView *>(w)->page();
- p->setParent(nullptr);
- m_closedTabs.enqueue(p);
+ TabInformation tab;
+ tab.profile = w->profile();
+ tab.title = w->title();
+ tab.historyIndex = w->history()->currentItemIndex();
+ QDataStream stream(&tab.historyBuffer, QIODevice::WriteOnly);
+ stream << *w->history();
+ m_closedTabs.enqueue(tab);
while(m_closedTabs.length() > 5) {
- delete m_closedTabs.dequeue();
+ m_closedTabs.dequeue();
}
disconnect(w);