Converted first part of examples code.

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

@ -36,6 +36,13 @@ option( WITH_ALL_OPTIONS "Enable all optional support" OFF )
option( WITH_GCC_VISIBILITY "Enable fvisibility and fvisibility-inlines-hidden" ${WITH_ALL_OPTIONS} ) option( WITH_GCC_VISIBILITY "Enable fvisibility and fvisibility-inlines-hidden" ${WITH_ALL_OPTIONS} )
##### user requested modules
option( BUILD_ALL "Build all" OFF )
option( BUILD_EXAMPLES "Build examples" ${BUILD_ALL} )
option( BUILD_TESTS "Builds unit tests" ${BUILD_ALL} )
##### configure checks ########################## ##### configure checks ##########################
include( ConfigureChecks.cmake ) include( ConfigureChecks.cmake )
@ -48,6 +55,8 @@ tde_setup_install_path( BIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/bin" )
tde_setup_install_path( LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}" ) tde_setup_install_path( LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}" )
tde_setup_install_path( INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}" ) tde_setup_install_path( INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}" )
tde_setup_install_path( PKGCONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/pkgconfig" ) tde_setup_install_path( PKGCONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/pkgconfig" )
tde_setup_install_path( SHARE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/share" )
tde_setup_install_path( DATA_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/apps" )
##### write pkgconfig file ###################### ##### write pkgconfig file ######################
@ -80,10 +89,11 @@ add_definitions(
##### source directories ######################## ##### source directories ########################
add_subdirectory(core) add_subdirectory( core )
add_subdirectory(gui) add_subdirectory( gui )
add_subdirectory(agent) add_subdirectory( agent )
add_subdirectory(tests) tde_conditional_add_subdirectory( BUILD_EXAMPLES examples )
tde_conditional_add_subdirectory( BUILD_TESTS tests )
##### install files #### ######################## ##### install files #### ########################
@ -124,23 +134,6 @@ install(
DESTINATION DESTINATION
${INCLUDE_INSTALL_DIR} ) ${INCLUDE_INSTALL_DIR} )
##
## include (${TQT_USE_FILE})
## include (InstallSettings)
## include (MacroWriteBasicCMakeVersionFile)
## include (CheckFunctionExists)
##
## include_directories(
## ${CMAKE_CURRENT_BINARY_DIR}
## ${POLKIT_AGENT_INCLUDE_DIR}
## ${GLIB2_INCLUDE_DIR}
## ${GOBJECT_INCLUDE_DIR}
## ${GIO_INCLUDE_DIR}
## ${CMAKE_CURRENT_SOURCE_DIR}
## ${CMAKE_CURRENT_SOURCE_DIR}/core
## ${CMAKE_CURRENT_SOURCE_DIR}/includes
## ${TQT_TQTXML_INCLUDE_DIR}
## )
## ##
## if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} VERSION_GREATER 2.6.2) ## 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) ## 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)
@ -153,18 +146,6 @@ install(
## ##
## configure_file(polkittqt1-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/polkittqt1-version.h) ## configure_file(polkittqt1-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/polkittqt1-version.h)
## ##
## install(FILES
##
## agent/polkittqt1-agent-listener.h
## agent/polkittqt1-agent-session.h
##
## ${CMAKE_CURRENT_BINARY_DIR}/polkittqt1-version.h
## polkit-tqt-export.h
##
## DESTINATION
## ${INCLUDE_INSTALL_DIR}/polkit-qt-1 )
##
##
## # CMake Config files ## # CMake Config files
## configure_file(PolkitTQt-1Config.cmake.in "${CMAKE_BINARY_DIR}/PolkitTQt-1Config.cmake" @ONLY) ## configure_file(PolkitTQt-1Config.cmake.in "${CMAKE_BINARY_DIR}/PolkitTQt-1Config.cmake" @ONLY)
## ##
@ -182,15 +163,4 @@ install(
## ${CMAKE_BINARY_DIR}/PolkitTQt-1Config.cmake ## ${CMAKE_BINARY_DIR}/PolkitTQt-1Config.cmake
## DESTINATION ${_PolkitTQt-1Config_INSTALL_DIR} ) ## DESTINATION ${_PolkitTQt-1Config_INSTALL_DIR} )
## ##
## option(BUILD_EXAMPLES "Builds a set of examples for polkit-qt-1" OFF)
## if (BUILD_EXAMPLES)
## add_subdirectory(examples)
## endif (BUILD_EXAMPLES)
##
## add_subdirectory(cmake)
##
## option(BUILD_TEST "Builds unit tests for polkit-qt-1" OFF)
## if (BUILD_TEST)
## add_subdirectory(test)
## endif (BUILD_TEST)

@ -34,6 +34,12 @@ if( NOT POLKIT_AGENT_FOUND )
tde_message_fatal( "polkit-agent-1 is required, but was not found on your system" ) tde_message_fatal( "polkit-agent-1 is required, but was not found on your system" )
endif( ) endif( )
# check for dbus-1-tqt
pkg_search_module( DBUS_TQT dbus-1-tqt )
if( NOT DBUS_TQT_FOUND )
tde_message_fatal( "dbus-1-tqt is required, but was not found on your system" )
endif( )
# gcc visibility # gcc visibility
if( WITH_GCC_VISIBILITY ) if( WITH_GCC_VISIBILITY )
tde_setup_gcc_visibility( ) tde_setup_gcc_visibility( )

27
debian/control vendored

@ -4,22 +4,20 @@ Priority: optional
Maintainer: TDE Debian Team <team-debian@trinitydesktop.org> Maintainer: TDE Debian Team <team-debian@trinitydesktop.org>
XSBC-Original-Maintainer: Debian Qt/KDE Maintainers <debian-qt-kde@lists.debian.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, libpolkit-agent-1-dev libpolkit-gobject-1-dev, libpolkit-agent-1-dev, libdbus-1-tqt-dev
Standards-Version: 3.9.2 Standards-Version: 3.9.2
Package: libpolkit-tqt-dev Package: libpolkit-tqt-dev
Section: libdevel Section: libdevel
Architecture: any Architecture: any
Depends: libpolkit-tqt (= ${binary:Version}), libtqtinterface-dev Depends: libpolkit-tqt (= ${binary:Version}), libtqtinterface-dev
#, libdbus-1-dev (>= 0.90) Suggests: libpolkit-tqt-examples
#, libqt4-dev, ${misc:Depends}
Description: PolicyKit-tqt development files Description: PolicyKit-tqt development files
PolicyKit is an application-level toolkit for defining and handling the policy PolicyKit is an application-level toolkit for defining and handling the policy
that allows unprivileged processes to speak to privileged processes. that allows unprivileged processes to speak to privileged processes.
. .
It is a framework for centralizing the decision making process with respect to It is a framework for centralizing the decision making process with respect to
granting access to privileged operations (like calling the HAL Mount() method) granting access to privileged operations for unprivileged (desktop) applications.
for unprivileged (desktop) applications.
. .
libpolkit-tqt provides convenience classes and methods for TQt/TDE libpolkit-tqt provides convenience classes and methods for TQt/TDE
applications that want to use PolicyKit. applications that want to use PolicyKit.
@ -35,8 +33,7 @@ Description: PolicyKit-tqt library
that allows unprivileged processes to speak to privileged processes. that allows unprivileged processes to speak to privileged processes.
. .
It is a framework for centralizing the decision making process with respect to It is a framework for centralizing the decision making process with respect to
granting access to privileged operations (like calling the HAL Mount() method) granting access to privileged operations for unprivileged (desktop) applications.
for unprivileged (desktop) applications.
. .
libpolkit-tqt provides convenience classes and methods for TQt/TDE libpolkit-tqt provides convenience classes and methods for TQt/TDE
applications that want to use PolicyKit. applications that want to use PolicyKit.
@ -44,3 +41,19 @@ Description: PolicyKit-tqt library
This package contains the files necessary for running applications that use This package contains the files necessary for running applications that use
the libpolkit-tqt library. the libpolkit-tqt library.
Package: libpolkit-tqt-examples
Section: libs
Architecture: any
Depends: ${shlibs:Depends}, policykit-1
Description: PolicyKit-tqt library example files
PolicyKit is an application-level toolkit for defining and handling the policy
that allows unprivileged processes to speak to privileged processes.
.
It is a framework for centralizing the decision making process with respect to
granting access to privileged operations for unprivileged (desktop) applications.
.
libpolkit-tqt provides convenience classes and methods for TQt/TDE
applications that want to use PolicyKit.
.
This package contains example files and applications.

@ -0,0 +1,8 @@
debian/tmp/etc/dbus-1/system.d/org.tqt.policykit.examples.conf
debian/tmp/usr/bin/polkit-tqt-example
debian/tmp/usr/bin/polkit-tqt-example-helper
debian/tmp/usr/share/apps/polkit-tqt/examples/*
debian/tmp/usr/share/apps/polkit-tqt/icons/*
debian/tmp/usr/share/dbus-1/system-services/org.tqt.policykit.examples.service
debian/tmp/usr/share/polkit-1/actions/org.tqt.policykit.examples.policy

3
debian/rules vendored

@ -10,7 +10,8 @@ DEB_CMAKE_EXTRA_FLAGS := \
-DCMAKE_SKIP_RPATH="OFF" \ -DCMAKE_SKIP_RPATH="OFF" \
-DCMAKE_VERBOSE_MAKEFILE="ON" \ -DCMAKE_VERBOSE_MAKEFILE="ON" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DWITH_ALL_OPTIONS="ON" -DWITH_ALL_OPTIONS="ON" \
-DBUILD_ALL="ON"
DEB_MAKE_CHECK_TARGET = check DEB_MAKE_CHECK_TARGET = check

@ -1,89 +1,99 @@
#################################################
#
# (C) 2021 Michele Calgaro
# Michele (DOT) Calgaro (AT) yahoo.it
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 2
#
#################################################
install(FILES org.qt.policykit.examples.policy DESTINATION ${SHARE_INSTALL_PREFIX}/polkit-1/actions/)
include_directories( include_directories(
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/core
${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/gui
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${TQT_INCLUDE_DIRS}
${DBUS_TQT_INCLUDE_DIRS}
) )
set(polkit_example_SRCS link_directories(
main.cpp ${TQT_LIBRARY_DIRS}
PkExample.cpp
) )
SET(polkit_example_RESOUCES
icons/icons.qrc
)
QT4_WRAP_CPP(polkit_example_MOC_SRCS ##### install paths setup #######################
PkExample.h
)
QT4_WRAP_UI(polkit_example_UI_SRCS tde_setup_dbus( dbus-1-tqt )
PkExample.ui
) set( POLKIT_TQT_EXAMPLE "${DATA_INSTALL_DIR}/polkit-tqt/examples/" )
QT4_ADD_RESOURCES (qtsourceview_RC_SRCS ${polkit_example_RESOUCES}) ##### install examples runtime config ###########################
add_executable(polkit-example configure_file( org.tqt.policykit.examples.service.cmake org.tqt.policykit.examples.service @ONLY )
${polkit_example_SRCS}
${polkit_example_MOC_SRCS} install(
${polkit_example_UI_SRCS} FILES org.tqt.policykit.examples.policy
${qtsourceview_RC_SRCS} DESTINATION ${SHARE_INSTALL_PREFIX}/polkit-1/actions/
) )
target_link_libraries(polkit-example install(
${QT_QTCORE_LIBRARY} FILES org.tqt.policykit.examples.conf
${QT_QTGUI_LIBRARY} DESTINATION ${DBUS_SYSTEM_CONF_DIRECTORY}
polkit-qt-gui-1
polkit-qt-core-1
) )
#--------Helper Application install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tqt.policykit.examples.service
# This macro is defined in FindPolkitQt.cmake DESTINATION ${DBUS_SERVICE_DIRECTORY}
macro(dbus_add_activation_system_service _sources)
foreach (_i ${_sources})
get_filename_component(_service_file ${_i} ABSOLUTE)
string(REGEX REPLACE "\\.service.*$" ".service" _output_file ${_i})
set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_output_file})
configure_file(${_service_file} ${_target})
install(FILES ${_target} DESTINATION ${SHARE_INSTALL_PREFIX}/dbus-1/system-services )
#install(FILES ${_target} DESTINATION ${_install_dir})
endforeach (_i ${ARGN})
endmacro(dbus_add_activation_system_service _sources)
set(polkit_example_helper_SRCS
PkExampleHelper.cpp
mainHelper.cpp
) )
qt4_add_dbus_adaptor(polkit_example_helper_SRCS
org.qt.policykit.examples.xml ##### install examples source code ###########################
PkExampleHelper.h
PkExampleHelper install(
FILES COPYING
DESTINATION ${POLKIT_TQT_EXAMPLE}
) )
QT4_WRAP_CPP(polkit_example_helper_MOC_SRCS install(
PkExampleHelper.h FILES
org.tqt.policykit.examples.conf
org.tqt.policykit.examples.policy
org.tqt.policykit.examples.xml
${CMAKE_CURRENT_BINARY_DIR}/org.tqt.policykit.examples.service
DESTINATION ${POLKIT_TQT_EXAMPLE}/config
) )
add_executable(polkit-example-helper install(
${polkit_example_helper_SRCS} FILES PkExample.h PkExample.cpp main.cpp
${polkit_example_helper_MOC_SRCS} DESTINATION ${POLKIT_TQT_EXAMPLE}/main
) )
# see our helper is pretty small :D install(
target_link_libraries(polkit-example-helper FILES PkExampleHelper.h PkExampleHelper.cpp mainHelper.cpp
${QT_QTCORE_LIBRARY} DESTINATION ${POLKIT_TQT_EXAMPLE}/helper
polkit-qt-core-1
) )
install(TARGETS polkit-example-helper DESTINATION ${BIN_INSTALL_DIR})
dbus_add_activation_system_service(org.qt.policykit.examples.service.in) ##### install icons ###########################
install(FILES org.qt.policykit.examples.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d) add_subdirectory( icons )
##### example executables #########################
tde_add_executable( polkit-tqt-example AUTOMOC
SOURCES PkExample.cpp main.cpp
LINK ${TQT_LIBRARIES} ${DBUS_TQT_LIBRARIES} polkit-tqt-core-shared polkit-tqt-gui-shared
DESTINATION ${BIN_INSTALL_DIR}
)
tde_add_executable( polkit-tqt-example-helper AUTOMOC
SOURCES PkExampleHelper.cpp mainHelper.cpp
LINK ${TQT_LIBRARIES} ${DBUS_TQT_LIBRARIES} polkit-tqt-core-shared
DESTINATION ${BIN_INSTALL_DIR}
)
add_subdirectory(agent)

@ -1,12 +1,12 @@
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 2, June 1991 Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
Preamble Preamble
The licenses for most software are designed to take away your The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public freedom to share and change it. By contrast, the GNU General Public
@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and The precise terms and conditions for copying, distribution and
modification follow. modification follow.
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains 0. This License applies to any program or other work which contains
@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally. of promoting the sharing and reuse of software generally.
NO WARRANTY NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES. POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it possible use to the public, the best way to achieve this is to make it

@ -21,220 +21,346 @@
#include "PkExample.h" #include "PkExample.h"
#include "gui/polkitqt1-gui-actionbutton.h" #include "gui/polkit-tqt-gui-actionbutton.h"
#include "gui/polkitqt1-gui-actionbuttons.h" #include "gui/polkit-tqt-gui-actionbuttons.h"
#include "core/polkitqt1-authority.h" #include "core/polkit-tqt-authority.h"
#include <TQtCore/TQDebug>
#include <TQtDBus/TQDBusMessage> #include <tqdbusconnection.h>
#include <TQtDBus/TQDBusConnection> #include <tqdbuserror.h>
#include <tqdbusmessage.h>
#include <tqdbusproxy.h>
#include <tqvariant.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqcombobox.h>
#include <tqheader.h>
#include <tqlistview.h>
#include <tqlayout.h>
#include <tqtooltip.h>
#include <tqwhatsthis.h>
#include <tqaction.h>
#include <tqmenubar.h>
#include <tqpopupmenu.h>
#include <tqtoolbar.h>
using namespace PolkitTQt; using namespace PolkitTQt;
using namespace PolkitTQt::Gui; using namespace PolkitTQt::Gui;
PkExample::PkExample(TQMainWindow *parent)
: TQMainWindow(parent) PkExample::PkExample() : TQMainWindow(0, "Polkit tqt example application", WDestructiveClose)
{ {
setupUi(this); TQWidget *privateLayoutWidget = new TQWidget(this, "qt_central_widget");
setCentralWidget(privateLayoutWidget);
ActionButton *bt;
grid = new TQGridLayout(0, 9, 1, 0, 6, "grid");
// Here we create an ActionButton that is a subclass of Action grid->setColSpacing(0, 700);
// always pass a TQButton pointer and action id grid->setColSpacing(1, 200);
// You can change the action id later if you want
bt = new ActionButton(kickPB, "org.qt.policykit.examples.kick", this); kickL = new TQLabel(privateLayoutWidget, "kickL");
// Here we are setting the text and icon to all four states kickPB = new TQPushButton(privateLayoutWidget, "kickPB");
// an action might have grid->addWidget(kickL, 0, 0);
bt->setText("Kick!"); grid->addWidget(kickPB, 0, 1);
bt->setIcon(TQPixmap(":/Icons/custom-no.png"));
// By using set{Yes|No|Auth}Enabled you can set the states cryL = new TQLabel(privateLayoutWidget, "cryL");
// when the button is enabled cryPB = new TQPushButton(privateLayoutWidget, "cryPB");
bt->setEnabled(true, Action::No); grid->addWidget(cryL, 1, 0);
// As ActionButton is also an Action we cast it to add to menu grid->addWidget(cryPB, 1, 1);
menuActions->addAction(qobject_cast<Action *>(bt));
toolBar->addAction(qobject_cast<Action *>(bt)); bleedL = new TQLabel(privateLayoutWidget, "bleedL");
// this signal is emitted when the user click on the action, bleedPB = new TQPushButton(privateLayoutWidget, "bleedPB");
// it will only happen if it was inserted in a TQMenu or a TQToolBar grid->addWidget(bleedL, 2, 0);
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); grid->addWidget(bleedPB, 2, 1);
// This signal was propagated from the TQButton just for
// convenience in this case we don't have any benefit but the code playL = new TQLabel(privateLayoutWidget, "playL");
// look cleaner playPB = new TQPushButton(privateLayoutWidget, "playPB");
connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); grid->addWidget(playL, 3, 0);
// this is the Action activated signal, it is always emmited whenever grid->addWidget(playPB, 3, 1);
// someone click and get authorized to do the action
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); listenL = new TQLabel(privateLayoutWidget, "listenL");
listenPB = new TQPushButton(privateLayoutWidget, "listenPB");
bt = new ActionButton(cryPB, "org.qt.policykit.examples.cry", this); grid->addWidget(listenL, 4, 0);
bt->setText("Cry!"); grid->addWidget(listenPB, 4, 1);
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"));
menuActions->addAction(qobject_cast<Action *>(bt)); deleteL = new TQLabel(privateLayoutWidget, "deleteL");
toolBar->addAction(qobject_cast<Action *>(bt)); deletePB = new TQPushButton(privateLayoutWidget, "deletePB");
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); grid->addWidget(deleteL, 5, 0);
connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); grid->addWidget(deletePB, 5, 1);
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
deleteL_2 = new TQLabel(privateLayoutWidget, "deleteL_2");
bt = new ActionButton(bleedPB, "org.qt.policykit.examples.bleed", this); setCB = new TQComboBox(FALSE, privateLayoutWidget, "setCB");
bt->setText("Bleed!"); grid->addMultiCellWidget(deleteL_2, 6, 7, 0, 0);
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png")); grid->addWidget(setCB, 6, 1);
menuActions->addAction(qobject_cast<Action *>(bt));
toolBar->addAction(qobject_cast<Action *>(bt)); setPB = new TQPushButton(privateLayoutWidget, "setPB");
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); deleteL_3 = new TQLabel(privateLayoutWidget, "deleteL_3");
connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); grid->addWidget(setPB, 7, 1);
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); grid->addWidget(deleteL_3, 8, 0);
// This action is more customized shoutPB = new TQPushButton(privateLayoutWidget, "shoutPB");
bt = new ActionButton(playPB, "org.qt.policykit.examples.play", this); grid->addWidget(shoutPB, 8, 1);
bt->setText("Play!");
bt->setVisible(true, Action::No | Action::Auth | Action::Yes); vLayout = new TQVBoxLayout(privateLayoutWidget, 11, 6, "vLayout");
bt->setEnabled(true, Action::No | Action::Auth | Action::Yes); vLayout->addLayout(grid);
// here we set the behavior of PolKitResul = No
bt->setText("Can't play!", Action::No); actionList = new TQListView(privateLayoutWidget);
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), Action::No); actionList->addColumn("Action");
bt->setToolTip("If your admin wasn't annoying, you could do this", Action::No); actionList->addColumn("Result");
// here we set the behavior of PolKitResul = Auth actionList->setSorting(-1);
bt->setText("Play?", Action::Auth);
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), Action::Auth); vLayout->addWidget(actionList);
bt->setToolTip("Only card carrying tweakers can do this!", Action::Auth);
// here we set the behavior of PolKitResul = Yes // menubar
bt->setText("Play!", Action::Yes); menubar = new TQMenuBar(this, "menubar");
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes); menubar->setGeometry(TQRect(0, 0, 800, 22));
bt->setToolTip("Go ahead, play!", Action::Yes); menuActions = new TQPopupMenu(this);
menubar->insertItem(TQString(""), menuActions, 2);
menuActions->addAction(qobject_cast<Action *>(bt));
toolBar->addAction(qobject_cast<Action *>(bt)); // toolbars
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); toolBar = new TQToolBar(TQString(""), this, DockTop);
connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); // statusbar
statusBar();
bt = new ActionButton(deletePB, "org.qt.policykit.examples.delete", this);
bt->setText("Delete!"); languageChange();
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), Action::No); resize(TQSize(900, 700).expandedTo(minimumSizeHint()));
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), Action::Auth); clearWState(WState_Polished);
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes);
menuActions->addAction(qobject_cast<Action *>(bt)); // Setup actions
toolBar->addAction(qobject_cast<Action *>(bt)); ActionButton *bt;
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); // Here we create an ActionButton that is a subclass of Action
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); // always pass a TQButton pointer and action id
// You can change the action id later if you want
bt = new ActionButton(listenPB, "org.qt.policykit.examples.listen", this); bt = new ActionButton(kickPB, "org.tqt.policykit.examples.kick", this);
bt->setText("Listen!"); // Here we are setting the text and icon to all four states
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), Action::No); // an action might have
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), Action::Auth); bt->setText("Kick!");
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"));
menuActions->addAction(qobject_cast<Action *>(bt)); // By using set{Yes|No|Auth}Enabled you can set the states
toolBar->addAction(qobject_cast<Action *>(bt)); // when the button is enabled
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); bt->setEnabled(true, Action::No);
connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); // As ActionButton is also an Action we cast it to add to menu
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); ::tqt_cast<TQAction*>(bt)->addTo(menuActions);
::tqt_cast<TQAction*>(bt)->addTo(toolBar);
bt = new ActionButton(setPB, "org.qt.policykit.examples.set", this); // this signal is emitted when the user click on the action,
bt->setText("Set!"); // it will only happen if it was inserted in a TQMenu or a TQToolBar
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), Action::No); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), Action::Auth); // This signal was propagated from the TQButton just for
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes); // convenience in this case we don't have any benefit but the code
menuActions->addAction(qobject_cast<Action *>(bt)); // look cleaner
toolBar->addAction(qobject_cast<Action *>(bt)); connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); // this is the Action activated signal, it is always emmited whenever
connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); // someone click and get authorized to do the action
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
bt = new ActionButton(shoutPB, "org.qt.policykit.examples.shout", this); bt = new ActionButton(cryPB, "org.tqt.policykit.examples.cry", this);
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), Action::No); bt->setText("Cry!");
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), Action::Auth); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"));
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes); ::tqt_cast<TQAction*>(bt)->addTo(menuActions);
bt->setText("Can't shout!", Action::No); ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
bt->setText("Shout?", Action::Auth); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
bt->setText("Shout!", Action::Yes); connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
menuActions->addAction(qobject_cast<Action *>(bt)); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
toolBar->addAction(qobject_cast<Action *>(bt));
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); bt = new ActionButton(bleedPB, "org.tqt.policykit.examples.bleed", this);
connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); bt->setText("Bleed!");
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"));
::tqt_cast<TQAction*>(bt)->addTo(menuActions);
// test configChanged ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
// This action is more customized
bt = new ActionButton(playPB, "org.tqt.policykit.examples.play", this);
bt->setText("Play!");
bt->setVisible(true, (Action::States)(Action::No | Action::Auth | Action::Yes));
bt->setEnabled(true, (Action::States)(Action::No | Action::Auth | Action::Yes));
// here we set the behavior of PolKitResul = No
bt->setText("Can't play!", Action::No);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"), Action::No);
bt->setToolTip("If your admin wasn't annoying, you could do this", Action::No);
// here we set the behavior of PolKitResul = Auth
bt->setText("Play?", Action::Auth);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"), Action::Auth);
bt->setToolTip("Only card carrying tweakers can do this!", Action::Auth);
// here we set the behavior of PolKitResul = Yes
bt->setText("Play!", Action::Yes);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
bt->setToolTip("Go ahead, play!", Action::Yes);
::tqt_cast<TQAction*>(bt)->addTo(menuActions);
::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
bt = new ActionButton(listenPB, "org.tqt.policykit.examples.listen", this);
bt->setText("Listen!");
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"), Action::No);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"), Action::Auth);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
::tqt_cast<TQAction*>(bt)->addTo(menuActions);
::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
bt = new ActionButton(deletePB, "org.tqt.policykit.examples.delete", this);
bt->setText("Delete!");
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"), Action::No);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"), Action::Auth);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
::tqt_cast<TQAction*>(bt)->addTo(menuActions);
::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
bt = new ActionButton(setPB, "org.tqt.policykit.examples.set", this);
bt->setText("Set!");
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"), Action::No);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"), Action::Auth);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
::tqt_cast<TQAction*>(bt)->addTo(menuActions);
::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
bt = new ActionButton(shoutPB, "org.tqt.policykit.examples.shout", this);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"), Action::No);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"), Action::Auth);
bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
bt->setText("Can't shout!", Action::No);
bt->setText("Shout?", Action::Auth);
bt->setText("Shout!", Action::Yes);
::tqt_cast<TQAction*>(bt)->addTo(menuActions);
::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
} }
PkExample::~PkExample() void PkExample::languageChange()
{ {
setCaption(tr("PolicyKit-tqt example"));
kickL->setText(tr("Making the helper <b>Kick</b> is not allowed. Action cannot be activated."));
kickPB->setText(tr("Kick!"));
cryL->setText(tr("Making the helper <b>Cry</b> is always allowed. Action can be activated without authentication."));
cryPB->setText(tr("Cry!"));
bleedL->setText(tr("Making the helper <b>Bleed</b> requires the user to authenticate. This is a one-shot authorization."));
bleedPB->setText(tr("Bleed!"));
playL->setText(tr("Making the helper <b>Play</b> requires a system administrator to authenticate. This is a one-shot authorization."));
playPB->setText(tr("Play!"));
listenL->setText(tr("Making the helper <b>Listen</b> requires the user to authenticate. The authorization will be kept for a brief period."));
listenPB->setText(tr("Listen!"));
deleteL->setText(tr("Making the helper <b>Delete</b> requires a system administrator to authenticate. The authorization will be kept for a brief period."));
deletePB->setText(tr("Delete!"));
deleteL_2->setText(tr("<b>Set</b> is special action. It sets the permissions for the <b>Shout</b> action by actually using the helper application to change the implicit authorization."));
setCB->clear();
setCB->insertItem(tr("no"));
setCB->insertItem(tr("yes"));
setCB->insertItem(tr("auth_self"));
setCB->insertItem(tr("auth_admin"));
setCB->insertItem(tr("auth_self_keep"));
setCB->insertItem(tr("auth_admin_keep"));
setPB->setText(tr("Set!"));
deleteL_3->setText(tr("The implicit authorization for the <b>Shout</b> action is set by the <b>Set</b> action. You can watch how different options can change behaviour of this action."));
shoutPB->setText(tr("Shout!"));
toolBar->setCaption(tr("toolBar"));
if (menubar->findItem(2))
{
menubar->findItem(2)->setText(tr("&Actions"));
}
} }
void PkExample::activateAction() void PkExample::activateAction()
{ {
// Here we cast the sender() to an Action and call activate() // Here we cast the sender() to an Action and call activate() on it.
// on it. // Be careful in doing the same for ActionButton won't work as expected
// Be careful in doing the same for ActionButton won't work as expected // as action->activate() is calling Action::activate() and
// as action->activate() is calling Action::activate() and // not ActionButton::activate which are different.
// not ActionButton::activate which are different. // You can cast then to ActionButton but be carefull
// You can cast then to ActionButton but be carefull // an Action casted to ActionButton may crash you app
// an Action casted to ActionButton may crash you app Action *action = ::tqt_cast<Action*>(sender());
Action *action = qobject_cast<Action *>(sender()); // calling activate with winId() makes the auth dialog
// calling activate with winId() makes the auth dialog // be correct parented with your application.
// be correct parented with your application. action->activate();
action->activate();
} }
void PkExample::actionActivated() void PkExample::actionActivated()
{ {
// This slot is called whenever an action is allowed // This slot is called whenever an action is allowed
// here you will do your dirt job by calling a helper application // here you will do your dirt job by calling a helper application
// that might erase your hardrive ;) // that might erase your hardrive ;)
Action *action = qobject_cast<Action *>(sender()); Action *action = ::tqt_cast<Action*>(sender());
// this is our Special Action that after allowed will call the helper
if (action->is("org.qt.policykit.examples.set")) {
tqDebug() << "toggled for: org.qt.policykit.examples.set";
TQDBusMessage message;
message = TQDBusMessage::createMethodCall("org.qt.policykit.examples",
"/",
"org.qt.policykit.examples",
TQLatin1String("set"));
TQList<TQVariant> argumentList;
argumentList << qVariantFromValue(setCB->currentText());
message.setArguments(argumentList);
// notice the systemBus here..
TQDBusMessage reply = TQDBusConnection::systemBus().call(message);
if (reply.type() == TQDBusMessage::ReplyMessage
&& reply.arguments().size() == 1) {
// the reply can be anything, here we receive a bool
TQListWidgetItem *item;
if (reply.arguments().first().toBool())
item = new TQListWidgetItem(TQPixmap(":/Icons/custom-yes.png"),
TQString("Implicit authorization for shout has been set to %0")
.arg(setCB->currentText()));
else
item = new TQListWidgetItem(TQPixmap(":/Icons/custom-no.png"),
TQString("Can't change the implicit authorization. Denied."));
actionList->addItem(item);
tqDebug() << reply.arguments().first().toString();
} else if (reply.type() == TQDBusMessage::MethodCallMessage) {
tqWarning() << "Message did not receive a reply (timeout by message bus)";
}
return;
}
// As debug message says we are pretending to be the mechanism for the // this is our Special Action that after allowed will call the helper
// following action, here you will actually call your DBus helper that if (action->is("org.tqt.policykit.examples.set"))
// will run as root (setuid is not needed, see DBus docs). {
// In the helper application you will issue checkAuthorizationSync, tqDebug("toggled for: org.tqt.policykit.examples.set");
// passing the action id and the caller pid (which DBus will tell you).
tqDebug() << "pretending to be the mechanism for action:" << action->actionId(); TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
TQT_DBusProxy exampleProxy("org.tqt.policykit.examples", "/", "org.tqt.policykit.examples", dbusConn);
Authority::Result result; TQT_DBusError error;
UnixProcessSubject subject(static_cast<uint>(TQCoreApplication::applicationPid())); TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromString(setCB->currentText());
result = Authority::instance()->checkAuthorizationSync(action->actionId(), subject, TQT_DBusMessage reply = exampleProxy.sendWithReply("set", params, &error);
Authority::AllowUserInteraction); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1)
if (result == Authority::Yes) { {
// in the helper you will do the action // the reply can be anything, here we receive a bool
tqDebug() << "caller is authorized to do:" << action->actionId(); TQListViewItem *item;
TQListWidgetItem *item = new TQListWidgetItem(TQPixmap(":/Icons/custom-yes.png"), action->actionId()); if (reply[0].toBool())
actionList->addItem(item); {
} else { item = new TQListViewItem(actionList);
// OR return false to notify the caller that the action is not authorized. item->setText(0, TQString("Implicit authorization for shout has been set to ") +
tqDebug() << "caller is NOT authorized to do:" << action->actionId(); setCB->currentText());
TQListWidgetItem *item = new TQListWidgetItem(TQIcon(":/Icons/custom-no.png"), action->actionId()); item->setPixmap(1, TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"));
actionList->addItem(item); }
else
{
item = new TQListViewItem(actionList);
item->setText(0, TQString("Can't change the implicit authorization. Denied."));
item->setPixmap(1, TQPixmap("/usr/share/apps/icons/custom-no.png"));
}
actionList->insertItem(item);
}
else if (reply.type() == TQT_DBusMessage::MethodCallMessage)
{
tqDebug("Message did not receive a reply (timeout by message bus)");
} }
return;
}
// As debug message says we are pretending to be the mechanism for the
// following action, here you will actually call your DBus helper that
// will run as root (setuid is not needed, see DBus docs).
// In the helper application you will issue checkAuthorizationSync,
// passing the action id and the caller pid (which DBus will tell you).
tqDebug("Pretending to be the mechanism for action " + action->actionId());
Authority::Result result;
UnixProcessSubject subject(static_cast<uint>(getpid()));
result = Authority::instance()->checkAuthorizationSync(action->actionId(), subject,
Authority::AllowUserInteraction);
TQListViewItem *item;
item = new TQListViewItem(actionList);
item->setText(0, action->actionId());
if (result == Authority::Yes)
{
// in the helper you will do the action
tqDebug("caller is authorized to do: " + action->actionId());
item->setPixmap(1, TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"));
}
else
{
// or return false to notify the caller that the action is not authorized.
tqDebug("caller is NOT authorized to do: " + action->actionId());
item->setPixmap(1, TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"));
}
actionList->insertItem(item);
} }
#include "PkExample.moc"

@ -22,20 +22,60 @@
#ifndef PKEXAMPLE_H #ifndef PKEXAMPLE_H
#define PKEXAMPLE_H #define PKEXAMPLE_H
#include "ui_PkExample.h" #include <tqvariant.h>
#include <tqmainwindow.h>
class PkExample : public TQMainWindow, Ui::PkExample class TQVBoxLayout;
class TQGridLayout;
class TQSpacerItem;
class TQToolBar;
class TQPopupMenu;
class TQLabel;
class TQPushButton;
class TQComboBox;
class TQListView;
class PkExample : public TQMainWindow
{ {
Q_OBJECT TQ_OBJECT
public: public:
PkExample(TQMainWindow *parent = 0); PkExample();
~PkExample();
TQLabel *kickL;
TQPushButton *kickPB;
TQLabel *cryL;
TQPushButton *cryPB;
TQLabel *bleedL;
TQPushButton *bleedPB;
TQLabel *playL;
TQPushButton *playPB;
TQLabel *listenL;
TQPushButton *listenPB;
TQLabel *deleteL;
TQPushButton *deletePB;
TQLabel *deleteL_2;
TQComboBox *setCB;
TQPushButton *setPB;
TQLabel *deleteL_3;
TQPushButton *shoutPB;
TQListView *actionList;
TQMenuBar *menubar;
TQPopupMenu *menuActions;
TQToolBar *toolBar;
protected:
TQVBoxLayout *vLayout;
TQGridLayout *grid;
protected slots:
virtual void languageChange();
private Q_SLOTS: private slots:
void activateAction(); void activateAction();
void actionActivated(); void actionActivated();
};
};
#endif #endif

@ -1,234 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PkExample</class>
<widget class="TQMainWindow" name="PkExample">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>PolicyKit-qt example</string>
</property>
<widget class="TQWidget" name="centralwidget">
<layout class="TQHBoxLayout" name="horizontalLayout">
<item>
<layout class="TQGridLayout" name="gridLayout" columnstretch="3,1">
<item row="0" column="0">
<widget class="TQLabel" name="kickL">
<property name="text">
<string>Making the helper &lt;b&gt;Kick&lt;/b&gt; is not allowed. Action cannot be triggered.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="TQPushButton" name="kickPB">
<property name="text">
<string>Kick!</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="TQLabel" name="cryL">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Making the helper &lt;span style=&quot; font-weight:600;&quot;&gt;Cry&lt;/span&gt; is always allowed. Action can be triggered without authentication.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="TQPushButton" name="cryPB">
<property name="text">
<string>Cry!</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="TQLabel" name="bleedL">
<property name="text">
<string>Making the helper &lt;b&gt;Bleed&lt;/b&gt; requires the user to authenticate. This is a one-shot authorization.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="TQPushButton" name="bleedPB">
<property name="text">
<string>Bleed!</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="TQLabel" name="playL">
<property name="text">
<string>Making the helper &lt;b&gt;Play&lt;/b&gt; requires a system administrator to authenticate. This is a one-shot authorization.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="TQPushButton" name="playPB">
<property name="text">
<string>Play!</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="TQLabel" name="listenL">
<property name="text">
<string>Making the helper &lt;b&gt;Listen&lt;/b&gt; requires the user to authenticate. The authorization will be kept for a brief period.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="TQPushButton" name="listenPB">
<property name="text">
<string>Listen!</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="TQLabel" name="deleteL">
<property name="text">
<string>Making the helper &lt;b&gt;Delete&lt;/b&gt; requires a system administrator to authenticate. The authorization will be kept for a brief period.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="TQPushButton" name="deletePB">
<property name="text">
<string>Delete!</string>
</property>
</widget>
</item>
<item row="6" column="0" rowspan="2">
<widget class="TQLabel" name="deleteL_2">
<property name="text">
<string>&lt;b&gt;Set&lt;/b&gt; is special action. It sets the permissions for the &lt;b&gt;Shout&lt;/b&gt; action by actually using the helper application to change the implicit authorization.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="TQComboBox" name="setCB">
<item>
<property name="text">
<string>no</string>
</property>
</item>
<item>
<property name="text">
<string>yes</string>
</property>
</item>
<item>
<property name="text">
<string>auth_self</string>
</property>
</item>
<item>
<property name="text">
<string>auth_admin</string>
</property>
</item>
<item>
<property name="text">
<string>auth_self_keep</string>
</property>
</item>
<item>
<property name="text">
<string>auth_admin_keep</string>
</property>
</item>
</widget>
</item>
<item row="7" column="1">
<widget class="TQPushButton" name="setPB">
<property name="text">
<string>Set!</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="TQLabel" name="deleteL_3">
<property name="text">
<string>The implicit authorization for the &lt;b&gt;Shout&lt;/b&gt; action is set by the &lt;b&gt;Set&lt;/b&gt; action. You can watch how different options can change behaviour of this action.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="TQPushButton" name="shoutPB">
<property name="text">
<string>Shout!</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="TQListWidget" name="actionList"/>
</item>
</layout>
</widget>
<widget class="TQMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
</rect>
</property>
<widget class="TQMenu" name="menuActions">
<property name="title">
<string>Actions</string>
</property>
</widget>
<addaction name="menuActions"/>
</widget>
<widget class="TQToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<property name="toolButtonStyle">
<enum>TQt::ToolButtonTextUnderIcon</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
</widget>
<resources/>
<connections/>
</ui>

@ -20,91 +20,134 @@
***************************************************************************/ ***************************************************************************/
#include "PkExampleHelper.h" #include "PkExampleHelper.h"
#include "examplesadaptor.h"
#include "polkittqt-authority.h" #include "polkit-tqt-authority.h"
#include <TQtDBus/TQDBusConnection> #include <tqdbusdatalist.h>
#include <TQtCore/TQTimer> #include <tqdbuserror.h>
#include <TQtCore/TQDebug> #include <tqdbusmessage.h>
#include <TQtXml/TQDomDocument> #include <tqdom.h>
#include <tqfile.h>
#define MINUTE 60000 #include <tqtimer.h>
using namespace PolkitTQt; using namespace PolkitTQt;
PkExampleHelper::PkExampleHelper(int &argc, char **argv)
: TQCoreApplication(argc, argv)
{
tqDebug() << "Creating Helper";
(void) new ExamplesAdaptor(this);
// Register the DBus service
if (!TQDBusConnection::systemBus().registerService("org.tqt.policykit.examples")) {
tqDebug() << TQDBusConnection::systemBus().lastError().message();;
TQTimer::singleShot(0, this, SLOT(quit()));
return;
}
if (!TQDBusConnection::systemBus().registerObject("/", this)) { PkExampleHelper::PkExampleHelper(int &argc, char **argv) : TQApplication(argc, argv, false)
tqDebug() << "unable to register service interface to dbus"; {
TQTimer::singleShot(0, this, SLOT(quit())); tqDebug("Creating Helper");
return; // Register the DBus service
} m_connection = TQT_DBusConnection::systemBus();
// Normally you will set a timeout so your application can if (!m_connection.registerObject("/", this))
// free some resources of the poor client machine ;) {
TQTimer::singleShot(MINUTE, this, SLOT(quit())); tqDebug("unable to register 'org.tqt.policykit.examples' service interface to dbus");
tqDebug(m_connection.lastError().message());
return;
}
if (!m_connection.requestName("org.tqt.policykit.examples"))
{
tqDebug("unable to acquire 'org.tqt.policykit.examples' service interface to dbus");
tqDebug(m_connection.lastError().message());
return;
}
// Exit if not used for 10 minutes
TQTimer::singleShot(600000, this, TQT_SLOT(quit()));
tqDebug("Register successful");
} }
PkExampleHelper::~PkExampleHelper() PkExampleHelper::~PkExampleHelper()
{ {
tqDebug() << "Destroying Helper"; tqDebug("Destroying Helper");
m_connection.unregisterObject("org.tqt.policykit.examples");
} }
bool PkExampleHelper::set(const TQString &action) bool PkExampleHelper::handleMethodCall(const TQT_DBusMessage& message)
{ {
tqDebug() << "PkExampleHelper::set" << action; if (message.interface() != "org.tqt.policykit.examples")
// message().service() is the service name of the caller {
// We can check if the caller is authorized to the following action return false;
Authority::Result result; }
SystemBusNameSubject subject(message().service());
result = Authority::instance()->checkAuthorizationSync("org.tqt.policykit.examples.set", if (message.member() == "set")
subject , Authority::AllowUserInteraction); {
if (result == Authority::Yes) { // check parameters
tqDebug() << message().service() << TQString("Implicit authorization set to") << action; if (message.count() != 1 || message[0].type() != TQT_DBusData::String)
// Caller is authorized so we can perform the action {
return setValue(action); // method signature not what we expected
} else { TQT_DBusError error = TQT_DBusError::stdInvalidArgs(
tqDebug() << message().service() << TQString("Can't set the implicit authorization"); "Expected one argument of type string");
// Caller is not authorized so the action can't be performed TQT_DBusMessage reply = TQT_DBusMessage::methodError(message, error);
return false; m_connection.send(reply);
return true;
} }
bool res = set(message[0].toString());
TQT_DBusMessage reply = TQT_DBusMessage::methodReply(message);
reply << TQT_DBusData::fromBool(res);
m_connection.send(reply);
return true;
}
TQT_DBusMessage reply = TQT_DBusMessage::methodReply(message);
reply << TQT_DBusData::fromString("Bad request");
m_connection.send(reply);
return true;
}
bool PkExampleHelper::set(const TQString &action)
{
// We can check if the caller is authorized to the following action
SystemBusNameSubject subject(m_connection.uniqueName());
Authority::Result result;
result = Authority::instance()->checkAuthorizationSync("org.tqt.policykit.examples.set",
subject , Authority::AllowUserInteraction);
if (result == Authority::Yes)
{
// Caller is authorized so we can perform the action
tqDebug(TQString("Implicit authorization set to ") + action);
return setValue(action);
}
else
{
// Caller is not authorized so the action can't be performed
tqDebug(TQString("Can't set the implicit authorization to ") + action);
return false;
}
} }
bool PkExampleHelper::setValue(const TQString &action) bool PkExampleHelper::setValue(const TQString &action)
{ {
// This action must be authorized first. It will set the implicit // This action must be authorized first. It will set the implicit
// authorization for the Shout action by editing the .policy file // authorization for the Shout action by editing the .policy file
TQDomDocument doc = TQDomDocument("policy"); TQDomDocument doc = TQDomDocument("policy");
TQFile file("/usr/share/polkit-1/actions/org.tqt.policykit.examples.policy"); TQFile file("/usr/share/polkit-1/actions/org.tqt.policykit.examples.policy");
if (!file.open(TQIODevice::ReadOnly)) if (!file.open(IO_ReadOnly))
return false; {
doc.setContent(&file); return false;
file.close(); }
TQDomElement el = doc.firstChildElement("policyconfig"). doc.setContent(&file);
firstChildElement("action"); file.close();
while (!el.isNull() && el.attribute("id", TQString()) != "org.tqt.policykit.examples.shout") { TQDomElement el = doc.namedItem("policyconfig").namedItem("action").toElement();
el = el.nextSiblingElement("action"); while (!el.isNull() && el.attribute("id") != "org.tqt.policykit.examples.shout")
} {
el = el.firstChildElement("defaults"); el = el.nextSibling().toElement();
el = el.firstChildElement("allow_active"); }
if (el.isNull()) el = el.namedItem("defaults").toElement();
return false; el = el.namedItem("allow_active").toElement();
el.firstChild().toText().setData(action); if (el.isNull())
if (!file.open(TQIODevice::WriteOnly)) {
return false; return false;
TQTextStream stream(&file); }
doc.save(stream, 2); el.firstChild().toText().setData(action);
file.close(); if (!file.open(IO_WriteOnly))
return true; {
return false;
}
TQTextStream stream(&file);
doc.save(stream, 2);
file.close();
return true;
} }
#include "PkExampleHelper.moc"

@ -22,21 +22,27 @@
#ifndef PKEXAMPLE_HELPER_H #ifndef PKEXAMPLE_HELPER_H
#define PKEXAMPLE_HELPER_H #define PKEXAMPLE_HELPER_H
#include <TQtDBus/TQDBusContext> #include <tqdbusobject.h>
#include <TQtCore/TQCoreApplication> #include <tqdbusconnection.h>
#include "tqapplication.h"
class PkExampleHelper : public TQCoreApplication, protected TQDBusContext class PkExampleHelper : public TQApplication, public TQT_DBusObjectBase
{ {
Q_OBJECT Q_OBJECT
TQ_CLASSINFO("D-Bus Interface", "org.tqt.policykit.examples")
public: public:
PkExampleHelper(int &argc, char **argv); PkExampleHelper(int &argc, char **argv);
~PkExampleHelper(); ~PkExampleHelper();
public Q_SLOTS:
bool set(const TQString &action); bool set(const TQString &action);
bool setValue(const TQString &action); bool setValue(const TQString &action);
};
protected:
bool handleMethodCall(const TQT_DBusMessage& message);
private:
TQT_DBusConnection m_connection;
};
#endif #endif

@ -0,0 +1,16 @@
#################################################
#
# (C) 2021 Michele Calgaro
# Michele (DOT) Calgaro (AT) yahoo.it
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 2
#
#################################################
install(
FILES action-locked-default.png action-locked.png action-unlocked.png custom-yes.png custom-no.png
DESTINATION ${DATA_INSTALL_DIR}/polkit-tqt/icons
)

@ -1,9 +0,0 @@
<RCC>
<qresource prefix="Icons" >
<file>action-locked-default.png</file>
<file>action-locked.png</file>
<file>action-unlocked.png</file>
<file>custom-no.png</file>
<file>custom-yes.png</file>
</qresource>
</RCC>

@ -19,14 +19,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/ ***************************************************************************/
#include <TQtGui/TQApplication> #include <tqapplication.h>
#include "PkExample.h" #include "PkExample.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
TQApplication app(argc, argv); TQApplication app(argc, argv);
PkExample example; PkExample *example = new PkExample;
example.show(); example->show();
return app.exec(); app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
return app.exec();
} }

