diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-11-13 19:53:11 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-11-13 19:53:22 +0900 |
commit | 98b37ff3b1d307add5fe3f9e1f9c7923831debd4 (patch) | |
tree | f99bdc8ee40242e1baba1d09b2522e1344098c5d | |
parent | 8f1d08da58bce00523534cf39807732f7dee91ce (diff) | |
download | polkit-tqt-98b37ff3b1d307add5fe3f9e1f9c7923831debd4.tar.gz polkit-tqt-98b37ff3b1d307add5fe3f9e1f9c7923831debd4.zip |
Conversion of 'gui' library module.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r-- | CMakeLists.txt | 32 | ||||
-rw-r--r-- | Mainpage.dox | 4 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | debian/libpolkit-tqt-dev.install | 12 | ||||
-rw-r--r-- | examples/PkExample.cpp | 20 | ||||
-rw-r--r-- | gui/CMakeLists.txt | 41 | ||||
-rw-r--r-- | gui/dummy-gui.h | 56 | ||||
-rw-r--r-- | gui/polkit-tqt-gui-action.cpp | 661 | ||||
-rw-r--r-- | gui/polkit-tqt-gui-action.h (renamed from gui/polkittqt1-gui-action.h) | 98 | ||||
-rw-r--r-- | gui/polkit-tqt-gui-actionbutton.cpp | 173 | ||||
-rw-r--r-- | gui/polkit-tqt-gui-actionbutton.h (renamed from gui/polkittqt1-gui-actionbutton.h) | 52 | ||||
-rw-r--r-- | gui/polkit-tqt-gui-actionbutton_p.h (renamed from gui/dummy-gui.cpp) | 37 | ||||
-rw-r--r-- | gui/polkit-tqt-gui-actionbuttons.cpp (renamed from gui/polkittqt1-gui-actionbuttons.cpp) | 42 | ||||
-rw-r--r-- | gui/polkit-tqt-gui-actionbuttons.h (renamed from gui/polkittqt1-gui-actionbuttons.h) | 37 | ||||
-rw-r--r-- | gui/polkit-tqt-gui-actionbuttons_p.h (renamed from gui/polkittqt1-gui-actionbuttons_p.h) | 29 | ||||
-rw-r--r-- | gui/polkittqt1-gui-action.cpp | 517 | ||||
-rw-r--r-- | gui/polkittqt1-gui-actionbutton.cpp | 166 | ||||
-rw-r--r-- | gui/polkittqt1-gui-actionbutton_p.h | 50 |
18 files changed, 1059 insertions, 970 deletions
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<TQAbstractButton*>() << listenPB << listenCB, +bt = new ActionButtons(TQList<TQButton*>() << 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 @@ -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<Action *>(bt)); toolBar->addAction(qobject_cast<Action *>(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<Action *>(bt)); toolBar->addAction(qobject_cast<Action *>(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<Action *>(bt)); toolBar->addAction(qobject_cast<Action *>(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<Action *>(bt)); toolBar->addAction(qobject_cast<Action *>(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<Action *>(bt)); toolBar->addAction(qobject_cast<Action *>(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<Action *>(bt)); toolBar->addAction(qobject_cast<Action *>(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<Action *>(bt)); toolBar->addAction(qobject_cast<Action *>(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.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 <dantti85-pk@yahoo.com.br> - * Copyright (C) 2009 Dario Freddi <drf@kde.org> - * Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com> - * Copyright (C) 2009 Radek Novacek <rnovacek@redhat.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef DUMMY_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 <dantti85-pk@yahoo.com.br> + * Copyright (C) 2009 Dario Freddi <drf@kde.org> + * Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "polkit-tqt-gui-action.h" +#include "polkit-tqt-authority.h" +#include "polkit-tqt-subject.h" + +#include <tqapplication.h> + + +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<TQAction*>(parent)->setVisible(noVisible); + ::tqt_cast<TQAction*>(parent)->setEnabled(noEnabled); + ::tqt_cast<TQAction*>(parent)->setText(noText); + if (!noWhatsThis.isNull()) + { + ::tqt_cast<TQAction*>(parent)->setWhatsThis(noWhatsThis); + } + if (!noToolTip.isNull()) + { + ::tqt_cast<TQAction*>(parent)->setToolTip(noToolTip); + } + ::tqt_cast<TQAction*>(parent)->setIconSet(noIconSet); + break; + } + + case Authority::Challenge: + { + ::tqt_cast<TQAction*>(parent)->setVisible(authVisible); + ::tqt_cast<TQAction*>(parent)->setEnabled(authEnabled); + ::tqt_cast<TQAction*>(parent)->setText(authText); + if (!authWhatsThis.isNull()) + { + ::tqt_cast<TQAction*>(parent)->setWhatsThis(authWhatsThis); + } + if (!authToolTip.isNull()) + { + ::tqt_cast<TQAction*>(parent)->setToolTip(authToolTip); + } + ::tqt_cast<TQAction*>(parent)->setIconSet(authIconSet); + break; + } + + case Authority::Yes: + { + ::tqt_cast<TQAction*>(parent)->setVisible(yesVisible); + ::tqt_cast<TQAction*>(parent)->setEnabled(yesEnabled); + ::tqt_cast<TQAction*>(parent)->setText(yesText); + if (!yesWhatsThis.isNull()) + { + ::tqt_cast<TQAction*>(parent)->setWhatsThis(yesWhatsThis); + } + if (!yesToolTip.isNull()) + { + ::tqt_cast<TQAction*>(parent)->setToolTip(yesToolTip); + } + ::tqt_cast<TQAction*>(parent)->setIconSet(yesIconSet); + if (parent->isOn()) + { + ::tqt_cast<TQAction*>(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/polkittqt1-gui-action.h b/gui/polkit-tqt-gui-action.h index 802a790f8..3149fff92 100644 --- a/gui/polkittqt1-gui-action.h +++ b/gui/polkit-tqt-gui-action.h @@ -24,7 +24,7 @@ #include "polkit-tqt-export.h" -#include <TQtGui/TQAction> +#include <tqaction.h> namespace PolkitTQt @@ -45,32 +45,31 @@ namespace Gui * 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 + * 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 POLKITTQT1_EXPORT Action : public TQAction +class POLKIT_TQT_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 + 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 }; - TQ_DECLARE_FLAGS(States, State) /** * Constructs a new Action item @@ -78,10 +77,11 @@ public: * \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); + explicit Action(const TQString& actionId = TQString::null, TQObject *parent = 0); + ~Action(); -Q_SIGNALS: + signals: /** * Emitted when the PolicyKit result (PolKitResult) * for the given action or the internal data changes @@ -92,20 +92,18 @@ Q_SIGNALS: 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 + * 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: +public slots: /** - * Use this slot if you want to activate - * the action. authorized() will be emitted - * if the action gets authorized. + * 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 * @@ -173,15 +171,15 @@ public: void setWhatsThis(const TQString &whatsThis, States states = All); /** - * Sets the icon for the current action. This will + * 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 TQIcon here. You can easily - * create one from a Pixmap, or pass a KIcon - * \param icon the new icon for the action + * \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 setIcon(const TQIcon &icon, States states = All); + void setIconSet(const TQIconSet &iconset, States states = All); /** * Sets whether the current action is visible or not. This will @@ -217,7 +215,7 @@ public: * \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; + TQString text(States state = None) const; /** * Gets the tooltip of the action when it is in the specified state @@ -226,7 +224,7 @@ public: * \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; + TQString toolTip(States state = None) const; /** * Gets the whatsThis of the action when it is in the specified state @@ -234,16 +232,16 @@ public: * \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; + TQString whatsThis(States state = None) const; /** - * Gets the icon of the action when it is in the specified state + * 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 icon shown when the action is in the specified state + * \returns The iconset shown when the action is in the specified state */ - TQIcon icon(State state = None) const; + TQIconSet iconSet(States state = None) const; /** * Gets whether the action is visible or not when it is in the specified state @@ -252,7 +250,7 @@ public: * \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; + bool isVisible(States state = None) const; /** * Gets whether the action is enabled or not when it is in the specified state @@ -261,7 +259,7 @@ public: * \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; + bool isEnabled(States state = None) const; /** * \see setTargetPID @@ -289,17 +287,21 @@ public: */ bool is(const TQString &actionId) const; -private: + private: + // Disable copy + Action(const Action&); + Action& operator=(const Action&); + class Private; - Private * const d; + Private *const d; - Q_PRIVATE_SLOT(d, void configChanged()) + private slots: + void slotConfigChanged(); }; } } -TQ_DECLARE_OPERATORS_FOR_FLAGS(PolkitTQt1::Gui::Action::States) - #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 <dantti85-pk@yahoo.com.br> + * Copyright (C) 2009 Dario Freddi <drf@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "polkit-tqt-gui-actionbutton.h" +#include "polkit-tqt-gui-actionbutton_p.h" + +#include <tqbutton.h> +#include <tqstring.h> +#include <tqvaluelist.h> + + +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<TQButton*>::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<TQButton*>(this->sender()), c); +} + +void ActionButton::updateButton() +{ + TQValueList<TQButton*>::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<TQButton*>::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/polkittqt1-gui-actionbutton.h b/gui/polkit-tqt-gui-actionbutton.h index fba18d3ae..44faff4ac 100644 --- a/gui/polkittqt1-gui-actionbutton.h +++ b/gui/polkit-tqt-gui-actionbutton.h @@ -25,7 +25,9 @@ #include "polkit-tqt-export.h" #include "polkit-tqt-gui-action.h" -class TQAbstractButton; +class TQButton; +class TQString; + namespace PolkitTQt { @@ -34,14 +36,15 @@ namespace Gui { class ActionButtonPrivate; + /** * \class ActionButton polkit-tqt-gui-actionbutton.h ActionButton * \author Daniel Nicoletti <dantti85-pk@yahoo.com.br> * \author Dario Freddi <drf@kde.org> * - * \brief Class used to hold and update a TQAbstractButton + * \brief Class used to hold and update a TQButton * - * This class allows you to associate TQAbstractButtons + * 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. * @@ -52,25 +55,24 @@ class ActionButtonPrivate; */ class POLKIT_TQT_EXPORT ActionButton : public Action { - Q_OBJECT - TQ_DECLARE_PRIVATE(ActionButton) - TQ_DISABLE_COPY(ActionButton) + Q_OBJECT -public: + public: /** * Constructs a new ActionButton. You need to pass this - * constructor an existing TQAbstractButton, whose properties + * 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 TQAbstractButton to associate to this ActionButton + * \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(TQAbstractButton *button, const TQString &actionId = TQString(), TQObject *parent = 0); + explicit ActionButton(TQButton *button, const TQString &actionId = TQString::null, + TQObject *parent = 0); virtual ~ActionButton(); /** @@ -87,16 +89,16 @@ public: * * \param button the new button associated with the underlying action */ - void setButton(TQAbstractButton *button); + void setButton(TQButton *button); /** * Returns the current button * * \return the button currently associated with the underlying action */ - TQAbstractButton *button() const; + TQButton* button() const; -public Q_SLOTS: + public slots: /** * Connect clicked() signals to this slot. This should be * manually done, as in some cases we might want @@ -113,10 +115,10 @@ public Q_SLOTS: */ bool activate(); -Q_SIGNALS: + signals: /** * Emitted when the abstract button clicked(bool) signal - * is emitted. This allows you to use qobject_cast<ActionButton *>(sender()) + * is emitted. This allows you to use qobject_cast<ActionButton*>(sender()) * in a slot connected to this signal and call activate() on it. * * \note you will normally want to connect this signal @@ -126,16 +128,23 @@ Q_SIGNALS: * \param checked the checked state, if applicable. Otherwise \c false * */ - void clicked(TQAbstractButton *button, bool checked = false); + void clicked(TQButton *button, bool checked = false); -protected: + protected: ActionButton(ActionButtonPrivate &dd, const TQString &actionId, TQObject *parent = 0); - ActionButtonPrivate * const d_ptr; + ActionButtonPrivate *const d; + + private: + // Disable copy + ActionButton(const ActionButton&); + ActionButton& operator=(const ActionButton&); -private: - Q_PRIVATE_SLOT(d_func(), void updateButton()) - Q_PRIVATE_SLOT(d_func(), void streamClicked(bool)) + friend class ActionButtonPrivate; + + private slots: + void updateButton(); + void streamClicked(bool); }; } @@ -143,3 +152,4 @@ private: } #endif + diff --git a/gui/dummy-gui.cpp b/gui/polkit-tqt-gui-actionbutton_p.h index d40e5e631..e53eeae0a 100644 --- a/gui/dummy-gui.cpp +++ b/gui/polkit-tqt-gui-actionbutton_p.h @@ -1,9 +1,6 @@ /* * This file is part of the Polkit-tqt project - * Copyright (C) 2009 Daniel Nicoletti <dantti85-pk@yahoo.com.br> * Copyright (C) 2009 Dario Freddi <drf@kde.org> - * Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com> - * Copyright (C) 2009 Radek Novacek <rnovacek@redhat.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,17 +18,43 @@ * Boston, MA 02110-1301, USA. */ -#include "dummy-gui.h" +#ifndef POLKIT_TQT_GUI_ACTIONBUTTON_P_H +#define POLKIT_TQT_GUI_ACTIONBUTTON_P_H + +#include <polkit-tqt-gui-actionbutton.h> + +class TQButton; +template <typename> class TQValueList; + namespace PolkitTQt { +namespace Gui +{ -DummyGui* DummyGui::instance() +class ActionButtonPrivate { - return 0; + public: + ActionButtonPrivate() + { + } + + virtual ~ActionButtonPrivate() + { + } + + void addButton(TQButton *button); + void removeButton(TQButton *button); + + ActionButton *q; + + TQValueList<TQButton*> buttons; +}; + } } -#include "dummy-gui.moc" +#endif + diff --git a/gui/polkittqt1-gui-actionbuttons.cpp b/gui/polkit-tqt-gui-actionbuttons.cpp index 28837ecc8..78aced5d6 100644 --- a/gui/polkittqt1-gui-actionbuttons.cpp +++ b/gui/polkit-tqt-gui-actionbuttons.cpp @@ -19,51 +19,52 @@ */ #include "polkit-tqt-gui-actionbuttons.h" - #include "polkit-tqt-gui-actionbuttons_p.h" +#include <tqbutton.h> +#include <tqstring.h> +#include <tqvaluelist.h> + + namespace PolkitTQt { namespace Gui { -ActionButtons::ActionButtons(const TQList<TQAbstractButton *> &buttons, const TQString &actionId, TQObject *parent) - : ActionButton(*new ActionButtonsPrivate(buttons), actionId, parent) +ActionButtons::ActionButtons(const TQValueList<TQButton*> &buttons, const TQString &actionId, + TQObject *parent) : ActionButton(*new ActionButtonPrivate(), actionId, parent) { - setButtons(buttons); + setButtons(buttons); } ActionButtons::~ActionButtons() { } -void ActionButtons::setButtons(const TQList<TQAbstractButton *> &buttons) +void ActionButtons::setButtons(const TQValueList<TQButton*> &buttons) { - TQ_FOREACH(TQAbstractButton *ent, buttons) { - addButton(ent); - } + TQValueList<TQButton*>::iterator butIt; + for (butIt = d->buttons.begin(); butIt != d->buttons.end(); ++butIt) + { + TQButton *ent = *butIt; + addButton(ent); + } } -TQList<TQAbstractButton *> ActionButtons::buttons() const +TQValueList<TQButton *> ActionButtons::buttons() const { - TQ_D(const ActionButtons); - - return d->buttons; + return d->buttons; } -void ActionButtons::addButton(TQAbstractButton *button) +void ActionButtons::addButton(TQButton *button) { - TQ_D(ActionButtons); - - d->addButton(button); + d->addButton(button); } -void ActionButtons::removeButton(TQAbstractButton *button) +void ActionButtons::removeButton(TQButton *button) { - TQ_D(ActionButtons); - - d->removeButton(button); + d->removeButton(button); } } @@ -71,3 +72,4 @@ void ActionButtons::removeButton(TQAbstractButton *button) } #include "polkit-tqt-gui-actionbuttons.moc" + diff --git a/gui/polkittqt1-gui-actionbuttons.h b/gui/polkit-tqt-gui-actionbuttons.h index 4324b0bf9..b85b632be 100644 --- a/gui/polkittqt1-gui-actionbuttons.h +++ b/gui/polkit-tqt-gui-actionbuttons.h @@ -23,6 +23,7 @@ #include "polkit-tqt-gui-actionbutton.h" + namespace PolkitTQt { @@ -30,40 +31,39 @@ namespace Gui { class ActionButtonsPrivate; + /** * \class ActionButtons polkit-tqt-gui-actionbuttons.h ActionButtons * \author Dario Freddi <drf@kde.org> * - * \brief Class used to hold and update a list of TQAbstractButtons + * \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 TQAbstractButtons with a single - * action. Every button will be updated accordingly upon action's properties - * changes. + * 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 - TQ_DECLARE_PRIVATE(ActionButtons) - TQ_DISABLE_COPY(ActionButtons) + Q_OBJECT -public: + public: /** - * Constructs a new ActionButton. You need to pass this - * constructor an existing list of TQAbstractButtons, whose properties + * 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 TQAbstractButton to associate to this ActionButton + * \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 TQList<TQAbstractButton *> &buttons, const TQString &actionId = TQString(), TQObject *parent = 0); + explicit ActionButtons(const TQValueList<TQButton*> &buttons, + const TQString &actionId = TQString::null, TQObject *parent = 0); virtual ~ActionButtons(); /** @@ -80,14 +80,14 @@ public: * * \param buttons the new buttons associated with the underlying action */ - void setButtons(const TQList<TQAbstractButton *> &buttons); + void setButtons(const TQValueList<TQButton*> &buttons); /** * Returns the current buttons list * * \return the buttons currently associated with the underlying action */ - TQList<TQAbstractButton *> buttons() const; + TQValueList<TQButton*> buttons() const; /** * Adds a button to the current button list. The button's properties @@ -95,7 +95,7 @@ public: * * \param button the button to add */ - void addButton(TQAbstractButton *button); + void addButton(TQButton *button); /** * Removes a button from the current list. Please note that Polkit-TQt @@ -104,7 +104,12 @@ public: * * \param button the button to remove */ - void removeButton(TQAbstractButton *button); + void removeButton(TQButton *button); + + private: + // Disable copy + ActionButtons(const ActionButtons&); + ActionButtons& operator=(const ActionButtons&); }; } diff --git a/gui/polkittqt1-gui-actionbuttons_p.h b/gui/polkit-tqt-gui-actionbuttons_p.h index 1040177cb..74e918eb2 100644 --- a/gui/polkittqt1-gui-actionbuttons_p.h +++ b/gui/polkit-tqt-gui-actionbuttons_p.h @@ -23,14 +23,27 @@ #include "polkit-tqt-gui-actionbutton_p.h" -/** - * \internal - */ -class PolkitTQt::Gui::ActionButtonsPrivate : public ActionButtonPrivate +class TQButton; +template <typename> class TQValueList; + + +namespace PolkitTQt { -public: - ActionButtonsPrivate(const TQList<TQAbstractButton *> &b) - : ActionButtonPrivate(b) {} + +namespace Gui +{ + +class ActionButtonsPrivate : public ActionButtonPrivate +{ + public: + ActionButtonsPrivate() : ActionButtonPrivate() + { + } }; -#endif /* ACTIONBUTTONS_P_H */ +} + +} + +#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 <dantti85-pk@yahoo.com.br> - * Copyright (C) 2009 Dario Freddi <drf@kde.org> - * Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "polkit-tqt-gui-action.h" -#include "polkit-tqt-authority.h" -#include "polkit-tqt-subject.h" - -#include <TQtCore/TQCoreApplication> - - -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<TQAction *>(parent)->setVisible(noVisible); - qobject_cast<TQAction *>(parent)->setEnabled(noEnabled); - qobject_cast<TQAction *>(parent)->setText(noText); - if (!noWhatsThis.isNull()) { - qobject_cast<TQAction *>(parent)->setWhatsThis(noWhatsThis); - } - if (!noToolTip.isNull()) { - qobject_cast<TQAction *>(parent)->setToolTip(noToolTip); - } - qobject_cast<TQAction *>(parent)->setIcon(noIcon); - break; - - case Authority::Challenge: - qobject_cast<TQAction *>(parent)->setVisible(authVisible); - qobject_cast<TQAction *>(parent)->setEnabled(authEnabled); - qobject_cast<TQAction *>(parent)->setText(authText); - if (!authWhatsThis.isNull()) { - qobject_cast<TQAction *>(parent)->setWhatsThis(authWhatsThis); - } - if (!authToolTip.isNull()) { - qobject_cast<TQAction *>(parent)->setToolTip(authToolTip); - } - qobject_cast<TQAction *>(parent)->setIcon(authIcon); - break; - case Authority::Yes: - qobject_cast<TQAction *>(parent)->setVisible(yesVisible); - qobject_cast<TQAction *>(parent)->setEnabled(yesEnabled); - qobject_cast<TQAction *>(parent)->setText(yesText); - if (!yesWhatsThis.isNull()) { - qobject_cast<TQAction *>(parent)->setWhatsThis(yesWhatsThis); - } - if (!yesToolTip.isNull()) { - qobject_cast<TQAction *>(parent)->setToolTip(yesToolTip); - } - qobject_cast<TQAction *>(parent)->setIcon(yesIcon); - if (parent->isCheckable()) { - qobject_cast<TQAction *>(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-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 <dantti85-pk@yahoo.com.br> - * Copyright (C) 2009 Dario Freddi <drf@kde.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "polkit-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<TQAbstractButton *>() << 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<TQAbstractButton *>(q->sender()), c); -} - -} - -} - -#include "polkit-tqt-gui-actionbutton.moc" 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 <drf@kde.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef POLKIT_TQT_GUI_ACTIONBUTTON_P_H -#define POLKIT_TQT_GUI_ACTIONBUTTON_P_H - -#include <polkit-tqt-gui-actionbutton.h> - -#include <TQtCore/TQList> -#include <TQtGui/TQAbstractButton> - -/** - * \internal - */ -class PolkitTQt::Gui::ActionButtonPrivate -{ -public: - ActionButtonPrivate(const TQList<TQAbstractButton *> &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<TQAbstractButton *> buttons; -}; - -#endif /* ACTIONBUTTON_P_H */ |