Open book on double & middle click in library

Fix #410
This commit is contained in:
Nikhil Tanwar 2023-07-03 19:23:50 +05:30
parent d2061a69a5
commit 078dd8ebe4
3 changed files with 22 additions and 0 deletions

View File

@ -62,6 +62,7 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
connect(&m_remoteLibraryManager, &OpdsRequestManager::requestReceived, this, &ContentManager::updateRemoteLibrary);
connect(mp_view->getView(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onCustomContextMenu(const QPoint &)));
connect(this, &ContentManager::pendingRequest, mp_view, &ContentManagerView::showLoader);
connect(treeView, &QTreeView::doubleClicked, this, &ContentManager::openBookWithIndex);
}
QList<QMap<QString, QVariant>> ContentManager::getBooksList()
@ -227,6 +228,21 @@ QMap<QString, QVariant> ContentManager::getBookInfos(QString id, const QStringLi
}
#undef ADD_V
void ContentManager::openBookWithIndex(const QModelIndex &index)
{
try {
Node* bookNode = static_cast<Node*>(index.internalPointer());
auto bookId = bookNode->getBookId();
if (bookNode->isAdditonal())
bookId = bookNode->parentItem()->getBookId();
// check if the book is available in local library, will throw std::out_of_range if it isn't.
KiwixApp::instance()->getLibrary()->getBookById(bookId);
if (getBookInfos(bookId, {"downloadId"})["downloadId"] != "")
return;
openBook(bookId);
} catch (std::out_of_range &e) {}
}
void ContentManager::openBook(const QString &id)
{
QUrl url("zim://"+id+".zim/");

View File

@ -77,6 +77,7 @@ public slots:
void resumeBook(const QString& id, QModelIndex index);
void cancelBook(const QString& id, QModelIndex index);
void onCustomContextMenu(const QPoint &point);
void openBookWithIndex(const QModelIndex& index);
};
#endif // CONTENTMANAGER_H

View File

@ -218,6 +218,11 @@ bool ContentManagerDelegate::editorEvent(QEvent *event, QAbstractItemModel *mode
w = r.width();
h = r.height();
if (e->button() == Qt::MiddleButton && index.column() != 5) {
KiwixApp::instance()->getContentManager()->openBookWithIndex(index);
return true;
}
const auto lastColumnClicked = ((index.column() == 5) && (clickX > x && clickX < x + w)
&& (clickY > y && clickY < y + h));