@@ -1,193 +0,0 @@
1−/*
2− * Copyright 2012 Canonical Ltd.
3− *
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.
7− *
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.
12− *
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/>.
15− *
16− * Authors:
17− * Renato Araujo Oliveira Filho <renato@canonical.com>
18− */
19−
20−#include "fake_pluginmodel.h"
21−#include "paths.h"
22−
23−#include <QQmlContext>
24−#include <QQmlEngine>
25−#include <QDebug>
26−#include <QQmlComponent>
27−
28−struct Indicator {
29− Indicator(QString const& title, QString iconSource, QString label, QString description, QString componentSource)
30− : title(title)
31− , iconSource(iconSource)
32− , label(label)
33− , description(description)
34− , componentSource(componentSource)
35− , isValid(true)
36− {}
37−
38− QString title;
39− QString iconSource;
40− QString label;
41− QString description;
42− QString componentSource;
43− QMap<QString, QVariant> initialProperties;
44− bool isValid;
45−};
46−
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");
53−
54−
55−PluginModel::PluginModel(QObject *parent)
56− : QAbstractListModel(parent)
57−{
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()));
61−}
62−
63−/*! \internal */
64−PluginModel::~PluginModel()
65−{
66−}
67−
68−/*!
69− \qmlmethod PluginModel::get(int)
70−
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.
73−*/
74−QVariantMap PluginModel::get(int row) const
75−{
76− QVariantMap result;
77−
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]);
84− }
85− }
86− return result;
87−}
88−
89−/*!
90− \qmlproperty PluginModel::count
91− The number of data entries in the model.
92−
93− \b Note: methods should only be called after the Component has completed.
94−*/
95−int PluginModel::count() const
96−{
97− return rowCount();
98−}
99−
100−/*!
101− \qmlmethod PluginModel::load()
102−
103− Load all plugin information available on baseDir.
104−*/
105−void PluginModel::load()
106−{
107−
108−}
109−
110−/*!
111− \qmlmethod PluginModel::unload()
112−
113− Unload all plugins.
114−*/
115−void PluginModel::unload()
116−{
117−}
118−
119−/*! \internal */
120−QHash<int, QByteArray> PluginModel::roleNames() const
121−{
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";
131− }
132− return roles;
133−}
134−
135−/*! \internal */
136−int PluginModel::columnCount(const QModelIndex &) const
137−{
138− return 1;
139−}
140−
141−/*! \internal */
142−QVariant PluginModel::data(const QModelIndex &index, int role) const
143−{
144− QVariant attribute;
145−
146− if ((index.row() >= 0) && (index.row() < indicator_list.size())) {
147− Indicator indicator = (indicator_list[index.row()]);
148−
149− switch (role) {
150− case Title:
151− attribute = indicator.title;
152− break;
153− case IconSource:
154− attribute = indicator.iconSource;
155− break;
156− case Label:
157− attribute = indicator.label;
158− break;
159− case Description:
160− attribute = indicator.description;
161− break;
162− case QMLComponent:
163− {
164− QQmlContext *context = QQmlEngine::contextForObject(this);
165− if (context) {
166− QQmlComponent* component = new QQmlComponent(context->parentContext()->engine(), QUrl(indicator.componentSource), NULL);
167− attribute = QVariant::fromValue<QQmlComponent*>(component);
168− }
169− } break;
170− case InitialProperties:
171− attribute = indicator.initialProperties;
172− break;
173− case IsValid:
174− attribute = indicator.isValid;
175− break;
176− default:
177− break;
178− }
179− }
180− return attribute;
181−}
182−
183−/*! \internal */
184−QModelIndex PluginModel::parent(const QModelIndex&) const
185−{
186− return QModelIndex();
187−}
188−
189−/*! \internal */
190−int PluginModel::rowCount(const QModelIndex &) const
191−{
192− return indicator_list.size();
193−}