~ubuntu-branches/ubuntu/precise/kactivities/precise-proposed

« back to all changes in this revision

Viewing changes to service/plugins/nepomuk/NepomukCommon.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-13 11:53:27 UTC
  • Revision ID: package-import@ubuntu.com-20111213115327-vqhdel92qx65us8y
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2010 Ivan Cukic <ivan.cukic(at)kde.org>
 
3
 *
 
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
 
7
 *   Software Foundation
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include "NepomukCommon.h"
 
21
 
 
22
#include <KDebug>
 
23
 
 
24
#include <Soprano/Vocabulary/NAO>
 
25
#include "kext.h"
 
26
 
 
27
using namespace Nepomuk::Vocabulary;
 
28
using namespace Soprano::Vocabulary;
 
29
 
 
30
QHash < QString, Nepomuk::Resource > NepomukPluginCommon::activityResources;
 
31
 
 
32
Nepomuk::Resource activityResource(const QString & id)
 
33
{
 
34
    kDebug() << "Getting the resource of activity:" << id;
 
35
 
 
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()
 
41
                 << resource
 
42
                 << resource.property(NAO::identifier());
 
43
        return resource;
 
44
    }
 
45
 
 
46
    // Otherwise
 
47
    const QString & query = QString::fromLatin1(
 
48
            "select ?activity where { "
 
49
                "?activity a kext:Activity . "
 
50
                "?activity nao:identifier %1 ."
 
51
            "} LIMIT 1"
 
52
        ).arg(litN3(id));
 
53
 
 
54
    Soprano::QueryResultIterator it
 
55
        = Nepomuk::ResourceManager::instance()->mainModel()->executeQuery(query, Soprano::Query::QueryLanguageSparql);
 
56
 
 
57
    Nepomuk::Resource resource;
 
58
 
 
59
    if (it.next()) {
 
60
        resource = Nepomuk::Resource(it[0].uri());
 
61
        it.close();
 
62
 
 
63
    } else {
 
64
        kDebug() << "A very strange thing is happening - seems like" << id <<
 
65
            "activity doesn't exist stored in Nepomuk!";
 
66
 
 
67
        resource = Nepomuk::Resource(id, KExt::Activity());
 
68
    }
 
69
 
 
70
    // Adding to cache and returning the value
 
71
    NepomukPluginCommon::activityResources[id] = resource;
 
72
 
 
73
    kDebug() << "Returning the resource object"
 
74
        << resource.genericLabel()
 
75
        << resource
 
76
        << resource.property(NAO::identifier());
 
77
    return resource;
 
78
}