mirror of
				https://github.com/nomic-ai/gpt4all.git
				synced 2025-10-31 13:51:43 +00:00 
			
		
		
		
	Add a collection immediately and show a placeholder + busy indicator in localdocs settings.
This commit is contained in:
		| @@ -249,6 +249,7 @@ bool selectAllFromCollections(QSqlQuery &q, QList<CollectionItem> *collections) | |||||||
|         i.collection = q.value(0).toString(); |         i.collection = q.value(0).toString(); | ||||||
|         i.folder_path = q.value(1).toString(); |         i.folder_path = q.value(1).toString(); | ||||||
|         i.folder_id = q.value(0).toInt(); |         i.folder_id = q.value(0).toInt(); | ||||||
|  |         i.installed = true; | ||||||
|         collections->append(i); |         collections->append(i); | ||||||
|     } |     } | ||||||
|     return true; |     return true; | ||||||
|   | |||||||
| @@ -29,6 +29,7 @@ struct CollectionItem { | |||||||
|     QString collection; |     QString collection; | ||||||
|     QString folder_path; |     QString folder_path; | ||||||
|     int folder_id = -1; |     int folder_id = -1; | ||||||
|  |     bool installed = false; | ||||||
| }; | }; | ||||||
| Q_DECLARE_METATYPE(CollectionItem) | Q_DECLARE_METATYPE(CollectionItem) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -33,11 +33,13 @@ LocalDocs::LocalDocs() | |||||||
| void LocalDocs::addFolder(const QString &collection, const QString &path) | void LocalDocs::addFolder(const QString &collection, const QString &path) | ||||||
| { | { | ||||||
|     const QUrl url(path); |     const QUrl url(path); | ||||||
|     if (url.isLocalFile()) { |     const QString localPath = url.isLocalFile() ? url.toLocalFile() : path; | ||||||
|         emit requestAddFolder(collection, url.toLocalFile()); |     // Add a placeholder collection that is not installed yet | ||||||
|     } else { |     CollectionItem i; | ||||||
|         emit requestAddFolder(collection, path); |     i.collection = collection; | ||||||
|     } |     i.folder_path = localPath; | ||||||
|  |     m_localDocsModel->addCollectionItem(i); | ||||||
|  |     emit requestAddFolder(collection, localPath); | ||||||
| } | } | ||||||
|  |  | ||||||
| void LocalDocs::removeFolder(const QString &collection, const QString &path) | void LocalDocs::removeFolder(const QString &collection, const QString &path) | ||||||
|   | |||||||
| @@ -22,6 +22,8 @@ QVariant LocalDocsModel::data(const QModelIndex &index, int role) const | |||||||
|             return item.collection; |             return item.collection; | ||||||
|         case FolderPathRole: |         case FolderPathRole: | ||||||
|             return item.folder_path; |             return item.folder_path; | ||||||
|  |         case InstalledRole: | ||||||
|  |             return item.installed; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return QVariant(); |     return QVariant(); | ||||||
| @@ -32,9 +34,17 @@ QHash<int, QByteArray> LocalDocsModel::roleNames() const | |||||||
|     QHash<int, QByteArray> roles; |     QHash<int, QByteArray> roles; | ||||||
|     roles[CollectionRole] = "collection"; |     roles[CollectionRole] = "collection"; | ||||||
|     roles[FolderPathRole] = "folder_path"; |     roles[FolderPathRole] = "folder_path"; | ||||||
|  |     roles[InstalledRole] = "installed"; | ||||||
|     return roles; |     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<CollectionItem> &collectionList) | void LocalDocsModel::handleCollectionListUpdated(const QList<CollectionItem> &collectionList) | ||||||
| { | { | ||||||
|     beginResetModel(); |     beginResetModel(); | ||||||
|   | |||||||
| @@ -11,7 +11,8 @@ class LocalDocsModel : public QAbstractListModel | |||||||
| public: | public: | ||||||
|     enum Roles { |     enum Roles { | ||||||
|         CollectionRole = Qt::UserRole + 1, |         CollectionRole = Qt::UserRole + 1, | ||||||
|         FolderPathRole |         FolderPathRole, | ||||||
|  |         InstalledRole | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     explicit LocalDocsModel(QObject *parent = nullptr); |     explicit LocalDocsModel(QObject *parent = nullptr); | ||||||
| @@ -20,6 +21,7 @@ public: | |||||||
|     QHash<int, QByteArray> roleNames() const override; |     QHash<int, QByteArray> roleNames() const override; | ||||||
|  |  | ||||||
| public Q_SLOTS: | public Q_SLOTS: | ||||||
|  |     void addCollectionItem(const CollectionItem &item); | ||||||
|     void handleCollectionListUpdated(const QList<CollectionItem> &collectionList); |     void handleCollectionListUpdated(const QList<CollectionItem> &collectionList); | ||||||
|  |  | ||||||
| private: | private: | ||||||
|   | |||||||
| @@ -166,7 +166,7 @@ Item { | |||||||
|                         id: removeButton |                         id: removeButton | ||||||
|                         anchors.centerIn: parent |                         anchors.centerIn: parent | ||||||
|                         text: qsTr("Remove") |                         text: qsTr("Remove") | ||||||
|                         visible: !item.removing |                         visible: !item.removing && installed | ||||||
|                         onClicked: { |                         onClicked: { | ||||||
|                             item.removing = true |                             item.removing = true | ||||||
|                             LocalDocs.removeFolder(collection, folder_path) |                             LocalDocs.removeFolder(collection, folder_path) | ||||||
| @@ -175,7 +175,7 @@ Item { | |||||||
|                     MyBusyIndicator { |                     MyBusyIndicator { | ||||||
|                         id: busyIndicator |                         id: busyIndicator | ||||||
|                         anchors.centerIn: parent |                         anchors.centerIn: parent | ||||||
|                         visible: item.removing |                         visible: item.removing || !installed | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user