Commit 9ee9f113 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳
Browse files

mobile filechooser: Show inline message for errors

parent 02bcfbc6
......@@ -5,6 +5,7 @@ set(filepicker_lib_SRCS
declarative/dirmodelutils.cpp
declarative/fileplacesmodel.cpp
declarative/filechooserqmlcallback.cpp
declarative/dirlister.cpp
declarative/filepicker.qrc
)
......
......@@ -5,7 +5,7 @@
import QtQuick 2.7
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.2 as Controls
import org.kde.kirigami 2.5 as Kirigami
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kirigamifilepicker 0.1
......@@ -84,25 +84,36 @@ Kirigami.ScrollablePage {
root.fileUrlsChanged()
}
header: Controls.ToolBar {
Row {
Controls.ToolButton {
icon.name: "folder-root-symbolic"
height: parent.height
width: height
onClicked: dirModel.folder = "file:///"
}
Repeater {
model: DirModelUtils.getUrlParts(dirModel.folder)
header: ColumnLayout {
spacing: 0
Controls.ToolBar {
Layout.fillWidth: true
Row {
Controls.ToolButton {
icon.name: "arrow-right"
text: modelData
onClicked: dirModel.folder = DirModelUtils.partialUrlForIndex(
dirModel.folder, index)
icon.name: "folder-root-symbolic"
height: parent.height
width: height
onClicked: dirModel.folder = "file:///"
}
Repeater {
model: DirModelUtils.getUrlParts(dirModel.folder)
Controls.ToolButton {
icon.name: "arrow-right"
text: modelData
onClicked: dirModel.folder = DirModelUtils.partialUrlForIndex(
dirModel.folder, index)
}
}
}
}
Kirigami.InlineMessage {
id: errorMessage
Layout.fillWidth: true
type: Kirigami.MessageType.Error
text: dirModel.lastError
showCloseButton: true
}
}
footer: Controls.ToolBar {
visible: !root.selectExisting
......@@ -140,6 +151,8 @@ Kirigami.ScrollablePage {
folder: root.folder
showDotFiles: false
mimeFilters: root.mimeTypeFilters
onLastErrorChanged: errorMessage.visible = true
onFolderChanged: errorMessage.visible = false
}
Controls.BusyIndicator {
......
// SPDX-FileCopyrightText: 2020 Jonah Brüchert <jbb@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "dirlister.h"
#include <KIO/Job>
DirLister::DirLister(QObject *parent) : KDirLister(parent)
{
}
void DirLister::handleError(KIO::Job *job)
{
handleErrorMessage(job->errorString());
}
void DirLister::handleErrorMessage(const QString &message)
{
Q_EMIT errorOccured(message);
}
// SPDX-FileCopyrightText: 2020 Jonah Brüchert <jbb@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QObject>
#include <KIOWidgets/KDirLister>
class DirLister : public KDirLister
{
Q_OBJECT
public:
explicit DirLister(QObject *parent = nullptr);
void handleError(KIO::Job *job) override;
void handleErrorMessage(const QString &message) override;
Q_SIGNALS:
void errorOccured(const QString &message);
};
......@@ -8,12 +8,19 @@
#include <KIOWidgets/KDirModel>
#include <KIOWidgets/KDirLister>
#include "dirlister.h"
DirModel::DirModel(QObject *parent)
: KDirSortFilterProxyModel(parent)
, m_lister(m_dirModel.dirLister())
, m_lister(new DirLister(this))
{
setSourceModel(&m_dirModel);
m_dirModel.setDirLister(m_lister);
connect(m_lister, QOverload<>::of(&KCoreDirLister::completed), this, &DirModel::isLoadingChanged);
connect(m_lister, &DirLister::errorOccured, this, [this](const QString &message) {
m_lastError = message;
Q_EMIT lastErrorChanged();
});
}
QVariant DirModel::data(const QModelIndex &index, int role) const
......@@ -128,3 +135,8 @@ void DirModel::setMimeFilters(const QStringList &mimeFilters)
emit mimeFiltersChanged();
}
}
QString DirModel::lastError() const
{
return m_lastError;
}
......@@ -11,7 +11,7 @@
#include <KIOFileWidgets/KDirSortFilterProxyModel>
#include <KIOWidgets/KDirModel>
class KDirLister;
class DirLister;
class DirModel : public KDirSortFilterProxyModel
{
......@@ -22,6 +22,8 @@ class DirModel : public KDirSortFilterProxyModel
Q_PROPERTY(QString nameFilter READ nameFilter WRITE setNameFilter NOTIFY nameFilterChanged)
Q_PROPERTY(QStringList mimeFilters READ mimeFilters WRITE setMimeFilters NOTIFY mimeFiltersChanged)
Q_PROPERTY(QString lastError READ lastError NOTIFY lastErrorChanged);
public:
enum Roles {
Name = Qt::UserRole + 1,
......@@ -58,6 +60,8 @@ public:
QStringList mimeFilters() const;
void setMimeFilters(const QStringList &mimeFilters);
QString lastError() const;
Q_SIGNALS:
void folderChanged();
void showDotFilesChanged();
......@@ -65,7 +69,11 @@ Q_SIGNALS:
void nameFilterChanged();
void mimeFiltersChanged();
void lastErrorChanged();
private:
KDirModel m_dirModel;
KDirLister *m_lister;
DirLister *m_lister;
QString m_lastError;
};
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