Baloo Widgets

ondemandextractor.cpp
1 /*
2  * <one line to give the library's name and an idea of what it does.>
3  * Copyright (C) 2019 Stefan BrĂ¼ns <[email protected]>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  */
20 
21 #include "ondemandextractor.h"
22 #include "widgetsdebug.h"
23 #include "extractorutil_p.h"
24 
25 #include <QDataStream>
26 #include <QStandardPaths>
27 
28 namespace Baloo {
29 namespace Private {
30 
31 OnDemandExtractor::OnDemandExtractor(QObject* parent) : QObject(parent)
32 {
33 }
34 
35 OnDemandExtractor::~OnDemandExtractor()
36 {
37 }
38 
39 void OnDemandExtractor::process(const QString& filePath)
40 {
41  const QString exe = QStandardPaths::findExecutable(QLatin1String("baloo_filemetadata_temp_extractor"));
42 
43  m_process.setReadChannel(QProcess::StandardOutput);
44 
45  connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
46  this, &OnDemandExtractor::slotIndexedFile);
47  m_process.start(exe, QStringList{ filePath });
48 }
49 
50 void OnDemandExtractor::slotIndexedFile(int, QProcess::ExitStatus exitStatus)
51 {
52  if (exitStatus == QProcess::CrashExit) {
53  qCWarning(WIDGETS) << "Extractor crashed when processing" << m_process.arguments();
54  Q_EMIT fileFinished(exitStatus);
55  return;
56  }
57  QByteArray data = m_process.readAllStandardOutput();
59 
60  m_properties.clear();
61  in >> m_properties;
62  Q_EMIT fileFinished(QProcess::NormalExit);
63 }
64 
65 bool OnDemandExtractor::waitFinished()
66 {
67  return m_process.waitForFinished();
68 }
69 
70 KFileMetaData::PropertyMap OnDemandExtractor::properties() const
71 {
72  return m_properties;
73 }
74 
75 } // namespace Private
76 } // namespace Baloo
QString findExecutable(const QString &executableName, const QStringList &paths)
void finished(int exitCode)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Oct 21 2021 23:07:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.