* signal when operations change

* allow associating widgets with specific operations

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=841832
This commit is contained in:
Aaron J. Seigo 2008-08-04 08:00:47 +00:00
parent 684a1b4e4e
commit 0d175ab165
3 changed files with 80 additions and 2 deletions

View File

@ -22,6 +22,10 @@
#include "servicejob.h" #include "servicejob.h"
#include <QGraphicsWidget>
#include <QMultiHash>
#include <QWidget>
#include <KTemporaryFile> #include <KTemporaryFile>
namespace Plasma namespace Plasma
@ -78,11 +82,23 @@ public:
QString name; QString name;
ConfigXml *config; ConfigXml *config;
KTemporaryFile *tempFile; KTemporaryFile *tempFile;
QMultiHash<QWidget *, QString> associatedWidgets;
QMultiHash<QGraphicsWidget *, QString> associatedGraphicsWidgets;
void jobFinished(KJob* job) void jobFinished(KJob* job)
{ {
emit q->finished(static_cast<ServiceJob*>(job)); emit q->finished(static_cast<ServiceJob*>(job));
} }
void associatedWidgetDestroyed(QObject *obj)
{
associatedWidgets.remove(static_cast<QWidget*>(obj));
}
void associatedGraphicsWidgetDestroyed(QObject *obj)
{
associatedGraphicsWidgets.remove(static_cast<QGraphicsWidget*>(obj));
}
}; };
} // namespace Plasma } // namespace Plasma

View File

@ -153,6 +153,18 @@ ServiceJob* Service::startOperationCall(const KConfigGroup &description)
return job; return job;
} }
void Service::associateWidget(QWidget *widget, const QString &operation)
{
d->associatedWidgets.insert(widget, operation);
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedWidgetDestroyed(QObject*)));
}
void Service::associateWidget(QGraphicsWidget *widget, const QString &operation)
{
d->associatedGraphicsWidgets.insert(widget, operation);
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedGraphicsWidgetDestroyed(QObject*)));
}
QString Service::name() const QString Service::name() const
{ {
return d->name; return d->name;
@ -180,7 +192,25 @@ void Service::setOperationsScheme(QIODevice *xml)
//FIXME: make KSharedConfig and KConfigSkeleton not braindamaged in 4.2 and then get rid of the //FIXME: make KSharedConfig and KConfigSkeleton not braindamaged in 4.2 and then get rid of the
// temp file object here // temp file object here
d->tempFile = new KTemporaryFile; d->tempFile = new KTemporaryFile;
d->config = new ConfigXml(KSharedConfig::openConfig(d->tempFile->fileName()), xml, this); KSharedConfigPtr c = KSharedConfig::openConfig(d->tempFile->fileName());
d->config = new ConfigXml(c, xml, this);
emit operationsChanged();
{
QHashIterator<QWidget *, QString> it(d->associatedWidgets);
while (it.hasNext()) {
it.next();
it.key()->setEnabled(d->config->hasGroup(it.value()));
}
}
{
QHashIterator<QGraphicsWidget *, QString> it(d->associatedGraphicsWidgets);
while (it.hasNext()) {
it.next();
it.key()->setEnabled(d->config->hasGroup(it.value()));
}
}
} }
void Service::registerOperationsScheme() void Service::registerOperationsScheme()

View File

@ -27,7 +27,9 @@
#include <KDE/KConfigGroup> #include <KDE/KConfigGroup>
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
class QGraphicsWidget;
class QIODevice; class QIODevice;
class QWidget;
namespace Plasma namespace Plasma
{ {
@ -126,9 +128,37 @@ public:
*/ */
QString name() const; QString name() const;
/**
* Assoicates a widget with an operation, which allows the service to
* automatically manage, for example, the enabled state of a widget.
*
* @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);
/**
* Assoicates a widget with an operation, which allows the service to
* automatically manage, for example, the enabled state of a widget.
*
* @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);
Q_SIGNALS: Q_SIGNALS:
/**
* Emitted when a job associated with this Service completes its task
*/
void finished(ServiceJob* job); void finished(ServiceJob* job);
/**
* Emitted when the Service's operations change. For example, a
* media player service may change what operations are available
* in response to the state of the player.
*/
void operationsChanged();
protected: protected:
/** /**
* Default constructor * Default constructor
@ -175,7 +205,9 @@ protected:
void setName(const QString &name); void setName(const QString &name);
private: private:
Q_PRIVATE_SLOT(d, void jobFinished(KJob*)) Q_PRIVATE_SLOT(d, void jobFinished(KJob *))
Q_PRIVATE_SLOT(d, void associatedWidgetDestroyed(QObject *))
Q_PRIVATE_SLOT(d, void associatedGraphicsWidgetDestroyed(QObject *))
ServicePrivate * const d; ServicePrivate * const d;