diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 0ea1c79..9338a3b 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -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> ContentManager::getBooksList() @@ -227,6 +228,21 @@ QMap ContentManager::getBookInfos(QString id, const QStringLi } #undef ADD_V +void ContentManager::openBookWithIndex(const QModelIndex &index) +{ + try { + Node* bookNode = static_cast(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/"); diff --git a/src/contentmanager.h b/src/contentmanager.h index 1d093a4..7650dea 100644 --- a/src/contentmanager.h +++ b/src/contentmanager.h @@ -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 diff --git a/src/contentmanagerdelegate.cpp b/src/contentmanagerdelegate.cpp index fbc8e27..f1de60b 100644 --- a/src/contentmanagerdelegate.cpp +++ b/src/contentmanagerdelegate.cpp @@ -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));