Conversion of 'gui' library module.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>pull/1/head
parent
8f1d08da58
commit
98b37ff3b1
@ -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
|
|
@ -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"
|
||||||
|
|
@ -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"
|
||||||
|
|
@ -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"
|
|
||||||
|
|
@ -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"
|
|
@ -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 */
|
|
Loading…
Reference in New Issue