support enabling and disabling operations in services
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=845852
This commit is contained in:
parent
0e22094ff0
commit
3461b97edc
@ -25,6 +25,7 @@
|
||||
#include <QGraphicsWidget>
|
||||
#include <QMultiHash>
|
||||
#include <QWidget>
|
||||
#include <QSet>
|
||||
|
||||
#include <KTemporaryFile>
|
||||
|
||||
@ -77,14 +78,6 @@ public:
|
||||
delete tempFile;
|
||||
}
|
||||
|
||||
Service *q;
|
||||
QString destination;
|
||||
QString name;
|
||||
ConfigXml *config;
|
||||
KTemporaryFile *tempFile;
|
||||
QMultiHash<QWidget *, QString> associatedWidgets;
|
||||
QMultiHash<QGraphicsWidget *, QString> associatedGraphicsWidgets;
|
||||
|
||||
void jobFinished(KJob* job)
|
||||
{
|
||||
emit q->finished(static_cast<ServiceJob*>(job));
|
||||
@ -99,6 +92,15 @@ public:
|
||||
{
|
||||
associatedGraphicsWidgets.remove(static_cast<QGraphicsWidget*>(obj));
|
||||
}
|
||||
|
||||
Service *q;
|
||||
QString destination;
|
||||
QString name;
|
||||
ConfigXml *config;
|
||||
KTemporaryFile *tempFile;
|
||||
QMultiHash<QWidget *, QString> associatedWidgets;
|
||||
QMultiHash<QGraphicsWidget *, QString> associatedGraphicsWidgets;
|
||||
QSet<QString> disabledOperations;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
53
service.cpp
53
service.cpp
@ -137,9 +137,14 @@ ServiceJob* Service::startOperationCall(const KConfigGroup &description)
|
||||
return new NullServiceJob(parent());
|
||||
}
|
||||
|
||||
QString op = description.name();
|
||||
if (d->disabledOperations.contains(op)) {
|
||||
kDebug() << "Operation" << op << "is disabled";
|
||||
return new NullServiceJob(parent());
|
||||
}
|
||||
|
||||
d->config->writeConfig();
|
||||
QMap<QString, QVariant> params;
|
||||
QString op = description.name();
|
||||
foreach (const QString &key, description.keyList()) {
|
||||
KConfigSkeletonItem *item = d->config->findItem(op, key);
|
||||
if (item) {
|
||||
@ -157,12 +162,20 @@ void Service::associateWidget(QWidget *widget, const QString &operation)
|
||||
{
|
||||
d->associatedWidgets.insert(widget, operation);
|
||||
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedWidgetDestroyed(QObject*)));
|
||||
|
||||
if (d->disabledOperations.contains(operation)) {
|
||||
widget->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Service::associateWidget(QGraphicsWidget *widget, const QString &operation)
|
||||
{
|
||||
d->associatedGraphicsWidgets.insert(widget, operation);
|
||||
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedGraphicsWidgetDestroyed(QObject*)));
|
||||
|
||||
if (d->disabledOperations.contains(operation)) {
|
||||
widget->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
QString Service::name() const
|
||||
@ -184,6 +197,44 @@ void Service::setName(const QString &name)
|
||||
registerOperationsScheme();
|
||||
}
|
||||
|
||||
void Service::setOperationEnabled(const QString &operation, bool enable)
|
||||
{
|
||||
if (!d->config->hasGroup(operation)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
d->disabledOperations.remove(operation);
|
||||
} else if (!d->disabledOperations.contains(operation)) {
|
||||
d->disabledOperations.insert(operation);
|
||||
}
|
||||
|
||||
{
|
||||
QHashIterator<QWidget *, QString> it(d->associatedWidgets);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.value() == operation) {
|
||||
it.key()->setEnabled(enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
QHashIterator<QGraphicsWidget *, QString> it(d->associatedGraphicsWidgets);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.value() == operation) {
|
||||
it.key()->setEnabled(enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Service::operationIsEnabled(const QString &operation) const
|
||||
{
|
||||
d->config->hasGroup(operation) && !d->disabledOperations.contains(operation);
|
||||
}
|
||||
|
||||
void Service::setOperationsScheme(QIODevice *xml)
|
||||
{
|
||||
delete d->config;
|
||||
|
16
service.h
16
service.h
@ -204,6 +204,22 @@ protected:
|
||||
*/
|
||||
void setName(const QString &name);
|
||||
|
||||
/**
|
||||
* Enables a given service by name
|
||||
*
|
||||
* @param operation the name of the operation to enable or disable
|
||||
* @param enable true if the operation should be enabld, false if disabled
|
||||
*/
|
||||
void setOperationEnabled(const QString &operation, bool enable);
|
||||
|
||||
/**
|
||||
* Query to find if an operation is enabled or not.
|
||||
*
|
||||
* @param operation the name of the operation to check
|
||||
* @return true if the operation is enabled, false otherwise
|
||||
*/
|
||||
bool operationIsEnabled(const QString &operation) const;
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void jobFinished(KJob *))
|
||||
Q_PRIVATE_SLOT(d, void associatedWidgetDestroyed(QObject *))
|
||||
|
Loading…
Reference in New Issue
Block a user