|
|
|
@ -63,11 +63,17 @@ void ChatListModel::removeChatFile(Chat *chat) const
|
|
|
|
|
qWarning() << "ERROR: Couldn't remove chat file:" << file.fileName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChatListModel::saveChats() const
|
|
|
|
|
ChatSaver::ChatSaver()
|
|
|
|
|
: QObject(nullptr)
|
|
|
|
|
{
|
|
|
|
|
moveToThread(&m_thread);
|
|
|
|
|
m_thread.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChatListModel::saveChats()
|
|
|
|
|
{
|
|
|
|
|
QElapsedTimer timer;
|
|
|
|
|
timer.start();
|
|
|
|
|
const QString savePath = Download::globalInstance()->downloadLocalModelsPath();
|
|
|
|
|
QVector<Chat*> toSave;
|
|
|
|
|
for (Chat *chat : m_chats) {
|
|
|
|
|
if (chat == m_serverChat)
|
|
|
|
|
continue;
|
|
|
|
@ -76,6 +82,23 @@ void ChatListModel::saveChats() const
|
|
|
|
|
continue;
|
|
|
|
|
if (isChatGPT && !m_shouldSaveChatGPTChats)
|
|
|
|
|
continue;
|
|
|
|
|
toSave.append(chat);
|
|
|
|
|
}
|
|
|
|
|
if (toSave.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ChatSaver *saver = new ChatSaver;
|
|
|
|
|
connect(this, &ChatListModel::requestSaveChats, saver, &ChatSaver::saveChats, Qt::QueuedConnection);
|
|
|
|
|
connect(saver, &ChatSaver::saveChatsFinished, this, &ChatListModel::saveChatsFinished, Qt::QueuedConnection);
|
|
|
|
|
emit requestSaveChats(toSave);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChatSaver::saveChats(const QVector<Chat *> &chats)
|
|
|
|
|
{
|
|
|
|
|
QElapsedTimer timer;
|
|
|
|
|
timer.start();
|
|
|
|
|
const QString savePath = Download::globalInstance()->downloadLocalModelsPath();
|
|
|
|
|
for (Chat *chat : chats) {
|
|
|
|
|
QString fileName = "gpt4all-" + chat->id() + ".chat";
|
|
|
|
|
QFile file(savePath + "/" + fileName);
|
|
|
|
|
bool success = file.open(QIODevice::WriteOnly);
|
|
|
|
@ -98,6 +121,7 @@ void ChatListModel::saveChats() const
|
|
|
|
|
}
|
|
|
|
|
qint64 elapsedTime = timer.elapsed();
|
|
|
|
|
qDebug() << "serializing chats took:" << elapsedTime << "ms";
|
|
|
|
|
emit saveChatsFinished();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChatsRestoreThread::run()
|
|
|
|
|