Don't retry downloading too often
This commit is contained in:
parent
e3370bf73e
commit
4f275a5405
2 changed files with 41 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Slava Monich at al.
|
Copyright (C) 2020-2021 Slava Monich at al.
|
||||||
|
|
||||||
This file is part of Fernschreiber.
|
This file is part of Fernschreiber.
|
||||||
|
|
||||||
|
@ -107,6 +107,7 @@ void TDLibFile::init()
|
||||||
queuedSignals = 0;
|
queuedSignals = 0;
|
||||||
firstQueuedSignal = SignalCount;
|
firstQueuedSignal = SignalCount;
|
||||||
autoLoad = false;
|
autoLoad = false;
|
||||||
|
downloadHoldOffTimer = 0;
|
||||||
id = 0;
|
id = 0;
|
||||||
expected_size = 0;
|
expected_size = 0;
|
||||||
size = 0;
|
size = 0;
|
||||||
|
@ -174,7 +175,7 @@ void TDLibFile::updateTDLibWrapper(TDLibWrapper* tdlib)
|
||||||
if (tdlib) {
|
if (tdlib) {
|
||||||
connect(tdlib, SIGNAL(fileUpdated(int,QVariantMap)), SLOT(handleFileUpdated(int,QVariantMap)));
|
connect(tdlib, SIGNAL(fileUpdated(int,QVariantMap)), SLOT(handleFileUpdated(int,QVariantMap)));
|
||||||
if (autoLoad) {
|
if (autoLoad) {
|
||||||
load();
|
downloadFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queueSignal(SignalTdLibChanged);
|
queueSignal(SignalTdLibChanged);
|
||||||
|
@ -187,7 +188,7 @@ void TDLibFile::setAutoLoad(bool enableAutoLoad)
|
||||||
autoLoad = enableAutoLoad;
|
autoLoad = enableAutoLoad;
|
||||||
queueSignal(SignalAutoLoadChanged);
|
queueSignal(SignalAutoLoadChanged);
|
||||||
if (autoLoad) {
|
if (autoLoad) {
|
||||||
load();
|
downloadFile();
|
||||||
}
|
}
|
||||||
emitQueuedSignals();
|
emitQueuedSignals();
|
||||||
}
|
}
|
||||||
|
@ -195,7 +196,19 @@ void TDLibFile::setAutoLoad(bool enableAutoLoad)
|
||||||
|
|
||||||
bool TDLibFile::load()
|
bool TDLibFile::load()
|
||||||
{
|
{
|
||||||
if (id && tdLibWrapper && !is_downloading_active && !is_downloading_completed && can_be_downloaded) {
|
// Manual load ignores hold-off timer
|
||||||
|
if (downloadHoldOffTimer) {
|
||||||
|
killTimer(downloadHoldOffTimer);
|
||||||
|
downloadHoldOffTimer = 0;
|
||||||
|
}
|
||||||
|
return downloadFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TDLibFile::downloadFile()
|
||||||
|
{
|
||||||
|
if (id && tdLibWrapper && !downloadHoldOffTimer &&
|
||||||
|
!is_downloading_active && !is_downloading_completed && can_be_downloaded) {
|
||||||
|
downloadHoldOffTimer = startTimer(DownloadHoldOffMs);
|
||||||
tdLibWrapper->downloadFile(id);
|
tdLibWrapper->downloadFile(id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -205,12 +218,26 @@ bool TDLibFile::load()
|
||||||
void TDLibFile::setFileInfo(const QVariantMap &fileInfo)
|
void TDLibFile::setFileInfo(const QVariantMap &fileInfo)
|
||||||
{
|
{
|
||||||
updateFileInfo(fileInfo);
|
updateFileInfo(fileInfo);
|
||||||
|
if (is_downloading_completed && downloadHoldOffTimer) {
|
||||||
|
// Don't need this timer anymore
|
||||||
|
killTimer(downloadHoldOffTimer);
|
||||||
|
downloadHoldOffTimer = 0;
|
||||||
|
}
|
||||||
if (autoLoad) {
|
if (autoLoad) {
|
||||||
load();
|
downloadFile();
|
||||||
}
|
}
|
||||||
emitQueuedSignals();
|
emitQueuedSignals();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TDLibFile::timerEvent(QTimerEvent *)
|
||||||
|
{
|
||||||
|
killTimer(downloadHoldOffTimer);
|
||||||
|
downloadHoldOffTimer = 0;
|
||||||
|
if (autoLoad) {
|
||||||
|
downloadFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TDLibFile::handleFileUpdated(int fileId, const QVariantMap &fileInfo)
|
void TDLibFile::handleFileUpdated(int fileId, const QVariantMap &fileInfo)
|
||||||
{
|
{
|
||||||
if (id == fileId) {
|
if (id == fileId) {
|
||||||
|
@ -256,6 +283,7 @@ void TDLibFile::updateFileInfo(const QVariantMap &file)
|
||||||
bool b, fileChanged = false;
|
bool b, fileChanged = false;
|
||||||
int i = file.value(ID).toInt();
|
int i = file.value(ID).toInt();
|
||||||
if (id != i) {
|
if (id != i) {
|
||||||
|
LOG("File id has changed" << id << "=>" << i);
|
||||||
id = i;
|
id = i;
|
||||||
fileChanged = true;
|
fileChanged = true;
|
||||||
queueSignal(SignalIdChanged);
|
queueSignal(SignalIdChanged);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Slava Monich at al.
|
Copyright (C) 2020-2021 Slava Monich at al.
|
||||||
|
|
||||||
This file is part of Fernschreiber.
|
This file is part of Fernschreiber.
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ class TDLibFile : public QObject
|
||||||
Q_PROPERTY(bool isUploadingActive READ isUploadingActive NOTIFY uploadingActiveChanged)
|
Q_PROPERTY(bool isUploadingActive READ isUploadingActive NOTIFY uploadingActiveChanged)
|
||||||
Q_PROPERTY(bool isUploadingCompleted READ isUploadingCompleted NOTIFY uploadingCompletedChanged)
|
Q_PROPERTY(bool isUploadingCompleted READ isUploadingCompleted NOTIFY uploadingCompletedChanged)
|
||||||
|
|
||||||
|
enum { DownloadHoldOffMs = 1000 };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TDLibFile();
|
TDLibFile();
|
||||||
TDLibFile(TDLibWrapper *tdlib);
|
TDLibFile(TDLibWrapper *tdlib);
|
||||||
|
@ -102,10 +104,14 @@ signals:
|
||||||
private slots:
|
private slots:
|
||||||
void handleFileUpdated(int fileId, const QVariantMap &fileInfo);
|
void handleFileUpdated(int fileId, const QVariantMap &fileInfo);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void updateTDLibWrapper(TDLibWrapper* tdlib);
|
void updateTDLibWrapper(TDLibWrapper* tdlib);
|
||||||
void updateFileInfo(const QVariantMap &fileInfo);
|
void updateFileInfo(const QVariantMap &fileInfo);
|
||||||
|
bool downloadFile();
|
||||||
void queueSignal(uint signal);
|
void queueSignal(uint signal);
|
||||||
void emitQueuedSignals();
|
void emitQueuedSignals();
|
||||||
|
|
||||||
|
@ -114,6 +120,7 @@ private:
|
||||||
uint queuedSignals;
|
uint queuedSignals;
|
||||||
uint firstQueuedSignal;
|
uint firstQueuedSignal;
|
||||||
bool autoLoad;
|
bool autoLoad;
|
||||||
|
int downloadHoldOffTimer;
|
||||||
// file
|
// file
|
||||||
QVariantMap infoMap;
|
QVariantMap infoMap;
|
||||||
int id;
|
int id;
|
||||||
|
|
Loading…
Reference in a new issue