mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Illiminate Tabbar::widget method;
Fix potential segfault when settings tab is open and closing by zim ID
This commit is contained in:
parent
f576df02fd
commit
639f8dd5f5
@ -250,15 +250,7 @@ void ContentManager::eraseBookFilesFromComputer(const QString dirPath, const QSt
|
||||
void ContentManager::eraseBook(const QString& id)
|
||||
{
|
||||
auto tabBar = KiwixApp::instance()->getTabWidget();
|
||||
int i = 1;
|
||||
while (i < tabBar->count() - 1) {
|
||||
WebView* webView = tabBar->widget(i)->getWebView();
|
||||
if (webView->zimId() == id) {
|
||||
tabBar->closeTab(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
tabBar->closeTabsByZimId(id);
|
||||
kiwix::Book book = mp_library->getBookById(id);
|
||||
QString dirPath = QString::fromStdString(removeLastPathElement(book.getPath()));
|
||||
QString filename = QString::fromStdString(getLastPathElement(book.getPath())) + "*";
|
||||
|
@ -200,6 +200,19 @@ void TabBar::triggerWebPageAction(QWebEnginePage::WebAction action, ZimView *wid
|
||||
widget->getWebView()->setFocus();
|
||||
}
|
||||
|
||||
void TabBar::closeTabsByZimId(const QString &id)
|
||||
{
|
||||
// the last tab is + button, skip it
|
||||
for (int i = count() - 2 ; i >= 0 ; i--) {
|
||||
auto *zv = qobject_cast<ZimView*>(mp_stackedWidget->widget(i));
|
||||
if (!zv)
|
||||
continue;
|
||||
if (zv->getWebView()->zimId() == id) {
|
||||
closeTab(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TabBar::closeTab(int index)
|
||||
{
|
||||
setSelectionBehaviorOnRemove(index);
|
||||
@ -211,7 +224,7 @@ void TabBar::closeTab(int index)
|
||||
if (index < m_settingsIndex) {
|
||||
m_settingsIndex--;
|
||||
}
|
||||
auto webview = widget(index);
|
||||
auto webview = mp_stackedWidget->widget(index);
|
||||
mp_stackedWidget->removeWidget(webview);
|
||||
webview->setParent(nullptr);
|
||||
removeTab(index);
|
||||
@ -239,7 +252,7 @@ void TabBar::onCurrentChanged(int index)
|
||||
KiwixApp::instance()->setSideBar(KiwixApp::NONE);
|
||||
QTimer::singleShot(0, [=](){emit currentTitleChanged("");});
|
||||
} else if (index) {
|
||||
auto view = widget(index)->getWebView();
|
||||
auto view = static_cast<ZimView*>(mp_stackedWidget->widget(index))->getWebView();
|
||||
emit webActionEnabledChanged(QWebEnginePage::Back, view->isWebActionEnabled(QWebEnginePage::Back));
|
||||
emit webActionEnabledChanged(QWebEnginePage::Forward, view->isWebActionEnabled(QWebEnginePage::Forward));
|
||||
emit libraryPageDisplayed(false);
|
||||
|
@ -23,7 +23,6 @@ public:
|
||||
void setContentManagerView(ContentManagerView* view);
|
||||
void setNewTabButton();
|
||||
ZimView* createNewTab(bool setCurrent);
|
||||
ZimView* widget(int index) { return (index != 0) ? static_cast<ZimView*>(mp_stackedWidget->widget(index)) : nullptr; }
|
||||
WebView* currentWebView() { auto current = mp_stackedWidget->currentWidget();
|
||||
if (mp_stackedWidget->currentIndex() == 0 ||
|
||||
mp_stackedWidget->currentIndex() == m_settingsIndex) return nullptr;
|
||||
@ -46,6 +45,7 @@ public:
|
||||
QString currentArticleTitle();
|
||||
virtual QSize tabSizeHint(int index) const;
|
||||
void openFindInPageBar();
|
||||
void closeTabsByZimId(const QString &id);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
Loading…
x
Reference in New Issue
Block a user