1 #include "xml-freemind.h"
10 #include "linkablemapobj.h"
13 static BranchObj *lastBranch;
14 static FloatObj *lastFloat;
15 static OrnamentedObj *lastOO;
17 extern Settings settings;
18 extern QString vymVersion;
20 extern QString flagsPath;
22 parseFMHandler::parseFMHandler() {}
24 parseFMHandler::~parseFMHandler() {}
26 QString parseFMHandler::errorProtocol() { return errorProt; }
29 bool parseFMHandler::startDocument()
33 laststate = StateInit;
35 stateStack.append(StateInit);
43 QString parseFMHandler::parseHREF(QString href)
45 QString type=href.section(":",0,0);
46 QString path=href.section(":",1,1);
47 if (!tmpDir.endsWith("/"))
48 return tmpDir + "/" + path;
53 bool parseFMHandler::startElement ( const QString&, const QString&,
54 const QString& eName, const QXmlAttributes& atts )
58 cout << "startElement <"<< eName.ascii()
60 <<" laststate="<<stateStack.last()
61 <<" loadMode="<<loadMode
62 // <<" line="<<QXmlDefaultHandler::lineNumber().ascii()
65 stateStack.append (state);
66 if ( state == StateInit && (eName == "map") )
69 if (!atts.value( "version").isEmpty() )
72 if (!checkVersion(atts.value("version"),v))
73 QMessageBox::warning( 0, "Warning: Version Problem" ,
74 "<h3>Freemind map is newer than version " +v +" </h3>"
75 "<p>The map you are just trying to load was "
76 "saved using freemind " +atts.value("version")+". "
77 "The version of this vym can parse freemind " + v +".");
80 lastBranch=mc->getLastBranch();
81 lastBranch->move2RelPos (200,0);
82 lastBranch->setHeading (" ");
84 lastBranch=mc->getLastBranch();
85 lastBranch->move2RelPos (-200,0);
86 lastBranch->setHeading (" ");
89 } else if ( eName == "node" && (state == StateMap || state == StateNode ))
91 if (!atts.value( "POSITION").isEmpty() )
93 if (atts.value ("POSITION")=="left")
96 lastBranch=me->getSelectedBranch();
99 lastBranch->addBranch();
100 lastBranch=lastBranch->getLastBranch();
103 } else if (atts.value ("POSITION")=="right")
106 lastBranch=me->getSelectedBranch();
109 lastBranch->addBranch();
110 lastBranch=lastBranch->getLastBranch();
118 lastBranch->addBranch();
119 lastBranch=lastBranch->getLastBranch();
124 } else if ( eName == "font" && state == StateNode)
127 } else if ( eName == "edge" && state == StateNode)
130 } else if ( eName == "hook" && state == StateNode)
133 } else if ( eName == "icon" && state == StateNode)
136 if (!atts.value("BUILTIN").isEmpty() )
138 QString f=atts.value("BUILTIN");
142 else if (f=="messagebox_warning")
143 v="freemind-warning";
146 else if (f=="button_ok")
148 else if (f=="button_cancel")
150 else if (f.contains("full-"))
151 v=f.replace("full-","freemind-priority-"); //FIXME
154 else if (f=="forward")
155 v="freemind-forward";
156 else if (f=="attach")
158 else if (f=="ksmiletris")
160 else if (f=="clanbomber")
161 v="freemind-clanbomber";
162 else if (f=="desktop_new")
163 v="freemind-desktopnew";
166 else if (f=="gohome")
168 else if (f=="kaddressbook")
169 v="freemind-kaddressbook";
170 else if (f=="knotify")
171 v="freemind-knotify";
176 else if (f=="password")
177 v="freemind-password";
178 else if (f=="pencil")
182 else if (f=="wizard")
188 else if (f=="bookmark")
189 v="freemind-bookmark";
190 else if (f=="penguin")
191 v="freemind-penguin";
195 lastBranch->activateStandardFlag( v);
197 } else if ( eName == "arrowlink" && state == StateNode)
199 state=StateArrowLink;
200 } else if ( eName == "cloud" && state == StateNode)
203 } else if ( eName == "text" && state == StateHook)
207 return false; // Error
211 bool parseFMHandler::endElement ( const QString&, const QString&, const QString &eName)
214 cout << "endElement </" <<eName.ascii()
216 <<" laststate=" <<laststate
217 <<" stateStack="<<stateStack.last()
223 lastBranch=(BranchObj*)(lastBranch->getParObj());
228 state=stateStack.takeLast();
232 bool parseFMHandler::characters ( const QString& ch)
234 //cout << "characters \""<<ch.ascii()<<"\" state="<<state <<" laststate="<<laststate<<endl;
236 QString ch_org=quotemeta (ch);
237 QString ch_simplified=ch.simplifyWhiteSpace();
238 if ( ch_simplified.isEmpty() ) return true;
242 case StateInit: break;
243 case StateMap: break;
244 case StateNode: break;
245 case StateCloud: break;
246 case StateEdge: break;
247 case StateIcon: break;
248 case StateArrowLink: break;
249 case StateFont: break;
250 case StateHook: break;
252 lastBranch->setNote (ch_simplified);
260 QString parseFMHandler::errorString()
262 return "the document is not in the VYM file format";
265 bool parseFMHandler::fatalError( const QXmlParseException& exception )
267 errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
268 .arg( exception.message() )
269 .arg( exception.lineNumber() )
270 .arg( exception.columnNumber() );
271 // Try to read the bogus line
272 errorProt+=QString("File is: %1\n").arg(inputFile);
274 if (loadStringFromDisk (inputFile,s))
276 QStringList sl=QStringList::split ("\n",s);
278 QStringList::Iterator it = sl.begin();
279 while (i<exception.lineNumber())
285 s.insert (exception.columnNumber()-1,"<ERROR>");
288 return QXmlDefaultHandler::fatalError( exception );
291 void parseFMHandler::setMapEditor (MapEditor* e)
294 mc=me->getMapCenter();
297 void parseFMHandler::setTmpDir (QString tp)
302 void parseFMHandler::setInputFile (QString f)
307 void parseFMHandler::setLoadMode (const LoadMode &lm)
312 bool parseFMHandler::readNodeAttr (const QXmlAttributes& a)
316 if (a.value( "FOLDED")=="true" )
317 lastBranch->toggleScroll();
318 if (!a.value( "TEXT").isEmpty() )
319 lastBranch->setHeading (a.value ("TEXT"));
321 if (!a.value( "COLOR").isEmpty() )
322 lastBranch->setColor (QColor (a.value ("COLOR")));
324 if (!a.value( "LINK").isEmpty() )
325 lastBranch->setURL (a.value ("LINK"));