2
* This file is part of Checkbox
4
* Copyright 2013 Canonical Ltd.
7
* - Andrew Haigh <andrew.haigh@cellsoftware.co.uk>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; version 3.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "testitemmodel.h"
24
// Factory class to create or update a TestItem Model
25
ListModel* TestItemModel::CreateTestListModel(ListModel* model)
28
qDebug("TestItemModel::CreateTestListModel()");
30
// We can create OR update the model
32
qDebug("Creating fresh TestItemModel");
33
model = new ListModel(new TestItem, qApp);
35
qDebug("Recreating TestItemModel");
39
// We should interrogate the whitelist here
40
const QString engname("");
42
GuiEngine* myengine = qApp->findChild<GuiEngine*>(engname);
43
if(myengine == NULL) {
44
qDebug("Cant find guiengine object");
46
// NB: Model will be empty at this point
50
// Get all of the jobs here
51
QList<PBTreeNode*> jobnodes = myengine->GetJobNodes();
53
// Need to flatten the tree in the right order here
54
JobTreeNode* jt_top = myengine->GetJobTreeNodes();
57
qDebug("no valid JobTree");
61
QList<JobTreeNode*> flatnodes;
65
jt_top->Flatten(jt_top,flatnodes);
67
// dont forget the "first" node is our internal one
68
flatnodes.removeFirst();
70
QList<JobTreeNode*>::iterator iter = flatnodes.begin();
72
while(iter != flatnodes.end()) {
74
PBObjectInterface* iface = NULL;
76
JobTreeNode* jnode = *iter;
78
qDebug("We ran out of known nodes!");
82
if (jnode->m_node == NULL) {
83
qDebug("must be the top node again");
86
PBTreeNode* node = jnode->m_node;
87
// is this a valid item for the user?
88
QList<QDBusObjectPath> list;
90
list.append(node->object_path);
92
// check against our filtered list
93
QList<QDBusObjectPath> short_valid_list = \
94
JobTreeNode::FilteredJobs(list,\
95
myengine->GetVisibleRunList());
97
if (myengine->GetVisibleRunList().count() != 0) {
98
// we have _some_ valid tests :)
99
if (short_valid_list.isEmpty()) {
100
// we dont show this one
116
QString type = tr("Automatic");
120
bool check = true; // default to show every test
123
QList<QString> parent_names;
124
QList<QString> parent_ids;
126
// Fill in the parent names
127
JobTreeNode* temp = jnode->parent;
129
while (temp != jt_top) {
130
parent_names.prepend(temp->m_name);
135
// Fill in the parent ids
136
temp = jnode->parent;
138
while (temp != jt_top) {
139
parent_ids.prepend(temp->m_id);
144
// The path for this job is:
145
path = jnode->m_node->object_path.path();
147
for(int j=0; j < node->interfaces.count(); j++) {
149
iface = node->interfaces.at(j);
152
qDebug("Null interface");
154
if(iface->interface.compare(PlainboxJobDefinition1) == 0) {
157
variant = *iface->properties.find("estimated_duration");
158
if (variant.isValid() && variant.canConvert(QMetaType::Double)) {
159
duration = variant.toDouble();
162
variant = *iface->properties.find("checksum");
163
if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
164
checksum = variant.toString();
167
variant = *iface->properties.find("depends");
168
if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
169
depends = variant.toString();
171
variant = *iface->properties.find("description");
172
if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
173
description = variant.toString();
176
variant = *iface->properties.find("summary");
177
if (variant.isValid() && variant.canConvert(QMetaType::QString) ) {
178
testname = variant.toString();
181
variant = *iface->properties.find("partial_id");
182
if (variant.isValid() && variant.canConvert(QMetaType::QString) ) {
183
partial_id = variant.toString();
186
variant = *iface->properties.find("requires");
187
if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
188
requires = variant.toString();
192
if(iface->interface.compare(CheckBoxJobDefinition1) == 0) {
194
variant = *iface->properties.find("plugin");
196
if (variant.isValid() && variant.canConvert(QMetaType::QString) ) {
197
plugin = variant.toString();
199
/* show plugin type as either Automatic (default) or
202
if (variant.toString().compare("manual") == 0 ||
203
variant.toString().compare("user-interact") == 0 ||
204
variant.toString().compare("user-verify") == 0 ||
205
variant.toString().compare("user-interact-verify") == 0) {
209
// local jobs should display description if there's no summary
211
if (variant.toString().compare("local") == 0) {
212
if (testname == partial_id) {
213
testname = description;
218
variant = *iface->properties.find("via");
219
if (variant.isValid() && variant.canConvert(QMetaType::QString) ) {
220
via = variant.toString();
223
variant = *iface->properties.find("command");
224
if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
225
command = variant.toString();
231
// this will signal how far indented this item is
233
for (int i=0;i<parent_ids.count();i++) {
238
// Does this node have children?
240
if (!jnode->m_children.isEmpty()) {
243
/* Avoid trying to determine the Automatic/Manual nature of
244
* various categories of tests.
250
new TestItem(duration,
251
partial_id, checksum, depends, testname, requires, description, command,
252
environ, plugin, type, user, group, via, check, path,
253
parent_names, parent_ids, depth, branch, model));
257
qDebug("TestItemModel::CreateTestListModel() - done");
263
QList<QDBusObjectPath> TestItemModel::GetSelectedRealJobs(ListModel* model)
265
QList<QDBusObjectPath> selected_jobs_list;
267
qDebug() << "ERROR" << __FUNCTION__ << "model not supplied";
268
return selected_jobs_list;
270
for (int i=0; i<model->getCount(); i++) {
271
QModelIndex index = model->index(i);
272
QString objectpath = model->data(
273
index, TestItem::ObjectPathRole).toString();
274
QString partial_id = model->data(
275
index, TestItem::PartialIdRole).toString();
276
QString plugin = model->data(
277
index, TestItem::PluginRole).toString();
278
bool check = model->data(
279
index,TestItem::CheckRole).toBool();
280
if (check && plugin != "local") {
281
qDebug() << "[" << __FUNCTION__ << "]" << " SELECTING " << partial_id;
282
QDBusObjectPath opath(objectpath);
283
selected_jobs_list.append(opath);
285
qDebug() << "[" << __FUNCTION__ << "]" << " NOT SELECTING " << partial_id;
288
GuiEngine* myengine = qApp->findChild<GuiEngine*>("");
290
myengine->SetRealJobsList(selected_jobs_list);
291
qDebug() << "[" << __FUNCTION__ << "]" \
292
<< "SELECTED jobs copied to m_final_run_list";
294
qDebug() << "ERROR" << __FUNCTION__ << "cannot get gui-engine";
296
return selected_jobs_list;
300
QList<QDBusObjectPath> TestItemModel::GetSelectedRerunJobs(ListModel* model)
302
QList<QDBusObjectPath> selected_rerun_list;
304
qDebug() << "ERROR" << __FUNCTION__ << "model not supplied";
305
return selected_rerun_list;
307
for (int i=0; i<model->getCount(); i++) {
308
QModelIndex index = model->index(i);
309
QString objectpath = model->data(
310
index, TestItem::ObjectPathRole).toString();
311
QString partial_id = model->data(
312
index, TestItem::PartialIdRole).toString();
313
QString plugin = model->data(
314
index, TestItem::PluginRole).toString();
315
bool rerun = model->data(index, TestItem::RerunRole).toBool();
316
if (rerun && plugin != "local") {
317
qDebug() << "[" << __FUNCTION__ << "]" << "SELECTING" << partial_id;
318
selected_rerun_list.append(QDBusObjectPath(objectpath));
320
qDebug() << "[" << __FUNCTION__ << "]" << "NOT SELECTING" << partial_id;
323
GuiEngine* myengine = qApp->findChild<GuiEngine*>("");
325
myengine->SetRerunJobsList(selected_rerun_list);
326
qDebug() << "[" << __FUNCTION__ << "]" \
327
<< "SELECTED jobs copied to m_rerun_list";
329
qDebug() << "ERROR" << __FUNCTION__ << "cannot get gui-engine";
331
return selected_rerun_list;
335
/* Track the jobs which are actually needed for display in the runmanager
336
* as they will be needed when the gui is reconstructed after a session
339
QList<QDBusObjectPath> TestItemModel::GetSelectedVisibleJobs(ListModel* model)
341
QList<QDBusObjectPath> visible_jobs_list;
343
qDebug() << "ERROR" << __FUNCTION__ << "model not supplied";
344
return visible_jobs_list;
346
for (int i=0; i<model->getCount(); i++) {
347
QModelIndex index = model->index(i);
348
QString objectpath = model->data(
349
index, TestItem::ObjectPathRole).toString();
350
QString partial_id = model->data(
351
index, TestItem::PartialIdRole).toString();
352
QString plugin = model->data(
353
index, TestItem::PluginRole).toString();
354
bool check = model->data(index, TestItem::CheckRole).toBool();
356
qDebug() << "[" << __FUNCTION__ << "]" << "VISIBLE" << partial_id;
357
visible_jobs_list.append(QDBusObjectPath(objectpath));
359
qDebug() << "[" << __FUNCTION__ << "]" << "NOT VISIBLE" << partial_id;
362
GuiEngine* myengine = qApp->findChild<GuiEngine*>("");
364
myengine->SetVisibleJobsList(visible_jobs_list);
365
qDebug() << "[" << __FUNCTION__ << "]" \
366
<< "VISIBLE jobs copied to m_visible_run_list";
368
qDebug() << "ERROR" << __FUNCTION__ << "cannot get gui-engine";
370
return visible_jobs_list;