Repository: nomic-ai/gpt4all
File: gpt4all-chat/download.cpp (C++)

Code before:
{
    const QString filePath = MySettings::globalInstance()->modelPath() + modelFile;
    QFile incompleteFile(ModelList::globalInstance()->incompleteDownloadPath(modelFile));
    if (incompleteFile.exists()) {
        incompleteFile.remove();
    }

    bool shouldRemoveInstalled = false;
    QFile file(filePath);
    if (file.exists()) {
        const ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile);
        shouldRemoveInstalled = info.installed && !info.isClone() && (info.isDiscovered() || info.description() == "" /*indicates sideloaded*/);
        if (shouldRemoveInstalled)
            ModelList::globalInstance()->removeInstalled(info);
        Network::globalInstance()->sendRemoveModel(modelFile);
        file.remove();
    }

    if (!shouldRemoveInstalled) {
        QVector<QPair<int, QVariant>> data;
        data.append({ ModelList::InstalledRole, false });
        data.append({ ModelList::BytesReceivedRole, 0 });
        data.append({ ModelList::BytesTotalRole, 0 });
        data.append({ ModelList::TimestampRole, 0 });
        data.append({ ModelList::SpeedRole, QString() });
        data.append({ ModelList::DownloadErrorRole, QString() });
        ModelList::globalInstance()->updateDataByFilename(modelFile, data);
    }
}

void Download::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
{
    QUrl url = reply->request().url();
    for (const auto &e : errors)
        qWarning() << "ERROR: Received ssl error:" << e.errorString() << "for" << url;
}

void Download::handleReleaseJsonDownloadFinished()
{
    QNetworkReply *jsonReply = qobject_cast<QNetworkReply *>(sender());
    if (!jsonReply)
        return;

    QByteArray jsonData = jsonReply->readAll();
    jsonReply->deleteLater();
    parseReleaseJsonFile(jsonData);
}

void Download::parseReleaseJsonFile(const QByteArray &jsonData)
{
    QJsonParseError err;

Review comment (suggestion):
You could also use brace initialization in places like this:
```suggestion
        QVector<QPair<int, QVariant>> data {
            { ModelList::InstalledRole, false },
            { ModelList::BytesReceivedRole, 0 },
            { ModelList::BytesTotalRole, 0 },
            { ModelList::TimestampRole, 0 },
            { ModelList::SpeedRole, QString() },
            { ModelList::DownloadErrorRole, QString() },
        };
```

Code after:
{
    const QString filePath = MySettings::globalInstance()->modelPath() + modelFile;
    QFile incompleteFile(ModelList::globalInstance()->incompleteDownloadPath(modelFile));
    if (incompleteFile.exists()) {
        incompleteFile.remove();
    }

    bool shouldRemoveInstalled = false;
    QFile file(filePath);
    if (file.exists()) {
        const ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile);
        shouldRemoveInstalled = info.installed && !info.isClone() && (info.isDiscovered() || info.description() == "" /*indicates sideloaded*/);
        if (shouldRemoveInstalled)
            ModelList::globalInstance()->removeInstalled(info);
        Network::globalInstance()->sendRemoveModel(modelFile);
        file.remove();
    }

    if (!shouldRemoveInstalled) {
        QVector<QPair<int, QVariant>> data {
            { ModelList::InstalledRole, false },
            { ModelList::BytesReceivedRole, 0 },
            { ModelList::BytesTotalRole, 0 },
            { ModelList::TimestampRole, 0 },
            { ModelList::SpeedRole, QString() },
            { ModelList::DownloadErrorRole, QString() },
        };
        ModelList::globalInstance()->updateDataByFilename(modelFile, data);
    }
}

void Download::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
{
    QUrl url = reply->request().url();
    for (const auto &e : errors)
        qWarning() << "ERROR: Received ssl error:" << e.errorString() << "for" << url;
}

void Download::handleReleaseJsonDownloadFinished()
{
    QNetworkReply *jsonReply = qobject_cast<QNetworkReply *>(sender());
    if (!jsonReply)
        return;

    QByteArray jsonData = jsonReply->readAll();
    jsonReply->deleteLater();
    parseReleaseJsonFile(jsonData);
}

void Download::parseReleaseJsonFile(const QByteArray &jsonData)
{