Converted agent example code.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/1/head
Michele Calgaro 3 years ago
parent 7d1585c071
commit 855818127b
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -1,4 +1,5 @@
debian/tmp/etc/dbus-1/system.d/org.tqt.policykit.examples.conf
debian/tmp/usr/bin/polkit-tqt-agent-example
debian/tmp/usr/bin/polkit-tqt-example
debian/tmp/usr/bin/polkit-tqt-example-helper
debian/tmp/usr/share/apps/polkit-tqt/examples/*

@ -31,6 +31,7 @@ tde_setup_dbus( dbus-1-tqt )
set( POLKIT_TQT_EXAMPLE "${DATA_INSTALL_DIR}/polkit-tqt/examples/" )
##### install examples runtime config ###########################
configure_file( org.tqt.policykit.examples.service.cmake org.tqt.policykit.examples.service @ONLY )
@ -51,6 +52,16 @@ install(
)
##### install icons ###########################
add_subdirectory( icons )
##### adent directory ########################
add_subdirectory( agent )
##### install examples source code ###########################
install(
@ -78,11 +89,6 @@ install(
)
##### install icons ###########################
add_subdirectory( icons )
##### example executables #########################
tde_add_executable( polkit-tqt-example AUTOMOC

@ -29,11 +29,12 @@
#include <tqdom.h>
#include <tqfile.h>
#include <tqtimer.h>
#include <tqsessionmanager.h>
using namespace PolkitTQt;
PkExampleHelper::PkExampleHelper(int &argc, char **argv) : TQApplication(argc, argv, false)
PkExampleHelper::PkExampleHelper(int argc, char **argv) : TQApplication(argc, argv, false)
{
tqDebug("Creating Helper");
// Register the DBus service
@ -61,6 +62,11 @@ PkExampleHelper::~PkExampleHelper()
m_connection.unregisterObject("org.tqt.policykit.examples");
}
void PkExampleHelper::commitData(TQSessionManager &sm)
{
sm.setRestartHint(TQSessionManager::RestartNever);
}
bool PkExampleHelper::handleMethodCall(const TQT_DBusMessage& message)
{
if (message.interface() != "org.tqt.policykit.examples")

@ -26,17 +26,21 @@
#include <tqdbusconnection.h>
#include "tqapplication.h"
class TQSessionManager;
class PkExampleHelper : public TQApplication, public TQT_DBusObjectBase
{
Q_OBJECT
public:
PkExampleHelper(int &argc, char **argv);
PkExampleHelper(int argc, char **argv);
~PkExampleHelper();
bool set(const TQString &action);
bool setValue(const TQString &action);
void commitData(TQSessionManager &sm);
protected:
bool handleMethodCall(const TQT_DBusMessage& message);

@ -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,3 +1,4 @@
// This is an example not a library
/***************************************************************************
* Copyright (C) 2009 Jaroslav Reznik *
* *
@ -17,14 +18,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include <TQApplication>
#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
#include "pkagentexample.h"
int main(int argc, char *argv[])
{
PkAgentExample example(argc, argv);
return example.exec();
PkAgentExample example(argc, argv);
return example.exec();
}

@ -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"

@ -24,19 +24,24 @@
#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
#include <TQtDBus/TQDBusContext>
#include <TQCoreApplication>
#include "klistener.h"
#include <tqapplication.h>
class PkAgentExample : public TQCoreApplication
#include "tqtlistener.h"
class TQSessionManager;
class PkAgentExample : public TQApplication
{
Q_OBJECT
public:
PkAgentExample(int &argc, char **argv);
~PkAgentExample() {};
private:
KListener m_listener;
};
Q_OBJECT
public:
PkAgentExample(int argc, char **argv);
void commitData(TQSessionManager &sm);
private:
TQtListener m_listener;
};
#endif

@ -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"

@ -1,3 +1,4 @@
// This is an example not a library
/*
* This file is part of the Polkit-qt project
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
@ -18,32 +19,34 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef POLKIT_TQT_AGENT_KDE_LISTENER_H
#define POLKIT_TQT_AGENT_KDE_LISTENER_H
#ifndef POLKIT_TQT_AGENT_TDE_LISTENER_H
#define POLKIT_TQT_AGENT_TDE_LISTENER_H
#include <TQtCore/TQObject>
#include <TQtCore/TQString>
#include "polkit-tqt-agent-listener.h"
#include "agent/polkittqt1-agent-listener.h"
#include "core/polkittqt1-identity.h"
#include "core/polkittqt1-details.h"
#include "agent/polkittqt1-agent-session.h"
namespace PolkitTQt
{
class Details;
namespace Agent
{
class AsyncResult;
}
}
class KListener : public PolkitTQt::Agent::Listener
class TQtListener : public PolkitTQt::Agent::Listener
{
Q_OBJECT
TQ_DISABLE_COPY(KListener)
public:
KListener(TQObject *parent = 0);
~KListener() {};
public Q_SLOTS:
void initiateAuthentication(const TQString &actionId,
const TQString &message,
const TQString &iconName,
const PolkitTQt::Details &details,
const TQString &cookie,
const PolkitTQt::Identity::List &identities,
PolkitTQt::Agent::AsyncResult *result);
Q_OBJECT
public:
TQtListener(TQObject *parent = 0);
public slots:
void initiateAuthentication(const TQString &actionId, const TQString &message,
const TQString &iconName, const PolkitTQt::Details &details,
const TQString &cookie, const PolkitTQt::Identity::List &identities,
PolkitTQt::Agent::AsyncResult *result);
bool initiateAuthenticationFinish();
void cancelAuthentication();
@ -51,6 +54,12 @@ public Q_SLOTS:
void completed(bool gainedAuthorization);
void showError(const TQString &text);
void showInfo(const TQString &text);
private:
// Disable copy
TQtListener(const TQtListener&);
TQtListener& operator=(const TQtListener&);
};
#endif
Loading…
Cancel
Save