Commit 332936c2 authored by Harald Sitter's avatar Harald Sitter 🏳️‍🌈
Browse files

fix remote listing

this was crashing because we randomly casted a qobject to qwidget
without any safety nets whatsoever. I've refactored the ctor arguments
to not be nonesense and removed the offending widget setting (we have no
widget don't you know)

additionally the remote scanning was skipping running management in
scanmanager. it's not part of running() and accordingly emits
runningChanged when needed
parent a4e1899d
Pipeline #188258 passed with stage
in 1 minute and 39 seconds
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
......@@ -62,14 +63,13 @@ private:
Store &operator=(const Store &);
};
RemoteLister::RemoteLister(const QUrl &url, QWidget *parent, ScanManager *manager)
RemoteLister::RemoteLister(const QUrl &url, ScanManager *manager, QObject *parent)
: KDirLister(parent)
, m_root(new Store(url, url.url(), nullptr))
, m_store(m_root)
, m_manager(manager)
{
setShowingDotFiles(true); // Stupid KDirLister API function names
setMainWindow(parent);
// Use SIGNAL(result(KIO::Job*)) instead and then use Job::error()
connect(this, static_cast<void (KCoreDirLister::*)()>(&KCoreDirLister::completed), this, &RemoteLister::onCompleted);
......
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
......@@ -19,7 +20,7 @@ class RemoteLister : public KDirLister
{
Q_OBJECT
public:
RemoteLister(const QUrl &url, QWidget *parent, ScanManager *manager);
RemoteLister(const QUrl &url, ScanManager *manager, QObject *parent = nullptr);
~RemoteLister() override;
Q_SIGNALS:
......
......@@ -48,7 +48,7 @@ ScanManager::~ScanManager()
bool ScanManager::running() const
{
return m_thread && m_thread->isRunning();
return (m_thread && m_thread->isRunning()) || (m_remoteLister && !m_remoteLister->isFinished());
}
bool ScanManager::start(const QUrl &url)
......@@ -71,11 +71,12 @@ bool ScanManager::start(const QUrl &url)
if (!url.isLocalFile()) {
QGuiApplication::changeOverrideCursor(Qt::BusyCursor);
// will start listing straight away
Filelight::RemoteLister *remoteLister = new Filelight::RemoteLister(url, (QWidget *)parent(), this);
connect(remoteLister, &Filelight::RemoteLister::branchCompleted, this, &ScanManager::cacheTree, Qt::QueuedConnection);
remoteLister->setParent(this);
remoteLister->setObjectName(QStringLiteral("remote_lister"));
remoteLister->openUrl(url);
m_remoteLister = std::make_unique<Filelight::RemoteLister>(url, this, this);
connect(m_remoteLister.get(), &Filelight::RemoteLister::branchCompleted, this, &ScanManager::cacheTree, Qt::QueuedConnection);
connect(m_remoteLister.get(), &Filelight::RemoteLister::completed, this, &ScanManager::runningChanged);
m_remoteLister->setObjectName(QStringLiteral("remote_lister"));
m_remoteLister->openUrl(url);
Q_EMIT runningChanged();
return true;
}
......@@ -174,8 +175,8 @@ bool ScanManager::abort()
{
m_abort = true;
delete findChild<RemoteLister *>(QStringLiteral("remote_lister"));
m_remoteLister->stop();
m_remoteLister = nullptr;
const bool ret = m_thread && m_thread->wait();
Q_EMIT runningChanged();
......
......@@ -9,6 +9,8 @@
#ifndef SCAN_H
#define SCAN_H
#include <memory>
#include <QList>
#include <QMutex>
#include <QObject>
......@@ -21,6 +23,7 @@ namespace Filelight
{
class LocalLister;
class RemoteLister;
class ScanManager : public QObject
{
......@@ -70,6 +73,7 @@ private:
QMutex m_mutex;
LocalLister *m_thread;
QList<Folder *> m_cache;
std::unique_ptr<RemoteLister> m_remoteLister;
};
}
......
Supports Markdown
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