NOISSUE refactor *Download into more, smaller pieces
* Download is now Download. * Download uses Sink subclasses to process various events. * Validators can be used to further customize the Sink behaviour.
This commit is contained in:
@@ -59,7 +59,7 @@
|
||||
#include <SkinUtils.h>
|
||||
#include <net/URLConstants.h>
|
||||
#include <net/NetJob.h>
|
||||
#include <net/CacheDownload.h>
|
||||
#include <net/Download.h>
|
||||
#include <news/NewsChecker.h>
|
||||
#include <notifications/NotificationChecker.h>
|
||||
#include <tools/BaseProfiler.h>
|
||||
@@ -519,7 +519,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
||||
|
||||
auto accounts = MMC->accounts();
|
||||
|
||||
QList<CacheDownloadPtr> skin_dls;
|
||||
QList<Net::Download::Ptr> skin_dls;
|
||||
for (int i = 0; i < accounts->count(); i++)
|
||||
{
|
||||
auto account = accounts->at(i);
|
||||
@@ -531,7 +531,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
||||
for (auto profile : account->profiles())
|
||||
{
|
||||
auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.id + ".png");
|
||||
auto action = CacheDownload::make(QUrl("https://" + URLConstants::SKINS_BASE + profile.id + ".png"), meta);
|
||||
auto action = Net::Download::makeCached(QUrl("https://" + URLConstants::SKINS_BASE + profile.id + ".png"), meta);
|
||||
skin_dls.append(action);
|
||||
meta->setStale(true);
|
||||
}
|
||||
@@ -1045,9 +1045,8 @@ InstancePtr MainWindow::instanceFromZipPack(QString instName, QString instGroup,
|
||||
const QString path = url.host() + '/' + url.path();
|
||||
auto entry = ENV.metacache()->resolveEntry("general", path);
|
||||
entry->setStale(true);
|
||||
CacheDownloadPtr dl = CacheDownload::make(url, entry);
|
||||
NetJob job(tr("Modpack download"));
|
||||
job.addNetAction(dl);
|
||||
job.addNetAction(Net::Download::makeCached(url, entry));
|
||||
|
||||
// FIXME: possibly causes endless loop problems
|
||||
ProgressDialog dlDialog(this);
|
||||
|
@@ -109,16 +109,16 @@ AboutDialog::~AboutDialog()
|
||||
|
||||
void AboutDialog::loadPatronList()
|
||||
{
|
||||
NetJob* job = new NetJob("Patreon Patron List");
|
||||
patronListDownload = ByteArrayDownload::make(QUrl("http://files.multimc.org/patrons.txt"));
|
||||
job->addNetAction(patronListDownload);
|
||||
connect(job, &NetJob::succeeded, this, &AboutDialog::patronListLoaded);
|
||||
job->start();
|
||||
netJob.reset(new NetJob("Patreon Patron List"));
|
||||
netJob->addNetAction(Net::Download::makeByteArray(QUrl("http://files.multimc.org/patrons.txt"), &dataSink));
|
||||
connect(netJob.get(), &NetJob::succeeded, this, &AboutDialog::patronListLoaded);
|
||||
netJob->start();
|
||||
}
|
||||
|
||||
void AboutDialog::patronListLoaded()
|
||||
{
|
||||
QString patronListStr(patronListDownload->m_data);
|
||||
QString patronListStr(dataSink);
|
||||
dataSink.clear();
|
||||
QString html = getCreditsHtml(patronListStr.split("\n", QString::SkipEmptyParts));
|
||||
ui->creditsText->setHtml(html);
|
||||
}
|
||||
|
@@ -16,8 +16,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include <net/ByteArrayDownload.h>
|
||||
#include <net/NetJob.h>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@@ -43,5 +42,6 @@ slots:
|
||||
private:
|
||||
Ui::AboutDialog *ui;
|
||||
|
||||
ByteArrayDownloadPtr patronListDownload;
|
||||
NetJobPtr netJob;
|
||||
QByteArray dataSink;
|
||||
};
|
||||
|
@@ -46,8 +46,7 @@ void UpdateDialog::loadChangelog()
|
||||
url = QString("https://api.github.com/repos/MultiMC/MultiMC5/compare/%1...%2").arg(BuildConfig.GIT_COMMIT, channel);
|
||||
m_changelogType = CHANGELOG_COMMITS;
|
||||
}
|
||||
changelogDownload = ByteArrayDownload::make(QUrl(url));
|
||||
dljob->addNetAction(changelogDownload);
|
||||
dljob->addNetAction(Net::Download::makeByteArray(QUrl(url), &changelogData));
|
||||
connect(dljob.get(), &NetJob::succeeded, this, &UpdateDialog::changelogLoaded);
|
||||
connect(dljob.get(), &NetJob::failed, this, &UpdateDialog::changelogFailed);
|
||||
dljob->start();
|
||||
@@ -201,12 +200,13 @@ void UpdateDialog::changelogLoaded()
|
||||
switch(m_changelogType)
|
||||
{
|
||||
case CHANGELOG_COMMITS:
|
||||
result = reprocessCommits(changelogDownload->m_data);
|
||||
result = reprocessCommits(changelogData);
|
||||
break;
|
||||
case CHANGELOG_MARKDOWN:
|
||||
result = reprocessMarkdown(changelogDownload->m_data);
|
||||
result = reprocessMarkdown(changelogData);
|
||||
break;
|
||||
}
|
||||
changelogData.clear();
|
||||
ui->changelogBrowser->setHtml(result);
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "net/ByteArrayDownload.h"
|
||||
#include "net/NetJob.h"
|
||||
|
||||
namespace Ui
|
||||
@@ -60,7 +59,7 @@ public slots:
|
||||
void changelogFailed(QString reason);
|
||||
|
||||
private:
|
||||
ByteArrayDownloadPtr changelogDownload;
|
||||
QByteArray changelogData;
|
||||
NetJobPtr dljob;
|
||||
ChangelogType m_changelogType = CHANGELOG_MARKDOWN;
|
||||
};
|
||||
|
@@ -131,8 +131,7 @@ void AccountListPage::addAccount(const QString &errMsg)
|
||||
for (AccountProfile profile : account->profiles())
|
||||
{
|
||||
auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.id + ".png");
|
||||
auto action = CacheDownload::make(
|
||||
QUrl("https://" + URLConstants::SKINS_BASE + profile.id + ".png"), meta);
|
||||
auto action = Net::Download::makeCached(QUrl("https://" + URLConstants::SKINS_BASE + profile.id + ".png"), meta);
|
||||
job->addNetAction(action);
|
||||
meta->setStale(true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user