File indexing completed on 2024-04-28 04:58:01
0001 /* 0002 SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org> 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #ifndef SMBCDISCOVERER_H 0007 #define SMBCDISCOVERER_H 0008 0009 #include <QObject> 0010 0011 #include "discovery.h" 0012 #include "kio_smb.h" 0013 0014 class QEventLoop; 0015 0016 class SMBCDiscovery : public Discovery 0017 { 0018 public: 0019 SMBCDiscovery(const UDSEntry &entry); 0020 QString udsName() const override; 0021 KIO::UDSEntry toEntry() const override; 0022 0023 protected: 0024 UDSEntry m_entry; 0025 0026 private: 0027 const QString m_name; 0028 }; 0029 0030 class SMBCDiscoverer : public QObject, public Discoverer 0031 { 0032 Q_OBJECT 0033 public: 0034 SMBCDiscoverer(const SMBUrl &url, QEventLoop *discoverNext, SMBWorker *worker); 0035 ~SMBCDiscoverer() override; 0036 0037 void start() override; 0038 bool isFinished() const override; 0039 0040 bool dirWasRoot() const; 0041 int error() const; 0042 0043 Q_SIGNALS: 0044 void newDiscovery(Discovery::Ptr discovery) override; 0045 void finished() override; 0046 0047 private Q_SLOTS: 0048 /** 0049 * Process one dirent, queue a new loop event and return. 0050 * @see customEvent 0051 * @see queue 0052 */ 0053 void discoverNext(); 0054 0055 protected: 0056 void customEvent(QEvent *event) override; 0057 0058 private: 0059 void stop() override; 0060 0061 /** 0062 * readdirplus2 based file_info looping 0063 * @returns whether a file info was looped on 0064 */ 0065 bool discoverNextFileInfo(); 0066 0067 /// init discoverer (calls opendir) 0068 void init(); 0069 0070 /// queue new loop run 0071 inline void queue(); 0072 0073 SMBUrl m_url; 0074 QEventLoop *m_loop = nullptr; 0075 SMBWorker *m_worker = nullptr; 0076 bool m_finished = false; 0077 int m_error = 0; 0078 bool m_dirWasRoot = true; 0079 int m_dirFd = -1; 0080 }; 0081 0082 #endif // SMBCDISCOVERER_H