2
* Copyright (C) 2010 Ivan Cukic <ivan.cukic(at)kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2,
6
* or (at your option) any later version, as published by the Free
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "NepomukCommon.h"
24
#include <Soprano/Vocabulary/NAO>
27
using namespace Nepomuk::Vocabulary;
28
using namespace Soprano::Vocabulary;
30
QHash < QString, Nepomuk::Resource > NepomukPluginCommon::activityResources;
32
Nepomuk::Resource activityResource(const QString & id)
34
kDebug() << "Getting the resource of activity:" << id;
36
// Do we already have the resource cached?
37
if (NepomukPluginCommon::activityResources.contains(id)) {
38
const Nepomuk::Resource & resource = NepomukPluginCommon::activityResources[id];
39
kDebug() << "We have the resource already cached"
40
<< resource.genericLabel()
42
<< resource.property(NAO::identifier());
47
const QString & query = QString::fromLatin1(
48
"select ?activity where { "
49
"?activity a kext:Activity . "
50
"?activity nao:identifier %1 ."
54
Soprano::QueryResultIterator it
55
= Nepomuk::ResourceManager::instance()->mainModel()->executeQuery(query, Soprano::Query::QueryLanguageSparql);
57
Nepomuk::Resource resource;
60
resource = Nepomuk::Resource(it[0].uri());
64
kDebug() << "A very strange thing is happening - seems like" << id <<
65
"activity doesn't exist stored in Nepomuk!";
67
resource = Nepomuk::Resource(id, KExt::Activity());
70
// Adding to cache and returning the value
71
NepomukPluginCommon::activityResources[id] = resource;
73
kDebug() << "Returning the resource object"
74
<< resource.genericLabel()
76
<< resource.property(NAO::identifier());