~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kplato/kptxmlloaderobject.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <qdatetime.h>
 
26
#include <qstring.h>
 
27
#include <qstringlist.h>
 
28
 
 
29
namespace KPlato 
 
30
{
 
31
 
 
32
class XMLLoaderObject {
 
33
public:
 
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 = QDateTime::currentDateTime();
 
50
        m_errors = m_warnings = 0;
 
51
        m_log.clear();
 
52
        addMsg(QString("Loading started at %1").arg(m_starttime.toString()));
 
53
    }
 
54
    void stopLoad() { 
 
55
        m_elapsed = m_timer.elapsed();
 
56
        addMsg(QString("Loading finished at %1, took %2").arg(QDateTime::currentDateTime().toString()).arg(formatElapsed()));
 
57
    }
 
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); }
 
61
    
 
62
    void setLogLevel(Severity sev) { m_logLevel = sev; }
 
63
    const QStringList &log() const { return m_log; }
 
64
    void addMsg(int sev, QString msg) {
 
65
        increment(sev);
 
66
        if (m_logLevel < sev) return;
 
67
        QString 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<<QString("%1: %2").arg(s, 13).arg(msg);
 
74
    }
 
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; }
 
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
 
 
87
protected:
 
88
    Project *m_project;
 
89
    int m_errors;
 
90
    int m_warnings;
 
91
    int m_logLevel;
 
92
    QStringList m_log;
 
93
    QDateTime m_starttime;
 
94
    QTime m_timer;
 
95
    int m_elapsed;
 
96
};
 
97
 
 
98
} //namespace KPlato
 
99
 
 
100
#endif