@@ -1,193 +0,0 @@
2− * Copyright 2012 Canonical Ltd.
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
17− * Renato Araujo Oliveira Filho <renato@canonical.com>
20−#include "fake_pluginmodel.h"
23−#include <QQmlContext>
26−#include <QQmlComponent>
29− Indicator(QString const& title, QString iconSource, QString label, QString description, QString componentSource)
31− , iconSource(iconSource)
33− , description(description)
34− , componentSource(componentSource)
42− QString componentSource;
43− QMap<QString, QVariant> initialProperties;
47−const QList<Indicator> indicator_list = QList<Indicator>()
48− << Indicator("Menu1", sourceDirectory()+"Panel/graphics/Battery@18.png", "", "", sourceDirectory()+"tests/qmltests/Panel/qml/fake_menu_plugin1.qml")
49− << Indicator("Menu2", sourceDirectory()+"Panel/graphics/Bluetooth@18.png", "", "", sourceDirectory()+"tests/qmltests/Panel/qml/fake_menu_plugin2.qml")
50− << Indicator("Menu3", sourceDirectory()+"Panel/graphics/Clock@18.png", "", "", sourceDirectory()+"tests/qmltests/Panel/qml/fake_menu_plugin3.qml")
51− << Indicator("Menu4", sourceDirectory()+"Panel/graphics/Location@18.png", "", "", sourceDirectory()+"tests/qmltests/Panel/qml/fake_menu_plugin4.qml")
52− << Indicator("Menu5", sourceDirectory()+"Panel/graphics/Network@18.png", "", "", sourceDirectory()+"tests/qmltests/Panel/qml/fake_menu_plugin5.qml");
55−PluginModel::PluginModel(QObject *parent)
56− : QAbstractListModel(parent)
58− QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
59− QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
60− QObject::connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
64−PluginModel::~PluginModel()
69− \qmlmethod PluginModel::get(int)
71− Returns the item at index in the model. This allows the item data to be accessed from JavaScript:
72− \b Note: methods should only be called after the Component has completed.
74−QVariantMap PluginModel::get(int row) const
78− QModelIndex index = this->index(row);
79− if (index.isValid()) {
80− QMap<int, QVariant> data = itemData(index);
81− const QHash<int, QByteArray> roleNames = this->roleNames();
82− Q_FOREACH(int i, roleNames.keys()) {
83− result.insert(roleNames[i], data[i]);
90− \qmlproperty PluginModel::count
91− The number of data entries in the model.
93− \b Note: methods should only be called after the Component has completed.
95−int PluginModel::count() const
101− \qmlmethod PluginModel::load()
103− Load all plugin information available on baseDir.
105−void PluginModel::load()
111− \qmlmethod PluginModel::unload()
115−void PluginModel::unload()
120−QHash<int, QByteArray> PluginModel::roleNames() const
122− static QHash<int, QByteArray> roles;
123− if (roles.isEmpty()) {
124− roles[Title] = "title";
125− roles[IconSource] = "iconSource";
126− roles[Label] = "label";
127− roles[Description] = "description";
128− roles[QMLComponent] = "component";
129− roles[InitialProperties] = "initialProperties";
130− roles[IsValid] = "isValid";
136−int PluginModel::columnCount(const QModelIndex &) const
142−QVariant PluginModel::data(const QModelIndex &index, int role) const
146− if ((index.row() >= 0) && (index.row() < indicator_list.size())) {
147− Indicator indicator = (indicator_list[index.row()]);
151− attribute = indicator.title;
154− attribute = indicator.iconSource;
157− attribute = indicator.label;
160− attribute = indicator.description;
164− QQmlContext *context = QQmlEngine::contextForObject(this);
166− QQmlComponent* component = new QQmlComponent(context->parentContext()->engine(), QUrl(indicator.componentSource), NULL);
167− attribute = QVariant::fromValue<QQmlComponent*>(component);
170− case InitialProperties:
171− attribute = indicator.initialProperties;
174− attribute = indicator.isValid;
184−QModelIndex PluginModel::parent(const QModelIndex&) const
186− return QModelIndex();
190−int PluginModel::rowCount(const QModelIndex &) const
192− return indicator_list.size();