diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-12-09 17:02:13 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-12-09 17:02:13 +0900 |
commit | 855818127b02c367fb187e67b9bb9b229b916304 (patch) | |
tree | c353d9b96b0135baf7f7a553c59926f2e5866a31 | |
parent | 7d1585c071206dd8460ed624eff764de5464dde7 (diff) | |
download | polkit-tqt-855818127b02c367fb187e67b9bb9b229b916304.tar.gz polkit-tqt-855818127b02c367fb187e67b9bb9b229b916304.zip |
Converted agent example code.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r-- | debian/libpolkit-tqt-examples.install | 1 | ||||
-rw-r--r-- | examples/CMakeLists.txt | 16 | ||||
-rw-r--r-- | examples/PkExampleHelper.cpp | 8 | ||||
-rw-r--r-- | examples/PkExampleHelper.h | 6 | ||||
-rw-r--r-- | examples/agent/CMakeLists.txt | 50 | ||||
-rw-r--r-- | examples/agent/klistener.cpp | 100 | ||||
-rw-r--r-- | examples/agent/main.cpp | 9 | ||||
-rw-r--r-- | examples/agent/pkagentexample.cpp | 24 | ||||
-rw-r--r-- | examples/agent/pkagentexample.h | 27 | ||||
-rw-r--r-- | examples/agent/tqtlistener.cpp | 116 | ||||
-rw-r--r-- | examples/agent/tqtlistener.h (renamed from examples/agent/klistener.h) | 53 |
11 files changed, 240 insertions, 170 deletions
diff --git a/debian/libpolkit-tqt-examples.install b/debian/libpolkit-tqt-examples.install index 7486b823c..2a6649d81 100644 --- a/debian/libpolkit-tqt-examples.install +++ b/debian/libpolkit-tqt-examples.install @@ -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/* diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d3b3a8407..8cb8e8c5b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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 diff --git a/examples/PkExampleHelper.cpp b/examples/PkExampleHelper.cpp index a6d169207..7b27de58f 100644 --- a/examples/PkExampleHelper.cpp +++ b/examples/PkExampleHelper.cpp @@ -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") diff --git a/examples/PkExampleHelper.h b/examples/PkExampleHelper.h index f4b13786b..322366557 100644 --- a/examples/PkExampleHelper.h +++ b/examples/PkExampleHelper.h @@ -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); diff --git a/examples/agent/CMakeLists.txt b/examples/agent/CMakeLists.txt index 17dc16272..4ce78eddb 100644 --- a/examples/agent/CMakeLists.txt +++ b/examples/agent/CMakeLists.txt @@ -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} ) + diff --git a/examples/agent/klistener.cpp b/examples/agent/klistener.cpp deleted file mode 100644 index 6bc95a990..000000000 --- a/examples/agent/klistener.cpp +++ /dev/null @@ -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; -} diff --git a/examples/agent/main.cpp b/examples/agent/main.cpp index 8e61f7066..cf2406b57 100644 --- a/examples/agent/main.cpp +++ b/examples/agent/main.cpp @@ -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(); } diff --git a/examples/agent/pkagentexample.cpp b/examples/agent/pkagentexample.cpp index 1ffe39f53..becd51d46 100644 --- a/examples/agent/pkagentexample.cpp +++ b/examples/agent/pkagentexample.cpp @@ -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" + diff --git a/examples/agent/pkagentexample.h b/examples/agent/pkagentexample.h index 61dfb3dab..1776df117 100644 --- a/examples/agent/pkagentexample.h +++ b/examples/agent/pkagentexample.h @@ -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 + diff --git a/examples/agent/tqtlistener.cpp b/examples/agent/tqtlistener.cpp new file mode 100644 index 000000000..e915eabce --- /dev/null +++ b/examples/agent/tqtlistener.cpp @@ -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" + diff --git a/examples/agent/klistener.h b/examples/agent/tqtlistener.h index a4367f981..202efa278 100644 --- a/examples/agent/klistener.h +++ b/examples/agent/tqtlistener.h @@ -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 + |