Changeset View
Changeset View
Standalone View
Standalone View
src/file/extractorprocess.cpp
Show All 23 Lines | |||||
24 | #include <QDebug> | 24 | #include <QDebug> | ||
25 | 25 | | |||
26 | using namespace Baloo; | 26 | using namespace Baloo; | ||
27 | 27 | | |||
28 | ExtractorProcess::ExtractorProcess(QObject* parent) | 28 | ExtractorProcess::ExtractorProcess(QObject* parent) | ||
29 | : QObject(parent) | 29 | : QObject(parent) | ||
30 | , m_extractorPath(QStandardPaths::findExecutable(QStringLiteral("baloo_file_extractor"))) | 30 | , m_extractorPath(QStandardPaths::findExecutable(QStringLiteral("baloo_file_extractor"))) | ||
31 | , m_extractorProcess(this) | 31 | , m_extractorProcess(this) | ||
32 | , m_extractorIdle(true) | | |||
33 | { | 32 | { | ||
34 | connect(&m_extractorProcess, &QProcess::readyRead, this, &ExtractorProcess::slotIndexingFile); | 33 | connect(&m_extractorProcess, &QProcess::readyRead, this, &ExtractorProcess::slotIndexingFile); | ||
35 | m_extractorProcess.start(m_extractorPath, QStringList(), QIODevice::Unbuffered | QIODevice::ReadWrite); | 34 | m_extractorProcess.start(m_extractorPath, QStringList(), QIODevice::Unbuffered | QIODevice::ReadWrite); | ||
36 | m_extractorProcess.waitForStarted(); | 35 | m_extractorProcess.waitForStarted(); | ||
37 | m_extractorProcess.setReadChannel(QProcess::StandardOutput); | 36 | m_extractorProcess.setReadChannel(QProcess::StandardOutput); | ||
38 | } | 37 | } | ||
39 | 38 | | |||
40 | ExtractorProcess::~ExtractorProcess() | 39 | ExtractorProcess::~ExtractorProcess() | ||
41 | { | 40 | { | ||
42 | m_extractorProcess.close(); | 41 | m_extractorProcess.close(); | ||
43 | } | 42 | } | ||
44 | 43 | | |||
45 | void ExtractorProcess::index(const QVector<quint64>& fileIds) | 44 | void ExtractorProcess::index(const QVector<quint64>& fileIds) | ||
46 | { | 45 | { | ||
47 | Q_ASSERT(m_extractorProcess.state() == QProcess::Running); | 46 | Q_ASSERT(m_extractorProcess.state() == QProcess::Running); | ||
48 | Q_ASSERT(m_extractorIdle); | | |||
49 | Q_ASSERT(!fileIds.isEmpty()); | 47 | Q_ASSERT(!fileIds.isEmpty()); | ||
50 | 48 | | |||
51 | QByteArray batchData; | 49 | QByteArray batchData; | ||
52 | 50 | | |||
53 | quint32 batchSize = fileIds.size(); | 51 | quint32 batchSize = fileIds.size(); | ||
54 | batchData.append(reinterpret_cast<char*>(&batchSize), sizeof(quint32)); | 52 | batchData.append(reinterpret_cast<char*>(&batchSize), sizeof(quint32)); | ||
55 | for (quint64 id : fileIds) { | 53 | for (quint64 id : fileIds) { | ||
56 | batchData.append(reinterpret_cast<char*>(&id), sizeof(quint64)); | 54 | batchData.append(reinterpret_cast<char*>(&id), sizeof(quint64)); | ||
57 | } | 55 | } | ||
58 | 56 | | |||
59 | m_extractorIdle = false; | | |||
60 | m_extractorProcess.write(batchData.data(), batchData.size()); | 57 | m_extractorProcess.write(batchData.data(), batchData.size()); | ||
61 | } | 58 | } | ||
62 | 59 | | |||
63 | void ExtractorProcess::slotIndexingFile() | 60 | void ExtractorProcess::slotIndexingFile() | ||
64 | { | 61 | { | ||
65 | while (m_extractorProcess.canReadLine()) { | 62 | while (m_extractorProcess.canReadLine()) { | ||
66 | QString line = m_extractorProcess.readLine().trimmed(); | 63 | QString line = m_extractorProcess.readLine().trimmed(); | ||
67 | if (line.isEmpty()) { | 64 | if (line.isEmpty()) { | ||
Show All 9 Lines | 72 | case 'S': | |||
77 | break; | 74 | break; | ||
78 | 75 | | |||
79 | case 'F': | 76 | case 'F': | ||
80 | Q_EMIT finishedIndexingFile(arg); | 77 | Q_EMIT finishedIndexingFile(arg); | ||
81 | break; | 78 | break; | ||
82 | 79 | | |||
83 | case 'B': | 80 | case 'B': | ||
84 | Q_EMIT done(); | 81 | Q_EMIT done(); | ||
85 | m_extractorIdle = true; | | |||
86 | break; | 82 | break; | ||
87 | 83 | | |||
88 | default: | 84 | default: | ||
89 | qCritical() << "Got unknown result from extractor" << command << arg; | 85 | qCritical() << "Got unknown result from extractor" << command << arg; | ||
90 | } | 86 | } | ||
91 | } | 87 | } | ||
92 | } | 88 | } |