Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Fine-Tuned Zim Search #1189

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7b7c949
Introduce suggestiolistmodel.{h, cpp}
ShaopengLin Aug 19, 2024
1f1743b
Move SearchBarLineEdit urlList to SuggestionListModel
ShaopengLin Sep 1, 2024
8611a1c
Enter Library::getZimIcon()
ShaopengLin Sep 1, 2024
6cbc9e8
Add Suggestion Icon Decoration Role
ShaopengLin Sep 1, 2024
c029da2
Refactor SuggestionListWorker
ShaopengLin Sep 1, 2024
d5de7c6
Introduce SuggestionListModel::lastIndex
ShaopengLin Sep 17, 2024
0aac03f
Introduce Endless Suggestions
ShaopengLin Sep 17, 2024
84e29ec
Endless Suggestion Key press compatible
ShaopengLin Sep 17, 2024
2aca115
Endless Suggestion Page_Down Compatible
ShaopengLin Sep 17, 2024
1894d41
Correctly handle Endless w/Fulltext
ShaopengLin Sep 17, 2024
d0a1680
Fetch Only When More Suggesion Exist
ShaopengLin Sep 18, 2024
76bae0d
Make First Row Visible on Suggestion Popup
ShaopengLin Sep 17, 2024
a7d7304
Introduce Kiwix Search Header
ShaopengLin Sep 17, 2024
d713173
Replace m_completer.popup() with m_suggestionView
ShaopengLin Sep 17, 2024
b3d9424
Enter KiwixApp::getSearchBar()
ShaopengLin Sep 17, 2024
ff7117b
BugFix openCompletion Connected Multiple Times
ShaopengLin Sep 28, 2024
ce36366
Make SearchBar Margin Consistent
ShaopengLin Sep 28, 2024
b9f4f94
Align Search Suggestion with Line Edit
ShaopengLin Sep 28, 2024
02e042a
Fix Suggestion Flickering when Typing
ShaopengLin Sep 28, 2024
dac8d04
Proper Size for Suggestion View
ShaopengLin Sep 28, 2024
fcebdd0
Proper Suggestion Icon&Text Spacing
ShaopengLin Sep 28, 2024
64b30c3
Proper Hover Style to Suggestion Items
ShaopengLin Sep 28, 2024
b19ea81
Proper Elide for Suggestion List Text
ShaopengLin Sep 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kiwix-desktop.pro
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ SOURCES += \
src/kiwixloader.cpp \
src/rownode.cpp \
src/suggestionlistworker.cpp \
src/suggestionlistmodel.cpp \
ShaopengLin marked this conversation as resolved.
Show resolved Hide resolved
src/suggestionlistdelegate.cpp \
src/thumbnaildownloader.cpp \
src/translation.cpp \
src/main.cpp \
Expand Down Expand Up @@ -109,6 +111,8 @@ HEADERS += \
src/node.h \
src/rownode.h \
src/suggestionlistworker.h \
src/suggestionlistmodel.h \
src/suggestionlistdelegate.h \
src/thumbnaildownloader.h \
src/translation.h \
src/mainwindow.h \
Expand Down
25 changes: 24 additions & 1 deletion resources/css/popup.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
QWidget {
QTreeView {
background-color: white;
outline: 0px;
border: none;
}

QTreeView::item:selected {
border: 1px solid #3366CC;
background-color: #D9E9FF;
color: black;
}

/* data of src/suggestionlistModel.cpp and SearchBarLineEdit of src/searchbar.cpp
references the line-height and padding.
*/
QHeaderView::section {
border: none;
color: #3b3b3b;
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 5px;
background-color: white;
font-size: 16px;
line-height: 24px;
font-weight: 400;
}

QScrollBar {
width: 5px;
border: none;
Expand Down
10 changes: 3 additions & 7 deletions resources/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ QToolButton {
border: none;
}

/* getCompleterRect of src/searchbar.cpp references the margin and border */
SearchBar {
background-color: white;
margin: 2px 5px;
margin: 2px;
border: 1px solid #ccc;
border-radius: 3px;

Expand All @@ -43,7 +44,7 @@ SearchBar > QLabel#searchIcon {
padding: 0;
border: none;
background-color: none;
margin: 0px 4px 0px 9px;
margin: 0px 6px;

max-height: 38px;
max-width: 38px;
Expand All @@ -68,11 +69,6 @@ SearchBar > QToolButton {
max-width: 38px;
}

SearchBar > BookmarkButton {
margin-right: 3px;
margin-left: 3px;
}

SearchBar > QToolButton:pressed,
SearchBar > QToolButton:hover {
border: 1px solid #3366CC;
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@
"save-page-as": "Save As...",
"portable-disabled-tooltip": "Function disabled in portable mode",
"scroll-next-tab": "Scroll to next tab",
"scroll-previous-tab": "Scroll to previous tab"
"scroll-previous-tab": "Scroll to previous tab",
"kiwix-search": "Kiwix search"
}
3 changes: 2 additions & 1 deletion resources/i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,6 @@
"save-page-as": "Represents the action of saving the current tab content to a file chosen by the user.",
"portable-disabled-tooltip": "Tooltip used to explain disabled components in the portable version.",
"scroll-next-tab": "Represents the action of scrolling to the next tab of the current tab which toward the end of the tab bar.",
"scroll-previous-tab": "Represents the action of scrolling to the previous tab of the current tab which toward the start of the tab bar."
"scroll-previous-tab": "Represents the action of scrolling to the previous tab of the current tab which toward the start of the tab bar.",
"kiwix-search": "Title text for a list of search results, which notes to the user those are from Kiwix's Search Engine"
}
2 changes: 1 addition & 1 deletion src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ KiwixApp::~KiwixApp()
void KiwixApp::newTab()
{
getTabWidget()->createNewTab(true, false);
auto& searchBarLineEdit = mp_mainWindow->getTopWidget()->getSearchBar().getLineEdit();
auto& searchBarLineEdit = getSearchBar().getLineEdit();
searchBarLineEdit.setFocus(Qt::MouseFocusReason);
searchBarLineEdit.clear();
searchBarLineEdit.clearSuggestions();
Expand Down
1 change: 1 addition & 0 deletions src/kiwixapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class KiwixApp : public QtSingleApplication
MainWindow* getMainWindow() { return mp_mainWindow; }
ContentManager* getContentManager() { return mp_manager; }
TabBar* getTabWidget() { return getMainWindow()->getTabBar(); }
SearchBar& getSearchBar() { return getMainWindow()->getTopWidget()->getSearchBar(); }
QAction* getAction(Actions action);
QString getLibraryDirectory() { return m_libraryDirectory; };
kiwix::Server* getLocalServer() { return &m_server; }
Expand Down
18 changes: 18 additions & 0 deletions src/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <kiwix/manager.h>
#include <kiwix/tools.h>
#include <zim/item.h>

#include <QtDebug>
#include <QtConcurrent/QtConcurrentRun>
Expand Down Expand Up @@ -72,6 +73,23 @@ std::shared_ptr<zim::Searcher> Library::getSearcher(const QString &zimId)
return mp_library->getSearcherById(zimId.toStdString());
}

QIcon Library::getZimIcon(const QString &zimId, QIcon defaultIcon)
ShaopengLin marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
auto book = getBookById(zimId);
auto illustration = book.getIllustration(48);
std::string content = illustration->getData();
QPixmap pixmap;
pixmap.loadFromData((const uchar*)content.data(), content.size());
return QIcon(pixmap);
}
catch (...)
{
return defaultIcon;
}
}

