Baloo Widgets

filefetchjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Vishesh Handa <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include "filefetchjob.h"
8 #include "filemetadatautil_p.h"
9 #include "widgetsdebug.h"
10 
11 #include <Baloo/File>
12 #include <QFileInfo>
13 #include <QTimer>
14 
15 #include <KFileMetaData/UserMetaData>
16 
17 using namespace Baloo;
18 
19 FileFetchJob::FileFetchJob(const QStringList &urls, bool canEditAll, FileFetchJob::UseRealtimeIndexing useRealtime, QObject *parent)
20  : KJob(parent)
21  , m_urls(urls)
22  , m_canEditAll(canEditAll)
23  , m_useRealtime(useRealtime)
24 {
25 }
26 
28 {
29  QTimer::singleShot(0, this, SLOT(doStart()));
30 }
31 
32 void FileFetchJob::doStart()
33 {
34  for (const QString &filePath : std::as_const(m_urls)) {
35  bool extractorRunning = false;
36  KFileMetaData::PropertyMultiMap fileProperties;
37 
38  // UseRealtimeIndexing::Fallback: try DB first, then filesystem
39  // UseRealtimeIndexing::Disabled: DB contents only
40  // UseRealtimeIndexing::Only: DB disabled, use filesystem
41  if (m_useRealtime != UseRealtimeIndexing::Only) {
42  Baloo::File file(filePath);
43  file.load();
44  fileProperties = file.properties();
45  qCDebug(WIDGETS) << filePath << "DB properties:" << fileProperties;
46  }
47  if (fileProperties.empty() && m_useRealtime != UseRealtimeIndexing::Disabled) {
48  extractorRunning = true;
49  m_extractor.process(filePath);
50  }
51 
52  QVariantMap prop;
53  KFileMetaData::UserMetaData umd(filePath);
54 
55  if (umd.isSupported()) {
56  prop = Baloo::Private::convertUserMetaData(umd);
57  } else {
58  m_canEditAll = false;
59  }
60  if (m_canEditAll) {
61  m_canEditAll = QFileInfo(filePath).isWritable();
62  }
63 
64  if (extractorRunning) {
65  m_extractor.waitFinished();
66  fileProperties = m_extractor.properties();
67  qCDebug(WIDGETS) << filePath << " properties:" << fileProperties;
68  }
69  prop.insert(Baloo::Private::toNamedVariantMap(fileProperties));
70 
71  m_data << prop;
72  }
73 
74  emitResult();
75 }
76 
77 QList<QVariantMap> Baloo::FileFetchJob::data() const
78 {
79  return m_data;
80 }
81 
82 bool FileFetchJob::canEditAll() const
83 {
84  return m_canEditAll;
85 }
Q_SCRIPTABLE Q_NOREPLY void start()
bool isWritable() const const
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.