Completed conversion of 'core' library module.

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

@ -90,22 +90,33 @@ add_subdirectory(agent)
install(
FILES
## includes/PolkitTQt/Authority
## includes/PolkitTQt/Details
## includes/PolkitTQt/Identity
includes/PolkitTQt/Authority
includes/PolkitTQt/Details
includes/PolkitTQt/Identity
includes/PolkitTQt/Subject
## includes/PolkitTQt/TemporaryAuthorization
## includes/PolkitTQt/ActionDescription
includes/PolkitTQt/TemporaryAuthorization
includes/PolkitTQt/ActionDescription
DESTINATION
${INCLUDE_INSTALL_DIR}/PolkitTQt )
install(
FILES
polkit-tqt-export.h
## gui/polkittqt1-gui-action.h
## gui/polkittqt1-gui-actionbutton.h
## gui/polkittqt1-gui-actionbuttons.h
##
## agent/polkittqt1-agent-listener.h
## agent/polkittqt1-agent-session.h
##
## ${CMAKE_CURRENT_BINARY_DIR}/polkittqt1-version.h
##
DESTINATION
${INCLUDE_INSTALL_DIR} )
## find_package(Qt4 REQUIRED)
## find_package(GObject REQUIRED)
## find_package(GIO REQUIRED)
##
## add_definitions(-DTQT_NO_KEYWORDS)
##
## include (${TQT_USE_FILE})
## include (InstallSettings)
## include (MacroWriteBasicCMakeVersionFile)
@ -123,17 +134,6 @@ install(
## ${TQT_TQTXML_INCLUDE_DIR}
## )
##
## # Check for older polkit
## set(CMAKE_REQUIRED_INCLUDES ${POLKIT_INCLUDE_DIR} ${POLKIT_AGENT_INCLUDE_DIR})
## set(CMAKE_REQUIRED_LIBRARIES ${POLKIT_LIBRARIES} ${POLKIT_AGENT_LIBRARY})
## check_function_exists(polkit_agent_listener_register HAVE_POLKIT_AGENT_LISTENER_REGISTER)
## check_function_exists(polkit_authority_get_sync HAVE_POLKIT_AUTHORITY_GET_SYNC)
##
## if (NOT HAVE_POLKIT_AGENT_LISTENER_REGISTER OR NOT HAVE_POLKIT_AUTHORITY_GET_SYNC)
## message(STATUS "You have an older polkit-1 version: Polkit-TQt-1 will be built in compatibility mode")
## add_definitions(-DPOLKIT_TQT_1_COMPATIBILITY_MODE)
## endif (NOT HAVE_POLKIT_AGENT_LISTENER_REGISTER OR NOT HAVE_POLKIT_AUTHORITY_GET_SYNC)
##
## if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} VERSION_GREATER 2.6.2)
## option(USE_COMMON_CMAKE_PACKAGE_CONFIG_DIR "Prefer to install the <package>Config.cmake files to lib/cmake/<package> instead of lib/<package>/cmake" TRUE)
## endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} VERSION_GREATER 2.6.2)
@ -150,13 +150,6 @@ install(
## gui/polkittqt1-gui-actionbutton.h
## gui/polkittqt1-gui-actionbuttons.h
##
## core/polkittqt1-authority.h
## core/polkittqt1-details.h
## core/polkittqt1-identity.h
## core/polkittqt1-subject.h
## core/polkittqt1-temporaryauthorization.h
## core/polkittqt1-actiondescription.h
##
## agent/polkittqt1-agent-listener.h
## agent/polkittqt1-agent-session.h
##
@ -179,20 +172,6 @@ install(
## DESTINATION
## ${INCLUDE_INSTALL_DIR}/polkit-qt-1/PolkitTQt1/Agent )
##
## if(NOT WIN32)
## # Pkgconfig
## configure_file(${CMAKE_CURRENT_SOURCE_DIR}/polkit-qt-1.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/polkit-qt-1.pc @ONLY)
## install(FILES ${CMAKE_CURRENT_BINARY_DIR}/polkit-qt-1.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
## configure_file(${CMAKE_CURRENT_SOURCE_DIR}/polkit-qt-core-1.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/polkit-qt-core-1.pc
## @ONLY)
## install(FILES ${CMAKE_CURRENT_BINARY_DIR}/polkit-qt-core-1.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
## configure_file(${CMAKE_CURRENT_SOURCE_DIR}/polkit-qt-gui-1.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/polkit-qt-gui-1.pc @ONLY)
## install(FILES ${CMAKE_CURRENT_BINARY_DIR}/polkit-qt-gui-1.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
## configure_file(${CMAKE_CURRENT_SOURCE_DIR}/polkit-qt-agent-1.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/polkit-qt-agent-1.pc
## @ONLY)
## install(FILES ${CMAKE_CURRENT_BINARY_DIR}/polkit-qt-agent-1.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
## endif(NOT WIN32)
##
## # CMake Config files
## configure_file(PolkitTQt-1Config.cmake.in "${CMAKE_BINARY_DIR}/PolkitTQt-1Config.cmake" @ONLY)
##
@ -221,7 +200,4 @@ install(
## if (BUILD_TEST)
## add_subdirectory(test)
## endif (BUILD_TEST)
##
##
## # Always last!
## include (PolkitTQt-1Dist)

@ -22,14 +22,14 @@ tde_setup_largefiles( )
# tqt
find_package( TQt )
# polkit
# check for polkit
pkg_search_module( POLKIT polkit-gobject-1 )
if( NOT POLKIT_FOUND )
tde_message_fatal( "polkit is required, but was not found on your system" )
endif( )
# gcc visibility
if( WITH_GCC_VISIBILITY )
tde_setup_gcc_visibility( )
endif( )

@ -25,7 +25,12 @@ link_directories(
##### install headers ###########################
install( FILES
polkit-tqt-actiondescription.h
polkit-tqt-authority.h
polkit-tqt-details.h
polkit-tqt-identity.h
polkit-tqt-subject.h
polkit-tqt-temporaryauthorization.h
DESTINATION ${INCLUDE_INSTALL_DIR} )
@ -33,31 +38,19 @@ install( FILES
tde_add_library( polkit-tqt-core SHARED AUTOMOC
SOURCES ${polkit_tqt_MOCS}
polkit-tqt-actiondescription.cpp
polkit-tqt-authority.cpp
polkit-tqt-details.cpp
polkit-tqt-identity.cpp
polkit-tqt-subject.cpp
polkit-tqt-temporaryauthorization.cpp
VERSION 0.0.0
LINK ${TQT_LIBRARIES} ${POLKIT_LIBRARIES}
DESTINATION ${LIB_INSTALL_DIR}
)
## set(polkit_tqt_core_SRCS
## polkittqt1-authority.cpp
## polkittqt1-identity.cpp
## polkittqt1-temporaryauthorization.cpp
## polkittqt1-details.cpp
## polkittqt1-actiondescription.cpp
## )
##
## target_link_libraries(polkit-tqt-core-1
## ${TQT_TQTDBUS_LIBRARY}
## ${TQT_TQTXML_LIBRARY}
## ${GLIB2_LIBRARIES}
## ${GOBJECT_LIBRARIES}
## ${GIO_LIBRARIES}
## )
##
## set_target_properties(polkit-tqt-core-1 PROPERTIES VERSION ${POLKITTQT-1_LIBRARY_VERSION}
## SOVERSION ${POLKITTQT-1_ABI_VERSION}
## DEFINE_SYMBOL MAKE_POLKITTQT1_LIB)
##
## install(TARGETS polkit-tqt-core-1 ${INSTALL_TARGETS_DEFAULT_ARGS})

@ -0,0 +1,165 @@
/*
* This file is part of the Polkit-tqt project
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
* Copyright (C) 2010 Dario Freddi <drf@kde.org>
*
* 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/polkit.h>
#include "polkit-tqt-actiondescription.h"
#include <tqshared.h>
#include <tqstring.h>
namespace PolkitTQt
{
//--------------------------------------
// ActionDescription::Data
//--------------------------------------
class ActionDescription::Data : public TQShared
{
public:
Data()
{
}
Data(const Data &other) : actionId(other.actionId), description(other.description),
message(other.message), vendorName(other.vendorName), vendorUrl(other.vendorUrl),
iconName(other.iconName), implicitAny(other.implicitAny),
implicitInactive(other.implicitInactive), implicitActive(other.implicitActive)
{
}
~Data()
{
}
TQString actionId;
TQString description;
TQString message;
TQString vendorName;
TQString vendorUrl;
TQString iconName;
ImplicitAuthorization implicitAny;
ImplicitAuthorization implicitInactive;
ImplicitAuthorization implicitActive;
};
//--------------------------------------
// ActionDescription
//--------------------------------------
ActionDescription::ActionDescription() : d(new Data)
{
}
ActionDescription::ActionDescription(PolkitActionDescription *pkActionDescription) : d(new Data)
{
d->actionId = TQString::fromUtf8(polkit_action_description_get_action_id(pkActionDescription));
d->description = TQString::fromUtf8(polkit_action_description_get_description(pkActionDescription));
d->message = TQString::fromUtf8(polkit_action_description_get_message(pkActionDescription));
d->vendorName = TQString::fromUtf8(polkit_action_description_get_vendor_name(pkActionDescription));
d->vendorUrl = TQString::fromUtf8(polkit_action_description_get_vendor_url(pkActionDescription));
d->iconName = TQString::fromUtf8(polkit_action_description_get_icon_name(pkActionDescription));
d->implicitAny = static_cast<ImplicitAuthorization>(
polkit_action_description_get_implicit_any(pkActionDescription));
d->implicitInactive = static_cast<ImplicitAuthorization>(
polkit_action_description_get_implicit_inactive(pkActionDescription));
d->implicitActive = static_cast<ImplicitAuthorization>(
polkit_action_description_get_implicit_active(pkActionDescription));
}
ActionDescription::ActionDescription(const ActionDescription &other) : d(other.d)
{
d->ref();
}
ActionDescription& ActionDescription::operator=(const ActionDescription &other)
{
if (d != other.d)
{
if (d->deref())
{
delete d;
}
d = other.d;
d->ref();
}
return *this;
}
ActionDescription::~ActionDescription()
{
if (d->deref())
{
delete d;
}
}
TQString ActionDescription::actionId() const
{
return d->actionId;
}
TQString ActionDescription::description() const
{
return d->description;
}
TQString ActionDescription::message() const
{
return d->message;
}
TQString ActionDescription::vendorName() const
{
return d->vendorName;
}
TQString ActionDescription::vendorUrl() const
{
return d->vendorUrl;
}
TQString ActionDescription::iconName() const
{
return d->iconName;
}
ActionDescription::ImplicitAuthorization ActionDescription::implicitAny() const
{
return d->implicitAny;
}
ActionDescription::ImplicitAuthorization ActionDescription::implicitInactive() const
{
return d->implicitInactive;
}
ActionDescription::ImplicitAuthorization ActionDescription::implicitActive() const
{
return d->implicitActive;
}
}

@ -19,21 +19,22 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef POLKITTQT1_ACTION_DESCRIPTION_H
#define POLKITTQT1_ACTION_DESCRIPTION_H
#ifndef POLKIT_TQT_ACTION_DESCRIPTION_H
#define POLKIT_TQT_ACTION_DESCRIPTION_H
#include "polkit-tqt-export.h"
#include <TQtCore/TQList>
#include <TQtCore/TQMetaType>
#include <TQtCore/TQSharedData>
typedef struct _PolkitActionDescription PolkitActionDescription;
class TQString;
template<typename> class TQValueList;
namespace PolkitTQt
{
/**
* \class ActionDescription polkittqt1-actiondescription.h ActionDescription
* \class ActionDescription polkit-tqt-actiondescription.h ActionDescription
* \author Jaroslav Reznik <jreznik@redhat.com>
* \author Dario Freddi <drf@kde.org>
*
@ -41,27 +42,31 @@ namespace PolkitTQt
*/
class POLKIT_TQT_EXPORT ActionDescription
{
public:
enum ImplicitAuthorization {
/** Unknown whether the subject is authorized, never returned in any public API. **/
Unknown = -1,
/** Subject is not authorized. **/
NotAuthorized = 0,
/** Authentication is required. **/
AuthenticationRequired = 1,
/** Authentication as an administrator is required. **/
AdministratorAuthenticationRequired = 2,
/** Authentication is required. If the authorization is obtained, it is retained. **/
AuthenticationRequiredRetained = 3,
/** Authentication as an administrator is required. If the authorization is obtained, it is retained. **/
AdministratorAuthenticationRequiredRetained = 4,
/** The subject is authorized. **/
Authorized = 5
public:
enum ImplicitAuthorization
{
/** Unknown whether the subject is authorized, never returned in any public API. **/
Unknown = -1,
/** Subject is not authorized. **/
NotAuthorized = 0,
/** Authentication is required. **/
AuthenticationRequired = 1,
/** Authentication as an administrator is required. **/
AdministratorAuthenticationRequired = 2,
/** Authentication is required. If the authorization is obtained, it is retained. **/
AuthenticationRequiredRetained = 3,
/** Authentication as an administrator is required. If the authorization is obtained, it is retained. **/
AdministratorAuthenticationRequiredRetained = 4,
/** The subject is authorized. **/
Authorized = 5
};
typedef TQList< ActionDescription > List;
typedef TQValueList<ActionDescription> List;
ActionDescription();
ActionDescription(const ActionDescription &other);
~ActionDescription();
/**
* \brief Constructor of ActionDescription object from PolkitActionDescription
*
@ -69,11 +74,9 @@ public:
*
* \param actionDesciption PolkitActionDescription
*/
explicit ActionDescription(PolkitActionDescription *actionDescription);
ActionDescription(const ActionDescription &other);
~ActionDescription();
explicit ActionDescription(PolkitActionDescription *pkActionDescription);
ActionDescription &operator=(const ActionDescription &other);
ActionDescription& operator=(const ActionDescription &other);
/**
* \brief Gets the action id for ActionDescription
@ -90,7 +93,7 @@ public:
TQString description() const;
/**
* \brief Gets the message user for ActionDescription
* \brief Gets the message used for ActionDescription
*
* \return action message
*/
@ -118,32 +121,35 @@ public:
TQString iconName() const;
/**
* \brief Gets the implicit authorization for ActionDescription used for any subject
* \brief Gets the implicit authorization for ActionDescription used
* for any subject
*
* \return A value from ImplicitAuthorization enumeration
*/
ActionDescription::ImplicitAuthorization implicitAny() const;
ImplicitAuthorization implicitAny() const;
/**
* \brief Gets the implicit authorization for ActionDescription used for subjects in inactive session on a local console
* \brief Gets the implicit authorization for ActionDescription used
* for subjects in inactive session on a local console
*
* \return A value from ImplicitAuthorization enumeration
*/
ActionDescription::ImplicitAuthorization implicitInactive() const;
ImplicitAuthorization implicitInactive() const;
/**
* \brief Gets the implicit authorization for ActionDescription used for subjects in active session on a local console
* \brief Gets the implicit authorization for ActionDescription used
* for subjects in active session on a local console
*
* \return A value from ImplicitAuthorization enumeration
*/
ActionDescription::ImplicitAuthorization implicitActive() const;
ImplicitAuthorization implicitActive() const;
private:
private:
class Data;
TQSharedDataPointer< Data > d;
Data *d;
};
}
TQ_DECLARE_METATYPE(PolkitTQt::ActionDescription::List)
#endif
#endif //POLKIT_TQT_ACTION_DESCRIPTION_H

@ -0,0 +1,816 @@
/*
* 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 <polkit/polkit.h>
#include "polkit-tqt-authority.h"
namespace PolkitTQt
{
//--------------------------------------
// General functions
//--------------------------------------
Authority *Authority::m_theAuthority = NULL;
Authority* Authority::instance(PolkitAuthority *authority)
{
if (!m_theAuthority)
{
m_theAuthority = new Authority();
}
return m_theAuthority;
}
Authority::Result polkitResultToResult(PolkitAuthorizationResult *result)
{
if (polkit_authorization_result_get_is_challenge(result))
{
return Authority::Challenge;
}
else if (polkit_authorization_result_get_is_authorized(result))
{
return Authority::Yes;
}
else
{
return Authority::No;
}
}
ActionDescription::List actionsToListAndFree(GList *glist)
{
ActionDescription::List result;
for (GList *glist2 = glist; glist2; glist2 = g_list_next(glist2))
{
gpointer i = glist2->data;
result.append(ActionDescription(static_cast<PolkitActionDescription*>(i)));
g_object_unref(i);
}
g_list_free(glist);
return result;
}
//--------------------------------------
// Authority::Private
//--------------------------------------
class Authority::Private
{
public:
Private(Authority *qq) : q(qq), pkAuthority(NULL), m_hasError(false)
{
}
~Private();
void init();
/** Use this method to set the error message to \p message. Set recover to \c true
* to try to reinitialize this object with init() method
*/
void setError(ErrorCode code, const TQString &details = TQString::null, bool recover = false);
Authority *q;
PolkitAuthority *pkAuthority;
bool m_hasError;
ErrorCode m_lastError;
TQString m_errorDetails;
GCancellable *m_checkAuthorizationCancellable;
GCancellable *m_enumerateActionsCancellable;
GCancellable *m_registerAuthenticationAgentCancellable;
GCancellable *m_unregisterAuthenticationAgentCancellable;
GCancellable *m_authenticationAgentResponseCancellable;
GCancellable *m_enumerateTemporaryAuthorizationsCancellable;
GCancellable *m_revokeTemporaryAuthorizationsCancellable;
GCancellable *m_revokeTemporaryAuthorizationCancellable;
static void pk_config_changed();
static void checkAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void enumerateActionsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void registerAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void unregisterAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void authenticationAgentResponseCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void enumerateTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void revokeTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void revokeTemporaryAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data);
};
Authority::Private::~Private()
{
g_object_unref(m_checkAuthorizationCancellable);
g_object_unref(m_enumerateActionsCancellable);
g_object_unref(m_registerAuthenticationAgentCancellable);
g_object_unref(m_unregisterAuthenticationAgentCancellable);
g_object_unref(m_authenticationAgentResponseCancellable);
g_object_unref(m_enumerateTemporaryAuthorizationsCancellable);
g_object_unref(m_revokeTemporaryAuthorizationsCancellable);
g_object_unref(m_revokeTemporaryAuthorizationCancellable);
}
void Authority::Private::init()
{
m_checkAuthorizationCancellable = g_cancellable_new();
m_enumerateActionsCancellable = g_cancellable_new();
m_registerAuthenticationAgentCancellable = g_cancellable_new();
m_unregisterAuthenticationAgentCancellable = g_cancellable_new();
m_authenticationAgentResponseCancellable = g_cancellable_new();
m_enumerateTemporaryAuthorizationsCancellable = g_cancellable_new();
m_revokeTemporaryAuthorizationsCancellable = g_cancellable_new();
m_revokeTemporaryAuthorizationCancellable = g_cancellable_new();
GError *gerror = NULL;
if (pkAuthority == NULL)
{
pkAuthority = polkit_authority_get_sync(NULL, &gerror);
if (gerror != NULL)
{
setError(E_GetAuthority, gerror->message);
g_error_free(gerror);
return;
}
}
if (pkAuthority == NULL)
{
return;
}
// connect changed signal
g_signal_connect(G_OBJECT(pkAuthority), "changed", G_CALLBACK(pk_config_changed), NULL);
}
void Authority::Private::setError(Authority::ErrorCode code, const TQString &details, bool recover)
{
if (recover)
{
init();
}
m_lastError = code;
m_errorDetails = details;
m_hasError = true;
}
//--------------------------------------
// Authority
//--------------------------------------
Authority::Authority(TQObject *parent) : TQObject(parent), d(new Private(this))
{
d->init();
}
Authority::~Authority()
{
g_object_unref(d->pkAuthority);
delete d;
}
bool Authority::hasError() const
{
return d->m_hasError;
}
Authority::ErrorCode Authority::lastError() const
{
return d->m_lastError;
}
const TQString Authority::errorDetails() const
{
if (d->m_lastError == E_None)
{
return TQString::null;
}
else
{
return d->m_errorDetails;
}
}
void Authority::clearError()
{
d->m_hasError = false;
d->m_lastError = E_None;
}
void Authority::Private::pk_config_changed()
{
emit Authority::instance()->configChanged();
}
PolkitAuthority* Authority::polkitAuthority() const
{
return d->pkAuthority;
}
Authority::Result Authority::checkAuthorizationSync(const TQString &actionId,
const Subject &subject, AuthorizationFlags flags)
{
if (Authority::instance()->hasError())
{
return Unknown;
}
if (!subject.isValid())
{
d->setError(E_WrongSubject);
return Unknown;
}
GError *error = NULL;
PolkitAuthorizationResult *pk_result = polkit_authority_check_authorization_sync(d->pkAuthority,
subject.subject(), actionId.ascii(), NULL, (PolkitCheckAuthorizationFlags)(int)flags,
NULL, &error);
if (error != NULL)
{
d->setError(E_CheckFailed, error->message);
g_error_free(error);
return Unknown;
}
if (!pk_result)
{
d->setError(E_UnknownResult);
return Unknown;
}
else
{
Authority::Result res = polkitResultToResult(pk_result);
g_object_unref(pk_result);
return res;
}
}
void Authority::checkAuthorization(const TQString &actionId, const Subject &subject, AuthorizationFlags flags)
{
if (Authority::instance()->hasError())
{
return;
}
if (!subject.isValid())
{
d->setError(E_WrongSubject);
return;
}
polkit_authority_check_authorization(d->pkAuthority, subject.subject(), actionId.ascii(), NULL,
(PolkitCheckAuthorizationFlags)(int)flags, d->m_checkAuthorizationCancellable,
d->checkAuthorizationCallback, this);
}
void Authority::Private::checkAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority*)user_data;
if (!authority)
{
return;
}
GError *error = NULL;
PolkitAuthorizationResult *pkResult = polkit_authority_check_authorization_finish(
(PolkitAuthority*)object, result, &error);
if (error != NULL)
{
// We don't want to set error if this is cancellation of some action
if (error->code != 1)
{
authority->d->setError(E_CheckFailed, error->message);
}
g_error_free(error);
return;
}
if (pkResult != NULL)
{
emit authority->checkAuthorizationFinished(polkitResultToResult(pkResult));
g_object_unref(pkResult);
}
else
{
authority->d->setError(E_UnknownResult);
}
}
void Authority::checkAuthorizationCancel()
{
if (!g_cancellable_is_cancelled(d->m_checkAuthorizationCancellable))
{
g_cancellable_cancel(d->m_checkAuthorizationCancellable);
}
}
ActionDescription::List Authority::enumerateActionsSync()
{
if (Authority::instance()->hasError())
{
return ActionDescription::List();
}
GError *error = NULL;
GList *glist = polkit_authority_enumerate_actions_sync(d->pkAuthority, NULL, &error);
if (error != NULL)
{
d->setError(E_EnumFailed, error->message);
g_error_free(error);
return ActionDescription::List();
}
return actionsToListAndFree(glist);
}
void Authority::enumerateActions()
{
if (Authority::instance()->hasError())
{
return;
}
polkit_authority_enumerate_actions(d->pkAuthority, d->m_enumerateActionsCancellable,
d->enumerateActionsCallback, Authority::instance());
}
void Authority::Private::enumerateActionsCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority*)user_data;
if (!authority)
{
return;
}
GError *error = NULL;
GList *list = polkit_authority_enumerate_actions_finish((PolkitAuthority*)object, result, &error);
if (error != NULL)
{
// We don't want to set error if this is cancellation of some action
if (error->code != 1)
{
authority->d->setError(E_EnumFailed, error->message);
}
g_error_free(error);
return;
}
emit authority->enumerateActionsFinished(actionsToListAndFree(list));
}
void Authority::enumerateActionsCancel()
{
if (!g_cancellable_is_cancelled(d->m_enumerateActionsCancellable))
{
g_cancellable_cancel(d->m_enumerateActionsCancellable);
}
}
bool Authority::registerAuthenticationAgentSync(const Subject &subject, const TQString &locale,
const TQString &objectPath)
{
if (Authority::instance()->hasError())
{
return false;
}
if (!subject.isValid())
{
d->setError(E_WrongSubject);
return false;
}
GError *error = NULL;
gboolean result = polkit_authority_register_authentication_agent_sync(d->pkAuthority,
subject.subject(), locale.ascii(), objectPath.ascii(), NULL, &error);
if (error)
{
d->setError(E_RegisterFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::registerAuthenticationAgent(const Subject &subject, const TQString &locale,
const TQString &objectPath)
{
if (Authority::instance()->hasError())
{
return;
}
if (!subject.isValid())
{
d->setError(E_WrongSubject);
return;
}
polkit_authority_register_authentication_agent(d->pkAuthority, subject.subject(), locale.ascii(),
objectPath.ascii(), d->m_registerAuthenticationAgentCancellable,
d->registerAuthenticationAgentCallback, this);
}
void Authority::Private::registerAuthenticationAgentCallback(GObject *object, GAsyncResult *result,
gpointer user_data)
{
Authority *authority = (Authority*)user_data;
if (!authority)
{
return;
}
GError *error = NULL;
bool res = polkit_authority_register_authentication_agent_finish((PolkitAuthority*)object, result, &error);
if (error != NULL)
{
// We don't want to set error if this is cancellation of some action
if (error->code != 1)
{
authority->d->setError(E_EnumFailed , error->message);
}
g_error_free(error);
return;
}
emit authority->registerAuthenticationAgentFinished(res);
}
void Authority::registerAuthenticationAgentCancel()
{
if (!g_cancellable_is_cancelled(d->m_registerAuthenticationAgentCancellable))
{
g_cancellable_cancel(d->m_registerAuthenticationAgentCancellable);
}
}
bool Authority::unregisterAuthenticationAgentSync(const Subject &subject, const TQString &objectPath)
{
if (d->pkAuthority)
{
return false;
}
if (!subject.isValid())
{
d->setError(E_WrongSubject);
return false;
}
GError *error = NULL;
bool result = polkit_authority_unregister_authentication_agent_sync(d->pkAuthority,
subject.subject(), objectPath.utf8().data(), NULL, &error);
if (error != NULL)
{
d->setError(E_UnregisterFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::unregisterAuthenticationAgent(const Subject &subject, const TQString &objectPath)
{
if (Authority::instance()->hasError())
{
return;
}
if (!subject.isValid())
{
d->setError(E_WrongSubject);
return;
}
polkit_authority_unregister_authentication_agent(d->pkAuthority, subject.subject(),
objectPath.utf8().data(), d->m_unregisterAuthenticationAgentCancellable,
d->unregisterAuthenticationAgentCallback, this);
}
void Authority::Private::unregisterAuthenticationAgentCallback(GObject *object,
GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority*)user_data;
if (!authority)
{
return;
}
GError *error = NULL;
bool res = polkit_authority_unregister_authentication_agent_finish((PolkitAuthority*)object,
result, &error);
if (error != NULL)
{
// We don't want to set error if this is cancellation of some action
if (error->code != 1)
{
authority->d->setError(E_UnregisterFailed, error->message);
}
g_error_free(error);
return;
}
emit authority->unregisterAuthenticationAgentFinished(res);
}
void Authority::unregisterAuthenticationAgentCancel()
{
if (!g_cancellable_is_cancelled(d->m_unregisterAuthenticationAgentCancellable))
{
g_cancellable_cancel(d->m_unregisterAuthenticationAgentCancellable);
}
}
bool Authority::authenticationAgentResponseSync(const TQString &cookie, const Identity &identity)
{
if (Authority::instance()->hasError())
{
return false;
}
if (cookie.isEmpty() || !identity.isValid())
{
d->setError(E_CookieOrIdentityEmpty);
return false;
}
GError *error = NULL;
bool result = polkit_authority_authentication_agent_response_sync(d->pkAuthority,
cookie.utf8().data(), identity.identity(), NULL, &error);
if (error != NULL)
{
d->setError(E_AgentResponseFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::authenticationAgentResponse(const TQString &cookie, const Identity &identity)
{
if (Authority::instance()->hasError())
{
return;
}
if (cookie.isEmpty() || !identity.isValid())
{
d->setError(E_CookieOrIdentityEmpty);
return;
}
polkit_authority_authentication_agent_response(d->pkAuthority, cookie.utf8().data(),
identity.identity(), d->m_authenticationAgentResponseCancellable,
d->authenticationAgentResponseCallback, this);
}
void Authority::Private::authenticationAgentResponseCallback(GObject *object, GAsyncResult *result,
gpointer user_data)
{
Authority *authority = (Authority*)user_data;
if (!authority)
{
return;
}
GError *error = NULL;
bool res = polkit_authority_authentication_agent_response_finish((PolkitAuthority*)object, result,
&error);
if (error != NULL)
{
// We don't want to set error if this is cancellation of some action
if (error->code != 1)
{
authority->d->setError(E_AgentResponseFailed, error->message);
}
g_error_free(error);
return;
}
emit authority->authenticationAgentResponseFinished(res);
}
void Authority::authenticationAgentResponseCancel()
{
if (!g_cancellable_is_cancelled(d->m_authenticationAgentResponseCancellable))
{
g_cancellable_cancel(d->m_authenticationAgentResponseCancellable);
}
}
TemporaryAuthorization::List Authority::enumerateTemporaryAuthorizationsSync(const Subject &subject)
{
TemporaryAuthorization::List result;
GError *error = NULL;
GList *glist = polkit_authority_enumerate_temporary_authorizations_sync(d->pkAuthority,
subject.subject(), NULL, &error);
if (error != NULL)
{
d->setError(E_EnumFailed, error->message);
g_error_free(error);
return result;
}
GList *glist2;
for (glist2 = glist; glist2 != NULL; glist2 = g_list_next(glist2))
{
result.append(TemporaryAuthorization((PolkitTemporaryAuthorization*)glist2->data));
g_object_unref(glist2->data);
}
g_list_free(glist);
return result;
}
void Authority::Private::enumerateTemporaryAuthorizationsCallback(GObject *object,
GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority*)user_data;
if (!authority)
{
return;
}
GError *error = NULL;
GList *glist = polkit_authority_enumerate_temporary_authorizations_finish((PolkitAuthority*)object,
result, &error);
if (error != NULL)
{
// We don't want to set error if this is cancellation of some action
if (error->code != 1)
{
authority->d->setError(E_EnumFailed, error->message);
}
g_error_free(error);
return;
}
TemporaryAuthorization::List res;
GList *glist2;
for (glist2 = glist; glist2 != NULL; glist2 = g_list_next(glist2))
{
res.append(TemporaryAuthorization((PolkitTemporaryAuthorization*)glist2->data));
g_object_unref(glist2->data);
}
g_list_free(glist);
emit authority->enumerateTemporaryAuthorizationsFinished(res);
}
void Authority::enumerateTemporaryAuthorizationsCancel()
{
if (!g_cancellable_is_cancelled(d->m_enumerateTemporaryAuthorizationsCancellable))
{
g_cancellable_cancel(d->m_enumerateTemporaryAuthorizationsCancellable);
}
}
bool Authority::revokeTemporaryAuthorizationsSync(const Subject &subject)
{
if (Authority::instance()->hasError())
{
return false;
}
GError *error = NULL;
bool result = polkit_authority_revoke_temporary_authorizations_sync(d->pkAuthority,
subject.subject(), NULL, &error);
if (error != NULL)
{
d->setError(E_RevokeFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::revokeTemporaryAuthorizations(const Subject &subject)
{
if (Authority::instance()->hasError())
{
return;
}
polkit_authority_revoke_temporary_authorizations(d->pkAuthority, subject.subject(),
d->m_revokeTemporaryAuthorizationsCancellable,
d->revokeTemporaryAuthorizationsCallback, this);
}
void Authority::Private::revokeTemporaryAuthorizationsCallback(GObject *object,
GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority*)user_data;
if (!authority)
{
return;
}
GError *error = NULL;
bool res = polkit_authority_revoke_temporary_authorizations_finish((PolkitAuthority*)object, result, &error);
if (error != NULL)
{
// We don't want to set error if this is cancellation of some action
if (error->code != 1)
{
authority->d->setError(E_RevokeFailed, error->message);
}
g_error_free(error);
return;
}
emit authority->revokeTemporaryAuthorizationsFinished(res);
}
void Authority::revokeTemporaryAuthorizationsCancel()
{
if (!g_cancellable_is_cancelled(d->m_revokeTemporaryAuthorizationsCancellable))
{
g_cancellable_cancel(d->m_revokeTemporaryAuthorizationsCancellable);
}
}
bool Authority::revokeTemporaryAuthorizationSync(const TQString &id)
{
if (Authority::instance()->hasError())
{
return false;
}
GError *error = NULL;
bool result = polkit_authority_revoke_temporary_authorization_by_id_sync(d->pkAuthority,
id.utf8().data(), NULL, &error);
if (error != NULL)
{
d->setError(E_RevokeFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::revokeTemporaryAuthorization(const TQString &id)
{
if (Authority::instance()->hasError())
{
return;
}
polkit_authority_revoke_temporary_authorization_by_id(d->pkAuthority, id.utf8().data(),
d->m_revokeTemporaryAuthorizationCancellable,
d->revokeTemporaryAuthorizationCallback, this);
}
void Authority::Private::revokeTemporaryAuthorizationCallback(GObject *object,
GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority*)user_data;
if (!authority)
{
return;
}
GError *error = NULL;
bool res = polkit_authority_revoke_temporary_authorization_by_id_finish((PolkitAuthority*)object,
result, &error);
if (error != NULL)
{
// We don't want to set error if this is cancellation of some action
if (error->code != 1)
{
authority->d->setError(E_RevokeFailed, error->message);
}
g_error_free(error);
return;
}
emit authority->revokeTemporaryAuthorizationFinished(res);
}
void Authority::revokeTemporaryAuthorizationCancel()
{
if (!g_cancellable_is_cancelled(d->m_revokeTemporaryAuthorizationCancellable))
{
g_cancellable_cancel(d->m_revokeTemporaryAuthorizationCancellable);
}
}
}
#include "polkit-tqt-authority.moc"

@ -21,20 +21,21 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef POLKITTQT1_AUTHORITY_H
#define POLKITTQT1_AUTHORITY_H
#ifndef POLKIT_TQT_AUTHORITY_H
#define POLKIT_TQT_AUTHORITY_H
#include "polkit-tqt-export.h"
#include "polkittqt1-identity.h"
#include "polkittqt1-subject.h"
#include "polkittqt1-temporaryauthorization.h"
#include "polkittqt1-actiondescription.h"
#include "polkit-tqt-identity.h"
#include "polkit-tqt-subject.h"
#include "polkit-tqt-temporaryauthorization.h"
#include "polkit-tqt-actiondescription.h"
#include <TQtCore/TQObject>
#include <TQtCore/TQMetaType>
#include "tqobject.h"
typedef struct _PolkitAuthority PolkitAuthority;
class TQStringList;
class TQString;
/**
* \namespace PolkitTQt PolkitTQt
@ -47,14 +48,14 @@ namespace PolkitTQt
{
/**
* \class Authority polkittqt1-authority.h Authority
* \class Authority polkit-tqt-authority.h Authority
* \author Daniel Nicoletti <dantti85-pk@yahoo.com.br>
* \author Dario Freddi <drf@kde.org>
* \author Jaroslav Reznik <jreznik@redhat.com>
*
* \brief Convenience class for TQt/KDE applications
* \brief Convenience class for TQt/TDE applications
*
* This class is a singleton that provides makes easy the usage
* This class is a singleton that makes easy the usage
* of PolKitAuthority. It emits configChanged()
* whenever PolicyKit files change (e.g. the PolicyKit.conf
* or .policy files) or when ConsoleKit reports activities changes.
@ -65,58 +66,58 @@ namespace PolkitTQt
*/
class POLKIT_TQT_EXPORT Authority : public TQObject
{
Q_OBJECT
TQ_DISABLE_COPY(Authority)
TQ_ENUMS(Result)
TQ_ENUMS(ErrorCode)
public:
enum Result {
/** Result unknown */
Unknown = 0x00,
/** The subject is authorized for the specified action */
Yes = 0x01,
/** The subject is not authorized for the specified action */
No = 0x02,
/** The subject is authorized if more information is provided */
Challenge = 0x03
Q_OBJECT
public:
enum Result
{
/** Result unknown */
Unknown = 0x00,
/** The subject is authorized for the specified action */
Yes = 0x01,
/** The subject is not authorized for the specified action */
No = 0x02,
/** The subject is authorized if more information is provided */
Challenge = 0x03
};
enum AuthorizationFlag {
/** No flags set **/
None = 0x00,
/** If the subject can obtain the authorization through authentication,
* and an authentication agent is available, then attempt to do so.
*
* Note, this means that the method used for checking authorization is likely
* to block for a long time. **/
AllowUserInteraction = 0x01
enum AuthorizationFlags
{
/** No flags set **/
None = 0x00,
/** If the subject can obtain the authorization through authentication,
* and an authentication agent is available, then attempt to do so.
*
* Note, this means that the method used for checking authorization is likely
* to block for a long time. **/
AllowUserInteraction = 0x01
};
TQ_DECLARE_FLAGS(AuthorizationFlags, AuthorizationFlag)
/** Error codes for the authority class */
enum ErrorCode {
/** No error occurred **/
E_None = 0x00,
/** Authority cannot be obtained **/
E_GetAuthority = 0x01,
/** Authority check failed **/
E_CheckFailed = 0x02,
/** Wrong or empty subject was given **/
E_WrongSubject = 0x03,
/** Action returned unknown result **/
E_UnknownResult = 0x04,
/** Enumerating actions failed **/
E_EnumFailed = 0x05,
/** Registration of authentication agent failed **/
E_RegisterFailed = 0x06,
/** Unregistration of authentication agent failed **/
E_UnregisterFailed = 0x07,
/** Cookie or polkittqt1-identity.handled to the action is empty **/
E_CookieOrIdentityEmpty = 0x08,
/** Response of auth agent failed **/
E_AgentResponseFailed = 0x09,
/** Revoke temporary authorizations failed **/
E_RevokeFailed = 0x0A
enum ErrorCode
{
/** No error occurred **/
E_None = 0x00,
/** Authority cannot be obtained **/
E_GetAuthority = 0x01,
/** Authority check failed **/
E_CheckFailed = 0x02,
/** Wrong or empty subject was given **/
E_WrongSubject = 0x03,
/** Action returned unknown result **/
E_UnknownResult = 0x04,
/** Enumerating actions failed **/
E_EnumFailed = 0x05,
/** Registration of authentication agent failed **/
E_RegisterFailed = 0x06,
/** Unregistration of authentication agent failed **/
E_UnregisterFailed = 0x07,
/** Cookie or polkittqt1-identity.handled to the action is empty **/
E_CookieOrIdentityEmpty = 0x08,
/** Response of auth agent failed **/
E_AgentResponseFailed = 0x09,
/** Revoke temporary authorizations failed **/
E_RevokeFailed = 0x0A
};
/**
@ -136,7 +137,7 @@ public:
*
* \return The current authority instance
*/
static Authority *instance(PolkitAuthority *authority = 0);
static Authority* instance(PolkitAuthority *authority = NULL);
~Authority();
@ -177,7 +178,7 @@ public:
*
* \return the current PolkitAuthority instance
*/
PolkitAuthority *polkitAuthority() const;
PolkitAuthority* polkitAuthority() const;
/**
* This function should be used by mechanisms (e.g.: helper applications).
@ -321,7 +322,8 @@ public:
void unregisterAuthenticationAgentCancel();
/**
* Provide response that \p identity successfully authenticated for the authentication request identified by \p cookie.
* Provide response that \p identity successfully authenticated for the authentication
* request identified by \p cookie.
*
* \see authenticationAgentResponseSync Synchronous version of this method.
* \see authenticationAgentResponseFinished Signal that is emitted when this method finishes.
@ -333,7 +335,8 @@ public:
void authenticationAgentResponse(const TQString &cookie, const Identity &identity);
/**
* Provide response that \p identity successfully authenticated for the authentication request identified by \p cookie.
* Provide response that \p identity successfully authenticated for the authentication
* request identified by \p cookie.
*
* \see authenticationAgentResponse Asynchronous version of this method.
*
@ -343,7 +346,7 @@ public:
* \return \c true if authority acknowledged the call, \c false if error is set.
*
*/
bool authenticationAgentResponseSync(const TQString& cookie, const PolkitTQt::Identity& identity);
bool authenticationAgentResponseSync(const TQString &cookie, const Identity &identity);
/**
* This method can be used to cancel the authenticationAgentResponseAsync method.
@ -436,43 +439,27 @@ public:
*/
void revokeTemporaryAuthorizationCancel();
Q_SIGNALS:
signals:
/**
* This signal will be emitted when a configuration
* file gets changed (e.g. /etc/PolicyKit/PolicyKit.conf or
* .policy files).
* Connect to this signal if you want to track down
* actions.
* file gets changed (e.g. /etc/PolicyKit/PolicyKit.conf or .policy files).
* Connect to this signal if you want to track down actions.
*/
void configChanged();
/**
* This signal is emitted when ConsoleKit configuration
* changes. This might happen when a session becomes active
* or inactive.
*
* If you want to track your actions directly you should
* connect to this signal, as this might change the return value
* PolicyKit will give you.
*
* \note If you use Action you'll probably prefer to
* use the dataChanged() signal to track Action changes.
*/
void consoleKitDBChanged();
/**
* This signal is emitted when asynchronous method checkAuthorization finishes.
*
* The argument is the result of authorization.
*/
void checkAuthorizationFinished(PolkitTQt::Authority::Result);
void checkAuthorizationFinished(Result);
/**
* This signal is emitted when asynchronous method enumerateActions finishes.
*
* The argument is the list of all Action IDs.
*/
void enumerateActionsFinished(PolkitTQt::ActionDescription::List);
void enumerateActionsFinished(ActionDescription::List);
/**
* This signal is emitted when asynchronous method registerAuthenticationAgent finishes.
@ -498,16 +485,16 @@ Q_SIGNALS:
void authenticationAgentResponseFinished(bool);
/**
* This signal is emmited when asynchronous method enumerateTemporaryAuthorizations finishes.
* This signal is emitted when asynchronous method enumerateTemporaryAuthorizations finishes.
*
* The argument is list of all temporary authorizations.
*
* \note Free all TemporaryAuthorization objects using \p delete operator.
*/
void enumerateTemporaryAuthorizationsFinished(PolkitTQt::TemporaryAuthorization::List);
void enumerateTemporaryAuthorizationsFinished(TemporaryAuthorization::List);
/**
* This signal is emmited when asynchronous method revokeTemporaryAuthorizations finishes.
* This signal is emitted when asynchronous method revokeTemporaryAuthorizations finishes.
*
* The argument is \c true if all temporary authorizations were revoked
* \c false if the revoking failed
@ -515,25 +502,26 @@ Q_SIGNALS:
void revokeTemporaryAuthorizationsFinished(bool);
/**
* This signal is emmited when asynchronous method revokeTemporaryAuthorization finishes.
* This signal is emitted when asynchronous method revokeTemporaryAuthorization finishes.
* \return \c true if the temporary authorization was revoked
* \c false if the revoking failed
*/
void revokeTemporaryAuthorizationFinished(bool);
private:
explicit Authority(PolkitAuthority *context, TQObject *parent = 0);
private:
// Disable copy
Authority(const Authority&);
Authority& operator=(const Authority&);
class Private;
friend class Private;
Private * const d;
Authority(TQObject *parent = NULL);
static Authority *m_theAuthority;
Q_PRIVATE_SLOT(d, void dbusFilter(const TQDBusMessage &message))
class Private;
Private *const d;
};
}
Q_DECLARE_OPERATORS_FOR_FLAGS(PolkitTQt::Authority::AuthorizationFlags)
Q_DECLARE_METATYPE(PolkitTQt::Authority::Result)
#endif

@ -0,0 +1,134 @@
/*
* 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.
*/
#include <polkit/polkit.h>
#include "polkit-tqt-details.h"
#include <tqshared.h>
#include <tqstring.h>
#include <tqstringlist.h>
namespace PolkitTQt
{
//--------------------------------------
// Details::Data
//--------------------------------------
class Details::Data : public TQShared
{
public:
Data() : details(NULL)
{
}
Data(const Data &other) : details(other.details)
{
g_object_ref(details);
}
Data(PolkitDetails *_details) : details(_details)
{
g_object_ref(details);
}
~Data()
{
g_object_unref(details);
}
PolkitDetails *details;
};
//--------------------------------------
// Details
//--------------------------------------
Details::Details() : d(new Data)
{
d->details = polkit_details_new();
}
Details::Details(PolkitDetails *pkDetails) : d(new Data(pkDetails))
{
}
Details::Details(const Details &other) : d(other.d)
{
d->ref();
}
Details& Details::operator=(const Details &other)
{
if (d != other.d)
{
if (d->deref())
{
delete d;
}
d = other.d;
d->ref();
}
return *this;
}
Details::~Details()
{
if (d->deref())
{
delete d;
}
}
TQString Details::lookup(const TQString &key) const
{
const gchar *result = polkit_details_lookup(d->details, key.utf8().data());
if (result != NULL)
{
return TQString::fromUtf8(result);
}
else
{
return TQString::null;
}
}
void Details::insert(const TQString &key, const TQString &value)
{
polkit_details_insert(d->details, key.utf8().data(), value.utf8().data());
}
TQStringList Details::keys() const
{
gchar **result = polkit_details_get_keys(d->details);
TQStringList list;
int len = g_strv_length(result);
for (int i = 0; i < len; i++)
{
list.append(TQString::fromUtf8(result[i]));
}
g_strfreev(result);
return list;
}
}

@ -18,16 +18,17 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef POLKITTQT1_DETAILS_H
#define POLKITTQT1_DETAILS_H
#ifndef POLKIT_TQT_DETAILS_H
#define POLKIT_TQT_DETAILS_H
#include "polkit-tqt-export.h"
#include <TQtCore/TQObject>
#include <TQtCore/TQSharedData>
typedef struct _PolkitDetails PolkitDetails;
class TQString;
class TQStringList;
/**
* \namespace PolkitTQt PolkitTQt
*
@ -39,18 +40,17 @@ namespace PolkitTQt
{
/**
* \class Details polkittqt1-details.h Details
* \class Details polkit-tqt-details.h Details
* \author Radek Novacek <rnovacek@redhat.com>
*
* \brief Class used for passing details around.
*/
class POLKIT_TQT_EXPORT Details
{
public:
/**
* Creates a new Details object
*/
public:
Details();
Details(const Details &other);
~Details();
/**
* Creates Details object from PolkitDetails
@ -61,9 +61,7 @@ public:
*/
explicit Details(PolkitDetails *pkDetails);
~Details();
Details &operator=(const Details &other);
Details& operator=(const Details &other);
/**
* Get the value for \p key
@ -87,11 +85,13 @@ public:
* \return List of all keys.
*/
TQStringList keys() const;
private:
private:
class Data;
Data *d;
};
}
#endif // DETAILS_H
#endif

@ -0,0 +1,219 @@
/*
* This file is part of the Polkit-tqt project
* Copyright (C) 2009 Lukas Tinkl <ltinkl@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/polkit.h>
#include "polkit-tqt-identity.h"
#include <tqshared.h>
#include <tqstring.h>
namespace PolkitTQt
{
//--------------------------------------
// Identity::Data
//--------------------------------------
class Identity::Data : public TQShared
{
public:
Data() : identity(NULL)
{
}
Data(const Data &other) : identity(other.identity)
{
g_object_ref(identity);
}
Data(PolkitIdentity *_identity) : identity(_identity)
{
g_object_ref(identity);
}
~Data()
{
g_object_unref(identity);
}
PolkitIdentity *identity;
};
//--------------------------------------
// Identity
//--------------------------------------
Identity::Identity() : d(new Data)
{
}
Identity::Identity(PolkitIdentity *pkIdentity) : d(new Data(pkIdentity))
{
}
Identity::Identity(const Identity &other) : d(other.d)
{
d->ref();
}
Identity& Identity::operator=(const Identity &other)
{
if (d != other.d)
{
if (d->deref())
{
delete d;
}
d = other.d;
d->ref();
}
return *this;
}
Identity::~Identity()
{
if (d->deref())
{
delete d;
}
}
bool Identity::isValid() const
{
return (d->identity != NULL);
}
PolkitIdentity* Identity::identity() const
{
return d->identity;
}
void Identity::setIdentity(PolkitIdentity *identity)
{
if (d->identity != identity)
{
g_object_unref(d->identity);
d->identity = identity;
g_object_ref(identity);
}
}
TQString Identity::toString() const
{
if (!d->identity)
{
return TQString::null;
}
return TQString::fromUtf8(polkit_identity_to_string(d->identity));
}
Identity Identity::fromString(const TQString &string)
{
if (string.isEmpty())
{
tqWarning(TQString("Cannot create valid Identity from empty string."));
return Identity();
}
GError *error = NULL;
PolkitIdentity *poliden = polkit_identity_from_string(string.utf8().data(), &error);
if (error != NULL)
{
tqWarning(TQString("Cannot create valid Identity from string: %1").arg(error->message));
return Identity();
}
return Identity(poliden);
}
//--------------------------------------
// UnixUserIdentity
//--------------------------------------
UnixUserIdentity::UnixUserIdentity(const TQString &name) : Identity()
{
GError *error = NULL;
setIdentity(polkit_unix_user_new_for_name(name.utf8().data(), &error));
if (error != NULL)
{
tqWarning(TQString("Cannot create UnixUserIdentity: %1").arg(error->message));
setIdentity(NULL);
}
}
UnixUserIdentity::UnixUserIdentity(uid_t uid) : Identity()
{
setIdentity(polkit_unix_user_new(uid));
}
UnixUserIdentity::UnixUserIdentity(PolkitUnixUser *pkUnixUser)
: Identity((PolkitIdentity*)pkUnixUser)
{
}
uid_t UnixUserIdentity::uid() const
{
return polkit_unix_user_get_uid((PolkitUnixUser*)identity());
}
void UnixUserIdentity::setUid(uid_t uid)
{
polkit_unix_user_set_uid((PolkitUnixUser*)identity(), uid);
}
//--------------------------------------
// UnixGroupIdentity
//--------------------------------------
UnixGroupIdentity::UnixGroupIdentity(const TQString &name) : Identity()
{
GError *error = NULL;
setIdentity(polkit_unix_group_new_for_name(name.utf8().data(), &error));
if (error != NULL)
{
tqWarning(TQString("Cannot create UnixGroupIdentity: %1").arg(error->message));
setIdentity(NULL);
}
}
UnixGroupIdentity::UnixGroupIdentity(gid_t gid) : Identity()
{
setIdentity(polkit_unix_group_new(gid));
}
UnixGroupIdentity::UnixGroupIdentity(PolkitUnixGroup *pkUnixGroup)
: Identity((PolkitIdentity*)pkUnixGroup)
{
}
gid_t UnixGroupIdentity::gid() const
{
return polkit_unix_group_get_gid((PolkitUnixGroup*)identity());
}
void UnixGroupIdentity::setGid(gid_t gid)
{
polkit_unix_group_set_gid((PolkitUnixGroup*)identity(), gid);
}
}

@ -18,20 +18,21 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef POLKITTQT1_IDENTITY_H
#define POLKITTQT1_IDENTITY_H
#ifndef POLKIT_TQT_IDENTITY_H
#define POLKIT_TQT_IDENTITY_H
#include "polkit-tqt-export.h"
#include <unistd.h>
#include <TQtCore/TQObject>
#include <TQtCore/TQSharedData>
typedef struct _PolkitIdentity PolkitIdentity;
typedef struct _PolkitUnixUser PolkitUnixUser;
typedef struct _PolkitIdentity PolkitIdentity;
typedef struct _PolkitUnixUser PolkitUnixUser;
typedef struct _PolkitUnixGroup PolkitUnixGroup;
class TQString;
template<typename> class TQValueList;
/**
* \namespace PolkitTQt PolkitTQt
*
@ -42,11 +43,8 @@ typedef struct _PolkitUnixGroup PolkitUnixGroup;
namespace PolkitTQt
{
class UnixUserIdentity;
class UnixGroupIdentity;
/**
* \class Identity polkittqt1-identity.h Identity
* \class Identity polkit-tqt-identity.h Identity
* \author Lukas Tinkl <ltinkl@redhat.com>
*
* This class encapsulates the PolkitIdentity interface.
@ -58,17 +56,29 @@ class UnixGroupIdentity;
*/
class POLKIT_TQT_EXPORT Identity
{
public:
typedef TQList< Identity > List;
public:
typedef TQValueList<Identity> List;
Identity();
explicit Identity(PolkitIdentity *polkitIdentity);
Identity(const Identity &other);
~Identity();
Identity &operator=(const Identity &other);
/**
* Creates an Identity object from PolkitIdentity
*
* \warning It shouldn't be used directly unless you are completely aware of what are you doing
*
* \param pkIdentity PolkitIdentity object
*/
explicit Identity(PolkitIdentity *pkIdentity);
Identity& operator=(const Identity &other);
/**
* Check whether an identity is valid
*
* \return true is the identity is valid
*/
bool isValid() const;
/**
@ -83,13 +93,10 @@ public:
*
* \param string string representation of the object
*
* \return Pointer to new Identity instance
* \return the new Identity instance
*/
static Identity fromString(const TQString &string);
UnixUserIdentity toUnixUserIdentity();
UnixGroupIdentity toUnixGroupIdentity();
/**
* Gets PolkitIdentity object.
*
@ -97,17 +104,17 @@ public:
*
* \return Pointer to PolkitIdentity instance
*/
PolkitIdentity *identity() const;
protected:
PolkitIdentity* identity() const;
void setIdentity(PolkitIdentity *identity);
private:
private:
class Data;
Data *d;
};
/**
* \class UnixUserIdentity polkittqt1-identity.h Identity
* \class UnixUserIdentity polkit-tqt-identity.h Identity
*
* An object representing a user identity on a UNIX system.
*
@ -116,8 +123,7 @@ private:
*/
class POLKIT_TQT_EXPORT UnixUserIdentity : public Identity
{
public:
UnixUserIdentity();
public:
/**
* Creates UnixUser object by UID of the user
*
@ -157,7 +163,7 @@ public:
};
/**
* \class UnixGroupIdentity polkittqt1-identity.h Identity
* \class UnixGroupIdentity polkit-tqt-identity.h Identity
*
* An object representing a group identity on a UNIX system.
*
@ -166,8 +172,7 @@ public:
*/
class POLKIT_TQT_EXPORT UnixGroupIdentity : public Identity
{
public:
UnixGroupIdentity();
public:
/**
* Creates UnixGroup object by GID of the group
*
@ -208,4 +213,5 @@ public:
}
#endif // POLKIT_TQT_IDENTITY_H
#endif

@ -18,12 +18,12 @@
* Boston, MA 02110-1301, USA.
*/
#include <polkit/polkit.h>
#include "polkit-tqt-subject.h"
#include <tqglobal.h>
#include <tqshared.h>
#include <polkit/polkit.h>
#include <tqstring.h>
namespace PolkitTQt
@ -66,7 +66,7 @@ Subject::Subject() : d(new Data)
{
}
Subject::Subject(PolkitSubject *subject) : d(new Data(subject))
Subject::Subject(PolkitSubject *pkSubject) : d(new Data(pkSubject))
{
}

@ -1,5 +1,5 @@
/*
* This file is part of the PolKit1-tqt project
* 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
@ -23,8 +23,8 @@
#include "polkit-tqt-export.h"
typedef struct _PolkitSubject PolkitSubject;
typedef struct _PolkitUnixProcess PolkitUnixProcess;
typedef struct _PolkitSubject PolkitSubject;
typedef struct _PolkitUnixProcess PolkitUnixProcess;
typedef struct _PolkitSystemBusName PolkitSystemBusName;
class TQString;
@ -59,10 +59,19 @@ class POLKIT_TQT_EXPORT Subject
Subject(const Subject &other);
~Subject();
/**
* Creates a Subject object from PolkitSubject
*
* \warning It shouldn't be used directly unless you are completely aware of what are you doing
*
* \param pkSubject PolkitSubject object
*/
explicit Subject(PolkitSubject *pkSubject);
Subject& operator=(const Subject &other);
/**
* Check whether a message is valid
* Check whether a subject is valid
*
* \return true is the subject is valid
*/
@ -93,9 +102,6 @@ class POLKIT_TQT_EXPORT Subject
*/
PolkitSubject* subject() const;
protected:
Subject(PolkitSubject *subject);
void setSubject(PolkitSubject *subject);
private:

@ -0,0 +1,141 @@
/*
* 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.
*/
#include <polkit/polkit.h>
#include "polkit-tqt-temporaryauthorization.h"
#include "polkit-tqt-authority.h"
#include <tqdatetime.h>
#include <tqshared.h>
#include <tqstring.h>
namespace PolkitTQt
{
//--------------------------------------
// TemporaryAuthorization::Data
//--------------------------------------
class TemporaryAuthorization::Data : public TQShared
{
public:
Data() : id(TQString::null) , actionId(TQString::null), subject(),
timeObtained(TQDateTime()), timeExpires(TQDateTime())
{
}
Data(const Data& other) : id(other.id), actionId(other.actionId), subject(other.subject),
timeObtained(other.timeObtained), timeExpires(other.timeExpires)
{
}
~Data()
{
}
TQString id;
TQString actionId;
Subject subject;
TQDateTime timeObtained;
TQDateTime timeExpires;
};
//--------------------------------------
// TemporaryAuthorization
//--------------------------------------
TemporaryAuthorization::TemporaryAuthorization() : d(new Data)
{
}
TemporaryAuthorization::TemporaryAuthorization(PolkitTemporaryAuthorization *pkTemporaryAuthorization) : d(new Data)
{
d->id = TQString::fromUtf8(polkit_temporary_authorization_get_id(pkTemporaryAuthorization));
d->actionId = TQString::fromUtf8(polkit_temporary_authorization_get_action_id(pkTemporaryAuthorization));
d->subject = Subject::fromString(polkit_subject_to_string(polkit_temporary_authorization_get_subject(pkTemporaryAuthorization)));
d->timeObtained = TQDateTime();
d->timeObtained.setTime_t(polkit_temporary_authorization_get_time_obtained(pkTemporaryAuthorization));
d->timeExpires = TQDateTime();
d->timeExpires.setTime_t(polkit_temporary_authorization_get_time_expires(pkTemporaryAuthorization));
}
TemporaryAuthorization::TemporaryAuthorization(const TemporaryAuthorization &other) : d(other.d)
{
d->ref();
}
TemporaryAuthorization& TemporaryAuthorization::operator=(const PolkitTQt::TemporaryAuthorization& other)
{
if (d != other.d)
{
if (d->deref())
{
delete d;
}
d = other.d;
d->ref();
}
return *this;
}
TemporaryAuthorization::~TemporaryAuthorization()
{
if (d->deref())
{
delete d;
}
}
TQString TemporaryAuthorization::id() const
{
return d->id;
}
TQString TemporaryAuthorization::actionId() const
{
return d->actionId;
}
Subject TemporaryAuthorization::subject() const
{
return d->subject;
}
TQDateTime TemporaryAuthorization::obtainedAt() const
{
return d->timeObtained;
}
TQDateTime TemporaryAuthorization::expirationTime() const
{
return d->timeExpires;
}
bool TemporaryAuthorization::revoke()
{
Authority::instance()->revokeTemporaryAuthorization(id());
return true;
}
}

@ -1,5 +1,5 @@
/*
* This file is part of the PolKit1-qt project
* 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
@ -18,18 +18,19 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef POLKITTQT1_TEMPORARYAUTHORIZATION_H
#define POLKITTQT1_TEMPORARYAUTHORIZATION_H
#ifndef POLKIT_TQT_TEMPORARY_AUTHORIZATION_H
#define POLKIT_TQT_TEMPORARY_AUTHORIZATION_H
#include "polkittqt1-subject.h"
#include <TQtCore/TQObject>
#include <TQtCore/TQDateTime>
#include <TQtCore/TQMetaType>
#include <TQtCore/TQSharedData>
#include "polkit-tqt-export.h"
#include "polkit-tqt-subject.h"
typedef struct _PolkitTemporaryAuthorization PolkitTemporaryAuthorization;
class TQDateTime;
class TQString;
template<typename> class TQValueList;
/**
* \namespace PolkitTQt PolkitTQt
*
@ -41,7 +42,7 @@ namespace PolkitTQt
{
/**
* \class TemporaryAuthorization polkittqt1-temporaryauthorization.h TemporaryAuthorization
* \class TemporaryAuthorization polkit-tqt-temporaryauthorization.h TemporaryAuthorization
* \author Radek Novacek <rnovacek@redhat.com>
*
* \brief This class represents PolicyKit temporary authorization
@ -50,23 +51,23 @@ namespace PolkitTQt
*/
class POLKIT_TQT_EXPORT TemporaryAuthorization
{
public:
typedef TQList< TemporaryAuthorization > List;
public:
typedef TQValueList<TemporaryAuthorization> List;
TemporaryAuthorization();
TemporaryAuthorization(const TemporaryAuthorization &other);
~TemporaryAuthorization();
/**
* Creates TemporaryAuthorization object from PolkitTemporaryAuthorization
*
* \warning It shouldn't be used directly unless you are completely aware of what are you doing
*
* \param pkTemporaryAuthorization PolkitTemporaryAuthorization object
* \param parent
*/
explicit TemporaryAuthorization(PolkitTemporaryAuthorization *pkTemporaryAuthorization);
TemporaryAuthorization(const TemporaryAuthorization &other);
TemporaryAuthorization(PolkitTemporaryAuthorization *pkTemporaryAuthorization);
~TemporaryAuthorization();
TemporaryAuthorization &operator=(const TemporaryAuthorization &other);
TemporaryAuthorization& operator=(const TemporaryAuthorization &other);
/**
* \brief Gets the identifier for the authorization.
@ -113,12 +114,12 @@ public:
*/
bool revoke();
private:
private:
class Data;
TQSharedDataPointer< Data > d;
Data *d;
};
}
TQ_DECLARE_METATYPE(PolkitTQt::TemporaryAuthorization::List)
#endif
#endif // TEMPORARYAUTHORIZATION_H

@ -1,148 +0,0 @@
/*
* This file is part of the Polkit-tqt project
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
* Copyright (C) 2010 Dario Freddi <drf@kde.org>
*
* 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-actiondescription.h"
#include <TQtCore/TQString>
#include <polkit/polkit.h>
namespace PolkitTQt
{
class ActionDescription::Data : public TQSharedData
{
public:
Data() {}
Data(const Data& other)
: TQSharedData(other)
, actionId(other.actionId)
, description(other.description)
, message(other.message)
, vendorName(other.vendorName)
, vendorUrl(other.vendorUrl)
, iconName(other.iconName)
, implicitAny(other.implicitAny)
, implicitInactive(other.implicitInactive)
, implicitActive(other.implicitActive)
{
}
virtual ~Data() {}
TQString actionId;
TQString description;
TQString message;
TQString vendorName;
TQString vendorUrl;
TQString iconName;
ActionDescription::ImplicitAuthorization implicitAny;
ActionDescription::ImplicitAuthorization implicitInactive;
ActionDescription::ImplicitAuthorization implicitActive;
};
ActionDescription::ActionDescription()
: d(new Data)
{
}
ActionDescription::ActionDescription(PolkitActionDescription *polkitActionDescription)
: d(new Data)
{
g_type_init();
d->actionId = TQString::fromUtf8(polkit_action_description_get_action_id(polkitActionDescription));
d->description = TQString::fromUtf8(polkit_action_description_get_description(polkitActionDescription));
d->message = TQString::fromUtf8(polkit_action_description_get_message(polkitActionDescription));
d->vendorName = TQString::fromUtf8(polkit_action_description_get_vendor_name(polkitActionDescription));
d->vendorUrl = TQString::fromUtf8(polkit_action_description_get_vendor_url(polkitActionDescription));
d->iconName = TQString::fromUtf8(polkit_action_description_get_icon_name(polkitActionDescription));
d->implicitAny = static_cast<ActionDescription::ImplicitAuthorization>(polkit_action_description_get_implicit_any(
polkitActionDescription));
d->implicitInactive = static_cast<ActionDescription::ImplicitAuthorization>(polkit_action_description_get_implicit_inactive(
polkitActionDescription));
d->implicitActive = static_cast<ActionDescription::ImplicitAuthorization>(polkit_action_description_get_implicit_active(
polkitActionDescription));
}
ActionDescription::ActionDescription(const PolkitTQt::ActionDescription& other)
: d(other.d)
{
}
ActionDescription& ActionDescription::operator=(const PolkitTQt::ActionDescription& other)
{
d = other.d;
return *this;
}
ActionDescription::~ActionDescription()
{
}
TQString ActionDescription::actionId() const
{
return d->actionId;
}
TQString ActionDescription::description() const
{
return d->description;
}
TQString ActionDescription::message() const
{
return d->message;
}
TQString ActionDescription::vendorName() const
{
return d->vendorName;
}
TQString ActionDescription::vendorUrl() const
{
return d->vendorUrl;
}
TQString ActionDescription::iconName() const
{
return d->iconName;
}
ActionDescription::ImplicitAuthorization ActionDescription::implicitAny() const
{
return d->implicitAny;
}
ActionDescription::ImplicitAuthorization ActionDescription::implicitInactive() const
{
return d->implicitInactive;
}
ActionDescription::ImplicitAuthorization ActionDescription::implicitActive() const
{
return d->implicitActive;
}
}

@ -1,855 +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 "polkittqt1-authority.h"
#include <TQtDBus/TQDBusInterface>
#include <TQtDBus/TQDBusReply>
#include <polkit/polkit.h>
namespace PolkitTQt
{
class AuthorityHelper
{
public:
AuthorityHelper() : q(0) {}
~AuthorityHelper() {
delete q;
}
Authority *q;
};
TQ_GLOBAL_STATIC(AuthorityHelper, s_globalAuthority)
Authority *Authority::instance(PolkitAuthority *authority)
{
if (!s_globalAuthority()->q) {
new Authority(authority);
}
return s_globalAuthority()->q;
}
Authority::Result polkitResultToResult(PolkitAuthorizationResult *result)
{
if (polkit_authorization_result_get_is_challenge(result)) {
return Authority::Challenge;
} else if (polkit_authorization_result_get_is_authorized(result)) {
return Authority::Yes;
} else {
return Authority::No;
}
}
ActionDescription::List actionsToListAndFree(GList *glist)
{
ActionDescription::List result;
for (GList *glist2 = glist; glist2; glist2 = g_list_next(glist2)) {
gpointer i = glist2->data;
result.append(ActionDescription(static_cast<PolkitActionDescription *>(i)));
g_object_unref(i);
}
g_list_free(glist);
return result;
}
class Authority::Private
{
public:
// Polkit will return NULL on failures, hence we use it instead of 0
Private(Authority *qq) : q(qq)
, pkAuthority(NULL)
, m_hasError(false) {}
~Private();
void init();
/** Use this method to set the error message to \p message. Set recover to \c true
* to try to reinitialize this object with init() method
*/
void setError(Authority::ErrorCode code, const TQString &details = TQString(), bool recover = false);
void dbusFilter(const TQDBusMessage &message);
void dbusSignalAdd(const TQString &service, const TQString &path, const TQString &interface, const TQString &name);
void seatSignalsConnect(const TQString &seat);
Authority *q;
PolkitAuthority *pkAuthority;
bool m_hasError;
Authority::ErrorCode m_lastError;
TQString m_errorDetails;
TQDBusConnection *m_systemBus;
GCancellable *m_checkAuthorizationCancellable,
*m_enumerateActionsCancellable,
*m_registerAuthenticationAgentCancellable,
*m_unregisterAuthenticationAgentCancellable,
*m_authenticationAgentResponseCancellable,
*m_enumerateTemporaryAuthorizationsCancellable,
*m_revokeTemporaryAuthorizationsCancellable,
*m_revokeTemporaryAuthorizationCancellable;
static void pk_config_changed();
static void checkAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void enumerateActionsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void registerAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void unregisterAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void authenticationAgentResponseCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void enumerateTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void revokeTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
static void revokeTemporaryAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data);
};
Authority::Private::~Private()
{
g_object_unref(m_checkAuthorizationCancellable);
g_object_unref(m_enumerateActionsCancellable);
g_object_unref(m_registerAuthenticationAgentCancellable);
g_object_unref(m_unregisterAuthenticationAgentCancellable);
g_object_unref(m_authenticationAgentResponseCancellable);
g_object_unref(m_enumerateTemporaryAuthorizationsCancellable);
g_object_unref(m_revokeTemporaryAuthorizationsCancellable);
g_object_unref(m_revokeTemporaryAuthorizationCancellable);
}
Authority::Authority(PolkitAuthority *authority, TQObject *parent)
: TQObject(parent)
, d(new Private(this))
{
qRegisterMetaType<PolkitTQt::Authority::Result> ();
qRegisterMetaType<PolkitTQt::ActionDescription::List>();
Q_ASSERT(!s_globalAuthority()->q);
s_globalAuthority()->q = this;
if (authority) {
d->pkAuthority = authority;
}
d->init();
}
Authority::~Authority()
{
if (d->pkAuthority != NULL) {
g_object_unref(d->pkAuthority);
}
delete d;
}
void Authority::Private::init()
{
TQDBusError error;
TQDBusError dbus_error;
g_type_init();
m_checkAuthorizationCancellable = g_cancellable_new();
m_enumerateActionsCancellable = g_cancellable_new();
m_registerAuthenticationAgentCancellable = g_cancellable_new();
m_unregisterAuthenticationAgentCancellable = g_cancellable_new();
m_authenticationAgentResponseCancellable = g_cancellable_new();
m_enumerateTemporaryAuthorizationsCancellable = g_cancellable_new();
m_revokeTemporaryAuthorizationsCancellable = g_cancellable_new();
m_revokeTemporaryAuthorizationCancellable = g_cancellable_new();
#ifndef POLKIT_TQT_1_COMPATIBILITY_MODE
GError *gerror = NULL;
#endif
if (pkAuthority == NULL) {
#ifndef POLKIT_TQT_1_COMPATIBILITY_MODE
pkAuthority = polkit_authority_get_sync(NULL, &gerror);
if (gerror != NULL) {
setError(E_GetAuthority, gerror->message);
g_error_free(gerror);
return;
}
#else
pkAuthority = polkit_authority_get();
#endif
}
if (pkAuthority == NULL) {
#ifdef POLKIT_TQT_1_COMPATIBILITY_MODE
(E_GetAuthority);
#endif
return;
}
// connect changed signal
g_signal_connect(G_OBJECT(pkAuthority), "changed", G_CALLBACK(pk_config_changed), NULL);
// need to listen to NameOwnerChanged
dbusSignalAdd("org.freedesktop.DBus", "/", "org.freedesktop.DBus", "NameOwnerChanged");
TQString consoleKitService("org.freedesktop.ConsoleKit");
TQString consoleKitManagerPath("/org/freedesktop/ConsoleKit/Manager");
TQString consoleKitManagerInterface("org.freedesktop.ConsoleKit.Manager");
TQString consoleKitSeatInterface("org.freedesktop.ConsoleKit.Seat");
// first, add signals SeadAdded and SeatRemoved from ConsoleKit Manager
dbusSignalAdd(consoleKitService, consoleKitManagerPath, consoleKitManagerInterface, "SeatAdded");
dbusSignalAdd(consoleKitService, consoleKitManagerPath, consoleKitManagerInterface, "SeatRemoved");
// then we need to extract all seats from ConsoleKit
TQDBusMessage msg = TQDBusMessage::createMethodCall(consoleKitService, consoleKitManagerPath, consoleKitManagerInterface, "GetSeats");
msg = TQDBusConnection::systemBus().call(msg);
if (!msg.arguments().isEmpty()) {
// this method returns a list with present seats
TQList<TQString> seats;
qVariantValue<TQDBusArgument> (msg.arguments()[0]) >> seats;
// it can be multiple seats present so connect all their signals
TQ_FOREACH(const TQString &seat, seats) {
seatSignalsConnect(seat);
}
}
}
void Authority::Private::setError(Authority::ErrorCode code, const TQString &details, bool recover)
{
if (recover) {
init();
}
m_lastError = code;
m_errorDetails = details;
m_hasError = true;
}
void Authority::Private::seatSignalsConnect(const TQString &seat)
{
TQString consoleKitService("org.freedesktop.ConsoleKit");
TQString consoleKitSeatInterface("org.freedesktop.ConsoleKit.Seat");
// we want to connect to all slots of the seat
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "DeviceAdded");
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "DeviceRemoved");
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "SessionAdded");
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "SessionRemoved");
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "ActiveSessionChanged");
}
void Authority::Private::dbusSignalAdd(const TQString &service, const TQString &path, const TQString &interface, const TQString &name)
{
// FIXME: This code seems to be nonfunctional - it needs to be fixed somewhere (is it TQt BUG?)
TQDBusConnection::systemBus().connect(service, path, interface, name,
q, SLOT(dbusFilter(const TQDBusMessage &)));
}
void Authority::Private::dbusFilter(const TQDBusMessage &message)
{
if (message.type() == TQDBusMessage::SignalMessage) {
TQ_EMIT q->consoleKitDBChanged();
// TODO: Test this with the multiseat support
if (message.member() == "SeatAdded") {
seatSignalsConnect(qVariantValue<TQDBusObjectPath> (message.arguments()[0]).path());
}
}
}
bool Authority::hasError() const
{
return d->m_hasError;
}
Authority::ErrorCode Authority::lastError() const
{
return d->m_lastError;
}
const TQString Authority::errorDetails() const
{
if (d->m_lastError == E_None) {
return TQString();
} else {
return d->m_errorDetails;
}
}
void Authority::clearError()
{
d->m_hasError = false;
d->m_lastError = E_None;
}
void Authority::Private::pk_config_changed()
{
TQ_EMIT Authority::instance()->configChanged();
}
PolkitAuthority *Authority::polkitAuthority() const
{
return d->pkAuthority;
}
Authority::Result Authority::checkAuthorizationSync(const TQString &actionId, const Subject &subject, AuthorizationFlags flags)
{
PolkitAuthorizationResult *pk_result;
GError *error = NULL;
if (Authority::instance()->hasError()) {
return Unknown;
}
if (!subject.isValid()) {
d->setError(E_WrongSubject);
return Unknown;
}
pk_result = polkit_authority_check_authorization_sync(d->pkAuthority,
subject.subject(),
actionId.toAscii().data(),
NULL,
(PolkitCheckAuthorizationFlags)(int)flags,
NULL,
&error);
if (error != NULL) {
d->setError(E_CheckFailed, error->message);
g_error_free(error);
return Unknown;
}
if (!pk_result) {
d->setError(E_UnknownResult);
return Unknown;
} else {
Authority::Result res = polkitResultToResult(pk_result);
g_object_unref(pk_result);
return res;
}
}
void Authority::checkAuthorization(const TQString &actionId, const Subject &subject, AuthorizationFlags flags)
{
if (Authority::instance()->hasError()) {
return;
}
if (!subject.isValid()) {
d->setError(E_WrongSubject);
return;
}
polkit_authority_check_authorization(d->pkAuthority,
subject.subject(),
actionId.toAscii().data(),
NULL,
(PolkitCheckAuthorizationFlags)(int)flags,
d->m_checkAuthorizationCancellable,
d->checkAuthorizationCallback, this);
}
void Authority::Private::checkAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority *) user_data;
Q_ASSERT(authority != NULL);
GError *error = NULL;
PolkitAuthorizationResult *pkResult = polkit_authority_check_authorization_finish((PolkitAuthority *) object, result, &error);
if (error != NULL) {
// We don't want to set error if this is cancellation of some action
if (error->code != 1) {
authority->d->setError(E_CheckFailed, error->message);
}
g_error_free(error);
return;
}
if (pkResult != NULL) {
Q_EMIT authority->checkAuthorizationFinished(polkitResultToResult(pkResult));
g_object_unref(pkResult);
} else {
authority->d->setError(E_UnknownResult);
}
}
void Authority::checkAuthorizationCancel()
{
if (!g_cancellable_is_cancelled(d->m_checkAuthorizationCancellable)) {
g_cancellable_cancel(d->m_checkAuthorizationCancellable);
}
}
ActionDescription::List Authority::enumerateActionsSync()
{
if (Authority::instance()->hasError()) {
return ActionDescription::List();
}
GError *error = NULL;
GList *glist = polkit_authority_enumerate_actions_sync(d->pkAuthority,
NULL,
&error);
if (error != NULL) {
d->setError(E_EnumFailed, error->message);
g_error_free(error);
return ActionDescription::List();
}
return actionsToListAndFree(glist);
}
void Authority::enumerateActions()
{
if (Authority::instance()->hasError()) {
return;
}
polkit_authority_enumerate_actions(d->pkAuthority,
d->m_enumerateActionsCancellable,
d->enumerateActionsCallback,
Authority::instance());
}
void Authority::Private::enumerateActionsCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority *) user_data;
Q_ASSERT(authority != NULL);
GError *error = NULL;
GList *list = polkit_authority_enumerate_actions_finish((PolkitAuthority *) object, result, &error);
if (error != NULL) {
// We don't want to set error if this is cancellation of some action
if (error->code != 1) {
authority->d->setError(E_EnumFailed, error->message);
}
g_error_free(error);
return;
}
TQ_EMIT authority->enumerateActionsFinished(actionsToListAndFree(list));
}
void Authority::enumerateActionsCancel()
{
if (!g_cancellable_is_cancelled(d->m_enumerateActionsCancellable)) {
g_cancellable_cancel(d->m_enumerateActionsCancellable);
}
}
bool Authority::registerAuthenticationAgentSync(const Subject &subject, const TQString &locale, const TQString &objectPath)
{
if (Authority::instance()->hasError()) {
return false;
}
gboolean result;
GError *error = NULL;
if (!subject.isValid()) {
d->setError(E_WrongSubject);
return false;
}
result = polkit_authority_register_authentication_agent_sync(d->pkAuthority,
subject.subject(), locale.toAscii().data(),
objectPath.toAscii().data(), NULL, &error);
if (error) {
d->setError(E_RegisterFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::registerAuthenticationAgent(const Subject &subject, const TQString &locale, const TQString &objectPath)
{
if (Authority::instance()->hasError()) {
return;
}
if (!subject.isValid()) {
d->setError(E_WrongSubject);
return;
}
polkit_authority_register_authentication_agent(d->pkAuthority,
subject.subject(),
locale.toAscii().data(),
objectPath.toAscii().data(),
d->m_registerAuthenticationAgentCancellable,
d->registerAuthenticationAgentCallback,
this);
}
void Authority::Private::registerAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority *) user_data;
Q_ASSERT(authority != NULL);
GError *error = NULL;
bool res = polkit_authority_register_authentication_agent_finish((PolkitAuthority *) object, result, &error);
if (error != NULL) {
// We don't want to set error if this is cancellation of some action
if (error->code != 1) {
authority->d->setError(E_EnumFailed , error->message);
}
g_error_free(error);
return;
}
TQ_EMIT authority->registerAuthenticationAgentFinished(res);
}
void Authority::registerAuthenticationAgentCancel()
{
if (!g_cancellable_is_cancelled(d->m_registerAuthenticationAgentCancellable)) {
g_cancellable_cancel(d->m_registerAuthenticationAgentCancellable);
}
}
bool Authority::unregisterAuthenticationAgentSync(const Subject &subject, const TQString &objectPath)
{
if (d->pkAuthority) {
return false;
}
if (!subject.isValid()) {
d->setError(E_WrongSubject);
return false;
}
GError *error = NULL;
bool result = polkit_authority_unregister_authentication_agent_sync(d->pkAuthority,
subject.subject(),
objectPath.toUtf8().data(),
NULL,
&error);
if (error != NULL) {
d->setError(E_UnregisterFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::unregisterAuthenticationAgent(const Subject &subject, const TQString &objectPath)
{
if (Authority::instance()->hasError()) {
return;
}
if (!subject.isValid()) {
d->setError(E_WrongSubject);
return;
}
polkit_authority_unregister_authentication_agent(d->pkAuthority,
subject.subject(),
objectPath.toUtf8().data(),
d->m_unregisterAuthenticationAgentCancellable,
d->unregisterAuthenticationAgentCallback,
this);
}
void Authority::Private::unregisterAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority *) user_data;
Q_ASSERT(authority);
GError *error = NULL;
bool res = polkit_authority_unregister_authentication_agent_finish((PolkitAuthority *) object, result, &error);
if (error != NULL) {
// We don't want to set error if this is cancellation of some action
if (error->code != 1) {
authority->d->setError(E_UnregisterFailed, error->message);
}
g_error_free(error);
return;
}
TQ_EMIT authority->unregisterAuthenticationAgentFinished(res);
}
void Authority::unregisterAuthenticationAgentCancel()
{
if (!g_cancellable_is_cancelled(d->m_unregisterAuthenticationAgentCancellable)) {
g_cancellable_cancel(d->m_unregisterAuthenticationAgentCancellable);
}
}
bool Authority::authenticationAgentResponseSync(const TQString &cookie, const Identity &identity)
{
if (Authority::instance()->hasError()) {
return false;
}
if (cookie.isEmpty() || !identity.isValid()) {
d->setError(E_CookieOrIdentityEmpty);
return false;
}
GError *error = NULL;
bool result = polkit_authority_authentication_agent_response_sync(d->pkAuthority,
cookie.toUtf8().data(),
identity.identity(),
NULL,
&error);
if (error != NULL) {
d->setError(E_AgentResponseFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::authenticationAgentResponse(const TQString &cookie, const Identity &identity)
{
if (Authority::instance()->hasError()) {
return;
}
if (cookie.isEmpty() || !identity.isValid()) {
d->setError(E_CookieOrIdentityEmpty);
return;
}
polkit_authority_authentication_agent_response(d->pkAuthority,
cookie.toUtf8().data(),
identity.identity(),
d->m_authenticationAgentResponseCancellable,
d->authenticationAgentResponseCallback,
this);
}
void Authority::Private::authenticationAgentResponseCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority *) user_data;
Q_ASSERT(authority);
GError *error = NULL;
bool res = polkit_authority_authentication_agent_response_finish((PolkitAuthority *) object, result, &error);
if (error != NULL) {
// We don't want to set error if this is cancellation of some action
if (error->code != 1) {
authority->d->setError(E_AgentResponseFailed, error->message);
}
g_error_free(error);
return;
}
TQ_EMIT authority->authenticationAgentResponseFinished(res);
}
void Authority::authenticationAgentResponseCancel()
{
if (!g_cancellable_is_cancelled(d->m_authenticationAgentResponseCancellable)) {
g_cancellable_cancel(d->m_authenticationAgentResponseCancellable);
}
}
TemporaryAuthorization::List Authority::enumerateTemporaryAuthorizationsSync(const Subject &subject)
{
TemporaryAuthorization::List result;
GError *error = NULL;
GList *glist = polkit_authority_enumerate_temporary_authorizations_sync(d->pkAuthority,
subject.subject(),
NULL,
&error);
if (error != NULL) {
d->setError(E_EnumFailed, error->message);
g_error_free(error);
return result;
}
GList *glist2;
for (glist2 = glist; glist2 != NULL; glist2 = g_list_next(glist2)) {
result.append(TemporaryAuthorization((PolkitTemporaryAuthorization *) glist2->data));
g_object_unref(glist2->data);
}
g_list_free(glist);
return result;
}
void Authority::Private::enumerateTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority *) user_data;
Q_ASSERT(authority);
GError *error = NULL;
GList *glist = polkit_authority_enumerate_temporary_authorizations_finish((PolkitAuthority *) object, result, &error);
if (error != NULL) {
// We don't want to set error if this is cancellation of some action
if (error->code != 1) {
authority->d->setError(E_EnumFailed, error->message);
}
g_error_free(error);
return;
}
TemporaryAuthorization::List res;
GList *glist2;
for (glist2 = glist; glist2 != NULL; glist2 = g_list_next(glist2)) {
res.append(TemporaryAuthorization((PolkitTemporaryAuthorization *) glist2->data));
g_object_unref(glist2->data);
}
g_list_free(glist);
TQ_EMIT authority->enumerateTemporaryAuthorizationsFinished(res);
}
void Authority::enumerateTemporaryAuthorizationsCancel()
{
if (!g_cancellable_is_cancelled(d->m_enumerateTemporaryAuthorizationsCancellable)) {
g_cancellable_cancel(d->m_enumerateTemporaryAuthorizationsCancellable);
}
}
bool Authority::revokeTemporaryAuthorizationsSync(const Subject &subject)
{
bool result;
if (Authority::instance()->hasError()) {
return false;
}
GError *error = NULL;
result = polkit_authority_revoke_temporary_authorizations_sync(d->pkAuthority,
subject.subject(),
NULL,
&error);
if (error != NULL) {
d->setError(E_RevokeFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::revokeTemporaryAuthorizations(const Subject &subject)
{
if (Authority::instance()->hasError()) {
return;
}
polkit_authority_revoke_temporary_authorizations(d->pkAuthority,
subject.subject(),
d->m_revokeTemporaryAuthorizationsCancellable,
d->revokeTemporaryAuthorizationsCallback,
this);
}
void Authority::Private::revokeTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority *) user_data;
Q_ASSERT(authority != NULL);
GError *error = NULL;
bool res = polkit_authority_revoke_temporary_authorizations_finish((PolkitAuthority *) object, result, &error);
if (error != NULL) {
// We don't want to set error if this is cancellation of some action
if (error->code != 1) {
authority->d->setError(E_RevokeFailed, error->message);
}
g_error_free(error);
return;
}
TQ_EMIT authority->revokeTemporaryAuthorizationsFinished(res);
}
void Authority::revokeTemporaryAuthorizationsCancel()
{
if (!g_cancellable_is_cancelled(d->m_revokeTemporaryAuthorizationsCancellable)) {
g_cancellable_cancel(d->m_revokeTemporaryAuthorizationsCancellable);
}
}
bool Authority::revokeTemporaryAuthorizationSync(const TQString &id)
{
bool result;
if (Authority::instance()->hasError()) {
return false;
}
GError *error = NULL;
result = polkit_authority_revoke_temporary_authorization_by_id_sync(d->pkAuthority,
id.toUtf8().data(),
NULL,
&error);
if (error != NULL) {
d->setError(E_RevokeFailed, error->message);
g_error_free(error);
return false;
}
return result;
}
void Authority::revokeTemporaryAuthorization(const TQString &id)
{
if (Authority::instance()->hasError()) {
return;
}
polkit_authority_revoke_temporary_authorization_by_id(d->pkAuthority,
id.toUtf8().data(),
d->m_revokeTemporaryAuthorizationCancellable,
d->revokeTemporaryAuthorizationCallback,
this);
}
void Authority::Private::revokeTemporaryAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data)
{
Authority *authority = (Authority *) user_data;
Q_ASSERT(authority != NULL);
GError *error = NULL;
bool res = polkit_authority_revoke_temporary_authorization_by_id_finish((PolkitAuthority *) object, result, &error);
if (error != NULL) {
// We don't want to set error if this is cancellation of some action
if (error->code != 1) {
authority->d->setError(E_RevokeFailed, error->message);
}
g_error_free(error);
return;
}
TQ_EMIT authority->revokeTemporaryAuthorizationFinished(res);
}
void Authority::revokeTemporaryAuthorizationCancel()
{
if (!g_cancellable_is_cancelled(d->m_revokeTemporaryAuthorizationCancellable)) {
g_cancellable_cancel(d->m_revokeTemporaryAuthorizationCancellable);
}
}
}
#include "polkittqt1-authority.moc"

@ -1,99 +0,0 @@
/*
* 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.
*/
#include "polkittqt1-details.h"
#include <TQtCore/TQStringList>
#include <polkit/polkit.h>
namespace PolkitTQt
{
class Details::Data : public TQSharedData
{
public:
Data() {}
Data(const Data &other)
: TQSharedData(other)
, polkitDetails(other.polkitDetails)
{
g_object_ref(polkitDetails);
}
~Data()
{
g_object_unref(polkitDetails);
}
PolkitDetails *polkitDetails;
};
Details::Details()
: d(new Data)
{
g_type_init();
d->polkitDetails = polkit_details_new();
}
Details::Details(PolkitDetails *pkDetails)
: d(new Data)
{
g_type_init();
d->polkitDetails = pkDetails;
}
Details::~Details()
{
}
Details& Details::operator=(const PolkitTQt::Details& other)
{
d = other.d;
return *this;
}
TQString Details::lookup(const TQString &key) const
{
const gchar *result = polkit_details_lookup(d->polkitDetails, key.toUtf8().data());
if (result != NULL) {
return TQString::fromUtf8(result);
} else {
return TQString();
}
}
void Details::insert(const TQString &key, const TQString &value)
{
polkit_details_insert(d->polkitDetails, key.toUtf8().data(), value.toUtf8().data());
}
TQStringList Details::keys() const
{
gchar **result = polkit_details_get_keys(d->polkitDetails);
TQStringList list;
int len = g_strv_length(result);
for (int i = 0; i < len; i++) {
list.append(TQString::fromUtf8(result[i]));
}
g_strfreev(result);
return list;
}
}

@ -1,227 +0,0 @@
/*
* This file is part of the Polkit-tqt project
* Copyright (C) 2009 Lukas Tinkl <ltinkl@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-identity.h"
#include <polkit/polkit.h>
#include <TQtCore/TQDebug>
namespace PolkitTQt
{
class Identity::Data : public TQSharedData
{
public:
Data() : identity(0) {}
Data(const Data& other)
: TQSharedData(other)
, identity(other.identity)
{
if (identity) {
g_object_ref(identity);
}
}
~Data()
{
if (identity) {
g_object_unref(identity);
}
}
PolkitIdentity *identity;
};
Identity::Identity()
: d(new Data)
{
g_type_init();
}
Identity::Identity(PolkitIdentity *polkitIdentity)
: d(new Data)
{
g_type_init();
d->identity = polkitIdentity;
if (d->identity) {
g_object_ref(d->identity);
}
}
Identity::Identity(const PolkitTQt::Identity& other)
: d(other.d)
{
}
Identity::~Identity()
{
}
Identity& Identity::operator=(const PolkitTQt::Identity& other)
{
d = other.d;
return *this;
}
bool Identity::isValid() const
{
return d->identity != NULL;
}
PolkitIdentity *Identity::identity() const
{
return d->identity;
}
void Identity::setIdentity(PolkitIdentity *identity)
{
if (d->identity == identity) {
return;
}
if (d->identity) {
g_object_unref(d->identity);
}
d->identity = identity;
if (d->identity) {
g_object_ref(d->identity);
}
}
TQString Identity::toString() const
{
Q_ASSERT(d->identity);
return TQString::fromUtf8(polkit_identity_to_string(d->identity));
}
Identity Identity::fromString(const TQString &string)
{
GError *error = NULL;
PolkitIdentity *pkIdentity = polkit_identity_from_string(string.toUtf8().data(), &error);
if (error != NULL) {
tqWarning() << TQString("Cannot create Identity from string: %1").arg(error->message);
return Identity();
}
return Identity(pkIdentity);
}
UnixGroupIdentity Identity::toUnixGroupIdentity()
{
UnixGroupIdentity *ugid = static_cast< UnixGroupIdentity* >(this);
if (!ugid) {
return UnixGroupIdentity();
}
return *ugid;
}
UnixUserIdentity Identity::toUnixUserIdentity()
{
UnixUserIdentity *uuid = static_cast< UnixUserIdentity* >(this);
if (!uuid) {
return UnixUserIdentity();
}
return *uuid;
}
UnixUserIdentity::UnixUserIdentity(const TQString &name)
: Identity()
{
GError *error = NULL;
setIdentity(polkit_unix_user_new_for_name(name.toUtf8().data(), &error));
if (error != NULL) {
tqWarning() << TQString("Cannot create UnixUserIdentity: %1").arg(error->message);
setIdentity(NULL);
}
}
UnixUserIdentity::UnixUserIdentity(uid_t uid)
: Identity()
{
setIdentity(polkit_unix_user_new(uid));
}
UnixUserIdentity::UnixUserIdentity(PolkitUnixUser *pkUnixUser)
: Identity((PolkitIdentity *)pkUnixUser)
{
}
UnixUserIdentity::UnixUserIdentity()
: Identity()
{
}
uid_t UnixUserIdentity::uid() const
{
return polkit_unix_user_get_uid((PolkitUnixUser *) identity());
}
void UnixUserIdentity::setUid(uid_t uid)
{
polkit_unix_user_set_uid((PolkitUnixUser *) identity(), uid);
}
UnixGroupIdentity::UnixGroupIdentity(const TQString &name)
: Identity()
{
GError *error = NULL;
setIdentity(polkit_unix_group_new_for_name(name.toUtf8().data(), &error));
if (error != NULL) {
tqWarning() << TQString("Cannot create UnixGroupIdentity: %1").arg(error->message);
setIdentity(NULL);
}
}
UnixGroupIdentity::UnixGroupIdentity(gid_t gid)
: Identity()
{
setIdentity(polkit_unix_group_new(gid));
}
UnixGroupIdentity::UnixGroupIdentity(PolkitUnixGroup *pkUnixGroup)
: Identity((PolkitIdentity *) pkUnixGroup)
{
}
UnixGroupIdentity::UnixGroupIdentity()
: Identity()
{
}
gid_t UnixGroupIdentity::gid() const
{
return polkit_unix_group_get_gid((PolkitUnixGroup *) identity());
}
void UnixGroupIdentity::setGid(gid_t gid)
{
polkit_unix_group_set_gid((PolkitUnixGroup *) identity(), gid);
}
}

@ -1,117 +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-temporaryauthorization.h"
#include "polkittqt1-authority.h"
#include <polkit/polkit.h>
namespace PolkitTQt
{
class TemporaryAuthorization::Data : public TQSharedData
{
public:
Data() {}
Data(const Data& other)
: TQSharedData(other)
, id(other.id)
, actionId(other.actionId)
, subject(other.subject)
, timeObtained(other.timeObtained)
, timeExpires(other.timeExpires)
{
}
~Data() {}
TQString id;
TQString actionId;
Subject subject;
TQDateTime timeObtained;
TQDateTime timeExpires;
};
TemporaryAuthorization::TemporaryAuthorization(PolkitTemporaryAuthorization *pkTemporaryAuthorization)
: d(new Data)
{
g_type_init();
d->id = TQString::fromUtf8(polkit_temporary_authorization_get_id(pkTemporaryAuthorization));
d->actionId = TQString::fromUtf8(polkit_temporary_authorization_get_action_id(pkTemporaryAuthorization));
d->subject = Subject::fromString(polkit_subject_to_string(polkit_temporary_authorization_get_subject(pkTemporaryAuthorization)));
d->timeObtained = TQDateTime::fromTime_t(polkit_temporary_authorization_get_time_obtained(pkTemporaryAuthorization));
d->timeExpires = TQDateTime::fromTime_t(polkit_temporary_authorization_get_time_expires(pkTemporaryAuthorization));
g_object_unref(pkTemporaryAuthorization);
}
TemporaryAuthorization::TemporaryAuthorization(const PolkitTQt::TemporaryAuthorization& other)
: d(other.d)
{
}
TemporaryAuthorization::TemporaryAuthorization()
: d(new Data)
{
}
TemporaryAuthorization& TemporaryAuthorization::operator=(const PolkitTQt::TemporaryAuthorization& other)
{
d = other.d;
return *this;
}
TemporaryAuthorization::~TemporaryAuthorization()
{
}
TQString TemporaryAuthorization::id() const
{
return d->id;
}
TQString TemporaryAuthorization::actionId() const
{
return d->actionId;
}
Subject TemporaryAuthorization::subject() const
{
//tqFatal(polkit_subject_to_string(polkit_temporary_authorization_get_subject(d->temporaryAuthorization)));
return d->subject;//Subject::fromString(polkit_subject_to_string(d->subject));
}
TQDateTime TemporaryAuthorization::obtainedAt() const
{
return d->timeObtained;
}
TQDateTime TemporaryAuthorization::expirationTime() const
{
return d->timeExpires;
}
bool TemporaryAuthorization::revoke()
{
Authority::instance()->revokeTemporaryAuthorization(id());
return true;
}
}

4
debian/control vendored

@ -3,10 +3,10 @@ Section: devel
Priority: optional
Maintainer: TDE Debian Team <team-debian@trinitydesktop.org>
XSBC-Original-Maintainer: Debian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Build-Depends: cdbs, debhelper (>= 9~), quilt, cmake-trinity, ninja-build, libtqtinterface-dev
Build-Depends: cdbs, debhelper (>= 9~), quilt, cmake-trinity, ninja-build, libtqtinterface-dev,
libpolkit-gobject-1-dev (>= 0.98)
#, libdbus-1-dev (>= 0.90)
# libpolkit-agent-1-dev (>= 0.98),
# libpolkit-gobject-1-dev (>= 0.98),
# libqt4-dev,
# pkg-kde-tools (>= 0.11)
Standards-Version: 3.9.2

@ -1,26 +1,26 @@
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/ActionDescription
debian/tmp/usr/include/polkit-tqt/PolkitTQt/ActionDescription
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Agent/Listener
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Agent/Session
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Authority
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Details
debian/tmp/usr/include/polkit-tqt/PolkitTQt/Authority
debian/tmp/usr/include/polkit-tqt/PolkitTQt/Details
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Gui/Action
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Gui/ActionButton
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Gui/ActionButtons
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Identity
debian/tmp/usr/include/polkit-tqt/PolkitTQt/Identity
debian/tmp/usr/include/polkit-tqt/PolkitTQt/Subject
#debian/tmp/usr/include/polkit-tqt/PolkitTQt/TemporaryAuthorization
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-actiondescription.h
debian/tmp/usr/include/polkit-tqt/PolkitTQt/TemporaryAuthorization
debian/tmp/usr/include/polkit-tqt/polkit-tqt-actiondescription.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-agent-listener.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-agent-session.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-authority.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-details.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-export.h
debian/tmp/usr/include/polkit-tqt/polkit-tqt-authority.h
debian/tmp/usr/include/polkit-tqt/polkit-tqt-details.h
debian/tmp/usr/include/polkit-tqt/polkit-tqt-export.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-gui-action.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-gui-actionbutton.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-gui-actionbuttons.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-identity.h
debian/tmp/usr/include/polkit-tqt/polkit-tqt-identity.h
debian/tmp/usr/include/polkit-tqt/polkit-tqt-subject.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-temporaryauthorization.h
debian/tmp/usr/include/polkit-tqt/polkit-tqt-temporaryauthorization.h
#debian/tmp/usr/include/polkit-tqt/polkit-tqt-version.h
#debian/tmp/usr/lib/cmake/PolkitTQt-1/PolkitTQt-1Config.cmake
#debian/tmp/usr/lib/cmake/PolkitTQt-1/PolkitTQt-1ConfigVersion.cmake

@ -1 +1 @@
#include "../polkittqt1-actiondescription.h"
#include "../polkit-tqt-actiondescription.h"

@ -1 +1 @@
#include "../polkittqt1-authority.h"
#include "../polkit-tqt-authority.h"

@ -1 +1 @@
#include "../polkittqt1-details.h"
#include "../polkit-tqt-details.h"

@ -1 +1 @@
#include "../polkittqt1-identity.h"
#include "../polkit-tqt-identity.h"

@ -1 +1 @@
#include "../polkittqt1-temporaryauthorization.h"
#include "../polkit-tqt-temporaryauthorization.h"

Loading…
Cancel
Save