File indexing completed on 2024-05-12 04:59:44
0001 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0002 // SPDX-FileCopyrightText: 2023 Harald Sitter <sitter@kde.org> 0003 0004 #include "mtplister.h" 0005 0006 #include "listeradaptor.h" 0007 #include "mtpfile.h" 0008 #include "mtpstorage.h" 0009 0010 MTPLister::MTPLister(std::unique_ptr<uint32_t> children, int childrenCount, LIBMTP_mtpdevice_t *device, const QString &path, MTPStorage *parent) 0011 : QObject(parent) 0012 , m_device(device) 0013 , m_path(path) 0014 , m_childrenOwner(std::move(children)) 0015 , m_children(m_childrenOwner.get(), childrenCount) 0016 , m_it(m_children.begin()) 0017 { 0018 new ListerAdaptor(this); 0019 } 0020 0021 void MTPLister::run() 0022 { 0023 if (m_it == m_children.end()) { 0024 Q_EMIT finished(); 0025 deleteLater(); 0026 return; 0027 } 0028 0029 std::unique_ptr<LIBMTP_file_t> file(LIBMTP_Get_Filemetadata(m_device, *m_it)); 0030 if (file) { // file may have disappeared in the time between the id listing and metadata retrieval 0031 Q_EMIT entry(createKMTPFile(file)); 0032 } 0033 0034 ++m_it; 0035 QMetaObject::invokeMethod(this, &MTPLister::run, Qt::QueuedConnection); 0036 } 0037 0038 void MTPLister::abort() 0039 { 0040 m_it = m_children.end(); 0041 QMetaObject::invokeMethod(this, &MTPLister::run, Qt::QueuedConnection); 0042 } 0043 0044 #include "moc_mtplister.cpp"