8#include "listeneradapter_p.h"
10#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
11#include <polkitagent/polkitagent.h>
19class ListenerAdapterHelper
22 ListenerAdapterHelper() : q(nullptr) {}
23 ~ListenerAdapterHelper() {
29Q_GLOBAL_STATIC(ListenerAdapterHelper, s_globalListenerAdapter)
31ListenerAdapter *ListenerAdapter::instance()
33 if (!s_globalListenerAdapter()->q) {
34 new ListenerAdapter();
37 return s_globalListenerAdapter()->q;
40ListenerAdapter::ListenerAdapter(QObject *parent)
43 Q_ASSERT(!s_globalListenerAdapter()->q);
44 s_globalListenerAdapter()->q =
this;
47Listener* ListenerAdapter::findListener(PolkitAgentListener *listener)
51 Q_FOREACH(listItem, m_listeners) {
54 if (listItem->listener() == listener) {
62void ListenerAdapter::polkit_qt_listener_initiate_authentication(PolkitAgentListener *listener,
63 const gchar *action_id,
65 const gchar *icon_name,
66 PolkitDetails *details,
69 GCancellable *cancellable,
70 GSimpleAsyncResult *result)
72 qDebug() <<
"polkit_qt_listener_initiate_authentication callback for " << listener;
76 Listener *
list = findListener(listener);
82 for (GList *entry = g_list_first(identities); entry !=
nullptr; entry = g_list_next(entry)) {
83 auto identity =
static_cast<PolkitIdentity *
>(entry->data);
93 new AsyncResult(result));
96gboolean ListenerAdapter::polkit_qt_listener_initiate_authentication_finish(PolkitAgentListener *listener,
100 qDebug() <<
"polkit_qt_listener_initiate_authentication_finish callback for " << listener;
102 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(res);
103 if (g_simple_async_result_propagate_error(simple, error)) {
109void ListenerAdapter::cancelled_cb(PolkitAgentListener *listener)
111 qDebug() <<
"cancelled_cb for " << listener;
113 Listener *
list = findListener(listener);
115 list->cancelAuthentication();
118void ListenerAdapter::addListener(Listener *listener)
120 qDebug() <<
"Adding new listener " << listener <<
"for " << listener->listener();
122 m_listeners.
append(listener);
125void ListenerAdapter::removeListener(Listener *listener)
127 qDebug() <<
"Removing listener " << listener;
130 m_listeners.removeOne(listener);
Class used for passing details around.
Abstract class representing identities.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
iterator insert(const Key &key, const T &value)
QList< T > values() const const
void append(QList< T > &&value)
QString fromUtf8(QByteArrayView str)