From 98b37ff3b1d307add5fe3f9e1f9c7923831debd4 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 13 Nov 2021 19:53:11 +0900 Subject: Conversion of 'gui' library module. Signed-off-by: Michele Calgaro --- CMakeLists.txt | 32 +- Mainpage.dox | 4 +- README | 2 +- debian/libpolkit-tqt-dev.install | 12 +- examples/PkExample.cpp | 20 +- gui/CMakeLists.txt | 41 +-- gui/dummy-gui.cpp | 37 -- gui/dummy-gui.h | 56 --- gui/polkit-tqt-gui-action.cpp | 661 +++++++++++++++++++++++++++++++++++ gui/polkit-tqt-gui-action.h | 307 ++++++++++++++++ gui/polkit-tqt-gui-actionbutton.cpp | 173 +++++++++ gui/polkit-tqt-gui-actionbutton.h | 155 ++++++++ gui/polkit-tqt-gui-actionbutton_p.h | 60 ++++ gui/polkit-tqt-gui-actionbuttons.cpp | 75 ++++ gui/polkit-tqt-gui-actionbuttons.h | 119 +++++++ gui/polkit-tqt-gui-actionbuttons_p.h | 49 +++ gui/polkittqt1-gui-action.cpp | 517 --------------------------- gui/polkittqt1-gui-action.h | 305 ---------------- gui/polkittqt1-gui-actionbutton.cpp | 166 --------- gui/polkittqt1-gui-actionbutton.h | 145 -------- gui/polkittqt1-gui-actionbutton_p.h | 50 --- gui/polkittqt1-gui-actionbuttons.cpp | 73 ---- gui/polkittqt1-gui-actionbuttons.h | 114 ------ gui/polkittqt1-gui-actionbuttons_p.h | 36 -- 24 files changed, 1649 insertions(+), 1560 deletions(-) delete mode 100644 gui/dummy-gui.cpp delete mode 100644 gui/dummy-gui.h create mode 100644 gui/polkit-tqt-gui-action.cpp create mode 100644 gui/polkit-tqt-gui-action.h create mode 100644 gui/polkit-tqt-gui-actionbutton.cpp create mode 100644 gui/polkit-tqt-gui-actionbutton.h create mode 100644 gui/polkit-tqt-gui-actionbutton_p.h create mode 100644 gui/polkit-tqt-gui-actionbuttons.cpp create mode 100644 gui/polkit-tqt-gui-actionbuttons.h create mode 100644 gui/polkit-tqt-gui-actionbuttons_p.h delete mode 100644 gui/polkittqt1-gui-action.cpp delete mode 100644 gui/polkittqt1-gui-action.h delete mode 100644 gui/polkittqt1-gui-actionbutton.cpp delete mode 100644 gui/polkittqt1-gui-actionbutton.h delete mode 100644 gui/polkittqt1-gui-actionbutton_p.h delete mode 100644 gui/polkittqt1-gui-actionbuttons.cpp delete mode 100644 gui/polkittqt1-gui-actionbuttons.h delete mode 100644 gui/polkittqt1-gui-actionbuttons_p.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 56798bf00..8470dfeb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,15 +97,21 @@ install( includes/PolkitTQt/TemporaryAuthorization includes/PolkitTQt/ActionDescription DESTINATION - ${INCLUDE_INSTALL_DIR}/PolkitTQt ) + ${INCLUDE_INSTALL_DIR}/PolkitTQt +) + +install( + FILES + includes/PolkitTQt/Gui/Action + includes/PolkitTQt/Gui/ActionButton + includes/PolkitTQt/Gui/ActionButtons + DESTINATION + ${INCLUDE_INSTALL_DIR}/PolkitTQt/Gui +) install( FILES polkit-tqt-export.h -## gui/polkittqt1-gui-action.h -## gui/polkittqt1-gui-actionbutton.h -## gui/polkittqt1-gui-actionbuttons.h -## ## agent/polkittqt1-agent-listener.h ## agent/polkittqt1-agent-session.h ## @@ -146,9 +152,6 @@ install( ## configure_file(polkittqt1-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/polkittqt1-version.h) ## ## install(FILES -## gui/polkittqt1-gui-action.h -## gui/polkittqt1-gui-actionbutton.h -## gui/polkittqt1-gui-actionbuttons.h ## ## agent/polkittqt1-agent-listener.h ## agent/polkittqt1-agent-session.h @@ -160,17 +163,10 @@ install( ## ${INCLUDE_INSTALL_DIR}/polkit-qt-1 ) ## ## install(FILES -## includes/PolkitTQt1/Gui/Action -## includes/PolkitTQt1/Gui/ActionButton -## includes/PolkitTQt1/Gui/ActionButtons -## DESTINATION -## ${INCLUDE_INSTALL_DIR}/polkit-qt-1/PolkitTQt1/Gui ) -## -## install(FILES -## includes/PolkitTQt1/Agent/Listener -## includes/PolkitTQt1/Agent/Session +## includes/PolkitTQt/Agent/Listener +## includes/PolkitTQt/Agent/Session ## DESTINATION -## ${INCLUDE_INSTALL_DIR}/polkit-qt-1/PolkitTQt1/Agent ) +## ${INCLUDE_INSTALL_DIR}/polkit-qt-1/PolkitTQt/Agent ) ## ## # CMake Config files ## configure_file(PolkitTQt-1Config.cmake.in "${CMAKE_BINARY_DIR}/PolkitTQt-1Config.cmake" @ONLY) diff --git a/Mainpage.dox b/Mainpage.dox index 1fceaafdd..1f69da9c2 100644 --- a/Mainpage.dox +++ b/Mainpage.dox @@ -62,7 +62,7 @@ UI file, \c kickPB . As you can see, you can set custom properties on your butto on the action status/result. The code is mostly self-explainatory \code -bt = new ActionButtons(TQList() << listenPB << listenCB, +bt = new ActionButtons(TQList() << listenPB << listenCB, "org.tqt.policykit.examples.listen", this); bt->setIcon(TQPixmap(":/Icons/action-locked.png")); bt->setIcon(TQPixmap(":/Icons/action-unlocked.png"), Action::Yes); @@ -75,7 +75,7 @@ are kept in sync with the action. \code connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); -connect(bt, SIGNAL(clicked(TQAbstractButton*,bool)), bt, SLOT(activate())); +connect(bt, SIGNAL(clicked(TQButton*,bool)), bt, SLOT(activate())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); \endcode diff --git a/README b/README index f7c87ad1a..95d301167 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ Polkit-tqt What is Polkit-tqt? ------------------ Polkit-tqt is a library that lets developers use the PolicyKit API through a nice -TQt-styled API. It is mainly a wrapper around TQAction and TQAbstractButton that +TQt-styled API. It is mainly a wrapper around TQAction and TQButton that lets you integrate those two component easily with PolicyKit This directory contains the sources of the library. diff --git a/debian/libpolkit-tqt-dev.install b/debian/libpolkit-tqt-dev.install index 79fadc135..649aaeb31 100644 --- a/debian/libpolkit-tqt-dev.install +++ b/debian/libpolkit-tqt-dev.install @@ -3,9 +3,9 @@ debian/tmp/usr/include/polkit-tqt/PolkitTQt/ActionDescription #debian/tmp/usr/include/polkit-tqt/PolkitTQt/Agent/Session debian/tmp/usr/include/polkit-tqt/PolkitTQt/Authority debian/tmp/usr/include/polkit-tqt/PolkitTQt/Details -#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Gui/Action -#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Gui/ActionButton -#debian/tmp/usr/include/polkit-tqt/PolkitTQt/Gui/ActionButtons +debian/tmp/usr/include/polkit-tqt/PolkitTQt/Gui/Action +debian/tmp/usr/include/polkit-tqt/PolkitTQt/Gui/ActionButton +debian/tmp/usr/include/polkit-tqt/PolkitTQt/Gui/ActionButtons debian/tmp/usr/include/polkit-tqt/PolkitTQt/Identity debian/tmp/usr/include/polkit-tqt/PolkitTQt/Subject debian/tmp/usr/include/polkit-tqt/PolkitTQt/TemporaryAuthorization @@ -15,9 +15,9 @@ debian/tmp/usr/include/polkit-tqt/polkit-tqt-actiondescription.h debian/tmp/usr/include/polkit-tqt/polkit-tqt-authority.h debian/tmp/usr/include/polkit-tqt/polkit-tqt-details.h debian/tmp/usr/include/polkit-tqt/polkit-tqt-export.h -#debian/tmp/usr/include/polkit-tqt/polkit-tqt-gui-action.h -#debian/tmp/usr/include/polkit-tqt/polkit-tqt-gui-actionbutton.h -#debian/tmp/usr/include/polkit-tqt/polkit-tqt-gui-actionbuttons.h +debian/tmp/usr/include/polkit-tqt/polkit-tqt-gui-action.h +debian/tmp/usr/include/polkit-tqt/polkit-tqt-gui-actionbutton.h +debian/tmp/usr/include/polkit-tqt/polkit-tqt-gui-actionbuttons.h debian/tmp/usr/include/polkit-tqt/polkit-tqt-identity.h debian/tmp/usr/include/polkit-tqt/polkit-tqt-subject.h debian/tmp/usr/include/polkit-tqt/polkit-tqt-temporaryauthorization.h diff --git a/examples/PkExample.cpp b/examples/PkExample.cpp index e200009d3..7366b4eaa 100644 --- a/examples/PkExample.cpp +++ b/examples/PkExample.cpp @@ -40,7 +40,7 @@ PkExample::PkExample(TQMainWindow *parent) ActionButton *bt; // Here we create an ActionButton that is a subclass of Action - // always pass a TQAbstractButton pointer and action id + // always pass a TQButton pointer and action id // You can change the action id later if you want bt = new ActionButton(kickPB, "org.qt.policykit.examples.kick", this); // Here we are setting the text and icon to all four states @@ -56,10 +56,10 @@ PkExample::PkExample(TQMainWindow *parent) // 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 connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); - // This signal was propagated from the TQAbstractButton just for + // This signal was propagated from the TQButton just for // convenience in this case we don't have any benefit but the code // look cleaner - connect(bt, SIGNAL(clicked(TQAbstractButton *, bool)), bt, SLOT(activate())); + connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); // this is the Action activated signal, it is always emmited whenever // someone click and get authorized to do the action connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); @@ -70,7 +70,7 @@ PkExample::PkExample(TQMainWindow *parent) menuActions->addAction(qobject_cast(bt)); toolBar->addAction(qobject_cast(bt)); connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); - connect(bt, SIGNAL(clicked(TQAbstractButton *, bool)), bt, SLOT(activate())); + connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); bt = new ActionButton(bleedPB, "org.qt.policykit.examples.bleed", this); @@ -79,7 +79,7 @@ PkExample::PkExample(TQMainWindow *parent) menuActions->addAction(qobject_cast(bt)); toolBar->addAction(qobject_cast(bt)); connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); - connect(bt, SIGNAL(clicked(TQAbstractButton *, bool)), bt, SLOT(activate())); + connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); // This action is more customized @@ -103,7 +103,7 @@ PkExample::PkExample(TQMainWindow *parent) menuActions->addAction(qobject_cast(bt)); toolBar->addAction(qobject_cast(bt)); connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); - connect(bt, SIGNAL(clicked(TQAbstractButton *, bool)), bt, SLOT(activate())); + connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); bt = new ActionButton(deletePB, "org.qt.policykit.examples.delete", this); @@ -114,7 +114,7 @@ PkExample::PkExample(TQMainWindow *parent) menuActions->addAction(qobject_cast(bt)); toolBar->addAction(qobject_cast(bt)); connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); - connect(bt, SIGNAL(clicked(TQAbstractButton *, bool)), bt, SLOT(activate())); + connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); bt = new ActionButton(listenPB, "org.qt.policykit.examples.listen", this); @@ -125,7 +125,7 @@ PkExample::PkExample(TQMainWindow *parent) menuActions->addAction(qobject_cast(bt)); toolBar->addAction(qobject_cast(bt)); connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); - connect(bt, SIGNAL(clicked(TQAbstractButton *, bool)), bt, SLOT(activate())); + connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); bt = new ActionButton(setPB, "org.qt.policykit.examples.set", this); @@ -136,7 +136,7 @@ PkExample::PkExample(TQMainWindow *parent) menuActions->addAction(qobject_cast(bt)); toolBar->addAction(qobject_cast(bt)); connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); - connect(bt, SIGNAL(clicked(TQAbstractButton *, bool)), bt, SLOT(activate())); + connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); bt = new ActionButton(shoutPB, "org.qt.policykit.examples.shout", this); @@ -149,7 +149,7 @@ PkExample::PkExample(TQMainWindow *parent) menuActions->addAction(qobject_cast(bt)); toolBar->addAction(qobject_cast(bt)); connect(bt, SIGNAL(triggered(bool)), this, SLOT(activateAction())); - connect(bt, SIGNAL(clicked(TQAbstractButton *, bool)), bt, SLOT(activate())); + connect(bt, SIGNAL(clicked(TQButton *, bool)), bt, SLOT(activate())); connect(bt, SIGNAL(authorized()), this, SLOT(actionActivated())); // test configChanged diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 7db12e36e..2a071e12c 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -10,8 +10,10 @@ ################################################# include_directories( - ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/core ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} ${TQT_INCLUDE_DIRS} ) @@ -22,38 +24,29 @@ link_directories( ##### install headers ########################### -install( FILES - dummy-gui.h - DESTINATION ${INCLUDE_INSTALL_DIR} ) +install( + FILES + polkit-tqt-gui-action.h + polkit-tqt-gui-actionbutton.h + polkit-tqt-gui-actionbuttons.h + DESTINATION ${INCLUDE_INSTALL_DIR} +) ##### polkit-tqt-gui (shared) ######################### tde_add_library( polkit-tqt-gui SHARED AUTOMOC - SOURCES ${polkit_tqt_MOCS} - dummy-gui.cpp + SOURCES ${polkit_tqt_gui_MOCS} + polkit-tqt-gui-action.cpp + polkit-tqt-gui-actionbutton.cpp + polkit-tqt-gui-actionbuttons.cpp VERSION 0.0.0 - LINK ${TQT_LIBRARIES} + LINK ${TQT_LIBRARIES} ${POLKIT_LIBRARIES} polkit-tqt-core-shared DESTINATION ${LIB_INSTALL_DIR} ) -## set(polkit_tqt_gui_SRCS -## polkittqt1-gui-action.cpp -## polkittqt1-gui-actionbutton.cpp -## polkittqt1-gui-actionbuttons.cpp -## ) -## -## target_link_libraries(polkit-tqt-gui-1 -## ${TQT_TQTCORE_LIBRARY} -## ${TQT_TQTGUI_LIBRARY} -## ${TQT_TQTDBUS_LIBRARY} -## ${POLKIT_LIBRARIES} -## polkit-tqt-core-1 -## ) -## ## set_target_properties(polkit-tqt-gui-1 PROPERTIES VERSION ${POLKITTQT-1_LIBRARY_VERSION} ## SOVERSION ${POLKITTQT-1_ABI_VERSION} -## DEFINE_SYMBOL MAKE_POLKITTQT1_LIB) -## -## install(TARGETS polkit-tqt-gui-1 ${INSTALL_TARGETS_DEFAULT_ARGS}) +## DEFINE_SYMBOL MAKE_POLKIT_TQT_LIB) +## diff --git a/gui/dummy-gui.cpp b/gui/dummy-gui.cpp deleted file mode 100644 index d40e5e631..000000000 --- a/gui/dummy-gui.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Daniel Nicoletti - * Copyright (C) 2009 Dario Freddi - * Copyright (C) 2009 Jaroslav Reznik - * Copyright (C) 2009 Radek Novacek - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "dummy-gui.h" - -namespace PolkitTQt -{ - - -DummyGui* DummyGui::instance() -{ - return 0; -} - -} - -#include "dummy-gui.moc" diff --git a/gui/dummy-gui.h b/gui/dummy-gui.h deleted file mode 100644 index f7c2f216f..000000000 --- a/gui/dummy-gui.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Daniel Nicoletti - * Copyright (C) 2009 Dario Freddi - * Copyright (C) 2009 Jaroslav Reznik - * Copyright (C) 2009 Radek Novacek - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef DUMMY_GUI_H -#define DUMMY_GUI_H - -#define POLKIT_TQT_EXPORT TQ_EXPORT - - -/** - * \namespace PolkitTQt1 PolkitTQt - * - * \brief Namespace wrapping Polkit-TQt classes - * - * This namespace wraps all Polkit-TQt classes. - */ -namespace PolkitTQt -{ - -/** - * \class DummyGui - * - * \brief Convenience class for TQt/KDE applications - * - * This class is a dummy used for initial basic compiling. - */ -class POLKIT_TQT_EXPORT DummyGui -{ -public: - - static DummyGui* instance(); -}; - -} - -#endif diff --git a/gui/polkit-tqt-gui-action.cpp b/gui/polkit-tqt-gui-action.cpp new file mode 100644 index 000000000..41a3395dd --- /dev/null +++ b/gui/polkit-tqt-gui-action.cpp @@ -0,0 +1,661 @@ +/* + * This file is part of the Polkit-tqt project + * Copyright (C) 2009 Daniel Nicoletti + * Copyright (C) 2009 Dario Freddi + * Copyright (C) 2009 Jaroslav Reznik + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "polkit-tqt-gui-action.h" +#include "polkit-tqt-authority.h" +#include "polkit-tqt-subject.h" + +#include + + +namespace PolkitTQt +{ + +namespace Gui +{ + +//-------------------------------------- +// Action::Private +//-------------------------------------- + +class Action::Private +{ + public: + Private(Action *p); + + void updateAction(); + bool computePkResult(); + + Action *parent; + + TQString actionId; + Authority::Result pkResult; + TQ_LONG targetPID; + + bool initiallyChecked; + + // states data + bool selfBlockedVisible; + bool selfBlockedEnabled; + TQString selfBlockedText; + TQString selfBlockedWhatsThis; + TQString selfBlockedToolTip; + TQIconSet selfBlockedIconSet; + + bool noVisible; + bool noEnabled; + TQString noText; + TQString noWhatsThis; + TQString noToolTip; + TQIconSet noIconSet; + + bool authVisible; + bool authEnabled; + TQString authText; + TQString authWhatsThis; + TQString authToolTip; + TQIconSet authIconSet; + + bool yesVisible; + bool yesEnabled; + TQString yesText; + TQString yesWhatsThis; + TQString yesToolTip; + TQIconSet yesIconSet; +}; + +Action::Private::Private(Action *p) : parent(p), targetPID(getpid()) +{ + initiallyChecked = false; + + // Set the default values + selfBlockedVisible = true; + selfBlockedEnabled = false; + + noVisible = true; + noEnabled = false; + + authVisible = true; + authEnabled = true; + + yesVisible = true; + yesEnabled = true; +} + +void Action::Private::updateAction() +{ + if (Authority::instance()->hasError()) + { + return; + } + + switch (pkResult) + { + default: + case Authority::Unknown: + case Authority::No: + { + ::tqt_cast(parent)->setVisible(noVisible); + ::tqt_cast(parent)->setEnabled(noEnabled); + ::tqt_cast(parent)->setText(noText); + if (!noWhatsThis.isNull()) + { + ::tqt_cast(parent)->setWhatsThis(noWhatsThis); + } + if (!noToolTip.isNull()) + { + ::tqt_cast(parent)->setToolTip(noToolTip); + } + ::tqt_cast(parent)->setIconSet(noIconSet); + break; + } + + case Authority::Challenge: + { + ::tqt_cast(parent)->setVisible(authVisible); + ::tqt_cast(parent)->setEnabled(authEnabled); + ::tqt_cast(parent)->setText(authText); + if (!authWhatsThis.isNull()) + { + ::tqt_cast(parent)->setWhatsThis(authWhatsThis); + } + if (!authToolTip.isNull()) + { + ::tqt_cast(parent)->setToolTip(authToolTip); + } + ::tqt_cast(parent)->setIconSet(authIconSet); + break; + } + + case Authority::Yes: + { + ::tqt_cast(parent)->setVisible(yesVisible); + ::tqt_cast(parent)->setEnabled(yesEnabled); + ::tqt_cast(parent)->setText(yesText); + if (!yesWhatsThis.isNull()) + { + ::tqt_cast(parent)->setWhatsThis(yesWhatsThis); + } + if (!yesToolTip.isNull()) + { + ::tqt_cast(parent)->setToolTip(yesToolTip); + } + ::tqt_cast(parent)->setIconSet(yesIconSet); + if (parent->isOn()) + { + ::tqt_cast(parent)->setOn(!initiallyChecked); + } + break; + } + } + emit parent->dataChanged(); +} + +bool Action::Private::computePkResult() +{ + Authority::Result old_result; + UnixProcessSubject subject(parent->targetPID()); + + old_result = pkResult; + pkResult = Authority::instance()->checkAuthorizationSync(actionId, subject, Authority::None); + + return old_result != pkResult; +} + +//-------------------------------------- +// Action +//-------------------------------------- + +Action::Action(const TQString &actionId, TQObject *parent) : TQAction(parent), d(new Private(this)) +{ + // this must be called AFTER the values initialization + setPolkitAction(actionId); + + // track the config changes to update the action + connect(Authority::instance(), SIGNAL(configChanged()), this, SLOT(slotConfigChanged())); +} + +Action::~Action() +{ + delete d; +} + +bool Action::activate() +{ + switch (d->pkResult) + { + case Authority::Yes: + case Authority::Challenge: + { + emit authorized(); + return true; + } + + case Authority::No: + default: + { + if (d->noEnabled) + { + /* If PolicyKit says no... and we got here.. it means + * that the user set the property "no-enabled" to TRUE.. + * Hence, they probably have a good reason for doing + * this so do let the 'activate' signal propagate.. + */ + emit authorized(); + return true; + } + break; + } + } + return false; +} + +void Action::setChecked(bool checked) +{ + // We store this as initiallyChecked + // to be able to undo changes in case the auth fails + d->initiallyChecked = checked; + TQAction::setOn(checked); +} + +void Action::slotConfigChanged() +{ + if (d->computePkResult()) + { + d->updateAction(); + } +} + +TQ_LONG Action::targetPID() const +{ + if (d->targetPID != 0) + { + return d->targetPID; + } + else + { + return getpid(); + } +} + +void Action::setTargetPID(TQ_LONG pid) +{ + d->targetPID = pid; + + d->computePkResult(); + d->updateAction(); +} + +bool Action::isAllowed() const +{ + return d->pkResult == Authority::Yes; +} + +bool Action::is(const TQString &other) const +{ + return d->actionId == other; +} + +void Action::revoke() +{ + /*TODO: implement it? no negative authorizations available, no authorization db*/ +} + +void Action::setText(const TQString &text, States states) +{ + if (states & All) + { + d->selfBlockedText = text; + d->noText = text; + d->authText = text; + d->yesText = text; + } + else if (states & Auth) + { + d->authText = text; + } + else if (states & No) + { + d->noText = text; + } + else if (states & SelfBlocked) + { + d->selfBlockedText = text; + } + else if (states & Yes) + { + d->yesText = text; + } + + d->updateAction(); +} + +TQString Action::text(Action::States state) const +{ + switch (state) + { + case Yes: + { + return d->yesText; + } + case No: + { + return d->noText; + } + case Auth: + { + return d->authText; + } + case SelfBlocked: + { + return d->selfBlockedText; + } + case None: + { + return TQAction::text(); + } + default: + { + return TQString::null; + } + } +} + +void Action::setToolTip(const TQString &toolTip, States states) +{ + if (states & All) + { + d->selfBlockedToolTip = toolTip; + d->noToolTip = toolTip; + d->authToolTip = toolTip; + d->yesToolTip = toolTip; + } + else if (states & Auth) + { + d->authToolTip = toolTip; + } + else if (states & No) + { + d->noToolTip = toolTip; + } + else if (states & SelfBlocked) + { + d->selfBlockedToolTip = toolTip; + } + else if (states & Yes) + { + d->yesToolTip = toolTip; + } + + d->updateAction(); +} + +TQString Action::toolTip(Action::States state) const +{ + switch (state) + { + case Yes: + { + return d->yesToolTip; + } + case No: + { + return d->noToolTip; + } + case Auth: + { + return d->authToolTip; + } + case SelfBlocked: + { + return d->selfBlockedToolTip; + } + case None: + { + return TQAction::toolTip(); + } + default: + { + return TQString::null; + } + } +} + +void Action::setWhatsThis(const TQString &whatsThis, States states) +{ + if (states & All) + { + d->selfBlockedWhatsThis = whatsThis; + d->noWhatsThis = whatsThis; + d->authWhatsThis = whatsThis; + d->yesWhatsThis = whatsThis; + } + else if (states & Auth) + { + d->authWhatsThis = whatsThis; + } + else if (states & No) + { + d->noWhatsThis = whatsThis; + } + else if (states & SelfBlocked) + { + d->selfBlockedWhatsThis = whatsThis; + } + else if (states & Yes) + { + d->yesWhatsThis = whatsThis; + } + + d->updateAction(); +} + +TQString Action::whatsThis(Action::States state) const +{ + switch (state) + { + case Yes: + { + return d->yesWhatsThis; + } + case No: + { + return d->noWhatsThis; + } + case Auth: + { + return d->authWhatsThis; + } + case SelfBlocked: + { + return d->selfBlockedWhatsThis; + } + case None: + { + return TQAction::whatsThis(); + } + default: + { + return TQString::null; + } + } +} + +void Action::setIconSet(const TQIconSet &iconset, States states) +{ + if (states & All) + { + d->selfBlockedIconSet = iconset; + d->noIconSet = iconset; + d->authIconSet = iconset; + d->yesIconSet = iconset; + } + else if (states & Auth) + { + d->authIconSet = iconset; + } + else if (states & No) + { + d->noIconSet = iconset; + } + else if (states & SelfBlocked) + { + d->selfBlockedIconSet = iconset; + } + else if (states & Yes) + { + d->yesIconSet = iconset; + } + + d->updateAction(); +} + +TQIconSet Action::iconSet(Action::States state) const +{ + switch (state) + { + case Yes: + { + return d->yesIconSet; + } + case No: + { + return d->noIconSet; + } + case Auth: + { + return d->authIconSet; + } + case SelfBlocked: + { + return d->selfBlockedIconSet; + } + case None: + { + return TQAction::iconSet(); + } + default: + { + return TQIconSet(); + } + } +} + +void Action::setEnabled(bool enabled, States states) +{ + if (states & All) + { + d->selfBlockedEnabled = enabled; + d->noEnabled = enabled; + d->authEnabled = enabled; + d->yesEnabled = enabled; + } + else if (states & Auth) + { + d->authEnabled = enabled; + } + else if (states & No) + { + d->noEnabled = enabled; + } + else if (states & SelfBlocked) + { + d->selfBlockedEnabled = enabled; + } + else if (states & Yes) + { + d->yesEnabled = enabled; + } + + d->updateAction(); +} + +bool Action::isEnabled(Action::States state) const +{ + switch (state) + { + case Yes: + { + return d->yesEnabled; + } + case No: + { + return d->noEnabled; + } + case Auth: + { + return d->authEnabled; + } + case SelfBlocked: + { + return d->selfBlockedEnabled; + } + case None: + { + return TQAction::isEnabled(); + } + default: + { + return false; + } + } +} + +void Action::setVisible(bool visible, States states) +{ + if (states & All) + { + d->selfBlockedVisible = visible; + d->noVisible = visible; + d->authVisible = visible; + d->yesVisible = visible; + } + else if (states & Auth) + { + d->authVisible = visible; + } + else if (states & No) + { + d->noVisible = visible; + } + else if (states & SelfBlocked) + { + d->selfBlockedVisible = visible; + } + else if (states & Yes) + { + d->yesVisible = visible; + } + + d->updateAction(); +} + +bool Action::isVisible(Action::States state) const +{ + switch (state) + { + case Yes: + { + return d->yesVisible; + } + case No: + { + return d->noVisible; + } + case Auth: + { + return d->authVisible; + } + case SelfBlocked: + { + return d->selfBlockedVisible; + } + case None: + { + return TQAction::isVisible(); + } + default: + { + return false; + } + } +} + +void Action::setPolkitAction(const TQString &actionId) +{ + d->actionId = actionId; + + d->computePkResult(); + d->updateAction(); +} + +TQString Action::actionId() const +{ + return d->actionId; +} + +} + +} + +#include "polkit-tqt-gui-action.moc" + diff --git a/gui/polkit-tqt-gui-action.h b/gui/polkit-tqt-gui-action.h new file mode 100644 index 000000000..3149fff92 --- /dev/null +++ b/gui/polkit-tqt-gui-action.h @@ -0,0 +1,307 @@ +/* + * This file is part of the Polkit-tqt project + * Copyright (C) 2009 Daniel Nicoletti + * Copyright (C) 2009 Dario Freddi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef POLKIT_TQT_GUI_ACTION_H +#define POLKIT_TQT_GUI_ACTION_H + +#include "polkit-tqt-export.h" + +#include + + +namespace PolkitTQt +{ + +namespace Gui +{ + +/** + * \class Action polkit-tqt-gui-action.h Action + * \author Daniel Nicoletti + * \author Dario Freddi + * + * \brief Class used to manage actions + * + * This class is an interface around PolicyKit Actions. + * By using this class, you are able to track the result of a + * given action. + * + * Most of the times, you would want to use this class combined + * with a TQButton. In this case, you can use the more + * comfortable ActionButton class that manages button's properties + * update for you. + * + * \see ActionButton + */ +class POLKIT_TQT_EXPORT Action : public TQAction +{ + Q_OBJECT + + public: + enum States + { + None = 0, + SelfBlocked = 1, + Yes = 2, + No = 4, + Auth = 8, + // Future usage = 16, + // Future usage = 32, + // Future usage = 64, + // Future usage = 128, + // Future usage = 256, + All = 512 + }; + + /** + * Constructs a new Action item + * + * \param actionId the PolicyKit action Id (e.g.: org.freedesktop.policykit.read) + * \param parent the object parent + */ + explicit Action(const TQString& actionId = TQString::null, TQObject *parent = 0); + + ~Action(); + + signals: + /** + * Emitted when the PolicyKit result (PolKitResult) + * for the given action or the internal data changes + * (i.e. the user called one of the set methods). + * You should connect to this signal if you want + * to track these changes. + */ + void dataChanged(); + + /** + * Emitted when using this class as a proxy for a given + * action, It's only emitted if the activate() slot is + * called and the auth permits the action + * + * \see activate() + */ + void authorized(); + +public slots: + /** + * Use this slot if you want to activate the action. + * authorized() will be emitted if the action gets authorized. + * + * \return \c true if the caller can do the action + * + * \see authorized() + */ + bool activate(); + + /** + * Defines the checked state. The opposite state will + * trigger authentication for this actions. For example, if + * you set this to \c true, when the action's checked state + * will become \c false, the authentication will be triggered. + * + * \param checked the new checked state + */ + void setChecked(bool checked); + + /** + * This method can be used to revoke the authorization + * obtained for this action. + */ + void revoke(); + +public: + /** + * Changes the action being tracked + * + * \param actionId The new action ID + */ + void setPolkitAction(const TQString &actionId); + + /** + * Returns the current action ID. + * + * \return The action ID + * + */ + TQString actionId() const; + + /** + * Sets the text for the current action. This will + * be shown only in the states specified in the \c states parameter. + * \param text the new text for the action + * \param states the states of the Polkit action on which the setting + * will be applied + */ + void setText(const TQString &text, States states = All); + + /** + * Sets the tooltip for the current action. This will + * be shown only in the states specified in the \c states parameter. + * \param toolTip the new tooltip for the action + * \param states the states of the Polkit action on which the setting + * will be applied + */ + void setToolTip(const TQString &toolTip, States states = All); + + /** + * Sets the whatsthis for the current action. This will + * be shown only in the states specified in the \c states parameter. + * \param whatsThis the new whatsthis for the action + * \param states the states of the Polkit action on which the setting + * will be applied + */ + void setWhatsThis(const TQString &whatsThis, States states = All); + + /** + * Sets the iconset for the current action. This will + * be shown only in the states specified in the \c states parameter. + * \note You need to pass a TQIconSet here. You can easily + * create one from a Pixmap + * \param iconset the new icon for the action + * \param states the states of the Polkit action on which the setting + * will be applied + */ + void setIconSet(const TQIconSet &iconset, States states = All); + + /** + * Sets whether the current action is visible or not. This will + * be applied only in the states specified in the \c states parameter. + * \param visible visibility of the action + * \param states the states of the Polkit action on which the setting + * will be applied + */ + void setVisible(bool visible, States states = All); + + /** + * Sets whether the current action is enabled or not. This will + * be shown only in the states specified in the \c states parameter. + * \param enabled whether the Action will be enabled or not + * \param states the states of the Polkit action on which the setting + * will be applied + */ + void setEnabled(bool enabled, States states = All); + + /** + * This function sets the process id of the target that + * should receive the authorization. Set this to 0 to set + * the current process as the target. + * + * \param pid The target process id; 0 if it is the current process + */ + void setTargetPID(TQ_LONG pid); + + /** + * Gets the text of the action when it is in the specified state + * + * \note Passing None will return the current value + * \param state The state to be checked + * \returns The text shown when the action is in the specified state + */ + TQString text(States state = None) const; + + /** + * Gets the tooltip of the action when it is in the specified state + * + * \note Passing None will return the current value + * \param state The state to be checked + * \returns The tooltip shown when the action is in the specified state + */ + TQString toolTip(States state = None) const; + + /** + * Gets the whatsThis of the action when it is in the specified state + * + * \param state The state to be checked + * \returns The whatsThis shown when the action is in the specified state + */ + TQString whatsThis(States state = None) const; + + /** + * Gets the iconset of the action when it is in the specified state + * + * \note Passing None will return the current value + * \param state The state to be checked + * \returns The iconset shown when the action is in the specified state + */ + TQIconSet iconSet(States state = None) const; + + /** + * Gets whether the action is visible or not when it is in the specified state + * + * \note Passing None will return the current value + * \param state The state to be checked + * \returns Whether the action is visible or not in the specified state + */ + bool isVisible(States state = None) const; + + /** + * Gets whether the action is enabled or not when it is in the specified state + * + * \note Passing None will return the current value + * \param state The state to be checked + * \returns Whether the action is enabled or not in the specified state + */ + bool isEnabled(States state = None) const; + + /** + * \see setTargetPID + */ + TQ_LONG targetPID() const; + + /** + * This method can be used to check the if the current action + * can be performed (i.e. PolKitResult is YES). + * \note This method does not call the authentication dialog, use + * activate() instead + * \return \c true if the action can be performed + */ + bool isAllowed() const; + + /** + * This method compares a PolicyKit action Id with the + * current one of the object. + * + * \see actionId() + * + * \param actionId the action Id to compare + * + * \return \c true if the actionId is the same as this object's one + */ + bool is(const TQString &actionId) const; + + private: + // Disable copy + Action(const Action&); + Action& operator=(const Action&); + + class Private; + Private *const d; + + private slots: + void slotConfigChanged(); +}; + +} + +} + +#endif + diff --git a/gui/polkit-tqt-gui-actionbutton.cpp b/gui/polkit-tqt-gui-actionbutton.cpp new file mode 100644 index 000000000..1447bab66 --- /dev/null +++ b/gui/polkit-tqt-gui-actionbutton.cpp @@ -0,0 +1,173 @@ +/* + * This file is part of the Polkit-tqt project + * Copyright (C) 2009 Daniel Nicoletti + * Copyright (C) 2009 Dario Freddi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "polkit-tqt-gui-actionbutton.h" +#include "polkit-tqt-gui-actionbutton_p.h" + +#include +#include +#include + + +namespace PolkitTQt +{ + +namespace Gui +{ + +//-------------------------------------- +// ActionButtonPrivate +//-------------------------------------- + +void ActionButtonPrivate::addButton(TQButton *button) +{ + buttons.append(button); + TQObject::connect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool))); + TQObject::connect(q, SIGNAL(toggled(bool)), button, SLOT(toggle())); + q->updateButton(); +} + +void ActionButtonPrivate::removeButton(TQButton *button) +{ + if (buttons.contains(button)) + { + TQObject::disconnect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool))); + TQObject::disconnect(q, SIGNAL(toggled(bool)), button, SLOT(toggle())); + TQValueList::iterator butIt = buttons.find(button); + if (butIt != buttons.end()) + { + buttons.remove(butIt); + } + } +} + +//-------------------------------------- +// ActionButton +//-------------------------------------- + +ActionButton::ActionButton(ActionButtonPrivate &dd, const TQString &actionId, TQObject *parent) + : Action(actionId, parent), d(&dd) +{ + d->q = this; + connect(this, SIGNAL(dataChanged()), SLOT(updateButton())); +} + +ActionButton::ActionButton(TQButton *button, const TQString &actionId, TQObject *parent) + : Action(actionId, parent), d(new ActionButtonPrivate()) +{ + d->q = this; + d->buttons.append(button); + + setButton(button); + connect(this, SIGNAL(dataChanged()), SLOT(updateButton())); +} + +ActionButton::~ActionButton() +{ + delete d; +} + +void ActionButton::streamClicked(bool c) +{ + emit clicked(::tqt_cast(this->sender()), c); +} + +void ActionButton::updateButton() +{ + TQValueList::iterator butIt; + for (butIt = d->buttons.begin(); butIt != d->buttons.end(); ++butIt) + { + TQButton *ent = *butIt; + if (isVisible()) + { + ent->show(); + } + else + { + ent->hide(); + } + ent->setEnabled(isEnabled()); + ent->setText(text()); + //if (!toolTip().isNull()) + //{ + // ent->setToolTip(toolTip()); + //} + //if (!whatsThis().isNull()) + //{ + // ent->setWhatsThis(whatsThis()); + //} + ent->setPixmap(iconSet().pixmap()); + // if the item cannot do the action anymore + // lets revert to the initial state + if (ent->isToggleButton()) + { + ent->setDown(isOn()); + } + } +} + +bool ActionButton::activate() +{ + bool tg = false; + TQValueList::iterator butIt; + for (butIt = d->buttons.begin(); butIt != d->buttons.end(); ++butIt) + { + TQButton *ent = *butIt; + if (ent->isToggleButton()) + { + // we set the the current Action state + ent->setDown(isOn()); + // toggle the action cause we are not directly connected there.. + tg = true; + } + } + + if (tg) + { + toggle(); + } + + return Action::activate(); +} + +void ActionButton::setButton(TQButton *button) +{ + // First, let's clear the list + while (!d->buttons.isEmpty()) + { + d->removeButton(d->buttons.first()); + } + + // And then add it + d->addButton(button); +} + +TQButton* ActionButton::button() const +{ + return d->buttons.first(); +} + +} + +} + +#include "polkit-tqt-gui-actionbutton.moc" + diff --git a/gui/polkit-tqt-gui-actionbutton.h b/gui/polkit-tqt-gui-actionbutton.h new file mode 100644 index 000000000..44faff4ac --- /dev/null +++ b/gui/polkit-tqt-gui-actionbutton.h @@ -0,0 +1,155 @@ +/* + * This file is part of the Polkit-tqt project + * Copyright (C) 2009 Daniel Nicoletti + * Copyright (C) 2009 Dario Freddi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef POLKIT_TQT_GUI_ACTIONBUTTON_H +#define POLKIT_TQT_GUI_ACTIONBUTTON_H + +#include "polkit-tqt-export.h" +#include "polkit-tqt-gui-action.h" + +class TQButton; +class TQString; + + +namespace PolkitTQt +{ + +namespace Gui +{ + +class ActionButtonPrivate; + +/** + * \class ActionButton polkit-tqt-gui-actionbutton.h ActionButton + * \author Daniel Nicoletti + * \author Dario Freddi + * + * \brief Class used to hold and update a TQButton + * + * This class allows you to associate TQButtons + * (i.e. TQPushButton) to a PolicyKit Action. It will update the + * button properties according to the PolicyKit Action automatically. + * + * \note You should connect the activated() signal to receive + * a notification when the user clicked the button and gets + * permission to perform the given action. If you set 'noEnabled' + * to \c true it will be emitted when PolKitResult is NO. + */ +class POLKIT_TQT_EXPORT ActionButton : public Action +{ + Q_OBJECT + + public: + /** + * Constructs a new ActionButton. You need to pass this + * constructor an existing TQButton, whose properties + * will be modified according to the underlying Action + * object. As ActionButton inherits from Action, you can + * define your button's behavior right through this wrapper. + * + * \see Action + * + * \param button the TQButton to associate to this ActionButton + * \param actionId the action Id to create the underlying Action + * \param parent the parent object + */ + explicit ActionButton(TQButton *button, const TQString &actionId = TQString::null, + TQObject *parent = 0); + virtual ~ActionButton(); + + /** + * Sets the button associated to the underlying action. + * + * \note If you are calling this function, you're probably + * changing the button the action is referring to. If this + * is the case, please note that Polkit-TQt does not handle + * the previous button's memory, so you should take care of + * deleting it yourself (if needed). You can retrieve it by + * using button() + * + * \see button + * + * \param button the new button associated with the underlying action + */ + void setButton(TQButton *button); + + /** + * Returns the current button + * + * \return the button currently associated with the underlying action + */ + TQButton* button() const; + + public slots: + /** + * Connect clicked() signals to this slot. This should be + * manually done, as in some cases we might want + * to manually call this. Calling this will emit authorized(). + * + * \note This slot is reentrant which is likely to only be a problem + * if you are creating an interface to setup PolicyKit policies. + * \note If you have a checkbox, connect to its' clicked() signal + * to avoid an infinite loop as this function internally calls setChecked(). + * You can always use the clicked(bool) signal in this class to + * connect to here. + * \warning if you use this class take care to not call Action::activate + * otherwise your checkable buttons won't be properly updated. + */ + bool activate(); + + signals: + /** + * Emitted when the abstract button clicked(bool) signal + * is emitted. This allows you to use qobject_cast(sender()) + * in a slot connected to this signal and call activate() on it. + * + * \note you will normally want to connect this signal + * to the activate slot. + * + * \param button the button that has been clicked + * \param checked the checked state, if applicable. Otherwise \c false + * + */ + void clicked(TQButton *button, bool checked = false); + + protected: + ActionButton(ActionButtonPrivate &dd, const TQString &actionId, TQObject *parent = 0); + + ActionButtonPrivate *const d; + + private: + // Disable copy + ActionButton(const ActionButton&); + ActionButton& operator=(const ActionButton&); + + friend class ActionButtonPrivate; + + private slots: + void updateButton(); + void streamClicked(bool); +}; + +} + +} + +#endif + diff --git a/gui/polkit-tqt-gui-actionbutton_p.h b/gui/polkit-tqt-gui-actionbutton_p.h new file mode 100644 index 000000000..e53eeae0a --- /dev/null +++ b/gui/polkit-tqt-gui-actionbutton_p.h @@ -0,0 +1,60 @@ +/* + * This file is part of the Polkit-tqt project + * Copyright (C) 2009 Dario Freddi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef POLKIT_TQT_GUI_ACTIONBUTTON_P_H +#define POLKIT_TQT_GUI_ACTIONBUTTON_P_H + +#include + +class TQButton; +template class TQValueList; + + +namespace PolkitTQt +{ + +namespace Gui +{ + +class ActionButtonPrivate +{ + public: + ActionButtonPrivate() + { + } + + virtual ~ActionButtonPrivate() + { + } + + void addButton(TQButton *button); + void removeButton(TQButton *button); + + ActionButton *q; + + TQValueList buttons; +}; + +} + +} + +#endif + diff --git a/gui/polkit-tqt-gui-actionbuttons.cpp b/gui/polkit-tqt-gui-actionbuttons.cpp new file mode 100644 index 000000000..78aced5d6 --- /dev/null +++ b/gui/polkit-tqt-gui-actionbuttons.cpp @@ -0,0 +1,75 @@ +/* + * This file is part of the Polkit-tqt project + * Copyright (C) 2009 Dario Freddi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "polkit-tqt-gui-actionbuttons.h" +#include "polkit-tqt-gui-actionbuttons_p.h" + +#include +#include +#include + + +namespace PolkitTQt +{ + +namespace Gui +{ + +ActionButtons::ActionButtons(const TQValueList &buttons, const TQString &actionId, + TQObject *parent) : ActionButton(*new ActionButtonPrivate(), actionId, parent) +{ + setButtons(buttons); +} + +ActionButtons::~ActionButtons() +{ +} + +void ActionButtons::setButtons(const TQValueList &buttons) +{ + TQValueList::iterator butIt; + for (butIt = d->buttons.begin(); butIt != d->buttons.end(); ++butIt) + { + TQButton *ent = *butIt; + addButton(ent); + } +} + +TQValueList ActionButtons::buttons() const +{ + return d->buttons; +} + +void ActionButtons::addButton(TQButton *button) +{ + d->addButton(button); +} + +void ActionButtons::removeButton(TQButton *button) +{ + d->removeButton(button); +} + +} + +} + +#include "polkit-tqt-gui-actionbuttons.moc" + diff --git a/gui/polkit-tqt-gui-actionbuttons.h b/gui/polkit-tqt-gui-actionbuttons.h new file mode 100644 index 000000000..b85b632be --- /dev/null +++ b/gui/polkit-tqt-gui-actionbuttons.h @@ -0,0 +1,119 @@ +/* + * This file is part of the Polkit-tqt project + * Copyright (C) 2009 Dario Freddi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef POLKIT_TQT_GUI_ACTIONBUTTONS_H +#define POLKIT_TQT_GUI_ACTIONBUTTONS_H + +#include "polkit-tqt-gui-actionbutton.h" + + +namespace PolkitTQt +{ + +namespace Gui +{ + +class ActionButtonsPrivate; + +/** + * \class ActionButtons polkit-tqt-gui-actionbuttons.h ActionButtons + * \author Dario Freddi + * + * \brief Class used to hold and update a list of TQButtons + * + * This class is a convenience wrapper around ActionButton that lets + * you associate an undefined number of TQButtons with a single action. + * Every button will be updated accordingly upon action's properties changes. + * + * \see ActionButton + */ +class ActionButtons : public ActionButton +{ + Q_OBJECT + + public: + /** + * Constructs a new ActionButtons. You need to pass this + * constructor an existing list of TQButtons, whose properties + * will be modified according to the underlying Action + * object. As ActionButtons inherits from Action, you can + * define your buttons' behavior right through this wrapper. + * + * \see Action + * + * \param buttons the TQButton to associate to this ActionButtons + * \param actionId the action Id to create the underlying Action + * \param parent the parent object + */ + explicit ActionButtons(const TQValueList &buttons, + const TQString &actionId = TQString::null, TQObject *parent = 0); + virtual ~ActionButtons(); + + /** + * Sets a list of buttons associated to the underlying action. + * + * \note If you are calling this function, you're probably + * changing the buttons list the action is referring to. If this + * is the case, please note that Polkit-TQt does not handle + * the previous buttons' memory, so you should take care of + * deleting them yourself (if needed). You can retrieve it by + * using buttons() + * + * \see buttons + * + * \param buttons the new buttons associated with the underlying action + */ + void setButtons(const TQValueList &buttons); + + /** + * Returns the current buttons list + * + * \return the buttons currently associated with the underlying action + */ + TQValueList buttons() const; + + /** + * Adds a button to the current button list. The button's properties + * will be updated according to the action upon adding. + * + * \param button the button to add + */ + void addButton(TQButton *button); + + /** + * Removes a button from the current list. Please note that Polkit-TQt + * does not handle the removed button's memory, so you should take care of + * deleting it yourself (if needed). + * + * \param button the button to remove + */ + void removeButton(TQButton *button); + + private: + // Disable copy + ActionButtons(const ActionButtons&); + ActionButtons& operator=(const ActionButtons&); +}; + +} + +} + +#endif diff --git a/gui/polkit-tqt-gui-actionbuttons_p.h b/gui/polkit-tqt-gui-actionbuttons_p.h new file mode 100644 index 000000000..74e918eb2 --- /dev/null +++ b/gui/polkit-tqt-gui-actionbuttons_p.h @@ -0,0 +1,49 @@ +/* + * This file is part of the Polkit-tqt project + * Copyright (C) 2009 Dario Freddi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef POLKIT_TQT_GUI_ACTIONBUTTONS_P_H +#define POLKIT_TQT_GUI_ACTIONBUTTONS_P_H + +#include "polkit-tqt-gui-actionbutton_p.h" + +class TQButton; +template class TQValueList; + + +namespace PolkitTQt +{ + +namespace Gui +{ + +class ActionButtonsPrivate : public ActionButtonPrivate +{ + public: + ActionButtonsPrivate() : ActionButtonPrivate() + { + } +}; + +} + +} + +#endif + diff --git a/gui/polkittqt1-gui-action.cpp b/gui/polkittqt1-gui-action.cpp deleted file mode 100644 index 2b399b29a..000000000 --- a/gui/polkittqt1-gui-action.cpp +++ /dev/null @@ -1,517 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Daniel Nicoletti - * Copyright (C) 2009 Dario Freddi - * Copyright (C) 2009 Jaroslav Reznik - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "polkit-tqt-gui-action.h" -#include "polkit-tqt-authority.h" -#include "polkit-tqt-subject.h" - -#include - - -namespace PolkitTQt -{ - -namespace Gui -{ - -/** - * \internal - */ -class Action::Private -{ -public: - Private(Action *p); - - Action *parent; - - TQString actionId; - Authority::Result pkResult; - TQ_LONG targetPID; - - void updateAction(); - bool computePkResult(); - void configChanged(); - - bool initiallyChecked; - - // states data - bool selfBlockedVisible; - bool selfBlockedEnabled; - TQString selfBlockedText; - TQString selfBlockedWhatsThis; - TQString selfBlockedToolTip; - TQIcon selfBlockedIcon; - - bool noVisible; - bool noEnabled; - TQString noText; - TQString noWhatsThis; - TQString noToolTip; - TQIcon noIcon; - - bool authVisible; - bool authEnabled; - TQString authText; - TQString authWhatsThis; - TQString authToolTip; - TQIcon authIcon; - - bool yesVisible; - bool yesEnabled; - TQString yesText; - TQString yesWhatsThis; - TQString yesToolTip; - TQIcon yesIcon; -}; - -Action::Private::Private(Action *p) - : parent(p) - , targetPID(getpid()) -{ - initiallyChecked = false; - - // Set the default values - selfBlockedVisible = true; - selfBlockedEnabled = false; - - noVisible = true; - noEnabled = false; - - authVisible = true; - authEnabled = true; - - yesVisible = true; - yesEnabled = true; -} - -Action::Action(const TQString &actionId, TQObject *parent) - : TQAction(parent) - , d(new Private(this)) -{ - // this must be called AFTER the values initialization - setPolkitAction(actionId); - - // track the config changes to update the action - connect(Authority::instance(), SIGNAL(configChanged()), - this, SLOT(configChanged())); - // for now we call config changed.. - connect(Authority::instance(), SIGNAL(consoleKitDBChanged()), - this, SLOT(configChanged())); -} - -Action::~Action() -{ - delete d; -} - -bool Action::activate() -{ - switch (d->pkResult) { - case Authority::Yes: - case Authority::Challenge: - // just Q_EMIT the 'activated' signal - TQ_EMIT authorized(); - return true; - break; - default: - case Authority::No: - if (d->noEnabled) { - /* If PolicyKit says no... and we got here.. it means - * that the user set the property "no-enabled" to - * TRUE.. - * - * Hence, they probably have a good reason for doing - * this so do let the 'activate' signal propagate.. - */ - TQ_EMIT authorized(); - return true; - } - break; - } - return false; -} - -void Action::setChecked(bool checked) -{ - // We store this as initiallyChecked - // to be able to undo changes in case the auth fails - d->initiallyChecked = checked; - TQAction::setChecked(checked); -} - -void Action::Private::updateAction() -{ - if (Authority::instance()->hasError()) { - return; - } - - switch (pkResult) { - default: - case Authority::Unknown: - case Authority::No: - qobject_cast(parent)->setVisible(noVisible); - qobject_cast(parent)->setEnabled(noEnabled); - qobject_cast(parent)->setText(noText); - if (!noWhatsThis.isNull()) { - qobject_cast(parent)->setWhatsThis(noWhatsThis); - } - if (!noToolTip.isNull()) { - qobject_cast(parent)->setToolTip(noToolTip); - } - qobject_cast(parent)->setIcon(noIcon); - break; - - case Authority::Challenge: - qobject_cast(parent)->setVisible(authVisible); - qobject_cast(parent)->setEnabled(authEnabled); - qobject_cast(parent)->setText(authText); - if (!authWhatsThis.isNull()) { - qobject_cast(parent)->setWhatsThis(authWhatsThis); - } - if (!authToolTip.isNull()) { - qobject_cast(parent)->setToolTip(authToolTip); - } - qobject_cast(parent)->setIcon(authIcon); - break; - case Authority::Yes: - qobject_cast(parent)->setVisible(yesVisible); - qobject_cast(parent)->setEnabled(yesEnabled); - qobject_cast(parent)->setText(yesText); - if (!yesWhatsThis.isNull()) { - qobject_cast(parent)->setWhatsThis(yesWhatsThis); - } - if (!yesToolTip.isNull()) { - qobject_cast(parent)->setToolTip(yesToolTip); - } - qobject_cast(parent)->setIcon(yesIcon); - if (parent->isCheckable()) { - qobject_cast(parent)->setChecked(!initiallyChecked); - } - break; - } - TQ_EMIT parent->dataChanged(); -} - -void Action::Private::configChanged() -{ - bool result_changed; - result_changed = computePkResult(); - if (result_changed) { - updateAction(); - } -} - -bool Action::Private::computePkResult() -{ - Authority::Result old_result; - UnixProcessSubject subject(parent->targetPID()); - - old_result = pkResult; - pkResult = Authority::Unknown; - - pkResult = Authority::instance()->checkAuthorizationSync(actionId, subject, Authority::None); - - return old_result != pkResult; -} - -TQ_LONG Action::targetPID() const -{ - if (d->targetPID != 0) { - return d->targetPID; - } else { - return TQCoreApplication::applicationPid(); - } -} - -void Action::setTargetPID(TQ_LONG pid) -{ - d->targetPID = pid; - - d->computePkResult(); - d->updateAction(); -} - -bool Action::isAllowed() const -{ - return d->pkResult == Authority::Yes; -} - -bool Action::is(const TQString &other) const -{ - return d->actionId == other; -} - -void Action::revoke() -{ - /*TODO: implement it? no negative authorizations available, no authorization db*/ -} - -void Action::setText(const TQString &text, States states) -{ - if (states & All) { - d->selfBlockedText = text; - d->noText = text; - d->authText = text; - d->yesText = text; - } else if (states & Auth) { - d->authText = text; - } else if (states & No) { - d->noText = text; - } else if (states & SelfBlocked) { - d->selfBlockedText = text; - } else if (states & Yes) { - d->yesText = text; - } - - d->updateAction(); -} - -TQString Action::text(Action::State state) const -{ - switch (state) { - case Yes: - return d->yesText; - case No: - return d->noText; - case Auth: - return d->authText; - case SelfBlocked: - return d->selfBlockedText; - case None: - return TQAction::text(); - default: - return TQString(); - } -} - -void Action::setToolTip(const TQString &toolTip, States states) -{ - if (states & All) { - d->selfBlockedToolTip = toolTip; - d->noToolTip = toolTip; - d->authToolTip = toolTip; - d->yesToolTip = toolTip; - } else if (states & Auth) { - d->authToolTip = toolTip; - } else if (states & No) { - d->noToolTip = toolTip; - } else if (states & SelfBlocked) { - d->selfBlockedToolTip = toolTip; - } else if (states & Yes) { - d->yesToolTip = toolTip; - } - - d->updateAction(); -} - -TQString Action::toolTip(Action::State state) const -{ - switch (state) { - case Yes: - return d->yesToolTip; - case No: - return d->noToolTip; - case Auth: - return d->authToolTip; - case SelfBlocked: - return d->selfBlockedToolTip; - case None: - return TQAction::toolTip(); - default: - return TQString(); - } -} - -void Action::setWhatsThis(const TQString &whatsThis, States states) -{ - if (states & All) { - d->selfBlockedWhatsThis = whatsThis; - d->noWhatsThis = whatsThis; - d->authWhatsThis = whatsThis; - d->yesWhatsThis = whatsThis; - } else if (states & Auth) { - d->authWhatsThis = whatsThis; - } else if (states & No) { - d->noWhatsThis = whatsThis; - } else if (states & SelfBlocked) { - d->selfBlockedWhatsThis = whatsThis; - } else if (states & Yes) { - d->yesWhatsThis = whatsThis; - } - - d->updateAction(); -} - -TQString Action::whatsThis(Action::State state) const -{ - switch (state) { - case Yes: - return d->yesWhatsThis; - case No: - return d->noWhatsThis; - case Auth: - return d->authWhatsThis; - case SelfBlocked: - return d->selfBlockedWhatsThis; - case None: - return TQAction::whatsThis(); - default: - return TQString(); - } -} - -void Action::setIcon(const TQIcon &icon, States states) -{ - if (states & All) { - d->selfBlockedIcon = icon; - d->noIcon = icon; - d->authIcon = icon; - d->yesIcon = icon; - } else if (states & Auth) { - d->authIcon = icon; - } else if (states & No) { - d->noIcon = icon; - } else if (states & SelfBlocked) { - d->selfBlockedIcon = icon; - } else if (states & Yes) { - d->yesIcon = icon; - } - - d->updateAction(); -} - -TQIcon Action::icon(Action::State state) const -{ - switch (state) { - case Yes: - return d->yesIcon; - case No: - return d->noIcon; - case Auth: - return d->authIcon; - case SelfBlocked: - return d->selfBlockedIcon; - case None: - return TQAction::icon(); - default: - return TQIcon(); - } -} - -void Action::setEnabled(bool enabled, States states) -{ - if (states & All) { - d->selfBlockedEnabled = enabled; - d->noEnabled = enabled; - d->authEnabled = enabled; - d->yesEnabled = enabled; - } else if (states & Auth) { - d->authEnabled = enabled; - } else if (states & No) { - d->noEnabled = enabled; - } else if (states & SelfBlocked) { - d->selfBlockedEnabled = enabled; - } else if (states & Yes) { - d->yesEnabled = enabled; - } - - d->updateAction(); -} - -bool Action::isEnabled(Action::State state) const -{ - switch (state) { - case Yes: - return d->yesEnabled; - case No: - return d->noEnabled; - case Auth: - return d->authEnabled; - case SelfBlocked: - return d->selfBlockedEnabled; - case None: - return TQAction::isEnabled(); - default: - return false; - } -} - -void Action::setVisible(bool visible, States states) -{ - if (states & All) { - d->selfBlockedVisible = visible; - d->noVisible = visible; - d->authVisible = visible; - d->yesVisible = visible; - } else if (states & Auth) { - d->authVisible = visible; - } else if (states & No) { - d->noVisible = visible; - } else if (states & SelfBlocked) { - d->selfBlockedVisible = visible; - } else if (states & Yes) { - d->yesVisible = visible; - } - - d->updateAction(); -} - -bool Action::isVisible(Action::State state) const -{ - switch (state) { - case Yes: - return d->yesVisible; - case No: - return d->noVisible; - case Auth: - return d->authVisible; - case SelfBlocked: - return d->selfBlockedVisible; - case None: - return TQAction::isVisible(); - default: - return false; - } -} - -void Action::setPolkitAction(const TQString &actionId) -{ - //TODO: - d->actionId = actionId; - - d->computePkResult(); - d->updateAction(); -} - -//-------------------------------------------------- - -TQString Action::actionId() const -{ - return d->actionId; -} - -} - -} - -#include "polkit-tqt-gui-action.moc" - diff --git a/gui/polkittqt1-gui-action.h b/gui/polkittqt1-gui-action.h deleted file mode 100644 index 802a790f8..000000000 --- a/gui/polkittqt1-gui-action.h +++ /dev/null @@ -1,305 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Daniel Nicoletti - * Copyright (C) 2009 Dario Freddi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef POLKIT_TQT_GUI_ACTION_H -#define POLKIT_TQT_GUI_ACTION_H - -#include "polkit-tqt-export.h" - -#include - - -namespace PolkitTQt -{ - -namespace Gui -{ - -/** - * \class Action polkit-tqt-gui-action.h Action - * \author Daniel Nicoletti - * \author Dario Freddi - * - * \brief Class used to manage actions - * - * This class is an interface around PolicyKit Actions. - * By using this class, you are able to track the result of a - * given action. - * - * Most of the times, you would want to use this class combined - * with a TQAbstractButton. In this case, you can use the more - * comfortable ActionButton class that manages button's properties - * update for you. - * - * \see ActionButton - */ -class POLKITTQT1_EXPORT Action : public TQAction -{ - Q_OBJECT - TQ_DISABLE_COPY(Action) -public: - - enum State { - None = 0, - SelfBlocked = 1, - Yes = 2, - No = 4, - Auth = 8, - // Future usage = 16, - // Future usage = 32, - // Future usage = 64, - // Future usage = 128, - // Future usage = 256, - All = 512 - }; - TQ_DECLARE_FLAGS(States, State) - - /** - * Constructs a new Action item - * - * \param actionId the PolicyKit action Id (e.g.: org.freedesktop.policykit.read) - * \param parent the object parent - */ - explicit Action(const TQString &actionId = TQString(), TQObject *parent = 0); - ~Action(); - -Q_SIGNALS: - /** - * Emitted when the PolicyKit result (PolKitResult) - * for the given action or the internal data changes - * (i.e. the user called one of the set methods). - * You should connect to this signal if you want - * to track these changes. - */ - void dataChanged(); - - /** - * Emitted when using this class as a proxy - * for a given action, It's only emitted if the - * activate() slot is called and the auth permits - * the action - * - * \see activate() - */ - void authorized(); - -public Q_SLOTS: - /** - * Use this slot if you want to activate - * the action. authorized() will be emitted - * if the action gets authorized. - * - * \return \c true if the caller can do the action - * - * \see authorized() - */ - bool activate(); - - /** - * Defines the checked state. The opposite state will - * trigger authentication for this actions. For example, if - * you set this to \c true, when the action's checked state - * will become \c false, the authentication will be triggered. - * - * \param checked the new checked state - */ - void setChecked(bool checked); - - /** - * This method can be used to revoke the authorization - * obtained for this action. - */ - void revoke(); - -public: - /** - * Changes the action being tracked - * - * \param actionId The new action ID - */ - void setPolkitAction(const TQString &actionId); - - /** - * Returns the current action ID. - * - * \return The action ID - * - */ - TQString actionId() const; - - /** - * Sets the text for the current action. This will - * be shown only in the states specified in the \c states parameter. - * \param text the new text for the action - * \param states the states of the Polkit action on which the setting - * will be applied - */ - void setText(const TQString &text, States states = All); - - /** - * Sets the tooltip for the current action. This will - * be shown only in the states specified in the \c states parameter. - * \param toolTip the new tooltip for the action - * \param states the states of the Polkit action on which the setting - * will be applied - */ - void setToolTip(const TQString &toolTip, States states = All); - - /** - * Sets the whatsthis for the current action. This will - * be shown only in the states specified in the \c states parameter. - * \param whatsThis the new whatsthis for the action - * \param states the states of the Polkit action on which the setting - * will be applied - */ - void setWhatsThis(const TQString &whatsThis, States states = All); - - /** - * Sets the icon for the current action. This will - * be shown only in the states specified in the \c states parameter. - * \note You need to pass a TQIcon here. You can easily - * create one from a Pixmap, or pass a KIcon - * \param icon the new icon for the action - * \param states the states of the Polkit action on which the setting - * will be applied - */ - void setIcon(const TQIcon &icon, States states = All); - - /** - * Sets whether the current action is visible or not. This will - * be applied only in the states specified in the \c states parameter. - * \param visible visibility of the action - * \param states the states of the Polkit action on which the setting - * will be applied - */ - void setVisible(bool visible, States states = All); - - /** - * Sets whether the current action is enabled or not. This will - * be shown only in the states specified in the \c states parameter. - * \param enabled whether the Action will be enabled or not - * \param states the states of the Polkit action on which the setting - * will be applied - */ - void setEnabled(bool enabled, States states = All); - - /** - * This function sets the process id of the target that - * should receive the authorization. Set this to 0 to set - * the current process as the target. - * - * \param pid The target process id; 0 if it is the current process - */ - void setTargetPID(TQ_LONG pid); - - /** - * Gets the text of the action when it is in the specified state - * - * \note Passing None will return the current value - * \param state The state to be checked - * \returns The text shown when the action is in the specified state - */ - TQString text(State state = None) const; - - /** - * Gets the tooltip of the action when it is in the specified state - * - * \note Passing None will return the current value - * \param state The state to be checked - * \returns The tooltip shown when the action is in the specified state - */ - TQString toolTip(State state = None) const; - - /** - * Gets the whatsThis of the action when it is in the specified state - * - * \param state The state to be checked - * \returns The whatsThis shown when the action is in the specified state - */ - TQString whatsThis(State state = None) const; - - /** - * Gets the icon of the action when it is in the specified state - * - * \note Passing None will return the current value - * \param state The state to be checked - * \returns The icon shown when the action is in the specified state - */ - TQIcon icon(State state = None) const; - - /** - * Gets whether the action is visible or not when it is in the specified state - * - * \note Passing None will return the current value - * \param state The state to be checked - * \returns Whether the action is visible or not in the specified state - */ - bool isVisible(State state = None) const; - - /** - * Gets whether the action is enabled or not when it is in the specified state - * - * \note Passing None will return the current value - * \param state The state to be checked - * \returns Whether the action is enabled or not in the specified state - */ - bool isEnabled(State state = None) const; - - /** - * \see setTargetPID - */ - TQ_LONG targetPID() const; - - /** - * This method can be used to check the if the current action - * can be performed (i.e. PolKitResult is YES). - * \note This method does not call the authentication dialog, use - * activate() instead - * \return \c true if the action can be performed - */ - bool isAllowed() const; - - /** - * This method compares a PolicyKit action Id with the - * current one of the object. - * - * \see actionId() - * - * \param actionId the action Id to compare - * - * \return \c true if the actionId is the same as this object's one - */ - bool is(const TQString &actionId) const; - -private: - class Private; - Private * const d; - - Q_PRIVATE_SLOT(d, void configChanged()) -}; - -} - -} - -TQ_DECLARE_OPERATORS_FOR_FLAGS(PolkitTQt1::Gui::Action::States) - -#endif diff --git a/gui/polkittqt1-gui-actionbutton.cpp b/gui/polkittqt1-gui-actionbutton.cpp deleted file mode 100644 index 7521fa550..000000000 --- a/gui/polkittqt1-gui-actionbutton.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Daniel Nicoletti - * Copyright (C) 2009 Dario Freddi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "polkit-tqt-gui-actionbutton.h" - -#include "polkit-tqt-gui-actionbutton_p.h" - -namespace PolkitTQt -{ - -namespace Gui -{ - -ActionButton::ActionButton(TQAbstractButton *button, const TQString &actionId, TQObject *parent) - : Action(actionId, parent) - , d_ptr(new ActionButtonPrivate(TQList() << button)) -{ - d_ptr->q_ptr = this; - - setButton(button); - connect(this, SIGNAL(dataChanged()), SLOT(updateButton())); -} - -ActionButton::ActionButton(ActionButtonPrivate &dd, const TQString &actionId, TQObject *parent) - : Action(actionId, parent) - , d_ptr(&dd) -{ - d_ptr->q_ptr = this; - - connect(this, SIGNAL(dataChanged()), SLOT(updateButton())); -} - -ActionButton::~ActionButton() -{ - delete d_ptr; -} - -void ActionButtonPrivate::updateButton() -{ - TQ_Q(ActionButton); - - TQ_FOREACH(TQAbstractButton *ent, buttons) { - ent->setVisible(q->isVisible()); - ent->setEnabled(q->isEnabled()); - ent->setText(q->text()); - if (!q->toolTip().isNull()) { - ent->setToolTip(q->toolTip()); - } - if (!q->whatsThis().isNull()) { - ent->setWhatsThis(q->whatsThis()); - } - ent->setIcon(q->icon()); - // if the item cannot do the action anymore - // lets revert to the initial state - if (ent->isCheckable()) { - ent->setChecked(q->isChecked()); - } - } -} - -bool ActionButton::activate() -{ - TQ_D(ActionButton); - - bool tg = false; - TQ_FOREACH(TQAbstractButton *ent, d->buttons) { - if (ent->isCheckable()) { - // we set the the current Action state - ent->setChecked(isChecked()); - // toggle the action cause we are not directly connected there.. - tg = true; - } - } - - if (tg) { - toggle(); - } - - return Action::activate(); -} - -void ActionButton::setButton(TQAbstractButton *button) -{ - TQ_D(ActionButton); - - // First, let's clear the list - TQ_FOREACH(TQAbstractButton *ent, d->buttons) { - d->removeButton(ent); - } - - // And then add it - d->addButton(button); -} - -void ActionButtonPrivate::addButton(TQAbstractButton *button) -{ - TQ_Q(ActionButton); - - buttons.append(button); - TQObject::connect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool))); - TQObject::connect(q, SIGNAL(toggled(bool)), button, SLOT(toggle())); - if (q->isCheckable()) { - // the button should follow our first buttons - button->setCheckable(true); - } else if (button->isCheckable()) { - // if we are not checkable BUT the button - // is (eg a TQCheckBox) we should set all buttons to - // checkable. - TQ_FOREACH(TQAbstractButton *ent, buttons) { - ent->setCheckable(true); - } - // set the checkable state of Action to store the initial state - q->setCheckable(true); - } - // call this after m_activateOnCheck receives the value - updateButton(); -} - -void ActionButtonPrivate::removeButton(TQAbstractButton *button) -{ - TQ_Q(ActionButton); - - if (buttons.contains(button)) { - TQObject::disconnect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool))); - TQObject::disconnect(q, SIGNAL(toggled(bool)), button, SLOT(toggle())); - buttons.removeOne(button); - } -} - -TQAbstractButton *ActionButton::button() const -{ - TQ_D(const ActionButton); - - return d->buttons.first(); -} - -void ActionButtonPrivate::streamClicked(bool c) -{ - TQ_Q(ActionButton); - - TQ_EMIT q->clicked(qobject_cast(q->sender()), c); -} - -} - -} - -#include "polkit-tqt-gui-actionbutton.moc" diff --git a/gui/polkittqt1-gui-actionbutton.h b/gui/polkittqt1-gui-actionbutton.h deleted file mode 100644 index fba18d3ae..000000000 --- a/gui/polkittqt1-gui-actionbutton.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Daniel Nicoletti - * Copyright (C) 2009 Dario Freddi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef POLKIT_TQT_GUI_ACTIONBUTTON_H -#define POLKIT_TQT_GUI_ACTIONBUTTON_H - -#include "polkit-tqt-export.h" -#include "polkit-tqt-gui-action.h" - -class TQAbstractButton; - -namespace PolkitTQt -{ - -namespace Gui -{ - -class ActionButtonPrivate; -/** - * \class ActionButton polkit-tqt-gui-actionbutton.h ActionButton - * \author Daniel Nicoletti - * \author Dario Freddi - * - * \brief Class used to hold and update a TQAbstractButton - * - * This class allows you to associate TQAbstractButtons - * (i.e. TQPushButton) to a PolicyKit Action. It will update the - * button properties according to the PolicyKit Action automatically. - * - * \note You should connect the activated() signal to receive - * a notification when the user clicked the button and gets - * permission to perform the given action. If you set 'noEnabled' - * to \c true it will be emitted when PolKitResult is NO. - */ -class POLKIT_TQT_EXPORT ActionButton : public Action -{ - Q_OBJECT - TQ_DECLARE_PRIVATE(ActionButton) - TQ_DISABLE_COPY(ActionButton) - -public: - /** - * Constructs a new ActionButton. You need to pass this - * constructor an existing TQAbstractButton, whose properties - * will be modified according to the underlying Action - * object. As ActionButton inherits from Action, you can - * define your button's behavior right through this wrapper. - * - * \see Action - * - * \param button the TQAbstractButton to associate to this ActionButton - * \param actionId the action Id to create the underlying Action - * \param parent the parent object - */ - explicit ActionButton(TQAbstractButton *button, const TQString &actionId = TQString(), TQObject *parent = 0); - virtual ~ActionButton(); - - /** - * Sets the button associated to the underlying action. - * - * \note If you are calling this function, you're probably - * changing the button the action is referring to. If this - * is the case, please note that Polkit-TQt does not handle - * the previous button's memory, so you should take care of - * deleting it yourself (if needed). You can retrieve it by - * using button() - * - * \see button - * - * \param button the new button associated with the underlying action - */ - void setButton(TQAbstractButton *button); - - /** - * Returns the current button - * - * \return the button currently associated with the underlying action - */ - TQAbstractButton *button() const; - -public Q_SLOTS: - /** - * Connect clicked() signals to this slot. This should be - * manually done, as in some cases we might want - * to manually call this. Calling this will emit authorized(). - * - * \note This slot is reentrant which is likely to only be a problem - * if you are creating an interface to setup PolicyKit policies. - * \note If you have a checkbox, connect to its' clicked() signal - * to avoid an infinite loop as this function internally calls setChecked(). - * You can always use the clicked(bool) signal in this class to - * connect to here. - * \warning if you use this class take care to not call Action::activate - * otherwise your checkable buttons won't be properly updated. - */ - bool activate(); - -Q_SIGNALS: - /** - * Emitted when the abstract button clicked(bool) signal - * is emitted. This allows you to use qobject_cast(sender()) - * in a slot connected to this signal and call activate() on it. - * - * \note you will normally want to connect this signal - * to the activate slot. - * - * \param button the button that has been clicked - * \param checked the checked state, if applicable. Otherwise \c false - * - */ - void clicked(TQAbstractButton *button, bool checked = false); - -protected: - ActionButton(ActionButtonPrivate &dd, const TQString &actionId, TQObject *parent = 0); - - ActionButtonPrivate * const d_ptr; - -private: - Q_PRIVATE_SLOT(d_func(), void updateButton()) - Q_PRIVATE_SLOT(d_func(), void streamClicked(bool)) -}; - -} - -} - -#endif diff --git a/gui/polkittqt1-gui-actionbutton_p.h b/gui/polkittqt1-gui-actionbutton_p.h deleted file mode 100644 index afbe2e063..000000000 --- a/gui/polkittqt1-gui-actionbutton_p.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Dario Freddi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef POLKIT_TQT_GUI_ACTIONBUTTON_P_H -#define POLKIT_TQT_GUI_ACTIONBUTTON_P_H - -#include - -#include -#include - -/** - * \internal - */ -class PolkitTQt::Gui::ActionButtonPrivate -{ -public: - ActionButtonPrivate(const TQList &b) - : buttons(b) {} - virtual ~ActionButtonPrivate() {} - - void addButton(TQAbstractButton *button); - void removeButton(TQAbstractButton *button); - void updateButton(); - void streamClicked(bool); - - TQ_DECLARE_PUBLIC(ActionButton) - ActionButton *q_ptr; - - TQList buttons; -}; - -#endif /* ACTIONBUTTON_P_H */ diff --git a/gui/polkittqt1-gui-actionbuttons.cpp b/gui/polkittqt1-gui-actionbuttons.cpp deleted file mode 100644 index 28837ecc8..000000000 --- a/gui/polkittqt1-gui-actionbuttons.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Dario Freddi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "polkit-tqt-gui-actionbuttons.h" - -#include "polkit-tqt-gui-actionbuttons_p.h" - -namespace PolkitTQt -{ - -namespace Gui -{ - -ActionButtons::ActionButtons(const TQList &buttons, const TQString &actionId, TQObject *parent) - : ActionButton(*new ActionButtonsPrivate(buttons), actionId, parent) -{ - setButtons(buttons); -} - -ActionButtons::~ActionButtons() -{ -} - -void ActionButtons::setButtons(const TQList &buttons) -{ - TQ_FOREACH(TQAbstractButton *ent, buttons) { - addButton(ent); - } -} - -TQList ActionButtons::buttons() const -{ - TQ_D(const ActionButtons); - - return d->buttons; -} - -void ActionButtons::addButton(TQAbstractButton *button) -{ - TQ_D(ActionButtons); - - d->addButton(button); -} - -void ActionButtons::removeButton(TQAbstractButton *button) -{ - TQ_D(ActionButtons); - - d->removeButton(button); -} - -} - -} - -#include "polkit-tqt-gui-actionbuttons.moc" diff --git a/gui/polkittqt1-gui-actionbuttons.h b/gui/polkittqt1-gui-actionbuttons.h deleted file mode 100644 index 4324b0bf9..000000000 --- a/gui/polkittqt1-gui-actionbuttons.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Dario Freddi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef POLKIT_TQT_GUI_ACTIONBUTTONS_H -#define POLKIT_TQT_GUI_ACTIONBUTTONS_H - -#include "polkit-tqt-gui-actionbutton.h" - -namespace PolkitTQt -{ - -namespace Gui -{ - -class ActionButtonsPrivate; -/** - * \class ActionButtons polkit-tqt-gui-actionbuttons.h ActionButtons - * \author Dario Freddi - * - * \brief Class used to hold and update a list of TQAbstractButtons - * - * This class is a convenience wrapper around ActionButton that lets - * you associate an undefined number of TQAbstractButtons with a single - * action. Every button will be updated accordingly upon action's properties - * changes. - * - * \see ActionButton - */ -class ActionButtons : public ActionButton -{ - Q_OBJECT - TQ_DECLARE_PRIVATE(ActionButtons) - TQ_DISABLE_COPY(ActionButtons) - -public: - /** - * Constructs a new ActionButton. You need to pass this - * constructor an existing list of TQAbstractButtons, whose properties - * will be modified according to the underlying Action - * object. As ActionButtons inherits from Action, you can - * define your buttons' behavior right through this wrapper. - * - * \see Action - * - * \param buttons the TQAbstractButton to associate to this ActionButton - * \param actionId the action Id to create the underlying Action - * \param parent the parent object - */ - explicit ActionButtons(const TQList &buttons, const TQString &actionId = TQString(), TQObject *parent = 0); - virtual ~ActionButtons(); - - /** - * Sets a list of buttons associated to the underlying action. - * - * \note If you are calling this function, you're probably - * changing the buttons list the action is referring to. If this - * is the case, please note that Polkit-TQt does not handle - * the previous buttons' memory, so you should take care of - * deleting them yourself (if needed). You can retrieve it by - * using buttons() - * - * \see buttons - * - * \param buttons the new buttons associated with the underlying action - */ - void setButtons(const TQList &buttons); - - /** - * Returns the current buttons list - * - * \return the buttons currently associated with the underlying action - */ - TQList buttons() const; - - /** - * Adds a button to the current button list. The button's properties - * will be updated according to the action upon adding. - * - * \param button the button to add - */ - void addButton(TQAbstractButton *button); - - /** - * Removes a button from the current list. Please note that Polkit-TQt - * does not handle the removed button's memory, so you should take care of - * deleting it yourself (if needed). - * - * \param button the button to remove - */ - void removeButton(TQAbstractButton *button); -}; - -} - -} - -#endif diff --git a/gui/polkittqt1-gui-actionbuttons_p.h b/gui/polkittqt1-gui-actionbuttons_p.h deleted file mode 100644 index 1040177cb..000000000 --- a/gui/polkittqt1-gui-actionbuttons_p.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Dario Freddi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef POLKIT_TQT_GUI_ACTIONBUTTONS_P_H -#define POLKIT_TQT_GUI_ACTIONBUTTONS_P_H - -#include "polkit-tqt-gui-actionbutton_p.h" - -/** - * \internal - */ -class PolkitTQt::Gui::ActionButtonsPrivate : public ActionButtonPrivate -{ -public: - ActionButtonsPrivate(const TQList &b) - : ActionButtonPrivate(b) {} -}; - -#endif /* ACTIONBUTTONS_P_H */ -- cgit v1.2.1