~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to checkbox-gui/checkbox-gui/testitemmodel.cpp

  • Committer: Sylvain Pineau
  • Date: 2014-07-29 16:05:54 UTC
  • mto: This revision was merged to the branch mainline in revision 3149.
  • Revision ID: sylvain.pineau@canonical.com-20140729160554-qev8887xbunn9tmi
checkbox-ng:launchers:checkbox-cli: The checkbox-cli launcher

Running the default whitelist (with the suite selection screen skipped)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Checkbox
 
3
 *
 
4
 * Copyright 2013 Canonical Ltd.
 
5
 *
 
6
 * Authors:
 
7
 * - Andrew Haigh <andrew.haigh@cellsoftware.co.uk>
 
8
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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/>.
 
20
 */
 
21
 
 
22
#include "testitemmodel.h"
 
23
 
 
24
// Factory class to create or update a TestItem Model
 
25
ListModel* TestItemModel::CreateTestListModel(ListModel* model)
 
26
{
 
27
    // Create a model
 
28
    qDebug("TestItemModel::CreateTestListModel()");
 
29
 
 
30
    // We can create OR update the model
 
31
    if (model==NULL) {
 
32
        qDebug("Creating fresh TestItemModel");
 
33
        model = new ListModel(new TestItem, qApp);
 
34
    } else {
 
35
        qDebug("Recreating TestItemModel");
 
36
        model->clear();
 
37
    }
 
38
 
 
39
    // We should interrogate the whitelist here
 
40
    const QString engname("");
 
41
 
 
42
    GuiEngine* myengine = qApp->findChild<GuiEngine*>(engname);
 
43
    if(myengine == NULL) {
 
44
        qDebug("Cant find guiengine object");
 
45
 
 
46
        // NB: Model will be empty at this point
 
47
        return model;
 
48
    }
 
49
 
 
50
    // Get all of the jobs here
 
51
    QList<PBTreeNode*> jobnodes = myengine->GetJobNodes();
 
52
 
 
53
    // Need to flatten the tree in the right order here
 
54
    JobTreeNode* jt_top = myengine->GetJobTreeNodes();
 
55
 
 
56
    if (!jt_top) {
 
57
        qDebug("no valid JobTree");
 
58
        return NULL;
 
59
    }
 
60
 
 
61
    QList<JobTreeNode*> flatnodes;
 
62
 
 
63
    flatnodes.clear();
 
64
 
 
65
    jt_top->Flatten(jt_top,flatnodes);
 
66
 
 
67
    // dont forget the "first" node is our internal one
 
68
    flatnodes.removeFirst();
 
69
 
 
70
    QList<JobTreeNode*>::iterator iter = flatnodes.begin();
 
71
 
 
72
    while(iter != flatnodes.end()) {
 
73
 
 
74
        PBObjectInterface* iface = NULL;
 
75
 
 
76
        JobTreeNode* jnode = *iter;
 
77
        if (jnode == NULL) {
 
78
            qDebug("We ran out of known nodes!");
 
79
            break;
 
80
        }
 
81
 
 
82
        if (jnode->m_node == NULL) {
 
83
            qDebug("must be the top node again");
 
84
        }
 
85
 
 
86
        PBTreeNode* node = jnode->m_node;
 
87
        // is this a valid item for the user?
 
88
        QList<QDBusObjectPath> list;
 
89
 
 
90
        list.append(node->object_path);
 
91
 
 
92
        // check against our filtered list
 
93
        QList<QDBusObjectPath> short_valid_list = \
 
94
                JobTreeNode::FilteredJobs(list,\
 
95
                                       myengine->GetVisibleRunList());
 
96
 
 
97
        if (myengine->GetVisibleRunList().count() != 0) {
 
98
            // we have _some_ valid tests :)
 
99
            if (short_valid_list.isEmpty()) {
 
100
                // we dont show this one
 
101
                iter++;
 
102
                continue;
 
103
            }
 
104
        }
 
105
 
 
106
        double duration;
 
107
        QString checksum;
 
108
        QString depends;
 
109
        QString partial_id;
 
110
        QString testname;
 
111
        QString requires;
 
112
        QString description;
 
113
        QString command;
 
114
        QString environ;
 
115
        QString plugin;
 
116
        QString type = tr("Automatic");
 
117
        QString user;
 
118
        QString via;
 
119
        QString group;
 
120
        bool check = true; // default to show every test
 
121
        QString path;
 
122
 
 
123
        QList<QString> parent_names;
 
124
        QList<QString> parent_ids;
 
125
 
 
126
        // Fill in the parent names
 
127
        JobTreeNode* temp = jnode->parent;
 
128
 
 
129
        while (temp != jt_top) {
 
130
            parent_names.prepend(temp->m_name);
 
131
 
 
132
            temp = temp->parent;
 
133
        }
 
134
 
 
135
        // Fill in the parent ids
 
136
        temp = jnode->parent;
 
137
 
 
138
        while (temp != jt_top) {
 
139
           parent_ids.prepend(temp->m_id);
 
140
 
 
141
           temp = temp->parent;
 
142
        }
 
143
 
 
144
        // The path for this job is:
 
145
        path = jnode->m_node->object_path.path();
 
146
 
 
147
        for(int j=0; j < node->interfaces.count(); j++) {
 
148
 
 
149
            iface = node->interfaces.at(j);
 
150
 
 
151
            if (iface == NULL) {
 
152
                qDebug("Null interface");
 
153
            } else {
 
154
                if(iface->interface.compare(PlainboxJobDefinition1) == 0) {
 
155
                    QVariant variant;
 
156
 
 
157
                    variant = *iface->properties.find("estimated_duration");
 
158
                    if (variant.isValid() && variant.canConvert(QMetaType::Double)) {
 
159
                        duration = variant.toDouble();
 
160
                    }
 
161
 
 
162
                    variant = *iface->properties.find("checksum");
 
163
                    if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
 
164
                        checksum = variant.toString();
 
165
                    }
 
166
 
 
167
                    variant = *iface->properties.find("depends");
 
168
                    if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
 
169
                        depends = variant.toString();
 
170
                    }
 
171
                    variant = *iface->properties.find("description");
 
172
                    if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
 
173
                        description = variant.toString();
 
174
                    }
 
175
 
 
176
                    variant = *iface->properties.find("summary");
 
177
                    if (variant.isValid() && variant.canConvert(QMetaType::QString) ) {
 
178
                        testname = variant.toString();
 
179
                    }
 
180
 
 
181
                    variant = *iface->properties.find("partial_id");
 
182
                    if (variant.isValid() && variant.canConvert(QMetaType::QString) ) {
 
183
                        partial_id = variant.toString();
 
184
                    }
 
185
 
 
186
                    variant = *iface->properties.find("requires");
 
187
                    if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
 
188
                        requires = variant.toString();
 
189
                    }
 
190
                }
 
