insilmaril@566
|
1 |
#include "xml-freemind.h"
|
insilmaril@566
|
2 |
|
insilmaril@566
|
3 |
#include <QMessageBox>
|
insilmaril@566
|
4 |
#include <QColor>
|
insilmaril@566
|
5 |
#include <QTextStream>
|
insilmaril@566
|
6 |
#include <iostream>
|
insilmaril@566
|
7 |
|
insilmaril@566
|
8 |
#include "misc.h"
|
insilmaril@566
|
9 |
#include "settings.h"
|
insilmaril@566
|
10 |
#include "linkablemapobj.h"
|
insilmaril@566
|
11 |
#include "version.h"
|
insilmaril@566
|
12 |
|
insilmaril@566
|
13 |
static BranchObj *lastBranch;
|
insilmaril@666
|
14 |
//static FloatObj *lastFloat;
|
insilmaril@566
|
15 |
static OrnamentedObj *lastOO;
|
insilmaril@566
|
16 |
|
insilmaril@566
|
17 |
extern Settings settings;
|
insilmaril@566
|
18 |
extern QString vymVersion;
|
insilmaril@566
|
19 |
|
insilmaril@566
|
20 |
extern QString flagsPath;
|
insilmaril@566
|
21 |
|
insilmaril@574
|
22 |
bool parseFreemindHandler::startDocument()
|
insilmaril@566
|
23 |
{
|
insilmaril@566
|
24 |
errorProt = "";
|
insilmaril@566
|
25 |
state = StateInit;
|
insilmaril@566
|
26 |
laststate = StateInit;
|
insilmaril@566
|
27 |
stateStack.clear();
|
insilmaril@566
|
28 |
stateStack.append(StateInit);
|
insilmaril@566
|
29 |
isVymPart=false;
|
insilmaril@566
|
30 |
return true;
|
insilmaril@566
|
31 |
}
|
insilmaril@566
|
32 |
|
insilmaril@566
|
33 |
|
insilmaril@574
|
34 |
QString parseFreemindHandler::parseHREF(QString href)
|
insilmaril@566
|
35 |
{
|
insilmaril@566
|
36 |
QString type=href.section(":",0,0);
|
insilmaril@566
|
37 |
QString path=href.section(":",1,1);
|
insilmaril@566
|
38 |
if (!tmpDir.endsWith("/"))
|
insilmaril@566
|
39 |
return tmpDir + "/" + path;
|
insilmaril@566
|
40 |
else
|
insilmaril@566
|
41 |
return tmpDir + path;
|
insilmaril@566
|
42 |
}
|
insilmaril@566
|
43 |
|
insilmaril@574
|
44 |
bool parseFreemindHandler::startElement ( const QString&, const QString&,
|
insilmaril@566
|
45 |
const QString& eName, const QXmlAttributes& atts )
|
insilmaril@566
|
46 |
{
|
insilmaril@566
|
47 |
QColor col;
|
insilmaril@566
|
48 |
/* Testing
|
insilmaril@660
|
49 |
cout << "startElement <"<< qPrintable(eName)
|
insilmaril@566
|
50 |
<<"> state="<<state
|
insilmaril@566
|
51 |
<<" laststate="<<stateStack.last()
|
insilmaril@566
|
52 |
<<" loadMode="<<loadMode
|
insilmaril@660
|
53 |
// <<" line="<<qPrintable (QXmlDefaultHandler::lineNumber())
|
insilmaril@566
|
54 |
<<endl;
|
insilmaril@566
|
55 |
*/
|
insilmaril@566
|
56 |
stateStack.append (state);
|
insilmaril@566
|
57 |
if ( state == StateInit && (eName == "map") )
|
insilmaril@566
|
58 |
{
|
insilmaril@566
|
59 |
state = StateMap;
|
insilmaril@566
|
60 |
if (!atts.value( "version").isEmpty() )
|
insilmaril@566
|
61 |
{
|
insilmaril@566
|
62 |
QString v="0.8.0";
|
insilmaril@566
|
63 |
if (!checkVersion(atts.value("version"),v))
|
insilmaril@566
|
64 |
QMessageBox::warning( 0, "Warning: Version Problem" ,
|
insilmaril@566
|
65 |
"<h3>Freemind map is newer than version " +v +" </h3>"
|
insilmaril@566
|
66 |
"<p>The map you are just trying to load was "
|
insilmaril@566
|
67 |
"saved using freemind " +atts.value("version")+". "
|
insilmaril@566
|
68 |
"The version of this vym can parse freemind " + v +".");
|
insilmaril@566
|
69 |
}
|
insilmaril@666
|
70 |
cout <<"model="<<model<<" first="<<model->first()<<endl;
|
insilmaril@647
|
71 |
model->first()->addBranch();
|
insilmaril@647
|
72 |
lastBranch=model->first()->getLastBranch();
|
insilmaril@566
|
73 |
lastBranch->move2RelPos (200,0);
|
insilmaril@566
|
74 |
lastBranch->setHeading (" ");
|
insilmaril@647
|
75 |
model->first()->addBranch();
|
insilmaril@647
|
76 |
lastBranch=model->first()->getLastBranch();
|
insilmaril@566
|
77 |
lastBranch->move2RelPos (-200,0);
|
insilmaril@566
|
78 |
lastBranch->setHeading (" ");
|
insilmaril@647
|
79 |
lastBranch=model->first();
|
insilmaril@566
|
80 |
|
insilmaril@566
|
81 |
} else if ( eName == "node" && (state == StateMap || state == StateNode ))
|
insilmaril@566
|
82 |
{
|
insilmaril@566
|
83 |
if (!atts.value( "POSITION").isEmpty() )
|
insilmaril@566
|
84 |
{
|
insilmaril@566
|
85 |
if (atts.value ("POSITION")=="left")
|
insilmaril@566
|
86 |
{
|
insilmaril@647
|
87 |
model->select ("bo:1");
|
insilmaril@647
|
88 |
lastBranch=model->getSelectedBranch();
|
insilmaril@566
|
89 |
if (lastBranch)
|
insilmaril@566
|
90 |
{
|
insilmaril@566
|
91 |
lastBranch->addBranch();
|
insilmaril@566
|
92 |
lastBranch=lastBranch->getLastBranch();
|
insilmaril@566
|
93 |
readNodeAttr (atts);
|
insilmaril@566
|
94 |
}
|
insilmaril@566
|
95 |
} else if (atts.value ("POSITION")=="right")
|
insilmaril@566
|
96 |
{
|
insilmaril@647
|
97 |
model->select ("bo:0");
|
insilmaril@647
|
98 |
lastBranch=model->getSelectedBranch();
|
insilmaril@566
|
99 |
if (lastBranch)
|
insilmaril@566
|
100 |
{
|
insilmaril@566
|
101 |
lastBranch->addBranch();
|
insilmaril@566
|
102 |
lastBranch=lastBranch->getLastBranch();
|
insilmaril@566
|
103 |
readNodeAttr (atts);
|
insilmaril@566
|
104 |
}
|
insilmaril@566
|
105 |
}
|
insilmaril@566
|
106 |
} else
|
insilmaril@566
|
107 |
{
|
insilmaril@566
|
108 |
if (state!=StateMap)
|
insilmaril@566
|
109 |
{
|
insilmaril@566
|
110 |
lastBranch->addBranch();
|
insilmaril@566
|
111 |
lastBranch=lastBranch->getLastBranch();
|
insilmaril@566
|
112 |
}
|
insilmaril@566
|
113 |
readNodeAttr (atts);
|
insilmaril@566
|
114 |
}
|
insilmaril@566
|
115 |
state=StateNode;
|
insilmaril@566
|
116 |
} else if ( eName == "font" && state == StateNode)
|
insilmaril@566
|
117 |
{
|
insilmaril@566
|
118 |
state=StateFont;
|
insilmaril@566
|
119 |
} else if ( eName == "edge" && state == StateNode)
|
insilmaril@566
|
120 |
{
|
insilmaril@566
|
121 |
state=StateEdge;
|
insilmaril@566
|
122 |
} else if ( eName == "hook" && state == StateNode)
|
insilmaril@566
|
123 |
{
|
insilmaril@566
|
124 |
state=StateHook;
|
insilmaril@566
|
125 |
} else if ( eName == "icon" && state == StateNode)
|
insilmaril@566
|
126 |
{
|
insilmaril@566
|
127 |
state=StateIcon;
|
insilmaril@566
|
128 |
if (!atts.value("BUILTIN").isEmpty() )
|
insilmaril@566
|
129 |
{
|
insilmaril@566
|
130 |
QString f=atts.value("BUILTIN");
|
insilmaril@566
|
131 |
QString v;
|
insilmaril@566
|
132 |
if (f=="help")
|
insilmaril@566
|
133 |
v="questionmark";
|
insilmaril@566
|
134 |
else if (f=="messagebox_warning")
|
insilmaril@566
|
135 |
v="freemind-warning";
|
insilmaril@566
|
136 |
else if (f=="idea")
|
insilmaril@566
|
137 |
v="lamp";
|
insilmaril@566
|
138 |
else if (f=="button_ok")
|
insilmaril@566
|
139 |
v="hook-green";
|
insilmaril@566
|
140 |
else if (f=="button_cancel")
|
insilmaril@566
|
141 |
v="cross-red";
|
insilmaril@566
|
142 |
else if (f.contains("full-"))
|
insilmaril@574
|
143 |
v=f.replace("full-","freemind-priority-");
|
insilmaril@566
|
144 |
else if (f=="back")
|
insilmaril@566
|
145 |
v="freemind-back";
|
insilmaril@566
|
146 |
else if (f=="forward")
|
insilmaril@566
|
147 |
v="freemind-forward";
|
insilmaril@566
|
148 |
else if (f=="attach")
|
insilmaril@566
|
149 |
v="freemind-attach";
|
insilmaril@566
|
150 |
else if (f=="ksmiletris")
|
insilmaril@566
|
151 |
v="smiley-good"; //
|
insilmaril@566
|
152 |
else if (f=="clanbomber")
|
insilmaril@566
|
153 |
v="freemind-clanbomber";
|
insilmaril@566
|
154 |
else if (f=="desktop_new")
|
insilmaril@566
|
155 |
v="freemind-desktopnew";
|
insilmaril@566
|
156 |
else if (f=="flag")
|
insilmaril@566
|
157 |
v="freemind-flag";
|
insilmaril@566
|
158 |
else if (f=="gohome")
|
insilmaril@566
|
159 |
v="freemind-gohome";
|
insilmaril@566
|
160 |
else if (f=="kaddressbook")
|
insilmaril@566
|
161 |
v="freemind-kaddressbook";
|
insilmaril@566
|
162 |
else if (f=="knotify")
|
insilmaril@566
|
163 |
v="freemind-knotify";
|
insilmaril@566
|
164 |
else if (f=="korn")
|
insilmaril@566
|
165 |
v="freemind-korn";
|
insilmaril@566
|
166 |
else if (f=="Mail")
|
insilmaril@566
|
167 |
v="freemind-mail";
|
insilmaril@566
|
168 |
else if (f=="password")
|
insilmaril@566
|
169 |
v="freemind-password";
|
insilmaril@566
|
170 |
else if (f=="pencil")
|
insilmaril@566
|
171 |
v="freemind-pencil";
|
insilmaril@566
|
172 |
else if (f=="stop")
|
insilmaril@566
|
173 |
v="freemind-stop";
|
insilmaril@566
|
174 |
else if (f=="wizard")
|
insilmaril@566
|
175 |
v="freemind-wizard";
|
insilmaril@566
|
176 |
else if (f=="xmag")
|
insilmaril@566
|
177 |
v="freemind-xmag";
|
insilmaril@566
|
178 |
else if (f=="bell")
|
insilmaril@566
|
179 |
v="freemind-bell";
|
insilmaril@566
|
180 |
else if (f=="bookmark")
|
insilmaril@566
|
181 |
v="freemind-bookmark";
|
insilmaril@566
|
182 |
else if (f=="penguin")
|
insilmaril@566
|
183 |
v="freemind-penguin";
|
insilmaril@566
|
184 |
else if (f=="licq")
|
insilmaril@566
|
185 |
v="freemind-licq";
|
insilmaril@566
|
186 |
|
insilmaril@566
|
187 |
lastBranch->activateStandardFlag( v);
|
insilmaril@566
|
188 |
}
|
insilmaril@566
|
189 |
} else if ( eName == "arrowlink" && state == StateNode)
|
insilmaril@566
|
190 |
{
|
insilmaril@566
|
191 |
state=StateArrowLink;
|
insilmaril@566
|
192 |
} else if ( eName == "cloud" && state == StateNode)
|
insilmaril@566
|
193 |
{
|
insilmaril@566
|
194 |
state=StateCloud;
|
insilmaril@566
|
195 |
} else if ( eName == "text" && state == StateHook)
|
insilmaril@566
|
196 |
{
|
insilmaril@566
|
197 |
state=StateText;
|
insilmaril@566
|
198 |
} else
|
insilmaril@566
|
199 |
return false; // Error
|
insilmaril@566
|
200 |
return true;
|
insilmaril@566
|
201 |
}
|
insilmaril@566
|
202 |
|
insilmaril@666
|
203 |
bool parseFreemindHandler::endElement ( const QString&, const QString&, const QString&)
|
insilmaril@566
|
204 |
{
|
insilmaril@566
|
205 |
/* Testing
|
insilmaril@660
|
206 |
cout << "endElement </" <<qPrintable(eName)
|
insilmaril@566
|
207 |
<<"> state=" <<state
|
insilmaril@566
|
208 |
<<" laststate=" <<laststate
|
insilmaril@566
|
209 |
<<" stateStack="<<stateStack.last()
|
insilmaril@566
|
210 |
<<endl;
|
insilmaril@566
|
211 |
*/
|
insilmaril@566
|
212 |
switch ( state )
|
insilmaril@566
|
213 |
{
|
insilmaril@566
|
214 |
case StateNode:
|
insilmaril@566
|
215 |
lastBranch=(BranchObj*)(lastBranch->getParObj());
|
insilmaril@566
|
216 |
break;
|
insilmaril@566
|
217 |
default:
|
insilmaril@566
|
218 |
break;
|
insilmaril@566
|
219 |
}
|
insilmaril@566
|
220 |
state=stateStack.takeLast();
|
insilmaril@566
|
221 |
return true;
|
insilmaril@566
|
222 |
}
|
insilmaril@566
|
223 |
|
insilmaril@574
|
224 |
bool parseFreemindHandler::characters ( const QString& ch)
|
insilmaril@566
|
225 |
{
|
insilmaril@660
|
226 |
//cout << "characters \""<<qPrintable(ch)<<"\" state="<<state <<" laststate="<<laststate<<endl;
|
insilmaril@566
|
227 |
|
insilmaril@566
|
228 |
QString ch_org=quotemeta (ch);
|
insilmaril@566
|
229 |
QString ch_simplified=ch.simplifyWhiteSpace();
|
insilmaril@566
|
230 |
if ( ch_simplified.isEmpty() ) return true;
|
insilmaril@566
|
231 |
|
insilmaril@566
|
232 |
switch ( state )
|
insilmaril@566
|
233 |
{
|
insilmaril@566
|
234 |
case StateInit: break;
|
insilmaril@566
|
235 |
case StateMap: break;
|
insilmaril@566
|
236 |
case StateNode: break;
|
insilmaril@566
|
237 |
case StateCloud: break;
|
insilmaril@566
|
238 |
case StateEdge: break;
|
insilmaril@566
|
239 |
case StateIcon: break;
|
insilmaril@566
|
240 |
case StateArrowLink: break;
|
insilmaril@566
|
241 |
case StateFont: break;
|
insilmaril@566
|
242 |
case StateHook: break;
|
insilmaril@566
|
243 |
case StateText:
|
insilmaril@566
|
244 |
lastBranch->setNote (ch_simplified);
|
insilmaril@566
|
245 |
break;
|
insilmaril@566
|
246 |
default:
|
insilmaril@566
|
247 |
return false;
|
insilmaril@566
|
248 |
}
|
insilmaril@566
|
249 |
return true;
|
insilmaril@566
|
250 |
}
|
insilmaril@566
|
251 |
|
insilmaril@574
|
252 |
QString parseFreemindHandler::errorString()
|
insilmaril@566
|
253 |
{
|
insilmaril@574
|
254 |
return "the document is not in the Freemind file format";
|
insilmaril@566
|
255 |
}
|
insilmaril@566
|
256 |
|
insilmaril@574
|
257 |
bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a)
|
insilmaril@566
|
258 |
{
|
insilmaril@566
|
259 |
lastOO=lastBranch;
|
insilmaril@566
|
260 |
|
insilmaril@566
|
261 |
if (a.value( "FOLDED")=="true" )
|
insilmaril@566
|
262 |
lastBranch->toggleScroll();
|
insilmaril@566
|
263 |
if (!a.value( "TEXT").isEmpty() )
|
insilmaril@566
|
264 |
lastBranch->setHeading (a.value ("TEXT"));
|
insilmaril@566
|
265 |
|
insilmaril@566
|
266 |
if (!a.value( "COLOR").isEmpty() )
|
insilmaril@566
|
267 |
lastBranch->setColor (QColor (a.value ("COLOR")));
|
insilmaril@566
|
268 |
|
insilmaril@566
|
269 |
if (!a.value( "LINK").isEmpty() )
|
insilmaril@566
|
270 |
lastBranch->setURL (a.value ("LINK"));
|
insilmaril@566
|
271 |
|
insilmaril@566
|
272 |
return true;
|
insilmaril@566
|
273 |
}
|
insilmaril@566
|
274 |
|
insilmaril@566
|
275 |
|