Converted first part of examples code.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/1/head
Michele Calgaro 4 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 ######################
@ -83,7 +92,8 @@ add_definitions(
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_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/core
${CMAKE_SOURCE_DIR}/gui
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/gui ${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 ###########################
add_subdirectory( icons )
##### example executables #########################
install(FILES org.qt.policykit.examples.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d) 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)

@ -21,41 +21,131 @@
#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);
grid = new TQGridLayout(0, 9, 1, 0, 6, "grid");
grid->setColSpacing(0, 700);
grid->setColSpacing(1, 200);
kickL = new TQLabel(privateLayoutWidget, "kickL");
kickPB = new TQPushButton(privateLayoutWidget, "kickPB");
grid->addWidget(kickL, 0, 0);
grid->addWidget(kickPB, 0, 1);
cryL = new TQLabel(privateLayoutWidget, "cryL");
cryPB = new TQPushButton(privateLayoutWidget, "cryPB");
grid->addWidget(cryL, 1, 0);
grid->addWidget(cryPB, 1, 1);
bleedL = new TQLabel(privateLayoutWidget, "bleedL");
bleedPB = new TQPushButton(privateLayoutWidget, "bleedPB");
grid->addWidget(bleedL, 2, 0);
grid->addWidget(bleedPB, 2, 1);
playL = new TQLabel(privateLayoutWidget, "playL");
playPB = new TQPushButton(privateLayoutWidget, "playPB");
grid->addWidget(playL, 3, 0);
grid->addWidget(playPB, 3, 1);
listenL = new TQLabel(privateLayoutWidget, "listenL");
listenPB = new TQPushButton(privateLayoutWidget, "listenPB");
grid->addWidget(listenL, 4, 0);
grid->addWidget(listenPB, 4, 1);
deleteL = new TQLabel(privateLayoutWidget, "deleteL");
deletePB = new TQPushButton(privateLayoutWidget, "deletePB");
grid->addWidget(deleteL, 5, 0);
grid->addWidget(deletePB, 5, 1);
deleteL_2 = new TQLabel(privateLayoutWidget, "deleteL_2");
setCB = new TQComboBox(FALSE, privateLayoutWidget, "setCB");
grid->addMultiCellWidget(deleteL_2, 6, 7, 0, 0);
grid->addWidget(setCB, 6, 1);
setPB = new TQPushButton(privateLayoutWidget, "setPB");
deleteL_3 = new TQLabel(privateLayoutWidget, "deleteL_3");
grid->addWidget(setPB, 7, 1);
grid->addWidget(deleteL_3, 8, 0);
shoutPB = new TQPushButton(privateLayoutWidget, "shoutPB");
grid->addWidget(shoutPB, 8, 1);
vLayout = new TQVBoxLayout(privateLayoutWidget, 11, 6, "vLayout");
vLayout->addLayout(grid);
actionList = new TQListView(privateLayoutWidget);
actionList->addColumn("Action");
actionList->addColumn("Result");
actionList->setSorting(-1);
vLayout->addWidget(actionList);
// menubar
menubar = new TQMenuBar(this, "menubar");
menubar->setGeometry(TQRect(0, 0, 800, 22));
menuActions = new TQPopupMenu(this);
menubar->insertItem(TQString(""), menuActions, 2);
// toolbars
toolBar = new TQToolBar(TQString(""), this, DockTop);
// statusbar
statusBar();
languageChange();
resize(TQSize(900, 700).expandedTo(minimumSizeHint()));
clearWState(WState_Polished);
// Setup actions
ActionButton *bt; ActionButton *bt;
// Here we create an ActionButton that is a subclass of Action // Here we create an ActionButton that is a subclass of Action
// always pass a TQButton pointer and action id // always pass a TQButton pointer and action id
// You can change the action id later if you want // You can change the action id later if you want
bt = new ActionButton(kickPB, "org.qt.policykit.examples.kick", this); bt = new ActionButton(kickPB, "org.tqt.policykit.examples.kick", this);
// Here we are setting the text and icon to all four states // Here we are setting the text and icon to all four states
// an action might have // an action might have
bt->setText("Kick!"); bt->setText("Kick!");
bt->setIcon(TQPixmap(":/Icons/custom-no.png")); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"));
// By using set{Yes|No|Auth}Enabled you can set the states // By using set{Yes|No|Auth}Enabled you can set the states
// when the button is enabled // when the button is enabled
bt->setEnabled(true, Action::No); bt->setEnabled(true, Action::No);
// As ActionButton is also an Action we cast it to add to menu // As ActionButton is also an Action we cast it to add to menu
menuActions->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(menuActions);
toolBar->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
// this signal is emitted when the user click on the action, // this signal is emitted when the user click on the action,
// it will only happen if it was inserted in a TQMenu or a TQToolBar // it will only happen if it was inserted in a TQMenu or a TQToolBar
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
// This signal was propagated from the TQButton just for // This signal was propagated from the TQButton just for
// convenience in this case we don't have any benefit but the code // convenience in this case we don't have any benefit but the code
// look cleaner // look cleaner
@ -64,111 +154,136 @@ PkExample::PkExample(TQMainWindow *parent)
// someone click and get authorized to do the action // 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(cryPB, "org.qt.policykit.examples.cry", this); bt = new ActionButton(cryPB, "org.tqt.policykit.examples.cry", this);
bt->setText("Cry!"); bt->setText("Cry!");
bt->setIcon(TQPixmap(":/Icons/custom-yes.png")); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"));
menuActions->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(menuActions);
toolBar->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
bt = new ActionButton(bleedPB, "org.qt.policykit.examples.bleed", this); bt = new ActionButton(bleedPB, "org.tqt.policykit.examples.bleed", this);
bt->setText("Bleed!"); bt->setText("Bleed!");
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png")); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"));
menuActions->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(menuActions);
toolBar->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
// This action is more customized // This action is more customized
bt = new ActionButton(playPB, "org.qt.policykit.examples.play", this); bt = new ActionButton(playPB, "org.tqt.policykit.examples.play", this);
bt->setText("Play!"); bt->setText("Play!");
bt->setVisible(true, Action::No | Action::Auth | Action::Yes); bt->setVisible(true, (Action::States)(Action::No | Action::Auth | Action::Yes));
bt->setEnabled(true, 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 // here we set the behavior of PolKitResul = No
bt->setText("Can't play!", Action::No); bt->setText("Can't play!", Action::No);
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), 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); bt->setToolTip("If your admin wasn't annoying, you could do this", Action::No);
// here we set the behavior of PolKitResul = Auth // here we set the behavior of PolKitResul = Auth
bt->setText("Play?", Action::Auth); bt->setText("Play?", Action::Auth);
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), 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); bt->setToolTip("Only card carrying tweakers can do this!", Action::Auth);
// here we set the behavior of PolKitResul = Yes // here we set the behavior of PolKitResul = Yes
bt->setText("Play!", Action::Yes); bt->setText("Play!", Action::Yes);
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
bt->setToolTip("Go ahead, play!", Action::Yes); bt->setToolTip("Go ahead, play!", Action::Yes);
::tqt_cast<TQAction*>(bt)->addTo(menuActions);
menuActions->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
toolBar->addAction(qobject_cast<Action *>(bt)); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
bt = new ActionButton(deletePB, "org.qt.policykit.examples.delete", this); bt = new ActionButton(listenPB, "org.tqt.policykit.examples.listen", this);
bt->setText("Delete!"); bt->setText("Listen!");
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), Action::No); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"), Action::No);
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), Action::Auth); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"), Action::Auth);
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
menuActions->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(menuActions);
toolBar->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
bt = new ActionButton(listenPB, "org.qt.policykit.examples.listen", this); bt = new ActionButton(deletePB, "org.tqt.policykit.examples.delete", this);
bt->setText("Listen!"); bt->setText("Delete!");
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), Action::No); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"), Action::No);
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), Action::Auth); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"), Action::Auth);
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
menuActions->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(menuActions);
toolBar->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
bt = new ActionButton(setPB, "org.qt.policykit.examples.set", this); bt = new ActionButton(setPB, "org.tqt.policykit.examples.set", this);
bt->setText("Set!"); bt->setText("Set!");
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), Action::No); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"), Action::No);
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), Action::Auth); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"), Action::Auth);
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
menuActions->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(menuActions);
toolBar->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
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(shoutPB, "org.tqt.policykit.examples.shout", this);
bt->setIcon(TQPixmap(":/Icons/custom-no.png"), Action::No); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-no.png"), Action::No);
bt->setIcon(TQPixmap(":/Icons/action-locked-default.png"), Action::Auth); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/action-locked-default.png"), Action::Auth);
bt->setIcon(TQPixmap(":/Icons/custom-yes.png"), Action::Yes); bt->setIconSet(TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"), Action::Yes);
bt->setText("Can't shout!", Action::No); bt->setText("Can't shout!", Action::No);
bt->setText("Shout?", Action::Auth); bt->setText("Shout?", Action::Auth);
bt->setText("Shout!", Action::Yes); bt->setText("Shout!", Action::Yes);
menuActions->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(menuActions);
toolBar->addAction(qobject_cast<Action *>(bt)); ::tqt_cast<TQAction*>(bt)->addTo(toolBar);
connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); connect(bt, SIGNAL(activated()), this, SLOT(activateAction()));
connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(clicked(TQButton*, bool)), bt, SLOT(activate()));
connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated()));
// test configChanged
} }
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 = qobject_cast<Action *>(sender()); Action *action = ::tqt_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();
@ -179,37 +294,41 @@ 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 // this is our Special Action that after allowed will call the helper
if (action->is("org.qt.policykit.examples.set")) { if (action->is("org.tqt.policykit.examples.set"))
tqDebug() << "toggled for: org.qt.policykit.examples.set"; {
tqDebug("toggled for: org.tqt.policykit.examples.set");
TQDBusMessage message;
message = TQDBusMessage::createMethodCall("org.qt.policykit.examples", TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
"/", TQT_DBusProxy exampleProxy("org.tqt.policykit.examples", "/", "org.tqt.policykit.examples", dbusConn);
"org.qt.policykit.examples", TQT_DBusError error;
TQLatin1String("set")); TQValueList<TQT_DBusData> params;
TQList<TQVariant> argumentList; params << TQT_DBusData::fromString(setCB->currentText());
argumentList << qVariantFromValue(setCB->currentText()); TQT_DBusMessage reply = exampleProxy.sendWithReply("set", params, &error);
message.setArguments(argumentList); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1)
// 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 // the reply can be anything, here we receive a bool
TQListWidgetItem *item; TQListViewItem *item;
if (reply.arguments().first().toBool()) if (reply[0].toBool())
item = new TQListWidgetItem(TQPixmap(":/Icons/custom-yes.png"), {
TQString("Implicit authorization for shout has been set to %0") item = new TQListViewItem(actionList);
.arg(setCB->currentText())); item->setText(0, TQString("Implicit authorization for shout has been set to ") +
setCB->currentText());
item->setPixmap(1, TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"));
}
else else
item = new TQListWidgetItem(TQPixmap(":/Icons/custom-no.png"), {
TQString("Can't change the implicit authorization. Denied.")); item = new TQListViewItem(actionList);
actionList->addItem(item); item->setText(0, TQString("Can't change the implicit authorization. Denied."));
tqDebug() << reply.arguments().first().toString(); item->setPixmap(1, TQPixmap("/usr/share/apps/icons/custom-no.png"));
} else if (reply.type() == TQDBusMessage::MethodCallMessage) { }
tqWarning() << "Message did not receive a reply (timeout by message bus)"; actionList->insertItem(item);
}
else if (reply.type() == TQT_DBusMessage::MethodCallMessage)
{
tqDebug("Message did not receive a reply (timeout by message bus)");
} }
return; return;
} }
@ -219,22 +338,29 @@ void PkExample::actionActivated()
// will run as root (setuid is not needed, see DBus docs). // will run as root (setuid is not needed, see DBus docs).
// In the helper application you will issue checkAuthorizationSync, // In the helper application you will issue checkAuthorizationSync,
// passing the action id and the caller pid (which DBus will tell you). // passing the action id and the caller pid (which DBus will tell you).
tqDebug() << "pretending to be the mechanism for action:" << action->actionId(); tqDebug("Pretending to be the mechanism for action " + action->actionId());
Authority::Result result; Authority::Result result;
UnixProcessSubject subject(static_cast<uint>(TQCoreApplication::applicationPid())); UnixProcessSubject subject(static_cast<uint>(getpid()));
result = Authority::instance()->checkAuthorizationSync(action->actionId(), subject, result = Authority::instance()->checkAuthorizationSync(action->actionId(), subject,
Authority::AllowUserInteraction); Authority::AllowUserInteraction);
if (result == Authority::Yes) { TQListViewItem *item;
item = new TQListViewItem(actionList);
item->setText(0, action->actionId());
if (result == Authority::Yes)
{
// in the helper you will do the action // in the helper you will do the action
tqDebug() << "caller is authorized to do:" << action->actionId(); tqDebug("caller is authorized to do: " + action->actionId());
TQListWidgetItem *item = new TQListWidgetItem(TQPixmap(":/Icons/custom-yes.png"), action->actionId()); item->setPixmap(1, TQPixmap("/usr/share/apps/polkit-tqt/icons/custom-yes.png"));
actionList->addItem(item);
} else {
// OR return false to notify the caller that the action is not authorized.
tqDebug() << "caller is NOT authorized to do:" << action->actionId();
TQListWidgetItem *item = new TQListWidgetItem(TQIcon(":/Icons/custom-no.png"), action->actionId());
actionList->addItem(item);
} }
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,63 +20,97 @@
***************************************************************************/ ***************************************************************************/
#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) PkExampleHelper::PkExampleHelper(int &argc, char **argv) : TQApplication(argc, argv, false)
{ {
tqDebug() << "Creating Helper"; tqDebug("Creating Helper");
(void) new ExamplesAdaptor(this);
// Register the DBus service // Register the DBus service
if (!TQDBusConnection::systemBus().registerService("org.tqt.policykit.examples")) { m_connection = TQT_DBusConnection::systemBus();
tqDebug() << TQDBusConnection::systemBus().lastError().message();; if (!m_connection.registerObject("/", this))
TQTimer::singleShot(0, this, SLOT(quit())); {
tqDebug("unable to register 'org.tqt.policykit.examples' service interface to dbus");
tqDebug(m_connection.lastError().message());
return; return;
} }
if (!m_connection.requestName("org.tqt.policykit.examples"))
if (!TQDBusConnection::systemBus().registerObject("/", this)) { {
tqDebug() << "unable to register service interface to dbus"; tqDebug("unable to acquire 'org.tqt.policykit.examples' service interface to dbus");
TQTimer::singleShot(0, this, SLOT(quit())); tqDebug(m_connection.lastError().message());
return; return;
} }
// Normally you will set a timeout so your application can // Exit if not used for 10 minutes
// free some resources of the poor client machine ;) TQTimer::singleShot(600000, this, TQT_SLOT(quit()));
TQTimer::singleShot(MINUTE, this, SLOT(quit())); tqDebug("Register successful");
} }
PkExampleHelper::~PkExampleHelper() PkExampleHelper::~PkExampleHelper()
{ {
tqDebug() << "Destroying Helper"; tqDebug("Destroying Helper");
m_connection.unregisterObject("org.tqt.policykit.examples");
}
bool PkExampleHelper::handleMethodCall(const TQT_DBusMessage& message)
{
if (message.interface() != "org.tqt.policykit.examples")
{
return false;
}
if (message.member() == "set")
{
// check parameters
if (message.count() != 1 || message[0].type() != TQT_DBusData::String)
{
// method signature not what we expected
TQT_DBusError error = TQT_DBusError::stdInvalidArgs(
"Expected one argument of type string");
TQT_DBusMessage reply = TQT_DBusMessage::methodError(message, error);
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) bool PkExampleHelper::set(const TQString &action)
{ {
tqDebug() << "PkExampleHelper::set" << action;
// message().service() is the service name of the caller
// We can check if the caller is authorized to the following action // We can check if the caller is authorized to the following action
SystemBusNameSubject subject(m_connection.uniqueName());
Authority::Result result; Authority::Result result;
SystemBusNameSubject subject(message().service());
result = Authority::instance()->checkAuthorizationSync("org.tqt.policykit.examples.set", result = Authority::instance()->checkAuthorizationSync("org.tqt.policykit.examples.set",
subject , Authority::AllowUserInteraction); subject , Authority::AllowUserInteraction);
if (result == Authority::Yes) { if (result == Authority::Yes)
tqDebug() << message().service() << TQString("Implicit authorization set to") << action; {
// Caller is authorized so we can perform the action // Caller is authorized so we can perform the action
tqDebug(TQString("Implicit authorization set to ") + action);
return setValue(action); return setValue(action);
} else { }
tqDebug() << message().service() << TQString("Can't set the implicit authorization"); else
{
// Caller is not authorized so the action can't be performed // Caller is not authorized so the action can't be performed
tqDebug(TQString("Can't set the implicit authorization to ") + action);
return false; return false;
} }
} }
@ -87,24 +121,33 @@ bool PkExampleHelper::setValue(const TQString &action)
// 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; return false;
}
doc.setContent(&file); doc.setContent(&file);
file.close(); file.close();
TQDomElement el = doc.firstChildElement("policyconfig"). TQDomElement el = doc.namedItem("policyconfig").namedItem("action").toElement();
firstChildElement("action"); while (!el.isNull() && el.attribute("id") != "org.tqt.policykit.examples.shout")
while (!el.isNull() && el.attribute("id", TQString()) != "org.tqt.policykit.examples.shout") { {
el = el.nextSiblingElement("action"); el = el.nextSibling().toElement();
} }
el = el.firstChildElement("defaults"); el = el.namedItem("defaults").toElement();
el = el.firstChildElement("allow_active"); el = el.namedItem("allow_active").toElement();
if (el.isNull()) if (el.isNull())
{
return false; return false;
}
el.firstChild().toText().setData(action); el.firstChild().toText().setData(action);
if (!file.open(TQIODevice::WriteOnly)) if (!file.open(IO_WriteOnly))
{
return false; return false;
}
TQTextStream stream(&file); TQTextStream stream(&file);
doc.save(stream, 2); doc.save(stream, 2);
file.close(); file.close();
return true; 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();
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
return app.exec(); return app.exec();
} }

@ -21,6 +21,7 @@
#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);

@ -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

@ -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