1 #include "xml-freemind.h"
8 #include "branchitem.h"
11 #include "linkablemapobj.h"
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 //FIXME-3 TreeItem *ti=model->first(); // this will be NULL !!!
74 if (ti->getType()==TreeItem::MapCenter)
75 bo=(BranchObj*)(ti->getLMO());
77 qWarning ("parseFreeMindHandler::startElement no mapCenter!!");
79 //cout <<"model="<<model<<" first="<<model->first()<<endl;
81 lastBranch=bo->addBranch();
83 lastBranch->move2RelPos (200,0);
84 lastBranch->setHeading (" ");
85 lastBranch=bo->addBranch();
86 lastBranch->move2RelPos (-200,0);
87 lastBranch->setHeading (" ");
90 } else if ( eName == "node" && (state == StateMap || state == StateNode ))
92 if (!atts.value( "POSITION").isEmpty() )
94 if (atts.value ("POSITION")=="left")
96 model->select ("bo:1");
97 lastBranchItem=model->getSelectedBranchItem();
100 lastBranchItem=model->createBranch();
101 lastBranch=lastBranchItem->getBranchObj();
104 } else if (atts.value ("POSITION")=="right")
106 model->select ("bo:0");
107 lastBranchItem=model->getSelectedBranchItem();
110 lastBranchItem=model->createBranch();
111 lastBranch=lastBranchItem->getBranchObj();
119 lastBranchItem=model->createBranch();
120 lastBranch=lastBranchItem->getBranchObj();
125 } else if ( eName == "font" && state == StateNode)
128 } else if ( eName == "edge" && state == StateNode)
131 } else if ( eName == "hook" && state == StateNode)
134 } else if ( eName == "icon" && state == StateNode)
137 if (!atts.value("BUILTIN").isEmpty() )
139 QString f=atts.value("BUILTIN");
143 else if (f=="messagebox_warning")
144 v="freemind-warning";
147 else if (f=="button_ok")
149 else if (f=="button_cancel")
151 else if (f.contains("full-"))
152 v=f.replace("full-","freemind-priority-");
155 else if (f=="forward")
156 v="freemind-forward";
157 else if (f=="attach")
159 else if (f=="ksmiletris")
161 else if (f=="clanbomber")
162 v="freemind-clanbomber";
163 else if (f=="desktop_new")
164 v="freemind-desktopnew";
167 else if (f=="gohome")
169 else if (f=="kaddressbook")
170 v="freemind-kaddressbook";
171 else if (f=="knotify")
172 v="freemind-knotify";
177 else if (f=="password")
178 v="freemind-password";
179 else if (f=="pencil")
183 else if (f=="wizard")
189 else if (f=="bookmark")
190 v="freemind-bookmark";
191 else if (f=="penguin")
192 v="freemind-penguin";
196 lastBranch->activateStandardFlag( v);
198 } else if ( eName == "arrowlink" && state == StateNode)
200 state=StateArrowLink;
201 } else if ( eName == "cloud" && state == StateNode)
204 } else if ( eName == "text" && state == StateHook)
208 return false; // Error
212 bool parseFreemindHandler::endElement ( const QString&, const QString&, const QString&)
215 cout << "endElement </" <<qPrintable(eName)
217 <<" laststate=" <<laststate
218 <<" stateStack="<<stateStack.last()
224 lastBranch=(BranchObj*)(lastBranch->getParObj());
229 state=stateStack.takeLast();
233 bool parseFreemindHandler::characters ( const QString& ch)
235 //cout << "characters \""<<qPrintable(ch)<<"\" state="<<state <<" laststate="<<laststate<<endl;
237 QString ch_org=quotemeta (ch);
238 QString ch_simplified=ch.simplifyWhiteSpace();
239 if ( ch_simplified.isEmpty() ) return true;
243 case StateInit: break;
244 case StateMap: break;
245 case StateNode: break;
246 case StateCloud: break;
247 case StateEdge: break;
248 case StateIcon: break;
249 case StateArrowLink: break;
250 case StateFont: break;
251 case StateHook: break;
253 lastBranch->getTreeItem()->setNote (ch_simplified);
261 QString parseFreemindHandler::errorString()
263 return "the document is not in the Freemind file format";
266 bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a)
269 lastBranchItem=(BranchItem*)(lastBranch->getTreeItem() );
271 if (a.value( "FOLDED")=="true" )
272 lastBranchItem->toggleScroll();
273 if (!a.value( "TEXT").isEmpty() )
274 lastBranch->setHeading (a.value ("TEXT"));
276 if (!a.value( "COLOR").isEmpty() )
277 lastBranch->setColor (QColor (a.value ("COLOR")));
279 if (!a.value( "LINK").isEmpty() )
280 lastBranch->setURL (a.value ("LINK"));