• 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
fileindexer.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE Project
2  Copyright (c) 2008-2010 Sebastian Trueg <trueg@kde.org>
3  Copyright (c) 2010-2011 Vishesh Handa <handa.vish@gmail.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "fileindexer.h"
21 #include "fileindexeradaptor.h"
22 #include "indexscheduler.h"
23 #include "fileindexerconfig.h"
24 #include "util.h"
25 
26 #include <KDebug>
27 #include <KDirNotify>
28 
29 #include "resourcemanager.h"
30 
31 #include <QtCore/QTimer>
32 #include <Soprano/QueryResultIterator>
33 #include <Soprano/Model>
34 #include <Soprano/Node>
35 
36 Nepomuk2::FileIndexer::FileIndexer()
37  : Service2()
38 {
39  // Create the configuration instance singleton (for thread-safety)
40  // ==============================================================
41  (void)new FileIndexerConfig(this);
42 
43  // setup the actual index scheduler
44  // ==============================================================
45  m_indexScheduler = new IndexScheduler(this);
46 
47  // setup status connections
48  connect( m_indexScheduler, SIGNAL(statusStringChanged()),
49  this, SIGNAL(statusStringChanged()) );
50 
51  // start initial indexing honoring the hidden config option to disable it
52  if( FileIndexerConfig::self()->isInitialRun() || !FileIndexerConfig::self()->initialUpdateDisabled() ) {
53  m_indexScheduler->updateAll();
54  }
55 
56  // Connect some signals used in the DBus interface
57  connect( this, SIGNAL( statusStringChanged() ),
58  this, SIGNAL( statusChanged() ) );
59  connect( m_indexScheduler, SIGNAL( indexingStarted() ),
60  this, SIGNAL( indexingStarted() ) );
61  connect( m_indexScheduler, SIGNAL( indexingStopped() ),
62  this, SIGNAL( indexingStopped() ) );
63  connect( m_indexScheduler, SIGNAL(fileIndexingDone()),
64  this, SIGNAL(fileIndexingDone()) );
65  connect( m_indexScheduler, SIGNAL(basicIndexingDone()),
66  this, SLOT(slotIndexingDone()) );
67 
68  connect( m_indexScheduler, SIGNAL( statusStringChanged() ),
69  this, SLOT( emitStatusMessage() ) );
70 
71 }
72 
73 
74 Nepomuk2::FileIndexer::~FileIndexer()
75 {
76 }
77 
78 void Nepomuk2::FileIndexer::slotIndexingDone()
79 {
80  FileIndexerConfig::self()->setInitialRun(false);
81 }
82 
83 void Nepomuk2::FileIndexer::emitStatusMessage()
84 {
85  QString message = m_indexScheduler->userStatusString();
86 
87  emit status((int)m_indexScheduler->currentStatus(), message);
88 }
89 
90 QString Nepomuk2::FileIndexer::statusMessage() const
91 {
92  return m_indexScheduler->userStatusString();
93 }
94 
95 int Nepomuk2::FileIndexer::currentStatus() const
96 {
97  return (int)m_indexScheduler->currentStatus();
98 }
99 
100 QString Nepomuk2::FileIndexer::userStatusString() const
101 {
102  return m_indexScheduler->userStatusString();
103 }
104 
105 void Nepomuk2::FileIndexer::setSuspended( bool suspend )
106 {
107  if ( suspend ) {
108  m_indexScheduler->suspend();
109  }
110  else {
111  m_indexScheduler->resume();
112  }
113 }
114 
115 
116 bool Nepomuk2::FileIndexer::isSuspended() const
117 {
118  return m_indexScheduler->isSuspended();
119 }
120 
121 
122 bool Nepomuk2::FileIndexer::isIndexing() const
123 {
124  return m_indexScheduler->isIndexing();
125 }
126 
127 bool Nepomuk2::FileIndexer::isCleaning() const
128 {
129  return m_indexScheduler->isCleaning();
130 }
131 
132 
133 void Nepomuk2::FileIndexer::suspend() const
134 {
135  m_indexScheduler->suspend();
136 }
137 
138 
139 void Nepomuk2::FileIndexer::resume() const
140 {
141  m_indexScheduler->resume();
142 }
143 
144 
145 QString Nepomuk2::FileIndexer::currentFile() const
146 {
147  return m_indexScheduler->currentUrl().toLocalFile();
148 }
149 
150 
151 QString Nepomuk2::FileIndexer::currentFolder() const
152 {
153  return KUrl(m_indexScheduler->currentUrl()).directory();
154 }
155 
156 
157 void Nepomuk2::FileIndexer::updateFolder(const QString& path, bool recursive, bool forced)
158 {
159  kDebug() << "Called with path: " << path;
160  QFileInfo info( path );
161  if ( info.exists() ) {
162  QString dirPath;
163  if ( info.isDir() )
164  dirPath = info.absoluteFilePath();
165  else
166  dirPath = info.absolutePath();
167 
168  if ( FileIndexerConfig::self()->shouldFolderBeIndexed( dirPath ) ) {
169  indexFolder(path, recursive, forced);
170  }
171  }
172 }
173 
174 int Nepomuk2::FileIndexer::indexedFiles() const
175 {
176  QString query = QString::fromLatin1("select count(distinct ?r) where { ?r kext:indexingLevel ?t. "
177  " FILTER(?t >= %1) . }")
178  .arg( Soprano::Node::literalToN3( Soprano::LiteralValue(2) ) );
179 
180  Soprano::Model* model = Nepomuk2::ResourceManager::instance()->mainModel();
181  Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
182  if( it.next() )
183  return it[0].literal().toInt();
184 
185  return 0;
186 }
187 
188 int Nepomuk2::FileIndexer::totalFiles() const
189 {
190  QString query = QString::fromLatin1("select count(distinct ?r) where { ?r kext:indexingLevel ?t. }");
191 
192  Soprano::Model* model = Nepomuk2::ResourceManager::instance()->mainModel();
193  Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
194  if( it.next() )
195  return it[0].literal().toInt();
196 
197  return 0;
198 }
199 
200 
201 void Nepomuk2::FileIndexer::updateAllFolders(bool forced)
202 {
203  m_indexScheduler->updateAll( forced );
204 }
205 
206 
207 void Nepomuk2::FileIndexer::indexFile(const QString& path)
208 {
209  m_indexScheduler->analyzeFile( path );
210 }
211 
212 
213 void Nepomuk2::FileIndexer::indexFolder(const QString& path, bool recursive, bool forced)
214 {
215  QFileInfo info( path );
216  if ( info.exists() ) {
217  QString dirPath;
218  if ( info.isDir() )
219  dirPath = info.absoluteFilePath();
220  else
221  dirPath = info.absolutePath();
222 
223  kDebug() << "Updating : " << dirPath;
224 
225  Nepomuk2::UpdateDirFlags flags;
226  if(recursive)
227  flags |= Nepomuk2::UpdateRecursive;
228  if(forced)
229  flags |= Nepomuk2::ForceUpdate;
230 
231  m_indexScheduler->updateDir( dirPath, flags );
232  }
233 }
234 
235 
236 int main( int argc, char **argv ) {
237  KAboutData aboutData( "nepomukfileindexer",
238  "nepomukfileindexer",
239  ki18n("Nepomuk File Indexer"),
240  NEPOMUK_VERSION_STRING,
241  ki18n("Nepomuk File Indexer"),
242  KAboutData::License_GPL,
243  ki18n("(c) 2008-2013, Sebastian Trüg"),
244  KLocalizedString(),
245  "http://nepomuk.kde.org" );
246  aboutData.addAuthor(ki18n("Sebastian Trüg"),ki18n("Developer"), "trueg@kde.org");
247  aboutData.addAuthor(ki18n("Vishesh Handa"),ki18n("Maintainer"), "me@vhanda.in");
248 
249  Nepomuk2::Service2::initUI<Nepomuk2::FileIndexer>( argc, argv, aboutData );
250 }
251 #include "fileindexer.moc"
252 
fileindexerconfig.h
Nepomuk2::ForceUpdate
The files in the folder should be updated regardless of their state.
Definition: basicindexingqueue.h:51
Nepomuk2::FileIndexer::resume
Q_SCRIPTABLE void resume() const
Definition: fileindexer.cpp:139
Nepomuk2::FileIndexer::indexingStopped
Q_SCRIPTABLE void indexingStopped()
Nepomuk2::FileIndexer::currentFolder
Q_SCRIPTABLE QString currentFolder() const
Definition: fileindexer.cpp:151
Nepomuk2::FileIndexer::totalFiles
Q_SCRIPTABLE int totalFiles() const
Definition: fileindexer.cpp:188
indexscheduler.h
Nepomuk2::FileIndexer::isSuspended
Q_SCRIPTABLE bool isSuspended() const
Definition: fileindexer.cpp:116
Nepomuk2::FileIndexer::setSuspended
Q_SCRIPTABLE void setSuspended(bool)
Definition: fileindexer.cpp:105
util.h
Nepomuk2::FileIndexer::statusMessage
Q_SCRIPTABLE QString statusMessage() const
Translated status message of the current Indexer behaviour.
Definition: fileindexer.cpp:90
Nepomuk2::IndexScheduler
The IndexScheduler is responsible for controlling the indexing queues and reacting to events...
Definition: indexscheduler.h:39
Nepomuk2::FileIndexer::currentStatus
Q_SCRIPTABLE int currentStatus() const
Returns the internal state of the indexer.
Definition: fileindexer.cpp:95
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::FileIndexer::statusStringChanged
void statusStringChanged()
Nepomuk2::FileIndexer::suspend
Q_SCRIPTABLE void suspend() const
Definition: fileindexer.cpp:133
Nepomuk2::Service2
New Base class for all Nepomuk services.
Definition: service2.h:88
Nepomuk2::FileIndexer::isCleaning
Q_SCRIPTABLE bool isCleaning() const
Definition: fileindexer.cpp:127
Nepomuk2::FileIndexer::FileIndexer
FileIndexer()
Definition: fileindexer.cpp:36
Nepomuk2::IndexScheduler::updateAll
void updateAll(bool forceUpdate=false)
Updates all configured folders.
Definition: indexscheduler.cpp:218
Nepomuk2::UpdateRecursive
The folder should be updated recursive.
Definition: basicindexingqueue.h:39
Nepomuk2::ResourceManager::instance
static ResourceManager * instance()
Definition: resourcemanager.cpp:270
Nepomuk2::FileIndexer::updateFolder
Q_SCRIPTABLE void updateFolder(const QString &path, bool recursive, bool forced)
Update folder path if it is configured to be indexed.
Definition: fileindexer.cpp:157
resourcemanager.h
Nepomuk2::FileIndexer::indexFolder
Q_SCRIPTABLE void indexFolder(const QString &path, bool recursive, bool forced)
Index a folder independent of its configuration status.
Definition: fileindexer.cpp:213
Nepomuk2::FileIndexer::indexFile
Q_SCRIPTABLE void indexFile(const QString &path)
Index a specific file.
Definition: fileindexer.cpp:207
fileindexer.h
Nepomuk2::FileIndexer::statusChanged
Q_SCRIPTABLE void statusChanged()
Nepomuk2::FileIndexer::userStatusString
Q_SCRIPTABLE QString userStatusString() const
Definition: fileindexer.cpp:100
Nepomuk2::FileIndexer::currentFile
Q_SCRIPTABLE QString currentFile() const
Definition: fileindexer.cpp:145
Nepomuk2::FileIndexerConfig::setInitialRun
void setInitialRun(bool isInitialRun)
Should be called once the initial indexing is done, ie.
Definition: fileindexerconfig.cpp:466
Nepomuk2::FileIndexer::updateAllFolders
Q_SCRIPTABLE void updateAllFolders(bool forced)
Update all folders configured to be indexed.
Definition: fileindexer.cpp:201
Nepomuk2::FileIndexer::isIndexing
Q_SCRIPTABLE bool isIndexing() const
Definition: fileindexer.cpp:122
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
Nepomuk2::FileIndexer::indexedFiles
Q_SCRIPTABLE int indexedFiles() const
Definition: fileindexer.cpp:174
main
int main(int argc, char **argv)
Definition: fileindexer.cpp:236
Nepomuk2::FileIndexer::indexingStarted
Q_SCRIPTABLE void indexingStarted()
Nepomuk2::FileIndexer::~FileIndexer
~FileIndexer()
Definition: fileindexer.cpp:74
Nepomuk2::FileIndexer::fileIndexingDone
Q_SCRIPTABLE void fileIndexingDone()
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