Baloo Widgets

filefetchjob.cpp
1 /*
2  * <one line to give the library's name and an idea of what it does.>
3  * Copyright (C) 2014 Vishesh Handa <[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 "filefetchjob.h"
22 #include "filemetadatautil_p.h"
23 #include "widgetsdebug.h"
24 
25 #include <QFileInfo>
26 #include <QTimer>
27 #include <Baloo/File>
28 
29 #include <KFileMetaData/UserMetaData>
30 
31 using namespace Baloo;
32 
33 FileFetchJob::FileFetchJob(const QStringList& urls, bool canEditAll,
34  FileFetchJob::UseRealtimeIndexing useRealtime, QObject* parent)
35  : KJob(parent)
36  , m_urls(urls)
37  , m_canEditAll(canEditAll)
38  , m_useRealtime(useRealtime)
39 {
40 }
41 
42 void FileFetchJob::start()
43 {
44  QTimer::singleShot(0, this, SLOT(doStart()));
45 }
46 
47 void FileFetchJob::doStart()
48 {
49  for (const QString& filePath : m_urls) {
50 
51  bool extractorRunning = false;
52  KFileMetaData::PropertyMap fileProperties;
53 
54  // UseRealtimeIndexing::Fallback: try DB first, then filesystem
55  // UseRealtimeIndexing::Disabled: DB contents only
56  // UseRealtimeIndexing::Only: DB disabled, use filesystem
57  if (m_useRealtime != UseRealtimeIndexing::Only) {
58  Baloo::File file(filePath);
59  file.load();
60  fileProperties = file.properties();
61  qCDebug(WIDGETS) << filePath << "DB properties:" << fileProperties;
62  }
63  if (fileProperties.empty() && m_useRealtime != UseRealtimeIndexing::Disabled) {
64  extractorRunning = true;
65  m_extractor.process(filePath);
66  }
67 
68  QVariantMap prop;
69  KFileMetaData::UserMetaData umd(filePath);
70 
71  if (umd.isSupported()) {
72  prop = Baloo::Private::convertUserMetaData(umd);
73  } else {
74  m_canEditAll = false;
75  }
76  if (m_canEditAll) {
77  m_canEditAll = QFileInfo(filePath).isWritable();
78  }
79 
80  if (extractorRunning) {
81  m_extractor.waitFinished();
82  fileProperties = m_extractor.properties();
83  qCDebug(WIDGETS) << filePath << " properties:" << fileProperties;
84  }
85  prop.unite(Baloo::Private::toNamedVariantMap(fileProperties));
86 
87  m_data << prop;
88  }
89 
90  emitResult();
91 }
92 
93 QList<QVariantMap> Baloo::FileFetchJob::data() const
94 {
95  return m_data;
96 }
97 
98 bool FileFetchJob::canEditAll() const
99 {
100  return m_canEditAll;
101 }
bool isWritable() const const
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.