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 !!!
73 if (ti->getType()!=TreeItem::MapCenter)
74 qWarning ("parseFreeMindHandler::startElement no mapCenter!!");
76 //cout <<"model="<<model<<" first="<<model->first()<<endl;
78 lastBranchItem=model->createBranch(lastBranchItem);
80 //FIXME-3 lastBranch->move2RelPos (200,0);
81 lastBranchItem->setHeading (" ");
82 //FIXME-3 lastBranch->move2RelPos (-200,0);
83 lastBranchItem->setHeading (" ");
84 lastBranchItem=(BranchItem*)lastBranchItem->parent();
86 } else if ( eName == "node" && (state == StateMap || state == StateNode ))
88 if (!atts.value( "POSITION").isEmpty() )
90 if (atts.value ("POSITION")=="left")
92 model->select ("bo:1");
93 lastBranchItem=model->getSelectedBranchItem();
96 lastBranchItem=model->createBranch(lastBranchItem);
99 } else if (atts.value ("POSITION")=="right")
101 model->select ("bo:0");
102 lastBranchItem=model->getSelectedBranchItem();
105 lastBranchItem=model->createBranch(lastBranchItem);
113 lastBranchItem=model->createBranch(lastBranchItem);
118 } else if ( eName == "font" && state == StateNode)
121 } else if ( eName == "edge" && state == StateNode)
124 } else if ( eName == "hook" && state == StateNode)
127 } else if ( eName == "icon" && state == StateNode)
130 if (!atts.value("BUILTIN").isEmpty() )
132 QString f=atts.value("BUILTIN");
136 else if (f=="messagebox_warning")
137 v="freemind-warning";
140 else if (f=="button_ok")
142 else if (f=="button_cancel")
144 else if (f.contains("full-"))
145 v=f.replace("full-","freemind-priority-");
148 else if (f=="forward")
149 v="freemind-forward";
150 else if (f=="attach")
152 else if (f=="ksmiletris")
154 else if (f=="clanbomber")
155 v="freemind-clanbomber";
156 else if (f=="desktop_new")
157 v="freemind-desktopnew";
160 else if (f=="gohome")
162 else if (f=="kaddressbook")
163 v="freemind-kaddressbook";
164 else if (f=="knotify")
165 v="freemind-knotify";
170 else if (f=="password")
171 v="freemind-password";
172 else if (f=="pencil")
176 else if (f=="wizard")
182 else if (f=="bookmark")
183 v="freemind-bookmark";
184 else if (f=="penguin")
185 v="freemind-penguin";
189 //FIXME-3 lastBranch->activateStandardFlag( v);
191 } else if ( eName == "arrowlink" && state == StateNode)
193 state=StateArrowLink;
194 } else if ( eName == "cloud" && state == StateNode)
197 } else if ( eName == "text" && state == StateHook)
201 return false; // Error
205 bool parseFreemindHandler::endElement ( const QString&, const QString&, const QString&)
208 cout << "endElement </" <<qPrintable(eName)
210 <<" laststate=" <<laststate
211 <<" stateStack="<<stateStack.last()
217 lastBranchItem=(BranchItem*)lastBranchItem->parent();
222 state=stateStack.takeLast();
226 bool parseFreemindHandler::characters ( const QString& ch)
228 //cout << "characters \""<<qPrintable(ch)<<"\" state="<<state <<" laststate="<<laststate<<endl;
230 QString ch_org=quotemeta (ch);
231 QString ch_simplified=ch.simplifyWhiteSpace();
232 if ( ch_simplified.isEmpty() ) return true;
236 case StateInit: break;
237 case StateMap: break;
238 case StateNode: break;
239 case StateCloud: break;
240 case StateEdge: break;
241 case StateIcon: break;
242 case StateArrowLink: break;
243 case StateFont: break;
244 case StateHook: break;
246 lastBranchItem->setNote (ch_simplified);
254 QString parseFreemindHandler::errorString()
256 return "the document is not in the Freemind file format";
259 bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a) //FIXME-3
262 //lastBranchItem=(BranchItem*)(lastBranch->getTreeItem() );
264 if (a.value( "FOLDED")=="true" )
265 lastBranchItem->toggleScroll();
267 if (!a.value( "TEXT").isEmpty() )
268 lastBranch->setHeading (a.value ("TEXT"));
270 if (!a.value( "COLOR").isEmpty() )
271 lastBranch->setColor (QColor (a.value ("COLOR")));
273 if (!a.value( "LINK").isEmpty() )
274 lastBranch->setURL (a.value ("LINK"));