diff --git a/src/webview.cpp b/src/webview.cpp index 37817994..6fdb8a4e 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -135,17 +135,28 @@ QMenu* WebView::getHistoryForwardMenu() const return ret; } +/** + * @brief Get the Zim Item object corresponding to the given url. + * + * @param url QUrl + * @return zim::Item + * + * @exception throws exception if zimId is invalid, archive doesn't exist, + * entry is invalid or not found, or entry is redirect. + */ +zim::Item getZimItem(const QUrl& url) +{ + const auto app = KiwixApp::instance(); + const auto library = app->getLibrary(); + const auto archive = library->getArchive(getZimIdFromUrl(url)); + const auto entry = getArchiveEntryFromUrl(*archive, url); + return entry.getItem(true); +} + void WebView::saveViewContent() { try { - auto app = KiwixApp::instance(); - auto library = app->getLibrary(); - auto archive = library->getArchive(m_currentZimId); - auto entry = getArchiveEntryFromUrl(*archive, this->url()); - if (entry.isRedirect()) - return; - - auto item = entry.getItem(true); + const auto item = getZimItem(url()); auto mimeType = QByteArray::fromStdString(item.getMimetype()); mimeType = mimeType.split(';')[0];