xml.cpp
author insilmaril
Mon, 30 Jul 2007 09:47:09 +0000
changeset 571 bc9083a4a7fb
parent 558 3665eee7a842
permissions -rw-r--r--
1.9.4 New base class for XML based file parsing (vym & Freemind)
insilmaril@0
     1
#include "xml.h"
insilmaril@0
     2
insilmaril@407
     3
#include <QMessageBox>
insilmaril@407
     4
#include <QColor>
insilmaril@366
     5
#include <QTextStream>
insilmaril@0
     6
#include <iostream>
insilmaril@0
     7
insilmaril@0
     8
#include "misc.h"
insilmaril@0
     9
#include "settings.h"
insilmaril@95
    10
#include "linkablemapobj.h"
insilmaril@0
    11
#include "version.h"
insilmaril@0
    12
insilmaril@0
    13
static BranchObj *lastBranch;
insilmaril@0
    14
static FloatObj *lastFloat;
insilmaril@246
    15
static OrnamentedObj *lastOO;
insilmaril@0
    16
insilmaril@0
    17
extern Settings settings;
insilmaril@404
    18
extern QString vymVersion;
insilmaril@0
    19
insilmaril@558
    20
parseVYMHandler::parseVYMHandler() {}
insilmaril@0
    21
insilmaril@558
    22
parseVYMHandler::~parseVYMHandler() {}
insilmaril@0
    23
insilmaril@558
    24
QString parseVYMHandler::errorProtocol() { return errorProt; }
insilmaril@0
    25
insilmaril@428
    26
insilmaril@558
    27
bool parseVYMHandler::startDocument()
insilmaril@0
    28
{
insilmaril@0
    29
    errorProt = "";
insilmaril@0
    30
    state = StateInit;
insilmaril@0
    31
    laststate = StateInit;
insilmaril@421
    32
	stateStack.clear();
insilmaril@421
    33
	stateStack.append(StateInit);
insilmaril@0
    34
    branchDepth=0;
insilmaril@0
    35
	htmldata="";
insilmaril@0
    36
	isVymPart=false;
insilmaril@0
    37
    return true;
insilmaril@0
    38
}
insilmaril@0
    39
insilmaril@0
    40
insilmaril@558
    41
QString parseVYMHandler::parseHREF(QString href)
insilmaril@0
    42
{
insilmaril@0
    43
	QString type=href.section(":",0,0);
insilmaril@0
    44
	QString path=href.section(":",1,1);
insilmaril@0
    45
	if (!tmpDir.endsWith("/"))
insilmaril@0
    46
		return tmpDir + "/" + path;
insilmaril@0
    47
	else	
insilmaril@0
    48
		return tmpDir + path;
insilmaril@0
    49
}
insilmaril@0
    50
insilmaril@558
    51
bool parseVYMHandler::startElement  ( const QString&, const QString&,
insilmaril@0
    52
                    const QString& eName, const QXmlAttributes& atts ) 