191
 
 
192
                if(iface->interface.compare(CheckBoxJobDefinition1) == 0) {
 
193
                    QVariant variant;
 
194
                    variant = *iface->properties.find("plugin");
 
195
 
 
196
                    if (variant.isValid() && variant.canConvert(QMetaType::QString) ) {
 
197
                        plugin = variant.toString();
 
198
 
 
199
                        /* show plugin type as either Automatic (default) or
 
200
                         * Manual.
 
201
                         */
 
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) {
 
206
                            type = tr("Manual");
 
207
                        }
 
208
 
 
209
                        // local jobs should display description if there's no summary
 
210
                        // not partial_id
 
211
                        if (variant.toString().compare("local") == 0) {
 
212
                            if (testname == partial_id) {
 
213
                                testname = description;
 
214
                            }
 
215
                        }
 
216
                    }
 
217
 
 
218
                    variant = *iface->properties.find("via");
 
219
                    if (variant.isValid() && variant.canConvert(QMetaType::QString) ) {
 
220
                        via = variant.toString();
 
221
                    }
 
222
 
 
223
                    variant = *iface->properties.find("command");
 
224
                    if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
 
225
                        command = variant.toString();
 
226
                    }
 
227
                }
 
228
            }
 
229
        }
 
230
 
 
231
        // this will signal how far indented this item is
 
232
        int depth = 0;
 
233
        for (int i=0;i<parent_ids.count();i++) {
 
234
 
 
235
            depth++;
 
236
        }
 
237
 
 
238
        // Does this node have children?
 
