1.1 --- a/vym.pro Mon Jul 30 09:47:12 2007 +0000
1.2 +++ b/vym.pro Mon Jul 30 09:47:13 2007 +0000
1.3 @@ -47,7 +47,8 @@
1.4 simplescripteditor.h\
1.5 texteditor.h \
1.6 version.h \
1.7 - xml.h \
1.8 + xml-base.h \
1.9 + xml-vym.h \
1.10 xml-freemind.h \
1.11 xsltproc.h \
1.12 settings.h \
1.13 @@ -93,7 +94,8 @@
1.14 simplescripteditor.cpp \
1.15 texteditor.cpp \
1.16 version.cpp \
1.17 - xml.cpp \
1.18 + xml-base.cpp \
1.19 + xml-vym.cpp \
1.20 xml-freemind.cpp \
1.21 xsltproc.cpp \
1.22 settings.cpp \
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/xml-base.cpp Mon Jul 30 09:47:13 2007 +0000
2.3 @@ -0,0 +1,108 @@
2.4 +#include "xml-base.h"
2.5 +
2.6 +#include <QMessageBox>
2.7 +#include <QColor>
2.8 +#include <QTextStream>
2.9 +#include <iostream>
2.10 +
2.11 +#include "misc.h"
2.12 +#include "settings.h"
2.13 +#include "linkablemapobj.h"
2.14 +#include "version.h"
2.15 +
2.16 +/*
2.17 +static BranchObj *lastBranch;
2.18 +static FloatObj *lastFloat;
2.19 +static OrnamentedObj *lastOO;
2.20 +
2.21 +extern Settings settings;
2.22 +extern QString vymVersion;
2.23 +*/
2.24 +
2.25 +parseBaseHandler::parseBaseHandler() {}
2.26 +
2.27 +parseBaseHandler::~parseBaseHandler() {}
2.28 +
2.29 +QString parseBaseHandler::errorProtocol() { return errorProt; }
2.30 +
2.31 +
2.32 +/*
2.33 +bool parseBaseHandler::startDocument()
2.34 +{
2.35 + errorProt = "";
2.36 + state = StateInit;
2.37 + laststate = StateInit;
2.38 + stateStack.clear();
2.39 + stateStack.append(StateInit);
2.40 + branchDepth=0;
2.41 + htmldata="";
2.42 + isVymPart=false;
2.43 + return true;
2.44 +}
2.45 +*/
2.46 +
2.47 +QString parseBaseHandler::parseHREF(QString href)
2.48 +{
2.49 + QString type=href.section(":",0,0);
2.50 + QString path=href.section(":",1,1);
2.51 + if (!tmpDir.endsWith("/"))
2.52 + return tmpDir + "/" + path;
2.53 + else
2.54 + return tmpDir + path;
2.55 +}
2.56 +
2.57 +
2.58 +/*
2.59 +QString parseBaseHandler::errorString()
2.60 +{
2.61 + return "the document is not in the VYM file format";
2.62 +}
2.63 +*/
2.64 +
2.65 +bool parseBaseHandler::fatalError( const QXmlParseException& exception )
2.66 +{
2.67 + errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
2.68 + .arg( exception.message() )
2.69 + .arg( exception.lineNumber() )
2.70 + .arg( exception.columnNumber() );
2.71 + // Try to read the bogus line
2.72 + errorProt+=QString("File is: %1\n").arg(inputFile);
2.73 + QString s;
2.74 + if (loadStringFromDisk (inputFile,s))
2.75 + {
2.76 + QStringList sl=QStringList::split ("\n",s);
2.77 + int i=1;
2.78 + QStringList::Iterator it = sl.begin();
2.79 + while (i<exception.lineNumber()-1)
2.80 + {
2.81 + it++;
2.82 + i++;
2.83 + }
2.84 + s=*it;
2.85 + s.insert (exception.columnNumber()-1,"<ERROR>");
2.86 + errorProt+=s;
2.87 + }
2.88 + return QXmlDefaultHandler::fatalError( exception );
2.89 +}
2.90 +
2.91 +void parseBaseHandler::setMapEditor (MapEditor* e)
2.92 +{
2.93 + me=e;
2.94 + mc=me->getMapCenter();
2.95 +}
2.96 +
2.97 +void parseBaseHandler::setTmpDir (QString tp)
2.98 +{
2.99 + tmpDir=tp;
2.100 +}
2.101 +
2.102 +void parseBaseHandler::setInputFile (QString f)
2.103 +{
2.104 + inputFile=f;
2.105 +}
2.106 +
2.107 +void parseBaseHandler::setLoadMode (const LoadMode &lm)
2.108 +{
2.109 + loadMode=lm;
2.110 +}
2.111 +
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/xml-base.h Mon Jul 30 09:47:13 2007 +0000
3.3 @@ -0,0 +1,50 @@
3.4 +#ifndef XML_BASE
3.5 +#define XML_BASE
3.6 +
3.7 +
3.8 +#include <QString>
3.9 +#include <QXmlAttributes>
3.10 +
3.11 +#include "file.h"
3.12 +#include "mapcenterobj.h"
3.13 +#include "mapeditor.h"
3.14 +
3.15 +
3.16 +/*! \brief Base class for parsing maps from XML documents */
3.17 +
3.18 +class parseBaseHandler : public QXmlDefaultHandler
3.19 +{
3.20 +public:
3.21 + parseBaseHandler();
3.22 + ~parseBaseHandler();
3.23 + QString errorProtocol();
3.24 + QString parseHREF(QString);
3.25 + virtual bool startElement ( const QString&, const QString&,
3.26 + const QString& eName, const QXmlAttributes& atts )=0;
3.27 + virtual bool endElement ( const QString&, const QString&, const QString& )=0;
3.28 + virtual bool characters ( const QString&)=0;
3.29 +
3.30 + virtual QString errorString()=0;
3.31 + bool fatalError( const QXmlParseException&);
3.32 + void setMapEditor (MapEditor*);
3.33 + void setTmpDir (QString);
3.34 + void setInputFile (QString);
3.35 + void setLoadMode (const LoadMode &);
3.36 +
3.37 +protected:
3.38 + QString errorProt;
3.39 +
3.40 + LoadMode loadMode;
3.41 + bool isVymPart;
3.42 +// State state;
3.43 +// State laststate;
3.44 +// QList <State> stateStack;
3.45 +// QString htmldata;
3.46 + int branchDepth;
3.47 +// NoteObj no;
3.48 + MapCenterObj* mc;
3.49 + MapEditor* me;
3.50 + QString tmpDir;
3.51 + QString inputFile;
3.52 +};
3.53 +#endif
4.1 --- a/xml-freemind.cpp Mon Jul 30 09:47:12 2007 +0000
4.2 +++ b/xml-freemind.cpp Mon Jul 30 09:47:13 2007 +0000
4.3 @@ -19,14 +19,7 @@
4.4
4.5 extern QString flagsPath;
4.6
4.7 -parseFMHandler::parseFMHandler() {}
4.8 -
4.9 -parseFMHandler::~parseFMHandler() {}
4.10 -
4.11 -QString parseFMHandler::errorProtocol() { return errorProt; }
4.12 -
4.13 -
4.14 -bool parseFMHandler::startDocument()
4.15 +bool parseFreemindHandler::startDocument()
4.16 {
4.17 errorProt = "";
4.18 state = StateInit;
4.19 @@ -34,13 +27,12 @@
4.20 stateStack.clear();
4.21 stateStack.append(StateInit);
4.22 branchDepth=0;
4.23 - htmldata="";
4.24 isVymPart=false;
4.25 return true;
4.26 }
4.27
4.28
4.29 -QString parseFMHandler::parseHREF(QString href)
4.30 +QString parseFreemindHandler::parseHREF(QString href)
4.31 {
4.32 QString type=href.section(":",0,0);
4.33 QString path=href.section(":",1,1);
4.34 @@ -50,7 +42,7 @@
4.35 return tmpDir + path;
4.36 }
4.37
4.38 -bool parseFMHandler::startElement ( const QString&, const QString&,
4.39 +bool parseFreemindHandler::startElement ( const QString&, const QString&,
4.40 const QString& eName, const QXmlAttributes& atts )
4.41 {
4.42 QColor col;
4.43 @@ -148,7 +140,7 @@
4.44 else if (f=="button_cancel")
4.45 v="cross-red";
4.46 else if (f.contains("full-"))
4.47 - v=f.replace("full-","freemind-priority-"); //FIXME
4.48 + v=f.replace("full-","freemind-priority-");
4.49 else if (f=="back")
4.50 v="freemind-back";
4.51 else if (f=="forward")
4.52 @@ -208,7 +200,7 @@
4.53 return true;
4.54 }
4.55
4.56 -bool parseFMHandler::endElement ( const QString&, const QString&, const QString &eName)
4.57 +bool parseFreemindHandler::endElement ( const QString&, const QString&, const QString &eName)
4.58 {
4.59 /* Testing
4.60 cout << "endElement </" <<eName.ascii()
4.61 @@ -229,7 +221,7 @@
4.62 return true;
4.63 }
4.64
4.65 -bool parseFMHandler::characters ( const QString& ch)
4.66 +bool parseFreemindHandler::characters ( const QString& ch)
4.67 {
4.68 //cout << "characters \""<<ch.ascii()<<"\" state="<<state <<" laststate="<<laststate<<endl;
4.69
4.70 @@ -257,59 +249,12 @@
4.71 return true;
4.72 }
4.73
4.74 -QString parseFMHandler::errorString()
4.75 +QString parseFreemindHandler::errorString()
4.76 {
4.77 - return "the document is not in the VYM file format";
4.78 + return "the document is not in the Freemind file format";
4.79 }
4.80
4.81 -bool parseFMHandler::fatalError( const QXmlParseException& exception )
4.82 -{
4.83 - errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
4.84 - .arg( exception.message() )
4.85 - .arg( exception.lineNumber() )
4.86 - .arg( exception.columnNumber() );
4.87 - // Try to read the bogus line
4.88 - errorProt+=QString("File is: %1\n").arg(inputFile);
4.89 - QString s;
4.90 - if (loadStringFromDisk (inputFile,s))
4.91 - {
4.92 - QStringList sl=QStringList::split ("\n",s);
4.93 - int i=1;
4.94 - QStringList::Iterator it = sl.begin();
4.95 - while (i<exception.lineNumber())
4.96 - {
4.97 - it++;
4.98 - i++;
4.99 - }
4.100 - s=*it;
4.101 - s.insert (exception.columnNumber()-1,"<ERROR>");
4.102 - errorProt+=s;
4.103 - }
4.104 - return QXmlDefaultHandler::fatalError( exception );
4.105 -}
4.106 -
4.107 -void parseFMHandler::setMapEditor (MapEditor* e)
4.108 -{
4.109 - me=e;
4.110 - mc=me->getMapCenter();
4.111 -}
4.112 -
4.113 -void parseFMHandler::setTmpDir (QString tp)
4.114 -{
4.115 - tmpDir=tp;
4.116 -}
4.117 -
4.118 -void parseFMHandler::setInputFile (QString f)
4.119 -{
4.120 - inputFile=f;
4.121 -}
4.122 -
4.123 -void parseFMHandler::setLoadMode (const LoadMode &lm)
4.124 -{
4.125 - loadMode=lm;
4.126 -}
4.127 -
4.128 -bool parseFMHandler::readNodeAttr (const QXmlAttributes& a)
4.129 +bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a)
4.130 {
4.131 lastOO=lastBranch;
4.132