insilmaril@0
    53
{
insilmaril@0
    54
    QColor col;
insilmaril@395
    55
	/* Testing
insilmaril@428
    56
	cout << "startElement <"<< eName.ascii()
insilmaril@428
    57
		<<">  state="<<state 
insilmaril@428
    58
		<<"  laststate="<<stateStack.last()
insilmaril@428
    59
		<<"   loadMode="<<loadMode
insilmaril@428
    60
		<<"       line="<<QXmlDefaultHandler::lineNumber()
insilmaril@428
    61
		<<endl;
insilmaril@395
    62
	*/	
insilmaril@421
    63
	stateStack.append (state);	
insilmaril@0
    64
    if ( state == StateInit && (eName == "vymmap")  ) 
insilmaril@0
    65
	{
insilmaril@0
    66
        state = StateMap;
insilmaril@0
    67
		if (!atts.value( "version").isEmpty() ) 
insilmaril@0
    68
		{
insilmaril@395
    69
			if (!checkVersion(atts.value("version")))
insilmaril@0
    70
				QMessageBox::warning( 0, "Warning: Version Problem" ,
insilmaril@0
    71
				   "<h3>Map is newer than VYM</h3>"
insilmaril@0
    72
				   "<p>The map you are just trying to load was "
insilmaril@0
    73
				   "saved using vym " +atts.value("version")+". "
insilmaril@404
    74
				   "The version of this vym is " + vymVersion + 
insilmaril@0
    75
				   ". If you run into problems after pressing "
insilmaril@0
    76
				   "the ok-button below, updating vym should help.");
insilmaril@395
    77
			else	   
insilmaril@395
    78
				mc->setVersion(atts.value( "version" ));
insilmaril@0
    79
insilmaril@0
    80
		}
insilmaril@398
    81
		if (loadMode==NewMap || 
insilmaril@398
    82
			(loadMode==ImportReplace && me->getSelection()==mc))
insilmaril@0
    83
		{
insilmaril@0
    84
			if (!atts.value( "author").isEmpty() )
insilmaril@0
    85
			{
insilmaril@0
    86
				mc->setAuthor(atts.value( "author" ) );
insilmaril@0
    87
			}
insilmaril@0
    88
			if (!atts.value( "comment").isEmpty() )
insilmaril@0
    89
			{
insilmaril@0
    90
				mc->setComment (atts.value( "comment" ) );
insilmaril@0
    91
			}
insilmaril@0
    92
			if (!atts.value( "backgroundColor").isEmpty() )
insilmaril@0
    93
			{
insilmaril@0
    94
				col.setNamedColor(atts.value("backgroundColor"));
insilmaril@408
    95
				mc->getScene()->setBackgroundBrush(col);
insilmaril@0
    96
			}	    
insilmaril@444
    97
			if (!atts.value( "selectionColor").isEmpty() )
insilmaril@444
    98
			{
insilmaril@444
    99
				col.setNamedColor(atts.value("selectionColor"));
insilmaril@444
   100
				me->setSelectionColor(col);
insilmaril@444
   101
			}	    
insilmaril@0
   102
			if (!atts.value( "linkColorHint").isEmpty() ) 
insilmaril@0
   103
			{
insilmaril@0
   104
				if (atts.value("linkColorHint")=="HeadingColor")
insilmaril@460
   105
					me->setMapLinkColorHint(LinkableMapObj::HeadingColor);
insilmaril@0
   106
				else
insilmaril@460
   107
					me->setMapLinkColorHint(LinkableMapObj::DefaultColor);
insilmaril@0
   108
			}
insilmaril@0
   109
			if (!atts.value( "linkStyle").isEmpty() ) 
insilmaril@0
   110
			{
insilmaril@398
   111
				me->setMapLinkStyle(atts.value("linkStyle"));
insilmaril@0
   112
			}	
insilmaril@0
   113
			if (!atts.value( "linkColor").isEmpty() ) 
insilmaril@0
   114
			{
insilmaril@0
   115
				col.setNamedColor(atts.value("linkColor"));
insilmaril@398
   116
				me->setMapDefLinkColor(col);
insilmaril@0
   117
			}	
insilmaril@100
   118
			if (!atts.value( "defXLinkColor").isEmpty() ) 
insilmaril@97
   119
			{
insilmaril@100
   120
				col.setNamedColor(atts.value("defXLinkColor"));
insilmaril@398
   121
				me->setMapDefXLinkColor(col);
insilmaril@97
   122
			}	
insilmaril@100
   123
			if (!atts.value( "defXLinkWidth").isEmpty() ) 
insilmaril@97
   124
			{
insilmaril@398
   125
				me->setMapDefXLinkWidth(atts.value("defXLinkWidth").toInt ());
insilmaril@97
   126
			}	
insilmaril@0
   127
		}	
insilmaril@0
   128
	} else if ( eName == "select" && state == StateMap ) 
insilmaril@0
   129
	{
insilmaril@0
   130
		state=StateMapSelect;
insilmaril@0
   131
	} else if ( eName == "setting" && state == StateMap ) 
insilmaril@0
   132
	{
insilmaril@0
   133
		state=StateMapSetting;
insilmaril@0
   134
		if (loadMode==NewMap)
insilmaril@0
   135
			readSettingAttr (atts);
insilmaril@0
   136
	} else if ( eName == "mapcenter" && state == StateMap ) 
insilmaril@0
   137
	{
insilmaril@0
   138
		state=StateMapCenter;
insilmaril@0
   139
		if (loadMode==NewMap)
insilmaril@0
   140
		{	
insilmaril@0
   141
			// Really use the found mapcenter as MCO in a new map
insilmaril@0
   142
			lastBranch=mc;	// avoid empty pointer
insilmaril@0
   143
		} else
insilmaril@0
   144
		{
insilmaril@0
   145
			// Treat the found mapcenter as a branch 
insilmaril@0
   146
			// in an existing map
insilmaril@0
   147
			LinkableMapObj* lmo=me->getSelection();
insilmaril@0
   148
			if (lmo && (typeid(*lmo) == typeid(BranchObj) ) 
insilmaril@0
   149
			        || (typeid(*lmo) == typeid(MapCenterObj) ) )
insilmaril@0
   150
			{
insilmaril@160
   151
				lastBranch=(BranchObj*)lmo;
insilmaril@0
   152
				if (loadMode==ImportAdd)
insilmaril@0
   153
				{
insilmaril@0
   154
					lastBranch->addBranch();
insilmaril@0
   155
					lastBranch=lastBranch->getLastBranch();
insilmaril@0
   156
				} else
insilmaril@0
   157
					lastBranch->clear();
insilmaril@0
   158
			} else
insilmaril@0
   159
				return false;
insilmaril@0
   160
		}
insilmaril@0
   161
		readBranchAttr (atts);
insilmaril@421
   162
	} else if ( 
insilmaril@421
   163
		(eName == "standardflag" ||eName == "standardFlag") && 
insilmaril@421
   164
		(state == StateMapCenter || state==StateBranch)) 
insilmaril@0
   165
	{
insilmaril@421
   166
		state=StateStandardFlag;
insilmaril@421
   167
	} else if ( eName == "heading" && (state == StateMapCenter||state==StateBranch)) 
insilmaril@0
   168
	{
insilmaril@421
   169
		laststate=state;
insilmaril@421
   170
		state=StateHeading;
insilmaril@0
   171
		if (!atts.value( "textColor").isEmpty() ) 
insilmaril@0
   172
		{
insilmaril@0
   173
			col.setNamedColor(atts.value("textColor"));
insilmaril@239
   174
			lastBranch->setColor(col );
insilmaril@0
   175
		}	    
insilmaril@421
   176
	} else if ( eName == "note" && 
insilmaril@421
   177
				(state == StateMapCenter ||state==StateBranch))
insilmaril@0
   178
	{	// only for backward compatibility (<1.4.6). Use htmlnote now.
insilmaril@421
   179
		state=StateNote;
insilmaril@0
   180
		if (!readNoteAttr (atts) ) return false;
insilmaril@0
   181
	} else if ( eName == "htmlnote" && state == StateMapCenter) 
insilmaril@0
   182
	{
insilmaril@0
   183
		laststate=state;
insilmaril@0
   184
		state=StateHtmlNote;
insilmaril@421
   185
    } else if ( eName == "floatimage" && 
insilmaril@421
   186
				(state == StateMapCenter ||state==StateBranch)) 
insilmaril@0
   187
	{
insilmaril@421
   188
		state=StateFloatImage;
insilmaril@0
   189
        lastBranch->addFloatImage();
insilmaril@0
   190
		lastFloat=lastBranch->getLastFloatImage();
insilmaril@0
   191
		if (!readFloatImageAttr(atts)) return false;
insilmaril@166
   192
	} else if ( (eName == "branch"||eName=="floatimage") && state == StateMap) 
insilmaril@0
   193
	{
insilmaril@0
   194
		// This is used in vymparts, which have no mapcenter!
insilmaril@0
   195
		isVymPart=true;
insilmaril@0
   196
		LinkableMapObj* lmo=me->getSelection();
insilmaril@83
   197
		if (!lmo)
insilmaril@83
   198
		{
insilmaril@83
   199
			// If a vym part is _loaded_ (not imported), 
insilmaril@83
   200
			// selection==lmo==NULL
insilmaril@83
   201
			// Treat it like ImportAdd then...
insilmaril@83
   202
			loadMode=ImportAdd;
insilmaril@83
   203
			lmo=mc;
insilmaril@83
   204
		}	
insilmaril@0
   205
		if (lmo && (typeid(*lmo) == typeid(BranchObj) ) 
insilmaril@0
   206
				|| (typeid(*lmo) == typeid(MapCenterObj) ) )
insilmaril@0
   207
		{
insilmaril@0
   208
			lastBranch=(BranchObj*)(lmo);
insilmaril@166
   209
			if (eName=="branch")
insilmaril@0
   210
			{
insilmaril@166
   211
				state=StateBranch;
insilmaril@166
   212
				if (loadMode==ImportAdd)
insilmaril@166
   213
				{
insilmaril@166
   214
					lastBranch->addBranch();
insilmaril@166
   215
					lastBranch=lastBranch->getLastBranch();
insilmaril@166
   216
					
insilmaril@166
   217
				} else
insilmaril@166
   218
					lastBranch->clear();
insilmaril@166
   219
				branchDepth=1;
insilmaril@166
   220
				readBranchAttr (atts);
insilmaril@166
   221
			} else if (eName=="floatimage")
insilmaril@166
   222
			{
insilmaril@166
   223
				state=StateFloatImage;
insilmaril@166
   224
				lastBranch->addFloatImage();
insilmaril@166
   225
				lastFloat=lastBranch->getLastFloatImage();
insilmaril@166
   226
				if (!readFloatImageAttr(atts)) return false;
insilmaril@166
   227
			} else return false;
insilmaril@166
   228
		} else return false;
insilmaril@0
   229
	} else if ( eName == "branch" && state == StateMapCenter) 
insilmaril@0
   230
	{
insilmaril@0
   231
		state=StateBranch;
insilmaril@0
   232
		branchDepth=1;
insilmaril@0
   233
		lastBranch->addBranch();
insilmaril@0
   234
		lastBranch=lastBranch->getLastBranch();
insilmaril@0
   235
		readBranchAttr (atts);
insilmaril@0
   236
	} else if ( eName == "htmlnote" && state == StateBranch) 
insilmaril@0
   237
	{
insilmaril@0
   238
		laststate=state;
insilmaril@0
   239
		state=StateHtmlNote;
insilmaril@0
   240
		no.clear();
insilmaril@0
   241
		if (!atts.value( "fonthint").isEmpty() ) 
insilmaril@0
   242
			no.setFontHint(atts.value ("fonthint") );
insilmaril@421
   243
	} else if ( eName == "frame" && (state == StateBranch||state==StateMapCenter)) 
insilmaril@0
   244
	{
insilmaril@421
   245
		laststate=state;
insilmaril@421
   246
		state=StateFrame;
insilmaril@421
   247
		if (!readFrameAttr(atts)) return false;
insilmaril@95
   248
    } else if ( eName == "xlink" && state == StateBranch ) 
insilmaril@95
   249
	{
insilmaril@95
   250
		state=StateBranchXLink;
insilmaril@95
   251
		if (!readXLinkAttr (atts)) return false;
insilmaril@0
   252
    } else if ( eName == "branch" && state == StateBranch ) 
insilmaril@0
   253
	{
insilmaril@0
   254
        lastBranch->addBranch();
insilmaril@0
   255
		lastBranch=lastBranch->getLastBranch();		
insilmaril@0
   256
        branchDepth++;
insilmaril@0
   257
		readBranchAttr (atts);
insilmaril@0
   258
    } else if ( eName == "html" && state == StateHtmlNote ) 
insilmaril@0
   259
	{
insilmaril@0
   260
		state=StateHtml;
insilmaril@0
   261
		htmldata="<"+eName;
insilmaril@0
   262
		readHtmlAttr(atts);
insilmaril@0
   263
		htmldata+=">";
insilmaril@0
   264
    } else if ( state == StateHtml ) 
insilmaril@0
   265
	{
insilmaril@0
   266
		// accept all while in html mode,
insilmaril@0
   267
		htmldata+="<"+eName;
insilmaril@0
   268
		readHtmlAttr(atts);
insilmaril@0
   269
		htmldata+=">";
insilmaril@0
   270
    } else
insilmaril@0
   271
        return false;   // Error
insilmaril@0
   272
    return true;
insilmaril@0
   273
}
insilmaril@0
   274
insilmaril@558
   275
bool parseVYMHandler::endElement  ( const QString&, const QString&, const QString &eName)
insilmaril@0
   276
{
insilmaril@421
   277
	/* Testing
insilmaril@421
   278
	cout << "endElement </" <<eName.ascii()
insilmaril@421
   279
		<<">  state=" <<state 
insilmaril@421
   280
		<<"  laststate=" <<laststate
insilmaril@421
   281
		<<"  stateStack="<<stateStack.last() 
insilmaril@421
   282
		<<endl;
insilmaril@421
   283
	*/
insilmaril@0
   284
    switch ( state ) 
insilmaril@0
   285
	{
insilmaril@0
   286
        case StateBranch: 
insilmaril@0
   287
			lastBranch=(BranchObj*)(lastBranch->getParObj());
insilmaril@421
   288
            break;
insilmaril@0
   289
        case StateHtml: 
insilmaril@0
   290
			htmldata+="</"+eName+">";
insilmaril@0
   291
			if (eName=="html")
insilmaril@0
   292
			{
insilmaril@0
   293
				state=StateHtmlNote;  
insilmaril@0
   294
				htmldata.replace ("<br></br>","<br />");
insilmaril@0
   295
				no.setNote (htmldata);
insilmaril@0
   296
				lastBranch->setNote (no);
insilmaril@0
   297
			}	
insilmaril@421
   298
			break;
insilmaril@421
   299
		default: 
insilmaril@421
   300
			break;
insilmaril@421
   301
    }  
insilmaril@421
   302
	state=stateStack.takeLast();	
insilmaril@421
   303
	return true;
insilmaril@0
   304
}
insilmaril@0
   305
insilmaril@558
   306
bool parseVYMHandler::characters   ( const QString& ch)
insilmaril@0
   307
{
insilmaril@0
   308
	//cout << "characters \""<<ch<<"\"  state="<<state <<"  laststate="<<laststate<<endl;
insilmaril@0
   309
insilmaril@0
   310
	QString ch_org=quotemeta (ch);
insilmaril@0
   311
    QString ch_simplified=ch.simplifyWhiteSpace();
insilmaril@0
   312
    if ( ch_simplified.isEmpty() ) return true;
insilmaril@0
   313
insilmaril@0
   314
    switch ( state ) 
insilmaril@0
   315
    {
insilmaril@0
   316
        case StateInit: break;
insilmaril@0
   317
        case StateMap: break; 
insilmaril@0
   318
		case StateMapSelect:
insilmaril@0
   319
			me->select(ch_simplified);
insilmaril@0
   320
			break;
insilmaril@0
   321
		case StateMapSetting:break;
insilmaril@0
   322
        case StateMapCenter: break;
insilmaril@421
   323
        case StateNote:
insilmaril@0
   324
			lastBranch->setNote(ch_simplified);
insilmaril@0
   325
			break;
insilmaril@0
   326
        case StateBranch: break;
insilmaril@421
   327
        case StateStandardFlag: 
insilmaril@0
   328
            lastBranch->activateStandardFlag(ch_simplified); 
insilmaril@0
   329
            break;
insilmaril@421
   330
        case StateFloatImage: break;
insilmaril@0
   331
        case StateHtmlNote: break;
insilmaril@0
   332
        case StateHtml:
insilmaril@0
   333
			htmldata+=ch_org;
insilmaril@0
   334
			break;
insilmaril@421
   335
        case StateHeading: 
insilmaril@421
   336
            lastBranch->setHeading(ch_simplified);
insilmaril@421
   337
            break;
insilmaril@0
   338
        default: 
insilmaril@0
   339
			return false;
insilmaril@0
   340
    }
insilmaril@0
   341
    return true;
insilmaril@0
   342
}
insilmaril@0
   343
insilmaril@558
   344
QString parseVYMHandler::errorString() 
insilmaril@0
   345
{
insilmaril@0
   346
    return "the document is not in the VYM file format";
insilmaril@0
   347
}
insilmaril@0
   348
insilmaril@558
   349
bool parseVYMHandler::fatalError( const QXmlParseException& exception ) 
insilmaril@0
   350
{
insilmaril@239
   351
    errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
insilmaril@0
   352
    .arg( exception.message() )
insilmaril@0
   353
    .arg( exception.lineNumber() )
insilmaril@0
   354
    .arg( exception.columnNumber() );
insilmaril@181
   355
	// Try to read the bogus line
insilmaril@246
   356
	errorProt+=QString("File is: %1\n").arg(inputFile);
insilmaril@181
   357
	QString s;
insilmaril@239
   358
	if (loadStringFromDisk (inputFile,s))
insilmaril@181
   359
	{
insilmaril@239
   360
		QStringList sl=QStringList::split ("\n",s);
insilmaril@239
   361
		int i=1;
insilmaril@239
   362
		QStringList::Iterator it = sl.begin();
insilmaril@246
   363
		while (i<exception.lineNumber()-1)
insilmaril@239
   364
		{
insilmaril@239
   365
			it++;
insilmaril@239
   366
			i++;
insilmaril@239
   367
		}
insilmaril@239
   368
		s=*it;
insilmaril@239
   369
		s.insert (exception.columnNumber()-1,"<ERROR>");
insilmaril@239
   370
		errorProt+=s;
insilmaril@239
   371
    }
insilmaril@0
   372
    return QXmlDefaultHandler::fatalError( exception );
insilmaril@0
   373
}
insilmaril@0
   374
insilmaril@558
   375
void parseVYMHandler::setMapEditor (MapEditor* e)
insilmaril@0
   376
{
insilmaril@0
   377
    me=e;
insilmaril@0
   378
	mc=me->getMapCenter();
insilmaril@0
   379
}
insilmaril@0
   380
insilmaril@558
   381
void parseVYMHandler::setTmpDir (QString tp)
insilmaril@0
   382
{
insilmaril@0
   383
	tmpDir=tp;
insilmaril@0
   384
}
insilmaril@0
   385
insilmaril@558
   386
void parseVYMHandler::setInputFile (QString f)
insilmaril@239
   387
{
insilmaril@239
   388
	inputFile=f;
insilmaril@239
   389
}
insilmaril@239
   390
insilmaril@558
   391
void parseVYMHandler::setLoadMode (const LoadMode &lm)
insilmaril@0
   392
{
insilmaril@0
   393
	loadMode=lm;
insilmaril@0
   394
}
insilmaril@0
   395
insilmaril@558
   396
bool parseVYMHandler::readBranchAttr (const QXmlAttributes& a)
insilmaril@0
   397
{
insilmaril@246
   398
	lastOO=lastBranch;
insilmaril@246
   399
	if (!readOOAttr(a)) return false;
insilmaril@239
   400
insilmaril@239
   401
	if (!a.value( "scrolled").isEmpty() )
insilmaril@239
   402
		lastBranch->toggleScroll();
insilmaril@0
   403
	if (!a.value( "frameType").isEmpty() ) 
insilmaril@444
   404
		lastOO->setFrameType (a.value("frameType")); //Compatibility 1.8.1
insilmaril@169
   405
insilmaril@169
   406
	if (!a.value( "incImgV").isEmpty() ) 
insilmaril@200
   407
	{	
insilmaril@200
   408
		if (a.value("incImgV")=="true")
insilmaril@200
   409
			lastBranch->setIncludeImagesVer(true);
insilmaril@200
   410
		else	
insilmaril@200
   411
			lastBranch->setIncludeImagesVer(false);
insilmaril@200
   412
	}	
insilmaril@169
   413
	if (!a.value( "incImgH").isEmpty() ) 
insilmaril@200
   414
	{	
insilmaril@200
   415
		if (a.value("incImgH")=="true")
insilmaril@200
   416
			lastBranch->setIncludeImagesHor(true);
insilmaril@200
   417
		else	
insilmaril@200
   418
			lastBranch->setIncludeImagesHor(false);
insilmaril@200
   419
	}	
insilmaril@0
   420
	return true;	
insilmaril@0
   421
}
insilmaril@0
   422
insilmaril@558
   423
bool parseVYMHandler::readFrameAttr (const QXmlAttributes& a)
insilmaril@421
   424
{
insilmaril@484
   425
	bool ok;
insilmaril@484
   426
	int x;
insilmaril@421
   427
	if (lastOO)
insilmaril@421
   428
	{
insilmaril@421
   429
		if (!a.value( "frameType").isEmpty() ) 
insilmaril@421
   430
			lastOO->setFrameType (a.value("frameType"));
insilmaril@444
   431
		if (!a.value( "penColor").isEmpty() ) 
insilmaril@444
   432
			lastOO->setFramePenColor (a.value("penColor"));
insilmaril@444
   433
		if (!a.value( "brushColor").isEmpty() ) 
insilmaril@444
   434
			lastOO->setFrameBrushColor (a.value("brushColor"));
insilmaril@484
   435
		if (!a.value( "padding").isEmpty() ) 
insilmaril@484
   436
		{
insilmaril@484
   437
			x=a.value("padding").toInt(&ok);
insilmaril@484
   438
			if (ok) lastOO->setFramePadding(x);
insilmaril@484
   439
		}	
insilmaril@484
   440
		if (!a.value( "borderWidth").isEmpty() ) 
insilmaril@484
   441
		{
insilmaril@484
   442
			x=a.value("borderWidth").toInt(&ok);
insilmaril@484
   443
			if (ok) lastOO->setFrameBorderWidth(x);
insilmaril@484
   444
		}	
insilmaril@421
   445
	}		
insilmaril@421
   446
	return true;
insilmaril@421
   447
}
insilmaril@421
   448
insilmaril@558
   449
bool parseVYMHandler::readOOAttr (const QXmlAttributes& a)
insilmaril@160
   450
{
insilmaril@246
   451
	if (lastOO)
insilmaril@160
   452
	{
insilmaril@246
   453
		bool okx,oky;
insilmaril@246
   454
		int x,y;
insilmaril@394
   455
		if (!a.value( "relPosX").isEmpty() ) 
insilmaril@388
   456
		{
insilmaril@388
   457
			if (!a.value( "relPosY").isEmpty() ) 
insilmaril@388
   458
			{
insilmaril@388
   459
				x=a.value("relPosX").toInt (&okx, 10);
insilmaril@388
   460
				y=a.value("relPosY").toInt (&oky, 10);
insilmaril@388
   461
				if (okx && oky  )
insilmaril@388
   462
				{
insilmaril@388
   463
					lastOO->setUseRelPos (true);
insilmaril@388
   464
					lastOO->move2RelPos (x,y);
insilmaril@388
   465
				}	
insilmaril@388
   466
				else
insilmaril@388
   467
					return false;   // Couldn't read relPos
insilmaril@388
   468
			}           
insilmaril@388
   469
		}           
insilmaril@246
   470
		if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2) 
insilmaril@246
   471
		{
insilmaril@246
   472
			if (!a.value( "absPosY").isEmpty() ) 
insilmaril@246
   473
			{
insilmaril@246
   474
				x=a.value("absPosX").toInt (&okx, 10);
insilmaril@246
   475
				y=a.value("absPosY").toInt (&oky, 10);
insilmaril@246
   476
				if (okx && oky  )
insilmaril@246
   477
					lastOO->move(x,y);
insilmaril@246
   478
				else
insilmaril@246
   479
					return false;   // Couldn't read absPos
insilmaril@246
   480
			}           
insilmaril@246
   481
		}           
insilmaril@529
   482
		if (!a.value( "id").isEmpty() ) 
insilmaril@529
   483
			lastOO->setID (a.value ("id"));
insilmaril@246
   484
		if (!a.value( "url").isEmpty() ) 
insilmaril@246
   485
			lastOO->setURL (a.value ("url"));
insilmaril@246
   486
		if (!a.value( "vymLink").isEmpty() ) 
insilmaril@246
   487
			lastOO->setVymLink (a.value ("vymLink"));
insilmaril@246
   488
		if (!a.value( "hideInExport").isEmpty() ) 
insilmaril@246
   489
			if (a.value("hideInExport")=="true")
insilmaril@246
   490
				lastOO->setHideInExport(true);
insilmaril@246
   491
insilmaril@169
   492
		if (!a.value( "hideLink").isEmpty()) 
insilmaril@169
   493
		{
insilmaril@169
   494
			if (a.value ("hideLink") =="true")
insilmaril@246
   495
				lastOO->setHideLinkUnselected(true);
insilmaril@169
   496
			else	
insilmaril@246
   497
				lastOO->setHideLinkUnselected(false);
insilmaril@169
   498
		}	
insilmaril@169
   499
	}
insilmaril@160
   500
	return true;	
insilmaril@160
   501
}
insilmaril@160
   502
insilmaril@558
   503
