1
/* This file is part of the KDE project
2
Copyright (C) 2006 Dag Andersen <danders@get2net.dk>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation;
7
version 2 of the License.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#ifndef XMLLOADEROBJECT_H
21
#define XMLLOADEROBJECT_H
23
#include "kptproject.h"
25
#include <qdatetime.h>
27
#include <qstringlist.h>
32
class XMLLoaderObject {
34
enum Severity { None=0, Errors=1, Warnings=2, Diagnostics=3, Debug=4 };
39
m_logLevel(Diagnostics),
44
void setProject(Project *proj) { m_project = proj; }
45
Project &project() const { return *m_project; }
49
m_starttime = QDateTime::currentDateTime();
50
m_errors = m_warnings = 0;
52
addMsg(QString("Loading started at %1").arg(m_starttime.toString()));
55
m_elapsed = m_timer.elapsed();
56
addMsg(QString("Loading finished at %1, took %2").arg(QDateTime::currentDateTime().toString()).arg(formatElapsed()));
58
QDateTime lastLoaded() const { return m_starttime; }
59
int elapsed() const { return m_elapsed; }
60
QString formatElapsed() { return QString("%1 seconds").arg((double)m_elapsed/1000); }
62
void setLogLevel(Severity sev) { m_logLevel = sev; }
63
const QStringList &log() const { return m_log; }
64
void addMsg(int sev, QString msg) {
66
if (m_logLevel < sev) return;
68
if (sev == Errors) s = "ERROR";
69
else if (sev == Warnings) s = "WARNING";
70
else if (sev == Diagnostics) s = "Diagnostic";
71
else if (sev == Debug) s = "Debug";
73
m_log<<QString("%1: %2").arg(s, 13).arg(msg);
75
void addMsg(QString msg) { m_log<<msg; }
76
void increment(int sev) {
77
if (sev == Errors) { incErrors(); return; }
78
if (sev == Warnings) { incWarnings(); return; }
80
void incErrors() { ++m_errors; }
81
int errors() const { return m_errors; }
82
bool error() const { return m_errors > 0; }
83
void incWarnings() { ++m_warnings; }
84
int warnings() const { return m_warnings; }
85
bool warning() const { return m_warnings > 0; }
93
QDateTime m_starttime;