summaryrefslogtreecommitdiff
path: root/core/pim/datebook/holiday/national/nationalcfg.cpp
Side-by-side diff
Diffstat (limited to 'core/pim/datebook/holiday/national/nationalcfg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/holiday/national/nationalcfg.cpp11
1 files changed, 2 insertions, 9 deletions
diff --git a/core/pim/datebook/holiday/national/nationalcfg.cpp b/core/pim/datebook/holiday/national/nationalcfg.cpp
index a293251..52c453f 100644
--- a/core/pim/datebook/holiday/national/nationalcfg.cpp
+++ b/core/pim/datebook/holiday/national/nationalcfg.cpp
@@ -4,115 +4,109 @@
#include <qfile.h>
static QString _key_desc="description";
static QString _key_doc="nationaldays";
static QString _key_list="entries";
static QString _key_entry="entry";
static QString _content_name="name";
static QString _content_date="date";
NHcfg::NHcfg()
:QXmlDefaultHandler(),err(""),_path("")
{
}
NHcfg::~NHcfg()
{
}
bool NHcfg::load(const QString&aPath)
{
_path=aPath;
stage = 0;
_content.clear();
- odebug << "Start loading file "<<_path<<oendl;
QFile *f=new QFile(_path);
if (!f) {
oerr << "Could not open file" << oendl;
return false;
}
- odebug << "Source" << oendl;
QXmlInputSource is(*f);
- odebug << "Reader" << oendl;
QXmlSimpleReader reader;
- odebug << "Handler" << oendl;
reader.setContentHandler(this);
- odebug << "Error handler" << oendl;
reader.setErrorHandler(this);
err = "";
- odebug << "parse it" << oendl;
bool ret = reader.parse(is);
- odebug << "Errors: " << err << oendl;
+ if (err.length()>0)
+ odebug << "Errors: " << err << oendl;
return ret;
}
const tholidaylist&NHcfg::days()const
{
return _content;
}
bool NHcfg::warning(const QXmlParseException& e)
{
QString tmp;
tmp.sprintf("%d: warning: %s\n", e.lineNumber(),
(const char*) e.message().utf8());
err += tmp;
return true;
}
bool NHcfg::error(const QXmlParseException& e)
{
QString tmp;
tmp.sprintf("%d: error: %s\n", e.lineNumber(),
(const char*) e.message().utf8());
err += tmp;
return true;
}
bool NHcfg::fatalError(const QXmlParseException& e)
{
QString tmp;
tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(),
(const char*) e.message().utf8());
err += tmp;
return false;
}
bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr)
{
bool ret = false;
- odebug << "startElement: " << name << oendl;
if (name==_key_doc) {
stage = 1;
return true;
}
if (stage == 0) {
err = "This is not a national holiday config file";
return false;
}
if (name==_key_desc) {
stage = 2;
ret = setName(attr);
return ret;
}
if (stage<2) {return false;}
if (name==_key_list) {stage=3;return true;}
if (stage<3) {return false;}
return parsevalue(name,attr);
}
bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr)
{
int nindex = attr.index(_content_name);
int dindex = attr.index(_content_date);
if (name != _key_entry) {err = "Not a valid entry"; return false;}
@@ -123,27 +117,26 @@ bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr)
if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;}
QDate d(0,e[0].toInt(),e[1].toInt());
odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl;
_content[d].append(txt);
return true;
}
bool NHcfg::endElement(const QString&, const QString&,const QString& name)
{
return true;
}
const QString&NHcfg::errorString()const
{
return err;
}
bool NHcfg::setName(const QXmlAttributes&attr)
{
int nindx = attr.index("value");
if (nindx==-1) {
return false;
}
_contentname = attr.value(nindx);
- odebug << "Contentname = " << _contentname<<oendl;
return true;
}