Changeset View
Changeset View
Standalone View
Standalone View
src/util/externalcommand_authagent.cpp
- This file was added.
1 | /************************************************************************* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 by Shubham <shubham.jangra@kdemail.net> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or * | ||||
5 | * modify it under the terms of the GNU General Public License as * | ||||
6 | * published by the Free Software Foundation; either version 3 of * | ||||
7 | * the License, or (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>.* | ||||
16 | *************************************************************************/ | ||||
17 | | ||||
18 | #include <QDebug> | ||||
19 | | ||||
20 | #include <PolkitQt1/Agent/Listener> | ||||
21 | #include <PolkitQt1/Agent/Session> | ||||
22 | #include <PolkitQt1/Authority> | ||||
23 | #include <PolkitQt1/Details> | ||||
24 | #include <PolkitQt1/Identity> | ||||
25 | | ||||
26 | #include "util/externalcommand_authagent.h" | ||||
27 | | ||||
28 | using namespace PolkitQt1; | ||||
29 | | ||||
30 | Listener::Listener(QObject *parent) | ||||
31 | : Agent::Listener(parent), | ||||
32 | m_agentRegistered(false) | ||||
33 | { | ||||
34 | qDebug() << "Registration of Authentication started"; | ||||
35 | } | ||||
36 | | ||||
37 | Listener::~Listener() | ||||
38 | { | ||||
39 | delete m_authenticationSession; | ||||
40 | } | ||||
41 | | ||||
42 | bool Listener::registerListener(const Subject &subject, const QString &locale, const QString &objectPath) | ||||
43 | { | ||||
44 | Authority::instance()->registerAuthenticationAgent(subject, locale, objectPath); | ||||
45 | m_agentRegistered = true; | ||||
46 | return true; | ||||
47 | } | ||||
48 | | ||||
49 | bool Listener::unregisterListener(const Subject &subject, const QString &objectPath) | ||||
50 | { | ||||
51 | qDebug() << "Unregistering Agent Listener"; | ||||
52 | Authority::instance()->unregisterAuthenticationAgent(subject, objectPath); | ||||
53 | m_agentRegistered = false; | ||||
54 | return true; | ||||
55 | } | ||||
56 | | ||||
57 | void Listener::initiateAuthentication(const QString &actionId, | ||||
58 | const QString &message, | ||||
59 | const QString &iconName, | ||||
60 | const Details &details, | ||||
61 | const QString &cookie, | ||||
62 | const Identity::List &identities, | ||||
63 | Agent::AsyncResult *result) | ||||
64 | { | ||||
65 | qDebug() << "initiateAuthentication for " << actionId << " with message " << message; | ||||
66 | qDebug() << "iconName " << iconName; | ||||
67 | qDebug() << details.keys(); | ||||
68 | qDebug() << "cookie" << cookie; | ||||
69 | | ||||
70 | if (m_agentRegistered) { | ||||
71 | for (const Identity &identity : identities) { | ||||
72 | qDebug() << identity.toString(); | ||||
73 | m_authenticationSession = new Agent::Session(identity, cookie, result); | ||||
74 | | ||||
75 | connect(m_authenticationSession, &Agent::Session::request, this, &Listener::request); | ||||
76 | connect(m_authenticationSession, &Agent::Session::completed, this, &Listener::completed); | ||||
77 | connect(m_authenticationSession, &Agent::Session::showError, this, &Listener::showError); | ||||
78 | connect(m_authenticationSession, &Agent::Session::showInfo, this, &Listener::showInfo); | ||||
79 | | ||||
80 | // Using PolkitQt1::Session class member functions/API to initiate the authentication process | ||||
81 | m_authenticationSession->initiate(); | ||||
82 | } | ||||
83 | } | ||||
84 | } | ||||
85 | | ||||
86 | /*bool Listener::initiateAuthenticationFinish(const Subject &subject, const QString &objectPath) | ||||
87 | { | ||||
88 | qDebug() << "Initializing Authentication finish"; | ||||
89 | Authority::instance()->unregisterAuthenticationAgent(subject, objectPath); | ||||
90 | return true; | ||||
91 | }*/ | ||||
92 | | ||||
93 | void Listener::cancelAuthentication() | ||||
94 | { | ||||
95 | qDebug() << "Cancelling the Authentication session"; | ||||
96 | m_authenticationSession->cancel(); | ||||
97 | } | ||||
98 | | ||||
99 | void Listener::setResponse(const QString &response) | ||||
100 | { | ||||
101 | | ||||
102 | m_authenticationSession = dynamic_cast<Agent::Session *>(sender()); | ||||
103 | m_authenticationSession->setResponse(response); | ||||
104 | } | ||||
105 | | ||||
106 | void Listener::request(const QString &request, bool echo) | ||||
107 | { | ||||
108 | Q_UNUSED(echo) | ||||
109 | | ||||
110 | qDebug() << "Request: " << request; | ||||
111 | | ||||
112 | m_authenticationSession = dynamic_cast<Agent::Session *>(sender()); | ||||
113 | m_authenticationSession->setResponse(request); | ||||
114 | } | ||||
115 | | ||||
116 | void Listener::completed(bool gainedAuthorization) | ||||
117 | { | ||||
118 | qDebug() << "Action completed: " << gainedAuthorization; | ||||
119 | | ||||
120 | m_authenticationSession = dynamic_cast<Agent::Session *>(sender()); | ||||
121 | m_authenticationSession->result()->setCompleted(); | ||||
122 | } | ||||
123 | | ||||
124 | void Listener::showError(const QString& text) const | ||||
125 | { | ||||
126 | qDebug() << "Error: " << text; | ||||
127 | } | ||||
128 | | ||||
129 | void Listener::showInfo(const QString& text) const | ||||
130 | { | ||||
131 | qDebug() << "Information: " << text; | ||||
132 | } |