Conversion of 'agent' library module.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>pull/1/head
parent
98b37ff3b1
commit
a8e9f8dd80
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Daniel Nicoletti <dantti85-pk@yahoo.com.br>
|
||||
* Copyright (C) 2009 Dario Freddi <drf@kde.org>
|
||||
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@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 "dummy-agent.h"
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
|
||||
DummyAgent* DummyAgent::instance()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "dummy-agent.moc"
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Daniel Nicoletti <dantti85-pk@yahoo.com.br>
|
||||
* Copyright (C) 2009 Dario Freddi <drf@kde.org>
|
||||
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@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.
|
||||
*/
|
||||
|
||||
#ifndef DUMMY_AGENT_H
|
||||
#define DUMMY_AGENT_H
|
||||
|
||||
#define POLKIT_TQT_EXPORT TQ_EXPORT
|
||||
|
||||
|
||||
/**
|
||||
* \namespace PolkitTQt PolkitTQt
|
||||
*
|
||||
* \brief Namespace wrapping Polkit-TQt classes
|
||||
*
|
||||
* This namespace wraps all Polkit-TQt classes.
|
||||
*/
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
/**
|
||||
* \class DummyAgent
|
||||
*
|
||||
* \brief Convenience class for TQt/KDE applications
|
||||
*
|
||||
* This class is a dummy used for initial basic compiling.
|
||||
*/
|
||||
class POLKIT_TQT_EXPORT DummyAgent
|
||||
{
|
||||
public:
|
||||
|
||||
static DummyAgent* instance();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 "polkit-tqt-listener.h"
|
||||
#include "polkit-tqt-agent-listener.h"
|
||||
|
||||
#include "polkit-tqt-authority.h"
|
||||
#include "polkit-tqt-subject.h"
|
||||
#include "polkit-tqt-identity.h"
|
||||
#include "polkit-tqt-details.h"
|
||||
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
namespace Agent
|
||||
{
|
||||
|
||||
class ListenerPrivate
|
||||
{
|
||||
public:
|
||||
PolkitAgentListener *listener;
|
||||
void *registeredHandle;
|
||||
};
|
||||
|
||||
Listener::Listener(TQObject *parent) : TQObject(parent), d(new ListenerPrivate)
|
||||
{
|
||||
d->listener = polkit_tqt_listener_new();
|
||||
|
||||
tqDebug("New PolkitAgentListener %p", d->listener);
|
||||
|
||||
ListenerAdapter::instance()->addListener(this);
|
||||
}
|
||||
|
||||
Listener::Listener(PolkitAgentListener *listener, TQObject *parent)
|
||||
: TQObject(parent), d(new ListenerPrivate)
|
||||
{
|
||||
d->listener = listener;
|
||||
}
|
||||
|
||||
Listener::~Listener()
|
||||
{
|
||||
tqDebug("Destroying listener");
|
||||
|
||||
ListenerAdapter::instance()->removeListener(this);
|
||||
if (d->registeredHandle)
|
||||
{
|
||||
polkit_agent_listener_unregister(d->registeredHandle);
|
||||
}
|
||||
if (d->listener != NULL)
|
||||
{
|
||||
g_object_unref(d->listener);
|
||||
}
|
||||
}
|
||||
|
||||
bool Listener::registerListener(const PolkitTQt::Subject &subject, const TQString &objectPath)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
d->registeredHandle = polkit_agent_listener_register(d->listener,
|
||||
POLKIT_AGENT_REGISTER_FLAGS_NONE, subject.subject(), objectPath.ascii(), NULL, &error);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
tqWarning(TQString("Cannot register authentication agent: %1").arg(error->message));
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (d->registeredHandle == NULL)
|
||||
{
|
||||
tqWarning(TQString("Cannot register authentication agent!"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const PolkitAgentListener *Listener::listener()
|
||||
{
|
||||
return d->listener;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "polkit-tqt-agent-listener.moc"
|
||||
|
@ -0,0 +1,189 @@
|
||||
/*
|
||||
* This file is part of the PolKit-tqt project
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@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.
|
||||
*/
|
||||
|
||||
#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
|
||||
#include <polkitagent/polkitagent.h>
|
||||
|
||||
#include "polkit-tqt-identity.h"
|
||||
#include "polkit-tqt-agent-session.h"
|
||||
|
||||
#include <tqstring.h>
|
||||
|
||||
|
||||
using namespace PolkitTQt;
|
||||
using namespace PolkitTQt::Agent;
|
||||
|
||||
//--------------------------------------
|
||||
// Session::Private
|
||||
//--------------------------------------
|
||||
|
||||
class Session::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
{
|
||||
}
|
||||
|
||||
~Private()
|
||||
{
|
||||
// polkitAgentSession is freed in Session d'tor
|
||||
}
|
||||
|
||||
static void completed(PolkitAgentSession *s, gboolean gained_authorization, gpointer user_data);
|
||||
static void request(PolkitAgentSession *s, gchar *request, gboolean echo_on, gpointer user_data);
|
||||
static void showError(PolkitAgentSession *s, gchar *text, gpointer user_data);
|
||||
static void showInfo(PolkitAgentSession *s, gchar *text, gpointer user_data);
|
||||
|
||||
AsyncResult *result;
|
||||
PolkitAgentSession *polkitAgentSession;
|
||||
};
|
||||
|
||||
void Session::Private::completed(PolkitAgentSession *s, gboolean gained_authorization,
|
||||
gpointer user_data)
|
||||
{
|
||||
Session *session = (Session *)user_data;
|
||||
emit(session)->completed(gained_authorization);
|
||||
|
||||
//free session here as polkit documentation asks
|
||||
g_object_unref(session->d->polkitAgentSession);
|
||||
session->d->polkitAgentSession = 0;
|
||||
}
|
||||
|
||||
void Session::Private::request(PolkitAgentSession *s, gchar *request, gboolean echo_on,
|
||||
gpointer user_data)
|
||||
{
|
||||
emit((Session*)user_data)->request(TQString::fromUtf8(request), echo_on);
|
||||
}
|
||||
|
||||
void Session::Private::showError(PolkitAgentSession *s, gchar *text, gpointer user_data)
|
||||
{
|
||||
emit((Session*)user_data)->showError(TQString::fromUtf8(text));
|
||||
}
|
||||
|
||||
void Session::Private::showInfo(PolkitAgentSession *s, gchar *text, gpointer user_data)
|
||||
{
|
||||
emit((Session*)user_data)->showInfo(TQString::fromUtf8(text));
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Session
|
||||
//--------------------------------------
|
||||
|
||||
Session::Session(const Identity &identity, const TQString &cookie, AsyncResult *result,
|
||||
TQObject *parent) : TQObject(parent), d(new Private)
|
||||
{
|
||||
d->result = result;
|
||||
d->polkitAgentSession = polkit_agent_session_new(identity.identity(), cookie.utf8().data());
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "completed", G_CALLBACK(Private::completed), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "request", G_CALLBACK(Private::request), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "show-error", G_CALLBACK(Private::showError), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "show-info", G_CALLBACK(Private::showInfo), this);
|
||||
}
|
||||
|
||||
Session::Session(PolkitAgentSession *pkAgentSession, TQObject *parent)
|
||||
: TQObject(parent), d(new Private)
|
||||
{
|
||||
d->polkitAgentSession = pkAgentSession;
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "completed", G_CALLBACK(Private::completed), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "request", G_CALLBACK(Private::request), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "show-error", G_CALLBACK(Private::showError), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "show-info", G_CALLBACK(Private::showInfo), this);
|
||||
}
|
||||
|
||||
Session::~Session()
|
||||
{
|
||||
if (d->polkitAgentSession)
|
||||
{
|
||||
g_object_unref(d->polkitAgentSession);
|
||||
}
|
||||
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Session::initiate()
|
||||
{
|
||||
polkit_agent_session_initiate(d->polkitAgentSession);
|
||||
}
|
||||
|
||||
void Session::setResponse(const TQString &response)
|
||||
{
|
||||
polkit_agent_session_response(d->polkitAgentSession, response.utf8().data());
|
||||
}
|
||||
|
||||
void Session::cancel()
|
||||
{
|
||||
polkit_agent_session_cancel(d->polkitAgentSession);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// AsyncResult::Private
|
||||
//--------------------------------------
|
||||
|
||||
class AsyncResult::Private
|
||||
{
|
||||
public:
|
||||
Private(GSimpleAsyncResult *r) : result(r)
|
||||
{
|
||||
}
|
||||
|
||||
GSimpleAsyncResult *result;
|
||||
};
|
||||
|
||||
AsyncResult* Session::result()
|
||||
{
|
||||
return d->result;
|
||||
}
|
||||
|
||||
AsyncResult::AsyncResult(GSimpleAsyncResult *result) : d(new Private(result))
|
||||
{
|
||||
}
|
||||
|
||||
AsyncResult::~AsyncResult()
|
||||
{
|
||||
if (d->result)
|
||||
{
|
||||
g_object_unref(d->result);
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncResult::setCompleted()
|
||||
{
|
||||
if (d->result == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_simple_async_result_complete(d->result);
|
||||
// Assure that completed won't be called twice
|
||||
g_object_unref(d->result);
|
||||
d->result = NULL;
|
||||
}
|
||||
|
||||
void AsyncResult::setError(const TQString &text)
|
||||
{
|
||||
if (d->result == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_simple_async_result_set_error(d->result, POLKIT_ERROR, POLKIT_ERROR_FAILED, "%s",
|
||||
text.utf8().data());
|
||||
}
|
||||
|
||||
#include "polkit-tqt-agent-session.moc"
|
||||
|
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* polkit-tqt-listener based on code by David Zeuthen <davidz@redhat.com>
|
||||
*/
|
||||
|
||||
#include "polkit-tqt-listener.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
using namespace PolkitTQt::Agent;
|
||||
|
||||
struct _PolkitTQtListener
|
||||
{
|
||||
PolkitAgentListener parent_instance;
|
||||
};
|
||||
|
||||
struct _PolkitTQtListenerClass
|
||||
{
|
||||
PolkitAgentListenerClass parent_class;
|
||||
};
|
||||
|
||||
static void polkit_tqt_listener_initiate_authentication(PolkitAgentListener *agent_listener,
|
||||
const gchar *action_id, const gchar *message, const gchar *icon_name,
|
||||
PolkitDetails *details, const gchar *cookie, GList *identities,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
|
||||
|
||||
static gboolean polkit_tqt_listener_initiate_authentication_finish(PolkitAgentListener *listener,
|
||||
GAsyncResult *res, GError **error);
|
||||
|
||||
G_DEFINE_TYPE(PolkitTQtListener, polkit_tqt_listener, POLKIT_AGENT_TYPE_LISTENER);
|
||||
|
||||
static void polkit_tqt_listener_init(PolkitTQtListener *listener)
|
||||
{
|
||||
}
|
||||
|
||||
static void polkit_tqt_listener_finalize(GObject *object)
|
||||
{
|
||||
PolkitTQtListener *listener = POLKIT_TQT_LISTENER(object);
|
||||
if (G_OBJECT_CLASS(polkit_tqt_listener_parent_class)->finalize != NULL)
|
||||
{
|
||||
G_OBJECT_CLASS(polkit_tqt_listener_parent_class)->finalize(object);
|
||||
}
|
||||
}
|
||||
|
||||
static void polkit_tqt_listener_class_init(PolkitTQtListenerClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||
PolkitAgentListenerClass *listener_class = POLKIT_AGENT_LISTENER_CLASS(klass);
|
||||
|
||||
gobject_class->finalize = polkit_tqt_listener_finalize;
|
||||
|
||||
listener_class->initiate_authentication = polkit_tqt_listener_initiate_authentication;
|
||||
listener_class->initiate_authentication_finish = polkit_tqt_listener_initiate_authentication_finish;
|
||||
}
|
||||
|
||||
PolkitAgentListener *polkit_tqt_listener_new(void)
|
||||
{
|
||||
return POLKIT_AGENT_LISTENER(g_object_new(POLKIT_TQT_TYPE_LISTENER, NULL));
|
||||
}
|
||||
|
||||
static void cancelled_cb(GCancellable *cancellable, gpointer user_data)
|
||||
{
|
||||
ListenerAdapter::instance()->cancelled_cb((PolkitAgentListener *)user_data);
|
||||
}
|
||||
|
||||
static void polkit_tqt_listener_initiate_authentication(PolkitAgentListener *agent_listener,
|
||||
const gchar *action_id, const gchar *message, const gchar *icon_name,
|
||||
PolkitDetails *details, const gchar *cookie, GList *identities,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
tqDebug("Listener adapter polkit_tqt_listener_initiate_authentication");
|
||||
PolkitTQtListener *listener = POLKIT_TQT_LISTENER(agent_listener);
|
||||
|
||||
// The result of asynchronous method will be created here and it will be pushed to the listener.
|
||||
GSimpleAsyncResult *result = g_simple_async_result_new((GObject*)listener, callback, user_data,
|
||||
agent_listener);
|
||||
tqDebug("GSimpleAsyncResult: %p", result);
|
||||
|
||||
ListenerAdapter::instance()->polkit_tqt_listener_initiate_authentication(agent_listener,
|
||||
action_id, message, icon_name, details, cookie, identities, cancellable, result);
|
||||
if (cancellable != NULL)
|
||||
{
|
||||
g_signal_connect(cancellable, "cancelled", G_CALLBACK(cancelled_cb), agent_listener);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean polkit_tqt_listener_initiate_authentication_finish(PolkitAgentListener *listener,
|
||||
GAsyncResult *res, GError **error)
|
||||
{
|
||||
tqDebug("Listener adapter polkit_tqt_listener_initiate_authentication_finish");
|
||||
return ListenerAdapter::instance()->polkit_tqt_listener_initiate_authentication_finish(listener,
|
||||
res, error);
|
||||
}
|
||||
|
@ -1,124 +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 "polkittqt1-agent-listener.h"
|
||||
|
||||
#include <TQtCore/TQDebug>
|
||||
|
||||
#include "polkittqtlistener_p.h"
|
||||
|
||||
#include "polkittqt1-authority.h"
|
||||
#include "polkittqt1-subject.h"
|
||||
#include "polkittqt1-identity.h"
|
||||
#include "polkittqt1-details.h"
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
namespace Agent
|
||||
{
|
||||
|
||||
class ListenerPrivate
|
||||
{
|
||||
public:
|
||||
PolkitAgentListener *listener;
|
||||
#ifndef POLKIT_TQT_1_COMPATIBILITY_MODE
|
||||
void *registeredHandle;
|
||||
#endif
|
||||
};
|
||||
|
||||
Listener::Listener(TQObject *parent)
|
||||
: TQObject(parent), d(new ListenerPrivate)
|
||||
{
|
||||
g_type_init();
|
||||
|
||||
d->listener = polkit_tqt_listener_new();
|
||||
|
||||
tqDebug() << "New PolkitAgentListener " << d->listener;
|
||||
|
||||
ListenerAdapter::instance()->addListener(this);
|
||||
}
|
||||
|
||||
Listener::Listener(PolkitAgentListener *listener, TQObject *parent)
|
||||
: TQObject(parent), d(new ListenerPrivate)
|
||||
{
|
||||
g_type_init();
|
||||
|
||||
d->listener = listener;
|
||||
}
|
||||
|
||||
Listener::~Listener()
|
||||
{
|
||||
tqDebug("Destroying listener");
|
||||
|
||||
ListenerAdapter::instance()->removeListener(this);
|
||||
#ifndef POLKIT_TQT_1_COMPATIBILITY_MODE
|
||||
if (d->registeredHandle) {
|
||||
polkit_agent_listener_unregister(d->registeredHandle);
|
||||
}
|
||||
#endif
|
||||
if (d->listener != NULL) {
|
||||
g_object_unref(d->listener);
|
||||
}
|
||||
}
|
||||
|
||||
bool Listener::registerListener(const PolkitTQt::Subject &subject, const TQString &objectPath)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
#ifndef POLKIT_TQT_1_COMPATIBILITY_MODE
|
||||
d->registeredHandle = polkit_agent_listener_register(d->listener,
|
||||
POLKIT_AGENT_REGISTER_FLAGS_NONE,
|
||||
#else
|
||||
bool r = polkit_agent_register_listener(d->listener,
|
||||
#endif
|
||||
subject.subject(),
|
||||
objectPath.toAscii().data(),
|
||||
#ifndef POLKIT_TQT_1_COMPATIBILITY_MODE
|
||||
NULL,
|
||||
#endif
|
||||
&error);
|
||||
|
||||
if (error != NULL) {
|
||||
tqWarning() << TQString("Cannot register authentication agent: %1").arg(error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
#ifndef POLKIT_TQT_1_COMPATIBILITY_MODE
|
||||
if (d->registeredHandle == NULL) {
|
||||
tqWarning() << TQString("Cannot register authentication agent!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
const PolkitAgentListener *Listener::listener()
|
||||
{
|
||||
return d->listener;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "polkittqt1-agent-listener.moc"
|
@ -1,169 +0,0 @@
|
||||
/*
|
||||
* This file is part of the PolKit1-tqt project
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@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 "polkittqt1-agent-session.h"
|
||||
|
||||
#include <TQtCore/TQDebug>
|
||||
|
||||
#include "polkittqt1-identity.h"
|
||||
|
||||
#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
|
||||
#include <polkitagent/polkitagent.h>
|
||||
|
||||
using namespace PolkitTQt::Agent;
|
||||
|
||||
class Session::Private
|
||||
{
|
||||
public:
|
||||
Private() {}
|
||||
~Private();
|
||||
|
||||
static void completed(PolkitAgentSession *s, gboolean gained_authorization, gpointer user_data);
|
||||
static void request(PolkitAgentSession *s, gchar *request, gboolean echo_on, gpointer user_data);
|
||||
static void showError(PolkitAgentSession *s, gchar *text, gpointer user_data);
|
||||
static void showInfo(PolkitAgentSession *s, gchar *text, gpointer user_data);
|
||||
|
||||
AsyncResult *result;
|
||||
PolkitAgentSession *polkitAgentSession;
|
||||
};
|
||||
|
||||
Session::Private::~Private()
|
||||
{
|
||||
// polkitAgentSession is freed in Session d'tor
|
||||
}
|
||||
|
||||
Session::Session(const PolkitTQt::Identity &identity, const TQString &cookie, AsyncResult *result, TQObject *parent)
|
||||
: TQObject(parent)
|
||||
, d(new Private)
|
||||
{
|
||||
d->result = result;
|
||||
d->polkitAgentSession = polkit_agent_session_new(identity.identity(), cookie.toUtf8().data());
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "completed", G_CALLBACK(Private::completed), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "request", G_CALLBACK(Private::request), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "show-error", G_CALLBACK(Private::showError), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "show-info", G_CALLBACK(Private::showInfo), this);
|
||||
}
|
||||
|
||||
Session::Session(PolkitAgentSession *pkAgentSession, TQObject *parent)
|
||||
: TQObject(parent)
|
||||
, d(new Private)
|
||||
{
|
||||
d->polkitAgentSession = pkAgentSession;
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "completed", G_CALLBACK(Private::completed), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "request", G_CALLBACK(Private::request), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "show-error", G_CALLBACK(Private::showError), this);
|
||||
g_signal_connect(G_OBJECT(d->polkitAgentSession), "show-info", G_CALLBACK(Private::showInfo), this);
|
||||
}
|
||||
|
||||
Session::~Session()
|
||||
{
|
||||
if (d->polkitAgentSession)
|
||||
g_object_unref(d->polkitAgentSession);
|
||||
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Session::initiate()
|
||||
{
|
||||
polkit_agent_session_initiate(d->polkitAgentSession);
|
||||
}
|
||||
|
||||
void Session::setResponse(const TQString &response)
|
||||
{
|
||||
polkit_agent_session_response(d->polkitAgentSession, response.toUtf8().data());
|
||||
}
|
||||
|
||||
void Session::cancel()
|
||||
{
|
||||
polkit_agent_session_cancel(d->polkitAgentSession);
|
||||
}
|
||||
|
||||
AsyncResult *Session::result()
|
||||
{
|
||||
return d->result;
|
||||
}
|
||||
|
||||
void Session::Private::completed(PolkitAgentSession *s, gboolean gained_authorization, gpointer user_data)
|
||||
{
|
||||
tqDebug() << "COMPLETED";
|
||||
Session *session = (Session *)user_data;
|
||||
TQ_EMIT(session)->completed(gained_authorization);
|
||||
|
||||
//free session here as polkit documentation asks
|
||||
g_object_unref(session->d->polkitAgentSession);
|
||||
session->d->polkitAgentSession = 0;
|
||||
}
|
||||
|
||||
void Session::Private::request(PolkitAgentSession *s, gchar *request, gboolean echo_on, gpointer user_data)
|
||||
{
|
||||
tqDebug() << "REQUEST";
|
||||
TQ_EMIT((Session *)user_data)->request(TQString::fromUtf8(request), echo_on);
|
||||
}
|
||||
|
||||
void Session::Private::showError(PolkitAgentSession *s, gchar *text, gpointer user_data)
|
||||
{
|
||||
tqDebug() << "showError";
|
||||
TQ_EMIT((Session *)user_data)->showError(TQString::fromUtf8(text));
|
||||
}
|
||||
|
||||
void Session::Private::showInfo(PolkitAgentSession *s, gchar *text, gpointer user_data)
|
||||
{
|
||||
tqDebug() << "showInfo";
|
||||
TQ_EMIT((Session *)user_data)->showInfo(TQString::fromUtf8(text));
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
class AsyncResult::Private
|
||||
{
|
||||
public:
|
||||
Private(GSimpleAsyncResult *r) : result(r) {};
|
||||
|
||||
GSimpleAsyncResult *result;
|
||||
};
|
||||
|
||||
AsyncResult::AsyncResult(GSimpleAsyncResult *result)
|
||||
: d(new Private(result))
|
||||
{
|
||||
}
|
||||
|
||||
AsyncResult::~AsyncResult()
|
||||
{
|
||||
if (d->result)
|
||||
g_object_unref(d->result);
|
||||
}
|
||||
|
||||
void AsyncResult::setCompleted()
|
||||
{
|
||||
if (d->result == NULL)
|
||||
return;
|
||||
g_simple_async_result_complete(d->result);
|
||||
// Assure that completed won't be called twice
|
||||
g_object_unref(d->result);
|
||||
d->result = NULL;
|
||||
}
|
||||
|
||||
void AsyncResult::setError(const TQString &text)
|
||||
{
|
||||
Q_ASSERT(d->result);
|
||||
g_simple_async_result_set_error(d->result, POLKIT_ERROR, POLKIT_ERROR_FAILED, "%s", text.toUtf8().data());
|
||||
}
|
||||
|
||||
#include "polkittqt1-agent-session.moc"
|
@ -1,150 +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.
|
||||
*
|
||||
* polkit-tqt-listener based on code by David Zeuthen <davidz@redhat.com>
|
||||
*/
|
||||
|
||||
|
||||
#include "polkittqtlistener_p.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include <TQtCore/TQDebug>
|
||||
|
||||
#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1
|
||||
|
||||
using namespace PolkitTQt::Agent;
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
struct _PolkitTQtListener {
|
||||
PolkitAgentListener parent_instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
struct _PolkitTQtListenerClass {
|
||||
PolkitAgentListenerClass parent_class;
|
||||
};
|
||||
|
||||
static void polkit_tqt_listener_initiate_authentication(PolkitAgentListener *listener,
|
||||
const gchar *action_id,
|
||||
const gchar *message,
|
||||
const gchar *icon_name,
|
||||
PolkitDetails *details,
|
||||
const gchar *cookie,
|
||||
GList *identities,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
static gboolean polkit_tqt_listener_initiate_authentication_finish(PolkitAgentListener *listener,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
G_DEFINE_TYPE(PolkitTQtListener, polkit_tqt_listener, POLKIT_AGENT_TYPE_LISTENER);
|
||||
|
||||
static void polkit_tqt_listener_init(PolkitTQtListener *listener)
|
||||
{
|
||||
g_type_init();
|
||||
}
|
||||
|
||||
static void polkit_tqt_listener_finalize(GObject *object)
|
||||
{
|
||||
PolkitTQtListener *listener;
|
||||
|
||||
listener = POLKIT_TQT_LISTENER(object);
|
||||
|
||||
if (G_OBJECT_CLASS(polkit_tqt_listener_parent_class)->finalize != NULL) {
|
||||
G_OBJECT_CLASS(polkit_tqt_listener_parent_class)->finalize(object);
|
||||
}
|
||||
}
|
||||
|
||||
static void polkit_tqt_listener_class_init(PolkitTQtListenerClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
PolkitAgentListenerClass *listener_class;
|
||||
|
||||
gobject_class = G_OBJECT_CLASS(klass);
|
||||
listener_class = POLKIT_AGENT_LISTENER_CLASS(klass);
|
||||
|
||||
gobject_class->finalize = polkit_tqt_listener_finalize;
|
||||
|
||||
listener_class->initiate_authentication = polkit_tqt_listener_initiate_authentication;
|
||||
listener_class->initiate_authentication_finish = polkit_tqt_listener_initiate_authentication_finish;
|
||||
}
|
||||
|
||||
PolkitAgentListener *polkit_tqt_listener_new(void)
|
||||
{
|
||||
return POLKIT_AGENT_LISTENER(g_object_new(POLKIT_TQT_TYPE_LISTENER, NULL));
|
||||
}
|
||||
|
||||
static void cancelled_cb(GCancellable *cancellable, gpointer user_data)
|
||||
{
|
||||
ListenerAdapter::instance()->cancelled_cb((PolkitAgentListener *)user_data);
|
||||
}
|
||||
|
||||
static void polkit_tqt_listener_initiate_authentication(PolkitAgentListener *agent_listener,
|
||||
const gchar *action_id,
|
||||
const gchar *message,
|
||||
const gchar *icon_name,
|
||||
PolkitDetails *details,
|
||||
const gchar *cookie,
|
||||
GList *identities,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
tqDebug() << "Listener adapter polkit_tqt_listener_initiate_authentication";
|
||||
PolkitTQtListener *listener = POLKIT_TQT_LISTENER(agent_listener);
|
||||
|
||||
// The result of asynchronous method will be created here and it will be pushed to the listener.
|
||||
GSimpleAsyncResult *result = g_simple_async_result_new((GObject *) listener, callback, user_data, agent_listener);
|
||||
tqDebug() << "GSimpleAsyncResult:" << result;
|
||||
|
||||
ListenerAdapter::instance()->polkit_tqt_listener_initiate_authentication(agent_listener,
|
||||
action_id,
|
||||
message,
|
||||
icon_name,
|
||||
details,
|
||||
cookie,
|
||||
identities,
|
||||
cancellable,
|
||||
result);
|
||||
|
||||
if (cancellable != NULL) {
|
||||
g_signal_connect(cancellable,
|
||||
"cancelled",
|
||||
G_CALLBACK(cancelled_cb),
|
||||
agent_listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static gboolean polkit_tqt_listener_initiate_authentication_finish(PolkitAgentListener *listener,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
tqDebug() << "Listener adapter polkit_tqt_listener_initiate_authentication_finish";
|
||||
return ListenerAdapter::instance()->polkit_tqt_listener_initiate_authentication_finish(listener,
|
||||
res,
|
||||
error);
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
#include "../../polkittqt1-agent-listener.h"
|
||||
#include "../../polkit-tqt-agent-listener.h"
|
||||
|
@ -1 +1 @@
|
||||
#include "../../polkittqt1-agent-session.h"
|
||||
#include "../../polkit-tqt-agent-session.h"
|
||||
|
Loading…
Reference in New Issue