Initial checkin
[opensuse:qtobs.git] / projectresulttreewidget.cpp
1 /*
2  *  Qt OBS - A Qt based OBS client
3  *
4  *  Copyright (C) 2010 Novell Inc, Klaas Freitag <freitag@suse.de>
5  *
6  *  This program is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 2 of the License, or
9  *  (at your option) version 3.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  *  --
20  *  Written by Klaas Freitag <freitag@suse.de>
21  *  Contributors:
22  */
23
24 #include <QDebug>
25 #include <QMap>
26 #include <QTreeWidgetItem>
27
28 #include "projectresulttreewidget.h"
29 #include "obsbuildresults.h"
30
31 ProjectResultTreeWidget::ProjectResultTreeWidget( QWidget *parent )
32     : QTreeWidget( parent )
33 {
34
35 }
36
37 void ProjectResultTreeWidget::showStatus( OBSProjectBuildResults results )
38 {
39   QStringList headers;
40   headers << tr("Package") << results.repositories();
41   qDebug() << "XXXXXXXXX " << headers << " - " << headers.count();
42   setColumnCount( headers.count() );
43
44   setHeaderLabels( headers );
45
46   QMap<QString, QTreeWidgetItem*> packLineMap;
47   QListIterator<OBSProjectBuildResult> i( results );
48   while( i.hasNext() ) {
49     OBSProjectBuildResult res = i.next();
50
51     QListIterator<OBSPackageBuildResult> pi( res.packageResults() );
52     qDebug() << "---> " << res.project() << " - " << res.repository() << " - " << res.architecture() << endl;
53
54     QString repo = res.repository();
55     QString arch = res.architecture();
56
57     while( pi.hasNext()) {
58       OBSPackageBuildResult pRes = pi.next();
59       qDebug() << "      Package:> " << pRes.name();
60       QString package = pRes.name();
61       QString state = pRes.state();
62       QTreeWidgetItem *displayItem = 0;
63
64       if( packLineMap.contains( package ) ) {
65         displayItem = packLineMap.value( package );
66       } else {
67         // the package is new and a display item needs to be created
68         displayItem = new QTreeWidgetItem( this );
69         packLineMap.insert( package, displayItem );
70         displayItem->setText( 0, package );
71       }
72
73       if( displayItem ) {
74         int pos = headers.indexOf( repo );
75         displayState( displayItem, pos, arch, state );
76       }
77     }
78   }
79 }
80
81
82 void ProjectResultTreeWidget::displayState( QTreeWidgetItem *item, int col, const QString& arch, const QString& state )
83 {
84   QString currContent = item->text( col );
85
86   QString newArchDisplay = arch;
87
88   QString newInfo = QString (" %1 %2(%3)").arg(currContent).arg(arch).arg(state);
89
90   item->setText( col, newInfo );
91 }