summaryrefslogtreecommitdiff
path: root/fakepropertyadaptor.cpp
blob: 369c1c152fe20ba431ffc66264886c21e743c323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <QtCore/QRegExp>
#include <QtCore/QDebug>
#include <QtDBus/QDBusMessage>

#include "fakepropertyadaptor.h"

FakePropertyAdaptor::FakePropertyAdaptor(FakeProperty* property) :
	QDBusAbstractAdaptor(property), _property(property)
{
	connect(_property, SIGNAL(valueChanged()), SLOT(propertyChanged()));
}

QString FakePropertyAdaptor::objectPath() const
{
	if (_property->key().startsWith("/"))
		return QString(_property->key());

	return QString("/org/maemo/contextkit/") +
			QString(_property->key()).replace(".", "/").replace(QRegExp("[^A-Za-z0-9_/]"), "_");
}

void FakePropertyAdaptor::Subscribe(const QDBusMessage& msg, QVariantList& values, quint64& timestamp)
{
	Q_UNUSED(msg);
	Get(values, timestamp);
}

void FakePropertyAdaptor::Unsubscribe(const QDBusMessage& msg)
{
	Q_UNUSED(msg);
}

void FakePropertyAdaptor::Get(QVariantList& values, quint64& timestamp)
{
	values << _property->value();
	timestamp = _property->timestamp();
}

void FakePropertyAdaptor::propertyChanged()
{
	QVariantList values;
	quint64 timestamp;
	Get(values, timestamp);
	emit ValueChanged(values, timestamp);
}