24 #include <QtCore/QHash>
25 #include <QtCore/QMutexLocker>
27 #include <Soprano/QueryResultIterator>
28 #include <Soprano/Model>
29 #include <Soprano/Vocabulary/NRL>
30 #include <Soprano/Vocabulary/NAO>
31 #include <Soprano/Vocabulary/RDFS>
36 Nepomuk2::Types::EntityPrivate::EntityPrivate(
const QUrl& uri_ )
37 : mutex(QMutex::Recursive),
40 available( uri_.isValid() ? -1 : 0 ),
41 ancestorsAvailable( uri_.isValid() ? -1 : 0 )
46 void Nepomuk2::Types::EntityPrivate::init()
48 QMutexLocker lock( &mutex );
50 if ( available < 0 ) {
51 available = load() ? 1 : 0;
56 void Nepomuk2::Types::EntityPrivate::initAncestors()
58 QMutexLocker lock( &mutex );
60 if ( ancestorsAvailable < 0 ) {
61 ancestorsAvailable = loadAncestors() ? 1 : 0;
66 bool Nepomuk2::Types::EntityPrivate::load()
68 const QString query = QString::fromLatin1(
"select ?p ?o where { "
69 "graph ?g { <%1> ?p ?o . } . "
70 "{ ?g a %2 . } UNION { ?g a %3 . } . }" )
71 .arg( QString::fromAscii( uri.toEncoded() ),
72 Soprano::Node::resourceToN3( Soprano::Vocabulary::NRL::Ontology() ),
73 Soprano::Node::resourceToN3( Soprano::Vocabulary::NRL::KnowledgeBase() ) );
75 Soprano::QueryResultIterator it
78 QUrl
property = it.binding(
"p" ).uri();
79 Soprano::Node value = it.binding(
"o" );
81 if ( property == Soprano::Vocabulary::RDFS::label() ) {
82 if ( value.language().isEmpty() ) {
83 label = value.toString();
85 else if( value.language() == KGlobal::locale()->language() ) {
86 l10nLabel = value.toString();
90 else if ( property == Soprano::Vocabulary::RDFS::comment() ) {
91 if ( value.language().isEmpty() ) {
92 comment = value.toString();
94 else if( value.language() == KGlobal::locale()->language() ) {
95 l10nComment = value.toString();
99 else if ( property == Soprano::Vocabulary::NAO::hasSymbol() ) {
100 icon = KIcon( value.toString() );
103 else if ( property == Soprano::Vocabulary::NAO::userVisible() ) {
104 userVisible = value.literal().toBool();
112 return !it.lastError();
116 bool Nepomuk2::Types::EntityPrivate::loadAncestors()
118 const QString query = QString::fromLatin1(
"select ?s ?p where { "
119 "graph ?g { ?s ?p <%1> . } . "
120 "{ ?g a %2 . } UNION { ?g a %3 . } . }" )
121 .arg( QString::fromAscii( uri.toEncoded() ),
122 Soprano::Node::resourceToN3( Soprano::Vocabulary::NRL::Ontology() ),
123 Soprano::Node::resourceToN3( Soprano::Vocabulary::NRL::KnowledgeBase() ) );
125 Soprano::QueryResultIterator it
127 while ( it.next() ) {
128 addAncestorProperty( it.binding(
"s" ).uri(), it.binding(
"p" ).uri() );
131 return !it.lastError();
136 void Nepomuk2::Types::EntityPrivate::reset(
bool )
138 QMutexLocker lock( &mutex );
143 l10nComment.clear();;
148 ancestorsAvailable = -1;
177 return d ? d->uri : QUrl();
183 return d ? (d->uri.fragment().isEmpty() ? d->uri.toString().section(
'/',-1) : d->uri.fragment() ) : QString();
192 if ( language == KGlobal::locale()->language() &&
193 !d->l10nLabel.isEmpty() ) {
196 else if( !d->label.isEmpty() ) {
211 return const_cast<Entity*
>(
this)->label( language );
220 if ( language == KGlobal::locale()->language() &&
221 !d->l10nComment.isEmpty() ) {
222 return d->l10nComment;
236 return const_cast<Entity*
>(
this)->comment( language );
255 return const_cast<Entity*
>(
this)->icon();
261 return d ? d->uri.isValid() :
false;
269 return d->available == 1;
279 return const_cast<Entity*
>(
this)->isAvailable();
286 d->reset( recursive );
294 return d->userVisible;
306 return( d.constData() == other.
d.constData() );
313 return( d->uri == other );
315 return other.isEmpty();
323 return( d.constData() != other.
d.constData() );
330 return( d->uri != other );
332 return !other.isEmpty();
KJob * addProperty(const QList< QUrl > &resources, const QUrl &property, const QVariantList &values, const KComponentData &component=KGlobal::mainComponent())
Add one or more property values to one or more resources.
QUrl uri() const
The URI of the resource.
QIcon icon()
Retrieve the icon stored for the entity (nao:hasSymbol)
Entity & operator=(const Entity &)
Copy operator.
bool isAvailable()
Is this Entity available locally, i.e.
void reset(bool recursive=false)
The Types classes are optimized for performance under the aasumption that ontologies never change dur...
bool operator==(const Entity &other) const
Compares two Entity instances.
Abstract base class for Class and Property;.
virtual ~Entity()
Destructor.
bool userVisible() const
nao:userVisible can be used to hide certain properties and resources of a certain type from the user...
Entity()
Create an invalid Entity instance.
static ResourceManager * instance()
QString comment(const QString &language=KGlobal::locale() ->language())
Retrieve the comment of the entity (rdfs:comment)
QString name() const
The name of the resource.
QString label(const QString &language=KGlobal::locale() ->language())
Retrieve the label of the entity (rdfs:label)
QExplicitlySharedDataPointer< EntityPrivate > d
bool operator!=(const Entity &other) const
Compares two Entity instances.
bool isValid() const
Is this a valid Entity, i.e.
Soprano::Model * mainModel()
Retrieve the main data storage model.