@@ -19,18 +19,13 @@
20#include "indicatorsmodel.h"
20#include "indicatorsmodel.h"
21#include "indicatorsmanager.h"
21#include "indicatorsmanager.h"
22−#include "indicatorclientinterface.h"
22+#include "indicator.h"
24#include <QQmlContext>
25#include <QQmlContext>
25#include <QQmlEngine>
26#include <QQmlEngine>
26#include <QDebug>
27#include <QDebug>
29−static bool comparePlugins(const IndicatorClientInterface::Ptr obj1, const IndicatorClientInterface::Ptr obj2)
31− return obj1->priority() < obj2->priority();
35 \qmltype IndicatorsModel
30 \qmltype IndicatorsModel
36 \inherits QAbstractListModel
31 \inherits QAbstractListModel
@@ -128,37 +123,40 @@ void IndicatorsModel::unload()
128/*! \internal */
123/*! \internal */
129void IndicatorsModel::onIndicatorLoaded(const QString& indicator)
124void IndicatorsModel::onIndicatorLoaded(const QString& indicator)
131− IndicatorClientInterface::Ptr plugin = m_manager->indicator(indicator);
126+ Indicator::Ptr plugin = m_manager->indicator(indicator);
132 if (!plugin)
127 if (!plugin)
135− QList<IndicatorClientInterface::Ptr>::iterator i = qLowerBound(m_plugins.begin(), m_plugins.end(), plugin, comparePlugins);
130+ if (m_plugins.indexOf(plugin) >= 0)
136− int insert_pos = qMin(i - m_plugins.begin(), m_plugins.count());
131+ return;
138− beginInsertRows(QModelIndex(), insert_pos, insert_pos);
140− QObject* obj = dynamic_cast<QObject*>(plugin.get());
133+ // find the insert position
141− if (obj)
134+ int pos = 0;
142− {
135+ while (pos < count()) {
143− QObject::connect(obj, SIGNAL(identifierChanged(const QString&)), this, SLOT(onIdentifierChanged()));
136+ // keep going while the existing priority is less.
144− QObject::connect(obj, SIGNAL(titleChanged(const QString&)), this, SLOT(onTitleChanged()));
137+ if (indicatorData(plugin, Priority).toInt() < data(index(pos), Priority).toInt())
145− QObject::connect(obj, SIGNAL(labelChanged(const QString&)), this, SLOT(onLabelChanged()));
138+ break;
148− m_plugins.insert(i, plugin);
142+ QObject::connect(plugin.get(), SIGNAL(identifierChanged(const QString&)), this, SLOT(onIdentifierChanged()));
143+ QObject::connect(plugin.get(), SIGNAL(indicatorPropertiesChanged(const QVariant&)), this, SLOT(onIndicatorPropertiesChanged()));
145+ beginInsertRows(QModelIndex(), pos, pos);
147+ m_plugins.insert(pos, plugin);
150 endInsertRows();
148 endInsertRows();
153/*! \internal */
151/*! \internal */
154void IndicatorsModel::onIndicatorAboutToBeUnloaded(const QString& indicator)
152void IndicatorsModel::onIndicatorAboutToBeUnloaded(const QString& indicator)
156− IndicatorClientInterface::Ptr plugin = m_manager->indicator(indicator);
154+ Indicator::Ptr plugin = m_manager->indicator(indicator);
157 if (!plugin)
155 if (!plugin)
160 int i = 0;
158 int i = 0;
161− QMutableListIterator<IndicatorClientInterface::Ptr> iter(m_plugins);
159+ QMutableListIterator<Indicator::Ptr> iter(m_plugins);
162 while(iter.hasNext())
160 while(iter.hasNext())
164 if (plugin == iter.next())
162 if (plugin == iter.next())
@@ -179,26 +177,20 @@ void IndicatorsModel::onIdentifierChanged()
181/*! \internal */
179/*! \internal */
182−void IndicatorsModel::onTitleChanged()
180+void IndicatorsModel::onIndicatorPropertiesChanged()
184− notifyDataChanged(QObject::sender(), Title);
182+ notifyDataChanged(QObject::sender(), IndicatorProperties);
188−void IndicatorsModel::onLabelChanged()
190− notifyDataChanged(QObject::sender(), Label);
193/*! \internal */
185/*! \internal */
194void IndicatorsModel::notifyDataChanged(QObject *sender, int role)
186void IndicatorsModel::notifyDataChanged(QObject *sender, int role)
196− IndicatorClientInterface* plugin = dynamic_cast<IndicatorClientInterface*>(sender);
188+ Indicator* plugin = qobject_cast<Indicator*>(sender);
197 if (!plugin)
189 if (!plugin)
200 int index = 0;
192 int index = 0;
201− QMutableListIterator<IndicatorClientInterface::Ptr> iter(m_plugins);
193+ QMutableListIterator<Indicator::Ptr> iter(m_plugins);
202 while(iter.hasNext())
194 while(iter.hasNext())
204 if (iter.next().get() == plugin)
196 if (iter.next().get() == plugin)
@@ -215,14 +207,15 @@ void IndicatorsModel::notifyDataChanged(QObject *sender, int role)
215QHash<int, QByteArray> IndicatorsModel::roleNames() const
207QHash<int, QByteArray> IndicatorsModel::roleNames() const
217 static QHash<int, QByteArray> roles;
209 static QHash<int, QByteArray> roles;
218− if (roles.isEmpty()) {
210+ if (roles.isEmpty())
219 roles[Identifier] = "identifier";
212 roles[Identifier] = "identifier";
213+ roles[Priority] = "priority";
220 roles[Title] = "title";
214 roles[Title] = "title";
221− roles[Label] = "label";
222 roles[Description] = "description";
215 roles[Description] = "description";
223− roles[IconUrl] = "iconUrl";
216+ roles[IconQml] = "iconQml";
224− roles[PageUrl] = "pageUrl";
217+ roles[PageQml] = "pageQml";
225− roles[InitialProperties] = "initialProperties";
218+ roles[IndicatorProperties] = "indicatorProperties";
226 roles[IsValid] = "isValid";
219 roles[IsValid] = "isValid";
228 return roles;
221 return roles;
@@ -234,63 +227,69 @@ int IndicatorsModel::columnCount(const QModelIndex &) const
234 return 1;
227 return 1;
231+QVariant IndicatorsModel::defaultData(Indicator::Ptr plugin, int role)
238+ return plugin ? plugin->identifier() : "Unknown";
242+ return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorIcon.qml";
244+ return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorPage.qml";
237/*! \internal */
249/*! \internal */
238QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
250QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
240 if (!index.isValid() || index.row() >= m_plugins.size())
252 if (!index.isValid() || index.row() >= m_plugins.size())
241 return QVariant();
253 return QVariant();
245− IndicatorClientInterface::Ptr plugin = m_plugins[index.row()];
255+ Indicator::Ptr plugin = m_plugins[index.row()];
247− switch (role) {
257+ switch (role)
250− attribute = QVariant(plugin->identifier());
255− attribute = QVariant(plugin->title());
260− attribute = QVariant(plugin->label());
265− if (plugin) {
260+ if (plugin)
266− attribute = QVariant(plugin->description());
261+ {
262+ return QVariant(plugin->identifier());
265+ case IndicatorProperties:
268+ return QVariant(plugin->indicatorProperties());
272+ return (plugin.get() ? true : false);
278+ return indicatorData(plugin, role);
270− case IconUrl:
282+ return QVariant();
272− return plugin->iconComponentSource().toString();
284+
273− } else {
285+QVariant IndicatorsModel::indicatorData(const Indicator::Ptr& plugin, int role) const
274− attribute = QVariant("No plugin");
286+{
275− }
287+ if (plugin && m_parsed_indicator_data.contains(plugin->identifier()))
277− case PageUrl:
289+ QVariantMap data = m_parsed_indicator_data[plugin->identifier()];
278− if (plugin) {
290+ return data.value(roleNames()[role], QVariant());
279− return plugin->pageComponentSource();
282− case InitialProperties:
284− attribute = plugin->initialProperties();
288− attribute = QVariant(plugin != 0);
293− return attribute;
292+ return defaultData(plugin, role);
296/*! \internal */
295/*! \internal */
@@ -304,3 +303,24 @@ int IndicatorsModel::rowCount(const QModelIndex&) const
305 return m_plugins.count();
304 return m_plugins.count();
307+void IndicatorsModel::setIndicatorData(const QVariant& data)
309+ m_indicator_data = data;
311+ m_parsed_indicator_data.clear();
312+ QMap<QString, QVariant> map = data.toMap();
313+ QMapIterator<QString, QVariant> iter(map);
314+ while(iter.hasNext())
317+ m_parsed_indicator_data[iter.key()] = iter.value().toMap();
320+ Q_EMIT indicatorDataChanged(m_indicator_data);
323+QVariant IndicatorsModel::indicatorData() const
325+ return m_indicator_data;