diff --git a/service.cpp b/service.cpp index 3f9f33ce4..abc458d43 100644 --- a/service.cpp +++ b/service.cpp @@ -160,22 +160,32 @@ ServiceJob* Service::startOperationCall(const KConfigGroup &description) void Service::associateWidget(QWidget *widget, const QString &operation) { + disassociateWidget(widget); d->associatedWidgets.insert(widget, operation); connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedWidgetDestroyed(QObject*))); - if (d->disabledOperations.contains(operation)) { - widget->setEnabled(false); - } + widget->setEnabled(!d->disabledOperations.contains(operation)); +} + +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) { + disassociateWidget(widget); d->associatedGraphicsWidgets.insert(widget, operation); connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedGraphicsWidgetDestroyed(QObject*))); - if (d->disabledOperations.contains(operation)) { - widget->setEnabled(false); - } + widget->setEnabled(!d->disabledOperations.contains(operation)); +} + +void Service::disassociateWidget(QGraphicsWidget *widget) +{ + disconnect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedGraphicsWidgetDestroyed(QObject*))); + d->associatedGraphicsWidgets.remove(widget); } 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); } diff --git a/service.h b/service.h index de20b8477..945bd64b0 100644 --- a/service.h +++ b/service.h @@ -131,7 +131,7 @@ public: * @param operation the name of the operation to check * @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 @@ -142,20 +142,46 @@ public: * Assoicates a widget with an operation, which allows the service to * 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 operation the operation to associate the widget with */ 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 * 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 operation the operation to associate the widget with */ 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: /** * Emitted when a job associated with this Service completes its task