From 631a45394ee57802422e8ea9d1190ebaed0c5e67 Mon Sep 17 00:00:00 2001 From: reionwong Date: Wed, 1 Sep 2021 05:31:38 +0800 Subject: [PATCH] Error notification --- model/foldermodel.cpp | 6 ++++++ model/foldermodel.h | 2 ++ qml/Dialogs/OpenWithDialog.qml | 1 + qml/FolderPage.qml | 8 ++++++++ 4 files changed, 17 insertions(+) diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index d133b8d..958898b 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -85,6 +85,7 @@ FolderModel::FolderModel(QObject *parent) DirLister *dirLister = new DirLister(this); dirLister->setDelayedMimeTypes(true); dirLister->setAutoErrorHandlingEnabled(false, nullptr); + // connect(dirLister, &DirLister::error, this, &FolderModel::notification); m_dirModel = new KDirModel(this); m_dirModel->setDirLister(dirLister); @@ -242,6 +243,11 @@ void FolderModel::setUrl(const QString &url) const QUrl &resolvedNewUrl = resolve(url); + if (!QFile::exists(resolvedNewUrl.toLocalFile()) && !url.startsWith("trash:/")) { + emit notification(tr("The file or folder %1 does not exist.").arg(url)); + return; + } + // Refresh this directory. if (url == m_url) { m_dirModel->dirLister()->updateDirectory(resolvedNewUrl); diff --git a/model/foldermodel.h b/model/foldermodel.h index 3b211de..071959f 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -217,6 +217,8 @@ signals: void filterPatternChanged(); void filterMimeTypesChanged(); + void notification(const QString &message); + private slots: void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void dragSelectedInternal(int x, int y); diff --git a/qml/Dialogs/OpenWithDialog.qml b/qml/Dialogs/OpenWithDialog.qml index d19a622..945e30a 100644 --- a/qml/Dialogs/OpenWithDialog.qml +++ b/qml/Dialogs/OpenWithDialog.qml @@ -158,6 +158,7 @@ Item { focus: true flat: true text: qsTr("Open") + enabled: listView.count > 0 Layout.fillWidth: true onClicked: control.openApp() } diff --git a/qml/FolderPage.qml b/qml/FolderPage.qml index dd5edd1..db09609 100644 --- a/qml/FolderPage.qml +++ b/qml/FolderPage.qml @@ -150,6 +150,14 @@ Item { } } + Connections { + target: dirModel + + function onNotification(text) { + root.showPassiveNotification(text, 3000) + } + } + FM.ItemViewAdapter { id: viewAdapter adapterView: _viewLoader.item