Git commit 9a319d9ee6ff74273eb6e8a7ac8af69dadc7fc1f by Christian Mollekopf. Committed on 30/11/2011 at 23:00. Pushed by cmollekopf into branch 'master'. updated dms-copy (to make use of the bigger timeout) M +7 -23 agents/nepomukfeeder/dms-copy/CMakeLists.txt M +2 -2 agents/nepomukfeeder/dms-copy/README A +42 -0 agents/nepomukfeeder/dms-copy/abstracttimeoutdbusinterface.c= pp [License: LGPL] A +41 -0 agents/nepomukfeeder/dms-copy/abstracttimeoutdbusinterface.h= [License: LGPL] M +2 -1 agents/nepomukfeeder/dms-copy/createresourcejob.cpp M +0 -1 agents/nepomukfeeder/dms-copy/createresourcejob.h M +12 -13 agents/nepomukfeeder/dms-copy/datamanagement.cpp M +86 -3 agents/nepomukfeeder/dms-copy/datamanagement.h R +2 -2 agents/nepomukfeeder/dms-copy/datamanagementinterface.cpp [f= rom: agents/nepomukfeeder/dms-copy/interfaces/datamanagementinterface.cpp -= 078% similarity] R +33 -26 agents/nepomukfeeder/dms-copy/datamanagementinterface.h [fro= m: agents/nepomukfeeder/dms-copy/interfaces/datamanagementinterface.h - 084= % similarity] M +3 -0 agents/nepomukfeeder/dms-copy/dbustypes.cpp M +6 -2 agents/nepomukfeeder/dms-copy/dbustypes.h M +6 -3 agents/nepomukfeeder/dms-copy/describeresourcesjob.cpp M +5 -3 agents/nepomukfeeder/dms-copy/describeresourcesjob.h M +2 -1 agents/nepomukfeeder/dms-copy/genericdatamanagementjob.cpp D +0 -8 agents/nepomukfeeder/dms-copy/interfaces/CMakeLists.txt D +0 -121 agents/nepomukfeeder/dms-copy/interfaces/org.kde.nepomuk.Dat= aManagement.xml A +68 -0 agents/nepomukfeeder/dms-copy/kdbusconnectionpool.cpp [L= icense: LGPL (v2+)] A +39 -0 agents/nepomukfeeder/dms-copy/kdbusconnectionpool.h [Lic= ense: LGPL (v2+)] D +0 -395 agents/nepomukfeeder/dms-copy/nepomuk-simpleresource-rcgen.py M +1 -1 agents/nepomukfeeder/dms-copy/nepomukdatamanagement_export.h M +0 -1 agents/nepomukfeeder/dms-copy/resourcewatcher.cpp M +24 -4 agents/nepomukfeeder/dms-copy/simpleresource.cpp M +8 -2 agents/nepomukfeeder/dms-copy/simpleresource.h M +26 -8 agents/nepomukfeeder/dms-copy/simpleresourcegraph.cpp M +26 -4 agents/nepomukfeeder/dms-copy/simpleresourcegraph.h A +107 -0 agents/nepomukfeeder/dms-copy/storeresourcesjob.cpp [Lic= ense: LGPL] A +63 -0 agents/nepomukfeeder/dms-copy/storeresourcesjob.h [Licen= se: LGPL] http://commits.kde.org/kdepim-runtime/9a319d9ee6ff74273eb6e8a7ac8af69dadc7f= c1f diff --git a/agents/nepomukfeeder/dms-copy/CMakeLists.txt b/agents/nepomukf= eeder/dms-copy/CMakeLists.txt index 93e97f0..cfdaf39 100644 --- a/agents/nepomukfeeder/dms-copy/CMakeLists.txt +++ b/agents/nepomukfeeder/dms-copy/CMakeLists.txt @@ -9,33 +9,17 @@ set(datamanagement_SRC genericdatamanagementjob.cpp createresourcejob.cpp describeresourcesjob.cpp + storeresourcesjob.cpp dbustypes.cpp datamanagement.cpp resourcewatcher.cpp + abstracttimeoutdbusinterface.cpp + datamanagementinterface.cpp + kdbusconnectionpool.cpp ) = -# set(datamanagementservice_dbus_desc interfaces/org.kde.nepomuk.DataManag= ement.xml) -# = -# set_source_files_properties( -# ${datamanagementservice_dbus_desc} -# PROPERTIES -# INCLUDE "dbustypes.h") - #the interfaces are directly copied from the buildfiles to avoid installin= g the interface multiple times -set(datamanagement_SRC ${datamanagement_SRC} interfaces/resourcewatchercon= nectioninterface.cpp interfaces/resourcewatchermanagerinterface.cpp = -interfaces/datamanagementinterface.cpp) - -# qt4_add_dbus_interface(datamanagement_SRC -# interfaces/org.kde.nepomuk.ResourceWatcherConnection.xml -# resourcewatcherconnectioninterface) -# = -# qt4_add_dbus_interface(datamanagement_SRC -# interfaces/org.kde.nepomuk.ResourceWatcher.xml -# resourcewatchermanagerinterface) -# = -# qt4_add_dbus_interface(datamanagement_SRC -# ${datamanagementservice_dbus_desc} -# datamanagementinterface) +set(datamanagement_SRC ${datamanagement_SRC} interfaces/resourcewatchercon= nectioninterface.cpp interfaces/resourcewatchermanagerinterface.cpp) = kde4_add_library(nepomukdatamanagement-copy SHARED ${datamanagement_SRC}) @@ -47,5 +31,5 @@ target_link_libraries(nepomukdatamanagement-copy ${NEPOMUK_LIBRARIES} ${KDE4_KDECORE_LIBS}) = - install(TARGETS nepomukdatamanagement-copy - DESTINATION ${LIB_INSTALL_DIR}) +install(TARGETS nepomukdatamanagement-copy + DESTINATION ${LIB_INSTALL_DIR}) \ No newline at end of file diff --git a/agents/nepomukfeeder/dms-copy/README b/agents/nepomukfeeder/dm= s-copy/README index 19c0701..c907f86 100644 --- a/agents/nepomukfeeder/dms-copy/README +++ b/agents/nepomukfeeder/dms-copy/README @@ -1,2 +1,2 @@ -Copy from kde-runtime revision 5bfc371e40b22b032b428e2d278738da62555e18. -To be removed when the dms is moved to kdelibs (probably kde 4.8) \ No newline at end of file +Copy from kde-runtime revision c982c2326ba93c4380ad950ada8d93b5582e4e4f. +To be removed when the dms is moved to kdelibs (probably kde 4.9) \ No newline at end of file diff --git a/agents/nepomukfeeder/dms-copy/abstracttimeoutdbusinterface.cpp= b/agents/nepomukfeeder/dms-copy/abstracttimeoutdbusinterface.cpp new file mode 100644 index 0000000..cc060d3 --- /dev/null +++ b/agents/nepomukfeeder/dms-copy/abstracttimeoutdbusinterface.cpp @@ -0,0 +1,42 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2011 Sebastian Trueg + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "abstracttimeoutdbusinterface.h" + +#include + +AbstractTimeoutDBusInterface::AbstractTimeoutDBusInterface(const QString& = service, const QString& path, const char* interface, const QDBusConnection&= connection, QObject* parent) + : QDBusAbstractInterface( service, path, interface, connection, parent= ) +{ +} + +AbstractTimeoutDBusInterface::~AbstractTimeoutDBusInterface() +{ +} + +QDBusPendingCall AbstractTimeoutDBusInterface::asyncCallWithArgumentList(c= onst QString &method, const QList &args, int timeout) +{ + QDBusMessage msg =3D QDBusMessage::createMethodCall(service(), path(),= interface(), method); + msg.setArguments(args); + return connection().asyncCall(msg, timeout); +} + +#include "abstracttimeoutdbusinterface.moc" diff --git a/agents/nepomukfeeder/dms-copy/abstracttimeoutdbusinterface.h b= /agents/nepomukfeeder/dms-copy/abstracttimeoutdbusinterface.h new file mode 100644 index 0000000..3cd0f3f --- /dev/null +++ b/agents/nepomukfeeder/dms-copy/abstracttimeoutdbusinterface.h @@ -0,0 +1,41 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2011 Sebastian Trueg + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef ABSTRACTTIMEOUTDBUSINTERFACE_H +#define ABSTRACTTIMEOUTDBUSINTERFACE_H + +#include + +/** + * An extension of the abstract DBus interface which allows to set the tim= eout. + */ +class AbstractTimeoutDBusInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + AbstractTimeoutDBusInterface(const QString& service, const QString& pa= th, const char* interface, const QDBusConnection& connection, QObject* pare= nt =3D 0); + ~AbstractTimeoutDBusInterface(); + + QDBusPendingCall asyncCallWithArgumentList(const QString &method, cons= t QList &args, int timeout); +}; + +#endif // ABSTRACTTIMEOUTDBUSINTERFACE_H diff --git a/agents/nepomukfeeder/dms-copy/createresourcejob.cpp b/agents/n= epomukfeeder/dms-copy/createresourcejob.cpp index fb7880e..b0a1763 100644 --- a/agents/nepomukfeeder/dms-copy/createresourcejob.cpp +++ b/agents/nepomukfeeder/dms-copy/createresourcejob.cpp @@ -23,6 +23,7 @@ #include "datamanagementinterface.h" #include "dbustypes.h" #include "genericdatamanagementjob_p.h" +#include "kdbusconnectionpool.h" = #include #include @@ -50,7 +51,7 @@ Nepomuk::CreateResourceJob::CreateResourceJob(const QList= & types, { org::kde::nepomuk::DataManagement dms(QLatin1String(DMS_DBUS_SERVICE), QLatin1String("/datamanagement"), - QDBusConnection::sessionBus()); + KDBusConnectionPool::threadConne= ction()); QDBusPendingCallWatcher* dbusCallWatcher =3D new QDBusPendingCallWatcher(dms.createResource(Nepomuk::DB= us::convertUriList(types), label, diff --git a/agents/nepomukfeeder/dms-copy/createresourcejob.h b/agents/nep= omukfeeder/dms-copy/createresourcejob.h index 3cc4d1c..190aba9 100644 --- a/agents/nepomukfeeder/dms-copy/createresourcejob.h +++ b/agents/nepomukfeeder/dms-copy/createresourcejob.h @@ -28,7 +28,6 @@ #include = #include "nepomukdatamanagement_export.h" -#include "datamanagement.h" = class KComponentData; class QDBusPendingCallWatcher; diff --git a/agents/nepomukfeeder/dms-copy/datamanagement.cpp b/agents/nepo= mukfeeder/dms-copy/datamanagement.cpp index 9c570b0..aedf54f 100644 --- a/agents/nepomukfeeder/dms-copy/datamanagement.cpp +++ b/agents/nepomukfeeder/dms-copy/datamanagement.cpp @@ -23,6 +23,7 @@ #include "genericdatamanagementjob_p.h" #include "createresourcejob.h" #include "describeresourcesjob.h" +#include "storeresourcesjob.h" #include "dbustypes.h" #include "simpleresourcegraph.h" = @@ -131,18 +132,15 @@ KJob* Nepomuk::mergeResources(const QUrl& resource1, Q_ARG(QString, component.component= Name())); } = -KJob* Nepomuk::storeResources(const SimpleResourceGraph& resources, - StoreIdentificationMode identificationMode, - StoreResourcesFlags flags, - const QHash& additionalMetad= ata, - const KComponentData& component) + +Nepomuk::StoreResourcesJob* Nepomuk::storeResources(const Nepomuk::SimpleR= esourceGraph& resources, + Nepomuk::StoreIdentifi= cationMode identificationMode, + Nepomuk::StoreResource= sFlags flags, + const QHash& additionalMetadata, + const KComponentData& = component) { - return new GenericDataManagementJob("storeResources", - Q_ARG(QList, resources.toList()), - Q_ARG(int, int(identificationMode)= ), - Q_ARG(int, int(flags)), - Q_ARG(Nepomuk::PropertyHash, addit= ionalMetadata), - Q_ARG(QString, component.component= Name())); + return new StoreResourcesJob( resources, identificationMode, flags, + additionalMetadata, component ); } = KJob* Nepomuk::importResources(const KUrl& url, @@ -163,7 +161,8 @@ KJob* Nepomuk::importResources(const KUrl& url, } = Nepomuk::DescribeResourcesJob* Nepomuk::describeResources(const QList& resources, - bool includeSubR= esources) + DescribeResource= sFlags flags, + const QList& targetParties ) { - return new DescribeResourcesJob(resources, includeSubResources); + return new DescribeResourcesJob(resources, flags, targetParties); } diff --git a/agents/nepomukfeeder/dms-copy/datamanagement.h b/agents/nepomu= kfeeder/dms-copy/datamanagement.h index 97f0a9b..4c3cb90 100644 --- a/agents/nepomukfeeder/dms-copy/datamanagement.h +++ b/agents/nepomukfeeder/dms-copy/datamanagement.h @@ -47,6 +47,7 @@ class KUrl; = namespace Nepomuk { class DescribeResourcesJob; + class StoreResourcesJob; class CreateResourceJob; class SimpleResourceGraph; = @@ -131,6 +132,41 @@ namespace Nepomuk { * syncing). But it can be queried at any time to be used for whatever= purpose. * * + * \section nepomuk_dms_resource_identification Resource Identification + * + * Resource identification is an important issue in storeResources(). = There are basically three ways to identify a resource: + * -# The trivial way to identify a resource is to provide the exact r= esource URI. + * -# The second, also rather trivial way to identify a resource is th= rough its nie:url. This can be a local file URL or an + * http URL or anything else as decribed in \ref nepomuk_dms_resource_= uris. + * -# The last, most interesting way to identify a resource is through= its properties and relations. This is what + * storeResources() does in Nepomuk::IdentifyNew mode. + * + * In general all properties with a literal range are considered ident= ifying. This includes properties like nao:prefLabel, + * nie:title, nco:fullname, and so on. All properties with a non-liter= al range are considered non-identifying. However, + * there are exceptions to this rule. Some properties with literal ran= ges are non-identifying since they express the state + * of a resource or an opinion of a particular user. + * + * Examples of properties like this include \c nao:numericRating, nie:= comment, or nco:imStatus. On the other hand there are + * properties with non-literal ranges which are in fact identifying. T= ypical examples include \c rdf:type, \c nfo:hasHash, + * or \c nmm:performer. + * + * To this end we make use of \c nrl:IdentifyingProperty and \c nrl:Fl= uxProperty. The former is used to mark specific properties + * as being identifying while the latter states that a property can ch= ange over time without actually chaning the identity + * of the resource. + * + * In storeResources() two resources are considered being equal if all= of their identifying properties match and they have at + * least one identifying propery in common. Matching identifying prope= rties here means that there is no identifying property + * with a different value in the other resource. + * + * + * \section nepomuk_dms_permissions Permissions in %Nepomuk + * + * FIXME: define exactly how permissions are handled. By default all i= s private. Questions remaining: + * - Do we define permissions on the graph level? + * - What is the range of the permissions? \c nao:Party? + * - How do we define "public to all"? + * + * * \section nepomuk_dms_advanced Advanced Nepomuk Concepts * * This section described advanced concepts in Nepomuk such as the dat= a layout used throughout the database. @@ -350,6 +386,23 @@ namespace Nepomuk { Q_DECLARE_FLAGS(StoreResourcesFlags, StoreResourcesFlag) = /** + * \brief Flags to influence the result of describeResources(). + * + * See the documentation of describeResources() for details. + */ + enum DescribeResourcesFlag { + /// No flags - default behaviour + NoDescribeResourcesFlags =3D 0, + + /// Exclude discardable data, ie. data which can be re-generated + ExcludeDiscardableData =3D 1, + + /// Exclude related resources, only include literal properties + ExcludeRelatedResources =3D 2 + }; + Q_DECLARE_FLAGS(DescribeResourcesFlags, DescribeResourcesFlag) + + /** * \brief Remove all information about resources from the database whi= ch * has been created by a specific application. * @@ -410,8 +463,10 @@ namespace Nepomuk { * to state that the provided information can be recreated at any time= . Only built-in types * such as int, string, or url are supported. * \param component The calling component. Typically this is left to t= he default. + * + * See \ref nepomuk_dms_resource_identification for details on how res= ources are identified. */ - NEPOMUK_DATA_MANAGEMENT_EXPORT KJob* storeResources(const Nepomuk::Sim= pleResourceGraph& resources, + NEPOMUK_DATA_MANAGEMENT_EXPORT StoreResourcesJob* storeResources(const= Nepomuk::SimpleResourceGraph& resources, Nepomuk::StoreIden= tificationMode identificationMode =3D Nepomuk::IdentifyNew, Nepomuk::StoreReso= urcesFlags flags =3D Nepomuk::NoStoreResourcesFlags, const QHash& additionalMetadata =3D QHash(), @@ -439,6 +494,8 @@ namespace Nepomuk { * to state that the provided information can be recreated at any time= . Only built-in types * such as int, string, or url are supported. * \param component The calling component. Typically this is left to t= he default. + * + * See \ref nepomuk_dms_resource_identification for details on how res= ources are identified. */ NEPOMUK_DATA_MANAGEMENT_EXPORT KJob* importResources(const KUrl& url, Soprano::RdfSeria= lization serialization, @@ -451,16 +508,42 @@ namespace Nepomuk { /** * \brief Retrieve all information about a set of resources. * + * Different levels of detail are available when retrieving resources.= These are modified through the + * \p flags where the following values are supported: + * + * - \c ExcludeDiscardableData - If this flag is enabled no discardabl= e data will be returned. This means + * that any data that has been created through storeResources() using = additional metadata including a graph + * type \c nrl:DiscardableInstanceBase is ignored. This includes for e= xample all information the file + * indexer has created. Be aware that this might even mean that some o= f the requested \p resources are not + * returned at all since they only contain discardable information. + * + * - \c ExcludeRelatedResources - If this flag is enabled related reso= urces are ignored, only properties with + * a literal value will be returned. The only exception are sub-resour= ces which are treated as part of the + * resource itself. Typical examples of sub-resources are address deta= ils of a contact or the performer + * contact of a music track. + * + * \b Related \b resources: + * + * If the \c ExcludeRelatedResources flag is not specified related res= ources are returned as well. Related + * resoures are returned by including only their identifying propertie= s. \ref nepomuk_dms_resource_identification + * explains the usage of identifying properties in more detail. + * * \param resources The resources to describe. See \ref nepomuk_dms_re= source_uris for details. - * \param includeSubResources If \p true sub resources will be include= d. See \ref nepomuk_dms_sub_resources for details. + * \param flags Optional flags to modify the data which is returned. + * \param targetParties This optional list can be used to specify the = parties (nao:Party) which should + * receive the returned data. This will result in a filtering of the r= esult according to configured + * permissions. Only data which is set as being public or readable by = the specified parties is returned. + * See \ref nepomuk_dms_permissions for details. \b NOT \b IMPLEMENTED= \b YET! */ NEPOMUK_DATA_MANAGEMENT_EXPORT DescribeResourcesJob* describeResources= (const QList& resources, - = bool includeSubResources); + = DescribeResourcesFlags flags =3D NoDescribeResourcesFlags, + = const QList& targetParties =3D QList() ); //@} //@} } = Q_DECLARE_OPERATORS_FOR_FLAGS(Nepomuk::RemovalFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(Nepomuk::StoreResourcesFlags) +Q_DECLARE_OPERATORS_FOR_FLAGS(Nepomuk::DescribeResourcesFlags) = #endif diff --git a/agents/nepomukfeeder/dms-copy/interfaces/datamanagementinterfa= ce.cpp b/agents/nepomukfeeder/dms-copy/datamanagementinterface.cpp similarity index 78% rename from agents/nepomukfeeder/dms-copy/interfaces/datamanagementinterfac= e.cpp rename to agents/nepomukfeeder/dms-copy/datamanagementinterface.cpp index 39709f7..5019353 100644 --- a/agents/nepomukfeeder/dms-copy/interfaces/datamanagementinterface.cpp +++ b/agents/nepomukfeeder/dms-copy/datamanagementinterface.cpp @@ -1,6 +1,6 @@ /* * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -m -i dbustypes.h -p datamanagementinter= face /home/chrigi/devel/kde/kdepim-runtime/agents/nepomukfeeder/dms-copy/in= terfaces/org.kde.nepomuk.DataManagement.xml + * Command line was: qdbusxml2cpp -m -i dbustypes.h -p datamanagementinter= face /home/trueg/kde/dev/kde/src/kde-runtime/nepomuk/interfaces/org.kde.nep= omuk.DataManagement.xml * * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidi= ary(-ies). * @@ -16,7 +16,7 @@ */ = OrgKdeNepomukDataManagementInterface::OrgKdeNepomukDataManagementInterface= (const QString &service, const QString &path, const QDBusConnection &connec= tion, QObject *parent) - : QDBusAbstractInterface(service, path, staticInterfaceName(), connect= ion, parent) + : AbstractTimeoutDBusInterface(service, path, staticInterfaceName(), c= onnection, parent) { } = diff --git a/agents/nepomukfeeder/dms-copy/interfaces/datamanagementinterfa= ce.h b/agents/nepomukfeeder/dms-copy/datamanagementinterface.h similarity index 84% rename from agents/nepomukfeeder/dms-copy/interfaces/datamanagementinterfac= e.h rename to agents/nepomukfeeder/dms-copy/datamanagementinterface.h index 8460796..6157770 100644 --- a/agents/nepomukfeeder/dms-copy/interfaces/datamanagementinterface.h +++ b/agents/nepomukfeeder/dms-copy/datamanagementinterface.h @@ -1,15 +1,16 @@ /* * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -m -i dbustypes.h -p datamanagementinter= face /home/chrigi/devel/kde/kdepim-runtime/agents/nepomukfeeder/dms-copy/in= terfaces/org.kde.nepomuk.DataManagement.xml + * Command line was: qdbusxml2cpp -m -i dbustypes.h -p datamanagementinter= face /home/trueg/kde/dev/kde/src/kde-runtime/nepomuk/interfaces/org.kde.nep= omuk.DataManagement.xml * * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidi= ary(-ies). * * This is an auto-generated file. - * Do not edit! All changes made to it will be lost. + * + * It contains one small change: it is derived from AbstractTimeoutDbusInt= erface instead of QDBusAbstractInterface and uses a big timeout. */ = -#ifndef DATAMANAGEMENTINTERFACE_H_1312387679 -#define DATAMANAGEMENTINTERFACE_H_1312387679 +#ifndef DATAMANAGEMENTINTERFACE_H_1308595912 +#define DATAMANAGEMENTINTERFACE_H_1308595912 = #include #include @@ -21,12 +22,18 @@ #include #include "dbustypes.h" = +#include "abstracttimeoutdbusinterface.h" + /* * Proxy class for interface org.kde.nepomuk.DataManagement */ -class OrgKdeNepomukDataManagementInterface: public QDBusAbstractInterface +class OrgKdeNepomukDataManagementInterface: public AbstractTimeoutDBusInte= rface { Q_OBJECT + + /// we use a big timeout (10 min) since commands are queued in the DMS + static const int s_defaultTimeout =3D 600000; + public: static inline const char *staticInterfaceName() { return "org.kde.nepomuk.DataManagement"; } @@ -41,133 +48,133 @@ public Q_SLOTS: // METHODS { QList argumentList; argumentList << qVariantFromValue(resource) << qVariantFromValue(p= roperty) << qVariantFromValue(value) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("addProperty"), arg= umentList); + return asyncCallWithArgumentList(QLatin1String("addProperty"), arg= umentList, s_defaultTimeout); } = inline QDBusPendingReply<> addProperty(const QStringList &resources, c= onst QString &property, const QVariantList &values, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resources) << qVariantFromValue(= property) << qVariantFromValue(values) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("addProperty"), arg= umentList); + return asyncCallWithArgumentList(QLatin1String("addProperty"), arg= umentList, s_defaultTimeout); } = inline QDBusPendingReply createResource(const QString &type, = const QString &label, const QString &description, const QString &app) { QList argumentList; argumentList << qVariantFromValue(type) << qVariantFromValue(label= ) << qVariantFromValue(description) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("createResource"), = argumentList); + return asyncCallWithArgumentList(QLatin1String("createResource"), = argumentList, s_defaultTimeout); } = inline QDBusPendingReply createResource(const QStringList &ty= pes, const QString &label, const QString &description, const QString &app) { QList argumentList; argumentList << qVariantFromValue(types) << qVariantFromValue(labe= l) << qVariantFromValue(description) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("createResource"), = argumentList); + return asyncCallWithArgumentList(QLatin1String("createResource"), = argumentList, s_defaultTimeout); } = - inline QDBusPendingReply > describeReso= urces(const QStringList &resources, bool includeSubResources) + inline QDBusPendingReply > describeReso= urces(const QStringList &resources, int flags, const QStringList &targetPar= ties) { QList argumentList; - argumentList << qVariantFromValue(resources) << qVariantFromValue(= includeSubResources); - return asyncCallWithArgumentList(QLatin1String("describeResources"= ), argumentList); + argumentList << qVariantFromValue(resources) << qVariantFromValue(= flags) << qVariantFromValue(targetParties); + return asyncCallWithArgumentList(QLatin1String("describeResources"= ), argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> importResources(const QString &url, const Q= String &serialization, int identificationMode, int flags, const QString &ap= p) { QList argumentList; argumentList << qVariantFromValue(url) << qVariantFromValue(serial= ization) << qVariantFromValue(identificationMode) << qVariantFromValue(flag= s) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("importResources"),= argumentList); + return asyncCallWithArgumentList(QLatin1String("importResources"),= argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> importResources(const QString &url, const Q= String &serialization, int identificationMode, int flags, Nepomuk::Property= Hash additionalMetadata, const QString &app) { QList argumentList; argumentList << qVariantFromValue(url) << qVariantFromValue(serial= ization) << qVariantFromValue(identificationMode) << qVariantFromValue(flag= s) << qVariantFromValue(additionalMetadata) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("importResources"),= argumentList); + return asyncCallWithArgumentList(QLatin1String("importResources"),= argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> mergeResources(const QString &resource1, co= nst QString &resource2, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resource1) << qVariantFromValue(= resource2) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("mergeResources"), = argumentList); + return asyncCallWithArgumentList(QLatin1String("mergeResources"), = argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> removeDataByApplication(int flags, const QS= tring &app) { QList argumentList; argumentList << qVariantFromValue(flags) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("removeDataByApplic= ation"), argumentList); + return asyncCallWithArgumentList(QLatin1String("removeDataByApplic= ation"), argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> removeDataByApplication(const QStringList &= resources, int flags, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resources) << qVariantFromValue(= flags) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("removeDataByApplic= ation"), argumentList); + return asyncCallWithArgumentList(QLatin1String("removeDataByApplic= ation"), argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> removeProperties(const QString &resource, c= onst QString &property, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resource) << qVariantFromValue(p= roperty) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("removeProperties")= , argumentList); + return asyncCallWithArgumentList(QLatin1String("removeProperties")= , argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> removeProperties(const QStringList &resourc= es, const QStringList &properties, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resources) << qVariantFromValue(= properties) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("removeProperties")= , argumentList); + return asyncCallWithArgumentList(QLatin1String("removeProperties")= , argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> removeProperty(const QString &resource, con= st QString &property, const QDBusVariant &value, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resource) << qVariantFromValue(p= roperty) << qVariantFromValue(value) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("removeProperty"), = argumentList); + return asyncCallWithArgumentList(QLatin1String("removeProperty"), = argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> removeProperty(const QStringList &resources= , const QString &property, const QVariantList &values, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resources) << qVariantFromValue(= property) << qVariantFromValue(values) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("removeProperty"), = argumentList); + return asyncCallWithArgumentList(QLatin1String("removeProperty"), = argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> removeResources(const QString &resource, in= t flags, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resource) << qVariantFromValue(f= lags) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("removeResources"),= argumentList); + return asyncCallWithArgumentList(QLatin1String("removeResources"),= argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> removeResources(const QStringList &resource= s, int flags, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resources) << qVariantFromValue(= flags) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("removeResources"),= argumentList); + return asyncCallWithArgumentList(QLatin1String("removeResources"),= argumentList, s_defaultTimeout); } = inline QDBusPendingReply<> setProperty(const QString &resource, const = QString &property, const QDBusVariant &value, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resource) << qVariantFromValue(p= roperty) << qVariantFromValue(value) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("setProperty"), arg= umentList); + return asyncCallWithArgumentList(QLatin1String("setProperty"), arg= umentList, s_defaultTimeout); } = inline QDBusPendingReply<> setProperty(const QStringList &resources, c= onst QString &property, const QVariantList &values, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resources) << qVariantFromValue(= property) << qVariantFromValue(values) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("setProperty"), arg= umentList); + return asyncCallWithArgumentList(QLatin1String("setProperty"), arg= umentList, s_defaultTimeout); } = inline QDBusPendingReply<> storeResources(const QList &resources, int identificationMode, int flags, Nepomuk::PropertyHa= sh additionalMetadata, const QString &app) { QList argumentList; argumentList << qVariantFromValue(resources) << qVariantFromValue(= identificationMode) << qVariantFromValue(flags) << qVariantFromValue(additi= onalMetadata) << qVariantFromValue(app); - return asyncCallWithArgumentList(QLatin1String("storeResources"), = argumentList); + return asyncCallWithArgumentList(QLatin1String("storeResources"), = argumentList, s_defaultTimeout); } = Q_SIGNALS: // SIGNALS diff --git a/agents/nepomukfeeder/dms-copy/dbustypes.cpp b/agents/nepomukfe= eder/dms-copy/dbustypes.cpp index 27fd0f4..09e5dde 100644 --- a/agents/nepomukfeeder/dms-copy/dbustypes.cpp +++ b/agents/nepomukfeeder/dms-copy/dbustypes.cpp @@ -122,6 +122,9 @@ void Nepomuk::DBus::registerDBusTypes() = // required for the additional metadata in storeResources qDBusRegisterMetaType(); + + // required for returning the mappings in storeResources + qDBusRegisterMetaType< QHash >(); } = // We need the QUrl serialization to be able to pass URIs in variants diff --git a/agents/nepomukfeeder/dms-copy/dbustypes.h b/agents/nepomukfeed= er/dms-copy/dbustypes.h index 900e219..ce1e578 100644 --- a/agents/nepomukfeeder/dms-copy/dbustypes.h +++ b/agents/nepomukfeeder/dms-copy/dbustypes.h @@ -36,10 +36,14 @@ Q_DECLARE_METATYPE(Nepomuk::PropertyHash) Q_DECLARE_METATYPE(Nepomuk::SimpleResource) Q_DECLARE_METATYPE(QList) = +//CAUTION: Q_DECLARE_METATYPE doesn't accept template arguments like QHash= +typedef QHash __nepomuk_QHashQStringQString; +Q_DECLARE_METATYPE( __nepomuk_QHashQStringQString ) + namespace Nepomuk { namespace DBus { - QString convertUri(const QUrl& uri); - QStringList convertUriList(const QList& uris); + QString NEPOMUK_DATA_MANAGEMENT_EXPORT convertUri(const QUrl& uri); + QStringList NEPOMUK_DATA_MANAGEMENT_EXPORT convertUriList(const QL= ist& uris); = /// Convert QDBusArguments variants into QUrl, QDate, QTime, and Q= DateTime variants NEPOMUK_DATA_MANAGEMENT_EXPORT QVariant resolveDBusArguments(const= QVariant& v); diff --git a/agents/nepomukfeeder/dms-copy/describeresourcesjob.cpp b/agent= s/nepomukfeeder/dms-copy/describeresourcesjob.cpp index b955ea1..60a4420 100644 --- a/agents/nepomukfeeder/dms-copy/describeresourcesjob.cpp +++ b/agents/nepomukfeeder/dms-copy/describeresourcesjob.cpp @@ -24,6 +24,7 @@ #include "simpleresourcegraph.h" #include "dbustypes.h" #include "genericdatamanagementjob_p.h" +#include "kdbusconnectionpool.h" = #include #include @@ -43,7 +44,8 @@ public: }; = Nepomuk::DescribeResourcesJob::DescribeResourcesJob(const QList& res= ources, - bool includeSubResourc= es) + DescribeResourcesFlags= flags, + const QList& tar= getGroups) : KJob(0), d(new Private) { @@ -51,10 +53,11 @@ Nepomuk::DescribeResourcesJob::DescribeResourcesJob(con= st QList& resources = org::kde::nepomuk::DataManagement dms(QLatin1String(DMS_DBUS_SERVICE), QLatin1String("/datamanagement"), - QDBusConnection::sessionBus()); + KDBusConnectionPool::threadConne= ction()); QDBusPendingCallWatcher* dbusCallWatcher =3D new QDBusPendingCallWatcher(dms.describeResources(Nepomuk:= :DBus::convertUriList(resources), - includeSub= Resources)); + int(flags), + Nepomuk::D= Bus::convertUriList(targetGroups))); connect(dbusCallWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(slotDBusCallFinished(QDBusPendingCallWatcher*))); } diff --git a/agents/nepomukfeeder/dms-copy/describeresourcesjob.h b/agents/= nepomukfeeder/dms-copy/describeresourcesjob.h index 643b413..c63c854 100644 --- a/agents/nepomukfeeder/dms-copy/describeresourcesjob.h +++ b/agents/nepomukfeeder/dms-copy/describeresourcesjob.h @@ -27,8 +27,8 @@ #include #include = -#include "nepomukdatamanagement_export.h" #include "datamanagement.h" +#include "nepomukdatamanagement_export.h" = class QDBusPendingCallWatcher; = @@ -69,14 +69,16 @@ private Q_SLOTS: = private: DescribeResourcesJob(const QList& resources, - bool includeSubResources); + DescribeResourcesFlags flags, + const QList& targetGroups); void start(); = class Private; Private* const d; = friend Nepomuk::DescribeResourcesJob* Nepomuk::describeResources(const= QList&, - bool); + Nepom= uk::DescribeResourcesFlags, + const= QList&); }; } = diff --git a/agents/nepomukfeeder/dms-copy/genericdatamanagementjob.cpp b/a= gents/nepomukfeeder/dms-copy/genericdatamanagementjob.cpp index 949dfc0..3d79b62 100644 --- a/agents/nepomukfeeder/dms-copy/genericdatamanagementjob.cpp +++ b/agents/nepomukfeeder/dms-copy/genericdatamanagementjob.cpp @@ -22,6 +22,7 @@ #include "genericdatamanagementjob_p.h" #include "datamanagementinterface.h" #include "dbustypes.h" +#include "kdbusconnectionpool.h" = #include #include @@ -46,7 +47,7 @@ Nepomuk::GenericDataManagementJob::GenericDataManagementJ= ob(const char *methodNa = org::kde::nepomuk::DataManagement dms(QLatin1String(DMS_DBUS_SERVICE), QLatin1String("/datamanagement"), - QDBusConnection::sessionBus()); + KDBusConnectionPool::threadConne= ction()); QDBusPendingReply<> reply; QMetaObject::invokeMethod(&dms, methodName, diff --git a/agents/nepomukfeeder/dms-copy/interfaces/CMakeLists.txt b/agen= ts/nepomukfeeder/dms-copy/interfaces/CMakeLists.txt deleted file mode 100644 index 9490e99..0000000 --- a/agents/nepomukfeeder/dms-copy/interfaces/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -project(nepomuk_interfaces) - -#install(FILES -# org.kde.nepomuk.DataManagement.xml -# org.kde.nepomuk.ResourceWatcher.xml -# org.kde.nepomuk.ResourceWatcherConnection.xml -# DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} -# ) diff --git a/agents/nepomukfeeder/dms-copy/interfaces/org.kde.nepomuk.DataM= anagement.xml b/agents/nepomukfeeder/dms-copy/interfaces/org.kde.nepomuk.Da= taManagement.xml deleted file mode 100644 index 0172373..0000000 --- a/agents/nepomukfeeder/dms-copy/interfaces/org.kde.nepomuk.DataManageme= nt.xml +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/agents/nepomukfeeder/dms-copy/kdbusconnectionpool.cpp b/agents= /nepomukfeeder/dms-copy/kdbusconnectionpool.cpp new file mode 100644 index 0000000..43e1f5f --- /dev/null +++ b/agents/nepomukfeeder/dms-copy/kdbusconnectionpool.cpp @@ -0,0 +1,68 @@ +/* + * This file is part of the Nepomuk KDE project. + * Copyright (C) 2010 Sebastian Trueg + * Copyright (C) 2010 David Faure + * + * 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 Licen= se + * 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 "kdbusconnectionpool.h" +#include + +namespace { +QAtomicInt s_connectionCounter; + +class KDBusConnectionPoolPrivate +{ +public: + KDBusConnectionPoolPrivate() + : m_connection( QDBusConnection::connectToBus( + QDBusConnection::SessionBus, + QString::fromLatin1("NepomukQueryServiceConnec= tion%1").arg(newNumber()) ) ) + { + } + + ~KDBusConnectionPoolPrivate() + { + QDBusConnection::disconnectFromBus( m_connection.name() ); + } + + QDBusConnection connection() const + { + return m_connection; + } + +private: + static int newNumber() + { + return s_connectionCounter.fetchAndAddAcquire(1); + } + + QDBusConnection m_connection; +}; +} // namespace + +QThreadStorage s_perThreadConnection; + +QDBusConnection KDBusConnectionPool::threadConnection() +{ + if (!s_perThreadConnection.hasLocalData()) { + s_perThreadConnection.setLocalData(new KDBusConnectionPoolPrivate); + } + + return s_perThreadConnection.localData()->connection(); +} + diff --git a/agents/nepomukfeeder/dms-copy/kdbusconnectionpool.h b/agents/n= epomukfeeder/dms-copy/kdbusconnectionpool.h new file mode 100644 index 0000000..d4c7e9d --- /dev/null +++ b/agents/nepomukfeeder/dms-copy/kdbusconnectionpool.h @@ -0,0 +1,39 @@ +/* + * This file is part of the Nepomuk KDE project. + * Copyright (C) 2010 Sebastian Trueg + * + * 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 Licen= se + * 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 KDBUSCONNECTIONPOOL_H +#define KDBUSCONNECTIONPOOL_H + +#include + +namespace KDBusConnectionPool +{ +/** + * The KDBusConnectionPool works around the problem + * of QDBusConnection not being thread-safe. As soon as that + * has been fixed (either directly in libdbus or with a work- + * around in Qt) this method can be dropped in favor of + * QDBusConnection::sessionBus(). + */ +QDBusConnection threadConnection(); +} + +#endif + diff --git a/agents/nepomukfeeder/dms-copy/nepomuk-simpleresource-rcgen.py = b/agents/nepomukfeeder/dms-copy/nepomuk-simpleresource-rcgen.py deleted file mode 100644 index 304db56..0000000 --- a/agents/nepomukfeeder/dms-copy/nepomuk-simpleresource-rcgen.py +++ /dev/null @@ -1,395 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -## This file is part of the Nepomuk KDE project. -## Copyright (C) 2011 Sebastian Trueg -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) version 3, or any -## later version accepted by the membership of KDE e.V. (or its -## successor approved by the membership of KDE e.V.), which shall -## act as a proxy defined in Section 6 of version 3 of the license. -## -## 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 -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library. If not, see . - - -import optparse -import sys -import os, errno -from PyKDE4.soprano import Soprano -from PyQt4 import QtCore - -output_path =3D os.getcwd() -verbose =3D True - -def normalizeName(name): - "Normalize a class or property name to be used as a C++ entity." - name.replace('-', '_') - name.replace('.', '_') - return name - -def extractNameFromUri(uri): - "Extract the class or property name from an entity URI. This is the la= st section of the URI" - name =3D uri.toString().mid(uri.toString().lastIndexOf(QtCore.QRegExp(= '[#/:]'))+1) - return normalizeName(name) - -def makeFancy(name, cardinality): - if cardinality !=3D 1: - if name.endsWith('s'): - return name + 'es' - else: - return name + 's' - else: - return name - -def extractOntologyName(uri): - "The name of the ontology is typically the section before the name of = the entity" - return uri.toString().section(QtCore.QRegExp('[#/:]'), -2, -2) - = -def mkdir_p(path): - "Create a folder and all its missing parent folders" - try: - os.makedirs(path) - except OSError as exc: # Python >2.5 - if exc.errno =3D=3D errno.EEXIST: - pass - else: raise - -def typeString(rdfType, cardinality): - """ - Construct the C++/Qt type to be used for the given type and cardinalit= y. - Uses QUrl for all non-literal types - """ - if (rdfType =3D=3D Soprano.Vocabulary.XMLSchema.string() or rdfType = =3D=3D Soprano.Vocabulary.RDFS.Literal()) and cardinality !=3D 1: - return 'QStringList' - - simpleType =3D '' - if rdfType =3D=3D Soprano.Vocabulary.XMLSchema.integer(): simpleType = =3D "qint64" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.negativeInteger(): si= mpleType =3D "qint64" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.nonNegativeInteger():= simpleType =3D "quint64" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.xsdLong(): simpleType= =3D "qint64" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.unsignedLong(): simpl= eType =3D "quint64" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.xsdInt(): simpleType = =3D "qint32" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.unsignedInt(): simple= Type =3D "quint32" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.xsdShort(): simpleTyp= e =3D "qint16" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.unsignedShort(): simp= leType =3D "quint16" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.xsdFloat(): simpleTyp= e =3D "double" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.xsdDouble(): simpleTy= pe =3D "double" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.boolean(): simpleType= =3D "bool" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.date(): simpleType = =3D "QDate" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.time(): simpleType = =3D "QTime" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.dateTime(): simpleTyp= e =3D "QDateTime" - elif rdfType =3D=3D Soprano.Vocabulary.XMLSchema.string(): simpleType = =3D "QString" - elif rdfType =3D=3D Soprano.Vocabulary.RDFS.Literal(): simpleType =3D = "QString" - else: simpleType =3D 'QUrl' - - if cardinality !=3D 1: - return 'QList<%s>' % simpleType - else: - return simpleType - - -class OntologyParser(): - def __init__(self): - self.model =3D Soprano.createModel() - - def parseFile(self, path): - parser =3D Soprano.PluginManager.instance().discoverParserForSeria= lization(Soprano.SerializationTrig) - if not parser: - return False - it =3D parser.parseFile(path, QtCore.QUrl("dummy"), Soprano.Serial= izationTrig) - while it.next(): - self.model.addStatement(it.current()) - if parser.lastError(): - return False; - - return True - - def writeAll(self): - # add rdfs:Resource as domain for all properties without a domain - query =3D 'select ?p where { ?p a %s . OPTIONAL { ?p %s ?d . } . F= ILTER(!BOUND(?d)) . }' \ - % (Soprano.Node.resourceToN3(Soprano.Vocabulary.RDF.Prope= rty()), \ - Soprano.Node.resourceToN3(Soprano.Vocabulary.RDFS= .domain())) - nodes =3D self.model.executeQuery(query, Soprano.Query.QueryLangua= geSparql).iterateBindings(0).allNodes() - for p in nodes: - self.model.addStatement(p, Soprano.Node(Soprano.Vocabulary.RDF= S.domain()), Soprano.Node(Soprano.Vocabulary.RDFS.Resource())) - = - # cache a few values we need more than once - self.rdfsResourceProperties =3D self.getPropertiesForClass(Soprano= .Vocabulary.RDFS.Resource()) - - query =3D 'select distinct ?uri ?label ?comment where {{ ?uri a {0= } . ?uri {1} ?label . OPTIONAL {{ ?uri {2} ?comment . }} . }}' \ - .format(Soprano.Node.resourceToN3(Soprano.Vocabulary.RDFS.Clas= s()), \ - Soprano.Node.resourceToN3(Soprano.Vocabulary.RDFS= .label()), \ - Soprano.Node.resourceToN3(Soprano.Vocabulary.RDFS= .comment())) - it =3D self.model.executeQuery(query, Soprano.Query.QueryLanguageS= parql) - = - while it.next(): - uri =3D it['uri'].uri() - ns =3D self.getNamespaceAbbreviationForUri(uri) - name =3D extractNameFromUri(uri) - self.writeHeader(uri, ns, name, it['label'].toString(), it['co= mment'].toString()) - - def getNamespaceAbbreviationForUri(self, uri): - query =3D "select ?ns where { graph ?g { %s ?p ?o . } . ?g %s ?ns = . } LIMIT 1" \ - % (Soprano.Node.resourceToN3(uri), \ - Soprano.Node.resourceToN3(Soprano.Vocabulary.NAO.hasDefault= NamespaceAbbreviation())) - it =3D self.model.executeQuery(query, Soprano.Query.QueryLanguageS= parql) - if it.next(): - return it[0].toString().toLower() - else: - return extractOntologyName(uri) - - def getParentClasses(self, uri): - # We only select parent classes that we actually generate - query =3D "select distinct ?uri where {{ {0} {1} ?uri . ?uri a {2}= . }}" \ - .format(Soprano.Node.resourceToN3(uri), \ - Soprano.Node.resourceToN3(Soprano.Vocabulary.RDF= S.subClassOf()), \ - Soprano.Node.resourceToN3(Soprano.Vocabulary.RDF= S.Class())) - it =3D self.model.executeQuery(query, Soprano.Query.QueryLanguageS= parql) - classes =3D {} - while it.next(): - puri =3D it['uri'].uri() - if puri !=3D Soprano.Vocabulary.RDFS.Resource(): - cd =3D {} - cd['ns'] =3D self.getNamespaceAbbreviationForUri(puri) - cd['name'] =3D extractNameFromUri(puri) - classes[puri] =3D cd - return classes - - def getPropertiesForClass(self, uri): - #print "Getting properties for %s..." % uri.toString() - query =3D "select distinct ?p ?range ?comment ?c ?mc where { ?p a = %s . ?p %s %s . ?p %s ?range . OPTIONAL { ?p %s ?comment . } . OPTIONAL { ?= p %s ?c . } . OPTIONAL { ?p %s ?mc . } . }" \ - % (Soprano.Node.resourceToN3(Soprano.Vocabulary.RDF.Property()= ), - Soprano.Node.resourceToN3(Soprano.Vocabulary.RDFS.domain()), - Soprano.Node.resourceToN3(uri), - Soprano.Node.resourceToN3(Soprano.Vocabulary.RDFS.range()), - Soprano.Node.resourceToN3(Soprano.Vocabulary.RDFS.comment()= ), - Soprano.Node.resourceToN3(Soprano.Vocabulary.NRL.cardinalit= y()), - Soprano.Node.resourceToN3(Soprano.Vocabulary.NRL.maxCardina= lity())) - it =3D self.model.executeQuery(query, Soprano.Query.QueryLanguageS= parql) - #print "Property query done." - properties =3D {} - while it.next(): - p =3D it['p'].uri() - r =3D it['range'].uri() - comment =3D it['comment'].toString() - c =3D 0 - if it['c'].isValid(): - c =3D it['c'].literal().toInt(); - else: - c =3D it['mc'].literal().toInt(); - properties[p] =3D dict([('range', r), ('cardinality', c), ('co= mment', comment)]) - #print "Done getting properties." - return properties - - def writeComment(self, theFile, text, indent): - maxLine =3D 50; - - theFile.write(' ' * indent*4) - theFile.write("/**\n") - theFile.write(' ' * (indent*4+1)) - theFile.write("* ") - - words =3D QtCore.QString(text).split( QtCore.QRegExp("\\s"), QtCor= e.QString.SkipEmptyParts ) - cnt =3D 0; - for i in range(words.count()): - if cnt >=3D maxLine: - theFile.write('\n') - theFile.write(' ' * (indent*4+1)) - theFile.write("* ") - cnt =3D 0; - theFile.write(words[i]) - theFile.write(' ') - cnt +=3D words[i].length() - - theFile.write('\n') - theFile.write(' ' * (indent*4+1)) - theFile.write("*/\n") - - def writeGetter(self, theFile, prop, name, propRange, cardinality): - theFile.write(' %s %s() const {\n' % (typeString(propRange, car= dinality), makeFancy(name, cardinality))) - theFile.write(' %s value;\n' % typeString(propRange, cardin= ality)) - if cardinality =3D=3D 1: - theFile.write(' if(m_res->contains(QUrl::fromEncoded("%= s", QUrl::StrictMode)))\n' % prop.toString()) - theFile.write(' value =3D m_res->property(QUrl::fro= mEncoded("{0}", QUrl::StrictMode)).first().value<{1}>();\n'.format(prop.toS= tring(), typeString(propRange, 1))) - else: - theFile.write(' foreach(const QVariant& v, m_res->prope= rty(QUrl::fromEncoded("%s", QUrl::StrictMode)))\n' % prop.toString()) - theFile.write(' value << v.value<{0}>();\n'.format(= typeString(propRange, 1))) - theFile.write(' return value;\n') - theFile.write(' }\n') - - def writeSetter(self, theFile, prop, name, propRange, cardinality): - theFile.write(' void set%s%s(const %s& value) {\n' % (makeFancy= (name, cardinality)[0].toUpper(), makeFancy(name, cardinality).mid(1), type= String(propRange, cardinality))) - theFile.write(' m_res->addProperty(Soprano::Vocabulary::RDF= ::type(), resourceType());\n') - theFile.write(' QVariantList values;\n') - if cardinality =3D=3D 1: - theFile.write(' values << value;\n') - else: - theFile.write(' foreach(const %s& v, value)\n' % typeS= tring(propRange, 1)) - theFile.write(' values << v;\n') - theFile.write(' m_res->setProperty(QUrl::fromEncoded("%s", = QUrl::StrictMode), values);\n' % prop.toString()) - theFile.write(' }\n') - - def writeAdder(self, theFile, prop, name, propRange, cardinality): - theFile.write(' void add%s%s(const %s& value) {\n' % (makeFancy= (name, 1)[0].toUpper(), makeFancy(name, 1).mid(1), typeString(propRange, 1)= )) - theFile.write(' m_res->addProperty(Soprano::Vocabulary::RDF= ::type(), resourceType());\n') - theFile.write(' m_res->addProperty(QUrl::fromEncoded("%s", = QUrl::StrictMode), value);\n' % prop.toString()) - theFile.write(' }\n') - - def writeHeader(self, uri, nsAbbr, className, label, comment): - # Construct paths - folder =3D output_path + '/' + nsAbbr - filePath =3D folder + '/' + className.toLower() + '.h' - - if verbose: - print "Writing header file: %s" % filePath - - # Create the containing folder - mkdir_p(QtCore.QFile.encodeName(folder).data()) - - # open the header file - header =3D open(filePath, 'w') - - parentClasses =3D self.getParentClasses(uri) - - # write protecting ifdefs - header_protect =3D '_%s_%s_H_' % (nsAbbr.toUpper(), className.toUp= per()) - header.write('#ifndef %s\n' % header_protect) - header.write('#define %s\n' % header_protect) - header.write('\n') - = - # write default includes - header.write('#include \n') - header.write('#include \n') - header.write('#include \n') - header.write('#include \n') - header.write('#include \n') - header.write('#include \n') - header.write('#include \n') - header.write('\n') - - # all classes need the SimpleResource include - header.write('#include \n\n') - - # write includes for the parent classes - parentClassNames =3D [] - for parent in parentClasses.keys(): - header.write('#include "%s/%s.h"\n' % (parentClasses[parent][= 'ns'], parentClasses[parent]['name'].toLower())) - parentClassNames.append("%s::%s" %(parentClasses[parent]['ns'= ].toUpper(), parentClasses[parent]['name'])) - - # write the class namespace - header.write('namespace Nepomuk {\n') - header.write('namespace %s {\n' % nsAbbr.toUpper()) - - # write the class + parent classes - self.writeComment(header, comment, 0) - header.write('class %s' % className) - if len(parentClassNames) > 0: - header.write(' : ') - header.write(', '.join(['public %s' % (p) for p in parentClassName= s])) - header.write('\n{\n') - header.write('public:\n') - - # write the constructor - header.write(' %s(Nepomuk::SimpleResource* res)\n' % className) - header.write(' : ') - header.write(', '.join(['%s(res)' % p for p in parentClassNames])) - if len(parentClassNames) > 0: - header.write(', ') - header.write('m_res(res)\n {}\n\n') - - # write the destructor (necessary for the virtual resourceType() m= ethod - header.write(' virtual ~%s() {}\n\n' % className) - - # Write getter and setter methods for all properties - # This includes the properties that have domain rdfs:Resource on b= ase classes, ie. - # those that are not derived from any other class. That way these = properties are - # accessible from all classes. - properties =3D self.getPropertiesForClass(uri) - if len(parentClassNames) =3D=3D 0: - properties.update(self.rdfsResourceProperties) - - # There could be properties with the same name - in that case we g= ive the methods a prefix - for p in properties.keys(): - name =3D extractNameFromUri(p) - cnt =3D 0 - # search for the same name again - for op in properties.keys(): - if extractNameFromUri(op) =3D=3D name: - cnt+=3D1 - if cnt > 1: - name =3D self.getNamespaceAbbreviationForUri(p).toLower() = + name[0].toUpper() + name.mid(1) - properties[p]['name'] =3D name; - = - for p in properties.keys(): - self.writeComment(header, 'Get property %s. %s' % (p.toString(= ), properties[p]['comment']), 1) - self.writeGetter(header, p, properties[p]['name'], properties[= p]['range'], properties[p]['cardinality']) - header.write('\n') - self.writeComment(header, 'Set property %s. %s' % (p.toString(= ), properties[p]['comment']), 1) - self.writeSetter(header, p, properties[p]['name'], properties[= p]['range'], properties[p]['cardinality']) - header.write('\n') - self.writeComment(header, 'Add value to property %s. %s' % (p.= toString(), properties[p]['comment']), 1) - self.writeAdder(header, p, properties[p]['name'], properties[p= ]['range'], properties[p]['cardinality']) - header.write('\n') - - # write the protected resource type access method - header.write('protected:\n') - header.write(' virtual QUrl resourceType() const { return QUrl:= :fromEncoded("%s", QUrl::StrictMode); }\n' % uri.toString()) - header.write('\n') - - # write the private members - header.write('private:\n') - header.write(' Nepomuk::SimpleResource* m_res;\n') - - # close the class - header.write('};\n') - - # write the closing parenthesis for the namespaces - header.write('}\n}\n') - - # write the closing preprocessor thingi - header.write('\n#endif\n') - = - -def main(): - global output_path - global verbose - = - usage =3D "Usage: %prog [options] ontologyfile1 ontologyfile2 ..." - optparser =3D optparse.OptionParser(usage=3Dusage, description=3D"Nepo= muk SimpleResource code generator. It will generate a hierarchy of simple w= rapper classes around Nepomuk::SimpleResource which provide convinience met= hods to get and set properties of those classes. Each wrapper class will be= defined in its own header file and be written to a subdirectory named as t= he default ontology prefix. Example: the header file for nao:Tag would be w= ritten to nao/tag.h and be defined in the namespace Nepomuk::NAO.") - optparser.add_option('--output', '-o', metavar=3D'PATH', dest=3D'outpu= t', help=3D'The destination folder') - optparser.add_option('--quiet', '-q', action=3D"store_false", dest=3D"= verbose", default=3DTrue, help=3D"don't print status messages to stdout") - - (options, args) =3D optparser.parse_args() - if len(args) =3D=3D 0: - optparser.error('No ontology file specified.') - if options.output and len(options.output) > 0: - output_path =3D options.output - verbose =3D options.verbose - = - if verbose: - print 'Generating from ontology files %s' % ','.join(args) - print 'Writing files to %s.' % output_path - - # Parse all ontology files - ontoParser =3D OntologyParser() - for f in args: - if verbose: - print "Reading ontology '%s'" % f - ontoParser.parseFile(f) - if verbose: - print "All ontologies read. Generating code..." - - # Get all classes and handle them one by one - ontoParser.writeAll() - -if __name__ =3D=3D "__main__": - main() diff --git a/agents/nepomukfeeder/dms-copy/nepomukdatamanagement_export.h b= /agents/nepomukfeeder/dms-copy/nepomukdatamanagement_export.h index bf97f4d..929a737 100644 --- a/agents/nepomukfeeder/dms-copy/nepomukdatamanagement_export.h +++ b/agents/nepomukfeeder/dms-copy/nepomukdatamanagement_export.h @@ -24,7 +24,7 @@ #include = #ifndef NEPOMUK_DATA_MANAGEMENT_EXPORT -# if defined(MAKE_NEPOMUKDATAMANAGEMENT_COPY_LIB) +# if defined(MAKE_NEPOMUKDATAMANAGEMENT_LIB) /* We are building this library */ = # define NEPOMUK_DATA_MANAGEMENT_EXPORT KDE_EXPORT # else diff --git a/agents/nepomukfeeder/dms-copy/resourcewatcher.cpp b/agents/nep= omukfeeder/dms-copy/resourcewatcher.cpp index 0761aad..f6fc93c 100644 --- a/agents/nepomukfeeder/dms-copy/resourcewatcher.cpp +++ b/agents/nepomukfeeder/dms-copy/resourcewatcher.cpp @@ -118,7 +118,6 @@ bool Nepomuk::ResourceWatcher::start() void Nepomuk::ResourceWatcher::stop() { if (d->m_connectionInterface) { - d->m_connectionInterface->disconnect( this ); d->m_connectionInterface->close(); delete d->m_connectionInterface; d->m_connectionInterface =3D 0; diff --git a/agents/nepomukfeeder/dms-copy/simpleresource.cpp b/agents/nepo= mukfeeder/dms-copy/simpleresource.cpp index dfd72af..5293961 100644 --- a/agents/nepomukfeeder/dms-copy/simpleresource.cpp +++ b/agents/nepomukfeeder/dms-copy/simpleresource.cpp @@ -81,7 +81,7 @@ Nepomuk::SimpleResource::~SimpleResource() { } = -Nepomuk::SimpleResource & Nepomuk::SimpleResource::operator =3D(const Nepo= muk::SimpleResource &other) +Nepomuk::SimpleResource & Nepomuk::SimpleResource::operator=3D(const Nepom= uk::SimpleResource &other) { d =3D other.d; return *this; @@ -147,7 +147,7 @@ bool Nepomuk::SimpleResource::isValid() const return true; } = -bool Nepomuk::SimpleResource::operator =3D=3D(const Nepomuk::SimpleResourc= e &other) const +bool Nepomuk::SimpleResource::operator=3D=3D(const Nepomuk::SimpleResource= &other) const { return d->m_uri =3D=3D other.d->m_uri && d->m_properties =3D=3D other.= d->m_properties; } @@ -224,16 +224,36 @@ void Nepomuk::SimpleResource::addPropertyNode(const Q= Url &property, const Sopran // else do nothing } = -void Nepomuk::SimpleResource::removeProperty(const QUrl &property, const Q= Variant &value) +void Nepomuk::SimpleResource::remove(const QUrl &property, const QVariant = &value) { d->m_properties.remove(property, value); } = -void Nepomuk::SimpleResource::removeProperty(const QUrl &property) +void Nepomuk::SimpleResource::remove(const QUrl &property) { d->m_properties.remove(property); } = +void Nepomuk::SimpleResource::removeAll(const QUrl &property, const QVaria= nt &value) +{ + if(property.isEmpty()) { + if(value.isValid()) { + foreach(const QUrl& prop, d->m_properties.keys(value)) { + d->m_properties.remove(prop, value); + } + } + else { + d->m_properties.clear(); + } + } + else if(value.isValid()){ + d->m_properties.remove(property, value); + } + else { + d->m_properties.remove(property); + } +} + void Nepomuk::SimpleResource::addType(const QUrl &type) { addProperty(Soprano::Vocabulary::RDF::type(), type); diff --git a/agents/nepomukfeeder/dms-copy/simpleresource.h b/agents/nepomu= kfeeder/dms-copy/simpleresource.h index d2418ea..f5d7563 100644 --- a/agents/nepomukfeeder/dms-copy/simpleresource.h +++ b/agents/nepomukfeeder/dms-copy/simpleresource.h @@ -131,8 +131,14 @@ public: */ void addPropertyNode(const QUrl& property, const Soprano::Node& value); = - void removeProperty(const QUrl& property, const QVariant& value); - void removeProperty(const QUrl& property); + void remove(const QUrl& property, const QVariant& value); + void remove(const QUrl& property); + + /** + * Remove all property/value pairs matchin the provided pattern. Both + * parameters can be set to empty values to act as wildcards. + */ + void removeAll(const QUrl& property, const QVariant& value); = /** * A convenience method which adds a property of type rdf:type. diff --git a/agents/nepomukfeeder/dms-copy/simpleresourcegraph.cpp b/agents= /nepomukfeeder/dms-copy/simpleresourcegraph.cpp index 3bab264..41c4ee5 100644 --- a/agents/nepomukfeeder/dms-copy/simpleresourcegraph.cpp +++ b/agents/nepomukfeeder/dms-copy/simpleresourcegraph.cpp @@ -22,6 +22,7 @@ #include "simpleresourcegraph.h" #include "simpleresource.h" #include "datamanagement.h" +#include "storeresourcesjob.h" = #include #include @@ -121,15 +122,23 @@ void Nepomuk::SimpleResourceGraph::remove(const QUrl = &uri, const QUrl &property, { QHash< QUrl, SimpleResource >::iterator it =3D d->resources.find( uri = ); if( it !=3D d->resources.end() ) { - it.value().removeProperty(property, value); + it.value().remove(property, value); } } = -void Nepomuk::SimpleResourceGraph::removeAll(const QUrl &uri, const QUrl &= property) +void Nepomuk::SimpleResourceGraph::removeAll(const QUrl &uri, const QUrl &= property, const QVariant &value) { - QHash< QUrl, SimpleResource >::iterator it =3D d->resources.find( uri = ); - if( it !=3D d->resources.end() ) { - it.value().removeProperty(property); + if(!uri.isEmpty()) { + QHash< QUrl, SimpleResource >::iterator it =3D d->resources.find( = uri ); + if( it !=3D d->resources.end() ) { + it.value().removeAll(property, value); + } + } + else { + for(QHash::iterator it =3D d->resources.begi= n(); + it !=3D d->resources.end(); ++it) { + it->removeAll(property, value); + } } } = @@ -171,6 +180,11 @@ QList Nepomuk::SimpleResource= Graph::toList() const return d->resources.values(); } = +QList Nepomuk::SimpleResourceGraph::allResourceUris() const +{ + return d->resources.keys(); +} + void Nepomuk::SimpleResourceGraph::clear() { d->resources.clear(); @@ -243,15 +257,19 @@ void Nepomuk::SimpleResourceGraph::addStatement(const= Soprano::Node& subject, co addStatement( Soprano::Statement( subject, predicate, object ) ); } = - -KJob* Nepomuk::SimpleResourceGraph::save(const KComponentData& component) = const +Nepomuk::StoreResourcesJob* Nepomuk::SimpleResourceGraph::save(const KComp= onentData& component) const { return Nepomuk::storeResources(*this, Nepomuk::IdentifyNew, Nepomuk::N= oStoreResourcesFlags, QHash(), component); } = QDebug Nepomuk::operator<<(QDebug dbg, const Nepomuk::SimpleResourceGraph&= graph) { - return dbg << graph.toList(); + dbg.nospace() << "SimpleResourceGraph(" << endl; + foreach(const SimpleResource& res, graph.toList()) { + dbg << res << endl; + } + dbg.nospace() << ")" << endl; + return dbg; } = QDataStream & Nepomuk::operator<<(QDataStream & stream, const Nepomuk::Sim= pleResourceGraph& graph) diff --git a/agents/nepomukfeeder/dms-copy/simpleresourcegraph.h b/agents/n= epomukfeeder/dms-copy/simpleresourcegraph.h index 386b8c1..d897d4e 100644 --- a/agents/nepomukfeeder/dms-copy/simpleresourcegraph.h +++ b/agents/nepomukfeeder/dms-copy/simpleresourcegraph.h @@ -27,6 +27,7 @@ #include #include #include +#include = #include = @@ -41,6 +42,7 @@ class Node; } namespace Nepomuk { class SimpleResource; +class StoreResourcesJob; = class NEPOMUK_DATA_MANAGEMENT_EXPORT SimpleResourceGraph { @@ -68,7 +70,12 @@ public: void set(const QUrl& uri, const QUrl& property, const QVariant& value); = void remove(const QUrl& uri, const QUrl& property, const QVariant& val= ue); - void removeAll(const QUrl& uri, const QUrl& property); + + /** + * Remove all properties matching the provided parameters. It is possi= ble to + * provide empty values to act as wildcards. + */ + void removeAll(const QUrl& uri, const QUrl& property, const QVariant& = value =3D QVariant()); = void clear(); = @@ -82,12 +89,27 @@ public: = SimpleResource operator[](const QUrl& uri) const; = + /** + * Get a list of the URIs of all resources in this graph. + * The result is equivalent to: + * + * \code + * QList uris; + * foreach(const SimpleResource& res, toList()) + * uris << res.uri(); + * \endcode + * + * \return A list of all resource URIs in this graph. + */ + QList allResourceUris() const; + QSet toSet() const; QList toList() const; = void addStatement(const Soprano::Statement& statement); - void addStatement( const Soprano::Node & subject, const Soprano::Node = & predicate, - const Soprano::Node & object ); + void addStatement(const Soprano::Node & subject, + const Soprano::Node & predicate, + const Soprano::Node & object); = SimpleResourceGraph& operator+=3D( const SimpleResourceGraph & graph ); = @@ -102,7 +124,7 @@ public: * * \sa Nepomuk::storeResources() */ - KJob* save(const KComponentData& component =3D KGlobal::mainComponent(= )) const; + StoreResourcesJob* save(const KComponentData& component =3D KGlobal::m= ainComponent()) const; = bool operator=3D=3D( const SimpleResourceGraph & rhs) const; bool operator!=3D( const SimpleResourceGraph & rhs) const; diff --git a/agents/nepomukfeeder/dms-copy/storeresourcesjob.cpp b/agents/n= epomukfeeder/dms-copy/storeresourcesjob.cpp new file mode 100644 index 0000000..55f3637 --- /dev/null +++ b/agents/nepomukfeeder/dms-copy/storeresourcesjob.cpp @@ -0,0 +1,107 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2011 Vishesh Handa + Copyright (C) 2011 Sebastian Trueg + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "storeresourcesjob.h" +#include "datamanagementinterface.h" +#include "simpleresourcegraph.h" +#include "dbustypes.h" +#include "genericdatamanagementjob_p.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include + +class Nepomuk::StoreResourcesJob::Private { +public: + Nepomuk::StoreResourcesJob *q; + QHash m_mappings; + + void _k_slotDBusCallFinished(QDBusPendingCallWatcher* watcher); +}; + +Nepomuk::StoreResourcesJob::StoreResourcesJob(const Nepomuk::SimpleResourc= eGraph& resources, + Nepomuk::StoreIdentification= Mode identificationMode, + Nepomuk::StoreResourcesFlags= flags, + const QHash< QUrl, QVariant = >& additionalMetadata, + const KComponentData& compon= ent) + : KJob(), + d( new Nepomuk::StoreResourcesJob::Private ) +{ + d->q =3D this; + DBus::registerDBusTypes(); + + org::kde::nepomuk::DataManagement dms(QLatin1String(DMS_DBUS_SERVICE), + QLatin1String("/datamanagement"), + QDBusConnection::sessionBus()); + QDBusPendingCallWatcher* dbusCallWatcher + =3D new QDBusPendingCallWatcher(dms.storeResources( resources.toList()= , identificationMode, + flags, additionalMet= adata, + component.componentN= ame() )); + + connect(dbusCallWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(_k_slotDBusCallFinished(QDBusPendingCallWatcher*))); +} + +Nepomuk::StoreResourcesJob::~StoreResourcesJob() +{ + delete d; +} + +void Nepomuk::StoreResourcesJob::start() +{ + // Nothing to do +} + +QHash< QUrl, QUrl > Nepomuk::StoreResourcesJob::mappings() const +{ + return d->m_mappings; +} + +void Nepomuk::StoreResourcesJob::Private::_k_slotDBusCallFinished(QDBusPen= dingCallWatcher* watcher) +{ + QDBusPendingReply< QHash > reply =3D *watcher; + if (reply.isError()) { + QDBusError error =3D reply.error(); + q->setError(1); + q->setErrorText(error.message()); + } + else { + m_mappings.clear(); + QHash mappings =3D reply.value(); + QHash::const_iterator it =3D mappings.constBegin= (); + for( ; it !=3D mappings.constEnd(); it++ ) { + m_mappings.insert( KUrl( it.key() ), KUrl( it.value() ) ); + } + } + + watcher->deleteLater(); + q->emitResult(); +} + +#include "storeresourcesjob.moc" diff --git a/agents/nepomukfeeder/dms-copy/storeresourcesjob.h b/agents/nep= omukfeeder/dms-copy/storeresourcesjob.h new file mode 100644 index 0000000..9043f3c --- /dev/null +++ b/agents/nepomukfeeder/dms-copy/storeresourcesjob.h @@ -0,0 +1,63 @@ +/* + This file is part of the Nepomuk KDE project. + Copyright (C) 2011 Vishesh Handa + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + + +#ifndef STORERESOURCEJOB_H +#define STORERESOURCEJOB_H + +#include +#include "nepomukdatamanagement_export.h" +#include "datamanagement.h" + +class QDBusPendingCallWatcher; + +namespace Nepomuk { + + class NEPOMUK_DATA_MANAGEMENT_EXPORT StoreResourcesJob : public KJob + { + Q_OBJECT + public: + ~StoreResourcesJob(); + + QHash mappings() const; + + private: + StoreResourcesJob(const Nepomuk::SimpleResourceGraph& resources, + Nepomuk::StoreIdentificationMode identificationMo= de, + Nepomuk::StoreResourcesFlags flags, + const QHash& additionalMetadata, + const KComponentData& component); + class Private; + Private *d; + + void start(); + + Q_PRIVATE_SLOT( d, void _k_slotDBusCallFinished( QDBusPendingCallW= atcher* ) ) + + friend Nepomuk::StoreResourcesJob* storeResources(const SimpleReso= urceGraph&, + StoreIdentificati= onMode, + StoreResourcesFla= gs, + const QHash&, + const KComponentD= ata& ); + }; + +} +#endif // STORERESOURCEJOB_H