Add a collection immediately and show a placeholder + busy indicator in localdocs settings.

This commit is contained in:
Adam Treat 2023-06-03 10:08:59 -04:00
parent 23391d44e0
commit bc624f5389
6 changed files with 24 additions and 8 deletions

View File

@ -249,6 +249,7 @@ bool selectAllFromCollections(QSqlQuery &q, QList<CollectionItem> *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;

View File

@ -29,6 +29,7 @@ struct CollectionItem {
QString collection;
QString folder_path;
int folder_id = -1;
bool installed = false;
};
Q_DECLARE_METATYPE(CollectionItem)

View File

@ -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)

View File

@ -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<int, QByteArray> LocalDocsModel::roleNames() const
QHash<int, QByteArray> 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<CollectionItem> &collectionList)
{
beginResetModel();

View File

@ -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<int, QByteArray> roleNames() const override;
public Q_SLOTS:
void addCollectionItem(const CollectionItem &item);
void handleCollectionListUpdated(const QList<CollectionItem> &collectionList);
private:

View File

@ -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
}
}
}