You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.2 KiB
101 lines
3.2 KiB
/* 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::currentDateTime();
|
|
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::currentDateTime().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
|