[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: [kdelibs/nepomuk/DmsPort] nepomuk: Properly marshall the urls
From:       Sebastian_Trüg <trueg () kde ! org>
Date:       2012-01-02 9:25:52
Message-ID: 4F017820.6080707 () kde ! org
[Download RAW message or body]

ah, right. damn. this will only work in kde 5.0....

On 01/02/2012 10:17 AM, Vishesh Handa wrote:
> 
> 
> On Mon, Jan 2, 2012 at 2:36 PM, Sebastian Trüg <trueg@kde.org
> <mailto:trueg@kde.org>> wrote:
> 
>     why do we need this? Isn't this handled inside the DMS lib already?
> 
> 
> Yup. It is. But we aren't using the DMS library in kdelibs. We're just
> using dbus calls.
>  
> 
> 
>     On 12/26/2011 08:49 PM, Vishesh Handa wrote:
>     > Git commit 3e602f2ed9e114b3a831f2dcba01237eb8f478d8 by Vishesh Handa.
>     > Committed on 26/12/2011 at 20:48.
>     > Pushed by vhanda into branch 'nepomuk/DmsPort'.
>     >
>     > Properly marshall the urls into strings
>     >
>     > Copied dbustypes.* from
>     kde-runtime/nepomuk/services/storage/lib/dbustypes.*
>     >
>     > M  +1    -0    nepomuk/CMakeLists.txt
>     > A  +136  -0    nepomuk/core/dbustypes.cpp     [License: LGPL]
>     > A  +59   -0    nepomuk/core/dbustypes.h     [License: LGPL]
>     > M  +7    -10   nepomuk/core/resourcedata.cpp
>     > M  +3    -0    nepomuk/core/resourcemanager.cpp
>     >
>     >
>     http://commits.kde.org/kdelibs/3e602f2ed9e114b3a831f2dcba01237eb8f478d8
>     >
>     > diff --git a/nepomuk/CMakeLists.txt b/nepomuk/CMakeLists.txt
>     > index bd0104e..3319b9d 100644
>     > --- a/nepomuk/CMakeLists.txt
>     > +++ b/nepomuk/CMakeLists.txt
>     > @@ -36,6 +36,7 @@ set(nepomuk_core_SRCS
>     >    core/file.cpp
>     >    core/tag.cpp
>     >    core/nepomukservice.cpp
>     > +  core/dbustypes.cpp
>     >  )
>     >
>     >  if(NOT KDE_NO_DEPRECATED)
>     > diff --git a/nepomuk/core/dbustypes.cpp b/nepomuk/core/dbustypes.cpp
>     > new file mode 100644
>     > index 0000000..761ded2
>     > --- /dev/null
>     > +++ b/nepomuk/core/dbustypes.cpp
>     > @@ -0,0 +1,136 @@
>     > +/*
>     > +   This file is part of the Nepomuk KDE project.
>     > +   Copyright (C) 2011 Sebastian Trueg <trueg@kde.org
>     <mailto:trueg@kde.org>>
>     > +
>     > +   This library is free software; you can redistribute it and/or
>     > +   modify it under the terms of the GNU Lesser General Public
>     > +   License as published by the Free Software Foundation; either
>     > +   version 2.1 of the License, or (at your option) version 3, or any
>     > +   later version accepted by the membership of KDE e.V. (or its
>     > +   successor approved by the membership of KDE e.V.), which shall
>     > +   act as a proxy defined in Section 6 of version 3 of the license.
>     > +
>     > +   This library is distributed in the hope that it will be useful,
>     > +   but WITHOUT ANY WARRANTY; without even the implied warranty of
>     > +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>     > +   Lesser General Public License for more details.
>     > +
>     > +   You should have received a copy of the GNU Lesser General Public
>     > +   License along with this library.  If not, see
>     <http://www.gnu.org/licenses/>.
>     > +*/
>     > +
>     > +#include "dbustypes.h"
>     > +
>     > +#include <QtCore/QStringList>
>     > +#include <QtCore/QDate>
>     > +#include <QtCore/QTime>
>     > +#include <QtCore/QDateTime>
>     > +#include <QtDBus/QDBusMetaType>
>     > +
>     > +#include "kurl.h"
>     > +#include "kdebug.h"
>     > +
>     > +QString Nepomuk::DBus::convertUri(const QUrl& uri)
>     > +{
>     > +    return KUrl(uri).url();
>     > +}
>     > +
>     > +QStringList Nepomuk::DBus::convertUriList(const QList<QUrl>& uris)
>     > +{
>     > +    QStringList uriStrings;
>     > +    foreach(const QUrl& uri, uris)
>     > +        uriStrings << convertUri(uri);
>     > +    return uriStrings;
>     > +}
>     > +
>     > +QVariantList Nepomuk::DBus::normalizeVariantList(const
>     QVariantList& l)
>     > +{
>     > +    QVariantList newL;
>     > +    QListIterator<QVariant> it(l);
>     > +    while(it.hasNext()) {
>     > +        QVariant v = it.next();
>     > +        if(v.userType() == qMetaTypeId<KUrl>()) {
>     > +            newL.append(QVariant(QUrl(v.value<KUrl>())));
>     > +        }
>     > +        else {
>     > +            newL.append(v);
>     > +        }
>     > +    }
>     > +    return newL;
>     > +}
>     > +
>     > +QVariant Nepomuk::DBus::resolveDBusArguments(const QVariant& v)
>     > +{
>     > +    //
>     > +    // trueg: QDBus does not automatically convert non-basic
>     types but gives us a QDBusArgument in a QVariant.
>     > +    // Thus, we need to handle QUrl, QTime, QDate, and QDateTime
>     as a special cases here. They is the only complex types we support.
>     > +    //
>     > +    if(v.userType() == qMetaTypeId<QDBusArgument>()) {
>     > +        const QDBusArgument arg = v.value<QDBusArgument>();
>     > +
>     > +        QVariant v;
>     > +        if(arg.currentSignature() == QLatin1String("(s)")) {
>     > +            QUrl url;
>     > +            arg >> url;
>     > +            return url;
>     > +        }
>     > +        else if(arg.currentSignature() == QLatin1String("(iii)")) {
>     > +            QDate date;
>     > +            arg >> date;
>     > +            return date;
>     > +        }
>     > +        else if(arg.currentSignature() == QLatin1String("(iiii)")) {
>     > +            QTime time;
>     > +            arg >> time;
>     > +            return time;
>     > +        }
>     > +        else if(arg.currentSignature() ==
>     QLatin1String("((iii)(iiii)i)")) {
>     > +            QDateTime dt;
>     > +            arg >> dt;
>     > +            return dt;
>     > +        }
>     > +        else {
>     > +            kDebug() << "Unknown type signature in property hash
>     value:" << arg.currentSignature();
>     > +            return QVariant();
>     > +        }
>     > +    }
>     > +    else {
>     > +        return v;
>     > +    }
>     > +}
>     > +
>     > +QVariantList Nepomuk::DBus::resolveDBusArguments(const
>     QVariantList& l)
>     > +{
>     > +    QVariantList newL;
>     > +    QListIterator<QVariant> it(l);
>     > +    while(it.hasNext()) {
>     > +        newL.append(resolveDBusArguments(it.next()));
>     > +    }
>     > +    return newL;
>     > +}
>     > +
>     > +void Nepomuk::DBus::registerDBusTypes()
>     > +{
>     > +    // we need QUrl to be able to pass it in a QVariant
>     > +    qDBusRegisterMetaType<QUrl>();
>     > +}
>     > +
>     > +// We need the QUrl serialization to be able to pass URIs in variants
>     > +QDBusArgument& operator<<( QDBusArgument& arg, const QUrl& url )
>     > +{
>     > +    arg.beginStructure();
>     > +    arg << QString::fromAscii(url.toEncoded());
>     > +    arg.endStructure();
>     > +    return arg;
>     > +}
>     > +
>     > +// We need the QUrl serialization to be able to pass URIs in variants
>     > +const QDBusArgument& operator>>( const QDBusArgument& arg, QUrl&
>     url )
>     > +{
>     > +    arg.beginStructure();
>     > +    QString uriString;
>     > +    arg >> uriString;
>     > +    url = QUrl::fromEncoded(uriString.toAscii());
>     > +    arg.endStructure();
>     > +    return arg;
>     > +}
>     > diff --git a/nepomuk/core/dbustypes.h b/nepomuk/core/dbustypes.h
>     > new file mode 100644
>     > index 0000000..4a66a20
>     > --- /dev/null
>     > +++ b/nepomuk/core/dbustypes.h
>     > @@ -0,0 +1,59 @@
>     > +/*
>     > +   This file is part of the Nepomuk KDE project.
>     > +   Copyright (C) 2011 Sebastian Trueg <trueg@kde.org
>     <mailto:trueg@kde.org>>
>     > +
>     > +   This library is free software; you can redistribute it and/or
>     > +   modify it under the terms of the GNU Lesser General Public
>     > +   License as published by the Free Software Foundation; either
>     > +   version 2.1 of the License, or (at your option) version 3, or any
>     > +   later version accepted by the membership of KDE e.V. (or its
>     > +   successor approved by the membership of KDE e.V.), which shall
>     > +   act as a proxy defined in Section 6 of version 3 of the license.
>     > +
>     > +   This library is distributed in the hope that it will be useful,
>     > +   but WITHOUT ANY WARRANTY; without even the implied warranty of
>     > +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>     > +   Lesser General Public License for more details.
>     > +
>     > +   You should have received a copy of the GNU Lesser General Public
>     > +   License along with this library.  If not, see
>     <http://www.gnu.org/licenses/>.
>     > +*/
>     > +
>     > +#ifndef DBUSTYPES_H
>     > +#define DBUSTYPES_H
>     > +
>     > +#include <QtCore/QMetaType>
>     > +#include <QtCore/QHash>
>     > +#include <QtCore/QString>
>     > +#include <QtCore/QUrl>
>     > +#include <QtDBus/QDBusVariant>
>     > +#include <QtDBus/QDBusArgument>
>     > +
>     > +// #include "simpleresource.h"
>     > +// #include "nepomukdatamanagement_export.h"
>     > +#include "nepomuk_export.h"
>     > +
>     > +//CAUTION: Q_DECLARE_METATYPE doesn't accept template arguments
>     like QHash<T, T>
>     > +typedef QHash<QString, QString> __nepomuk_QHashQStringQString;
>     > +Q_DECLARE_METATYPE( __nepomuk_QHashQStringQString )
>     > +
>     > +namespace Nepomuk {
>     > +    namespace DBus {
>     > +        QString NEPOMUK_EXPORT convertUri(const QUrl& uri);
>     > +        QStringList NEPOMUK_EXPORT convertUriList(const
>     QList<QUrl>& uris);
>     > +
>     > +        /// Convert QDBusArguments variants into QUrl, QDate,
>     QTime, and QDateTime variants
>     > +        NEPOMUK_EXPORT QVariant resolveDBusArguments(const
>     QVariant& v);
>     > +        NEPOMUK_EXPORT QVariantList resolveDBusArguments(const
>     QVariantList& l);
>     > +
>     > +        /// Replaces KUrl with QUrl for DBus marshalling.
>     > +        QVariantList normalizeVariantList(const QVariantList& l);
>     > +
>     > +        NEPOMUK_EXPORT void registerDBusTypes();
>     > +    }
>     > +}
>     > +
>     > +QDBusArgument& operator<<( QDBusArgument& arg, const QUrl& url );
>     > +const QDBusArgument& operator>>( const QDBusArgument& arg, QUrl&
>     url );
>     > +
>     > +#endif // DBUSTYPES_H
>     > diff --git a/nepomuk/core/resourcedata.cpp
>     b/nepomuk/core/resourcedata.cpp
>     > index 023a6b9..1b516b9 100644
>     > --- a/nepomuk/core/resourcedata.cpp
>     > +++ b/nepomuk/core/resourcedata.cpp
>     > @@ -30,6 +30,7 @@
>     >  #include "nepomukmainmodel.h"
>     >  #include "dbusconnectionpool.h"
>     >  #include "class.h"
>     > +#include "dbustypes.h"
>     >
>     >  #include <Soprano/Statement>
>     >  #include <Soprano/StatementIterator>
>     > @@ -266,13 +267,10 @@ bool Nepomuk::ResourceData::store()
>     >                                                            
>     QLatin1String("org.kde.nepomuk.DataManagement"),
>     >                                                            
>     QLatin1String("createResource") );
>     >          QString app = KGlobal::mainComponent().componentName();
>     > -        QStringList types;
>     > -        foreach( const QUrl &type, m_types )
>     > -            types << type.toString();
>     > -
>     >          QVariantList arguments;
>     > +
>     >          //FIXME: Maybe we should be setting the 'label' over here.
>     > -        arguments << types << QString() << QString() << app;
>     > +        arguments << DBus::convertUriList(m_types) << QString()
>     << QString() << app;
>     >          msg.setArguments( arguments );
>     >
>     >          QDBusMessage reply = bus.call( msg );
>     > @@ -442,13 +440,12 @@ void Nepomuk::ResourceData::setProperty(
>     const QUrl& uri, const Nepomuk::Variant
>     >                                                            
>     QLatin1String("setProperty") );
>     >          QString app = KGlobal::mainComponent().componentName();
>     >          QVariantList arguments;
>     > -        QStringList resources;
>     > -        resources << m_uri.url();
>     >          QVariantList varList;
>     >          foreach( const Nepomuk::Variant var, value.toVariantList() )
>     >              varList << var.variant();
>     >
>     > -        arguments << resources << uri.toString() <<
>     QVariant(varList) << app;
>     > +        arguments << DBus::convertUriList(QList<QUrl>() << m_uri)
>     << DBus::convertUri(uri)
>     > +                  <<
>     QVariant(DBus::normalizeVariantList(varList)) << app;
>     >          msg.setArguments( arguments );
>     >
>     >          QDBusMessage reply = bus.call( msg );
>     > @@ -483,7 +480,7 @@ void Nepomuk::ResourceData::removeProperty(
>     const QUrl& uri )
>     >                                                            
>     QLatin1String("removeProperties") );
>     >          QString app = KGlobal::mainComponent().componentName();
>     >          QVariantList arguments;
>     > -        arguments << m_uri.url() << uri.toString() << app;
>     > +        arguments << DBus::convertUri(m_uri) <<
>     DBus::convertUri(uri) << app;
>     >          msg.setArguments( arguments );
>     >
>     >          QDBusMessage reply = bus.call( msg );
>     > @@ -516,7 +513,7 @@ void Nepomuk::ResourceData::remove( bool
>     recursive )
>     >          QString app = KGlobal::mainComponent().componentName();
>     >          QVariantList arguments;
>     >          // TODO: Set the flag over here
>     > -        arguments << m_uri.url() << 0 << app;
>     > +        arguments << DBus::convertUri(m_uri) << 0 << app;
>     >          msg.setArguments( arguments );
>     >
>     >          QDBusMessage reply = bus.call( msg );
>     > diff --git a/nepomuk/core/resourcemanager.cpp
>     b/nepomuk/core/resourcemanager.cpp
>     > index e8ce31d..e3ed0bd 100644
>     > --- a/nepomuk/core/resourcemanager.cpp
>     > +++ b/nepomuk/core/resourcemanager.cpp
>     > @@ -27,6 +27,7 @@
>     >  #include "resource.h"
>     >  #include "class.h"
>     >  #include "nie.h"
>     > +#include "dbustypes.h"
>     >
>     >  #include <kglobal.h>
>     >  #include <kdebug.h>
>     > @@ -47,6 +48,7 @@
>     >  #include <QtDBus/QDBusConnection>
>     >  #include <QtDBus/QDBusConnectionInterface>
>     >  #include <QtDBus/QDBusServiceWatcher>
>     > +#include <QtDBus/QDBusMetaType>
>     >
>     >  using namespace Soprano;
>     >
>     > @@ -59,6 +61,7 @@
>     Nepomuk::ResourceManagerPrivate::ResourceManagerPrivate(
>     ResourceManager* manage
>     >        dataCnt( 0 ),
>     >        m_manager( manager )
>     >  {
>     > +    Nepomuk::DBus::registerDBusTypes();
>     >  }
>     >
>     >
>     >
> 
> 
> 
> 
> -- 
> Vishesh Handa
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic