Jump to content

Projects/Nepomuk/Writeback

From KDE Community Wiki

Nepomuk: Metadata Writeback

This page is intended to gather ideas about the GSOC 2011 project Metadata Writeback by Smit Shah.


Ideas

Resource Watcher

This project relies heavily on one of the parts of Nepomuk called "Resource Watcher" , using it we could monitor the already indexed resources for any changes, this includes addition or removal of any property to be exact and perhaps change in the property in the future, this is a very important part of the project as once we find which resource has been modified using emitted signals and then we can call the method which would writeback the metadata to the resource if there is plugin for that rdf:type/mimetype.

To Connect the resource watcher should be fairly simple as shown below :

ResourceWatcher* resourcewatcher;

        resourcewatcher  = new ResourceWatcher(this);
        resourcewatcher->addType(NFO::FileDataObject());
        resourcewatcher->addType(NCO::Contact())
        resourcewatcher->start();

        connect( resourcewatcher, SIGNAL( propertyAdded(Nepomuk::Resource,                     Nepomuk::Types::Property, QVariant) ),this, SLOT ( write(Nepomuk::Resource) ) );
        connect( resourcewatcher, SIGNAL( propertyRemoved(Nepomuk::Resource,
Nepomuk::Types::Property, QVariant) ),this, SLOT ( write(Nepomuk::Resource) ) );

This how it will be in the future but as of now Resource Watcher has some problems so for now we would be monitoring only a handful of properties like NIE:title or NCO:nickname.

Hybrid Plugin System

This project as of now relies on mimetypes of plugin selection but that limits functionality of the project as it can not writeback metadata except for files (e.g. Akonadi), so it would a good approach to select plugins based on rdf:types as retaining the selection using mimetypes as well.

The current selection of plugin based on mimetype is shown below:

 const QStringList mimetypes = resource.property(NIE::mimeType()).toStringList();
        if(!mimetypes.isEmpty())
        {
            QString  mimetype = mimetypes.first();
            WritebackPlugin* plugin= KMimeTypeTrader::createInstanceFromQuery<WritebackPlugin>(mimetype,"Nepomuk/WritebackPlugin",this);

            if (plugin)
            {
                plugin->writeback(resource.resourceUri());
            }
         }

This is how the selection of done as of now but in future we would be using both rdf:types and mimetypes as well.

Writebackjob

To do the writeback job itself we would be relying on kjob to write a class that does the work, it later deletes the plugin after the job finishes and if the plugin does not write the data successfully it will use the next plugin the in the list.

The code looks something like below,

 class WritebackJob : public KJob {
    public:
    WritebackJob(const QList<Plugin*>& plugins, QObject* parent) {
        m_plugins = plugins;
    }
    ~WritebackJob() {
        qDeleteAll(m_plugins);
    }
 
    void start() {
        tryNextPlugin();
    }
 
    void tryNextPlugin() {
        Plugin* p = m_plugin.takeFirst();
        // start the plugin and so on
    }
 
    void slotWritebackFinished(Plugin* plugin) {
        if(plugin->success()) {
            emitResult();
        }
        else if(!m_plugins.isEmpty()) {
            tryNextPlugin();
        }
        plugin->deleteLater();
    }
}