• 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
util.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007-2011 Sebastian Trueg <trueg@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License as
6  published by the Free Software Foundation; either version 2 of
7  the License, or (at your option) any later version.
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 General Public License
15  along with this library; see the file COPYING. 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 "util.h"
21 #include "datamanagement.h"
22 #include "nepomuktools.h"
23 #include "resourcemanager.h"
24 #include "kext.h"
25 
26 #include <QtCore/QUrl>
27 #include <QtCore/QFile>
28 #include <QtCore/QFileInfo>
29 #include <QtCore/QUuid>
30 #include <QtCore/QScopedPointer>
31 #include <QtCore/QDebug>
32 
33 #include <KJob>
34 #include <KDebug>
35 #include <KGlobal>
36 #include <KComponentData>
37 
38 #include <Soprano/Model>
39 #include <Soprano/QueryResultIterator>
40 
41 
42 KJob* Nepomuk2::clearIndexedData( const QUrl& url )
43 {
44  return clearIndexedData(QList<QUrl>() << url);
45 }
46 
47 KJob* Nepomuk2::clearIndexedData( const QList<QUrl>& urls )
48 {
49  if ( urls.isEmpty() )
50  return 0;
51 
52  //kDebug() << urls;
53 
54  //
55  // New way of storing File Indexing Data
56  // The Datamanagement API will automatically find the resource corresponding to that url
57  //
58  KComponentData component = KGlobal::mainComponent();
59  if( component.componentName() != QLatin1String("nepomukindexer") ) {
60  component = KComponentData( QByteArray("nepomukindexer"),
61  QByteArray(), KComponentData::SkipMainComponentRegistration );
62  }
63  return Nepomuk2::removeDataByApplication( urls, RemoveSubResoures, component );
64 }
65 
66 using namespace Nepomuk2::Vocabulary;
67 
68 //
69 // We don't really care if the indexing level is in the incorrect graph
70 //
71 void Nepomuk2::updateIndexingLevel(const QUrl& uri, int level)
72 {
73  QString uriN3 = Soprano::Node::resourceToN3( uri );
74 
75  QString query = QString::fromLatin1("select ?g ?l where { graph ?g { %1 kext:indexingLevel ?l . } }")
76  .arg ( uriN3 );
77  Soprano::Model* model = ResourceManager::instance()->mainModel();
78  Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparqlNoInference );
79 
80  QUrl graph;
81  Soprano::Node prevLevel;
82  if( it.next() ) {
83  graph = it[0].uri();
84  prevLevel = it[1];
85  it.close();
86  }
87 
88  if( !graph.isEmpty() ) {
89  QString graphN3 = Soprano::Node::resourceToN3( graph );
90  QString removeCommand = QString::fromLatin1("sparql delete { graph %1 { %2 kext:indexingLevel %3 . } }")
91  .arg( graphN3, uriN3, prevLevel.toN3() );
92  model->executeQuery( removeCommand, Soprano::Query::QueryLanguageUser, QLatin1String("sql") );
93 
94  QString insertCommand = QString::fromLatin1("sparql insert { graph %1 { %2 kext:indexingLevel %3 . } }")
95  .arg( graphN3, uriN3, Soprano::Node::literalToN3(level) );
96  model->executeQuery( insertCommand, Soprano::Query::QueryLanguageUser, QLatin1String("sql") );
97  }
98  // Practically, this should never happen, but still
99  else {
100  QScopedPointer<KJob> job( Nepomuk2::setProperty( QList<QUrl>() << uri, KExt::indexingLevel(),
101  QVariantList() << QVariant(level) ) );
102  job->setAutoDelete(false);
103  job->exec();
104  }
105 }
util.h
Nepomuk2::clearIndexedData
KJob * clearIndexedData(const QUrl &url)
remove all indexed data for url the datamanagement way
Definition: util.cpp:42
Nepomuk2::ResourceManager::instance
static ResourceManager * instance()
Definition: resourcemanager.cpp:270
resourcemanager.h
datamanagement.h
Nepomuk2::setProperty
KJob * setProperty(const QList< QUrl > &resources, const QUrl &property, const QVariantList &values, const KComponentData &component=KGlobal::mainComponent())
Set the values of a property for one or more resources.
Definition: datamanagement.cpp:48
nepomuktools.h
Nepomuk2::RemoveSubResoures
Remove sub resources of the resources specified in the parameters.
Definition: datamanagement.h:245
Nepomuk2::ResourceManager::mainModel
Soprano::Model * mainModel()
Retrieve the main data storage model.
Definition: resourcemanager.cpp:363
KJob
Nepomuk2::removeDataByApplication
KJob * removeDataByApplication(const QList< QUrl > &resources, Nepomuk2::RemovalFlags flags=Nepomuk2::NoRemovalFlags, const KComponentData &component=KGlobal::mainComponent())
Remove all information about resources from the database which has been created by a specific applica...
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:09 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