Skip to content

Commit

Permalink
Introduce getZimItem in WebView.cpp
Browse files Browse the repository at this point in the history
Refactor the way to get item from url.
  • Loading branch information
ShaopengLin committed Oct 28, 2024
1 parent adfd924 commit b18a2cb
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit b18a2cb

Please sign in to comment.