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);
35 QString parseFreemindHandler::parseHREF(QString href)
37 QString type=href.section(":",0,0);
38 QString path=href.section(":",1,1);
39 if (!tmpDir.endsWith("/"))
40 return tmpDir + "/" + path;
45 bool parseFreemindHandler::startElement ( const QString&, const QString&,
46 const QString& eName, const QXmlAttributes& atts )
50 cout << "startElement <"<< eName.ascii()
52 <<" laststate="<<stateStack.last()
53 <<" loadMode="<<loadMode
54 // <<" line="<<QXmlDefaultHandler::lineNumber().ascii()
57 stateStack.append (state);
58 if ( state == StateInit && (eName == "map") )
61 if (!atts.value( "version").isEmpty() )
64 if (!checkVersion(atts.value("version"),v))
65 QMessageBox::warning( 0, "Warning: Version Problem" ,
66 "<h3>Freemind map is newer than version " +v +" </h3>"
67 "<p>The map you are just trying to load was "
68 "saved using freemind " +atts.value("version")+". "
69 "The version of this vym can parse freemind " + v +".");
71 model->first()->addBranch();
72 lastBranch=model->first()->getLastBranch();
73 lastBranch->move2RelPos (200,0);
74 lastBranch->setHeading (" ");
75 model->first()->addBranch();
76 lastBranch=model->first()->getLastBranch();
77 lastBranch->move2RelPos (-200,0);
78 lastBranch->setHeading (" ");
79 lastBranch=model->first();
81 } else if ( eName == "node" && (state == StateMap || state == StateNode ))
83 if (!atts.value( "POSITION").isEmpty() )
85 if (atts.value ("POSITION")=="left")
87 model->select ("bo:1");
88 lastBranch=model->getSelectedBranch();
91 lastBranch->addBranch();
92 lastBranch=lastBranch->getLastBranch();
95 } else if (atts.value ("POSITION")=="right")
97 model->select ("bo:0");
98 lastBranch=model->getSelectedBranch();
101 lastBranch->addBranch();
102 lastBranch=lastBranch->getLastBranch();
110 lastBranch->addBranch();
111 lastBranch=lastBranch->getLastBranch();
116 } else if ( eName == "font" && state == StateNode)
119 } else if ( eName == "edge" && state == StateNode)
122 } else if ( eName == "hook" && state == StateNode)
125 } else if ( eName == "icon" && state == StateNode)
128 if (!atts.value("BUILTIN").isEmpty() )
130 QString f=atts.value("BUILTIN");
134 else if (f=="messagebox_warning")
135 v="freemind-warning";
138 else if (f=="button_ok")
140 else if (f=="button_cancel")
142 else if (f.contains("full-"))
143 v=f.replace("full-","freemind-priority-");
146 else if (f=="forward")
147 v="freemind-forward";
148 else if (f=="attach")
150 else if (f=="ksmiletris")
152 else if (f=="clanbomber")
153 v="freemind-clanbomber";
154 else if (f=="desktop_new")
155 v="freemind-desktopnew";
158 else if (f=="gohome")
160 else if (f=="kaddressbook")
161 v="freemind-kaddressbook";
162 else if (f=="knotify")
163 v="freemind-knotify";
168 else if (f=="password")
169 v="freemind-password";
170 else if (f=="pencil")
174 else if (f=="wizard")
180 else if (f=="bookmark")
181 v="freemind-bookmark";
182 else if (f=="penguin")
183 v="freemind-penguin";
187 lastBranch->activateStandardFlag( v);
189 } else if ( eName == "arrowlink" && state == StateNode)
191 state=StateArrowLink;
192 } else if ( eName == "cloud" && state == StateNode)
195 } else if ( eName == "text" && state == StateHook)
199 return false; // Error
203 bool parseFreemindHandler::endElement ( const QString&, const QString&, const QString &eName)
206 cout << "endElement </" <<eName.ascii()
208 <<" laststate=" <<laststate
209 <<" stateStack="<<stateStack.last()
215 lastBranch=(BranchObj*)(lastBranch->getParObj());
220 state=stateStack.takeLast();
224 bool parseFreemindHandler::characters ( const QString& ch)
226 //cout << "characters \""<<ch.ascii()<<"\" state="<<state <<" laststate="<<laststate<<endl;
228 QString ch_org=quotemeta (ch);
229 QString ch_simplified=ch.simplifyWhiteSpace();
230 if ( ch_simplified.isEmpty() ) return true;
234 case StateInit: break;
235 case StateMap: break;
236 case StateNode: break;
237 case StateCloud: break;
238 case StateEdge: break;
239 case StateIcon: break;
240 case StateArrowLink: break;
241 case StateFont: break;
242 case StateHook: break;
244 lastBranch->setNote (ch_simplified);
252 QString parseFreemindHandler::errorString()
254 return "the document is not in the Freemind file format";
257 bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a)
261 if (a.value( "FOLDED")=="true" )
262 lastBranch->toggleScroll();
263 if (!a.value( "TEXT").isEmpty() )
264 lastBranch->setHeading (a.value ("TEXT"));
266 if (!a.value( "COLOR").isEmpty() )
267 lastBranch->setColor (QColor (a.value ("COLOR")));
269 if (!a.value( "LINK").isEmpty() )
270 lastBranch->setURL (a.value ("LINK"));