1/*
2 This file is part of the KDE Baloo project.
3 SPDX-FileCopyrightText: 2011 Sebastian Trueg <trueg@kde.org>
4 SPDX-FileCopyrightText: 2013-2014 Vishesh Handa <me@vhanda.in>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#ifndef PENDINGFILEQUEUE_H
10#define PENDINGFILEQUEUE_H
11
12#include "pendingfile.h"
13
14#include <QObject>
15#include <QString>
16#include <QHash>
17#include <QTimer>
18#include <QVector>
19
20namespace Baloo {
21
22class PendingFileQueueTest;
23
24/**
25 *
26 */
27class PendingFileQueue : public QObject
28{
29 Q_OBJECT
30
31public:
32 explicit PendingFileQueue(QObject* parent = nullptr);
33 ~PendingFileQueue() override;
34
35Q_SIGNALS:
36 void indexNewFile(const QString& fileUrl);
37 void indexModifiedFile(const QString& fileUrl);
38 void indexXAttr(const QString& fileUrl);
39 void removeFileIndex(const QString& fileUrl);
40
41public Q_SLOTS:
42 void enqueue(const PendingFile& file);
43
44 /**
45 * The number of seconds the file should be tracked after it has
46 * been emitted. This defaults to 2 minutes
47 */
48 void setTrackingTime(int seconds);
49
50 /**
51 * Set the minimum amount of seconds a file should be kept in the queue
52 * on receiving successive modifications events.
53 */
54 void setMinimumTimeout(int seconds);
55 void setMaximumTimeout(int seconds);
56
57private Q_SLOTS:
58 void processCache(const QTime& currentTime);
59 void processPendingFiles(const QTime& currentTime);
60 void clearRecentlyEmitted(const QTime& currentTime);
61
62private:
63 QVector<PendingFile> m_cache;
64
65 QTimer m_cacheTimer;
66 QTimer m_clearRecentlyEmittedTimer;
67 QTimer m_pendingFilesTimer;
68
69 /**
70 * Holds the list of files that were recently emitted along with
71 * the time they were last emitted.
72 */
73 QHash<QString, QTime> m_recentlyEmitted;
74
75 /**
76 * The QTime contains the time when these file events should be processed.
77 */
78 QHash<QString, QTime> m_pendingFiles;
79
80 int m_minTimeout;
81 int m_maxTimeout;
82 int m_trackingTime;
83
84 friend class PendingFileQueueTest;
85};
86
87}
88
89#endif
90

source code of baloo/src/file/pendingfilequeue.h