parent
7d1585c071
commit
855818127b
@ -1,24 +1,44 @@
|
||||
#################################################
|
||||
#
|
||||
# (C) 2021 Michele Calgaro
|
||||
# Michele (DOT) Calgaro (AT) yahoo.it
|
||||
#
|
||||
# Improvements and feedback are welcome
|
||||
#
|
||||
# This file is released under GPL >= 2
|
||||
#
|
||||
#################################################
|
||||
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/agent
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/agent
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${TQT_INCLUDE_DIRS}
|
||||
${POLKIT_GOBJECT_INCLUDE_DIRS}
|
||||
${POLKIT_AGENT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(polkit_agent_example_SRCS
|
||||
main.cpp
|
||||
pkagentexample.cpp
|
||||
klistener.cpp
|
||||
link_directories(
|
||||
${TQT_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
automoc4(polkit-agent-example polkit_agent_example_SRCS)
|
||||
|
||||
add_executable(polkit-agent-example
|
||||
${polkit_agent_example_SRCS}
|
||||
##### install agent source code ###########################
|
||||
|
||||
install(
|
||||
FILES main.cpp pkagentexample.cpp pkagentexample.h tqtlistener.cpp tqtlistener.h
|
||||
DESTINATION ${POLKIT_TQT_EXAMPLE}/agent
|
||||
)
|
||||
|
||||
target_link_libraries(polkit-agent-example
|
||||
${TQT_TQTCORE_LIBRARY}
|
||||
${TQT_TQTGUI_LIBRARY}
|
||||
polkit-tqt-agent-1
|
||||
polkit-tqt-core-1
|
||||
|
||||
##### agent executable #########################
|
||||
|
||||
tde_add_executable( polkit-tqt-agent-example AUTOMOC
|
||||
SOURCES main.cpp pkagentexample.cpp tqtlistener.cpp
|
||||
LINK ${TQT_LIBRARIES} ${POLKIT_GOBJECT_LIBRARIES} ${POLKIT_AGENT_LIBRARIES}
|
||||
polkit-tqt-core-shared polkit-tqt-agent-shared
|
||||
DESTINATION ${BIN_INSTALL_DIR}
|
||||
)
|
||||
|
||||
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <TQtCore/TQDebug>
|
||||
#include <TQInputDialog>
|
||||
|
||||
#include "klistener.h"
|
||||
#include "agent/polkittqt1-agent-session.h"
|
||||
|
||||
using namespace PolkitTQt::Agent;
|
||||
|
||||
KListener::KListener(TQObject *parent)
|
||||
: Listener(parent)
|
||||
{
|
||||
tqDebug() << "Registering KDE listener";
|
||||
}
|
||||
|
||||
// README: this is just testing code...
|
||||
|
||||
void KListener::initiateAuthentication(const TQString &actionId,
|
||||
const TQString &message,
|
||||
const TQString &iconName,
|
||||
const PolkitTQt::Details &details,
|
||||
const TQString &cookie,
|
||||
const PolkitTQt::Identity::List &identities,
|
||||
AsyncResult *result)
|
||||
{
|
||||
tqDebug() << "initiateAuthentication for " << actionId << " with message " << message;
|
||||
tqDebug() << "iconName " << iconName;
|
||||
tqDebug() << details.keys();
|
||||
tqDebug() << "cookie" << cookie;
|
||||
|
||||
TQ_FOREACH (const PolkitTQt::Identity &identity, identities) {
|
||||
tqDebug() << identity.toString();
|
||||
Session *session;
|
||||
session = new Session(identity, cookie, result);
|
||||
connect(session, SIGNAL(request(TQString, bool)), this, SLOT(request(TQString, bool)));
|
||||
connect(session, SIGNAL(completed(bool)), this, SLOT(completed(bool)));
|
||||
connect(session, SIGNAL(showError(TQString)), this, SLOT(showError(TQString)));
|
||||
connect(session, SIGNAL(showInfo(TQString)), this, SLOT(showInfo(TQString)));
|
||||
session->initiate();
|
||||
}
|
||||
}
|
||||
|
||||
bool KListener::initiateAuthenticationFinish()
|
||||
{
|
||||
tqDebug() << "initiateAuthenticationFinish()";
|
||||
return true;
|
||||
}
|
||||
|
||||
void KListener::cancelAuthentication()
|
||||
{
|
||||
tqDebug() << "Cancelling authentication";
|
||||
}
|
||||
|
||||
void KListener::request(const TQString &request, bool echo)
|
||||
{
|
||||
tqDebug() << "Request: " << request;
|
||||
|
||||
Session *session = (Session *)sender();
|
||||
|
||||
session->setResponse("");
|
||||
}
|
||||
|
||||
void KListener::completed(bool gainedAuthorization)
|
||||
{
|
||||
tqDebug() << "Completed: " << gainedAuthorization;
|
||||
Session *session = (Session *)sender();
|
||||
|
||||
session->result()->setCompleted();
|
||||
|
||||
delete session;
|
||||
}
|
||||
|
||||
void KListener::showError(const TQString &text)
|
||||
{
|
||||
tqDebug() << "Error: " << text;
|
||||
}
|
||||
|
||||
void KListener::showInfo(const TQString &text)
|
||||
{
|
||||
tqDebug() << "Info: " << text;
|
||||
}
|
@ -1,17 +1,23 @@
|
||||
#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
|
||||
|
||||
#include <polkitagent/polkitagent.h>
|
||||
|
||||
#include "pkagentexample.h"
|
||||
#include <glib-object.h>
|
||||
#include <TQtCore/TQDebug>
|
||||
#include "polkittqt1-subject.h"
|
||||
#include <unistd.h>
|
||||
#include <tqsessionmanager.h>
|
||||
|
||||
PkAgentExample::PkAgentExample(int &argc, char **argv)
|
||||
: TQCoreApplication(argc, argv)
|
||||
{
|
||||
g_type_init();
|
||||
#include "polkit-tqt-subject.h"
|
||||
|
||||
PolkitTQt::UnixSessionSubject session(getpid());
|
||||
PkAgentExample::PkAgentExample(int argc, char **argv) : TQApplication(argc, argv)
|
||||
{
|
||||
PolkitTQt::UnixSessionSubject session(getpid());
|
||||
m_listener.registerListener(session, "/org/tqt/PolicyKit1/AuthenticationAgent");
|
||||
}
|
||||
|
||||
m_listener.registerListener(session, "/org/kde/PolicyKit1/AuthenticationAgent");
|
||||
void PkAgentExample::commitData(TQSessionManager &sm)
|
||||
{
|
||||
sm.setRestartHint(TQSessionManager::RestartNever);
|
||||
}
|
||||
|
||||
#include "pkagentexample.moc"
|
||||
|
||||
|
@ -0,0 +1,116 @@
|
||||
// This is an example not a library
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "tqstringlist.h"
|
||||
#include "tqinputdialog.h"
|
||||
|
||||
#include "polkit-tqt-identity.h"
|
||||
#include "polkit-tqt-details.h"
|
||||
#include "polkit-tqt-agent-session.h"
|
||||
#include "tqtlistener.h"
|
||||
|
||||
|
||||
using namespace PolkitTQt::Agent;
|
||||
|
||||
TQtListener::TQtListener(TQObject *parent) : Listener(parent)
|
||||
{
|
||||
tqDebug("Registering TQt listener");
|
||||
}
|
||||
|
||||
void TQtListener::initiateAuthentication(const TQString &actionId, const TQString &message,
|
||||
const TQString &iconName, const PolkitTQt::Details &details, const TQString &cookie,
|
||||
const PolkitTQt::Identity::List &identities, AsyncResult *result)
|
||||
{
|
||||
tqDebug("Initiate authentication for " + actionId + " with message " + message);
|
||||
tqDebug(" iconName " + iconName);
|
||||
TQStringList dkeys = details.keys();
|
||||
TQStringList::Iterator dkIt;
|
||||
for (dkIt = dkeys.begin(); dkIt != dkeys.end(); ++dkIt)
|
||||
{
|
||||
tqDebug(" key " + (*dkIt));
|
||||
}
|
||||
tqDebug(" cookie " + cookie);
|
||||
|
||||
PolkitTQt::Identity::List::ConstIterator iIt;
|
||||
for (iIt = identities.begin(); iIt != identities.end(); ++iIt)
|
||||
{
|
||||
PolkitTQt::Identity identity = *iIt;
|
||||
tqDebug(identity.toString());
|
||||
Session *session = new Session(identity, cookie, result);
|
||||
connect(session, TQT_SIGNAL(request(const TQString&, bool)), this,
|
||||
TQT_SLOT(request(const TQString&, bool)));
|
||||
connect(session, TQT_SIGNAL(completed(bool)), this, TQT_SLOT(completed(bool)));
|
||||
connect(session, TQT_SIGNAL(showError(const TQString&)), this,
|
||||
TQT_SLOT(showError(const TQString&)));
|
||||
connect(session, TQT_SIGNAL(showInfo(const TQString&)), this,
|
||||
TQT_SLOT(showInfo(const TQString&)));
|
||||
session->initiate();
|
||||
}
|
||||
}
|
||||
|
||||
bool TQtListener::initiateAuthenticationFinish()
|
||||
{
|
||||
tqDebug("InitiateAuthenticationFinish() done");
|
||||
return true;
|
||||
}
|
||||
|
||||
void TQtListener::cancelAuthentication()
|
||||
{
|
||||
tqDebug("Cancelling authentication");
|
||||
}
|
||||
|
||||
void TQtListener::request(const TQString &request, bool echo)
|
||||
{
|
||||
tqDebug("Request: " + request);
|
||||
Session *session = (Session*)sender();
|
||||
bool ok;
|
||||
TQString text = TQInputDialog::getText("TQt Agent", "Enter authorization password:",
|
||||
TQLineEdit::Password, TQString::null, &ok, NULL );
|
||||
if (ok && !text.isEmpty())
|
||||
{
|
||||
session->setResponse(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
session->setResponse(TQString::null);
|
||||
}
|
||||
}
|
||||
|
||||
void TQtListener::completed(bool gainedAuthorization)
|
||||
{
|
||||
tqDebug(TQString("Completed: ") + (gainedAuthorization ? "true" : "false"));
|
||||
Session *session = (Session*)sender();
|
||||
session->result()->setCompleted();
|
||||
delete session;
|
||||
}
|
||||
|
||||
void TQtListener::showError(const TQString &text)
|
||||
{
|
||||
tqDebug("Error: " + text);
|
||||
}
|
||||
|
||||
void TQtListener::showInfo(const TQString &text)
|
||||
{
|
||||
tqDebug("Info: " + text);
|
||||
}
|
||||
|
||||
#include "tqtlistener.moc"
|
||||
|
Loading…
Reference in new issue