summaryrefslogtreecommitdiff
path: root/sysinfowatchlet/sysinfowatchlet.cpp
blob: 46d45e73d64e45fa78c1cf010496a99a31fc5b8e (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
#include "sysinfowatchlet.h"

using namespace sowatch;
QTM_USE_NAMESPACE

SysInfoWatchlet::SysInfoWatchlet(WatchServer* server) :
	DeclarativeWatchlet(server, "com.javispedro.sowatch.sysinfo"),
	_devInfo(new QSystemDeviceInfo(this)),
	_netMgr(new QNetworkConfigurationManager(this))
{
	rootContext()->setContextProperty("batteryLevel", 0);
	rootContext()->setContextProperty("networkName", "");
	setSource(QUrl(SOWATCH_QML_DIR "/sysinfowatchlet/" + server->watch()->model() + ".qml"));
	connect(this, SIGNAL(activated()), SLOT(handleActivated()));
}

void SysInfoWatchlet::handleActivated()
{
	QList<QNetworkConfiguration> cfgs = _netMgr->allConfigurations(QNetworkConfiguration::Active);
	rootContext()->setContextProperty("batteryLevel", _devInfo->batteryLevel());
	if (cfgs.size() > 0) {
		rootContext()->setContextProperty("networkName", cfgs[0].name());
	} else {
		rootContext()->setContextProperty("networkName", "-");
	}
}