File indexing completed on 2024-04-21 05:48:32
0001 /*********************************************************************** 0002 * SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com> 0003 * SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org> 0004 * SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 ***********************************************************************/ 0008 0009 #pragma once 0010 0011 #include <atomic> 0012 #include <memory> 0013 0014 #include <QList> 0015 #include <QMutex> 0016 #include <QObject> 0017 0018 #include "localLister.h" 0019 0020 class Folder; 0021 0022 namespace Filelight 0023 { 0024 0025 class LocalLister; 0026 class RemoteLister; 0027 0028 class ScanManager : public QObject 0029 { 0030 Q_OBJECT 0031 0032 friend class LocalLister; 0033 friend class RemoteLister; 0034 0035 Q_PROPERTY(bool running READ running NOTIFY runningChanged) 0036 0037 public: 0038 explicit ScanManager(QObject *parent); 0039 ~ScanManager() override; 0040 0041 bool start(const QUrl &path); 0042 bool running() const; 0043 0044 Q_INVOKABLE int files() const 0045 { 0046 return m_files.loadRelaxed(); 0047 } 0048 Q_INVOKABLE size_t totalSize() const 0049 { 0050 return m_totalSize.loadRelaxed(); 0051 } 0052 0053 void invalidateCacheFor(const QUrl &url); 0054 0055 public Q_SLOTS: 0056 bool abort(); 0057 void emptyCache(); 0058 void cacheTree(std::shared_ptr<Folder> folder); 0059 void foundCached(std::shared_ptr<Folder> folder); 0060 0061 Q_SIGNALS: 0062 void completed(std::shared_ptr<Folder> folder); 0063 void aboutToEmptyCache(); 0064 void branchCacheHit(std::shared_ptr<Folder> tree); 0065 void runningChanged(); 0066 void aborted(); 0067 0068 private: 0069 std::atomic_bool m_abort; 0070 QAtomicInt m_files; 0071 QAtomicInteger<size_t> m_totalSize; 0072 0073 QMutex m_mutex; 0074 std::unique_ptr<LocalLister> m_thread; 0075 QList<std::shared_ptr<Folder>> m_cache; 0076 std::unique_ptr<RemoteLister> m_remoteLister; 0077 0078 Q_DISABLE_COPY_MOVE(ScanManager) 0079 }; 0080 } // namespace Filelight