• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • services
  • fileindexer
fileindexingqueue.cpp
Go to the documentation of this file.
1 /*
2  <one line to give the library's name and an idea of what it does.>
3  Copyright (C) 2012 Vishesh Handa <me@vhanda.in>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 
21 #include "fileindexingqueue.h"
22 #include "resourcemanager.h"
23 #include "fileindexingjob.h"
24 #include "fileindexerconfig.h"
25 #include "util.h"
26 
27 #include <Soprano/Model>
28 #include <Soprano/QueryResultIterator>
29 
30 #include <KDebug>
31 #include <QTimer>
32 
33 namespace Nepomuk2 {
34 
35 FileIndexingQueue::FileIndexingQueue(QObject* parent): IndexingQueue(parent)
36 {
37  m_fileQueue.reserve( 10 );
38 
39  FileIndexerConfig* config = FileIndexerConfig::self();
40  connect( config, SIGNAL(configChanged()), this, SLOT(slotConfigChanged()) );
41 }
42 
43 void FileIndexingQueue::start()
44 {
45  fillQueue();
46  emit startedIndexing();
47 
48  callForNextIteration();
49 }
50 
51 void FileIndexingQueue::fillQueue()
52 {
53  /* prevent abuse this API */
54  if (m_fileQueue.size() > 0)
55  return;
56 
57  QString query = QString::fromLatin1("select distinct ?url where { ?r nie:url ?url ; kext:indexingLevel ?l "
58  " FILTER(?l = 1 ). } LIMIT 10");
59 
60  Soprano::Model* model = ResourceManager::instance()->mainModel();
61  Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
62  while( it.next() )
63  m_fileQueue.enqueue( it[0].uri() );
64 }
65 
66 void FileIndexingQueue::enqueue(const QUrl& url)
67 {
68  if( !m_fileQueue.contains(url) ) {
69  m_fileQueue.enqueue( url );
70  callForNextIteration();
71  }
72 }
73 
74 
75 bool FileIndexingQueue::isEmpty()
76 {
77  return m_fileQueue.isEmpty();
78 }
79 
80 void FileIndexingQueue::processNextIteration()
81 {
82  const QUrl fileUrl = m_fileQueue.dequeue();
83  process( fileUrl );
84 }
85 
86 void FileIndexingQueue::process(const QUrl& url)
87 {
88  m_currentUrl = url;
89 
90  KJob* job = new FileIndexingJob( url );
91  job->start();
92  emit beginIndexingFile( url );
93  connect( job, SIGNAL(finished(KJob*)), this, SLOT(slotFinishedIndexingFile(KJob*)) );
94 }
95 
96 void FileIndexingQueue::slotFinishedIndexingFile(KJob* job)
97 {
98  if( job->error() ) {
99  kDebug() << job->errorString();
100  // Get the uri of the current file
101  QString query = QString::fromLatin1("select ?r where { ?r nie:url %1 . }")
102  .arg( Soprano::Node::resourceToN3( m_currentUrl ) );
103  Soprano::Model* model = ResourceManager::instance()->mainModel();
104  Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparqlNoInference );
105 
106  if( it.next() ) {
107  // Update the indexing level to -1, signalling an error,
108  // so the next round of the queue doesn't try to index it again.
109  updateIndexingLevel(it[0].uri(), -1);
110  }
111  }
112 
113  QUrl url = m_currentUrl;
114  m_currentUrl.clear();
115  emit endIndexingFile( url );
116  if( m_fileQueue.isEmpty() ) {
117  fillQueue();
118  }
119  finishIteration();
120 }
121 
122 void FileIndexingQueue::clear()
123 {
124  m_currentUrl.clear();
125  m_fileQueue.clear();
126 }
127 
128 void FileIndexingQueue::clear(const QString& path)
129 {
130  QMutableListIterator<QUrl> it( m_fileQueue );
131  while( it.hasNext() ) {
132  if( it.next().toLocalFile().startsWith( path ) )
133  it.remove();
134  }
135 }
136 
137 
138 QUrl FileIndexingQueue::currentUrl()
139 {
140  return m_currentUrl;
141 }
142 
143 void FileIndexingQueue::slotConfigChanged()
144 {
145  m_fileQueue.clear();
146  fillQueue();
147 }
148 
149 
150 }
fileindexerconfig.h
fileindexingqueue.h
Nepomuk2::FileIndexingJob
Definition: fileindexingjob.h:51
util.h
Nepomuk2::FileIndexingQueue::clear
void clear()
Definition: fileindexingqueue.cpp:122
Nepomuk2::FileIndexerConfig
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
Definition: fileindexerconfig.h:38
Nepomuk2::FileIndexingQueue::start
void start()
Fills up the queue and starts the indexing.
Definition: fileindexingqueue.cpp:43
QObject
Nepomuk2::IndexingQueue::startedIndexing
void startedIndexing()
The derived queues must emit this signal when their queue gets filled up.
Nepomuk2::FileIndexingQueue::beginIndexingFile
void beginIndexingFile(const QUrl &url)
Nepomuk2::FileIndexingQueue::endIndexingFile
void endIndexingFile(const QUrl &url)
Nepomuk2::IndexingQueue::callForNextIteration
void callForNextIteration()
Definition: indexingqueue.cpp:64
Nepomuk2::IndexingQueue::finishIteration
void finishIteration()
Call this function when you have finished processing the iteration from processNextIteration.
Definition: indexingqueue.cpp:81
Nepomuk2::FileIndexingQueue::fillQueue
virtual void fillQueue()
fill the queue if there is available data, return true if something is enqueued.
Definition: fileindexingqueue.cpp:51
Nepomuk2::ResourceManager::instance
static ResourceManager * instance()
Definition: resourcemanager.cpp:270
Nepomuk2::FileIndexingQueue::enqueue
void enqueue(const QUrl &url)
Definition: fileindexingqueue.cpp:66
resourcemanager.h
Nepomuk2::IndexingQueue
An abstract class representing the queue.
Definition: indexingqueue.h:36
Nepomuk2::FileIndexingQueue::isEmpty
virtual bool isEmpty()
Definition: fileindexingqueue.cpp:75
Nepomuk2::FileIndexingQueue::FileIndexingQueue
FileIndexingQueue(QObject *parent=0)
Definition: fileindexingqueue.cpp:35
Nepomuk2::FileIndexingQueue::currentUrl
QUrl currentUrl()
Definition: fileindexingqueue.cpp:138
fileindexingjob.h
Nepomuk2::FileIndexerConfig::self
static FileIndexerConfig * self()
Get the first created instance of FileIndexerConfig.
Definition: fileindexerconfig.cpp:82
Nepomuk2::ResourceManager::mainModel
Soprano::Model * mainModel()
Retrieve the main data storage model.
Definition: resourcemanager.cpp:363
KJob
Nepomuk2::FileIndexingQueue::processNextIteration
virtual void processNextIteration()
Process the next iteration in your queue.
Definition: fileindexingqueue.cpp:80
Nepomuk2::updateIndexingLevel
void updateIndexingLevel(const QUrl &uri, int level)
update kext::indexingLevel for url
Definition: util.cpp:71
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal