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