Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F16569165
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
69 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/nepomuk/CMakeLists.txt b/nepomuk/CMakeLists.txt
index 26e743f0c8..bd0104e607 100644
--- a/nepomuk/CMakeLists.txt
+++ b/nepomuk/CMakeLists.txt
@@ -1,200 +1,198 @@
project(nepomuk)
include(SopranoAddOntology)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
add_definitions(-DKDE_DEFAULT_DEBUG_AREA=300000)
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
if(KDE_NO_DEPRECATED)
add_definitions(-DDISABLE_NEPOMUK_LEGACY=1)
endif(KDE_NO_DEPRECATED)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/core
${CMAKE_CURRENT_SOURCE_DIR}/types
${CMAKE_CURRENT_SOURCE_DIR}/ui
${CMAKE_CURRENT_SOURCE_DIR}/query
${CMAKE_CURRENT_SOURCE_DIR}/utils
${CMAKE_SOURCE_DIR}
${KDE4_KIO_INCLUDES}
${QT_INCLUDES}
${SOPRANO_INCLUDE_DIR}
)
set(nepomuk_core_SRCS
core/variant.cpp
core/resourcedata.cpp
core/resourcemanager.cpp
- core/resourcefiltermodel.cpp
core/nepomukmainmodel.cpp
core/dbusconnectionpool.cpp
core/resource.cpp
core/thing.cpp
core/file.cpp
core/tag.cpp
core/nepomukservice.cpp
- core/graphwrapper.cpp
)
if(NOT KDE_NO_DEPRECATED)
set(nepomuk_core_SRCS
${nepomuk_core_SRCS}
core/tools.cpp
)
endif(NOT KDE_NO_DEPRECATED)
set(nepomuk_ui_SRCS
ui/ktagcloudwidget.cpp
ui/kblocklayout.cpp
ui/kmetadatatagcloud.cpp
ui/ktagdisplaywidget.cpp
ui/nepomukmassupdatejob.cpp
ui/tagwidget.cpp
ui/kedittagsdialog.cpp
ui/tagcheckbox.cpp
)
set(nepomuk_types_SRCS
types/entity.cpp
types/ontology.cpp
types/class.cpp
types/property.cpp
types/literal.cpp
types/entitymanager.cpp
)
if(NOT KDE_NO_DEPRECATED)
set(nepomuk_types_SRCS
${nepomuk_types_SRCS}
types/desktopontologyloader.cpp
types/fileontologyloader.cpp
types/global.cpp
types/nepomukontologyloader.cpp
types/ontologyloader.cpp
types/ontologymanager.cpp
)
endif(NOT KDE_NO_DEPRECATED)
set(nepomuk_query_SRCS
query/term.cpp
query/negationterm.cpp
query/orterm.cpp
query/andterm.cpp
query/comparisonterm.cpp
query/simpleterm.cpp
query/groupterm.cpp
query/resourceterm.cpp
query/literalterm.cpp
query/resourcetypeterm.cpp
query/optionalterm.cpp
query/query.cpp
query/query_p.cpp
query/filequery.cpp
query/queryparser.cpp
query/dateparser.cpp
query/result.cpp
query/queryserviceclient.cpp
query/dbusoperators.cpp
)
set(nepomuk_LIB_SRCS
${nepomuk_core_SRCS}
${nepomuk_ui_SRCS}
${nepomuk_types_SRCS}
# ${nepomuk_query_SRCS}
)
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nie.trig" "NIE" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nfo.trig" "NFO" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/ncal.trig" "NCAL" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nco.trig" "NCO" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nmo.trig" "NMO" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nmm.trig" "NMM" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nexif.trig" "NEXIF" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/pimo/pimo.trig" "PIMO" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/pimo/tmo.trig" "TMO" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nepomuk/nuao.trig" "NUAO" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
soprano_add_ontology(nepomuk_LIB_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nepomuk/ndo.trig" "NDO" "Nepomuk::Vocabulary" "trig" VISIBILITY "nepomuk")
kde4_add_library(nepomuk ${LIBRARY_TYPE} ${nepomuk_LIB_SRCS})
target_link_libraries(nepomuk
${SOPRANO_LIBRARIES}
${SOPRANO_CLIENT_LIBRARIES}
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTDBUS_LIBRARY}
kdecore
kdeui
)
target_link_libraries(nepomuk
LINK_INTERFACE_LIBRARIES
kdeui
${SOPRANO_LIBRARIES})
set_target_properties(nepomuk PROPERTIES
VERSION ${GENERIC_LIB_VERSION}
SOVERSION ${GENERIC_LIB_SOVERSION}
)
install(TARGETS nepomuk EXPORT kdelibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES
nepomuk_export.h
core/variant.h
core/resourcemanager.h
core/nepomukservice.h
core/resource.h
core/thing.h
core/tag.h
core/file.h
types/entity.h
types/class.h
types/property.h
types/ontology.h
types/literal.h
ui/ktagcloudwidget.h
ui/kmetadatatagcloud.h
ui/kmetadatatagwidget.h
ui/ktagdisplaywidget.h
ui/nepomukmassupdatejob.h
ui/tagwidget.h
# Vocabularies
${CMAKE_CURRENT_BINARY_DIR}/nie.h
${CMAKE_CURRENT_BINARY_DIR}/nfo.h
${CMAKE_CURRENT_BINARY_DIR}/ncal.h
${CMAKE_CURRENT_BINARY_DIR}/nco.h
${CMAKE_CURRENT_BINARY_DIR}/nmo.h
${CMAKE_CURRENT_BINARY_DIR}/nmm.h
${CMAKE_CURRENT_BINARY_DIR}/nexif.h
${CMAKE_CURRENT_BINARY_DIR}/pimo.h
${CMAKE_CURRENT_BINARY_DIR}/tmo.h
${CMAKE_CURRENT_BINARY_DIR}/nuao.h
${CMAKE_CURRENT_BINARY_DIR}/ndo.h
DESTINATION ${INCLUDE_INSTALL_DIR}/nepomuk COMPONENT Devel
)
if(NOT KDE_NO_DEPRECATED)
install(FILES
core/tools.h
types/desktopontologyloader.h
types/fileontologyloader.h
types/global.h
types/nepomukontologyloader.h
types/ontologyloader.h
types/ontologymanager.h
DESTINATION ${INCLUDE_INSTALL_DIR}/nepomuk COMPONENT Devel
)
endif(NOT KDE_NO_DEPRECATED)
add_subdirectory(rcgen)
add_subdirectory(query)
add_subdirectory(utils)
add_subdirectory(test)
diff --git a/nepomuk/core/graphwrapper.cpp b/nepomuk/core/graphwrapper.cpp
deleted file mode 100644
index cd17113caf..0000000000
--- a/nepomuk/core/graphwrapper.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * This file is part of the Nepomuk KDE project.
- * Copyright (C) 2008-2009 Sebastian Trueg <trueg@kde.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "graphwrapper_p.h"
-#include "resourcemanager.h"
-
-#include <Soprano/Model>
-#include <Soprano/Node>
-#include <Soprano/QueryResultIterator>
-#include <Soprano/Vocabulary/RDF>
-#include <Soprano/Vocabulary/NRL>
-#include <Soprano/Vocabulary/NAO>
-
-#include <QtCore/QDateTime>
-#include <QtCore/QUuid>
-#include <QtCore/QRegExp>
-
-
-Nepomuk::GraphWrapper::GraphWrapper( QObject* parent )
- : QObject( parent ),
- m_currentGraphStored( true ),
- m_manager( 0 )
-{
- connect( &m_timer, SIGNAL(timeout()),
- this, SLOT(slotTimeout()) );
- m_timer.setSingleShot( true );
-}
-
-
-Nepomuk::GraphWrapper::~GraphWrapper()
-{
-}
-
-
-void Nepomuk::GraphWrapper::setManager( ResourceManager* manager )
-{
- if( m_manager != manager ) {
- m_manager = manager;
- m_currentGraph = QUrl();
- }
-}
-
-
-QUrl Nepomuk::GraphWrapper::lookupCurrentGraph() const
-{
- return m_currentGraph;
-}
-
-
-QUrl Nepomuk::GraphWrapper::currentGraph()
-{
- if( !m_currentGraph.isValid() ) {
- createNewGraph();
- }
-
- if( !m_currentGraphStored ) {
- storeGraph( m_currentGraph );
- m_currentGraphStored = true;
- }
- return m_currentGraph;
-}
-
-
-void Nepomuk::GraphWrapper::slotTimeout()
-{
- // generate a new graph every event loop if the last one was used
- if( m_currentGraphStored ) {
- createNewGraph();
- }
-}
-
-
-void Nepomuk::GraphWrapper::createNewGraph()
-{
- m_currentGraph = m_manager->generateUniqueUri( QLatin1String("ctx") );
- m_currentGraphStored = false;
-}
-
-
-void Nepomuk::GraphWrapper::storeGraph( const QUrl& graph )
-{
- QUrl metadataGraph = m_manager->generateUniqueUri( QLatin1String("ctx") );
-
- m_manager->mainModel()->addStatement( graph,
- Soprano::Vocabulary::RDF::type(),
- Soprano::Vocabulary::NRL::InstanceBase(),
- metadataGraph );
- m_manager->mainModel()->addStatement( graph,
- Soprano::Vocabulary::NAO::created(),
- Soprano::LiteralValue( QDateTime::currentDateTime() ),
- metadataGraph );
- m_manager->mainModel()->addStatement( metadataGraph,
- Soprano::Vocabulary::RDF::type(),
- Soprano::Vocabulary::NRL::GraphMetadata(),
- metadataGraph );
- m_manager->mainModel()->addStatement( metadataGraph,
- Soprano::Vocabulary::NRL::coreGraphMetadataFor(),
- graph,
- metadataGraph );
-
- //
- // We update the graph every 200 mseconds but only when entering
- // the event loop.
- // I think it is ok for the user to think that two things
- // created a quarter of a second apart are created at the same time
- //
- m_timer.start( 200 );
-}
-
-#include "graphwrapper_p.moc"
diff --git a/nepomuk/core/graphwrapper_p.h b/nepomuk/core/graphwrapper_p.h
deleted file mode 100644
index 72fcb5d0f4..0000000000
--- a/nepomuk/core/graphwrapper_p.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * This file is part of the Nepomuk KDE project.
- * Copyright (C) 2008-2009 Sebastian Trueg <trueg@kde.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef _NEPOMUK_GRAPH_WRAPPER_H_
-#define _NEPOMUK_GRAPH_WRAPPER_H_
-
-#include <QtCore/QObject>
-#include <QtCore/QTimer>
-#include <QtCore/QUrl>
-
-namespace Soprano {
- class Model;
-}
-
-namespace Nepomuk {
-
- class ResourceManager;
-
- /**
- * Creates a new graph whenever the event loop is entered.
- * This way we do not create a new graph for each statement
- * added to the main model but group sets of added statements
- * into graphs.
- *
- * We need separate graphs to be able to track their creation time.
- *
- * IDEA: We actually need multiple graphs to be able to save the creation date of statements (annotations)
- * At the same time we do not want to create one graph for each created statement as we do in KDE 4.1
- * A timeout is a bad idea, too, since some batch operations may take longer than our timeout which
- * would lead to different graphs for the same batch.
- * Thus, why not using the event loop? Just use a timer whenever statements are added to
- * trigger the creation of a new graph on the next adding. Long batch operations as done in the
- * Akonadi feeders would result in a single graph while separate user actions in a GUI would always
- * lead to separate graphs.
- */
- class GraphWrapper : public QObject
- {
- Q_OBJECT
-
- public:
- GraphWrapper( QObject* parent = 0 );
- ~GraphWrapper();
-
- /**
- * Only look at the graph.
- */
- QUrl lookupCurrentGraph() const;
-
- /**
- * Get the current graph. This will also store
- * the graph in the main model if not done already.
- */
- QUrl currentGraph();
-
- void setManager( ResourceManager* manager );
-
- private Q_SLOTS:
- void slotTimeout();
-
- private:
- void createNewGraph();
- void storeGraph( const QUrl& );
-
- QUrl m_currentGraph;
- bool m_currentGraphStored;
- QTimer m_timer;
-
- ResourceManager* m_manager;
- };
-}
-
-#endif
diff --git a/nepomuk/core/resourcedata.cpp b/nepomuk/core/resourcedata.cpp
index 38174f84c4..023a6b97b3 100644
--- a/nepomuk/core/resourcedata.cpp
+++ b/nepomuk/core/resourcedata.cpp
@@ -1,748 +1,747 @@
/*
* This file is part of the Nepomuk KDE project.
* Copyright (C) 2006-2010 Sebastian Trueg <trueg@kde.org>
* Copyright (C) 2010 Vishesh Handa <handa.vish@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "resourcedata.h"
#include "resourcemanager.h"
#include "resourcemanager_p.h"
-#include "resourcefiltermodel.h"
#include "resource.h"
#include "tools.h"
#include "nie.h"
#include "nfo.h"
#include "pimo.h"
#include "nepomukmainmodel.h"
#include "dbusconnectionpool.h"
#include "class.h"
#include <Soprano/Statement>
#include <Soprano/StatementIterator>
#include <Soprano/QueryResultIterator>
#include <Soprano/Model>
#include <Soprano/Vocabulary/RDFS>
#include <Soprano/Vocabulary/RDF>
#include <Soprano/Vocabulary/Xesam>
#include <Soprano/Vocabulary/NAO>
#include <QtCore/QFile>
#include <QtCore/QDateTime>
#include <QtCore/QMutexLocker>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
#include <kdebug.h>
#include <kurl.h>
#include <kcomponentdata.h>
using namespace Soprano;
#define MAINMODEL (m_rm->m_manager->mainModel())
Nepomuk::ResourceData::ResourceData( const QUrl& uri, const QUrl& kickOffUri, const QUrl& type, ResourceManagerPrivate* rm )
: m_uri(uri),
m_mainType( type ),
m_modificationMutex(QMutex::Recursive),
m_cacheDirty(true),
m_pimoThing(0),
m_groundingOccurence(0),
m_rm(rm)
{
if( m_mainType.isEmpty() ) {
m_mainType = Soprano::Vocabulary::RDFS::Resource();
}
m_types << m_mainType;
if( m_rm->dataCacheFull() )
m_rm->cleanupCache();
m_rm->dataCnt.ref();
if( !uri.isEmpty() ) {
m_kickoffUris.insert( uri );
}
if( !kickOffUri.isEmpty() ) {
m_kickoffUris.insert( kickOffUri );
}
m_rm->addToKickOffList( this, m_kickoffUris );
}
Nepomuk::ResourceData::~ResourceData()
{
resetAll(true);
m_rm->dataCnt.deref();
}
bool Nepomuk::ResourceData::isFile()
{
return( m_uri.scheme() == QLatin1String("file") ||
m_nieUrl.scheme() == QLatin1String("file") ||
(!m_kickoffUris.isEmpty() && (*m_kickoffUris.begin()).scheme() == QLatin1String("file")) ||
constHasType( Soprano::Vocabulary::Xesam::File() ) ||
constHasType( Nepomuk::Vocabulary::NFO::FileDataObject() ) );
}
QUrl Nepomuk::ResourceData::uri() const
{
return m_uri;
}
QUrl Nepomuk::ResourceData::type()
{
load();
return m_mainType;
}
QList<QUrl> Nepomuk::ResourceData::allTypes()
{
load();
return m_types;
}
void Nepomuk::ResourceData::setTypes( const QList<QUrl>& types )
{
store();
QMutexLocker lock(&m_modificationMutex);
// reset types
m_types.clear();
m_mainType = Soprano::Vocabulary::RDFS::Resource();
QList<Node> nodes;
// load types (and set maintype)
foreach( const QUrl& url, types ) {
loadType( url );
nodes << Node( url );
}
// update the data store
setProperty(Soprano::Vocabulary::RDF::type(), Nepomuk::Variant(types) );
}
void Nepomuk::ResourceData::resetAll( bool isDelete )
{
// remove us from all caches (store() will re-insert us later if necessary)
m_rm->mutex.lock();
if( !m_uri.isEmpty() )
m_rm->m_initializedData.remove( m_uri );
Q_FOREACH( const KUrl& uri, m_kickoffUris )
m_rm->m_uriKickoffData.remove( uri );
m_rm->mutex.unlock();
// reset all variables
m_uri = QUrl();
m_nieUrl = KUrl();
m_kickoffUris.clear();
m_cache.clear();
m_cacheDirty = false;
m_types.clear();
delete m_pimoThing;
m_pimoThing = 0;
m_groundingOccurence = 0;
// when we are being deleted the value of m_mainType is not important
// anymore. Also since ResourceManager is a global static it might be
// deleted after the global static behind Soprano::Vocabulary::RDFS
// which results in a crash.
if( !isDelete )
m_mainType = Soprano::Vocabulary::RDFS::Resource();
}
QHash<QUrl, Nepomuk::Variant> Nepomuk::ResourceData::allProperties()
{
load();
return m_cache;
}
bool Nepomuk::ResourceData::hasProperty( const QUrl& uri )
{
load();
QHash<QUrl, Variant>::const_iterator it = m_cache.constFind( uri );
if( it == m_cache.constEnd() )
return false;
return true;
}
bool Nepomuk::ResourceData::hasProperty( const QUrl& p, const Variant& v )
{
QHash<QUrl, Variant>::const_iterator it = m_cache.constFind( p );
if( it == m_cache.constEnd() )
return false;
QList<Variant> thisVals = it.value().toVariantList();
QList<Variant> vals = v.toVariantList();
Q_FOREACH( const Variant& val, vals ) {
if( !thisVals.contains(val) )
return false;
}
return true;
}
bool Nepomuk::ResourceData::hasType( const QUrl& uri )
{
load();
return constHasType( uri );
}
bool Nepomuk::ResourceData::constHasType( const QUrl& uri ) const
{
// we need to protect the reading, too. setTypes may be triggered from another thread
QMutexLocker lock(&m_modificationMutex);
Types::Class requestedType( uri );
for ( QList<QUrl>::const_iterator it = m_types.constBegin();
it != m_types.constEnd(); ++it ) {
Types::Class availType( *it );
if ( availType == requestedType ||
availType.isSubClassOf( requestedType ) ) {
return true;
}
}
return false;
}
Nepomuk::Variant Nepomuk::ResourceData::property( const QUrl& uri )
{
load();
// we need to protect the reading, too. load my be triggered from another thread's
// connection to a Soprano statement signal
QMutexLocker lock(&m_modificationMutex);
QHash<QUrl, Variant>::const_iterator it = m_cache.constFind( uri );
if ( it == m_cache.constEnd() ) {
return Variant();
}
else {
return *it;
}
}
bool Nepomuk::ResourceData::store()
{
QMutexLocker lock(&m_modificationMutex);
if ( m_uri.isEmpty() ) {
QMutexLocker rmlock(&m_rm->mutex);
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusMessage msg = QDBusMessage::createMethodCall( QLatin1String("org.kde.nepomuk.DataManagement"),
QLatin1String("/datamanagement"),
QLatin1String("org.kde.nepomuk.DataManagement"),
QLatin1String("createResource") );
QString app = KGlobal::mainComponent().componentName();
QStringList types;
foreach( const QUrl &type, m_types )
types << type.toString();
QVariantList arguments;
//FIXME: Maybe we should be setting the 'label' over here.
arguments << types << QString() << QString() << app;
msg.setArguments( arguments );
QDBusMessage reply = bus.call( msg );
if( reply.type() == QDBusMessage::ErrorMessage ) {
//TODO: Set the error somehow
kWarning() << reply.errorMessage();
return false;
}
else if( reply.type() == QDBusMessage::ReplyMessage ) {
m_uri = reply.arguments().at(0).toUrl();
}
// Add us to the initialized data, i.e. make us "valid"
m_rm->m_initializedData.insert( m_uri, this );
// each initialized resource has to be in a kickoff list
// thus, we make sure that is the case.
if( m_kickoffUris.isEmpty() ) {
m_kickoffUris.insert( m_uri );
m_rm->addToKickOffList( this, m_kickoffUris );
}
foreach( const KUrl& url, m_kickoffUris ) {
if( url.scheme().isEmpty() )
setProperty( Soprano::Vocabulary::NAO::identifier(), Variant(url.url()) );
else
setProperty( Nepomuk::Vocabulary::NIE::url(), Variant(url.url()) );
}
}
/*
// store our grounding occurrence in case we are a thing created by the pimoThing() method
if( m_groundingOccurence ) {
if( m_groundingOccurence != this )
m_groundingOccurence->store();
statements.append( Statement( m_uri, Vocabulary::PIMO::groundingOccurrence(), m_groundingOccurence->uri() ) );
}
*/
return true;
}
void Nepomuk::ResourceData::loadType( const QUrl& storedType )
{
if ( !m_types.contains( storedType ) ) {
m_types << storedType;
}
if ( m_mainType == Soprano::Vocabulary::RDFS::Resource() ) {
Q_ASSERT( !storedType.isEmpty() );
m_mainType = storedType;
}
else {
Types::Class currentTypeClass = m_mainType;
Types::Class storedTypeClass = storedType;
// Keep the type that is further down the hierarchy
if ( storedTypeClass.isSubClassOf( currentTypeClass ) ) {
m_mainType = storedTypeClass.uri();
}
else {
// This is a little convenience hack since the user is most likely
// more interested in the file content than the actual file
Types::Class xesamContentClass( Soprano::Vocabulary::Xesam::Content() );
if ( m_mainType == Soprano::Vocabulary::Xesam::File() &&
( storedTypeClass == xesamContentClass ||
storedTypeClass.isSubClassOf( xesamContentClass ) ) ) {
m_mainType = storedTypeClass.uri();
}
else {
// the same is true for nie:DataObject vs. nie:InformationElement
Types::Class nieInformationElementClass( Vocabulary::NIE::InformationElement() );
Types::Class nieDataObjectClass( Vocabulary::NIE::DataObject() );
if( ( currentTypeClass == nieDataObjectClass ||
currentTypeClass.isSubClassOf( nieDataObjectClass ) ) &&
( storedTypeClass == nieInformationElementClass ||
storedTypeClass.isSubClassOf( nieInformationElementClass ) ) ) {
m_mainType = storedTypeClass.uri();
}
}
}
}
}
bool Nepomuk::ResourceData::load()
{
QMutexLocker lock(&m_modificationMutex);
if ( m_cacheDirty ) {
m_cache.clear();
if ( m_uri.isValid() ) {
//
// We exclude properties that are part of the inference graph
// It would only pollute the user interface
//
Soprano::QueryResultIterator it = MAINMODEL->executeQuery(QString("select distinct ?p ?o where { "
"graph ?g { %1 ?p ?o . } . FILTER(?g!=<urn:crappyinference2:inferredtriples>) . "
"}").arg(Soprano::Node::resourceToN3(m_uri)),
Soprano::Query::QueryLanguageSparql);
while ( it.next() ) {
QUrl p = it["p"].uri();
Soprano::Node o = it["o"];
if ( p == Soprano::Vocabulary::RDF::type() ) {
if ( o.isResource() ) {
loadType( o.uri() );
}
}
else {
Nepomuk::Variant var = Variant::fromNode( o );
updateKickOffLists( p, var );
m_cache[p].append( var );
}
}
m_cacheDirty = false;
delete m_pimoThing;
m_pimoThing = 0;
if( hasType( Vocabulary::PIMO::Thing() ) ) {
m_pimoThing = new Thing( m_uri );
}
else {
// TODO: somehow handle pimo:referencingOccurrence and pimo:occurrence
QueryResultIterator pimoIt = MAINMODEL->executeQuery( QString( "select ?r where { ?r <%1> <%2> . }")
.arg( Vocabulary::PIMO::groundingOccurrence().toString() )
.arg( QString::fromAscii( m_uri.toEncoded() ) ),
Soprano::Query::QueryLanguageSparql );
if( pimoIt.next() ) {
m_pimoThing = new Thing( pimoIt.binding("r").uri() );
}
}
return true;
}
else {
return false;
}
}
else {
return true;
}
}
void Nepomuk::ResourceData::setProperty( const QUrl& uri, const Nepomuk::Variant& value )
{
Q_ASSERT( uri.isValid() );
if( store() ) {
// step 0: make sure this resource is in the store
QMutexLocker lock(&m_modificationMutex);
// make sure resource values are in the store
if ( value.simpleType() == qMetaTypeId<Resource>() ) {
QList<Resource> l = value.toResourceList();
for( QList<Resource>::iterator resIt = l.begin(); resIt != l.end(); ++resIt ) {
resIt->m_data->store();
}
}
// update the store
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusMessage msg = QDBusMessage::createMethodCall( QLatin1String("org.kde.nepomuk.DataManagement"),
QLatin1String("/datamanagement"),
QLatin1String("org.kde.nepomuk.DataManagement"),
QLatin1String("setProperty") );
QString app = KGlobal::mainComponent().componentName();
QVariantList arguments;
QStringList resources;
resources << m_uri.url();
QVariantList varList;
foreach( const Nepomuk::Variant var, value.toVariantList() )
varList << var.variant();
arguments << resources << uri.toString() << QVariant(varList) << app;
msg.setArguments( arguments );
QDBusMessage reply = bus.call( msg );
if( reply.type() == QDBusMessage::ErrorMessage ) {
//TODO: Set the error somehow
kWarning() << reply.errorMessage();
return;
}
// update the cache for now
if( value.isValid() )
m_cache[uri] = value;
else
m_cache.remove(uri);
// update the kickofflists
updateKickOffLists( uri, value );
}
}
void Nepomuk::ResourceData::removeProperty( const QUrl& uri )
{
Q_ASSERT( uri.isValid() );
if( !m_uri.isEmpty() ) {
QMutexLocker lock(&m_modificationMutex);
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusMessage msg = QDBusMessage::createMethodCall( QLatin1String("org.kde.nepomuk.DataManagement"),
QLatin1String("/datamanagement"),
QLatin1String("org.kde.nepomuk.DataManagement"),
QLatin1String("removeProperties") );
QString app = KGlobal::mainComponent().componentName();
QVariantList arguments;
arguments << m_uri.url() << uri.toString() << app;
msg.setArguments( arguments );
QDBusMessage reply = bus.call( msg );
if( reply.type() == QDBusMessage::ErrorMessage ) {
//TODO: Set the error somehow
kWarning() << reply.errorMessage();
return;
}
// Update the cache
m_cache.remove( uri );
// update the kickofflists
updateKickOffLists( uri, Variant() );
}
}
void Nepomuk::ResourceData::remove( bool recursive )
{
Q_UNUSED(recursive)
QMutexLocker lock(&m_modificationMutex);
if( !m_uri.isEmpty() ) {
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusMessage msg = QDBusMessage::createMethodCall( QLatin1String("org.kde.nepomuk.DataManagement"),
QLatin1String("/datamanagement"),
QLatin1String("org.kde.nepomuk.DataManagement"),
QLatin1String("removeResources") );
QString app = KGlobal::mainComponent().componentName();
QVariantList arguments;
// TODO: Set the flag over here
arguments << m_uri.url() << 0 << app;
msg.setArguments( arguments );
QDBusMessage reply = bus.call( msg );
if( reply.type() == QDBusMessage::ErrorMessage ) {
//TODO: Set the error somehow
kWarning() << reply.errorMessage();
return;
}
}
resetAll();
}
bool Nepomuk::ResourceData::exists()
{
if( m_uri.isValid() ) {
const QString query = QString::fromLatin1("ask { %1 ?p ?o . }")
.arg( Soprano::Node::resourceToN3(m_uri) );
return MAINMODEL->executeQuery( query, Soprano::Query::QueryLanguageSparql ).boolValue();
}
else {
return false;
}
}
bool Nepomuk::ResourceData::isValid() const
{
return( !m_mainType.isEmpty() && ( !m_uri.isEmpty() || !m_kickoffUris.isEmpty() ) );
}
Nepomuk::ResourceData* Nepomuk::ResourceData::determineUri()
{
// We have the following possible situations:
// 1. m_uri is already valid
// -> simple, nothing to do
//
// 2. m_uri is not valid
// -> we need to determine the URI
//
// 2.1. m_kickoffUri is valid
// 2.1.1. it is a file URL
// 2.1.1.1. it is nie:url for r
// -> use r as m_uri
// 2.1.1.2. it points to a file on a removable device for which we have a filex:/ URL
// -> use the r in r nie:url filex:/...
// 2.1.1.3. it is a file which is not an object in some nie:url relation
// -> create new random m_uri and use kickoffUriOrId() as m_nieUrl
// 2.1.2. it is a resource URI
// -> use it as m_uri
//
// 2.2. m_kickOffUri is not valid
// 2.2.1. m_kickOffUri is a nao:identifier for r
// -> use r as m_uri
//
if( m_uri.isEmpty() ) {
Soprano::Model* model = MAINMODEL;
if( !m_kickoffUris.isEmpty() ) {
KUrl kickOffUri = *m_kickoffUris.begin();
if( kickOffUri.scheme().isEmpty() ) {
//
// Not valid. Checking for nao:identifier
//
QString query = QString::fromLatin1("select distinct ?r where { ?r %1 %2. } LIMIT 1")
.arg( Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::identifier()) )
.arg( Soprano::Node::literalToN3( kickOffUri.url() ) );
Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
if( it.next() ) {
m_uri = it["r"].uri();
it.close();
}
}
else {
//
// In one query determine if the URI is already used as resource URI or as
// nie:url
//
QString query = QString::fromLatin1("select distinct ?r ?o where { "
"{ ?r %1 %2 . FILTER(?r!=%2) . } "
"UNION "
"{ %2 ?p ?o . } "
"} LIMIT 1")
.arg( Soprano::Node::resourceToN3( Nepomuk::Vocabulary::NIE::url() ) )
.arg( Soprano::Node::resourceToN3( kickOffUri ) );
Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
if( it.next() ) {
QUrl uri = it["r"].uri();
if( uri.isEmpty() ) {
m_uri = kickOffUri;
}
else {
m_uri = uri;
m_nieUrl = kickOffUri;
}
it.close();
}
else if( kickOffUri.scheme() == QLatin1String("nepomuk") ) {
// for nepomuk URIs we simply use the kickoff URI as resource URI
m_uri = kickOffUri;
}
else {
// for everything else we use m_kickoffUri as nie:url with a new random m_uri
m_nieUrl = kickOffUri;
}
}
}
}
//
// Move us to the final data hash now that the URI is known
//
if( !m_uri.isEmpty() ) {
//vHanda: Is there some way to avoid this hash lookup every time?
// It sure would speed things up.
ResourceDataHash::iterator it = m_rm->m_initializedData.find(m_uri);
if( it == m_rm->m_initializedData.end() ) {
m_rm->m_initializedData.insert( m_uri, this );
}
else {
return it.value();
}
}
return this;
}
void Nepomuk::ResourceData::invalidateCache()
{
m_cacheDirty = true;
}
Nepomuk::Thing Nepomuk::ResourceData::pimoThing()
{
load();
if( !m_pimoThing ) {
//
// We only create a new thing if we are a nie:InformationElement.
// All other resources will simply be converted into a pimo:Thing
//
// Files, however, are a special case in every aspect. this includes pimo things.
// Files are their own grounding occurrence. This makes a lot of things
// much simpler.
//
if( hasType( Vocabulary::PIMO::Thing() ) ||
isFile() ||
!hasType( Vocabulary::NIE::InformationElement() ) ) {
m_pimoThing = new Thing(this);
}
else {
m_pimoThing = new Thing();
}
m_pimoThing->m_data->m_groundingOccurence = this;
}
return *m_pimoThing;
}
bool Nepomuk::ResourceData::operator==( const ResourceData& other ) const
{
if( this == &other )
return true;
return( m_uri == other.m_uri &&
m_mainType == other.m_mainType &&
m_kickoffUris == other.m_kickoffUris );
}
QDebug Nepomuk::ResourceData::operator<<( QDebug dbg ) const
{
KUrl::List list = m_kickoffUris.toList();
dbg << QString::fromLatin1("[kickoffuri: %1; uri: %2; type: %3; ref: %4]")
.arg( list.toStringList().join(QLatin1String(",")),
m_uri.url(),
m_mainType.toString() )
.arg( m_ref );
return dbg;
}
QDebug operator<<( QDebug dbg, const Nepomuk::ResourceData& data )
{
return data.operator<<( dbg );
}
void Nepomuk::ResourceData::updateKickOffLists(const QUrl& prop, const Nepomuk::Variant& v)
{
KUrl oldUrl;
KUrl newUrl;
if( prop == Nepomuk::Vocabulary::NIE::url() ) {
oldUrl = m_nieUrl;
newUrl = v.toUrl();
m_nieUrl = newUrl;
}
else if( prop == Soprano::Vocabulary::NAO::identifier() ) {
Q_FOREACH( const KUrl& url, m_kickoffUris ) {
if( url.scheme().isEmpty() ) {
oldUrl = url;
break;
}
}
newUrl = KUrl( v.toString() );
}
else {
return;
}
if( oldUrl != newUrl ) {
QMutexLocker rmlock(&m_rm->mutex);
m_kickoffUris.remove( oldUrl );
m_rm->m_uriKickoffData.remove( oldUrl );
if( !newUrl.isEmpty() ) {
m_kickoffUris.insert( newUrl );
m_rm->m_uriKickoffData.insert( newUrl, this );
}
}
}
diff --git a/nepomuk/core/resourcefiltermodel.cpp b/nepomuk/core/resourcefiltermodel.cpp
deleted file mode 100644
index 39da1bbca8..0000000000
--- a/nepomuk/core/resourcefiltermodel.cpp
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * This file is part of the Nepomuk KDE project.
- * Copyright (C) 2006-2009 Sebastian Trueg <trueg@kde.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "resourcefiltermodel.h"
-#include "graphwrapper_p.h"
-#include "resourcemanager.h"
-
-#include <Soprano/Node>
-#include <Soprano/Statement>
-#include <Soprano/StatementIterator>
-#include <Soprano/NodeIterator>
-#include <Soprano/QueryResultIterator>
-#include <Soprano/Client/DBusModel>
-#include <Soprano/Client/DBusClient>
-#include <Soprano/Client/LocalSocketClient>
-#include <Soprano/Query/QueryLanguage>
-#include <Soprano/Util/DummyModel>
-#include <Soprano/Util/MutexModel>
-#include <Soprano/Vocabulary/RDF>
-#include <Soprano/Vocabulary/NRL>
-#include <Soprano/Vocabulary/NAO>
-
-#include <QtCore/QSet>
-
-using namespace Soprano;
-
-
-class Nepomuk::ResourceFilterModel::Private
-{
-public:
- GraphWrapper graphWrapper;
-};
-
-Nepomuk::ResourceFilterModel::ResourceFilterModel( ResourceManager* manager )
- : FilterModel( 0 ),
- d(new Private())
-{
- d->graphWrapper.setManager( manager );
-}
-
-
-Nepomuk::ResourceFilterModel::~ResourceFilterModel()
-{
- delete d;
-}
-
-
-Soprano::Error::ErrorCode Nepomuk::ResourceFilterModel::addStatement( const Statement& statement )
-{
- Statement s( statement );
- if( s.context().isEmpty() ) {
- s.setContext( mainContext() );
- }
- return FilterModel::addStatement( s );
-}
-
-
-QUrl Nepomuk::ResourceFilterModel::mainContext()
-{
- return d->graphWrapper.currentGraph();
-}
-
-
-Soprano::Error::ErrorCode Nepomuk::ResourceFilterModel::updateModificationDate( const QUrl& resource, const QDateTime& date )
-{
- Error::ErrorCode c = removeAllStatements( resource, Soprano::Vocabulary::NAO::lastModified(), Soprano::Node() );
- if ( c != Error::ErrorNone )
- return c;
- else
- return addStatement( resource, Soprano::Vocabulary::NAO::lastModified(), LiteralValue( date ), mainContext() );
-}
-
-
-Soprano::Error::ErrorCode Nepomuk::ResourceFilterModel::updateProperty( const QUrl& resource, const QUrl& property, const Node& value )
-{
- if( !property.isValid() ) {
- setError( "Cannot update invalid property", Error::ErrorInvalidArgument );
- return Error::ErrorInvalidArgument;
- }
-
- if( !value.isValid() ) {
- return removeProperty( resource, property );
- }
-
- StatementIterator it = listStatements( Statement( resource, property, Node() ) );
- if ( it.next() ) {
- Statement s = it.current();
- it.close();
- if ( s.object() == value ) {
- // nothing to do. Yey!
- return Error::ErrorNone;
- }
- else {
- removeStatement( s );
- }
- }
-
- // update property
- Error::ErrorCode c = addStatement( resource, property, value, mainContext() );
- if ( c != Error::ErrorNone )
- return updateModificationDate( resource );
-
- return c;
-}
-
-
-Soprano::Error::ErrorCode Nepomuk::ResourceFilterModel::updateProperty( const QUrl& resource, const QUrl& property, const QList<Node>& values )
-{
- if( !property.isValid() ) {
- setError( "Cannot update invalid property", Error::ErrorInvalidArgument );
- return Error::ErrorInvalidArgument;
- }
-
- if( values.isEmpty() ) {
- return removeProperty( resource, property );
- }
-
- QSet<Node> existingValuesSet = listStatements( Statement( resource, property, Node() ) ).iterateObjects().allNodes().toSet();
- QSet<Node> valuesSet = values.toSet();
-
- Error::ErrorCode c = Error::ErrorNone;
- foreach( const Node &node, existingValuesSet - valuesSet ) {
- if ( ( c = removeAllStatements( Statement( resource, property, node ) ) ) != Error::ErrorNone ) {
- return c;
- }
- }
-
- QSet<Node> newNodes = valuesSet- existingValuesSet;
- if ( !newNodes.isEmpty() ) {
- QUrl context = mainContext();
- foreach( const Node &node, newNodes ) {
- if ( ( c = addStatement( Statement( resource, property, node, context ) ) ) != Error::ErrorNone ) {
- return c;
- }
- }
-
- c = updateModificationDate( resource );
- }
-
- return c;
-}
-
-
-Soprano::Error::ErrorCode Nepomuk::ResourceFilterModel::removeProperty( const QUrl& resource, const QUrl& property )
-{
- if( !property.isValid() ) {
- setError( "Cannot remove invalid property", Error::ErrorInvalidArgument );
- return Error::ErrorInvalidArgument;
- }
-
- Soprano::Error::ErrorCode c = removeAllStatements( Statement( resource, property, Node() ) );
- if ( c == Soprano::Error::ErrorNone )
- return updateModificationDate( resource );
- else
- return c;
-}
-
-
-Soprano::Error::ErrorCode Nepomuk::ResourceFilterModel::ensureResource( const QUrl& resource, const QUrl& type )
-{
- if ( !containsAnyStatement( Statement( resource, Soprano::Vocabulary::RDF::type(), type ) ) ) {
- Soprano::Error::ErrorCode c = addStatement( Statement( resource, Soprano::Vocabulary::RDF::type(), type, mainContext() ) );
- if ( c == Soprano::Error::ErrorNone )
- return updateModificationDate( resource );
- else
- return c;
- }
- else {
- clearError();
- return Error::ErrorNone;
- }
-}
-
-#include "resourcefiltermodel.moc"
diff --git a/nepomuk/core/resourcefiltermodel.h b/nepomuk/core/resourcefiltermodel.h
deleted file mode 100644
index ca22eb1264..0000000000
--- a/nepomuk/core/resourcefiltermodel.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * This file is part of the Nepomuk KDE project.
- * Copyright (C) 2006-2009 Sebastian Trueg <trueg@kde.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef _NEPOMUK_RESOURCE_FILTER_MODEL_H_
-#define _NEPOMUK_RESOURCE_FILTER_MODEL_H_
-
-#include <Soprano/FilterModel>
-#include <Soprano/Node>
-#include <Soprano/Vocabulary/RDFS>
-
-#include <QtCore/QList>
-#include <QtCore/QDateTime>
-
-namespace Nepomuk {
-
- class ResourceManager;
-
- /**
- * Filter model that provides a set of convenience methods
- * for maintaining resource properties.
- *
- * It does automatic NRL named graph handling, i.e. provedance
- * data is created and deleted automatically.
- *
- * \warning This model assumes that no property value is stored twice,
- * i.e. in two different named graphs.
- */
- class ResourceFilterModel : public Soprano::FilterModel
- {
- Q_OBJECT
-
- public:
- ResourceFilterModel( ResourceManager* manager );
- ~ResourceFilterModel();
-
- /**
- * Adds a statement to the Model. Statements without a valid context will be
- * added to the mainContext.
- */
- Soprano::Error::ErrorCode addStatement( const Soprano::Statement& statement );
-
- /**
- * The ResourceFilterModel automatically creates graph metadata and tries to
- * group batch operations into one graph. This method returns the currently
- * "open" graph, i.e. that one which is used in all the convinience methods.
- */
- QUrl mainContext();
-
- /**
- * Updates the modification date of \p resource to \p date.
- */
- Soprano::Error::ErrorCode updateModificationDate( const QUrl& resource, const QDateTime& date = QDateTime::currentDateTime() );
-
- /**
- * Update a property. This means an existing property is replaced if it differs from
- * the provided value. Otherwise nothing is done.
- *
- * This method assumes that the cardinality or property is 1.
- */
- Soprano::Error::ErrorCode updateProperty( const QUrl& resource, const QUrl& property, const Soprano::Node& value );
-
- /**
- * Update a property with a cardinality > 1.
- * This method optmizes the add and remove actions necessary.
- */
- Soprano::Error::ErrorCode updateProperty( const QUrl& resource, const QUrl& property, const QList<Soprano::Node>& values );
-
- /**
- * Remove a property from a resource and make sure no dangling graphs are left
- */
- Soprano::Error::ErrorCode removeProperty( const QUrl& resource, const QUrl& property );
-
- /**
- * Ensures that resoruce exists with type.
- */
- Soprano::Error::ErrorCode ensureResource( const QUrl& resource, const QUrl& type = Soprano::Vocabulary::RDFS::Resource() );
-
- using FilterModel::addStatement;
-
- private:
- class Private;
- Private* const d;
- };
-}
-
-#endif
diff --git a/nepomuk/core/resourcemanager.cpp b/nepomuk/core/resourcemanager.cpp
index d64911b4ca..e8ce31d63d 100644
--- a/nepomuk/core/resourcemanager.cpp
+++ b/nepomuk/core/resourcemanager.cpp
@@ -1,549 +1,538 @@
/*
* This file is part of the Nepomuk KDE project.
* Copyright (C) 2006-2010 Sebastian Trueg <trueg@kde.org>
* Copyright (C) 2010 Vishesh Handa <handa.vish@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "resourcemanager.h"
#include "resourcemanager_p.h"
#include "resourcedata.h"
#include "tools.h"
#include "nepomukmainmodel.h"
#include "resource.h"
-#include "resourcefiltermodel.h"
#include "class.h"
#include "nie.h"
#include <kglobal.h>
#include <kdebug.h>
#include <krandom.h>
#include <Soprano/Node>
#include <Soprano/Statement>
#include <Soprano/Vocabulary/RDF>
#include <Soprano/StatementIterator>
#include <Soprano/QueryResultIterator>
#include <QtCore/QFileInfo>
#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>
#include <QtCore/QUuid>
#include <QtCore/QMutableHashIterator>
#include <QtCore/QCoreApplication>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusConnectionInterface>
#include <QtDBus/QDBusServiceWatcher>
using namespace Soprano;
Nepomuk::ResourceManager* Nepomuk::ResourceManager::s_instance = 0;
Nepomuk::ResourceManagerPrivate::ResourceManagerPrivate( ResourceManager* manager )
: mainModel( 0 ),
overrideModel( 0 ),
mutex(QMutex::Recursive),
dataCnt( 0 ),
m_manager( manager )
{
}
Nepomuk::ResourceData* Nepomuk::ResourceManagerPrivate::data( const QUrl& uri, const QUrl& type )
{
if ( uri.isEmpty() ) {
// return an invalid resource which may be activated by calling setProperty
return new ResourceData( QUrl(), QUrl(), type, this );
}
if( ResourceData* data = findData( uri ) ) {
return data;
}
else {
return new ResourceData( QUrl(), uri, type, this );
}
}
Nepomuk::ResourceData* Nepomuk::ResourceManagerPrivate::data( const QString& uriOrId, const QUrl& type )
{
if ( !uriOrId.isEmpty() ) {
KUrl url(uriOrId);
return data( url, type );
}
return new ResourceData( QUrl(), QUrl(), type, this );
}
Nepomuk::ResourceData* Nepomuk::ResourceManagerPrivate::dataForResourceUri( const QUrl& uri, const QUrl& type )
{
if ( uri.isEmpty() ) {
// return an invalid resource which may be activated by calling setProperty
return new ResourceData( QUrl(), QUrl(), type, this );
}
if( ResourceData* data = findData( uri ) ) {
return data;
}
else {
return new ResourceData( uri, QUrl(), type, this );
}
}
QList<Nepomuk::ResourceData*> Nepomuk::ResourceManagerPrivate::allResourceDataOfType( const QUrl& type )
{
QList<ResourceData*> l;
if( !type.isEmpty() ) {
mutex.lock();
QSet<ResourceData*> rdl = m_uriKickoffData.values().toSet();
mutex.unlock();
for( QSet<ResourceData*>::iterator rdIt = rdl.begin();
rdIt != rdl.end(); ++rdIt ) {
ResourceData* rd = *rdIt;
//
// make sure we do not trigger a load here since
// 1. that could result in the deletion of values from the iterated list (m_cache.clear() in ResourceData::load)
// 2. We only need to check non-existing resources anyway, since the rest is queried from the db below
//
if( rd->constHasType( type ) ) {
l.append( rd );
}
}
}
return l;
}
QList<Nepomuk::ResourceData*> Nepomuk::ResourceManagerPrivate::allResourceDataWithProperty( const QUrl& uri, const Variant& v )
{
QList<ResourceData*> l;
//
// We need to cache m_uriKickoffData since it might be changed
// in the loop by ResourceData::load()
//
mutex.lock();
QSet<ResourceData*> rdl = m_uriKickoffData.values().toSet();
mutex.unlock();
//
// make sure none of the ResourceData objects are deleted by ResourceData::load below
// which would result in a crash since we have them cached.
//
QList<Resource> tmp;
foreach( ResourceData* rd, rdl ) {
tmp << Resource( rd );
}
for( QSet<ResourceData*>::iterator rdIt = rdl.begin();
rdIt != rdl.end(); ++rdIt ) {
ResourceData* rd = *rdIt;
if( rd->hasProperty( uri ) &&
rd->property( uri ) == v ) {
l.append( rd );
}
}
return l;
}
QList<Nepomuk::ResourceData*> Nepomuk::ResourceManagerPrivate::allResourceData()
{
return m_uriKickoffData.values().toSet().toList();
}
bool Nepomuk::ResourceManagerPrivate::dataCacheFull() const
{
return dataCnt >= 1000;
}
void Nepomuk::ResourceManagerPrivate::cleanupCache( int num )
{
QMutexLocker lock( &mutex );
QSet<ResourceData*> rdl = m_uriKickoffData.values().toSet() + m_initializedData.values().toSet();
for( QSet<ResourceData*>::iterator rdIt = rdl.begin();
rdIt != rdl.end(); ++rdIt ) {
ResourceData* data = *rdIt;
if ( !data->cnt() ) {
delete data;
if( num > 0 && --num == 0 )
break;
}
}
}
bool Nepomuk::ResourceManagerPrivate::shouldBeDeleted( ResourceData * rd ) const
{
//
// We delete data objects in one of two cases:
// 1. They are not valid and as such not in one of the ResourceManagerPrivate kickoff lists
// 2. The cache is already full and we need to clean up
//
return( !rd->cnt() && ( !rd->isValid() || dataCacheFull() ));
}
void Nepomuk::ResourceManagerPrivate::addToKickOffList( ResourceData* rd, const QSet<KUrl> & uris )
{
Q_FOREACH( const KUrl& uri, uris )
m_uriKickoffData.insert( uri, rd );
}
void Nepomuk::ResourceManagerPrivate::_k_storageServiceInitialized( bool success )
{
if( success ) {
kDebug() << "Nepomuk Storage service up and initialized.";
cleanupCache(-1);
m_manager->init();
emit m_manager->nepomukSystemStarted();
}
}
void Nepomuk::ResourceManagerPrivate::_k_dbusServiceUnregistered( const QString& serviceName )
{
if( serviceName == QLatin1String("org.kde.NepomukStorage") ) {
kDebug() << "Nepomuk Storage service went down.";
cleanupCache(-1);
emit m_manager->nepomukSystemStopped();
}
}
Nepomuk::ResourceData* Nepomuk::ResourceManagerPrivate::findData( const QUrl& uri )
{
if ( !uri.isEmpty() ) {
QMutexLocker lock( &mutex );
// look for the URI in the initialized and in the URI kickoff data
ResourceDataHash::iterator end = m_initializedData.end();
ResourceDataHash::iterator it = m_initializedData.find( uri );
if( it == end ) {
end = m_uriKickoffData.end();
it = m_uriKickoffData.find( uri );
}
if( it != end ) {
return it.value();
}
}
return 0;
}
Nepomuk::ResourceManager::ResourceManager()
: QObject(),
d( new ResourceManagerPrivate( this ) )
{
- d->resourceFilterModel = new ResourceFilterModel( this );
- connect( d->resourceFilterModel, SIGNAL(statementsAdded()),
- this, SLOT(slotStoreChanged()) );
- connect( d->resourceFilterModel, SIGNAL(statementsRemoved()),
- this, SLOT(slotStoreChanged()) );
-
// connect to the storage service's initialized signal to be able to emit
// the nepomukSystemStarted signal
QDBusConnection::sessionBus().connect( QLatin1String("org.kde.NepomukStorage"),
QLatin1String("/servicecontrol"),
QLatin1String("org.kde.nepomuk.ServiceControl"),
QLatin1String("serviceInitialized"),
this,
SLOT(_k_storageServiceInitialized(bool)) );
// connect to the serviceUnregistered signal to be able to connect the nepomukSystemStopped
// signal once the storage service goes away
QDBusServiceWatcher *watcher = new QDBusServiceWatcher( QLatin1String("org.kde.NepomukStorage"),
QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForUnregistration,
this );
connect( watcher, SIGNAL(serviceUnregistered(QString)),
this, SLOT(_k_dbusServiceUnregistered(QString)) );
init();
}
Nepomuk::ResourceManager::~ResourceManager()
{
clearCache();
- delete d->resourceFilterModel;
delete d->mainModel;
delete d;
if(s_instance == this) {
s_instance = 0;
}
}
void Nepomuk::ResourceManager::deleteInstance()
{
delete this;
}
Nepomuk::ResourceManager* Nepomuk::ResourceManager::instance()
{
if(!s_instance) {
s_instance = new ResourceManager();
s_instance->setParent(QCoreApplication::instance());
}
return s_instance;
}
int Nepomuk::ResourceManager::init()
{
QMutexLocker lock( &d->initMutex );
if( !d->mainModel ) {
d->mainModel = new MainModel( this );
}
- d->resourceFilterModel->setParentModel( d->mainModel );
-
d->mainModel->init();
return d->mainModel->isValid() ? 0 : -1;
}
bool Nepomuk::ResourceManager::initialized() const
{
QMutexLocker lock( &d->initMutex );
return d->mainModel && d->mainModel->isValid();
}
#ifndef KDE_NO_DEPRECATED
Nepomuk::Resource Nepomuk::ResourceManager::createResourceFromUri( const QString& uri )
{
return Resource( uri, QUrl() );
}
#endif
void Nepomuk::ResourceManager::removeResource( const QString& uri )
{
Resource res( uri );
res.remove();
}
void Nepomuk::ResourceManager::notifyError( const QString& uri, int errorCode )
{
kDebug() << "(Nepomuk::ResourceManager) error: " << uri << " " << errorCode;
emit error( uri, errorCode );
}
#ifndef KDE_NO_DEPRECATED
QList<Nepomuk::Resource> Nepomuk::ResourceManager::allResourcesOfType( const QString& type )
{
return allResourcesOfType( QUrl(type) );
}
#endif
QList<Nepomuk::Resource> Nepomuk::ResourceManager::allResourcesOfType( const QUrl& type )
{
QSet<Resource> set;
if( !type.isEmpty() ) {
// check local data
QList<ResourceData*> localData = d->allResourceDataOfType( type );
for( QList<ResourceData*>::iterator rdIt = localData.begin();
rdIt != localData.end(); ++rdIt ) {
Resource res( *rdIt );
set.insert(res);
}
// kDebug() << " added local resources: " << l.count();
Soprano::Model* model = mainModel();
Soprano::StatementIterator it = model->listStatements( Soprano::Statement( Soprano::Node(), Soprano::Vocabulary::RDF::type(), type ) );
while( it.next() ) {
Statement s = *it;
Resource res( s.subject().uri() );
set.insert(res);
}
// kDebug() << " added remote resources: " << l.count();
}
return set.toList();
}
QList<Nepomuk::Resource> Nepomuk::ResourceManager::allResources()
{
QList<Nepomuk::Resource> l;
Q_FOREACH( ResourceData* data, d->allResourceData()) {
l << Resource( data );
}
Soprano::QueryResultIterator it = mainModel()->executeQuery( QLatin1String("select distinct ?r where { ?r a ?t . FILTER(?t != rdf:Property && ?t != rdfs:Class) . }"),
Soprano::Query::QueryLanguageSparql );
while( it.next() ) {
Resource r( it[0].uri() );
l << r;
}
return l;
}
#ifndef KDE_NO_DEPRECATED
QList<Nepomuk::Resource> Nepomuk::ResourceManager::allResourcesWithProperty( const QString& uri, const Variant& v )
{
return allResourcesWithProperty( QUrl(uri), v );
}
#endif
QList<Nepomuk::Resource> Nepomuk::ResourceManager::allResourcesWithProperty( const QUrl& uri, const Variant& v )
{
QSet<Resource> set;
if( v.isList() ) {
kDebug() << "(ResourceManager::allResourcesWithProperty) list values not supported.";
}
else {
// check local data
QList<ResourceData*> localData = d->allResourceDataWithProperty( uri, v );
for( QList<ResourceData*>::iterator rdIt = localData.begin();
rdIt != localData.end(); ++rdIt ) {
set.insert( Resource( *rdIt ) );
}
// check remote data
Soprano::Model* model = mainModel();
Soprano::StatementIterator it = model->listStatements( Soprano::Statement( Soprano::Node(), uri, v.toNode() ) );
while( it.next() ) {
Statement s = *it;
Resource res( s.subject().uri() );
set.insert( res );
}
}
return set.toList();
}
void Nepomuk::ResourceManager::clearCache()
{
d->cleanupCache( -1 );
}
#ifndef KDE_NO_DEPRECATED
QString Nepomuk::ResourceManager::generateUniqueUri()
{
return generateUniqueUri( QString() ).toString();
}
#endif
QUrl Nepomuk::ResourceManager::generateUniqueUri( const QString& name )
{
// default to res URIs
QString type = QLatin1String("res");
// ctx is the only used value for name
if(name == QLatin1String("ctx")) {
type = name;
}
Soprano::Model* model = mainModel();
while( 1 ) {
QString uuid = QUuid::createUuid().toString();
uuid = uuid.mid(1, uuid.length()-2);
QUrl uri = QUrl( QLatin1String("nepomuk:/") + type + QLatin1String("/") + uuid );
if ( !model->executeQuery( QString::fromLatin1("ask where { "
"{ <%1> ?p1 ?o1 . } "
"UNION "
"{ ?s2 <%1> ?o2 . } "
"UNION "
"{ ?s3 ?p3 <%1> . } "
"UNION "
"{ graph <%1> { ?s4 ?4 ?o4 . } . } "
"}")
.arg( QString::fromAscii( uri.toEncoded() ) ), Soprano::Query::QueryLanguageSparql ).boolValue() ) {
return uri;
}
}
}
Soprano::Model* Nepomuk::ResourceManager::mainModel()
{
// make sure we are initialized
if ( !d->overrideModel && !initialized() ) {
init();
}
- return d->resourceFilterModel;
+ return d->mainModel;
}
void Nepomuk::ResourceManager::slotStoreChanged()
{
QMutexLocker lock( &d->mutex );
Q_FOREACH( ResourceData* data, d->allResourceData()) {
data->invalidateCache();
}
}
void Nepomuk::ResourceManager::setOverrideMainModel( Soprano::Model* model )
{
QMutexLocker lock( &d->mutex );
- if( model != d->resourceFilterModel ) {
+ if( model != d->mainModel ) {
d->overrideModel = model;
- d->resourceFilterModel->setParentModel( model ? model : d->mainModel );
// clear cache to make sure we do not mix data
Q_FOREACH( ResourceData* data, d->allResourceData()) {
data->invalidateCache();
}
}
}
Nepomuk::ResourceManager* Nepomuk::ResourceManager::createManagerForModel( Soprano::Model* model )
{
ResourceManager* manager = new ResourceManager();
manager->setOverrideMainModel( model );
return manager;
}
#include "resourcemanager.moc"
diff --git a/nepomuk/core/resourcemanager_p.h b/nepomuk/core/resourcemanager_p.h
index fad14f565f..128dc5b6d8 100644
--- a/nepomuk/core/resourcemanager_p.h
+++ b/nepomuk/core/resourcemanager_p.h
@@ -1,132 +1,130 @@
/*
* This file is part of the Nepomuk KDE project.
* Copyright (C) 2006-2009 Sebastian Trueg <trueg@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _NEPOMUK_RESOURCE_MANAGER_P_H_
#define _NEPOMUK_RESOURCE_MANAGER_P_H_
#include <QtCore/QMutex>
#include <kurl.h>
#include <Soprano/Node> // for qHash(QUrl)
#include "resourcedata.h"
namespace Soprano {
class Model;
}
namespace Nepomuk {
class ResourceManager;
class MainModel;
- class ResourceFilterModel;
typedef QHash<KUrl, Nepomuk::ResourceData*> ResourceDataHash;
class ResourceManagerPrivate
{
public:
ResourceManagerPrivate( ResourceManager* manager );
Nepomuk::MainModel* mainModel;
- ResourceFilterModel* resourceFilterModel;
Soprano::Model* overrideModel;
/// used to protect the initialization
QMutex initMutex;
/// used to protect all data in ResourceManager
QMutex mutex;
/// contains all initialized ResourceData object, i.e. all those which
/// successfully ran determineUri()
ResourceDataHash m_initializedData;
/// contains all non-initialized ResourceData objects created in data(QUrl)
ResourceDataHash m_uriKickoffData;
QAtomicInt dataCnt;
ResourceManager* m_manager;
/**
* The Nepomuk lib is based on the fact that for each uri only one ResourceData object is
* created at all times. This method searches for an existing data object to reuse or creates
* a new one if none exists.
*
* \param uriOrId The URI or identifier of the resource is question.
* \type The type of the resource.
*
* The Resource constructors use this method in combination with ref()
*/
ResourceData* data( const QString& uriOrId, const QUrl& type );
/**
* The Nepomuk lib is based on the fact that for each uri only one ResourceData object is
* created at all times. This method searches for an existing data object to reuse or creates
* a new one if none exists.
*
* \param uri The URI of the resource is question or it's nie:url or even its identified stored in
* a QUrl object.
* \type The type of the resource.
*
* The Resource constructors use this method in combination with ref()
*/
ResourceData* data( const QUrl& uri, const QUrl& type );
/**
* In contrast to data(QUrl,QUrl) this method avoids the overhead of determining the resource URI
* via ResourceData::determineUri() and simply uses \p uri as the resource URI.
*/
ResourceData* dataForResourceUri( const QUrl& uri, const QUrl& type );
bool dataCacheFull() const;
/**
* Delete unused ResourceData objects from the cache.
* \param num The number of needed slots. The ResourceData constructor
* uses this to make room for itself. Use < 0 to free the complete cache.
*
* Does NOT lock the mutex.
*/
void cleanupCache( int num = 1 );
bool shouldBeDeleted( ResourceData* rd ) const;
void addToKickOffList( ResourceData* rd, const QSet<KUrl>& uris );
QList<ResourceData*> allResourceData();
QList<ResourceData*> allResourceDataOfType( const QUrl& type );
QList<ResourceData*> allResourceDataWithProperty( const QUrl& _uri, const Variant& v );
void _k_storageServiceInitialized( bool );
void _k_dbusServiceUnregistered( const QString& serviceName );
private:
ResourceData* findData( const QUrl& uri );
QUrl m_mainContext;
};
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Nov 1, 8:14 AM (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10074840
Default Alt Text
(69 KB)
Attached To
Mode
rKL kdelibs
Attached
Detach File
Event Timeline
Log In to Comment