BuildLogViewer/AtAGlance.cpp
author John Kern <johnk@symbian.org>
Thu, 26 Aug 2010 14:34:34 -0700
changeset 40 edc0144719a1
parent 3 e6d1a78b6db9
permissions -rwxr-xr-x
removed invariant from data() and rowCount(). Performance should be ok now.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     1
#include <QFile>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     2
#include <QFileInfo>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     3
#include <QDomDocument>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     4
#include <QDomElement>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     5
#include <QDomNode>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     6
#include <QMessageBox>
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents: 2
diff changeset
     7
#include <QGroupBox>
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     8
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     9
#include <QtGlobal>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    10
#include <QRegExp>
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    11
#include <QStringList>
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    12
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    13
#include <QGridLayout>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    14
#include <QLabel>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    15
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    16
#include <iostream>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    17
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    18
using namespace std;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    19
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    20
#include "AtAGlance.h"
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    21
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    22
AtAGlance::AtAGlance(QString filename, QWidget *parent)
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents: 2
diff changeset
    23
        : QWidget(parent), ui(new Ui::BuildResultsForm)
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    24
{
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents: 2
diff changeset
    25
    ui->setupUi(this);
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    26
    setAttribute(Qt::WA_DeleteOnClose);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    27
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    28
    QFile file(filename);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    29
    QFileInfo fi(file);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    30
    this->setWindowTitle("Status " + fi.baseName());
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    31
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    32
    m_buildStatus = new BuildStatus();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    33
    m_buildStatus->setTime(fi.lastModified());
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    34
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    35
    if (!file.open(QIODevice::ReadOnly)) {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    36
        QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot open log."));
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    37
        return ;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    38
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    39
    m_log = new QDomDocument("Build Log");
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    40
    if (!m_log->setContent(&file)) {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    41
        QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot set content."));
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    42
        file.close();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    43
        return ;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    44
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    45
    file.close();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    46
}
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    47
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    48
AtAGlance::~AtAGlance()
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    49
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    50
    delete m_log;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    51
    delete m_buildStatus;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    52
}
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    53
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    54
// Walk Dom tree.
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    55
void AtAGlance::traveAndPopulate()
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    56
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    57
    this->traveAndPopulate(m_log->documentElement());
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    58
}
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    59
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    60
void AtAGlance::traveAndPopulate(QDomElement e)
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    61
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    62
    QString name = e.tagName();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    63
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    64
    if (e.isNull())
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    65
    {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    66
        return;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    67
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    68
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    69
    //  if this is an info tags, look for
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    70
    //      <info>System Definition file sf/app/organizer/package_definition.xml</info>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    71
    if (name.compare("info",Qt::CaseInsensitive)== 0 )
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    72
    {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    73
        // example
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    74
        // System Definition file sf/app/organizer/package_definition.xml
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    75
        QRegExp re("System*package_definition.xml");
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    76
        re.setPatternSyntax(QRegExp::Wildcard);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    77
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    78
        if (re.exactMatch( e.text() ) )
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    79
        {
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    80
            QRegExp reToken("*package_definition.xml");
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    81
            // Which regex syntax should be used? Wildcard is ...
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    82
            reToken.setPatternSyntax(QRegExp::Wildcard);
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    83
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    84
            QStringList tokens = e.text().split(" ");
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    85
            QStringList::const_iterator constIterator;
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    86
            for (constIterator = tokens.constBegin();
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    87
                    constIterator != tokens.constEnd();
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    88
                    ++constIterator)
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    89
            {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    90
                if (reToken.exactMatch(*constIterator))
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    91
                {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    92
                    m_buildStatus->setName((*constIterator).toLocal8Bit().constData());
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    93
                }
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    94
            }
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    95
        }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    96
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    97
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    98
    // if this is a status tag and the exit attribute is failed, the build failed.
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    99
    if (name.compare("status",Qt::CaseInsensitive)== 0 )
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   100
    {
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   101
        QString rc = e.attribute("exit");
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   102
        if (!rc.isEmpty() && (rc.compare("failed", Qt::CaseInsensitive) == 0))
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   103
        {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   104
            m_buildStatus->setStatus(false);
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   105
        }
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   106
    }
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   107
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   108
    // unforunately, the build log isn't valid xml.  The recipe tag often contains
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   109
    // trace output from a shell program in addition to the status tag.  Sigh.
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   110
    // So this condition looks for the status tag in the body for the recipe tag.
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   111
    // here is what the status tag should look like:
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   112
    //   <status exit='ok' attempt='1' />
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   113
    if (name.compare("recipe",Qt::CaseInsensitive)== 0 )
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   114
    {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   115
        QRegExp re("*status exit*fail*");
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   116
        re.setPatternSyntax(QRegExp::Wildcard); 
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   117
        if (re.exactMatch(e.text()))
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   118
        {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   119
            m_buildStatus->setStatus(false);
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   120
        }
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   121
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   122
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   123
    QString text_debug;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   124
    QDomElement e1 = e.firstChild().toElement();
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   125
    name = e1.tagName();
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   126
    text_debug = e1.text();
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   127
    while(!e1.isNull())
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   128
    {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   129
        this->traveAndPopulate(e1);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   130
        e1 = e1.nextSibling().toElement();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   131
        name = e1.tagName();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   132
        text_debug = e1.text();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   133
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   134
}
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   135
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   136
void AtAGlance::decideOnLayout()
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   137
{
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents: 2
diff changeset
   138
    // QHBoxLayout *hLayout = new QHBoxLayout(this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents: 2
diff changeset
   139
    // QGroupBox *groupBox = new QGroupBox( "Synopsis of Build" );
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   140
    QGridLayout *layout = new QGridLayout(this);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   141
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   142
    layout->addWidget(new QLabel("What: "), 1, 1);
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   143
    layout->addWidget(new QLabel(*m_buildStatus->name()),1,2);
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   144
    layout->addWidget(new QLabel("When: "), 2, 1);
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   145
    layout->addWidget(new QLabel(m_buildStatus->time()) ,2,2);
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   146
    layout->addWidget(new QLabel("Status: "), 3, 1);
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   147
    layout->addWidget(new QLabel(*m_buildStatus->status()),3,2);
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents: 2
diff changeset
   148
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents: 2
diff changeset
   149
    // hLayout->addWidget(layout);
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   150
}