Baloo Widgets

filefetchjob.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
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
17using namespace Baloo;
18
19FileFetchJob::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
27void FileFetchJob::start()
28{
29 QTimer::singleShot(0, this, SLOT(doStart()));
30}
31
32void 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()) {
57 auto umdData = Baloo::Private::fetchUserMetaData(umd, Attribute::Tags | Attribute::Rating | Attribute::Comment | Attribute::OriginUrl);
58 prop = Baloo::Private::convertUserMetaData(umdData);
59 } else {
60 m_canEditAll = false;
61 }
62 if (m_canEditAll) {
63 m_canEditAll = QFileInfo(filePath).isWritable();
64 }
65
66 if (extractorRunning) {
67 m_extractor.waitFinished();
68 fileProperties = m_extractor.properties();
69 qCDebug(WIDGETS) << filePath << " properties:" << fileProperties;
70 }
71 prop.insert(Baloo::Private::toNamedVariantMap(fileProperties));
72
73 m_data << prop;
74 }
75
76 emitResult();
77}
78
79QList<QVariantMap> Baloo::FileFetchJob::data() const
80{
81 return m_data;
82}
83
84bool FileFetchJob::canEditAll() const
85{
86 return m_canEditAll;
87}
88
89#include "moc_filefetchjob.cpp"
void emitResult()
bool isWritable() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:45:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.