~mardy/ubuntu-system-settings-online-accounts/rtm-fixes

« back to all changes in this revision

Viewing changes to plugins/OnlineAccountsPlugin/request-handler.cpp

  • Committer: CI bot
  • Author(s): Alberto Mardegan
  • Date: 2014-10-09 20:20:41 UTC
  • mfrom: (193.2.6 master)
  • Revision ID: ps-jenkins@lists.canonical.com-20141009202041-tn2i5f3couen6zlw
Merge from master:

- Create the Ubuntu.OnlineAccounts.Plugin module 
Approved by: David Barth

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "request-handler.h"
22
22
 
23
 
#include "debug.h"
24
 
#include "ui-server.h"
25
 
 
26
23
#include <SignOn/uisessiondata_priv.h>
27
 
#include <QDBusArgument>
 
24
#include <QDebug>
28
25
#include <QList>
29
26
#include <QPointer>
30
27
#include <unistd.h>
50
47
    mutable RequestHandler *q_ptr;
51
48
};
52
49
 
 
50
class RequestHandlerWatcherPrivate
 
51
{
 
52
    Q_DECLARE_PUBLIC(RequestHandlerWatcher)
 
53
 
 
54
public:
 
55
    RequestHandlerWatcherPrivate(RequestHandlerWatcher *watcher);
 
56
    ~RequestHandlerWatcherPrivate();
 
57
 
 
58
    static RequestHandlerWatcherPrivate *instance();
 
59
    void registerHandler(RequestHandler *handler);
 
60
 
 
61
private:
 
62
    mutable RequestHandlerWatcher *q_ptr;
 
63
    static RequestHandlerWatcherPrivate *m_instance;
 
64
};
 
65
 
 
66
RequestHandlerWatcherPrivate *RequestHandlerWatcherPrivate::m_instance = 0;
 
67
 
53
68
} // namespace
54
69
 
55
70
RequestHandlerPrivate::RequestHandlerPrivate(RequestHandler *request):
68
83
{
69
84
    allRequestHandlers.append(this);
70
85
 
71
 
    OnlineAccountsUi::UiServer *server =
72
 
        OnlineAccountsUi::UiServer::instance();
73
 
    Q_ASSERT(server);
74
 
    server->registerHandler(this);
 
86
    RequestHandlerWatcherPrivate *watcher =
 
87
        RequestHandlerWatcherPrivate::instance();
 
88
    if (Q_LIKELY(watcher)) {
 
89
        watcher->registerHandler(this);
 
90
    }
75
91
}
76
92
 
77
93
RequestHandler::~RequestHandler()
106
122
    return d->m_matchId;
107
123
}
108
124
 
109
 
RequestHandler *RequestHandler::findMatching(const QVariantMap &parameters)
 
125
RequestHandlerWatcherPrivate::RequestHandlerWatcherPrivate(RequestHandlerWatcher *watcher):
 
126
    q_ptr(watcher)
 
127
{
 
128
    if (Q_UNLIKELY(m_instance)) {
 
129
        qWarning() << "RequestHandlerWatcher should be instantiated once!";
 
130
    }
 
131
 
 
132
    m_instance = this;
 
133
}
 
134
 
 
135
RequestHandlerWatcherPrivate::~RequestHandlerWatcherPrivate()
 
136
{
 
137
    m_instance = 0;
 
138
}
 
139
 
 
140
RequestHandlerWatcherPrivate *RequestHandlerWatcherPrivate::instance()
 
141
{
 
142
    return m_instance;
 
143
}
 
144
 
 
145
void RequestHandlerWatcherPrivate::registerHandler(RequestHandler *handler)
 
146
{
 
147
    Q_Q(RequestHandlerWatcher);
 
148
 
 
149
    Q_EMIT q->newHandler(handler);
 
150
}
 
151
 
 
152
RequestHandlerWatcher::RequestHandlerWatcher(QObject *parent):
 
153
    QObject(parent),
 
154
    d_ptr(new RequestHandlerWatcherPrivate(this))
 
155
{
 
156
}
 
157
 
 
158
RequestHandlerWatcher::~RequestHandlerWatcher()
 
159
{
 
160
    delete d_ptr;
 
161
}
 
162
 
 
163
RequestHandler *RequestHandlerWatcher::findMatching(const QVariantMap &parameters)
110
164
{
111
165
    /* Find if there's any RequestHandler expecting to handle the SignOnUi
112
166
     * request having "parameters" as parameters.
114
168
     * matchKey()), if present. We expect that account plugins add that field
115
169
     * to their AuthSession requests which they want to handle themselves.
116
170
     */
117
 
    DEBUG() << parameters;
 
171
    qDebug() << parameters;
118
172
    if (!parameters.contains(SSOUI_KEY_CLIENT_DATA)) return 0;
119
 
    QVariant variant = parameters[SSOUI_KEY_CLIENT_DATA];
120
 
    QVariantMap clientData = (variant.type() == QVariant::Map) ?
121
 
        variant.toMap() :
122
 
        qdbus_cast<QVariantMap>(variant.value<QDBusArgument>());
123
 
    DEBUG() << "client data:" << clientData;
 
173
    QVariantMap clientData = parameters[SSOUI_KEY_CLIENT_DATA].toMap();
 
174
    qDebug() << "client data:" << clientData;
124
175
    QString matchId = clientData.value(RequestHandler::matchKey()).toString();
125
176
    if (matchId.isEmpty()) return 0;
126
177