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 bool parseFreemindHandler::startDocument()
26 laststate = StateInit;
28 stateStack.append(StateInit);
34 QString parseFreemindHandler::parseHREF(QString href)
36 QString type=href.section(":",0,0);
37 QString path=href.section(":",1,1);
38 if (!tmpDir.endsWith("/"))
39 return tmpDir + "/" + path;
44 bool parseFreemindHandler::startElement ( const QString&, const QString&,
45 const QString& eName, const QXmlAttributes& atts )
49 cout << "startElement <"<< qPrintable(eName)
51 <<" laststate="<<stateStack.last()
52 <<" loadMode="<<loadMode
53 // <<" line="<<qPrintable (QXmlDefaultHandler::lineNumber())
56 stateStack.append (state);
57 if ( state == StateInit && (eName == "map") )
60 if (!atts.value( "version").isEmpty() )
63 if (!checkVersion(atts.value("version"),v))
64 QMessageBox::warning( 0, "Warning: Version Problem" ,
65 "<h3>Freemind map is newer than version " +v +" </h3>"
66 "<p>The map you are just trying to load was "
67 "saved using freemind " +atts.value("version")+". "
68 "The version of this vym can parse freemind " + v +".");
70 model->first()->addBranch();
71 lastBranch=model->first()->getLastBranch();
72 lastBranch->move2RelPos (200,0);
73 lastBranch->setHeading (" ");
74 model->first()->addBranch();
75 lastBranch=model->first()->getLastBranch();
76 lastBranch->move2RelPos (-200,0);
77 lastBranch->setHeading (" ");
78 lastBranch=model->first();
80 } else if ( eName == "node" && (state == StateMap || state == StateNode ))
82 if (!atts.value( "POSITION").isEmpty() )
84 if (atts.value ("POSITION")=="left")
86 model->select ("bo:1");
87 lastBranch=model->getSelectedBranch();
90 lastBranch->addBranch();
91 lastBranch=lastBranch->getLastBranch();
94 } else if (atts.value ("POSITION")=="right")
96 model->select ("bo:0");
97 lastBranch=model->getSelectedBranch();
100 lastBranch->addBranch();
101 lastBranch=lastBranch->getLastBranch();
109 lastBranch->addBranch();
110 lastBranch=lastBranch->getLastBranch();
115 } else if ( eName == "font" && state == StateNode)
118 } else if ( eName == "edge" && state == StateNode)
121 } else if ( eName == "hook" && state == StateNode)
124 } else if ( eName == "icon" && state == StateNode)
127 if (!atts.value("BUILTIN").isEmpty() )
129 QString f=atts.value("BUILTIN");
133 else if (f=="messagebox_warning")
134 v="freemind-warning";
137 else if (f=="button_ok")
139 else if (f=="button_cancel")
141 else if (f.contains("full-"))
142 v=f.replace("full-","freemind-priority-");
145 else if (f=="forward")
146 v="freemind-forward";
147 else if (f=="attach")
149 else if (f=="ksmiletris")
151 else if (f=="clanbomber")
152 v="freemind-clanbomber";
153 else if (f=="desktop_new")
154 v="freemind-desktopnew";
157 else if (f=="gohome")
159 else if (f=="kaddressbook")
160 v="freemind-kaddressbook";
161 else if (f=="knotify")
162 v="freemind-knotify";
167 else if (f=="password")
168 v="freemind-password";
169 else if (f=="pencil")
173 else if (f=="wizard")
179 else if (f=="bookmark")
180 v="freemind-bookmark";
181 else if (f=="penguin")
182 v="freemind-penguin";
186 lastBranch->activateStandardFlag( v);
188 } else if ( eName == "arrowlink" && state == StateNode)
190 state=StateArrowLink;
191 } else if ( eName == "cloud" && state == StateNode)
194 } else if ( eName == "text" && state == StateHook)
198 return false; // Error
202 bool parseFreemindHandler::endElement ( const QString&, const QString&, const QString &eName)
205 cout << "endElement </" <<qPrintable(eName)
207 <<" laststate=" <<laststate
208 <<" stateStack="<<stateStack.last()
214 lastBranch=(BranchObj*)(lastBranch->getParObj());
219 state=stateStack.takeLast();
223 bool parseFreemindHandler::characters ( const QString& ch)
225 //cout << "characters \""<<qPrintable(ch)<<"\" state="<<state <<" laststate="<<laststate<<endl;
227 QString ch_org=quotemeta (ch);
228 QString ch_simplified=ch.simplifyWhiteSpace();
229 if ( ch_simplified.isEmpty() ) return true;
233 case StateInit: break;
234 case StateMap: break;
235 case StateNode: break;
236 case StateCloud: break;
237 case StateEdge: break;
238 case StateIcon: break;
239 case StateArrowLink: break;
240 case StateFont: break;
241 case StateHook: break;
243 lastBranch->setNote (ch_simplified);
251 QString parseFreemindHandler::errorString()
253 return "the document is not in the Freemind file format";
256 bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a)
260 if (a.value( "FOLDED")=="true" )
261 lastBranch->toggleScroll();
262 if (!a.value( "TEXT").isEmpty() )
263 lastBranch->setHeading (a.value ("TEXT"));
265 if (!a.value( "COLOR").isEmpty() )
266 lastBranch->setColor (QColor (a.value ("COLOR")));
268 if (!a.value( "LINK").isEmpty() )
269 lastBranch->setURL (a.value ("LINK"));