QStringList Library::getBookIds() const
{
QStringList list;
Expand Down
2 changes: 2 additions & 0 deletions src/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QSharedPointer>
#include <QMap>
#include <QMutex>
#include <QIcon>

#define TQS(v) (QString::fromStdString(v))
#define FORWARD_GETTER(METH) QString METH() const { return TQS(mp_book->METH()); }
Expand All @@ -33,6 +34,7 @@ class Library : public QObject
QString openBookFromPath(const QString& zimPath);
std::shared_ptr<zim::Archive> getArchive(const QString& zimId);
std::shared_ptr<zim::Searcher> getSearcher(const QString& zimId);
QIcon getZimIcon(const QString& zimId, QIcon defaultIcon = QIcon{});
QStringList getBookIds() const;
QStringList listBookIds(const kiwix::Filter& filter, kiwix::supportedListSortBy sortBy, bool ascending) const;
const std::vector<kiwix::Bookmark> getBookmarks(bool onlyValidBookmarks = false) const { return mp_library->getBookmarks(onlyValidBookmarks); }
Expand Down
21 changes: 5 additions & 16 deletions src/readinglistbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,17 @@ void ReadingListBar::setupList()
auto listWidget = ui->listWidget;
listWidget->clear();
for(auto& bookmark:bookmarks) {
std::shared_ptr<zim::Archive> archive;
auto zimId = QString::fromStdString(bookmark.getBookId());
try {
archive = library->getArchive(QString::fromStdString(bookmark.getBookId()));
library->getArchive(zimId);
} catch (std::out_of_range& e) {
continue;
}
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);
new QListWidgetItem(
icon,
QString::fromStdString(bookmark.getTitle()),
listWidget);
} catch (zim::EntryNotFound& e) {
new QListWidgetItem(
auto item = new QListWidgetItem(
library->getZimIcon(zimId),
QString::fromStdString(bookmark.getTitle()),
listWidget);
}
item->setTextAlignment(Qt::TextWordWrap);
ShaopengLin marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading
Loading