Baloo Widgets

ondemandextractor.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 Stefan BrĂ¼ns <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include "ondemandextractor.h"
8 #include "extractorutil_p.h"
9 #include "widgetsdebug.h"
10 
11 #include <QDataStream>
12 #include <QStandardPaths>
13 
14 namespace Baloo
15 {
16 namespace Private
17 {
18 OnDemandExtractor::OnDemandExtractor(QObject *parent)
19  : QObject(parent)
20 {
21 }
22 
23 OnDemandExtractor::~OnDemandExtractor() = default;
24 
25 void OnDemandExtractor::process(const QString &filePath)
26 {
27  const QString exe = QStandardPaths::findExecutable(QLatin1String("baloo_filemetadata_temp_extractor"));
28 
29  m_process.setReadChannel(QProcess::StandardOutput);
30 
31  connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &OnDemandExtractor::slotIndexedFile);
32  m_process.start(exe, QStringList{filePath});
33 }
34 
35 void OnDemandExtractor::slotIndexedFile(int, QProcess::ExitStatus exitStatus)
36 {
37  if (exitStatus == QProcess::CrashExit) {
38  qCWarning(WIDGETS) << "Extractor crashed when processing" << m_process.arguments();
39  Q_EMIT fileFinished(exitStatus);
40  return;
41  }
42  QByteArray data = m_process.readAllStandardOutput();
44 
45  m_properties.clear();
46  in >> m_properties;
47  Q_EMIT fileFinished(QProcess::NormalExit);
48 }
49 
50 bool OnDemandExtractor::waitFinished()
51 {
52  return m_process.waitForFinished();
53 }
54 
55 KFileMetaData::PropertyMultiMap OnDemandExtractor::properties() const
56 {
57  return m_properties;
58 }
59 
60 } // namespace Private
61 } // namespace Baloo
void finished(int exitCode)
QString findExecutable(const QString &executableName, const QStringList &paths)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 04:12:56 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.