BuildLogViewer/AtAGlance.cpp
author John Kern <johnk@symbian.org>
Wed, 02 Sep 2009 19:04:26 -0700
changeset 1 8e9c5760ce6f
child 2 6894bf2709c0
permissions -rwxr-xr-x
working on a status view
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>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     7
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     8
#include <QtGlobal>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     9
#include <QRegExp>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    10
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    11
#include <QGridLayout>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    12
#include <QLabel>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    13
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    14
#include <iostream>
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
using namespace std;
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
#include "AtAGlance.h"
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
AtAGlance::AtAGlance(QString filename, QWidget *parent)
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
    setAttribute(Qt::WA_DeleteOnClose);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    23
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    24
    QFile file(filename);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    25
    QFileInfo fi(file);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    26
    this->setWindowTitle("Status " + fi.baseName());
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
    m_buildStatus = new BuildStatus();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    29
    m_buildStatus->setTime(fi.lastModified());
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    30
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    31
    if (!file.open(QIODevice::ReadOnly)) {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    32
        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
    33
        return ;
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
    m_log = new QDomDocument("Build Log");
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    36
    if (!m_log->setContent(&file)) {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    37
        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
    38
        file.close();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    39
        return ;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    40
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    41
    file.close();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    42
}
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    43
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    44
AtAGlance::~AtAGlance()
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    45
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    46
    delete m_log;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    47
    delete m_buildStatus;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    48
}
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
// Walk Dom tree.
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    51
void AtAGlance::traveAndPopulate()
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
    this->traveAndPopulate(m_log->documentElement());
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    54
}
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    55
void AtAGlance::traveAndPopulate(QDomElement e)
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
    QString name = e.tagName();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    58
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    59
    if (e.isNull())
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    60
    {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    61
        return;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    62
    }
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 this is an info tags, look for
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    65
    //      <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
    66
    if (name.compare("info",Qt::CaseInsensitive)== 0 )
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
        // example
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    69
        // System Definition file sf/app/organizer/package_definition.xml
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    70
        QRegExp re("^System Definition file .*package_definition.*$");
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    71
        re.setPatternSyntax(QRegExp::Wildcard);
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
        string blah = e.text().toStdString();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    74
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    75
        if (re.exactMatch( e.text() ) )
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    76
        {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    77
            std::cout << "info: " << e.text().toStdString()<< std::endl;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    78
        }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    79
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    80
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    81
    // 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
    82
    if (name.compare("status",Qt::CaseInsensitive)== 0 )
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    83
    {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    84
        m_buildStatus->setStatus(false);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    85
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    86
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    87
    QString text_debug;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    88
    QDomElement e1 = e.firstChild().toElement();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    89
    while(!e1.isNull())
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    90
    {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    91
        this->traveAndPopulate(e1);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    92
        e1 = e1.nextSibling().toElement();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    93
        name = e1.tagName();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    94
        text_debug = e1.text();
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
void AtAGlance::decideOnLayout()
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    99
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   100
    QGridLayout *layout = new QGridLayout(this);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   101
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   102
    layout->addWidget(new QLabel("What: "), 1, 1);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   103
    layout->addWidget(new QLabel("When: "), 2, 1);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   104
    layout->addWidget(new QLabel("Status: "), 3, 1);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   105
}