Difference between revisions of "Projects/Nepomuk/QuickStart"

Jump to: navigation, search
(New page: ==Nepomuk Quickstart== Reading or setting simple metadata in your own application can be very easy. But keep in mind that the process described here does not make much sense in terms of p...)
 
Line 9: Line 9:
 
Let's get the metadata for a file. Imagine the URL or the file is stored in <i>uri</i>.
 
Let's get the metadata for a file. Imagine the URL or the file is stored in <i>uri</i>.
  
<code>
+
<code cppqt>
 
Nepomuk::Resource res( uri );
 
Nepomuk::Resource res( uri );
 
QHash<QString, Variant> properties = res.allProperties();
 
QHash<QString, Variant> properties = res.allProperties();
Line 18: Line 18:
 
We can now use Nepomuk to get human readable labels for the properties and display the properties in a generic way:
 
We can now use Nepomuk to get human readable labels for the properties and display the properties in a generic way:
  
<code>
+
<code cppqt>
 
for( QHash<QString, Variant>::const_iterator it = properties.constBegin();
 
for( QHash<QString, Variant>::const_iterator it = properties.constBegin();
 
     it != properties.constEnd(); ++it ) {
 
     it != properties.constEnd(); ++it ) {
Line 37: Line 37:
 
Let's start with the tag and use the easy Nepomukish way:
 
Let's start with the tag and use the easy Nepomukish way:
  
<code>
+
<code cppqt>
 
Nepomuk::Tag tag( "This is my nice tag name" );
 
Nepomuk::Tag tag( "This is my nice tag name" );
 
Nepomuk::Resource res( uri );
 
Nepomuk::Resource res( uri );
Line 47: Line 47:
 
Now let's set a comment for the file without the use of the convenience methods in Nepomuk:
 
Now let's set a comment for the file without the use of the convenience methods in Nepomuk:
  
<code>
+
<code cppqt>
 
Nepomuk::Resource res( uri );
 
Nepomuk::Resource res( uri );
 
QString comment = getFancyFileComment();
 
QString comment = getFancyFileComment();

Revision as of 12:41, 15 February 2008

Nepomuk Quickstart

Reading or setting simple metadata in your own application can be very easy. But keep in mind that the process described here does not make much sense in terms of performance when changing a lot of metadata. We will now take a look at a simple way to access a resource's metadata.


Retrieve Metadata

Let's get the metadata for a file. Imagine the URL or the file is stored in uri.

Nepomuk::Resource res( uri ); QHash<QString, Variant> properties = res.allProperties();

That gives us all properties assigned to the file.

We can now use Nepomuk to get human readable labels for the properties and display the properties in a generic way:

for( QHash<QString, Variant>::const_iterator it = properties.constBegin();

    it != properties.constEnd(); ++it ) {
  QUrl propertyUri = it.key();
  Variant value = it.value();
  Nepomuk::Types::Class propertyType( propertyUri );
  someList->appendItem( propertyType.label() + ": " + value.toString() );

}


Set Metadata

Again uri is the URL of the file we want to set some metadata for. This time we want to set a tag and a comment and will do this in two slightly different ways:

Let's start with the tag and use the easy Nepomukish way:

Nepomuk::Tag tag( "This is my nice tag name" ); Nepomuk::Resource res( uri ); res.addTag( tag );

Simple! Actually if the tag already exists it will be reused.

Now let's set a comment for the file without the use of the convenience methods in Nepomuk:

Nepomuk::Resource res( uri ); QString comment = getFancyFileComment(); res.setProperty( Soprano::Vocabulary::NAO::description(), comment );

That's all. The comment it saved and will now be searchable via Nepomuk.


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal