PolkitQt-1

polkitqtlistener.cpp
1/*
2 This file is part of the Polkit-qt project
3 SPDX-FileCopyrightText: 2009 Jaroslav Reznik <jreznik@redhat.com>
4 SPDX-FileContributor: based on code by David Zeuthen <davidz@redhat.com>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9
10#include "polkitqtlistener_p.h"
11#include <stdio.h>
12
13#include <QDebug>
14
15#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
16
17using namespace PolkitQt1::Agent;
18
19/**
20 * \internal
21 */
22struct _PolkitQtListener {
23 PolkitAgentListener parent_instance;
24};
25
26/**
27 * \internal
28 */
29struct _PolkitQtListenerClass {
30 PolkitAgentListenerClass parent_class;
31};
32
33static void polkit_qt_listener_initiate_authentication(PolkitAgentListener *listener,
34 const gchar *action_id,
35 const gchar *message,
36 const gchar *icon_name,
37 PolkitDetails *details,
38 const gchar *cookie,
39 GList *identities,
40 GCancellable *cancellable,
41 GAsyncReadyCallback callback,
42 gpointer user_data);
43
44static gboolean polkit_qt_listener_initiate_authentication_finish(PolkitAgentListener *listener,
45 GAsyncResult *res,
46 GError **error);
47
48G_DEFINE_TYPE(PolkitQtListener, polkit_qt_listener, POLKIT_AGENT_TYPE_LISTENER)
49
50static void polkit_qt_listener_init(PolkitQtListener *listener)
51{
52}
53
54static void polkit_qt_listener_finalize(GObject *object)
55{
56 PolkitQtListener *listener;
57
58 listener = POLKIT_QT_LISTENER(object);
59
60 if (G_OBJECT_CLASS(polkit_qt_listener_parent_class)->finalize != nullptr) {
61 G_OBJECT_CLASS(polkit_qt_listener_parent_class)->finalize(object);
62 }
63}
64
65static void polkit_qt_listener_class_init(PolkitQtListenerClass *klass)
66{
67 GObjectClass *gobject_class;
68 PolkitAgentListenerClass *listener_class;
69
70 gobject_class = G_OBJECT_CLASS(klass);
71 listener_class = POLKIT_AGENT_LISTENER_CLASS(klass);
72
73 gobject_class->finalize = polkit_qt_listener_finalize;
74
75 listener_class->initiate_authentication = polkit_qt_listener_initiate_authentication;
76 listener_class->initiate_authentication_finish = polkit_qt_listener_initiate_authentication_finish;
77}
78
79PolkitAgentListener *polkit_qt_listener_new(void)
80{
81 return POLKIT_AGENT_LISTENER(g_object_new(POLKIT_QT_TYPE_LISTENER, nullptr));
82}
83
84static void cancelled_cb(GCancellable *cancellable, gpointer user_data)
85{
86 ListenerAdapter::instance()->cancelled_cb((PolkitAgentListener *)user_data);
87}
88
89static void polkit_qt_listener_initiate_authentication(PolkitAgentListener *agent_listener,
90 const gchar *action_id,
91 const gchar *message,
92 const gchar *icon_name,
93 PolkitDetails *details,
94 const gchar *cookie,
95 GList *identities,
96 GCancellable *cancellable,
97 GAsyncReadyCallback callback,
98 gpointer user_data)
99{
100 qDebug() << "Listener adapter polkit_qt_listener_initiate_authentication";
101 PolkitQtListener *listener = POLKIT_QT_LISTENER(agent_listener);
102
103 if (cancellable != nullptr) {
104 g_cancellable_connect(cancellable,
105 G_CALLBACK(cancelled_cb),
106 agent_listener,
107 nullptr);
108 }
109
110 // The result of asynchronous method will be created here and it will be pushed to the listener.
111 GSimpleAsyncResult *result = g_simple_async_result_new((GObject *) listener, callback, user_data, agent_listener);
112 qDebug() << "GSimpleAsyncResult:" << result;
113
114 ListenerAdapter::instance()->polkit_qt_listener_initiate_authentication(agent_listener,
115 action_id,
116 message,
117 icon_name,
118 details,
119 cookie,
120 identities,
121 cancellable,
122 result);
123
124}
125
126static gboolean polkit_qt_listener_initiate_authentication_finish(PolkitAgentListener *listener,
127 GAsyncResult *res,
128 GError **error)
129{
130 qDebug() << "Listener adapter polkit_qt_listener_initiate_authentication_finish";
131 return ListenerAdapter::instance()->polkit_qt_listener_initiate_authentication_finish(listener,
132 res,
133 error);
134}
135
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:47:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.