30 #include <QtCore/QList>
31 #include <QtCore/QFile>
32 #include <QtCore/QFileInfo>
33 #include <QtCore/QDirIterator>
34 #include <QtCore/QDateTime>
35 #include <QtCore/QByteArray>
36 #include <QtCore/QUrl>
40 #include <KStandardDirs>
41 #include <KConfigGroup>
48 , m_lastBasicIndexingFile( QDateTime::currentDateTime() )
49 , m_basicIndexingFileCount( 0 )
53 QFile::remove(KStandardDirs::locateLocal(
"data", QLatin1String(
"nepomuk/file-indexer-error-log")));
57 connect( indexConfig, SIGNAL(includeFolderListChanged(QStringList,QStringList)),
58 this, SLOT(slotIncludeFolderListChanged(QStringList,QStringList)) );
59 connect( indexConfig, SIGNAL(excludeFolderListChanged(QStringList,QStringList)),
60 this, SLOT(slotExcludeFolderListChanged(QStringList,QStringList)) );
63 connect( indexConfig, SIGNAL(fileExcludeFiltersChanged()),
64 this, SLOT(slotConfigFiltersChanged()) );
65 connect( indexConfig, SIGNAL(mimeTypeFiltersChanged()),
66 this, SLOT(slotConfigFiltersChanged()) );
76 connect( m_basicIQ, SIGNAL(finishedIndexing()),
this, SIGNAL(
basicIndexingDone()) );
77 connect( m_fileIQ, SIGNAL(finishedIndexing()),
this, SIGNAL(
fileIndexingDone()) );
79 connect( m_basicIQ, SIGNAL(beginIndexingFile(QUrl)),
this, SLOT(slotBeginIndexingFile(QUrl)) );
80 connect( m_basicIQ, SIGNAL(endIndexingFile(QUrl)),
this, SLOT(slotEndIndexingFile(QUrl)) );
81 connect( m_basicIQ, SIGNAL(endIndexingFile(QUrl)),
this, SLOT(slotEndBasicIndexingFile()) );
82 connect( m_fileIQ, SIGNAL(beginIndexingFile(QUrl)),
this, SLOT(slotBeginIndexingFile(QUrl)) );
83 connect( m_fileIQ, SIGNAL(endIndexingFile(QUrl)),
this, SLOT(slotEndIndexingFile(QUrl)) );
85 connect( m_basicIQ, SIGNAL(startedIndexing()),
this, SLOT(slotStartedIndexing()) );
86 connect( m_basicIQ, SIGNAL(finishedIndexing()),
this, SLOT(slotFinishedIndexing()) );
87 connect( m_fileIQ, SIGNAL(startedIndexing()),
this, SLOT(slotStartedIndexing()) );
88 connect( m_fileIQ, SIGNAL(finishedIndexing()),
this, SLOT(slotFinishedIndexing()) );
91 connect( m_basicIQ, SIGNAL(endIndexingFile(QUrl)), m_fileIQ, SLOT(enqueue(QUrl)) );
94 connect( m_basicIQ, SIGNAL(startedIndexing()),
this, SLOT(emitStatusStringChanged()) );
95 connect( m_basicIQ, SIGNAL(finishedIndexing()),
this, SLOT(emitStatusStringChanged()) );
96 connect( m_fileIQ, SIGNAL(startedIndexing()),
this, SLOT(emitStatusStringChanged()) );
97 connect( m_fileIQ, SIGNAL(finishedIndexing()),
this, SLOT(emitStatusStringChanged()) );
98 connect(
this, SIGNAL(
indexingSuspended(
bool)),
this, SLOT(emitStatusStringChanged()) );
101 connect( m_eventMonitor, SIGNAL(diskSpaceStatusChanged(
bool)),
102 this, SLOT(slotScheduleIndexing()) );
103 connect( m_eventMonitor, SIGNAL(idleStatusChanged(
bool)),
104 this, SLOT(slotScheduleIndexing()) );
105 connect( m_eventMonitor, SIGNAL(powerManagementStatusChanged(
bool)),
106 this, SLOT(slotScheduleIndexing()) );
109 connect( m_cleaner, SIGNAL(finished(
KJob*)),
this, SLOT(slotCleaningDone()) );
112 slotScheduleIndexing();
123 if ( m_state != State_Suspended ) {
124 m_state = State_Suspended;
125 slotScheduleIndexing();
127 m_eventMonitor->disable();
128 emit indexingSuspended(
true );
135 if( m_state == State_Suspended ) {
136 m_state = State_Normal;
137 slotScheduleIndexing();
139 m_eventMonitor->enable();
140 emit indexingSuspended(
false );
155 return m_state == State_Suspended;
160 return m_state == State_Cleaning;
170 if( !m_fileIQ->currentUrl().isEmpty() )
171 return m_fileIQ->currentUrl();
173 return m_basicIQ->currentUrl();
178 return m_basicIQ->currentFlags();
182 void Nepomuk2::IndexScheduler::setIndexingStarted(
bool started )
184 if ( started != m_indexing ) {
185 m_indexing = started;
186 emit indexingStateChanged( m_indexing );
188 emit indexingStarted();
190 emit indexingStopped();
194 void Nepomuk2::IndexScheduler::slotStartedIndexing()
196 m_eventMonitor->enable();
199 void Nepomuk2::IndexScheduler::slotFinishedIndexing()
201 m_eventMonitor->suspendDiskSpaceMonitor();
204 void Nepomuk2::IndexScheduler::slotCleaningDone()
208 m_state = State_Normal;
209 slotScheduleIndexing();
214 m_basicIQ->enqueue( path, flags );
220 queueAllFoldersForUpdate( forceUpdate );
224 void Nepomuk2::IndexScheduler::queueAllFoldersForUpdate(
bool forceUpdate )
234 m_basicIQ->enqueue( f, flags );
239 void Nepomuk2::IndexScheduler::slotIncludeFolderListChanged(
const QStringList& added,
const QStringList& removed)
241 kDebug() << added << removed;
242 foreach(
const QString& path, removed ) {
243 m_basicIQ->clear( path );
244 m_fileIQ->clear( path );
249 foreach(
const QString& path, added ) {
254 void Nepomuk2::IndexScheduler::slotExcludeFolderListChanged(
const QStringList& added,
const QStringList& removed)
256 kDebug() << added << removed;
257 foreach(
const QString& path, added ) {
258 m_basicIQ->clear( path );
259 m_fileIQ->clear( path );
264 foreach(
const QString& path, removed ) {
269 void Nepomuk2::IndexScheduler::restartCleaner()
277 m_cleaner =
new IndexCleaner(
this );
278 connect( m_cleaner, SIGNAL(finished(
KJob*)),
this, SLOT(slotCleaningDone()) );
280 m_state = State_Normal;
281 slotScheduleIndexing();
285 void Nepomuk2::IndexScheduler::slotConfigFiltersChanged()
293 queueAllFoldersForUpdate();
299 m_basicIQ->enqueue( path );
303 void Nepomuk2::IndexScheduler::slotBeginIndexingFile(
const QUrl&)
305 setIndexingStarted(
true );
308 void Nepomuk2::IndexScheduler::slotEndIndexingFile(
const QUrl&)
310 const QUrl basicUrl = m_basicIQ->currentUrl();
311 const QUrl fileUrl = m_fileIQ->currentUrl();
313 if( basicUrl.isEmpty() && fileUrl.isEmpty() ) {
314 setIndexingStarted(
false );
321 void Nepomuk2::IndexScheduler::slotEndBasicIndexingFile()
323 QDateTime current = QDateTime::currentDateTime();
324 if( current.secsTo(m_lastBasicIndexingFile) > 60 ) {
325 m_basicIQ->setDelay( 0 );
326 m_basicIndexingFileCount = 0;
329 if ( m_basicIndexingFileCount > 1000 ) {
330 m_basicIQ->setDelay( 400 );
332 else if ( m_basicIndexingFileCount > 750 ) {
333 m_basicIQ->setDelay( 300 );
335 else if ( m_basicIndexingFileCount > 500 ) {
336 m_basicIQ->setDelay( 200 );
338 else if ( m_basicIndexingFileCount > 200 ) {
339 m_basicIQ->setDelay( 100 );
342 m_basicIQ->setDelay( 0 );
345 m_basicIndexingFileCount++;
353 m_basicIQ->clear( path );
354 m_fileIQ->clear( path );
357 void Nepomuk2::IndexScheduler::slotScheduleIndexing()
359 if( m_state == State_Suspended ) {
360 kDebug() <<
"Suspended";
361 m_basicIQ->suspend();
364 m_cleaner->suspend();
367 else if( m_state == State_Cleaning ) {
368 kDebug() <<
"Cleaning";
369 m_basicIQ->suspend();
375 else if( m_eventMonitor->isDiskSpaceLow() ) {
376 kDebug() <<
"Disk Space";
377 m_state = State_LowDiskSpace;
379 m_basicIQ->suspend();
383 else if( m_eventMonitor->isOnBattery() ) {
384 kDebug() <<
"Battery";
385 m_state = State_OnBattery;
387 m_basicIQ->setDelay(0);
392 m_cleaner->suspend();
395 else if( m_eventMonitor->isIdle() ) {
398 m_state = State_Cleaning;
400 slotScheduleIndexing();
403 m_state = State_UserIdle;
404 m_basicIQ->setDelay( 0 );
407 m_fileIQ->setDelay( 0 );
413 kDebug() <<
"Normal";
414 m_state = State_Normal;
416 m_basicIQ->setDelay( 0 );
419 m_fileIQ->setDelay( 3000 );
426 bool indexing = isIndexing();
427 bool suspended = isSuspended();
428 bool cleaning = isCleaning();
429 bool processing = !m_basicIQ->isEmpty();
432 return i18nc(
"@info:status",
"File indexer is suspended." );
434 else if ( cleaning ) {
435 return i18nc(
"@info:status",
"Cleaning invalid file metadata");
437 else if ( indexing ) {
438 return i18nc(
"@info:status",
"Indexing files for desktop search." );
440 else if ( processing ) {
441 return i18nc(
"@info:status",
"Scanning for recent changes in files for desktop search");
444 return i18nc(
"@info:status",
"File indexer is idle." );
453 void Nepomuk2::IndexScheduler::emitStatusStringChanged()
455 QString status = userStatusString();
456 if( status != m_oldStatus ) {
457 emit statusStringChanged();
458 m_oldStatus = status;
464 #include "indexscheduler.moc"
The files in the folder should be updated regardless of their state.
QString mountPath() const
UpdateDirFlags currentFlags() const
The UpdateDirFlags of the the current url that is being indexed.
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
void indexingSuspended(bool suspended)
void updateDir(const QString &path, UpdateDirFlags flags=NoUpdateFlags)
Slot to connect to certain event systems like KDirNotify or KDirWatch.
This class represents a simple queue that iterates over the file system tree and indexes each file wh...
void updateAll(bool forceUpdate=false)
Updates all configured folders.
The folder should be updated recursive.
QUrl currentUrl() const
The current uri being indexed.
QString userStatusString() const
A user readable description of the scheduler's status.
The folder has been scheduled to update by the update system, not by a call to updateDir.
State
Represents the current state of the indexer.
State currentStatus() const
Returns the internal stateof the indexer as enum.
IndexScheduler(QObject *parent=0)
static FileIndexerConfig * self()
Get the first created instance of FileIndexerConfig.
void analyzeFile(const QString &path)
Analyze the one file without conditions.