summaryrefslogtreecommitdiffstats
path: root/kplato/kptxmlloaderobject.h
blob: 814af40b27acd23e8ba94b26bfacb36ac1931113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* This file is part of the KDE project
   Copyright (C) 2006 Dag Andersen <danders@get2net.dk>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation;
   version 2 of the License.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef XMLLOADEROBJECT_H
#define XMLLOADEROBJECT_H

#include "kptproject.h"

#include <tqdatetime.h>
#include <tqstring.h>
#include <tqstringlist.h>

namespace KPlato 
{

class XMLLoaderObject {
public:
    enum Severity { None=0, Errors=1, Warnings=2, Diagnostics=3, Debug=4 };
    XMLLoaderObject()
    : m_project(0),
      m_errors(0),
      m_warnings(0),
      m_logLevel(Diagnostics),
      m_log() {
    }
    ~XMLLoaderObject() {}
    
    void setProject(Project *proj) { m_project = proj; }
    Project &project() const { return *m_project; }
    
    void startLoad() {
        m_timer.start();
        m_starttime = TQDateTime::tqcurrentDateTime();
        m_errors = m_warnings = 0;
        m_log.clear();
        addMsg(TQString("Loading started at %1").tqarg(m_starttime.toString()));
    }
    void stopLoad() { 
        m_elapsed = m_timer.elapsed();
        addMsg(TQString("Loading finished at %1, took %2").tqarg(TQDateTime::tqcurrentDateTime().toString()).tqarg(formatElapsed()));
    }
    TQDateTime lastLoaded() const { return m_starttime; }
    int elapsed() const { return m_elapsed; }
    TQString formatElapsed() { return TQString("%1 seconds").tqarg((double)m_elapsed/1000); }
    
    void setLogLevel(Severity sev) { m_logLevel = sev; }
    const TQStringList &log() const { return m_log; }
    void addMsg(int sev, TQString msg) {
        increment(sev);
        if (m_logLevel < sev) return;
        TQString s;
        if (sev == Errors) s = "ERROR";
        else if (sev == Warnings) s = "WARNING";
        else if (sev == Diagnostics) s = "Diagnostic";
        else if (sev == Debug) s = "Debug";
        else s = "Message";
        m_log<<TQString("%1: %2").tqarg(s, 13).tqarg(msg);
    }
    void addMsg(TQString msg) { m_log<<msg; }
    void increment(int sev) {
        if (sev == Errors) { incErrors(); return; }
        if (sev == Warnings) { incWarnings(); return; }
    }
    void incErrors() { ++m_errors; }
    int errors() const { return m_errors; }
    bool error() const { return m_errors > 0; }
    void incWarnings() { ++m_warnings; }
    int warnings() const { return m_warnings; }
    bool warning() const { return m_warnings > 0; }

protected:
    Project *m_project;
    int m_errors;
    int m_warnings;
    int m_logLevel;
    TQStringList m_log;
    TQDateTime m_starttime;
    TQTime m_timer;
    int m_elapsed;
};

} //namespace KPlato

#endif