add more spacing
[personal-kdebase.git] / runtime / nepomuk / services / strigi / indexscheduler.h
blobc021dfbc021e447506c8f48f7894c74924dbdccc
1 /* This file is part of the KDE Project
2 Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #ifndef _NEPOMUK_STRIGI_INDEX_SCHEDULER_H_
20 #define _NEPOMUK_STRIGI_INDEX_SCHEDULER_H_
22 #include <QtCore/QThread>
23 #include <QtCore/QMutex>
24 #include <QtCore/QWaitCondition>
25 #include <QtCore/QSet>
28 namespace Strigi {
29 class StreamAnalyzer;
30 class IndexManager;
33 class StoppableConfiguration;
34 class QFileInfo;
35 class QUrl;
36 class QDateTime;
37 class QByteArray;
40 namespace Nepomuk {
41 /**
42 * The IndexScheduler performs the normal indexing,
43 * ie. the initial indexing and the timed updates
44 * of all files.
46 * Events are not handled.
48 class IndexScheduler : public QThread
50 Q_OBJECT
52 public:
53 IndexScheduler( Strigi::IndexManager* manager, QObject* parent );
54 ~IndexScheduler();
56 bool isSuspended() const;
57 bool isIndexing() const;
59 /**
60 * The folder currently being indexed. Empty if not indexing.
61 * If suspended the folder might still be set!
63 QString currentFolder() const;
65 public Q_SLOTS:
66 void suspend();
67 void resume();
68 void stop();
70 void setSuspended( bool );
72 /**
73 * Slot to connect to certain event systems like KDirNotify
74 * or KDirWatch
76 * Updates a complete folder (non-recursively). Makes sense for
77 * signals like KDirWatch::dirty.
79 void updateDir( const QString& path );
81 /**
82 * Updates all configured folders.
84 void updateAll();
86 /**
87 * Analyze a resource that is not read from the local harddisk.
89 * \param uri The resource URI to identify the resource.
90 * \param modificationTime The modification date of the resource. Used to determine if
91 * an actual update is necessary.
92 * \data The data to analyze, ie. the contents of the resource.
94 void analyzeResource( const QUrl& uri, const QDateTime& modificationTime, QDataStream& data );
96 Q_SIGNALS:
97 void indexingStarted();
98 void indexingStopped();
99 void indexingFolder( const QString& );
101 private Q_SLOTS:
102 void readConfig();
104 private:
105 void run();
107 bool waitForContinue();
108 bool updateDir( const QString& dir, Strigi::StreamAnalyzer* analyzer, bool recursive );
109 void analyzeFile( const QFileInfo& file, Strigi::StreamAnalyzer* analyzer );
111 // emits indexingStarted or indexingStopped based on parameter. Makes sure
112 // no signal is emitted twice
113 void setIndexingStarted( bool started );
115 bool m_suspended;
116 bool m_stopped;
117 bool m_indexing;
119 QMutex m_resumeStopMutex;
120 QWaitCondition m_resumeStopWc;
122 StoppableConfiguration* m_analyzerConfig;
123 Strigi::IndexManager* m_indexManager;
125 // set of folders to update (+flags defined in the source file) - changed by updateDir
126 QSet<QPair<QString, int> > m_dirsToUpdate;
128 QMutex m_dirsToUpdateMutex;
129 QWaitCondition m_dirsToUpdateWc;
131 QString m_currentFolder;
135 #endif