Removed some FIXMEs. Added translations
10 #include "linkablemapobj.h"
13 static BranchObj *lastBranch;
14 static FloatObj *lastFloat;
15 static OrnamentedObj *lastOO;
17 extern Settings settings;
18 extern QString vymVersion;
20 mapBuilderHandler::mapBuilderHandler() {}
22 mapBuilderHandler::~mapBuilderHandler() {}
24 QString mapBuilderHandler::errorProtocol() { return errorProt; }
26 bool mapBuilderHandler::startDocument()
30 laststate = StateInit;
38 QString mapBuilderHandler::parseHREF(QString href)
40 QString type=href.section(":",0,0);
41 QString path=href.section(":",1,1);
42 if (!tmpDir.endsWith("/"))
43 return tmpDir + "/" + path;
48 bool mapBuilderHandler::startElement ( const QString&, const QString&,
49 const QString& eName, const QXmlAttributes& atts )
53 cout << "startElement <"<< eName.ascii()<<
55 " laststate="<<laststate<<
56 " loadMode="<<loadMode<<endl;
58 if ( state == StateInit && (eName == "vymmap") )
61 if (!atts.value( "version").isEmpty() )
63 if (!checkVersion(atts.value("version")))
64 QMessageBox::warning( 0, "Warning: Version Problem" ,
65 "<h3>Map is newer than VYM</h3>"
66 "<p>The map you are just trying to load was "
67 "saved using vym " +atts.value("version")+". "
68 "The version of this vym is " + vymVersion +
69 ". If you run into problems after pressing "
70 "the ok-button below, updating vym should help.");
72 mc->setVersion(atts.value( "version" ));
75 if (loadMode==NewMap ||
76 (loadMode==ImportReplace && me->getSelection()==mc))
78 if (!atts.value( "author").isEmpty() )
80 mc->setAuthor(atts.value( "author" ) );
82 if (!atts.value( "comment").isEmpty() )
84 mc->setComment (atts.value( "comment" ) );
86 if (!atts.value( "backgroundColor").isEmpty() )
88 col.setNamedColor(atts.value("backgroundColor"));
89 mc->getScene()->setBackgroundBrush(col);
91 if (!atts.value( "linkColorHint").isEmpty() )
93 if (atts.value("linkColorHint")=="HeadingColor")
94 me->setMapLinkColorHint(HeadingColor);
96 me->setMapLinkColorHint(DefaultColor);
98 if (!atts.value( "linkStyle").isEmpty() )
100 me->setMapLinkStyle(atts.value("linkStyle"));
102 if (!atts.value( "linkColor").isEmpty() )
104 col.setNamedColor(atts.value("linkColor"));
105 me->setMapDefLinkColor(col);
107 if (!atts.value( "defXLinkColor").isEmpty() )
109 col.setNamedColor(atts.value("defXLinkColor"));
110 me->setMapDefXLinkColor(col);
112 if (!atts.value( "defXLinkWidth").isEmpty() )
114 me->setMapDefXLinkWidth(atts.value("defXLinkWidth").toInt ());
117 } else if ( eName == "select" && state == StateMap )
119 state=StateMapSelect;
120 } else if ( eName == "setting" && state == StateMap )
122 state=StateMapSetting;
123 if (loadMode==NewMap)
124 readSettingAttr (atts);
125 } else if ( eName == "mapcenter" && state == StateMap )
127 state=StateMapCenter;
128 if (loadMode==NewMap)
130 // Really use the found mapcenter as MCO in a new map
131 lastBranch=mc; // avoid empty pointer
134 // Treat the found mapcenter as a branch
135 // in an existing map
136 LinkableMapObj* lmo=me->getSelection();
137 if (lmo && (typeid(*lmo) == typeid(BranchObj) )
138 || (typeid(*lmo) == typeid(MapCenterObj) ) )
140 lastBranch=(BranchObj*)lmo;
141 if (loadMode==ImportAdd)
143 lastBranch->addBranch();
144 lastBranch=lastBranch->getLastBranch();
150 readBranchAttr (atts);
151 } else if ( (eName == "standardflag" ||eName == "standardFlag") && state == StateMapCenter)
153 state=StateMapCenterStandardFlag;
154 } else if ( eName == "heading" && state == StateMapCenter)
156 state=StateMapCenterHeading;
157 if (!atts.value( "textColor").isEmpty() )
159 col.setNamedColor(atts.value("textColor"));
160 lastBranch->setColor(col );
162 } else if ( eName == "note" && state == StateMapCenter)
163 { // only for backward compatibility (<1.4.6). Use htmlnote now.
164 state=StateMapCenterNote;
165 if (!readNoteAttr (atts) ) return false;
166 } else if ( eName == "htmlnote" && state == StateMapCenter)
170 } else if ( eName == "floatimage" && state == StateMapCenter )
172 state=StateMapCenterFloatImage;
173 lastBranch->addFloatImage();
174 lastFloat=lastBranch->getLastFloatImage();
175 if (!readFloatImageAttr(atts)) return false;
176 } else if ( (eName == "branch"||eName=="floatimage") && state == StateMap)
178 // This is used in vymparts, which have no mapcenter!
180 LinkableMapObj* lmo=me->getSelection();
183 // If a vym part is _loaded_ (not imported),
184 // selection==lmo==NULL
185 // Treat it like ImportAdd then...
189 if (lmo && (typeid(*lmo) == typeid(BranchObj) )
190 || (typeid(*lmo) == typeid(MapCenterObj) ) )
192 lastBranch=(BranchObj*)(lmo);
196 if (loadMode==ImportAdd)
198 lastBranch->addBranch();
199 lastBranch=lastBranch->getLastBranch();
204 readBranchAttr (atts);
205 } else if (eName=="floatimage")
207 state=StateFloatImage;
208 lastBranch->addFloatImage();
209 lastFloat=lastBranch->getLastFloatImage();
210 if (!readFloatImageAttr(atts)) return false;
213 } else if ( eName == "branch" && state == StateMapCenter)
217 lastBranch->addBranch();
218 lastBranch=lastBranch->getLastBranch();
219 readBranchAttr (atts);
220 } else if ( (eName=="standardflag" ||eName == "standardFlag") && state == StateBranch)
222 state=StateBranchStandardFlag;
223 } else if ( eName == "heading" && state == StateBranch)
225 state=StateBranchHeading;
226 if (!atts.value( "textColor").isEmpty() )
228 col.setNamedColor(atts.value("textColor"));
229 lastBranch->setColor(col );
231 } else if ( eName == "note" && state == StateBranch)
233 state=StateBranchNote;
234 if (!readNoteAttr (atts) ) return false;
235 } else if ( eName == "htmlnote" && state == StateBranch)
240 if (!atts.value( "fonthint").isEmpty() )
241 no.setFontHint(atts.value ("fonthint") );
242 } else if ( eName == "floatimage" && state == StateBranch )
244 state=StateBranchFloatImage;
245 lastBranch->addFloatImage();
246 lastFloat=lastBranch->getLastFloatImage();
247 if (!readFloatImageAttr(atts)) return false;
248 } else if ( eName == "xlink" && state == StateBranch )
250 state=StateBranchXLink;
251 if (!readXLinkAttr (atts)) return false;
252 } else if ( eName == "branch" && state == StateBranch )
254 lastBranch->addBranch();
255 lastBranch=lastBranch->getLastBranch();
257 readBranchAttr (atts);
258 } else if ( eName == "html" && state == StateHtmlNote )
264 } else if ( state == StateHtml )
266 // accept all while in html mode,
271 return false; // Error
275 bool mapBuilderHandler::endElement ( const QString&, const QString&, const QString &eName)
277 // cout << "endElement </"<<eName<<"> state="<<state <<" laststate="<<laststate<<endl;
280 case StateMapSelect: state=StateMap; return true;
281 case StateMapSetting: state=StateMap; return true;
282 case StateMapCenter: state=StateMap; return true;
283 case StateMapCenterStandardFlag: state=StateMapCenter; return true;
284 case StateMapCenterHeading: state=StateMapCenter; return true;
285 case StateMapCenterNote: state=StateMapCenter; return true;
286 case StateMapCenterFloatImage: state=StateMapCenter; return true;
287 case StateFloatImage: state=StateMap; return true;
299 state=StateMapCenter;
301 lastBranch=(BranchObj*)(lastBranch->getParObj());
303 case StateBranchStandardFlag: state=StateBranch; return true;
304 case StateBranchHeading: state=StateBranch; return true;
305 case StateBranchNote: state=StateBranch; return true;
306 case StateBranchFloatImage: state=StateBranch; return true;
307 case StateBranchXLink: state=StateBranch; return true;
308 case StateHtmlNote: state=laststate; return true;
310 htmldata+="</"+eName+">";
314 htmldata.replace ("<br></br>","<br />");
315 no.setNote (htmldata);
316 lastBranch->setNote (no);
322 case StateMap: state=StateInit; return true;
324 // even for HTML includes, this should never be reached
329 bool mapBuilderHandler::characters ( const QString& ch)
331 //cout << "characters \""<<ch<<"\" state="<<state <<" laststate="<<laststate<<endl;
333 QString ch_org=quotemeta (ch);
334 QString ch_simplified=ch.simplifyWhiteSpace();
335 if ( ch_simplified.isEmpty() ) return true;
339 case StateInit: break;
340 case StateMap: break;
342 me->select(ch_simplified);
344 case StateMapSetting:break;
345 case StateMapCenter: break;
346 case StateMapCenterStandardFlag:
347 lastBranch->activateStandardFlag(ch_simplified);
349 case StateMapCenterHeading:
350 lastBranch->setHeading(ch_simplified);
352 case StateMapCenterNote:
353 lastBranch->setNote(ch_simplified);
355 case StateBranch: break;
356 case StateBranchStandardFlag:
357 lastBranch->activateStandardFlag(ch_simplified);
359 case StateBranchHeading:
360 lastBranch->setHeading(ch_simplified);
362 case StateBranchNote:
363 lastBranch->setNote(ch_simplified);
365 case StateBranchFloatImage: break;
366 case StateHtmlNote: break;
376 QString mapBuilderHandler::errorString()
378 return "the document is not in the VYM file format";
381 bool mapBuilderHandler::fatalError( const QXmlParseException& exception )
383 errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
384 .arg( exception.message() )
385 .arg( exception.lineNumber() )
386 .arg( exception.columnNumber() );
387 // Try to read the bogus line
388 errorProt+=QString("File is: %1\n").arg(inputFile);
390 if (loadStringFromDisk (inputFile,s))
392 QStringList sl=QStringList::split ("\n",s);
394 QStringList::Iterator it = sl.begin();
395 while (i<exception.lineNumber()-1)
401 s.insert (exception.columnNumber()-1,"<ERROR>");
404 return QXmlDefaultHandler::fatalError( exception );
407 void mapBuilderHandler::setMapEditor (MapEditor* e)
410 mc=me->getMapCenter();
413 void mapBuilderHandler::setTmpDir (QString tp)
418 void mapBuilderHandler::setInputFile (QString f)
423 void mapBuilderHandler::setLoadMode (const LoadMode &lm)
428 bool mapBuilderHandler::readBranchAttr (const QXmlAttributes& a)
431 if (!readOOAttr(a)) return false;
433 if (!a.value( "scrolled").isEmpty() )
434 lastBranch->toggleScroll();
435 if (!a.value( "frameType").isEmpty() )
436 lastBranch->setFrameType (a.value("frameType"));
438 if (!a.value( "incImgV").isEmpty() )
440 if (a.value("incImgV")=="true")
441 lastBranch->setIncludeImagesVer(true);
443 lastBranch->setIncludeImagesVer(false);
445 if (!a.value( "incImgH").isEmpty() )
447 if (a.value("incImgH")=="true")
448 lastBranch->setIncludeImagesHor(true);
450 lastBranch->setIncludeImagesHor(false);
455 bool mapBuilderHandler::readOOAttr (const QXmlAttributes& a)
461 if (!a.value( "relPosX").isEmpty() )
463 if (!a.value( "relPosY").isEmpty() )
465 x=a.value("relPosX").toInt (&okx, 10);
466 y=a.value("relPosY").toInt (&oky, 10);
469 lastOO->setUseRelPos (true);
470 lastOO->move2RelPos (x,y);
473 return false; // Couldn't read relPos
476 if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2)
478 if (!a.value( "absPosY").isEmpty() )
480 x=a.value("absPosX").toInt (&okx, 10);
481 y=a.value("absPosY").toInt (&oky, 10);
485 return false; // Couldn't read absPos
488 if (!a.value( "url").isEmpty() )
489 lastOO->setURL (a.value ("url"));
490 if (!a.value( "vymLink").isEmpty() )
491 lastOO->setVymLink (a.value ("vymLink"));
492 if (!a.value( "hideInExport").isEmpty() )
493 if (a.value("hideInExport")=="true")
494 lastOO->setHideInExport(true);
496 if (!a.value( "hideLink").isEmpty())
498 if (a.value ("hideLink") =="true")
499 lastOO->setHideLinkUnselected(true);
501 lastOO->setHideLinkUnselected(false);
507 bool mapBuilderHandler::readNoteAttr (const QXmlAttributes& a)
508 { // only for backward compatibility (<1.4.6). Use htmlnote now.
511 if (!a.value( "href").isEmpty() )
514 fn=parseHREF(a.value ("href") );
516 QString s; // Reading a note
518 if ( !file.open( QIODevice::ReadOnly) )
520 qWarning ("mapBuilderHandler::readNoteAttr: Couldn't load "+fn);
523 QTextStream stream( &file );
525 while ( !stream.atEnd() ) {
526 lines += stream.readLine()+"\n";
530 lines ="<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body>"+lines + "</p></body></html>";
533 if (!a.value( "fonthint").isEmpty() )
534 no.setFontHint(a.value ("fonthint") );
535 if (state == StateMapCenterNote)
538 lastBranch->setNote(no);
542 bool mapBuilderHandler::readFloatImageAttr (const QXmlAttributes& a)
546 //if (!readOOAttr(a)) return false;
548 if (!a.value( "useOrientation").isEmpty() )
550 if (a.value ("useOrientation") =="true")
551 lastFloat->setUseOrientation (true);
553 lastFloat->setUseOrientation (false);
555 if (!a.value( "href").isEmpty() )
558 if (!lastFloat->load (parseHREF(a.value ("href") ) ))
560 QMessageBox::warning( 0, "Warning: " ,
561 "Couldn't load float image\n"+parseHREF(a.value ("href") ));
562 lastBranch->removeFloatImage(((FloatImageObj*)(lastFloat)));
568 if (!a.value( "floatExport").isEmpty() )
570 // Only for compatibility. THis is not used since 1.7.11
571 if (a.value ("floatExport") =="true")
572 lastFloat->setFloatExport(true);
574 lastFloat->setFloatExport (false);
576 if (!a.value( "zPlane").isEmpty() )
577 lastFloat->setZValue (a.value("zPlane").toInt ());
580 if (!a.value( "relPosX").isEmpty() )
582 if (!a.value( "relPosY").isEmpty() )
585 x=a.value("relPosX").toInt (&okx, 10);
586 y=a.value("relPosY").toInt (&oky, 10);
590 lastFloat->setRelPos (QPoint (x,y) );
591 // make sure floats in mapcenter are repositioned to relative pos
592 if (mc==lastBranch) mc->positionContents();
595 // Couldn't read relPos
600 if (!readOOAttr(a)) return false;
602 if (!a.value ("orgName").isEmpty() )
604 ((FloatImageObj*)(lastFloat))->setOriginalFilename (a.value("orgName"));
609 bool mapBuilderHandler::readXLinkAttr (const QXmlAttributes& a)
614 XLinkObj *xlo=new XLinkObj (mc->getScene());
615 if (!a.value( "color").isEmpty() )
617 col.setNamedColor(a.value("color"));
621 if (!a.value( "width").isEmpty() )
623 xlo->setWidth(a.value ("width").toInt (&okx, 10));
626 if (!a.value( "beginBranch").isEmpty() )
628 if (!a.value( "endBranch").isEmpty() )
630 LinkableMapObj *lmo=mc->findObjBySelect (a.value( "beginBranch"));
631 if (lmo && typeid (*lmo)==typeid (BranchObj))
633 xlo->setBegin ((BranchObj*)lmo);
634 lmo=mc->findObjBySelect (a.value( "endBranch"));
635 if (lmo && typeid (*lmo)==typeid (BranchObj))
637 xlo->setEnd ((BranchObj*)(lmo));
641 success=true; // Not all branches there yet, no error
644 if (!success) delete (xlo);
648 bool mapBuilderHandler::readHtmlAttr (const QXmlAttributes& a)
650 for (int i=1; i<=a.count(); i++)
651 htmldata+=" "+a.localName(i-1)+"=\""+a.value(i-1)+"\"";
655 bool mapBuilderHandler::readSettingAttr (const QXmlAttributes& a)
657 if (!a.value( "key").isEmpty() )
659 if (!a.value( "value").isEmpty() )
660 settings.setLocalEntry (me->getDestPath(), a.value ("key"), a.value ("value"));