2
* This file is part of online-accounts-ui
4
* Copyright (C) 2011-2014 Canonical Ltd.
6
* Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
8
* This program is free software: you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License version 3, as published
10
* by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranties of
14
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
* PURPOSE. See the GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "request-handler.h"
24
#include "request-manager.h"
25
#include "signonui-request.h"
26
#include "signonui-service.h"
27
#include "browser-request.h"
29
#include <QDBusArgument>
31
#include <SignOn/uisessiondata_priv.h>
33
using namespace SignOnUi;
37
static QVariant dbusValueToVariant(const QDBusArgument &argument)
41
/* Note: this function should operate recursively, but it doesn't. */
42
if (argument.currentType() == QDBusArgument::MapType) {
43
/* Assume that all maps are a{sv} */
44
ret = qdbus_cast<QVariantMap>(argument);
46
/* We don't know how to handle other types */
47
ret = argument.asVariant();
52
static QVariantMap expandDBusArguments(const QVariantMap &dbusMap)
55
QMapIterator<QString, QVariant> it(dbusMap);
56
while (it.hasNext()) {
58
if (qstrcmp(it.value().typeName(), "QDBusArgument") == 0) {
59
QDBusArgument dbusValue = it.value().value<QDBusArgument>();
60
map.insert(it.key(), dbusValueToVariant(dbusValue));
62
map.insert(it.key(), it.value());
68
class ServicePrivate: public QObject
71
Q_DECLARE_PUBLIC(Service)
74
ServicePrivate(Service *service);
77
void cancelUiRequest(const QString &requestId);
78
void removeIdentityData(quint32 id);
81
mutable Service *q_ptr;
86
ServicePrivate::ServicePrivate(Service *service):
92
ServicePrivate::~ServicePrivate()
96
void ServicePrivate::cancelUiRequest(const QString &requestId)
99
match.insert(SSOUI_KEY_REQUESTID, requestId);
100
OnlineAccountsUi::Request *request =
101
OnlineAccountsUi::Request::find(match);
103
DEBUG() << "Cancelling request" << request;
109
void ServicePrivate::removeIdentityData(quint32 id)
111
/* Remove any data associated with the given identity. */
113
/* The BrowserRequest class creates a directory to store the cookies */
114
BrowserRequest::removeIdentityData(id);
117
Service::Service(QObject *parent):
119
d_ptr(new ServicePrivate(this))
121
qmlRegisterType<SignOnUi::RequestHandler>("Ubuntu.OnlineAccounts.Plugin",
122
1, 0, "RequestHandler");
129
QVariantMap Service::queryDialog(const QVariantMap ¶meters)
131
QVariantMap cleanParameters = expandDBusArguments(parameters);
132
DEBUG() << "Got request:" << cleanParameters;
134
/* The following line tells QtDBus not to generate a reply now */
135
setDelayedReply(true);
137
OnlineAccountsUi::Request *request =
138
OnlineAccountsUi::Request::newRequest(connection(),
143
/* Check if a RequestHandler has been setup to handle this request. If
144
* so, bing the request object to the handler and start the request
146
SignOnUi::Request *signonRequest =
147
qobject_cast<SignOnUi::Request*>(request);
148
Q_ASSERT(signonRequest != 0);
150
RequestHandler *handler = RequestHandler::findMatching(cleanParameters);
152
DEBUG() << "Found RequestHandler!";
153
signonRequest->setHandler(handler);
154
QObject::connect(signonRequest, SIGNAL(completed()),
155
signonRequest, SLOT(deleteLater()));
156
signonRequest->start();
159
OnlineAccountsUi::RequestManager::instance()->enqueue(request);
162
return QVariantMap();
165
QVariantMap Service::refreshDialog(const QVariantMap &newParameters)
167
QVariantMap cleanParameters = expandDBusArguments(newParameters);
168
QString requestId = Request::id(cleanParameters);
169
// TODO find the request and update it
171
/* The following line tells QtDBus not to generate a reply now */
172
setDelayedReply(true);
173
return QVariantMap();
176
void Service::cancelUiRequest(const QString &requestId)
179
d->cancelUiRequest(requestId);
182
void Service::removeIdentityData(quint32 id)
185
d->removeIdentityData(id);
188
#include "signonui-service.moc"