2
This file is part of the Nepomuk KDE project.
3
Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) version 3, or any
9
later version accepted by the membership of KDE e.V. (or its
10
successor approved by the membership of KDE e.V.), which shall
11
act as a proxy defined in Section 6 of version 3 of the license.
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public
19
License along with this library. If not, see <http://www.gnu.org/licenses/>.
22
#include "datamanagementcommand.h"
23
#include "datamanagementmodel.h"
25
#include <Soprano/Error/Error>
26
#include <Soprano/Error/ErrorCode>
28
#include <QtDBus/QDBusConnection>
30
#include <QtCore/QStringList>
31
#include <QtCore/QEventLoop>
37
QDBusError::ErrorType convertSopranoErrorCode(int code)
40
case Soprano::Error::ErrorInvalidArgument:
41
return QDBusError::InvalidArgs;
43
return QDBusError::Failed;
49
Nepomuk::DataManagementCommand::DataManagementCommand(DataManagementModel* model, const QDBusMessage& msg)
56
Nepomuk::DataManagementCommand::~DataManagementCommand()
60
void Nepomuk::DataManagementCommand::run()
62
QVariant result = runCommand();
63
Soprano::Error::Error error = model()->lastError();
66
QDBusConnection::sessionBus().send(m_msg.createErrorReply(convertSopranoErrorCode(error.code()), error.message()));
69
// encode result (ie. convert QUrl to QString)
70
if(result.isValid()) {
71
if(result.type() == QVariant::Url) {
72
result = encodeUrl(result.toUrl());
74
QDBusConnection::sessionBus().send(m_msg.createReply(result));
77
QDBusConnection::sessionBus().send(m_msg.createReply());
82
// DBus requires event handling for signals to be emitted properly.
83
// (for example the Soprano statement signals which are emitted a
84
// lot during command execution.)
85
// Otherwise memory will fill up with queued DBus message objects.
86
// Instead of executing an event loop we avoid all the hassle and
87
// simply handle all events here.
95
QUrl Nepomuk::decodeUrl(const QString& urlsString)
97
// we use the power of KUrl to automatically convert file paths to file:/ URLs
98
return KUrl(urlsString);
102
QList<QUrl> Nepomuk::decodeUrls(const QStringList& urlStrings)
105
Q_FOREACH(const QString& urlString, urlStrings) {
106
urls << decodeUrl(urlString);
112
QString Nepomuk::encodeUrl(const QUrl& url)
114
return QString::fromAscii(url.toEncoded());