summaryrefslogtreecommitdiffstats
path: root/api/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-04-30 02:54:37 +0200
committerPetr Mrázek <peterix@gmail.com>2017-04-30 02:54:37 +0200
commit794102b32cb9b9c0ddb0c8268c572acb256dd6ba (patch)
tree86aff77c02ee18479cb18da035ae70d0a5c8e758 /api/logic
parent1be99b075ab1911e65a165e3b47513a3a8e290f3 (diff)
downloadMultiMC-794102b32cb9b9c0ddb0c8268c572acb256dd6ba.tar
MultiMC-794102b32cb9b9c0ddb0c8268c572acb256dd6ba.tar.gz
MultiMC-794102b32cb9b9c0ddb0c8268c572acb256dd6ba.tar.lz
MultiMC-794102b32cb9b9c0ddb0c8268c572acb256dd6ba.tar.xz
MultiMC-794102b32cb9b9c0ddb0c8268c572acb256dd6ba.zip
NOISSUE less jumpy download progress bars and redirect URL fix
Diffstat (limited to 'api/logic')
-rw-r--r--api/logic/net/Download.cpp22
-rw-r--r--api/logic/net/Download.h1
-rw-r--r--api/logic/net/NetJob.cpp22
-rw-r--r--api/logic/net/NetJob.h4
4 files changed, 31 insertions, 18 deletions
diff --git a/api/logic/net/Download.cpp b/api/logic/net/Download.cpp
index b346d5e0..97b03ac2 100644
--- a/api/logic/net/Download.cpp
+++ b/api/logic/net/Download.cpp
@@ -106,6 +106,17 @@ void Download::executeTask()
void Download::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
+ // FIXME: ignore unknown size. for now.
+ if(bytesTotal == -1)
+ {
+ return;
+ }
+ // FIXME: ignore redirects... for now.
+ auto redirectURL = getRedirect();
+ if(!redirectURL.isEmpty())
+ {
+ return;
+ }
m_progressTotal = bytesTotal;
m_progress = bytesReceived;
emit progress(bytesReceived, bytesTotal);
@@ -134,7 +145,7 @@ void Download::downloadError(QNetworkReply::NetworkError error)
}
}
-bool Download::handleRedirect()
+QString Download::getRedirect()
{
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
QString redirectURL;
@@ -151,10 +162,15 @@ bool Download::handleRedirect()
redirectURL = m_reply->url().scheme() + ":" + data;
}
}
+ return redirectURL;
+}
+
+bool Download::handleRedirect()
+{
+ auto redirectURL = getRedirect();
if (!redirectURL.isEmpty())
{
- m_url = QUrl(redirect.toString());
- qDebug() << "Following redirect to " << m_url.toString();
+ m_url = QUrl(redirectURL);
start();
return true;
}
diff --git a/api/logic/net/Download.h b/api/logic/net/Download.h
index 31e51792..0188a8ae 100644
--- a/api/logic/net/Download.h
+++ b/api/logic/net/Download.h
@@ -53,6 +53,7 @@ public: /* methods */
bool canAbort() const override;
private: /* methods */
+ QString getRedirect();
bool handleRedirect();
protected slots:
diff --git a/api/logic/net/NetJob.cpp b/api/logic/net/NetJob.cpp
index cf04998f..ff2c711b 100644
--- a/api/logic/net/NetJob.cpp
+++ b/api/logic/net/NetJob.cpp
@@ -69,14 +69,16 @@ void NetJob::partProgress(qint64 bytesReceived, qint64 bytesTotal)
void NetJob::setPartProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
{
auto &slot = m_parts[index];
-
- current_progress -= slot.current_progress;
slot.current_progress = bytesReceived;
- current_progress += slot.current_progress;
-
- total_progress -= slot.total_progress;
slot.total_progress = bytesTotal;
- total_progress += slot.total_progress;
+ qint64 current_progress = m_done.count() * 100;
+ qint64 total_progress = m_parts.count() * 100;
+ for(auto iter = m_doing.begin(); iter != m_doing.end(); iter++)
+ {
+ auto &part = m_parts[*iter];
+ float percentage = (float(part.current_progress) / float(part.total_progress)) * 100.0f;
+ current_progress += (qint64) percentage;
+ }
setProgress(current_progress, total_progress);
}
@@ -196,14 +198,8 @@ void NetJob::addNetAction(NetActionPtr action)
}
m_parts.append(pi);
- total_progress += pi.total_progress;
- current_progress += pi.current_progress;
-
- // if this is already running, the action needs to be started right away!
if (isRunning())
{
- setProgress(current_progress, total_progress);
- connectAction(action.get());
- action->start();
+ m_todo.enqueue(m_parts.size() - 1);
}
}
diff --git a/api/logic/net/NetJob.h b/api/logic/net/NetJob.h
index 637c4af5..5503cd24 100644
--- a/api/logic/net/NetJob.h
+++ b/api/logic/net/NetJob.h
@@ -76,7 +76,7 @@ private:
QSet<int> m_doing;
QSet<int> m_done;
QSet<int> m_failed;
- qint64 current_progress = 0;
- qint64 total_progress = 0;
+ //qint64 current_progress = 0;
+ //qint64 total_progress = 0;
bool m_aborted = false;
};