Update batch patch following review.

Signed-off-by: Adam Treat <treat.adam@gmail.com>
This commit is contained in:
Adam Treat 2024-03-08 08:12:49 -05:00 committed by AT
parent 8474d76fec
commit 099459c8b9

View File

@ -128,9 +128,7 @@ void Download::downloadModel(const QString &modelFile)
return; return;
} }
QVector<QPair<int, QVariant>> data; ModelList::globalInstance()->updateDataByFilename(modelFile, {{ ModelList::DownloadingRole, true }});
data.append(qMakePair(ModelList::DownloadingRole, true));
ModelList::globalInstance()->updateDataByFilename(modelFile, data);
ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile); ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile);
QString url = !info.url().isEmpty() ? info.url() : "http://gpt4all.io/models/gguf/" + modelFile; QString url = !info.url().isEmpty() ? info.url() : "http://gpt4all.io/models/gguf/" + modelFile;
Network::globalInstance()->sendDownloadStarted(modelFile); Network::globalInstance()->sendDownloadStarted(modelFile);
@ -168,9 +166,7 @@ void Download::cancelDownload(const QString &modelFile)
tempFile->deleteLater(); tempFile->deleteLater();
m_activeDownloads.remove(modelReply); m_activeDownloads.remove(modelReply);
QVector<QPair<int, QVariant>> data; ModelList::globalInstance()->updateDataByFilename(modelFile, {{ ModelList::DownloadingRole, false }});
data.append(qMakePair(ModelList::DownloadingRole, false));
ModelList::globalInstance()->updateDataByFilename(modelFile, data);
break; break;
} }
} }
@ -192,9 +188,7 @@ void Download::installModel(const QString &modelFile, const QString &apiKey)
ModelList::globalInstance()->updateModelsFromDirectory(); ModelList::globalInstance()->updateModelsFromDirectory();
} }
QVector<QPair<int, QVariant>> data; ModelList::globalInstance()->updateDataByFilename(modelFile, {{ ModelList::InstalledRole, true }});
data.append(qMakePair(ModelList::InstalledRole, true));
ModelList::globalInstance()->updateDataByFilename(modelFile, data);
} }
void Download::removeModel(const QString &modelFile) void Download::removeModel(const QString &modelFile)
@ -209,7 +203,7 @@ void Download::removeModel(const QString &modelFile)
QFile file(filePath); QFile file(filePath);
if (file.exists()) { if (file.exists()) {
const ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile); const ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile);
shouldRemoveInstalled = info.installed && !info.isClone() && (info.isDiscovered() || info.description() == ""); shouldRemoveInstalled = info.installed && !info.isClone() && (info.isDiscovered() || info.description() == "" /*indicates sideloaded*/);
if (shouldRemoveInstalled) if (shouldRemoveInstalled)
ModelList::globalInstance()->removeInstalled(info); ModelList::globalInstance()->removeInstalled(info);
Network::globalInstance()->sendRemoveModel(modelFile); Network::globalInstance()->sendRemoveModel(modelFile);
@ -326,9 +320,7 @@ void Download::handleErrorOccurred(QNetworkReply::NetworkError code)
.arg(code) .arg(code)
.arg(modelReply->errorString()); .arg(modelReply->errorString());
qWarning() << error; qWarning() << error;
QVector<QPair<int, QVariant>> data; ModelList::globalInstance()->updateDataByFilename(modelFilename, {{ ModelList::DownloadErrorRole, error }});
data.append(qMakePair(ModelList::DownloadErrorRole, error));
ModelList::globalInstance()->updateDataByFilename(modelFilename, data);
Network::globalInstance()->sendDownloadError(modelFilename, (int)code, modelReply->errorString()); Network::globalInstance()->sendDownloadError(modelFilename, (int)code, modelReply->errorString());
cancelDownload(modelFilename); cancelDownload(modelFilename);
} }
@ -495,9 +487,7 @@ void Download::handleModelDownloadFinished()
} }
// Notify that we are calculating hash // Notify that we are calculating hash
QVector<QPair<int, QVariant>> data; ModelList::globalInstance()->updateDataByFilename(modelFilename, {{ ModelList::CalcHashRole, true }});
data.append(qMakePair(ModelList::CalcHashRole, true));
ModelList::globalInstance()->updateDataByFilename(modelFilename, data);
QByteArray hash = ModelList::globalInstance()->modelInfoByFilename(modelFilename).hash; QByteArray hash = ModelList::globalInstance()->modelInfoByFilename(modelFilename).hash;
ModelInfo::HashAlgorithm hashAlgorithm = ModelList::globalInstance()->modelInfoByFilename(modelFilename).hashAlgorithm; ModelInfo::HashAlgorithm hashAlgorithm = ModelList::globalInstance()->modelInfoByFilename(modelFilename).hashAlgorithm;
const QString saveFilePath = MySettings::globalInstance()->modelPath() + modelFilename; const QString saveFilePath = MySettings::globalInstance()->modelPath() + modelFilename;