@ -21,8 +21,9 @@
#include "PkExampleHelper.h" #include "PkExampleHelper.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
PkExampleHelper example(argc, argv); PkExampleHelper example(argc, argv);
return example.exec(); return example.exec();
} }

@ -1,85 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
<policyconfig>
<vendor>KDE</vendor>
<vendor_url>http://www.kde.org</vendor_url>
<action id="org.tqt.policykit.examples.kick">
<description>Kick</description>
<message>Prevents PolicyKit-TQt example from kicking</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>no</allow_active>
</defaults>
</action>
<action id="org.tqt.policykit.examples.cry">
<description>Cry</description>
<message>Prevents PolicyKit-TQt example from crying</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>
<action id="org.tqt.policykit.examples.play">
<description>Play</description>
<message>Prevents PolicyKit-TQt example from playing</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_self</allow_active>
</defaults>
</action>
<action id="org.tqt.policykit.examples.bleed">
<description>Bleed</description>
<message>Prevents PolicyKit-TQt example from bleeding</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin</allow_active>
</defaults>
</action>
<action id="org.tqt.policykit.examples.listen">
<description>Listen</description>
<message>Prevents PolicyKit-TQt example from listening</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_self_keep</allow_active>
</defaults>
</action>
<action id="org.tqt.policykit.examples.delete">
<description>Delete</description>
<message>Prevents PolicyKit-TQt example from deleting</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
<!--
<action id="org.tqt.policykit.examples.shout">
<description>Shout</description>
<message>Prevents PolicyKit-TQt example from shouting</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.tqt.policykit.examples.shout">foo</annotate>
</action>
<action id="org.tqt.policykit.examples.push">
<description>Push</description>
<message>Prevents PolicyKit-TQt example from pushing</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.tqt.policykit.examples.push">bar</annotate>
</action>
<action id="org.tqt.policykit.examples.blow-up">
<description>Blow Up</description>
<message>Prevents PolicyKit-TQt example from blowing up</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.tqt.policykit.examples.blow-up">booo</annotate>
</action>
-->
</policyconfig>