239
        bool branch = false;
 
240
        if (!jnode->m_children.isEmpty()) {
 
241
            branch = true;
 
242
 
 
243
            /* Avoid trying to determine the Automatic/Manual nature of
 
244
             * various categories of tests.
 
245
             */
 
246
            type = tr("-");
 
247
        }
 
248
 
 
249
        model->appendRow(
 
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));
 
254
        iter++;
 
255
    }
 
256
 
 
257
    qDebug("TestItemModel::CreateTestListModel() - done");
 
258
 
 
259
    return model;
 
260
}
 
261
 
 
262
 
 
263
QList<QDBusObjectPath> TestItemModel::GetSelectedRealJobs(ListModel* model)
 
264
{
 
265
    QList<QDBusObjectPath> selected_jobs_list;
 
266
    if (!model) {
 
267
        qDebug() << "ERROR" << __FUNCTION__ << "model not supplied";
 
268
        return selected_jobs_list;
 
269
    }
 
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);
 
284
        } else {
 
285
            qDebug() << "[" << __FUNCTION__ << "]" << " NOT SELECTING " << partial_id;
 
286
        }
 
287
    }
 
288
    GuiEngine* myengine = qApp->findChild<GuiEngine*>("");
 
289
    if (myengine) {
 
290
        myengine->SetRealJobsList(selected_jobs_list);
 
291
        qDebug() << "[" << __FUNCTION__ << "]" \
 
292
            << "SELECTED jobs copied to m_final_run_list";
 
293
    } else {
 
294
        qDebug() << "ERROR" << __FUNCTION__ << "cannot get gui-engine";
 
295
    }
 
296
    return selected_jobs_list;
 
297
}
 
298
 
 
299
 
 
300
QList<QDBusObjectPath> TestItemModel::GetSelectedRerunJobs(ListModel* model)
 
301
{
 
302
    QList<QDBusObjectPath> selected_rerun_list;
 
303
    if (!model) {
 
304
        qDebug() << "ERROR" << __FUNCTION__ << "model not supplied";
 
305
        return selected_rerun_list;
 
306
    }
 
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));
 
319
        } else {
 
320
            qDebug() << "[" << __FUNCTION__ << "]" << "NOT SELECTING" << partial_id;
 
321
        }
 
322
    }
 
323
    GuiEngine* myengine = qApp->findChild<GuiEngine*>("");
 
324
    if (myengine) {
 
325
        myengine->SetRerunJobsList(selected_rerun_list);
 
326
        qDebug() << "[" << __FUNCTION__ << "]" \
 
327
            << "SELECTED jobs copied to m_rerun_list";
 
328
    } else {
 
329
        qDebug() << "ERROR" << __FUNCTION__ << "cannot get gui-engine";
 
330
    }
 
331
    return selected_rerun_list;
 
332
}
 
333
 
 
334
 
 
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
 
337
 * is resumed
 
338
 */
 
339
QList<QDBusObjectPath> TestItemModel::GetSelectedVisibleJobs(ListModel* model)
 
340
{
 
341
    QList<QDBusObjectPath> visible_jobs_list;
 
342
    if (!model) {
 
343
        qDebug() << "ERROR" << __FUNCTION__ << "model not supplied";
 
344
        return visible_jobs_list;
 
345
    }
 
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();
 
355
        if (check) {
 
356
            qDebug() << "[" << __FUNCTION__ << "]" << "VISIBLE" << partial_id;
 
357
            visible_jobs_list.append(QDBusObjectPath(objectpath));
 
358
        } else {
 
359
            qDebug() << "[" << __FUNCTION__ << "]" << "NOT VISIBLE" << partial_id;
 
360
        }
 
361
    }
 
362
    GuiEngine* myengine = qApp->findChild<GuiEngine*>("");
 
363
    if (myengine) {
 
364
        myengine->SetVisibleJobsList(visible_jobs_list);
 
365
        qDebug() << "[" << __FUNCTION__ << "]" \
 
366
            << "VISIBLE jobs copied to m_visible_run_list";
 
367
    } else {
 
368
        qDebug() << "ERROR" << __FUNCTION__ << "cannot get gui-engine";
 
369
    }
 
370
    return visible_jobs_list;
 
371
}