~ubuntu-branches/ubuntu/utopic/nepomuk-core/utopic

« back to all changes in this revision

Viewing changes to libnepomukcore/resource/resource.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-26 22:43:09 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120726224309-pf2v1e78ee7uljjp
Tags: 4:4.9.0a-0ubuntu1
* Use direct build-depends versions rather than kde-sc-dev-latest
* New upstream release
* New symbols, rename libnepomukcore4 to libnepomukcore4abi and enable Debian ABI manager

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * This file is part of the Nepomuk KDE project.
3
3
 * Copyright (C) 2006-2010 Sebastian Trueg <trueg@kde.org>
 
4
 * Copyright (C) 2012 Vishesh Handa <me@vhanda.in>
4
5
 *
5
6
 * This library is free software; you can redistribute it and/or
6
7
 * modify it under the terms of the GNU Library General Public
25
26
#include "tools.h"
26
27
#include "tag.h"
27
28
#include "pimo.h"
28
 
#include "thing.h"
29
29
#include "file.h"
30
30
#include "property.h"
31
31
#include "nfo.h"
40
40
 
41
41
#include <Soprano/Vocabulary/NAO>
42
42
#include <Soprano/Vocabulary/RDFS>
 
43
#include <Soprano/Vocabulary/RDF>
43
44
#include <Soprano/Model>
44
45
#include <Soprano/QueryResultIterator>
 
46
#include <Soprano/StatementIterator>
 
47
#include <Soprano/NodeIterator>
45
48
 
46
49
using namespace Nepomuk2::Vocabulary;
 
50
using namespace Soprano::Vocabulary;
 
51
 
47
52
 
48
53
Nepomuk2::Resource::Resource()
49
54
{
124
129
}
125
130
 
126
131
 
127
 
QUrl Nepomuk2::Resource::resourceUri() const
 
132
QUrl Nepomuk2::Resource::uri() const
128
133
{
129
134
    if ( m_data ) {
130
135
        determineFinalResourceData();
136
141
}
137
142
 
138
143
 
139
 
QUrl Nepomuk2::Resource::resourceType() const
 
144
QUrl Nepomuk2::Resource::type() const
140
145
{
141
146
    determineFinalResourceData();
142
147
    return m_data->type();
146
151
QList<QUrl> Nepomuk2::Resource::types() const
147
152
{
148
153
    determineFinalResourceData();
149
 
    return m_data->allTypes();
 
154
    return m_data->property( RDF::type() ).toUrlList();
150
155
}
151
156
 
152
157
 
153
158
void Nepomuk2::Resource::setTypes( const QList<QUrl>& types )
154
159
{
155
160
    determineFinalResourceData();
156
 
    m_data->setTypes( types );
 
161
    m_data->setProperty( RDF::type(), types );
157
162
}
158
163
 
159
164
 
160
165
void Nepomuk2::Resource::addType( const QUrl& type )
161
166
{
162
 
    QList<QUrl> tl = types();
163
 
    if( !tl.contains( type ) )
164
 
        setTypes( tl << type );
 
167
    determineFinalResourceData();
 
168
    m_data->addProperty( RDF::type(), type );
165
169
}
166
170
 
167
171
 
168
172
bool Nepomuk2::Resource::hasType( const QUrl& typeUri ) const
169
173
{
170
174
    determineFinalResourceData();
171
 
    return m_data->hasType( typeUri );
 
175
    return m_data->hasProperty( RDF::type(), typeUri );
172
176
}
173
177
 
174
178
 
279
283
    if(!label.isEmpty())
280
284
        return label;
281
285
 
282
 
    label = m_data->pimoThing().label();
283
 
    if(!label.isEmpty())
284
 
        return label;
 
286
    //label = m_data->pimoThing().label();
 
287
    //if(!label.isEmpty())
 
288
    //    return label;
285
289
 
286
290
    label = property( Nepomuk2::Vocabulary::NFO::fileName() ).toString();
287
291
    if(!label.isEmpty())
298
302
    QList<Resource> go = property( Vocabulary::PIMO::groundingOccurrence() ).toResourceList();
299
303
    if( !go.isEmpty() ) {
300
304
        label = go.first().genericLabel();
301
 
        if( label != KUrl(go.first().resourceUri()).pathOrUrl() ) {
 
305
        if( label != KUrl(go.first().uri()).pathOrUrl() ) {
302
306
            return label;
303
307
        }
304
308
    }
308
312
        return hashValue;
309
313
 
310
314
    // ugly fallback
311
 
    return KUrl(resourceUri()).pathOrUrl();
 
315
    return KUrl(uri()).pathOrUrl();
312
316
}
313
317
 
314
318
 
353
357
}
354
358
 
355
359
 
356
 
Nepomuk2::Thing Nepomuk2::Resource::pimoThing()
357
 
{
358
 
    determineFinalResourceData();
359
 
    return m_data->pimoThing();
360
 
}
361
 
 
362
 
 
363
360
bool Nepomuk2::Resource::operator==( const Resource& other ) const
364
361
{
365
362
    if( this == &other )
380
377
    if( m_data->uri().isEmpty() )
381
378
        return *m_data == *other.m_data;
382
379
    else
383
 
        return resourceUri() == other.resourceUri();
 
380
        return uri() == other.uri();
384
381
}
385
382
 
386
383
 
532
529
 
533
530
QList<Nepomuk2::Resource> Nepomuk2::Resource::isRelatedOf() const
534
531
{
535
 
    return convertResourceList<Resource>( ResourceManager::instance()->allResourcesWithProperty( Soprano::Vocabulary::NAO::isRelated(), *this ) );
 
532
    Soprano::Model* model = ResourceManager::instance()->mainModel();
 
533
    QList<Soprano::Node> list = model->listStatements( Soprano::Node(), NAO::isRelated(), uri() ).iterateSubjects().allNodes();
 
534
    QList<Nepomuk2::Resource> resources;
 
535
    foreach(const Soprano::Node& node, list)
 
536
        resources << node.uri();
 
537
    return resources;
536
538
}
537
539
 
538
540
 
613
615
 
614
616
uint Nepomuk2::qHash( const Resource& res )
615
617
{
616
 
    return qHash(res.resourceUri());
 
618
    return qHash(res.uri());
617
619
}