xml-base.cpp
author insilmaril
Mon, 22 Oct 2007 09:50:03 +0000
changeset 607 53c66cb9f5bd
parent 574 56fa27b2be3e
child 646 371945eb6d31
permissions -rw-r--r--
Various patches: Better windows support, branch sorting, Freedesktop support
insilmaril@574
     1
#include "xml-base.h"
insilmaril@574
     2
insilmaril@574
     3
#include <QMessageBox>
insilmaril@574
     4
#include <QColor>
insilmaril@574
     5
#include <QTextStream>
insilmaril@574
     6
#include <iostream>
insilmaril@574
     7
insilmaril@574
     8
#include "misc.h"
insilmaril@574
     9
#include "settings.h"
insilmaril@574
    10
#include "linkablemapobj.h"
insilmaril@574
    11
#include "version.h"
insilmaril@574
    12
insilmaril@574
    13
/*
insilmaril@574
    14
static BranchObj *lastBranch;
insilmaril@574
    15
static FloatObj *lastFloat;
insilmaril@574
    16
static OrnamentedObj *lastOO;
insilmaril@574
    17
insilmaril@574
    18
extern Settings settings;
insilmaril@574
    19
extern QString vymVersion;
insilmaril@574
    20
*/
insilmaril@574
    21
insilmaril@574
    22
parseBaseHandler::parseBaseHandler() {}
insilmaril@574
    23
insilmaril@574
    24
parseBaseHandler::~parseBaseHandler() {}
insilmaril@574
    25
insilmaril@574
    26
QString parseBaseHandler::errorProtocol() { return errorProt; }
insilmaril@574
    27
insilmaril@574
    28
insilmaril@574
    29
/*
insilmaril@574
    30
bool parseBaseHandler::startDocument()
insilmaril@574
    31
{
insilmaril@574
    32
    errorProt = "";
insilmaril@574
    33
    state = StateInit;
insilmaril@574
    34
    laststate = StateInit;
insilmaril@574
    35
	stateStack.clear();
insilmaril@574
    36
	stateStack.append(StateInit);
insilmaril@574
    37
    branchDepth=0;
insilmaril@574
    38
	htmldata="";
insilmaril@574
    39
	isVymPart=false;
insilmaril@574
    40
    return true;
insilmaril@574
    41
}
insilmaril@574
    42
*/
insilmaril@574
    43
insilmaril@574
    44
QString parseBaseHandler::parseHREF(QString href)
insilmaril@574
    45
{
insilmaril@574
    46
	QString type=href.section(":",0,0);
insilmaril@574
    47
	QString path=href.section(":",1,1);
insilmaril@574
    48
	if (!tmpDir.endsWith("/"))
insilmaril@574
    49
		return tmpDir + "/" + path;
insilmaril@574
    50
	else	
insilmaril@574
    51
		return tmpDir + path;
insilmaril@574
    52
}
insilmaril@574
    53
insilmaril@574
    54
insilmaril@574
    55
/*
insilmaril@574
    56
QString parseBaseHandler::errorString() 
insilmaril@574
    57
{
insilmaril@574
    58
    return "the document is not in the VYM file format";
insilmaril@574
    59
}
insilmaril@574
    60
*/
insilmaril@574
    61
insilmaril@574
    62
bool parseBaseHandler::fatalError( const QXmlParseException& exception ) 
insilmaril@574
    63
{
insilmaril@574
    64
    errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
insilmaril@574
    65
    .arg( exception.message() )
insilmaril@574
    66
    .arg( exception.lineNumber() )
insilmaril@574
    67
    .arg( exception.columnNumber() );
insilmaril@574
    68
	// Try to read the bogus line
insilmaril@574
    69
	errorProt+=QString("File is: %1\n").arg(inputFile);
insilmaril@574
    70
	QString s;
insilmaril@574
    71
	if (loadStringFromDisk (inputFile,s))
insilmaril@574
    72
	{
insilmaril@574
    73
		QStringList sl=QStringList::split ("\n",s);
insilmaril@574
    74
		int i=1;
insilmaril@574
    75
		QStringList::Iterator it = sl.begin();
insilmaril@574
    76
		while (i<exception.lineNumber()-1)
insilmaril@574
    77
		{
insilmaril@574
    78
			it++;
insilmaril@574
    79
			i++;
insilmaril@574
    80
		}
insilmaril@574
    81
		s=*it;
insilmaril@574
    82
		s.insert (exception.columnNumber()-1,"<ERROR>");
insilmaril@574
    83
		errorProt+=s;
insilmaril@574
    84
    }
insilmaril@574
    85
    return QXmlDefaultHandler::fatalError( exception );
insilmaril@574
    86
}
insilmaril@574
    87
insilmaril@574
    88
void parseBaseHandler::setMapEditor (MapEditor* e)
insilmaril@574
    89
{
insilmaril@574
    90
    me=e;
insilmaril@574
    91
	mc=me->getMapCenter();
insilmaril@574
    92
}
insilmaril@574
    93
insilmaril@574
    94
void parseBaseHandler::setTmpDir (QString tp)
insilmaril@574
    95
{
insilmaril@574
    96
	tmpDir=tp;
insilmaril@574
    97
}
insilmaril@574
    98
insilmaril@574
    99
void parseBaseHandler::setInputFile (QString f)
insilmaril@574
   100
{
insilmaril@574
   101
	inputFile=f;
insilmaril@574
   102
}
insilmaril@574
   103
insilmaril@574
   104
void parseBaseHandler::setLoadMode (const LoadMode &lm)
insilmaril@574
   105
{
insilmaril@574
   106
	loadMode=lm;
insilmaril@574
   107
}
insilmaril@574
   108