Skip to content

Commit

Permalink
Displays bookmarks of zims that have ther files missing
Browse files Browse the repository at this point in the history
The bookmarks will still be displayed whether or not their file is still in the library. Helps inform the user what happend to their bookmarks.
  • Loading branch information
ShaopengLin committed Jun 16, 2024
1 parent bfe264d commit 9c39cc2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/readinglistbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ void ReadingListBar::setupList()
auto library = KiwixApp::instance()->getLibrary();
auto bookmarks = library->getBookmarks();
ui->listWidget->clear();
for(auto& bookmark:bookmarks) {
for(unsigned i = 0; i < bookmarks.size(); i++) {
auto& bookmark = bookmarks[i];
std::shared_ptr<zim::Archive> archive;
const QString& title = QString::fromStdString(bookmark.getTitle());
try {
archive = library->getArchive(QString::fromStdString(bookmark.getBookId()));
} catch (std::out_of_range& e) {
/* There can be bookmarks whose information is lost. */
if (!bookmark.getBookId().empty())
addItem(title, i);
continue;
}
try {
Expand All @@ -56,9 +60,9 @@ void ReadingListBar::setupList()
QPixmap pixmap;
pixmap.loadFromData(reinterpret_cast<const uchar*>(content.data()), content.size());
auto icon = QIcon(pixmap);
addItem(title, icon);
addItem(title, i, icon);
} catch (zim::EntryNotFound& e) {
addItem(title);
addItem(title, i);
}
}
}
Expand Down Expand Up @@ -97,16 +101,17 @@ void ReadingListBar::onItemActivated(QListWidgetItem* item, Qt::MouseButtons but
}
}

void ReadingListBar::addItem(const QString &title, const QIcon &icon)
void ReadingListBar::addItem(const QString &title, unsigned idx, const QIcon &icon)
{
auto item = new QListWidgetItem(icon, title, ui->listWidget);
item->setTextAlignment(Qt::TextWordWrap);
item->setData(Qt::UserRole, idx);
}

void ReadingListBar::openUrl(QListWidgetItem* item, bool newTab)
{
int index = ui->listWidget->row(item);
auto bookmark = KiwixApp::instance()->getLibrary()->getBookmarks(true).at(index);
int index = item->data(Qt::UserRole).toUInt();
auto bookmark = KiwixApp::instance()->getLibrary()->getBookmarks(false).at(index);
QUrl url;
url.setScheme("zim");
url.setHost(QString::fromStdString(bookmark.getBookId())+".zim");
Expand Down
2 changes: 1 addition & 1 deletion src/readinglistbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public slots:
void onItemDoubleClicked(QListWidgetItem *item);
void onItemPressed(QListWidgetItem* item, Qt::MouseButtons buttons);
void onItemActivated(QListWidgetItem *item, Qt::MouseButtons buttons);
void addItem(const QString& title, const QIcon& icon = QIcon{});
void addItem(const QString& title, unsigned idx, const QIcon& icon = QIcon{});
private:
Ui::readinglistbar *ui;
int clickKind;
Expand Down

0 comments on commit 9c39cc2

Please sign in to comment.