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