mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
Downloading indicator in book list
If a book is downloading, it now shows "Downloading"
This commit is contained in:
parent
3f72af494e
commit
ef0227b08c
@ -357,6 +357,14 @@ QString ContentManager::downloadBook(const QString &id)
|
|||||||
bookCopy.setDownloadId(download->getDid());
|
bookCopy.setDownloadId(download->getDid());
|
||||||
mp_library->addBookToLibrary(bookCopy);
|
mp_library->addBookToLibrary(bookCopy);
|
||||||
mp_library->save();
|
mp_library->save();
|
||||||
|
QTimer *timer = new QTimer(this);
|
||||||
|
connect(timer, &QTimer::timeout, this, [=](){
|
||||||
|
auto downloadInfos = updateDownloadInfos(id, {"status"});
|
||||||
|
if (!downloadInfos["status"].isValid()) {
|
||||||
|
timer->stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timer->start(1000);
|
||||||
emit(oneBookChanged(id));
|
emit(oneBookChanged(id));
|
||||||
return QString::fromStdString(download->getDid());
|
return QString::fromStdString(download->getDid());
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <QStyleOptionViewItemV4>
|
#include <QStyleOptionViewItemV4>
|
||||||
#include "kiwixapp.h"
|
#include "kiwixapp.h"
|
||||||
#include <QStyleOptionViewItem>
|
#include <QStyleOptionViewItem>
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
ContentManagerDelegate::ContentManagerDelegate(QObject *parent)
|
ContentManagerDelegate::ContentManagerDelegate(QObject *parent)
|
||||||
: QStyledItemDelegate(parent), baseButton(new QPushButton)
|
: QStyledItemDelegate(parent), baseButton(new QPushButton)
|
||||||
@ -28,8 +29,20 @@ void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||||||
w = r.width();
|
w = r.width();
|
||||||
h = r.height();
|
h = r.height();
|
||||||
button.rect = QRect(x,y,w,h);
|
button.rect = QRect(x,y,w,h);
|
||||||
button.text = "Open";
|
|
||||||
button.state = QStyle::State_Enabled;
|
button.state = QStyle::State_Enabled;
|
||||||
|
auto node = static_cast<Node*>(index.internalPointer());
|
||||||
|
try {
|
||||||
|
const auto id = node->getBookId();
|
||||||
|
const auto book = KiwixApp::instance()->getLibrary()->getBookById(id);
|
||||||
|
if(KiwixApp::instance()->getContentManager()->getBookInfos(id, {"downloadId"})["downloadId"] != "") {
|
||||||
|
button.text = "Downloading";
|
||||||
|
button.state = QStyle::State_ReadOnly;
|
||||||
|
} else {
|
||||||
|
button.text = gt("open");
|
||||||
|
}
|
||||||
|
} catch (std::out_of_range& e) {
|
||||||
|
button.text = gt("download");
|
||||||
|
}
|
||||||
QStyleOptionViewItem eOpt = option;
|
QStyleOptionViewItem eOpt = option;
|
||||||
if (index.data(Qt::UserRole+1) != QVariant()) {
|
if (index.data(Qt::UserRole+1) != QVariant()) {
|
||||||
// additional info role
|
// additional info role
|
||||||
@ -61,20 +74,24 @@ bool ContentManagerDelegate::editorEvent(QEvent *event, QAbstractItemModel *mode
|
|||||||
int clickX = e->x();
|
int clickX = e->x();
|
||||||
int clickY = e->y();
|
int clickY = e->y();
|
||||||
|
|
||||||
QRect r = option.rect;//getting the rect of the cell
|
QRect r = option.rect;
|
||||||
int x,y,w,h;
|
int x,y,w,h;
|
||||||
x = r.left();//the X coordinate
|
x = r.left();
|
||||||
y = r.top();//the Y coordinate
|
y = r.top();
|
||||||
w = r.width();//button width
|
w = r.width();
|
||||||
h = r.height();//button height
|
h = r.height();
|
||||||
|
const auto node = static_cast<Node*>(index.internalPointer());
|
||||||
|
const auto id = node->getBookId();
|
||||||
|
|
||||||
if(index.column() == 5 && clickX > x && clickX < x + w )
|
if(index.column() == 5 && clickX > x && clickX < x + w )
|
||||||
if( clickY > y && clickY < y + h )
|
if( clickY > y && clickY < y + h && KiwixApp::instance()->getContentManager()->getBookInfos(id, {"downloadId"})["downloadId"] == "")
|
||||||
{
|
{
|
||||||
const auto modeel = index.model();
|
try {
|
||||||
const auto id = modeel->data(index).toString();
|
const auto book = KiwixApp::instance()->getLibrary()->getBookById(id);
|
||||||
KiwixApp::instance()->getContentManager()->openBook(id);
|
KiwixApp::instance()->getContentManager()->openBook(id);
|
||||||
|
} catch (std::out_of_range& e) {
|
||||||
|
KiwixApp::instance()->getContentManager()->downloadBook(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user