Commit 0b81b4ba authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Use KDirLister directly now that it emits a jobError() signal

Since KIO 5.82, KCoreDirLister (the base class of KDirLister) emits a jobError()
signal when the ListJob used internally emits an error.

Drop KFileItemModelDirLister class, now redundant.

This also bump the KF version to 5.82.
parent 7908aff3
......@@ -8,7 +8,7 @@ set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE
project(Dolphin VERSION ${RELEASE_SERVICE_VERSION})
set(QT_MIN_VERSION "5.15.0")
set(KF5_MIN_VERSION "5.81.0")
set(KF5_MIN_VERSION "5.82.0")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
......
......@@ -82,7 +82,6 @@ target_sources(dolphinprivate PRIVATE
kitemviews/private/kdirectorycontentscounter.cpp
kitemviews/private/kdirectorycontentscounterworker.cpp
kitemviews/private/kfileitemclipboard.cpp
kitemviews/private/kfileitemmodeldirlister.cpp
kitemviews/private/kfileitemmodelfilter.cpp
kitemviews/private/kitemlistheaderwidget.cpp
kitemviews/private/kitemlistkeyboardsearchmanager.cpp
......
......@@ -11,7 +11,6 @@
#include "dolphinpart_ext.h"
#include "dolphinremoveaction.h"
#include "kitemviews/kfileitemmodel.h"
#include "kitemviews/private/kfileitemmodeldirlister.h"
#include "views/dolphinnewfilemenuobserver.h"
#include "views/dolphinremoteencoding.h"
#include "views/dolphinview.h"
......@@ -22,6 +21,7 @@
#include <KAuthorized>
#include <KConfigGroup>
#include <KDialogJobUiDelegate>
#include <KDirLister>
#include <KFileItemListProperties>
#include <KIconLoader>
#include <KJobWidgets>
......
......@@ -11,10 +11,10 @@
#include "dolphin_generalsettings.h"
#include "dolphin_detailsmodesettings.h"
#include "dolphindebug.h"
#include "private/kfileitemmodeldirlister.h"
#include "private/kfileitemmodelsortalgorithm.h"
#include <kio_version.h>
#include <KDirLister>
#include <KIO/Job>
#include <KLocalizedString>
#include <KUrlMimeData>
......@@ -53,7 +53,8 @@ KFileItemModel::KFileItemModel(QObject* parent) :
loadSortingSettings();
m_dirLister = new KFileItemModelDirLister(this);
m_dirLister = new KDirLister(this);
m_dirLister->setAutoErrorHandlingEnabled(false);
m_dirLister->setDelayedMimeTypes(true);
const QWidget* parentWidget = qobject_cast<QWidget*>(parent);
......@@ -61,23 +62,17 @@ KFileItemModel::KFileItemModel(QObject* parent) :
m_dirLister->setMainWindow(parentWidget->window());
}
connect(m_dirLister, &KFileItemModelDirLister::started, this, &KFileItemModel::directoryLoadingStarted);
connect(m_dirLister, &KCoreDirLister::started, this, &KFileItemModel::directoryLoadingStarted);
connect(m_dirLister, QOverload<>::of(&KCoreDirLister::canceled), this, &KFileItemModel::slotCanceled);
connect(m_dirLister, &KFileItemModelDirLister::itemsAdded, this, &KFileItemModel::slotItemsAdded);
connect(m_dirLister, &KFileItemModelDirLister::itemsDeleted, this, &KFileItemModel::slotItemsDeleted);
connect(m_dirLister, &KFileItemModelDirLister::refreshItems, this, &KFileItemModel::slotRefreshItems);
connect(m_dirLister, &KCoreDirLister::itemsAdded, this, &KFileItemModel::slotItemsAdded);
connect(m_dirLister, &KCoreDirLister::itemsDeleted, this, &KFileItemModel::slotItemsDeleted);
connect(m_dirLister, &KCoreDirLister::refreshItems, this, &KFileItemModel::slotRefreshItems);
connect(m_dirLister, QOverload<>::of(&KCoreDirLister::clear), this, &KFileItemModel::slotClear);
connect(m_dirLister, &KFileItemModelDirLister::infoMessage, this, &KFileItemModel::infoMessage);
connect(m_dirLister, &KFileItemModelDirLister::errorMessage, this, &KFileItemModel::errorMessage);
connect(m_dirLister, &KFileItemModelDirLister::percent, this, &KFileItemModel::directoryLoadingProgress);
connect(m_dirLister, &KCoreDirLister::infoMessage, this, &KFileItemModel::infoMessage);
connect(m_dirLister, &KCoreDirLister::jobError, this, &KFileItemModel::slotListerError);
connect(m_dirLister, &KCoreDirLister::percent, this, &KFileItemModel::directoryLoadingProgress);
connect(m_dirLister, QOverload<const QUrl&, const QUrl&>::of(&KCoreDirLister::redirection), this, &KFileItemModel::directoryRedirection);
connect(m_dirLister, &KFileItemModelDirLister::urlIsFileError, this, &KFileItemModel::urlIsFileError);
#if KIO_VERSION < QT_VERSION_CHECK(5, 79, 0)
connect(m_dirLister, QOverload<const QUrl&>::of(&KCoreDirLister::completed), this, &KFileItemModel::slotCompleted);
#else
connect(m_dirLister, &KCoreDirLister::listingDirCompleted, this, &KFileItemModel::slotCompleted);
#endif
// Apply default roles that should be determined
resetRoles();
......@@ -2501,3 +2496,15 @@ bool KFileItemModel::isConsistent() const
return true;
}
void KFileItemModel::slotListerError(KIO::Job *job)
{
if (job->error() == KIO::ERR_IS_FILE) {
if (auto *listJob = qobject_cast<KIO::ListJob *>(job)) {
Q_EMIT urlIsFileError(listJob->url());
}
} else {
const QString errorString = job->errorString();
Q_EMIT errorMessage(!errorString.isEmpty() ? errorString : i18nc("@info:status", "Unknown error."));
}
}
......@@ -20,9 +20,14 @@
#include <functional>
class KFileItemModelDirLister;
class KDirLister;
class QTimer;
namespace KIO {
class Job;
}
/**
* @brief KItemModelBase implementation for KFileItems.
*
......@@ -270,6 +275,7 @@ private Q_SLOTS:
void slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& items);
void slotClear();
void slotSortingChoiceChanged();
void slotListerError(KIO::Job *job);
void dispatchPendingItemsToInsert();
......@@ -458,7 +464,7 @@ private:
bool isConsistent() const;
private:
KFileItemModelDirLister* m_dirLister;
KDirLister *m_dirLister = nullptr;
QCollator m_collator;
bool m_naturalSorting;
......
/*
* SPDX-FileCopyrightText: 2006-2012 Peter Penz <peter.penz19@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kfileitemmodeldirlister.h"
#include <KLocalizedString>
#include <KIO/Job>
#include <kio_version.h>
KFileItemModelDirLister::KFileItemModelDirLister(QObject* parent) :
KDirLister(parent)
{
#if KIO_VERSION < QT_VERSION_CHECK(5, 82, 0)
setAutoErrorHandlingEnabled(false, nullptr);
#else
setAutoErrorHandlingEnabled(false);
#endif
}
KFileItemModelDirLister::~KFileItemModelDirLister()
{
}
void KFileItemModelDirLister::handleError(KIO::Job* job)
{
if (job->error() == KIO::ERR_IS_FILE) {
Q_EMIT urlIsFileError(url());
} else {
const QString errorString = job->errorString();
if (errorString.isEmpty()) {
Q_EMIT errorMessage(i18nc("@info:status", "Unknown error."));
} else {
Q_EMIT errorMessage(errorString);
}
}
}
/*
* SPDX-FileCopyrightText: 2006-2012 Peter Penz <peter.penz19@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KFILEITEMMODELDIRLISTER_H
#define KFILEITEMMODELDIRLISTER_H
#include "dolphin_export.h"
#include <KDirLister>
#include <QUrl>
/**
* @brief Extends the class KDirLister by emitting a signal when an
* error occurred instead of showing an error dialog.
* KDirLister::autoErrorHandlingEnabled() is set to false.
*/
class DOLPHIN_EXPORT KFileItemModelDirLister : public KDirLister
{
Q_OBJECT
public:
explicit KFileItemModelDirLister(QObject* parent = nullptr);
~KFileItemModelDirLister() override;
Q_SIGNALS:
/** Is emitted whenever an error has occurred. */
void errorMessage(const QString& msg);
/**
* Is emitted when the URL of the directory lister represents a file.
* In this case no signal errorMessage() will be emitted.
*/
void urlIsFileError(const QUrl& url);
protected:
void handleError(KIO::Job* job) override;
};
#endif
......@@ -6,9 +6,10 @@
#include "kitemviews/kfileitemlistview.h"
#include "kitemviews/kfileitemmodel.h"
#include "kitemviews/private/kfileitemmodeldirlister.h"
#include "testdir.h"
#include <KDirLister>
#include <QGraphicsView>
#include <QTest>
#include <QSignalSpy>
......
......@@ -12,10 +12,10 @@
#include <QTimer>
#include <QMimeData>
#include <KDirLister>
#include <kio/job.h>
#include "kitemviews/kfileitemmodel.h"
#include "kitemviews/private/kfileitemmodeldirlister.h"
#include "testdir.h"
void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
......
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