~indicator-applet-developers/libusermetrics/trunk

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * Copyright (C) 2013 Canonical, Ltd.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of version 3 of the GNU Lesser General Public License as published
 * by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Pete Woods <pete.woods@canonical.com>
 */

#include <libusermetricsoutput/SyncedDataSet.h>
#include <libusermetricsoutput/SyncedUserData.h>
#include <libusermetricscommon/DataSetInterface.h>
#include <libusermetricscommon/DBusPaths.h>

using namespace com;
using namespace UserMetricsCommon;
using namespace UserMetricsOutput;

SyncedUserData::SyncedUserData(
		QSharedPointer<com::canonical::usermetrics::UserData> interface,
		QObject *parent) :
		UserData(parent), m_interface(interface) {

	connect(m_interface.data(),
			SIGNAL(dataSetAdded(const QString &, const QDBusObjectPath &)),
			this, SLOT(addDataSet(const QString &, const QDBusObjectPath &)));

	connect(m_interface.data(),
			SIGNAL(dataSetRemoved(const QString &, const QDBusObjectPath &)),
			this,
			SLOT(removeDataSet(const QString &, const QDBusObjectPath &)));

	for (const QDBusObjectPath &path : m_interface->dataSets()) {

		QSharedPointer<canonical::usermetrics::DataSet> dataSet(
				new canonical::usermetrics::DataSet(DBusPaths::serviceName(),
						path.path(), m_interface->connection()));

		QString dataSource(dataSet->dataSource());
		insert(dataSource, DataSetPtr(new SyncedDataSet(dataSet)));
	}

}

SyncedUserData::~SyncedUserData() {
}

void SyncedUserData::addDataSet(const QString &dataSourceName,
		const QDBusObjectPath &path) {
	QSharedPointer<canonical::usermetrics::DataSet> dataSet(
			new canonical::usermetrics::DataSet(DBusPaths::serviceName(),
					path.path(), m_interface->connection()));

	insert(dataSourceName, DataSetPtr(new SyncedDataSet(dataSet)));

	dataSetAdded(dataSourceName);
}

void SyncedUserData::removeDataSet(const QString &dataSetName,
		const QDBusObjectPath &path) {
	Q_UNUSED(path);
	m_dataSets.remove(dataSetName);
}