Rewrote handling of last column clicks using book states

This commit is contained in:
Veloman Yunkan 2024-05-03 15:41:01 +02:00 committed by Kelson
parent b6fbfb6104
commit 0ecb142ca6

View File

@ -257,21 +257,23 @@ void ContentManagerDelegate::handleLastColumnClicked(const QModelIndex& index, Q
int w = r.width();
ContentManager& contentMgr = *KiwixApp::instance()->getContentManager();
if (const auto downloadState = node->getDownloadState()) {
if ( !downloadState->paused ) {
contentMgr.pauseBook(id, index);
} else if (clickX < (x + w/2)) {
contentMgr.cancelBook(id);
} else {
contentMgr.resumeBook(id, index);
}
} else {
try {
const auto book = KiwixApp::instance()->getLibrary()->getBookById(id);
contentMgr.openBook(id);
} catch (std::out_of_range& e) {
contentMgr.downloadBook(id, index);
}
switch ( contentMgr.getBookState(id) ) {
case ContentManager::BookState::AVAILABLE_LOCALLY_AND_HEALTHY:
return contentMgr.openBook(id);
case ContentManager::BookState::AVAILABLE_ONLINE:
return contentMgr.downloadBook(id, index);
case ContentManager::BookState::DOWNLOADING:
return contentMgr.pauseBook(id, index);
case ContentManager::BookState::DOWNLOAD_PAUSED:
return clickX < (x + w/2)
? contentMgr.cancelBook(id)
: contentMgr.resumeBook(id, index);
default:
return;
}
}