Commit c77e9542 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Folder Model] Introduce status enum

This allows to use bindings for properties like plasmoid.busy

Differential Revision: https://phabricator.kde.org/D7598
parent 5a5b8f7e
......@@ -158,6 +158,12 @@ Item {
when: toolBox
}
Binding {
target: plasmoid
property: "busy"
value: !gridView.model && dir.status === Folder.FolderModel.Listing
}
function makeBackButton() {
return Qt.createQmlObject("BackButtonItem {}", main);
}
......@@ -1054,21 +1060,12 @@ Item {
previews: plasmoid.configuration.previews
previewPlugins: plasmoid.configuration.previewPlugins
onListingStarted: {
if (!gridView.model) {
plasmoid.busy = true;
}
}
onListingCompleted: {
if (!gridView.model) {
plasmoid.busy = false;
gridView.model = positioner;
}
}
onListingCanceled: plasmoid.busy = false;
onMove: {
var rows = (gridView.flow == GridView.FlowLeftToRight);
var axis = rows ? gridView.width : gridView.height;
......
......@@ -119,11 +119,20 @@ FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent),
dirLister->setAutoErrorHandlingEnabled(false, 0);
connect(dirLister, &DirLister::error, this, &FolderModel::dirListFailed);
connect(dirLister, &KCoreDirLister::itemsDeleted, this, &FolderModel::evictFromIsDirCache);
connect(dirLister, &KCoreDirLister::started, this, &FolderModel::listingStarted);
connect(dirLister, &KCoreDirLister::started, this, std::bind(&FolderModel::setStatus, this, Status::Listing));
void (KCoreDirLister::*myCompletedSignal)() = &KCoreDirLister::completed;
QObject::connect(dirLister, myCompletedSignal, this, &FolderModel::listingCompleted);
QObject::connect(dirLister, myCompletedSignal, this, [this] {
setStatus(Status::Ready);
emit listingCompleted();
});
void (KCoreDirLister::*myCanceledSignal)() = &KCoreDirLister::canceled;
QObject::connect(dirLister, myCanceledSignal, this, &FolderModel::listingCanceled);
QObject::connect(dirLister, myCanceledSignal, this, [this] {
setStatus(Status::Canceled);
emit listingCanceled();
});
m_dirModel = new KDirModel(this);
m_dirModel->setDirLister(dirLister);
......@@ -249,6 +258,19 @@ QString FolderModel::iconName() const
return rootItem.iconName();
}
FolderModel::Status FolderModel::status() const
{
return m_status;
}
void FolderModel::setStatus(Status status)
{
if (m_status != status) {
m_status = status;
emit statusChanged();
}
}
QString FolderModel::errorString() const
{
return m_errorString;
......
......@@ -76,6 +76,7 @@ class FolderModel : public QSortFilterProxyModel
Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(QString iconName READ iconName NOTIFY iconNameChanged)
Q_PROPERTY(QUrl resolvedUrl READ resolvedUrl NOTIFY resolvedUrlChanged)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
Q_PROPERTY(bool dragging READ dragging NOTIFY draggingChanged)
Q_PROPERTY(bool usedByContainment READ usedByContainment WRITE setUsedByContainment NOTIFY usedByContainmentChanged)
......@@ -113,6 +114,14 @@ class FolderModel : public QSortFilterProxyModel
FilterHideMatches
};
enum Status {
None,
Ready,
Listing,
Canceled
};
Q_ENUM(Status)
FolderModel(QObject *parent = 0);
~FolderModel();
......@@ -127,6 +136,8 @@ class FolderModel : public QSortFilterProxyModel
QUrl resolvedUrl() const;
Q_INVOKABLE QUrl resolve(const QString& url);
Status status() const;
QString errorString() const;
bool dragging() const;
......@@ -221,11 +232,11 @@ class FolderModel : public QSortFilterProxyModel
Q_SIGNALS:
void urlChanged() const;
void listingStarted() const;
void listingCompleted() const;
void listingCanceled() const;
void iconNameChanged() const;
void resolvedUrlChanged() const;
void statusChanged() const;
void errorStringChanged() const;
void draggingChanged() const;
void usedByContainmentChanged() const;
......@@ -273,6 +284,7 @@ class FolderModel : public QSortFilterProxyModel
void createActions();
void updatePasteAction();
void addDragImage(QDrag *drag, int x, int y);
void setStatus(Status status);
QList<QUrl> selectedUrls(bool forTrash) const;
KDirModel *m_dirModel;
KDirWatch *m_dirWatch;
......@@ -291,6 +303,7 @@ class FolderModel : public QSortFilterProxyModel
KNewFileMenu *m_newMenu;
KFileItemActions *m_fileItemActions;
KFileCopyToMenu *m_copyToMenu;
Status m_status = Status::None;
QString m_errorString;
bool m_usedByContainment;
bool m_locked;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment