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