10#include "datasource.h"
11#include <QAbstractItemModel>
15DataSource::DataSource(
QObject *parent)
23 setObjectName(QStringLiteral(
"DataSource"));
26void DataSource::classBegin()
30void DataSource::componentComplete()
36void DataSource::setConnectedSources(
const QStringList &sources)
38 bool sourcesChanged =
false;
39 for (
const QString &source : sources) {
40 if (!m_connectedSources.contains(source)) {
41 sourcesChanged =
true;
43 m_connectedSources.append(source);
44 m_dataEngine->connectSource(source,
this, m_interval, m_intervalAlignment);
45 Q_EMIT sourceConnected(source);
50 for (
const QString &source : std::as_const(m_connectedSources)) {
51 if (!sources.contains(source)) {
52 m_data->clear(source);
53 sourcesChanged =
true;
55 m_dataEngine->disconnectSource(source,
this);
56 Q_EMIT sourceDisconnected(source);
62 m_connectedSources = sources;
63 Q_EMIT connectedSourcesChanged();
67void DataSource::setEngine(
const QString &e)
75 if (m_engine.isEmpty()) {
76 Q_EMIT engineChanged();
83 qWarning() <<
"DataEngine" << m_engine <<
"not found";
84 Q_EMIT engineChanged();
89 m_dataEngine->disconnect(
this);
91 m_dataEngineConsumer.reset();
105 m_dataEngine = engine;
107 connect(m_dataEngine, &DataEngine::sourceRemoved,
this, &DataSource::updateSources);
110 connect(m_dataEngine, &DataEngine::sourceRemoved,
this, &DataSource::removeSource);
111 connect(m_dataEngine, &DataEngine::sourceRemoved,
this, &DataSource::sourceRemoved);
115 Q_EMIT engineChanged();
118void DataSource::setInterval(
const int interval)
120 if (interval == m_interval) {
124 m_interval = interval;
126 Q_EMIT intervalChanged();
131 if (intervalAlignment == m_intervalAlignment) {
135 m_intervalAlignment = intervalAlignment;
137 Q_EMIT intervalAlignmentChanged();
140void DataSource::setupData()
148 qDeleteAll(m_services);
151 for (
const QString &source : std::as_const(m_connectedSources)) {
152 m_dataEngine->connectSource(source,
this, m_interval, m_intervalAlignment);
153 Q_EMIT sourceConnected(source);
160 if (m_connectedSources.contains(sourceName)) {
161 m_data->insert(sourceName, data);
162 Q_EMIT dataChanged();
163 Q_EMIT newData(sourceName, data);
164 }
else if (m_dataEngine) {
165 m_dataEngine->disconnectSource(sourceName,
this);
172 m_models->clear(sourceName);
179 m_models->clear(sourceName);
183void DataSource::removeSource(
const QString &source)
185 m_data->clear(source);
186 m_models->clear(source);
189 if (m_connectedSources.contains(source)) {
190 m_connectedSources.removeAll(source);
191 Q_EMIT sourceDisconnected(source);
192 Q_EMIT connectedSourcesChanged();
197 if (it != m_services.end()) {
199 m_services.erase(it);
206 if (!m_services.contains(source)) {
211 m_services[source] = service;
214 return m_services.value(source);
217void DataSource::connectSource(
const QString &source)
219 if (m_connectedSources.contains(source)) {
223 m_connectedSources.append(source);
225 m_dataEngine->connectSource(source,
this, m_interval, m_intervalAlignment);
226 Q_EMIT sourceConnected(source);
227 Q_EMIT connectedSourcesChanged();
231void DataSource::disconnectSource(
const QString &source)
233 if (m_dataEngine && m_connectedSources.contains(source)) {
234 m_connectedSources.removeAll(source);
235 m_dataEngine->disconnectSource(source,
this);
236 Q_EMIT sourceDisconnected(source);
237 Q_EMIT connectedSourcesChanged();
241void DataSource::updateSources()
245 sources = m_dataEngine->sources();
248 if (sources != m_sources) {
250 Q_EMIT sourcesChanged();
256#include "moc_datasource.cpp"
A class that makes it safe and easy to use DataEngines.
Data provider for plasmoids (Plasma plugins)
This class provides a generic API for write access to settings or services.
IntervalAlignment
Possible timing alignments.
Namespace for everything in libplasma.
void destroyed(QObject *obj)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QVariant fromValue(T &&value)