diff --git a/src/lib/tabwidget/tabcontextmenu.cpp b/src/lib/tabwidget/tabcontextmenu.cpp index bcb2589ec..794c27adc 100644 --- a/src/lib/tabwidget/tabcontextmenu.cpp +++ b/src/lib/tabwidget/tabcontextmenu.cpp @@ -44,6 +44,7 @@ TabContextMenu::TabContextMenu(int index, Qt::Orientation orientation, BrowserWi connect(this, SIGNAL(closeToRight(int)), m_tabWidget, SLOT(closeToRight(int))); connect(this, SIGNAL(closeToLeft(int)), m_tabWidget, SLOT(closeToLeft(int))); connect(this, SIGNAL(duplicateTab(int)), m_tabWidget, SLOT(duplicateTab(int))); + connect(this, SIGNAL(unloadTab(int)), m_tabWidget, SLOT(unloadTab(int))); init(); } @@ -121,6 +122,11 @@ void TabContextMenu::init() addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab())); addAction(webTab->isMuted() ? tr("Un&mute Tab") : tr("&Mute Tab"), this, SLOT(muteTab())); + + if (webTab->isRestored()) { + addAction(tr("Unload Tab"), this, SLOT(unloadTab())); + } + addSeparator(); addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs())); diff --git a/src/lib/tabwidget/tabcontextmenu.h b/src/lib/tabwidget/tabcontextmenu.h index 0f02b7796..3a45399f0 100644 --- a/src/lib/tabwidget/tabcontextmenu.h +++ b/src/lib/tabwidget/tabcontextmenu.h @@ -39,12 +39,14 @@ signals: void closeToRight(int index); void closeToLeft(int index); void duplicateTab(int index); + void unloadTab(int index); private slots: void reloadTab() { emit reloadTab(m_clickedTab); } void stopTab() { emit stopTab(m_clickedTab); } void closeTab() { emit tabCloseRequested(m_clickedTab); } void duplicateTab() { emit duplicateTab(m_clickedTab); } + void unloadTab() { emit unloadTab(m_clickedTab); } void pinTab(); void muteTab(); diff --git a/src/lib/tabwidget/tabwidget.cpp b/src/lib/tabwidget/tabwidget.cpp index 1481f1a59..acbfe6843 100644 --- a/src/lib/tabwidget/tabwidget.cpp +++ b/src/lib/tabwidget/tabwidget.cpp @@ -672,6 +672,15 @@ int TabWidget::duplicateTab(int index) return id; } +void TabWidget::unloadTab(int index) +{ + if (!validIndex(index)) { + return; + } + + weTab(index)->unload(); +} + void TabWidget::restoreClosedTab(QObject* obj) { if (!obj) { diff --git a/src/lib/tabwidget/tabwidget.h b/src/lib/tabwidget/tabwidget.h index cbf9252c5..1d235d0fe 100644 --- a/src/lib/tabwidget/tabwidget.h +++ b/src/lib/tabwidget/tabwidget.h @@ -116,6 +116,7 @@ public slots: void closeToRight(int index); void closeToLeft(int index); void detachTab(int index); + void unloadTab(int index); void restoreClosedTab(QObject* obj = 0); void restoreAllClosedTabs(); void clearClosedTabsList(); diff --git a/src/lib/webtab/webtab.cpp b/src/lib/webtab/webtab.cpp index b4c411acc..7b3ec7c1d 100644 --- a/src/lib/webtab/webtab.cpp +++ b/src/lib/webtab/webtab.cpp @@ -311,14 +311,21 @@ QByteArray WebTab::historyData() const } } +void WebTab::stop() +{ + m_webView->stop(); +} + void WebTab::reload() { m_webView->reload(); } -void WebTab::stop() +void WebTab::unload() { - m_webView->stop(); + m_savedTab = SavedTab(this); + m_webView->history()->clear(); + m_webView->setUrl(QUrl(QSL("about:blank"))); } bool WebTab::isLoading() const @@ -426,6 +433,10 @@ void WebTab::showNotification(QWidget* notif) void WebTab::loadStarted() { + if (!isRestored()) { + return; + } + if (m_tabBar && m_webView->title(/*allowEmpty*/true).isEmpty()) { m_tabBar->setTabText(tabIndex(), tr("Loading...")); } @@ -433,12 +444,16 @@ void WebTab::loadStarted() void WebTab::loadFinished() { - titleChanged(m_webView->title()); + if (isRestored()) { + titleChanged(m_webView->title()); + } else if (m_webView->url().toString() == QL1S("about:blank")) { + m_webView->history()->clear(); + } } void WebTab::titleChanged(const QString &title) { - if (!m_tabBar || !m_window || title.isEmpty()) { + if (!m_tabBar || !m_window || title.isEmpty() || !isRestored()) { return; } @@ -449,25 +464,19 @@ void WebTab::titleChanged(const QString &title) m_tabBar->setTabText(tabIndex(), title); } -void WebTab::slotRestore() -{ - Q_ASSERT(m_tabBar); - - if (isRestored()) { - return; - } - - p_restoreTab(m_savedTab); - m_savedTab.clear(); -} - void WebTab::tabActivated() { if (isRestored()) { return; } - QTimer::singleShot(0, this, SLOT(slotRestore())); + QTimer::singleShot(0, this, [this]() { + if (isRestored()) { + return; + } + p_restoreTab(m_savedTab); + m_savedTab.clear(); + }); } void WebTab::resizeEvent(QResizeEvent *event) diff --git a/src/lib/webtab/webtab.h b/src/lib/webtab/webtab.h index 8ead83ed8..3d6cfbc92 100644 --- a/src/lib/webtab/webtab.h +++ b/src/lib/webtab/webtab.h @@ -77,6 +77,7 @@ public: void stop(); void reload(); + void unload(); bool isLoading() const; bool isPinned() const; @@ -110,8 +111,6 @@ private slots: void loadFinished(); void titleChanged(const QString &title); - void slotRestore(); - private: void resizeEvent(QResizeEvent *event) override;