diff --git a/gpt4all-chat/database.cpp b/gpt4all-chat/database.cpp index 1bb96115..949967e4 100644 --- a/gpt4all-chat/database.cpp +++ b/gpt4all-chat/database.cpp @@ -249,6 +249,7 @@ bool selectAllFromCollections(QSqlQuery &q, QList *collections) i.collection = q.value(0).toString(); i.folder_path = q.value(1).toString(); i.folder_id = q.value(0).toInt(); + i.installed = true; collections->append(i); } return true; diff --git a/gpt4all-chat/database.h b/gpt4all-chat/database.h index 59325ac4..b0e90472 100644 --- a/gpt4all-chat/database.h +++ b/gpt4all-chat/database.h @@ -29,6 +29,7 @@ struct CollectionItem { QString collection; QString folder_path; int folder_id = -1; + bool installed = false; }; Q_DECLARE_METATYPE(CollectionItem) diff --git a/gpt4all-chat/localdocs.cpp b/gpt4all-chat/localdocs.cpp index 7e4a910d..b121106f 100644 --- a/gpt4all-chat/localdocs.cpp +++ b/gpt4all-chat/localdocs.cpp @@ -33,11 +33,13 @@ LocalDocs::LocalDocs() void LocalDocs::addFolder(const QString &collection, const QString &path) { const QUrl url(path); - if (url.isLocalFile()) { - emit requestAddFolder(collection, url.toLocalFile()); - } else { - emit requestAddFolder(collection, path); - } + const QString localPath = url.isLocalFile() ? url.toLocalFile() : path; + // Add a placeholder collection that is not installed yet + CollectionItem i; + i.collection = collection; + i.folder_path = localPath; + m_localDocsModel->addCollectionItem(i); + emit requestAddFolder(collection, localPath); } void LocalDocs::removeFolder(const QString &collection, const QString &path) diff --git a/gpt4all-chat/localdocsmodel.cpp b/gpt4all-chat/localdocsmodel.cpp index f9670e42..8bd4fffd 100644 --- a/gpt4all-chat/localdocsmodel.cpp +++ b/gpt4all-chat/localdocsmodel.cpp @@ -22,6 +22,8 @@ QVariant LocalDocsModel::data(const QModelIndex &index, int role) const return item.collection; case FolderPathRole: return item.folder_path; + case InstalledRole: + return item.installed; } return QVariant(); @@ -32,9 +34,17 @@ QHash LocalDocsModel::roleNames() const QHash roles; roles[CollectionRole] = "collection"; roles[FolderPathRole] = "folder_path"; + roles[InstalledRole] = "installed"; return roles; } +void LocalDocsModel::addCollectionItem(const CollectionItem &item) +{ + beginInsertRows(QModelIndex(), m_collectionList.size(), m_collectionList.size()); + m_collectionList.append(item); + endInsertRows(); +} + void LocalDocsModel::handleCollectionListUpdated(const QList &collectionList) { beginResetModel(); diff --git a/gpt4all-chat/localdocsmodel.h b/gpt4all-chat/localdocsmodel.h index 2451537e..f3b30e6b 100644 --- a/gpt4all-chat/localdocsmodel.h +++ b/gpt4all-chat/localdocsmodel.h @@ -11,7 +11,8 @@ class LocalDocsModel : public QAbstractListModel public: enum Roles { CollectionRole = Qt::UserRole + 1, - FolderPathRole + FolderPathRole, + InstalledRole }; explicit LocalDocsModel(QObject *parent = nullptr); @@ -20,6 +21,7 @@ public: QHash roleNames() const override; public Q_SLOTS: + void addCollectionItem(const CollectionItem &item); void handleCollectionListUpdated(const QList &collectionList); private: diff --git a/gpt4all-chat/qml/LocalDocs.qml b/gpt4all-chat/qml/LocalDocs.qml index 487601ae..7659ba4d 100644 --- a/gpt4all-chat/qml/LocalDocs.qml +++ b/gpt4all-chat/qml/LocalDocs.qml @@ -166,7 +166,7 @@ Item { id: removeButton anchors.centerIn: parent text: qsTr("Remove") - visible: !item.removing + visible: !item.removing && installed onClicked: { item.removing = true LocalDocs.removeFolder(collection, folder_path) @@ -175,7 +175,7 @@ Item { MyBusyIndicator { id: busyIndicator anchors.centerIn: parent - visible: item.removing + visible: item.removing || !installed } } }