File indexing completed on 2024-05-05 13:10:48
0001 /* 0002 This file is part of the Polkit-qt project 0003 SPDX-FileCopyrightText: 2009 Jaroslav Reznik <jreznik@redhat.com> 0004 SPDX-FileContributor: based on code by David Zeuthen <davidz@redhat.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 0010 #include "polkitqtlistener_p.h" 0011 #include <stdio.h> 0012 0013 #include <QDebug> 0014 0015 #define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1 0016 0017 using namespace PolkitQt1::Agent; 0018 0019 /** 0020 * \internal 0021 */ 0022 struct _PolkitQtListener { 0023 PolkitAgentListener parent_instance; 0024 }; 0025 0026 /** 0027 * \internal 0028 */ 0029 struct _PolkitQtListenerClass { 0030 PolkitAgentListenerClass parent_class; 0031 }; 0032 0033 static void polkit_qt_listener_initiate_authentication(PolkitAgentListener *listener, 0034 const gchar *action_id, 0035 const gchar *message, 0036 const gchar *icon_name, 0037 PolkitDetails *details, 0038 const gchar *cookie, 0039 GList *identities, 0040 GCancellable *cancellable, 0041 GAsyncReadyCallback callback, 0042 gpointer user_data); 0043 0044 static gboolean polkit_qt_listener_initiate_authentication_finish(PolkitAgentListener *listener, 0045 GAsyncResult *res, 0046 GError **error); 0047 0048 G_DEFINE_TYPE(PolkitQtListener, polkit_qt_listener, POLKIT_AGENT_TYPE_LISTENER) 0049 0050 static void polkit_qt_listener_init(PolkitQtListener *listener) 0051 { 0052 } 0053 0054 static void polkit_qt_listener_finalize(GObject *object) 0055 { 0056 PolkitQtListener *listener; 0057 0058 listener = POLKIT_QT_LISTENER(object); 0059 0060 if (G_OBJECT_CLASS(polkit_qt_listener_parent_class)->finalize != nullptr) { 0061 G_OBJECT_CLASS(polkit_qt_listener_parent_class)->finalize(object); 0062 } 0063 } 0064 0065 static void polkit_qt_listener_class_init(PolkitQtListenerClass *klass) 0066 { 0067 GObjectClass *gobject_class; 0068 PolkitAgentListenerClass *listener_class; 0069 0070 gobject_class = G_OBJECT_CLASS(klass); 0071 listener_class = POLKIT_AGENT_LISTENER_CLASS(klass); 0072 0073 gobject_class->finalize = polkit_qt_listener_finalize; 0074 0075 listener_class->initiate_authentication = polkit_qt_listener_initiate_authentication; 0076 listener_class->initiate_authentication_finish = polkit_qt_listener_initiate_authentication_finish; 0077 } 0078 0079 PolkitAgentListener *polkit_qt_listener_new(void) 0080 { 0081 return POLKIT_AGENT_LISTENER(g_object_new(POLKIT_QT_TYPE_LISTENER, nullptr)); 0082 } 0083 0084 static void cancelled_cb(GCancellable *cancellable, gpointer user_data) 0085 { 0086 ListenerAdapter::instance()->cancelled_cb((PolkitAgentListener *)user_data); 0087 } 0088 0089 static void polkit_qt_listener_initiate_authentication(PolkitAgentListener *agent_listener, 0090 const gchar *action_id, 0091 const gchar *message, 0092 const gchar *icon_name, 0093 PolkitDetails *details, 0094 const gchar *cookie, 0095 GList *identities, 0096 GCancellable *cancellable, 0097 GAsyncReadyCallback callback, 0098 gpointer user_data) 0099 { 0100 qDebug() << "Listener adapter polkit_qt_listener_initiate_authentication"; 0101 PolkitQtListener *listener = POLKIT_QT_LISTENER(agent_listener); 0102 0103 if (cancellable != nullptr) { 0104 g_cancellable_connect(cancellable, 0105 G_CALLBACK(cancelled_cb), 0106 agent_listener, 0107 nullptr); 0108 } 0109 0110 // The result of asynchronous method will be created here and it will be pushed to the listener. 0111 GSimpleAsyncResult *result = g_simple_async_result_new((GObject *) listener, callback, user_data, agent_listener); 0112 qDebug() << "GSimpleAsyncResult:" << result; 0113 0114 ListenerAdapter::instance()->polkit_qt_listener_initiate_authentication(agent_listener, 0115 action_id, 0116 message, 0117 icon_name, 0118 details, 0119 cookie, 0120 identities, 0121 cancellable, 0122 result); 0123 0124 } 0125 0126 static gboolean polkit_qt_listener_initiate_authentication_finish(PolkitAgentListener *listener, 0127 GAsyncResult *res, 0128 GError **error) 0129 { 0130 qDebug() << "Listener adapter polkit_qt_listener_initiate_authentication_finish"; 0131 return ListenerAdapter::instance()->polkit_qt_listener_initiate_authentication_finish(listener, 0132 res, 0133 error); 0134 } 0135