xml-freemind.cpp
author insilmaril
Thu, 06 Aug 2009 10:42:17 +0000
changeset 786 6269016c9905
parent 776 25e634a7e1dc
child 787 c6bb4fdcc55f
permissions -rw-r--r--
First changes to allow attributes
     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 		if (ti->getType()!=TreeItem::MapCenter)
    74 			qWarning ("parseFreeMindHandler::startElement  no mapCenter!!");
    75 
    76 		//cout <<"model="<<model<<"   first="<<model->first()<<endl;
    77 
    78 		lastBranchItem=model->createBranch(lastBranchItem);
    79 
    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();
    85 
    86 	} else if ( eName == "node" &&  (state == StateMap || state == StateNode )) 
    87 	{
    88 		if (!atts.value( "POSITION").isEmpty() )
    89 		{
    90 			if (atts.value ("POSITION")=="left")
    91 			{
    92 				model->select ("bo:1");
    93 				lastBranchItem=model->getSelectedBranchItem();
    94 				if (lastBranchItem)
    95 				{	
    96 					lastBranchItem=model->createBranch(lastBranchItem);
    97 					readNodeAttr (atts);
    98 				}	
    99 			} else if (atts.value ("POSITION")=="right")
   100 			{
   101 				model->select ("bo:0");
   102 				lastBranchItem=model->getSelectedBranchItem();
   103 				if (lastBranchItem)
   104 				{	
   105 					lastBranchItem=model->createBranch(lastBranchItem);
   106 					readNodeAttr (atts);
   107 				}	
   108 			}
   109 		} else
   110 		{
   111 			if (state!=StateMap)
   112 			{
   113 				lastBranchItem=model->createBranch(lastBranchItem);
   114 			}
   115 			readNodeAttr (atts);
   116 		}
   117 		state=StateNode;
   118 	} else if ( eName == "font" && state == StateNode) 
   119 	{
   120 		state=StateFont;
   121 	} else if ( eName == "edge" && state == StateNode) 
   122 	{
   123 		state=StateEdge;
   124 	} else if ( eName == "hook" && state == StateNode) 
   125 	{
   126 		state=StateHook;
   127 	} else if ( eName == "icon" && state == StateNode) 
   128 	{
   129 		state=StateIcon;
   130 		if (!atts.value("BUILTIN").isEmpty() )
   131 		{
   132 			QString f=atts.value("BUILTIN");
   133 			QString v;
   134 			if (f=="help")
   135 				v="questionmark";
   136 			else if (f=="messagebox_warning")
   137 				v="freemind-warning"; 
   138 			else if (f=="idea")
   139 				v="lamp"; 
   140 			else if (f=="button_ok")
   141 				v="hook-green"; 
   142 			else if (f=="button_cancel")
   143 				v="cross-red"; 
   144 			else if (f.contains("full-"))
   145 				v=f.replace("full-","freemind-priority-"); 
   146 			else if (f=="back")
   147 				v="freemind-back"; 
   148 			else if (f=="forward")
   149 				v="freemind-forward"; 
   150 			else if (f=="attach")
   151 				v="freemind-attach"; 
   152 			else if (f=="ksmiletris")
   153 				v="smiley-good"; // 
   154 			else if (f=="clanbomber")
   155 				v="freemind-clanbomber"; 
   156 			else if (f=="desktop_new")
   157 				v="freemind-desktopnew"; 
   158 			else if (f=="flag")
   159 				v="freemind-flag"; 
   160 			else if (f=="gohome")
   161 				v="freemind-gohome"; 
   162 			else if (f=="kaddressbook")
   163 				v="freemind-kaddressbook"; 
   164 			else if (f=="knotify")
   165 				v="freemind-knotify"; 
   166 			else if (f=="korn")
   167 				v="freemind-korn";
   168 			else if (f=="Mail")
   169 				v="freemind-mail"; 
   170 			else if (f=="password")
   171 				v="freemind-password"; 
   172 			else if (f=="pencil")
   173 				v="freemind-pencil";
   174 			else if (f=="stop")
   175 				v="freemind-stop"; 
   176 			else if (f=="wizard")
   177 				v="freemind-wizard";
   178 			else if (f=="xmag")
   179 				v="freemind-xmag";
   180 			else if (f=="bell")
   181 				v="freemind-bell";
   182 			else if (f=="bookmark")
   183 				v="freemind-bookmark"; 
   184 			else if (f=="penguin")
   185 				v="freemind-penguin"; 
   186 			else if (f=="licq")
   187 				v="freemind-licq"; 
   188 
   189 			//FIXME-3 lastBranch->activateStandardFlag( v);
   190 		}
   191 	} else if ( eName == "arrowlink" && state == StateNode) 
   192 	{
   193 		state=StateArrowLink;
   194 	} else if ( eName == "cloud" && state == StateNode) 
   195 	{
   196 		state=StateCloud;
   197 	} else if ( eName == "text" && state == StateHook) 
   198 	{
   199 		state=StateText;
   200 	} else 
   201         return false;   // Error
   202     return true;
   203 }
   204 
   205 bool parseFreemindHandler::endElement  ( const QString&, const QString&, const QString&)
   206 {
   207 	/* Testing
   208 	cout << "endElement </" <<qPrintable(eName)
   209 		<<">  state=" <<state 
   210 		<<"  laststate=" <<laststate
   211 		<<"  stateStack="<<stateStack.last() 
   212 		<<endl;
   213 	*/
   214     switch ( state ) 
   215 	{
   216         case StateNode: 
   217 			lastBranchItem=(BranchItem*)lastBranchItem->parent();
   218             break;
   219 		default: 
   220 			break;
   221     }  
   222 	state=stateStack.takeLast();	
   223 	return true;
   224 }
   225 
   226 bool parseFreemindHandler::characters   ( const QString& ch)
   227 {
   228 	//cout << "characters \""<<qPrintable(ch)<<"\"  state="<<state <<"  laststate="<<laststate<<endl;
   229 
   230 	QString ch_org=quotemeta (ch);
   231     QString ch_simplified=ch.simplifyWhiteSpace();
   232     if ( ch_simplified.isEmpty() ) return true;
   233 
   234     switch ( state ) 
   235     {
   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; 
   245         case StateText: 
   246 			lastBranchItem->setNote (ch_simplified);
   247 			break; 
   248         default: 
   249 			return false;
   250     }
   251     return true;
   252 }
   253 
   254 QString parseFreemindHandler::errorString() 
   255 {
   256     return "the document is not in the Freemind file format";
   257 }
   258 
   259 bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a)	//FIXME-3
   260 {
   261 	//lastOO=lastBranch;
   262 	//lastBranchItem=(BranchItem*)(lastBranch->getTreeItem() );
   263 
   264 	if (a.value( "FOLDED")=="true" )
   265 		lastBranchItem->toggleScroll();
   266 /*
   267 	if (!a.value( "TEXT").isEmpty() )
   268 		lastBranch->setHeading (a.value ("TEXT"));
   269 
   270 	if (!a.value( "COLOR").isEmpty() )
   271 		lastBranch->setColor (QColor (a.value ("COLOR")));
   272 
   273 	if (!a.value( "LINK").isEmpty() )
   274 		lastBranch->setURL (a.value ("LINK"));
   275 */
   276 	return true;	
   277 }
   278 
   279