summaryrefslogtreecommitdiff
path: root/ckitcallnotification/ckitcallprovider.cpp
blob: 90dab97f7fa6e07a706b4738317e012e4e8092e0 (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
46
47
48
49
50
#include <QtCore/QtDebug>
#include <contextsubscriber/contextproperty.h>
#include "ckitcallnotification.h"
#include "ckitcallprovider.h"

using namespace sowatch;

CKitCallProvider::CKitCallProvider(QObject *parent) :
	NotificationProvider(parent),
	_activeCall(new ContextProperty("/com/nokia/CallUi/ActiveCall")),
	_notification(0)
{
	connect(_activeCall, SIGNAL(valueChanged()), SLOT(activeCallChanged()));
}

CKitCallProvider::~CKitCallProvider()
{

}

void CKitCallProvider::activeCallChanged()
{
	QVariantMap info = _activeCall->value().toMap();
	qDebug() << "active call changed" << info;
	if (!info.contains("state")) {
		qWarning() << "broken active call context property";
	}
	int state = info["state"].toInt();
	if (state == 0) {
		QString displayName = info["displayName"].toString();
		if (displayName.isEmpty()) {
			// Ignore call until display name is not empty.
			return;
		}
		// "Incoming call"
		if (_notification) {
			_notification->changeDisplayName(displayName);
		} else {
			_notification = new CKitCallNotification(displayName, this);
			emit incomingNotification(_notification);
		}
	} else {
		// Call is either answered, dropped, missed, ..
		if (_notification) {
			_notification->clear();
			_notification->deleteLater();
			_notification = 0;
		}
	}
}