Baloo

filemonitor.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "filemonitor.h"
8
9#include <QSet>
10#include <QString>
11#include <QStringList>
12#include <QDBusConnection>
13
14using namespace Baloo;
15
16class BALOO_CORE_NO_EXPORT FileMonitor::Private {
17public:
18 QSet<QString> m_files;
19};
20
21FileMonitor::FileMonitor(QObject* parent)
22 : QObject(parent)
23 , d(new Private)
24{
26 con.connect(QString(), QStringLiteral("/files"), QStringLiteral("org.kde"),
27 QStringLiteral("changed"), this, SLOT(slotFileMetaDataChanged(QStringList)));
28}
29
30FileMonitor::~FileMonitor() = default;
31
32void FileMonitor::addFile(const QString& fileUrl)
33{
34 QString f = fileUrl;
35 if (f.endsWith(QLatin1Char('/'))) {
36 f = f.mid(0, f.length() - 1);
37 }
38
39 d->m_files.insert(f);
40}
41
42void FileMonitor::addFile(const QUrl& url)
43{
44 const QString localFile = url.toLocalFile();
45 if (!localFile.isEmpty()) {
46 addFile(localFile);
47 }
48}
49
50void FileMonitor::setFiles(const QStringList& fileList)
51{
52 d->m_files = QSet<QString>(fileList.begin(), fileList.end());
53}
54
55QStringList FileMonitor::files() const
56{
57 return QList<QString>(d->m_files.begin(), d->m_files.end());
58}
59
60void FileMonitor::clear()
61{
62 d->m_files.clear();
63}
64
65void FileMonitor::slotFileMetaDataChanged(const QStringList& fileUrls)
66{
67 for (const QString& url : fileUrls) {
68 if (d->m_files.contains(url)) {
69 Q_EMIT fileMetaDataChanged(url);
70 }
71 }
72}
73
74#include "moc_filemonitor.cpp"
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
iterator begin()
iterator end()
Q_EMITQ_EMIT
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const
QString toLocalFile() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.