refactor: make shared_qobject_ptr ctor explicit

This turns issues like creating two shared ptrs from a single raw ptr
from popping up at runtime, instead making them a compile error.

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow
2023-01-24 16:52:09 -03:00
parent 5186ad95d3
commit 29f7ea752f
63 changed files with 301 additions and 287 deletions

View File

@ -265,7 +265,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
return { pixmap };
if (!m_current_icon_job)
m_current_icon_job = new NetJob("IconJob", APPLICATION->network());
m_current_icon_job.reset(new NetJob("IconJob", APPLICATION->network()));
if (m_currently_running_icon_actions.contains(url))
return {};

View File

@ -86,14 +86,14 @@ void ListModel::request()
modpacks.clear();
endResetModel();
auto *netJob = new NetJob("Atl::Request", APPLICATION->network());
auto netJob = makeShared<NetJob>("Atl::Request", APPLICATION->network());
auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/json/packsnew.json");
netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::requestFinished);
QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed);
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::requestFinished);
QObject::connect(netJob.get(), &NetJob::failed, this, &ListModel::requestFailed);
}
void ListModel::requestFinished()

View File

@ -155,7 +155,7 @@ void ListModel::fetchMore(const QModelIndex& parent)
void ListModel::performPaginatedSearch()
{
NetJob* netJob = new NetJob("Flame::Search", APPLICATION->network());
auto netJob = makeShared<NetJob>("Flame::Search", APPLICATION->network());
auto searchUrl = QString(
"https://api.curseforge.com/v1/mods/search?"
"gameId=432&"
@ -172,8 +172,8 @@ void ListModel::performPaginatedSearch()
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::searchRequestFinished);
QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed);
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::searchRequestFinished);
QObject::connect(netJob.get(), &NetJob::failed, this, &ListModel::searchRequestFailed);
}
void ListModel::searchWithTerm(const QString& term, int sort)

View File

@ -109,14 +109,14 @@ void ListModel::request()
modpacks.clear();
endResetModel();
auto *netJob = new NetJob("Ftb::Request", APPLICATION->network());
auto netJob = makeShared<NetJob>("Ftb::Request", APPLICATION->network());
auto url = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all");
netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::requestFinished);
QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed);
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::requestFinished);
QObject::connect(netJob.get(), &NetJob::failed, this, &ListModel::requestFailed);
}
void ListModel::abortRequest()
@ -158,14 +158,14 @@ void ListModel::requestFailed(QString reason)
void ListModel::requestPack()
{
auto *netJob = new NetJob("Ftb::Search", APPLICATION->network());
auto netJob = makeShared<NetJob>("Ftb::Search", APPLICATION->network());
auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1").arg(currentPack);
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::packRequestFinished);
QObject::connect(netJob, &NetJob::failed, this, &ListModel::packRequestFailed);
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::packRequestFinished);
QObject::connect(netJob.get(), &NetJob::failed, this, &ListModel::packRequestFailed);
}
void ListModel::packRequestFinished()
@ -281,16 +281,16 @@ void ListModel::requestLogo(QString logo, QString url)
bool stale = entry->isStale();
NetJob *job = new NetJob(QString("ModpacksCH Icon Download %1").arg(logo), APPLICATION->network());
auto job = makeShared<NetJob>(QString("ModpacksCH Icon Download %1").arg(logo), APPLICATION->network());
job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::finished, this, [this, logo, fullPath, stale]
QObject::connect(job.get(), &NetJob::finished, this, [this, logo, fullPath, stale]
{
logoLoaded(logo, stale);
});
QObject::connect(job, &NetJob::failed, this, [this, logo]
QObject::connect(job.get(), &NetJob::failed, this, [this, logo]
{
logoFailed(logo);
});

View File

@ -127,7 +127,7 @@ bool ModpackListModel::setData(const QModelIndex &index, const QVariant &value,
void ModpackListModel::performPaginatedSearch()
{
// TODO: Move to standalone API
NetJob* netJob = new NetJob("Modrinth::SearchModpack", APPLICATION->network());
auto netJob = makeShared<NetJob>("Modrinth::SearchModpack", APPLICATION->network());
auto searchAllUrl = QString(BuildConfig.MODRINTH_PROD_URL +
"/search?"
"offset=%1&"
@ -142,7 +142,7 @@ void ModpackListModel::performPaginatedSearch()
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchAllUrl), &m_all_response));
QObject::connect(netJob, &NetJob::succeeded, this, [this] {
QObject::connect(netJob.get(), &NetJob::succeeded, this, [this] {
QJsonParseError parse_error_all{};
QJsonDocument doc_all = QJsonDocument::fromJson(m_all_response, &parse_error_all);
@ -155,7 +155,7 @@ void ModpackListModel::performPaginatedSearch()
searchRequestFinished(doc_all);
});
QObject::connect(netJob, &NetJob::failed, this, &ModpackListModel::searchRequestFailed);
QObject::connect(netJob.get(), &NetJob::failed, this, &ModpackListModel::searchRequestFailed);
jobPtr = netJob;
jobPtr->start();

View File

@ -112,7 +112,7 @@ void Technic::ListModel::searchWithTerm(const QString& term)
void Technic::ListModel::performSearch()
{
NetJob *netJob = new NetJob("Technic::Search", APPLICATION->network());
auto netJob = makeShared<NetJob>("Technic::Search", APPLICATION->network());
QString searchUrl = "";
if (currentSearchTerm.isEmpty()) {
searchUrl = QString("%1trending?build=%2")
@ -137,8 +137,8 @@ void Technic::ListModel::performSearch()
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::searchRequestFinished);
QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed);
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::searchRequestFinished);
QObject::connect(netJob.get(), &NetJob::failed, this, &ListModel::searchRequestFailed);
}
void Technic::ListModel::searchRequestFinished()

View File

@ -141,10 +141,10 @@ void TechnicPage::suggestCurrent()
return;
}
NetJob *netJob = new NetJob(QString("Technic::PackMeta(%1)").arg(current.name), APPLICATION->network());
auto netJob = makeShared<NetJob>(QString("Technic::PackMeta(%1)").arg(current.name), APPLICATION->network());
QString slug = current.slug;
netJob->addNetAction(Net::Download::makeByteArray(QString("%1modpack/%2?build=%3").arg(BuildConfig.TECHNIC_API_BASE_URL, slug, BuildConfig.TECHNIC_API_BUILD), &response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, slug]
QObject::connect(netJob.get(), &NetJob::succeeded, this, [this, slug]
{
jobPtr.reset();
@ -247,11 +247,11 @@ void TechnicPage::metadataLoaded()
// version so we can display something quicker
ui->versionSelectionBox->addItem(current.currentVersion);
auto* netJob = new NetJob(QString("Technic::SolderMeta(%1)").arg(current.name), APPLICATION->network());
auto netJob = makeShared<NetJob>(QString("Technic::SolderMeta(%1)").arg(current.name), APPLICATION->network());
auto url = QString("%1/modpack/%2").arg(current.url, current.slug);
netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response));
QObject::connect(netJob, &NetJob::succeeded, this, &TechnicPage::onSolderLoaded);
QObject::connect(netJob.get(), &NetJob::succeeded, this, &TechnicPage::onSolderLoaded);
jobPtr = netJob;
jobPtr->start();