PolkitQt-1

polkitqt1-agent-listener.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 "polkitqt1-agent-listener.h"
9
10#include <QDebug>
11
12#include "polkitqtlistener_p.h"
13
14#include "polkitqt1-authority.h"
15#include "polkitqt1-subject.h"
16#include "polkitqt1-identity.h"
17#include "polkitqt1-details.h"
18
19namespace PolkitQt1
20{
21
22namespace Agent
23{
24
25class ListenerPrivate
26{
27public:
28 PolkitAgentListener *listener;
29#ifndef POLKIT_QT_1_COMPATIBILITY_MODE
30 void *registeredHandle;
31#endif
32};
33
35 : QObject(parent), d(new ListenerPrivate)
36{
37 d->listener = polkit_qt_listener_new();
38
39 qDebug() << "New PolkitAgentListener " << d->listener;
40
41 ListenerAdapter::instance()->addListener(this);
42}
43
44Listener::Listener(PolkitAgentListener *listener, QObject *parent)
45 : QObject(parent), d(new ListenerPrivate)
46{
47 d->listener = listener;
48
49 if (d->listener != nullptr) {
50 g_object_ref(d->listener);
51 }
52}
53
54Listener::~Listener()
55{
56 qDebug("Destroying listener");
57
58 ListenerAdapter::instance()->removeListener(this);
59#ifndef POLKIT_QT_1_COMPATIBILITY_MODE
60 if (d->registeredHandle) {
61 polkit_agent_listener_unregister(d->registeredHandle);
62 }
63#endif
64 if (d->listener != nullptr) {
65 g_object_unref(d->listener);
66 }
67}
68
69bool Listener::registerListener(const PolkitQt1::Subject &subject, const QString &objectPath)
70{
71 GError *error = nullptr;
72
73#ifndef POLKIT_QT_1_COMPATIBILITY_MODE
74 d->registeredHandle = polkit_agent_listener_register(d->listener,
75 POLKIT_AGENT_REGISTER_FLAGS_NONE,
76#else
77 bool r = polkit_agent_register_listener(d->listener,
78#endif
79 subject.subject(),
80 objectPath.toLatin1().data(),
81#ifndef POLKIT_QT_1_COMPATIBILITY_MODE
82 nullptr,
83#endif
84 &error);
85
86 if (error != nullptr) {
87 qWarning() << QString("Cannot register authentication agent: %1").arg(error->message);
88 g_error_free(error);
89 return false;
90 }
91#ifndef POLKIT_QT_1_COMPATIBILITY_MODE
92 if (d->registeredHandle == nullptr) {
93 qWarning() << QString("Cannot register authentication agent!");
94 return false;
95 }
96 return true;
97#else
98 return r;
99#endif
100}
101
102const PolkitAgentListener *Listener::listener()
103{
104 return d->listener;
105}
106
107}
108
109}
const PolkitAgentListener * listener()
Returns pointer to the PolkitAgentListener.
bool registerListener(const PolkitQt1::Subject &subject, const QString &objectPath)
Registers listener with polkit daemon as an authentication agent for subject.
Listener(QObject *parent=nullptr)
Constructor of Listener class.
This class represents PolicyKit subjects.
PolkitSubject * subject() const
Gets PolkitSubject object.
Agent.
char * data()
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QByteArray toLatin1() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:43:21 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.