summaryrefslogtreecommitdiffstats
path: root/examples/agent
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2021-10-30 12:06:43 +0900
committerMichele Calgaro <[email protected]>2021-10-30 12:06:43 +0900
commit28de2ff84f59ac0b173670aa9c5331bc77c1e63f (patch)
tree43dcf0f461ee5552100b648e38979982c971597d /examples/agent
downloadpolkit-tqt-28de2ff84f59ac0b173670aa9c5331bc77c1e63f.tar.gz
polkit-tqt-28de2ff84f59ac0b173670aa9c5331bc77c1e63f.zip
Initial import from polkit-qt-1 debian snapshot archive.
https://snapshot.debian.org/package/polkit-qt-1/0.103.0-1/ Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'examples/agent')
-rw-r--r--examples/agent/CMakeLists.txt24
-rw-r--r--examples/agent/klistener.cpp100
-rw-r--r--examples/agent/klistener.h56
-rw-r--r--examples/agent/main.cpp30
-rw-r--r--examples/agent/pkagentexample.cpp17
-rw-r--r--examples/agent/pkagentexample.h42
6 files changed, 269 insertions, 0 deletions
diff --git a/examples/agent/CMakeLists.txt b/examples/agent/CMakeLists.txt
new file mode 100644
index 000000000..ba708cb46
--- /dev/null
+++ b/examples/agent/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/agent
+)
+
+set(polkit_agent_example_SRCS
+ main.cpp
+ pkagentexample.cpp
+ klistener.cpp
+)
+
+automoc4(polkit-agent-example polkit_agent_example_SRCS)
+
+add_executable(polkit-agent-example
+ ${polkit_agent_example_SRCS}
+)
+
+target_link_libraries(polkit-agent-example
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTGUI_LIBRARY}
+ polkit-qt-agent-1
+ polkit-qt-core-1
+)
diff --git a/examples/agent/klistener.cpp b/examples/agent/klistener.cpp
new file mode 100644
index 000000000..32bfb981a
--- /dev/null
+++ b/examples/agent/klistener.cpp
@@ -0,0 +1,100 @@
+/*
+ * This file is part of the Polkit-qt project
+ * Copyright (C) 2009 Jaroslav Reznik <[email protected]>
+ *
+ * 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 <QtCore/QDebug>
+#include <QInputDialog>
+
+#include "klistener.h"
+#include "agent/polkitqt1-agent-session.h"
+
+using namespace PolkitQt1::Agent;
+
+KListener::KListener(QObject *parent)
+ : Listener(parent)
+{
+ qDebug() << "Registering KDE listener";
+}
+
+// README: this is just testing code...
+
+void KListener::initiateAuthentication(const QString &actionId,
+ const QString &message,
+ const QString &iconName,
+ const PolkitQt1::Details &details,
+ const QString &cookie,
+ const PolkitQt1::Identity::List &identities,
+ AsyncResult *result)
+{
+ qDebug() << "initiateAuthentication for " << actionId << " with message " << message;
+ qDebug() << "iconName " << iconName;
+ qDebug() << details.keys();
+ qDebug() << "cookie" << cookie;
+
+ Q_FOREACH (const PolkitQt1::Identity &identity, identities) {
+ qDebug() << identity.toString();
+ Session *session;
+ session = new Session(identity, cookie, result);
+ connect(session, SIGNAL(request(QString, bool)), this, SLOT(request(QString, bool)));
+ connect(session, SIGNAL(completed(bool)), this, SLOT(completed(bool)));
+ connect(session, SIGNAL(showError(QString)), this, SLOT(showError(QString)));
+ connect(session, SIGNAL(showInfo(QString)), this, SLOT(showInfo(QString)));
+ session->initiate();
+ }
+}
+
+bool KListener::initiateAuthenticationFinish()
+{
+ qDebug() << "initiateAuthenticationFinish()";
+ return true;
+}
+
+void KListener::cancelAuthentication()
+{
+ qDebug() << "Cancelling authentication";
+}
+
+void KListener::request(const QString &request, bool echo)
+{
+ qDebug() << "Request: " << request;
+
+ Session *session = (Session *)sender();
+
+ session->setResponse("");
+}
+
+void KListener::completed(bool gainedAuthorization)
+{
+ qDebug() << "Completed: " << gainedAuthorization;
+ Session *session = (Session *)sender();
+
+ session->result()->setCompleted();
+
+ delete session;
+}
+
+void KListener::showError(const QString &text)
+{
+ qDebug() << "Error: " << text;
+}
+
+void KListener::showInfo(const QString &text)
+{
+ qDebug() << "Info: " << text;
+}
diff --git a/examples/agent/klistener.h b/examples/agent/klistener.h
new file mode 100644
index 000000000..2576acdca
--- /dev/null
+++ b/examples/agent/klistener.h
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the Polkit-qt project
+ * Copyright (C) 2009 Jaroslav Reznik <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef POLKIT_QT_AGENT_KDE_LISTENER_H
+#define POLKIT_QT_AGENT_KDE_LISTENER_H
+
+#include <QtCore/QObject>
+#include <QtCore/QString>
+
+#include "agent/polkitqt1-agent-listener.h"
+#include "core/polkitqt1-identity.h"
+#include "core/polkitqt1-details.h"
+#include "agent/polkitqt1-agent-session.h"
+
+class KListener : public PolkitQt1::Agent::Listener
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(KListener)
+public:
+ KListener(QObject *parent = 0);
+ ~KListener() {};
+public Q_SLOTS:
+ void initiateAuthentication(const QString &actionId,
+ const QString &message,
+ const QString &iconName,
+ const PolkitQt1::Details &details,
+ const QString &cookie,
+ const PolkitQt1::Identity::List &identities,
+ PolkitQt1::Agent::AsyncResult *result);
+ bool initiateAuthenticationFinish();
+ void cancelAuthentication();
+
+ void request(const QString &request, bool echo);
+ void completed(bool gainedAuthorization);
+ void showError(const QString &text);
+ void showInfo(const QString &text);
+};
+
+#endif
diff --git a/examples/agent/main.cpp b/examples/agent/main.cpp
new file mode 100644
index 000000000..682b04747
--- /dev/null
+++ b/examples/agent/main.cpp
@@ -0,0 +1,30 @@
+/***************************************************************************
+ * Copyright (C) 2009 Jaroslav Reznik *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
+ ***************************************************************************/
+
+#include <QApplication>
+
+#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();
+}
diff --git a/examples/agent/pkagentexample.cpp b/examples/agent/pkagentexample.cpp
new file mode 100644
index 000000000..ed36363ba
--- /dev/null
+++ b/examples/agent/pkagentexample.cpp
@@ -0,0 +1,17 @@
+#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
+
+#include <polkitagent/polkitagent.h>
+#include "pkagentexample.h"
+#include <glib-object.h>
+#include <QtCore/QDebug>
+#include "polkitqt1-subject.h"
+
+PkAgentExample::PkAgentExample(int &argc, char **argv)
+ : QCoreApplication(argc, argv)
+{
+ g_type_init();
+
+ PolkitQt1::UnixSessionSubject session(getpid());
+
+ m_listener.registerListener(session, "/org/kde/PolicyKit1/AuthenticationAgent");
+}
diff --git a/examples/agent/pkagentexample.h b/examples/agent/pkagentexample.h
new file mode 100644
index 000000000..62c7035a5
--- /dev/null
+++ b/examples/agent/pkagentexample.h
@@ -0,0 +1,42 @@
+// This is an example not a library
+/***************************************************************************
+ * Copyright (C) 2008 Daniel Nicoletti <[email protected]> *
+ * Copyright (C) 2009 Radek Novacek <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
+ ***************************************************************************/
+
+#ifndef PKAGENTEXAMPLE_H
+#define PKAGENTEXAMPLE_H
+
+#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
+
+#include <QtDBus/QDBusContext>
+#include <QCoreApplication>
+#include "klistener.h"
+
+class PkAgentExample : public QCoreApplication
+{
+ Q_OBJECT
+public:
+ PkAgentExample(int &argc, char **argv);
+ ~PkAgentExample() {};
+private:
+ KListener m_listener;
+};
+
+
+#endif