File indexing completed on 2024-04-21 04:39:56

0001 /*
0002     SPDX-FileCopyrightText: 2019 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #include "ondemandextractor.h"
0008 #include "extractorutil_p.h"
0009 #include "widgetsdebug.h"
0010 
0011 #include <QDataStream>
0012 #include <QStandardPaths>
0013 
0014 namespace Baloo
0015 {
0016 namespace Private
0017 {
0018 OnDemandExtractor::OnDemandExtractor(QObject *parent)
0019     : QObject(parent)
0020 {
0021 }
0022 
0023 OnDemandExtractor::~OnDemandExtractor() = default;
0024 
0025 void OnDemandExtractor::process(const QString &filePath)
0026 {
0027     const QString exe = QStandardPaths::findExecutable(QLatin1String("baloo_filemetadata_temp_extractor"));
0028 
0029     m_process.setReadChannel(QProcess::StandardOutput);
0030 
0031     connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &OnDemandExtractor::slotIndexedFile);
0032     m_process.start(exe, QStringList{filePath});
0033 }
0034 
0035 void OnDemandExtractor::slotIndexedFile(int, QProcess::ExitStatus exitStatus)
0036 {
0037     if (exitStatus == QProcess::CrashExit) {
0038         qCWarning(WIDGETS) << "Extractor crashed when processing" << m_process.arguments();
0039         Q_EMIT fileFinished(exitStatus);
0040         return;
0041     }
0042     QByteArray data = m_process.readAllStandardOutput();
0043     QDataStream in(&data, QIODevice::ReadOnly);
0044 
0045     m_properties.clear();
0046     in >> m_properties;
0047     Q_EMIT fileFinished(QProcess::NormalExit);
0048 }
0049 
0050 bool OnDemandExtractor::waitFinished()
0051 {
0052     return m_process.waitForFinished();
0053 }
0054 
0055 KFileMetaData::PropertyMultiMap OnDemandExtractor::properties() const
0056 {
0057     return m_properties;
0058 }
0059 
0060 } // namespace Private
0061 } // namespace Baloo
0062 
0063 #include "moc_ondemandextractor.cpp"