kplato

kptxmlloaderobject.h
1/* This file is part of the KDE project
2 Copyright (C) 2006 Dag Andersen <danders@get2net.dk>
3
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.
8
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.
13
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.
18*/
19
20#ifndef XMLLOADEROBJECT_H
21#define XMLLOADEROBJECT_H
22
23#include "kptproject.h"
24
25#include <tqdatetime.h>
26#include <tqstring.h>
27#include <tqstringlist.h>
28
29namespace KPlato
30{
31
32class XMLLoaderObject {
33public:
34 enum Severity { None=0, Errors=1, Warnings=2, Diagnostics=3, Debug=4 };
35 XMLLoaderObject()
36 : m_project(0),
37 m_errors(0),
38 m_warnings(0),
39 m_logLevel(Diagnostics),
40 m_log() {
41 }
42 ~XMLLoaderObject() {}
43
44 void setProject(Project *proj) { m_project = proj; }
45 Project &project() const { return *m_project; }
46
47 void startLoad() {
48 m_timer.start();
49 m_starttime = TQDateTime::currentDateTime();
50 m_errors = m_warnings = 0;
51 m_log.clear();
52 addMsg(TQString("Loading started at %1").arg(m_starttime.toString()));
53 }
54 void stopLoad() {
55 m_elapsed = m_timer.elapsed();
56 addMsg(TQString("Loading finished at %1, took %2").arg(TQDateTime::currentDateTime().toString()).arg(formatElapsed()));
57 }
58 TQDateTime lastLoaded() const { return m_starttime; }
59 int elapsed() const { return m_elapsed; }
60 TQString formatElapsed() { return TQString("%1 seconds").arg((double)m_elapsed/1000); }
61
62 void setLogLevel(Severity sev) { m_logLevel = sev; }
63 const TQStringList &log() const { return m_log; }
64 void addMsg(int sev, TQString msg) {
65 increment(sev);
66 if (m_logLevel < sev) return;
67 TQString s;
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";
72 else s = "Message";
73 m_log<<TQString("%1: %2").arg(s, 13).arg(msg);
74 }
75 void addMsg(TQString msg) { m_log<<msg; }
76 void increment(int sev) {
77 if (sev == Errors) { incErrors(); return; }
78 if (sev == Warnings) { incWarnings(); return; }
79 }
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; }
86
87protected:
88 Project *m_project;
89 int m_errors;
90 int m_warnings;
91 int m_logLevel;
92 TQStringList m_log;
93 TQDateTime m_starttime;
94 TQTime m_timer;
95 int m_elapsed;
96};
97
98} //namespace KPlato
99
100#endif