File indexing completed on 2024-04-28 07:40:09
0001 /* 0002 This file is part of the KDE Baloo project. 0003 SPDX-FileCopyrightText: 2011 Sebastian Trueg <trueg@kde.org> 0004 SPDX-FileCopyrightText: 2013-2014 Vishesh Handa <me@vhanda.in> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef PENDINGFILEQUEUE_H 0010 #define PENDINGFILEQUEUE_H 0011 0012 #include "pendingfile.h" 0013 0014 #include <QObject> 0015 #include <QString> 0016 #include <QHash> 0017 #include <QTimer> 0018 #include <QVector> 0019 0020 namespace Baloo { 0021 0022 class PendingFileQueueTest; 0023 0024 /** 0025 * 0026 */ 0027 class PendingFileQueue : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 explicit PendingFileQueue(QObject* parent = nullptr); 0033 ~PendingFileQueue() override; 0034 0035 Q_SIGNALS: 0036 void indexNewFile(const QString& fileUrl); 0037 void indexModifiedFile(const QString& fileUrl); 0038 void indexXAttr(const QString& fileUrl); 0039 void removeFileIndex(const QString& fileUrl); 0040 0041 public Q_SLOTS: 0042 void enqueue(const PendingFile& file); 0043 0044 /** 0045 * The number of seconds the file should be tracked after it has 0046 * been emitted. This defaults to 2 minutes 0047 */ 0048 void setTrackingTime(int seconds); 0049 0050 /** 0051 * Set the minimum amount of seconds a file should be kept in the queue 0052 * on receiving successive modifications events. 0053 */ 0054 void setMinimumTimeout(int seconds); 0055 void setMaximumTimeout(int seconds); 0056 0057 private Q_SLOTS: 0058 void processCache(const QTime& currentTime); 0059 void processPendingFiles(const QTime& currentTime); 0060 void clearRecentlyEmitted(const QTime& currentTime); 0061 0062 private: 0063 QVector<PendingFile> m_cache; 0064 0065 QTimer m_cacheTimer; 0066 QTimer m_clearRecentlyEmittedTimer; 0067 QTimer m_pendingFilesTimer; 0068 0069 /** 0070 * Holds the list of files that were recently emitted along with 0071 * the time they were last emitted. 0072 */ 0073 QHash<QString, QTime> m_recentlyEmitted; 0074 0075 /** 0076 * The QTime contains the time when these file events should be processed. 0077 */ 0078 QHash<QString, QTime> m_pendingFiles; 0079 0080 int m_minTimeout; 0081 int m_maxTimeout; 0082 int m_trackingTime; 0083 0084 friend class PendingFileQueueTest; 0085 }; 0086 0087 } 0088 0089 #endif