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 lastBranchItem=model->createBranch();
83 //FIXME-3 lastBranch->move2RelPos (200,0);
84 lastBranchItem->setHeading (" ");
85 //FIXME-3 lastBranch->move2RelPos (-200,0);
86 lastBranchItem->setHeading (" ");
87 lastBranchItem=(BranchItem*)lastBranchItem->parent();
89 } else if ( eName == "node" && (state == StateMap || state == StateNode ))
91 if (!atts.value( "POSITION").isEmpty() )
93 if (atts.value ("POSITION")=="left")
95 model->select ("bo:1");
96 lastBranchItem=model->getSelectedBranchItem();
99 lastBranchItem=model->createBranch();
102 } else if (atts.value ("POSITION")=="right")
104 model->select ("bo:0");
105 lastBranchItem=model->getSelectedBranchItem();
108 lastBranchItem=model->createBranch();
116 lastBranchItem=model->createBranch();
121 } else if ( eName == "font" && state == StateNode)
124 } else if ( eName == "edge" && state == StateNode)
127 } else if ( eName == "hook" && state == StateNode)
130 } else if ( eName == "icon" && state == StateNode)
133 if (!atts.value("BUILTIN").isEmpty() )
135 QString f=atts.value("BUILTIN");
139 else if (f=="messagebox_warning")
140 v="freemind-warning";
143 else if (f=="button_ok")
145 else if (f=="button_cancel")
147 else if (f.contains("full-"))
148 v=f.replace("full-","freemind-priority-");
151 else if (f=="forward")
152 v="freemind-forward";
153 else if (f=="attach")
155 else if (f=="ksmiletris")
157 else if (f=="clanbomber")
158 v="freemind-clanbomber";
159 else if (f=="desktop_new")
160 v="freemind-desktopnew";
163 else if (f=="gohome")
165 else if (f=="kaddressbook")
166 v="freemind-kaddressbook";
167 else if (f=="knotify")
168 v="freemind-knotify";
173 else if (f=="password")
174 v="freemind-password";
175 else if (f=="pencil")
179 else if (f=="wizard")
185 else if (f=="bookmark")
186 v="freemind-bookmark";
187 else if (f=="penguin")
188 v="freemind-penguin";
192 //FIXME-3 lastBranch->activateStandardFlag( v);
194 } else if ( eName == "arrowlink" && state == StateNode)
196 state=StateArrowLink;
197 } else if ( eName == "cloud" && state == StateNode)
200 } else if ( eName == "text" && state == StateHook)
204 return false; // Error
208 bool parseFreemindHandler::endElement ( const QString&, const QString&, const QString&)
211 cout << "endElement </" <<qPrintable(eName)
213 <<" laststate=" <<laststate
214 <<" stateStack="<<stateStack.last()
220 lastBranchItem=(BranchItem*)lastBranchItem->parent();
225 state=stateStack.takeLast();
229 bool parseFreemindHandler::characters ( const QString& ch)
231 //cout << "characters \""<<qPrintable(ch)<<"\" state="<<state <<" laststate="<<laststate<<endl;
233 QString ch_org=quotemeta (ch);
234 QString ch_simplified=ch.simplifyWhiteSpace();
235 if ( ch_simplified.isEmpty() ) return true;
239 case StateInit: break;
240 case StateMap: break;
241 case StateNode: break;
242 case StateCloud: break;
243 case StateEdge: break;
244 case StateIcon: break;
245 case StateArrowLink: break;
246 case StateFont: break;
247 case StateHook: break;
249 lastBranchItem->setNote (ch_simplified);
257 QString parseFreemindHandler::errorString()
259 return "the document is not in the Freemind file format";
262 bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a) //FIXME-3
265 //lastBranchItem=(BranchItem*)(lastBranch->getTreeItem() );
267 if (a.value( "FOLDED")=="true" )
268 lastBranchItem->toggleScroll();
270 if (!a.value( "TEXT").isEmpty() )
271 lastBranch->setHeading (a.value ("TEXT"));
273 if (!a.value( "COLOR").isEmpty() )
274 lastBranch->setColor (QColor (a.value ("COLOR")));
276 if (!a.value( "LINK").isEmpty() )
277 lastBranch->setURL (a.value ("LINK"));