* rename operationIsEnabled to isOperationEnabled

* add disassociateWidget() methods
* don't allow a widget to associated with more than one operation
* set the enabled status properly when we associate a widget


svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=852983
This commit is contained in:
Alex Merry 2008-08-26 23:04:53 +00:00
parent 8355e9e027
commit 9ce3660816
2 changed files with 44 additions and 8 deletions

View File

@ -160,22 +160,32 @@ ServiceJob* Service::startOperationCall(const KConfigGroup &description)
void Service::associateWidget(QWidget *widget, const QString &operation) void Service::associateWidget(QWidget *widget, const QString &operation)
{ {
disassociateWidget(widget);
d->associatedWidgets.insert(widget, operation); d->associatedWidgets.insert(widget, operation);
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedWidgetDestroyed(QObject*))); connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedWidgetDestroyed(QObject*)));
if (d->disabledOperations.contains(operation)) { widget->setEnabled(!d->disabledOperations.contains(operation));
widget->setEnabled(false); }
}
void Service::disassociateWidget(QWidget *widget)
{
disconnect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedWidgetDestroyed(QObject*)));
d->associatedWidgets.remove(widget);
} }
void Service::associateWidget(QGraphicsWidget *widget, const QString &operation) void Service::associateWidget(QGraphicsWidget *widget, const QString &operation)
{ {
disassociateWidget(widget);
d->associatedGraphicsWidgets.insert(widget, operation); d->associatedGraphicsWidgets.insert(widget, operation);
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedGraphicsWidgetDestroyed(QObject*))); connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedGraphicsWidgetDestroyed(QObject*)));
if (d->disabledOperations.contains(operation)) { widget->setEnabled(!d->disabledOperations.contains(operation));
widget->setEnabled(false); }
}
void Service::disassociateWidget(QGraphicsWidget *widget)
{
disconnect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedGraphicsWidgetDestroyed(QObject*)));
d->associatedGraphicsWidgets.remove(widget);
} }
QString Service::name() const QString Service::name() const
@ -230,7 +240,7 @@ void Service::setOperationEnabled(const QString &operation, bool enable)
} }
} }
bool Service::operationIsEnabled(const QString &operation) const bool Service::isOperationEnabled(const QString &operation) const
{ {
return d->config->hasGroup(operation) && !d->disabledOperations.contains(operation); return d->config->hasGroup(operation) && !d->disabledOperations.contains(operation);
} }

View File

@ -131,7 +131,7 @@ public:
* @param operation the name of the operation to check * @param operation the name of the operation to check
* @return true if the operation is enabled, false otherwise * @return true if the operation is enabled, false otherwise
*/ */
bool operationIsEnabled(const QString &operation) const; bool isOperationEnabled(const QString &operation) const;
/** /**
* The name of this service * The name of this service
@ -142,20 +142,46 @@ public:
* Assoicates a widget with an operation, which allows the service to * Assoicates a widget with an operation, which allows the service to
* automatically manage, for example, the enabled state of a widget. * automatically manage, for example, the enabled state of a widget.
* *
* This will remove any previous associations the widget had with
* operations on this engine.
*
* @param widget the QWidget to associate with the service * @param widget the QWidget to associate with the service
* @param operation the operation to associate the widget with * @param operation the operation to associate the widget with
*/ */
void associateWidget(QWidget *widget, const QString &operation); void associateWidget(QWidget *widget, const QString &operation);
/**
* Disassociates a widget if it has been associated with an operation
* on this service.
*
* This will not change the enabled state of the widget.
*
* @param widget the QWidget to disassociate.
*/
void disassociateWidget(QWidget *widget);
/** /**
* Assoicates a widget with an operation, which allows the service to * Assoicates a widget with an operation, which allows the service to
* automatically manage, for example, the enabled state of a widget. * automatically manage, for example, the enabled state of a widget.
* *
* This will remove any previous associations the widget had with
* operations on this engine.
*
* @param widget the QGraphicsItem to associate with the service * @param widget the QGraphicsItem to associate with the service
* @param operation the operation to associate the widget with * @param operation the operation to associate the widget with
*/ */
void associateWidget(QGraphicsWidget *widget, const QString &operation); void associateWidget(QGraphicsWidget *widget, const QString &operation);
/**
* Disassociates a widget if it has been associated with an operation
* on this service.
*
* This will not change the enabled state of the widget.
*
* @param widget the QGraphicsWidget to disassociate.
*/
void disassociateWidget(QGraphicsWidget *widget);
Q_SIGNALS: Q_SIGNALS:
/** /**
* Emitted when a job associated with this Service completes its task * Emitted when a job associated with this Service completes its task