1 #include "xml-freemind.h"
8 #include "branchitem.h"
11 #include "linkablemapobj.h"
14 //static FloatObj *lastFloat;
16 extern Settings settings;
17 extern QString vymVersion;
19 extern QString flagsPath;
21 bool parseFreemindHandler::startDocument()
25 laststate = StateInit;
27 stateStack.append(StateInit);
33 QString parseFreemindHandler::parseHREF(QString href)
35 QString type=href.section(":",0,0);
36 QString path=href.section(":",1,1);
37 if (!tmpDir.endsWith("/"))
38 return tmpDir + "/" + path;
43 bool parseFreemindHandler::startElement ( const QString&, const QString&,
44 const QString& eName, const QXmlAttributes& atts )
48 cout << "startElement <"<< qPrintable(eName)
50 <<" laststate="<<stateStack.last()
51 <<" loadMode="<<loadMode
52 // <<" line="<<qPrintable (QXmlDefaultHandler::lineNumber())
55 stateStack.append (state);
56 if ( state == StateInit && (eName == "map") )
59 if (!atts.value( "version").isEmpty() )
62 if (!checkVersion(atts.value("version"),v))
63 QMessageBox::warning( 0, "Warning: Version Problem" ,
64 "<h3>Freemind map is newer than version " +v +" </h3>"
65 "<p>The map you are just trying to load was "
66 "saved using freemind " +atts.value("version")+". "
67 "The version of this vym can parse freemind " + v +".");
69 //FIXME-3 TreeItem *ti=model->first(); // this will be NULL !!!
72 if (ti->getType()!=TreeItem::MapCenter)
73 qWarning ("parseFreeMindHandler::startElement no mapCenter!!");
75 //cout <<"model="<<model<<" first="<<model->first()<<endl;
77 lastBranchItem=model->createBranch(lastBranchItem);
79 //FIXME-3 lastBranch->move2RelPos (200,0);
80 lastBranchItem->setHeading (" ");
81 //FIXME-3 lastBranch->move2RelPos (-200,0);
82 lastBranchItem->setHeading (" ");
83 lastBranchItem=(BranchItem*)lastBranchItem->parent();
85 } else if ( eName == "node" && (state == StateMap || state == StateNode ))
87 if (!atts.value( "POSITION").isEmpty() )
89 if (atts.value ("POSITION")=="left")
91 model->select ("bo:1");
92 lastBranchItem=model->getSelectedBranch();
95 lastBranchItem=model->createBranch(lastBranchItem);
98 } else if (atts.value ("POSITION")=="right")
100 model->select ("bo:0");
101 lastBranchItem=model->getSelectedBranch();
104 lastBranchItem=model->createBranch(lastBranchItem);
112 lastBranchItem=model->createBranch(lastBranchItem);
117 } else if ( eName == "font" && state == StateNode)
120 } else if ( eName == "edge" && state == StateNode)
123 } else if ( eName == "hook" && state == StateNode)
126 } else if ( eName == "icon" && state == StateNode)
129 if (!atts.value("BUILTIN").isEmpty() )
131 QString f=atts.value("BUILTIN");
135 else if (f=="messagebox_warning")
136 v="freemind-warning";
139 else if (f=="button_ok")
141 else if (f=="button_cancel")
143 else if (f.contains("full-"))
144 v=f.replace("full-","freemind-priority-");
147 else if (f=="forward")
148 v="freemind-forward";
149 else if (f=="attach")
151 else if (f=="ksmiletris")
153 else if (f=="clanbomber")
154 v="freemind-clanbomber";
155 else if (f=="desktop_new")
156 v="freemind-desktopnew";
159 else if (f=="gohome")
161 else if (f=="kaddressbook")
162 v="freemind-kaddressbook";
163 else if (f=="knotify")
164 v="freemind-knotify";
169 else if (f=="password")
170 v="freemind-password";
171 else if (f=="pencil")
175 else if (f=="wizard")
181 else if (f=="bookmark")
182 v="freemind-bookmark";
183 else if (f=="penguin")
184 v="freemind-penguin";
188 //FIXME-3 lastBranch->activateStandardFlag( v);
190 } else if ( eName == "arrowlink" && state == StateNode)
192 state=StateArrowLink;
193 } else if ( eName == "cloud" && state == StateNode)
196 } else if ( eName == "text" && state == StateHook)
200 return false; // Error
204 bool parseFreemindHandler::endElement ( const QString&, const QString&, const QString&)
207 cout << "endElement </" <<qPrintable(eName)
209 <<" laststate=" <<laststate
210 <<" stateStack="<<stateStack.last()
216 lastBranchItem=(BranchItem*)lastBranchItem->parent();
221 state=stateStack.takeLast();
225 bool parseFreemindHandler::characters ( const QString& ch)
227 //cout << "characters \""<<qPrintable(ch)<<"\" state="<<state <<" laststate="<<laststate<<endl;
229 QString ch_org=quotemeta (ch);
230 QString ch_simplified=ch.simplifyWhiteSpace();
231 if ( ch_simplified.isEmpty() ) return true;
235 case StateInit: break;
236 case StateMap: break;
237 case StateNode: break;
238 case StateCloud: break;
239 case StateEdge: break;
240 case StateIcon: break;
241 case StateArrowLink: break;
242 case StateFont: break;
243 case StateHook: break;
245 lastBranchItem->setNote (ch_simplified);
253 QString parseFreemindHandler::errorString()
255 return "the document is not in the Freemind file format";
258 bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a) //FIXME-3
260 //lastBranchItem=(BranchItem*)(lastBranch->getTreeItem() );
262 if (a.value( "FOLDED")=="true" )
263 lastBranchItem->toggleScroll();
265 if (!a.value( "TEXT").isEmpty() )
266 lastBranch->setHeading (a.value ("TEXT"));
268 if (!a.value( "COLOR").isEmpty() )
269 lastBranch->setColor (QColor (a.value ("COLOR")));
271 if (!a.value( "LINK").isEmpty() )
272 lastBranch->setURL (a.value ("LINK"));