PolkitQt-1

listeneradapter.cpp
1/*
2 This file is part of the Polkit-qt project
3 SPDX-FileCopyrightText: 2009 Jaroslav Reznik <jreznik@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "listeneradapter_p.h"
9#include <QDebug>
10#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
11#include <polkitagent/polkitagent.h>
12
13namespace PolkitQt1
14{
15
16namespace Agent
17{
18
19class ListenerAdapterHelper
20{
21public:
22 ListenerAdapterHelper() : q(nullptr) {}
23 ~ListenerAdapterHelper() {
24 delete q;
25 }
26 ListenerAdapter *q;
27};
28
29Q_GLOBAL_STATIC(ListenerAdapterHelper, s_globalListenerAdapter)
30
31ListenerAdapter *ListenerAdapter::instance()
32{
33 if (!s_globalListenerAdapter()->q) {
34 new ListenerAdapter();
35 }
36
37 return s_globalListenerAdapter()->q;
38}
39
40ListenerAdapter::ListenerAdapter(QObject *parent)
41 : QObject(parent)
42{
43 Q_ASSERT(!s_globalListenerAdapter()->q);
44 s_globalListenerAdapter()->q = this;
45}
46
47Listener* ListenerAdapter::findListener(PolkitAgentListener *listener)
48{
49 Listener *listItem;
50
51 Q_FOREACH(listItem, m_listeners) {
52 Q_ASSERT(listItem);
53
54 if (listItem->listener() == listener) {
55 return listItem;
56 }
57 }
58
59 return nullptr;
60}
61
62void ListenerAdapter::polkit_qt_listener_initiate_authentication(PolkitAgentListener *listener,
63 const gchar *action_id,
64 const gchar *message,
65 const gchar *icon_name,
66 PolkitDetails *details,
67 const gchar *cookie,
68 GList *identities,
69 GCancellable *cancellable,
70 GSimpleAsyncResult *result)
71{
72 qDebug() << "polkit_qt_listener_initiate_authentication callback for " << listener;
73
75 PolkitQt1::Details dets(details);
76
77 Listener *list = findListener(listener);
78
79 for (GList *identity = g_list_first(identities); identity != nullptr; identity = g_list_next(identity)) {
80 idents.append(PolkitQt1::Identity((PolkitIdentity *)identity->data));
81 }
82
83 list->initiateAuthentication(QString::fromUtf8(action_id),
84 QString::fromUtf8(message),
85 QString::fromUtf8(icon_name),
86 dets,
87 QString::fromUtf8(cookie),
88 idents,
89 new AsyncResult(result));
90}
91
92gboolean ListenerAdapter::polkit_qt_listener_initiate_authentication_finish(PolkitAgentListener *listener,
93 GAsyncResult *res,
94 GError **error)
95{
96 qDebug() << "polkit_qt_listener_initiate_authentication_finish callback for " << listener;
97
98 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(res);
99 if (g_simple_async_result_propagate_error(simple, error)) {
100 return false;
101 }
102 return true;
103}
104
105void ListenerAdapter::cancelled_cb(PolkitAgentListener *listener)
106{
107 qDebug() << "cancelled_cb for " << listener;
108
109 Listener *list = findListener(listener);
110
111 list->cancelAuthentication();
112}
113
114void ListenerAdapter::addListener(Listener *listener)
115{
116 qDebug() << "Adding new listener " << listener << "for " << listener->listener();
117
118 m_listeners.append(listener);
119}
120
121void ListenerAdapter::removeListener(Listener *listener)
122{
123 qDebug() << "Removing listener " << listener;
124
125 // should be safe as we don't have more than one same listener registered in one time
126 m_listeners.removeOne(listener);
127}
128
129}
130
131}
Class used for passing details around.
Abstract class representing identities.
Agent.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void append(QList< T > &&value)
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 15 2024 11:56:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.