@ -1,5 +1,5 @@
[D-BUS Service] [D-BUS Service]
Name=org.tqt.policykit.examples Name=org.tqt.policykit.examples
Exec=@BIN_INSTALL_DIR@/polkit-example-helper Exec=@BIN_INSTALL_DIR@/polkit-tqt-example-helper
User=root User=root

@ -100,7 +100,7 @@ class POLKIT_TQT_EXPORT Action : public TQAction
*/ */
void authorized(); void authorized();
public slots: public slots:
/** /**
* Use this slot if you want to activate the action. * Use this slot if you want to activate the action.
* authorized() will be emitted if the action gets authorized. * authorized() will be emitted if the action gets authorized.
@ -127,7 +127,7 @@ public slots:
*/ */
void revoke(); void revoke();
public: public:
/** /**
* Changes the action being tracked * Changes the action being tracked
* *

@ -40,8 +40,8 @@ namespace Gui
void ActionButtonPrivate::addButton(TQButton *button) void ActionButtonPrivate::addButton(TQButton *button)
{ {
buttons.append(button); buttons.append(button);
TQObject::connect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool))); TQObject::connect(button, TQT_SIGNAL(clicked()), q, TQT_SLOT(streamClicked()));
TQObject::connect(q, SIGNAL(toggled(bool)), button, SLOT(toggle())); TQObject::connect(q, TQT_SIGNAL(toggled(bool)), button, TQT_SLOT(toggle()));
q->updateButton(); q->updateButton();
} }
@ -49,7 +49,7 @@ void ActionButtonPrivate::removeButton(TQButton *button)
{ {
if (buttons.contains(button)) if (buttons.contains(button))
{ {
TQObject::disconnect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool))); TQObject::disconnect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked()));
TQObject::disconnect(q, SIGNAL(toggled(bool)), button, SLOT(toggle())); TQObject::disconnect(q, SIGNAL(toggled(bool)), button, SLOT(toggle()));
TQValueList<TQButton*>::iterator butIt = buttons.find(button); TQValueList<TQButton*>::iterator butIt = buttons.find(button);
if (butIt != buttons.end()) if (butIt != buttons.end())
@ -67,7 +67,7 @@ ActionButton::ActionButton(ActionButtonPrivate &dd, const TQString &actionId, TQ
: Action(actionId, parent), d(&dd) : Action(actionId, parent), d(&dd)
{ {
d->q = this; d->q = this;
connect(this, SIGNAL(dataChanged()), SLOT(updateButton())); connect(this, TQT_SIGNAL(dataChanged()), this, TQT_SLOT(updateButton()));
} }
ActionButton::ActionButton(TQButton *button, const TQString &actionId, TQObject *parent) ActionButton::ActionButton(TQButton *button, const TQString &actionId, TQObject *parent)
@ -77,7 +77,7 @@ ActionButton::ActionButton(TQButton *button, const TQString &actionId, TQObject
d->buttons.append(button); d->buttons.append(button);
setButton(button); setButton(button);
connect(this, SIGNAL(dataChanged()), SLOT(updateButton())); connect(this, TQT_SIGNAL(dataChanged()), this, TQT_SLOT(updateButton()));
} }
ActionButton::~ActionButton() ActionButton::~ActionButton()
@ -85,9 +85,9 @@ ActionButton::~ActionButton()
delete d; delete d;
} }
void ActionButton::streamClicked(bool c) void ActionButton::streamClicked()
{ {
emit clicked(::tqt_cast<TQButton*>(this->sender()), c); emit clicked(::tqt_cast<TQButton*>(this->sender()));
} }
void ActionButton::updateButton() void ActionButton::updateButton()
@ -105,7 +105,6 @@ void ActionButton::updateButton()
ent->hide(); ent->hide();
} }
ent->setEnabled(isEnabled()); ent->setEnabled(isEnabled());
ent->setText(text());
//if (!toolTip().isNull()) //if (!toolTip().isNull())
//{ //{
// ent->setToolTip(toolTip()); // ent->setToolTip(toolTip());
@ -115,6 +114,8 @@ void ActionButton::updateButton()
// ent->setWhatsThis(whatsThis()); // ent->setWhatsThis(whatsThis());
//} //}
ent->setPixmap(iconSet().pixmap()); ent->setPixmap(iconSet().pixmap());
// setPixmap() clears the button text, so setText() must be called afterwards
ent->setText(text());
// if the item cannot do the action anymore // if the item cannot do the action anymore
// lets revert to the initial state // lets revert to the initial state
if (ent->isToggleButton()) if (ent->isToggleButton())

@ -144,7 +144,7 @@ class POLKIT_TQT_EXPORT ActionButton : public Action
private slots: private slots:
void updateButton(); void updateButton();
void streamClicked(bool); void streamClicked();
}; };
} }

Loading…
Cancel
Save