Skip to content

Commit

Permalink
fixup! Replace deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
juuz0 committed May 17, 2022
1 parent 1f8298b commit afd23e1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 51 deletions.
25 changes: 14 additions & 11 deletions src/readinglistbar.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "readinglistbar.h"
#include "ui_readinglistbar.h"
#include "kiwixapp.h"
#include "zim/error.h"

#include <QListWidgetItem>

Expand Down Expand Up @@ -37,17 +38,19 @@ void ReadingListBar::setupList()
} catch (std::out_of_range& e) {
continue;
}
auto illustration = archive->getIllustrationItem(48);
std::string content = illustration.getData();
std::string mimeType = illustration.getMimetype();
QPixmap pixmap;
pixmap.loadFromData(reinterpret_cast<const uchar*>(content.data()), content.size());
auto icon = QIcon(pixmap);
auto item = new QListWidgetItem(
icon,
QString::fromStdString(bookmark.getTitle()),
listWidget);
item->setTextAlignment(Qt::TextWordWrap);
try {
auto illustration = archive->getIllustrationItem(48);
std::string content = illustration.getData();
std::string mimeType = illustration.getMimetype();
QPixmap pixmap;
pixmap.loadFromData(reinterpret_cast<const uchar*>(content.data()), content.size());
auto icon = QIcon(pixmap);
auto item = new QListWidgetItem(
icon,
QString::fromStdString(bookmark.getTitle()),
listWidget);
item->setTextAlignment(Qt::TextWordWrap);
} catch (zim::EntryNotFound& e) {}
}
}

Expand Down
48 changes: 19 additions & 29 deletions src/suggestionlistworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@ std::string lcAll(std::string title)
return word.toLower().toStdString();
}

bool searchSuggestionsSmart(std::shared_ptr<zim::Archive> archive,
std::string prefix,
unsigned int suggestionsCount,
kiwix::SuggestionsList_t& results)
{
auto suggestionSearcher = zim::SuggestionSearcher(*archive);
if (archive->hasTitleIndex()) {
auto suggestionSearch = suggestionSearcher.suggest(prefix);
const auto suggestions = suggestionSearch.getResults(0, suggestionsCount);
for (auto current : suggestions) {
kiwix::SuggestionItem suggestion(current.getTitle(), lcAll(current.getTitle()),
current.getPath(), current.getSnippet());
results.push_back(suggestion);
}
}
return results.size() > 0;
}

void SuggestionListWorker::run()
{
QStringList suggestionList;
Expand All @@ -48,13 +30,20 @@ void SuggestionListWorker::run()
QUrl url;
url.setScheme("zim");
url.setHost(currentZimId + ".zim");
kiwix::SuggestionsList_t suggestions;
searchSuggestionsSmart(archive, m_text.toStdString(), 15, suggestions);
for (auto& suggestion: suggestions) {
QString path = QString("/") + QString::fromStdString(suggestion.getPath());
url.setPath(path);
suggestionList.append(QString::fromStdString(suggestion.getTitle()));
urlList.append(url);
int suggestionsCount = 15;
auto prefix = m_text.toStdString();
auto suggestionSearcher = zim::SuggestionSearcher(*archive);
if (archive->hasTitleIndex()) {
auto suggestionSearch = suggestionSearcher.suggest(prefix);
const auto suggestions = suggestionSearch.getResults(0, suggestionsCount);
for (auto current : suggestions) {
kiwix::SuggestionItem suggestion(current.getTitle(), lcAll(current.getTitle()),
current.getPath(), current.getSnippet());
QString path = QString("/") + QString::fromStdString(suggestion.getPath());
url.setPath(path);
suggestionList.append(QString::fromStdString(suggestion.getTitle()));
urlList.append(url);
}
}

// Propose fulltext search
Expand All @@ -71,10 +60,11 @@ void SuggestionListWorker::run()
urlList.append(url);
}
} catch (std::out_of_range& e) {
// We do not allow multi zim search for now.
// We don't have a correct UI to select on which zim search,
// how to display results, ...
//url.setHost("library.search");
// Impossible to find the requested archive (bug ?)
// We could propose a suggestion to do multi-zim search with:
// url.setHost("library.search");
// but we don't have a correct UI to select on which zim search, how to display results, ...
// So do nothing for now
}
emit(searchFinished(suggestionList, urlList, m_token));
}
4 changes: 2 additions & 2 deletions src/urlschemehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ UrlSchemeHandler::handleContentRequest(QWebEngineUrlRequestJob *request)
try {
auto entry = getEntryFromPath(*archive, url);
if (entry.isRedirect()) {
entry = getFinalEntry(entry);
auto path = QString("/") + QString::fromStdString(entry.getPath());
auto item = entry.getItem(true);
auto path = QString("/") + QString::fromStdString(item.getPath());
qurl.setPath(path);
request->redirect(qurl);
return;
Expand Down
20 changes: 11 additions & 9 deletions src/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <QWebEngineSettings>
#include <QWebEngineHistory>
#include <QVBoxLayout>

#include <zim/error.h>

void WebViewBackMenu::showEvent(QShowEvent *)
{
Expand Down Expand Up @@ -173,16 +173,18 @@ void WebView::onUrlChanged(const QUrl& url) {
} catch (std::out_of_range& e) {
return;
}
std::string favicon, _mimetype;
auto item = archive->getIllustrationItem(48);
favicon = item.getData();
_mimetype = item.getMimetype();
QPixmap pixmap;
pixmap.loadFromData((const uchar*)favicon.data(), favicon.size());
m_icon = QIcon(pixmap);
emit iconChanged(m_icon);
auto zoomFactor = app->getSettingsManager()->getZoomFactorByZimId(zimId);
this->setZoomFactor(zoomFactor);
try {
std::string favicon, _mimetype;
auto item = archive->getIllustrationItem(48);
favicon = item.getData();
_mimetype = item.getMimetype();
QPixmap pixmap;
pixmap.loadFromData((const uchar*)favicon.data(), favicon.size());
m_icon = QIcon(pixmap);
emit iconChanged(m_icon);
} catch (zim::EntryNotFound& e) {}
}

void WebView::wheelEvent(QWheelEvent *event) {
Expand Down

0 comments on commit afd23e1

Please sign in to comment.