bool parseVYMHandler::readNoteAttr (const QXmlAttributes& a)
insilmaril@0
   504
{	// only for backward compatibility (<1.4.6). Use htmlnote now.
insilmaril@0
   505
	no.clear();
insilmaril@0
   506
	QString fn;
insilmaril@0
   507
	if (!a.value( "href").isEmpty() ) 
insilmaril@0
   508
	{
insilmaril@0
   509
		// Load note
insilmaril@0
   510
		fn=parseHREF(a.value ("href") );
insilmaril@0
   511
		QFile file (fn);
insilmaril@0
   512
		QString s;						// Reading a note
insilmaril@0
   513
insilmaril@366
   514
		if ( !file.open( QIODevice::ReadOnly) )
insilmaril@0
   515
		{
insilmaril@558
   516
			qWarning ("parseVYMHandler::readNoteAttr:  Couldn't load "+fn);
insilmaril@0
   517
			return false;
insilmaril@0
   518
		}	
insilmaril@0
   519
		QTextStream stream( &file );
insilmaril@0
   520
		QString lines;
insilmaril@366
   521
		while ( !stream.atEnd() ) {
insilmaril@0
   522
			lines += stream.readLine()+"\n"; 
insilmaril@0
   523
		}
insilmaril@0
   524
		file.close();
insilmaril@407
   525
insilmaril@0
   526
		lines ="<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body>"+lines + "</p></body></html>";
insilmaril@0
   527
		no.setNote (lines);
insilmaril@0
   528
	}		
insilmaril@0
   529
	if (!a.value( "fonthint").isEmpty() ) 
insilmaril@0
   530
		no.setFontHint(a.value ("fonthint") );
insilmaril@421
   531
	lastBranch->setNote(no);
insilmaril@0
   532
	return true;
insilmaril@0
   533
}
insilmaril@0
   534
insilmaril@558
   535
bool parseVYMHandler::readFloatImageAttr (const QXmlAttributes& a)
insilmaril@0
   536
{
insilmaril@246
   537
	lastOO=lastFloat;
insilmaril@160
   538
	
insilmaril@246
   539
	//if (!readOOAttr(a)) return false;
insilmaril@246
   540
insilmaril@0
   541
	if (!a.value( "useOrientation").isEmpty() ) 
insilmaril@0
   542
	{
insilmaril@0
   543
		if (a.value ("useOrientation") =="true")
insilmaril@0
   544
			lastFloat->setUseOrientation (true);
insilmaril@0
   545
		else	
insilmaril@0
   546
			lastFloat->setUseOrientation (false);
insilmaril@0
   547
	}	
insilmaril@0
   548
	if (!a.value( "href").isEmpty() )
insilmaril@0
   549
	{
insilmaril@0
   550
		// Load FloatImage
insilmaril@0
   551
		if (!lastFloat->load (parseHREF(a.value ("href") ) ))
insilmaril@0
   552
		{
insilmaril@0
   553
			QMessageBox::warning( 0, "Warning: " ,
insilmaril@0
   554
				"Couldn't load float image\n"+parseHREF(a.value ("href") ));
insilmaril@0
   555
			lastBranch->removeFloatImage(((FloatImageObj*)(lastFloat)));
insilmaril@0
   556
			lastFloat=NULL;
insilmaril@0
   557
			return true;
insilmaril@0
   558
		}
insilmaril@0
   559
		
insilmaril@0
   560
	}	
insilmaril@0
   561
	if (!a.value( "floatExport").isEmpty() ) 
insilmaril@0
   562
	{
insilmaril@246
   563
		// Only for compatibility. THis is not used since 1.7.11 
insilmaril@169
   564
		if (a.value ("floatExport") =="true")
insilmaril@246
   565
			lastFloat->setFloatExport(true);
insilmaril@0
   566
		else	
insilmaril@0
   567
			lastFloat->setFloatExport (false);
insilmaril@0
   568
	}	
insilmaril@0
   569
	if (!a.value( "zPlane").isEmpty() ) 
insilmaril@408
   570
		lastFloat->setZValue (a.value("zPlane").toInt ());
insilmaril@0
   571
    int x,y;
insilmaril@0
   572
    bool okx,oky;
insilmaril@0
   573
	if (!a.value( "relPosX").isEmpty() ) 
insilmaril@0
   574
	{
insilmaril@0
   575
		if (!a.value( "relPosY").isEmpty() ) 
insilmaril@0
   576
		{
insilmaril@0
   577
			// read relPos
insilmaril@0
   578
			x=a.value("relPosX").toInt (&okx, 10);
insilmaril@0
   579
			y=a.value("relPosY").toInt (&oky, 10);
insilmaril@0
   580
			if (okx && oky) 
insilmaril@246
   581
				
insilmaril@336
   582
				{
insilmaril@336
   583
					lastFloat->setRelPos (QPoint (x,y) );
insilmaril@336
   584
					// make sure floats in mapcenter are repositioned to relative pos
insilmaril@336
   585
					if (mc==lastBranch) mc->positionContents();
insilmaril@336
   586
				}
insilmaril@0
   587
			else
insilmaril@0
   588
				// Couldn't read relPos
insilmaril@0
   589
				return false;  
insilmaril@0
   590
		}           
insilmaril@0
   591
	}	
insilmaril@169
   592
	
insilmaril@246
   593
	if (!readOOAttr(a)) return false;
insilmaril@169
   594
insilmaril@336
   595
	if (!a.value ("orgName").isEmpty() )
insilmaril@336
   596
	{
insilmaril@336
   597
		((FloatImageObj*)(lastFloat))->setOriginalFilename (a.value("orgName"));
insilmaril@336
   598
	}
insilmaril@0
   599
	return true;
insilmaril@0
   600
}
insilmaril@0
   601
insilmaril@558
   602
bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a)
insilmaril@95
   603
{
insilmaril@95
   604
	QColor col;
insilmaril@97
   605
	bool okx;
insilmaril@103
   606
	bool success=false;
insilmaril@408
   607
	XLinkObj *xlo=new XLinkObj (mc->getScene());
insilmaril@97
   608
	if (!a.value( "color").isEmpty() ) 
insilmaril@95
   609
	{
insilmaril@97
   610
		col.setNamedColor(a.value("color"));
insilmaril@95
   611
		xlo->setColor (col);
insilmaril@95
   612
	}
insilmaril@95
   613
insilmaril@97
   614
	if (!a.value( "width").isEmpty() ) 
insilmaril@97
   615
	{
insilmaril@97
   616
		xlo->setWidth(a.value ("width").toInt (&okx, 10));
insilmaril@97
   617
	}
insilmaril@97
   618
insilmaril@529
   619
	// Connecting by select string for compatibility with version < 1.8.76
insilmaril@95
   620
	if (!a.value( "beginBranch").isEmpty() ) 
insilmaril@406
   621
	{ 
insilmaril@95
   622
		if (!a.value( "endBranch").isEmpty() ) 
insilmaril@95
   623
		{
insilmaril@106
   624
			LinkableMapObj *lmo=mc->findObjBySelect (a.value( "beginBranch"));
insilmaril@95
   625
			if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@95
   626
			{
insilmaril@406
   627
				xlo->setBegin ((BranchObj*)lmo);
insilmaril@106
   628
				lmo=mc->findObjBySelect (a.value( "endBranch"));
insilmaril@95
   629
				if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@95
   630
				{
insilmaril@95
   631
					xlo->setEnd ((BranchObj*)(lmo));
insilmaril@95
   632
					xlo->activate();
insilmaril@95
   633
				}
insilmaril@95
   634
			}
insilmaril@103
   635
			success=true; // Not all branches there yet, no error
insilmaril@95
   636
		}           
insilmaril@95
   637
	}	
insilmaril@529
   638
insilmaril@529
   639
	// object ID is used starting in version 1.8.76
insilmaril@529
   640
	if (!a.value( "beginID").isEmpty() ) 
insilmaril@529
   641
	{ 
insilmaril@529
   642
		if (!a.value( "endID").isEmpty() ) 
insilmaril@529
   643
		{
insilmaril@529
   644
			LinkableMapObj *lmo=mc->findID (a.value( "beginBranch"));
insilmaril@529
   645
			if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@529
   646
			{
insilmaril@529
   647
				xlo->setBegin ((BranchObj*)lmo);
insilmaril@529
   648
				lmo=mc->findID (a.value( "endID"));
insilmaril@529
   649
				if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@529
   650
				{
insilmaril@529
   651
					xlo->setEnd ((BranchObj*)(lmo));
insilmaril@529
   652
					xlo->activate();
insilmaril@529
   653
				}
insilmaril@529
   654
			}
insilmaril@529
   655
			success=true; // Not all branches there yet, no error
insilmaril@529
   656
		}           
insilmaril@529
   657
	}	
insilmaril@104
   658
	if (!success) delete (xlo);
insilmaril@103
   659
	return success;
insilmaril@95
   660
}
insilmaril@95
   661
insilmaril@558
   662
bool parseVYMHandler::readHtmlAttr (const QXmlAttributes& a)
insilmaril@0
   663
{
insilmaril@0
   664
	for (int i=1; i<=a.count(); i++)
insilmaril@0
   665
		htmldata+=" "+a.localName(i-1)+"=\""+a.value(i-1)+"\"";
insilmaril@0
   666
	return true;
insilmaril@0
   667
}
insilmaril@0
   668
insilmaril@558
   669
bool parseVYMHandler::readSettingAttr (const QXmlAttributes& a)
insilmaril@0
   670
{
insilmaril@0
   671
	if (!a.value( "key").isEmpty() ) 
insilmaril@0
   672
	{
insilmaril@0
   673
		if (!a.value( "value").isEmpty() ) 
insilmaril@0
   674
			settings.setLocalEntry (me->getDestPath(), a.value ("key"), a.value ("value"));
insilmaril@0
   675
		else
insilmaril@0
   676
			return false;
insilmaril@0
   677
		
insilmaril@0
   678
	} else
insilmaril@0
   679
		return false;
insilmaril@0
   680
	
insilmaril@0
   681
	return true;
insilmaril@0
   682
}