xml.cpp
author insilmaril
Wed, 25 Apr 2007 16:02:54 +0000
changeset 473 8b9cfc26638c
parent 460 12e763c3e486
child 484 2974ab561436
permissions -rw-r--r--
started doxygen documentation
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@0
    20
mapBuilderHandler::mapBuilderHandler() {}
insilmaril@0
    21
insilmaril@0
    22
mapBuilderHandler::~mapBuilderHandler() {}
insilmaril@0
    23
insilmaril@0
    24
QString mapBuilderHandler::errorProtocol() { return errorProt; }
insilmaril@0
    25
insilmaril@428
    26
insilmaril@0
    27
bool mapBuilderHandler::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@0
    41
QString mapBuilderHandler::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@0
    51
bool mapBuilderHandler::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@0
   275
bool mapBuilderHandler::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@0
   306
bool mapBuilderHandler::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@0
   344
QString mapBuilderHandler::errorString() 
insilmaril@0
   345
{
insilmaril@0
   346
    return "the document is not in the VYM file format";
insilmaril@0
   347
}
insilmaril@0
   348
insilmaril@0
   349
bool mapBuilderHandler::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@0
   375
void mapBuilderHandler::setMapEditor (MapEditor* e)
insilmaril@0
   376
{
insilmaril@0
   377
    me=e;
insilmaril@0
   378
	mc=me->getMapCenter();
insilmaril@0
   379
}
insilmaril@0
   380
insilmaril@0
   381
void mapBuilderHandler::setTmpDir (QString tp)
insilmaril@0
   382
{
insilmaril@0
   383
	tmpDir=tp;
insilmaril@0
   384
}
insilmaril@0
   385
insilmaril@239
   386
void mapBuilderHandler::setInputFile (QString f)
insilmaril@239
   387
{
insilmaril@239
   388
	inputFile=f;
insilmaril@239
   389
}
insilmaril@239
   390
insilmaril@0
   391
void mapBuilderHandler::setLoadMode (const LoadMode &lm)
insilmaril@0
   392
{
insilmaril@0
   393
	loadMode=lm;
insilmaril@0
   394
}
insilmaril@0
   395
insilmaril@0
   396
bool mapBuilderHandler::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@421
   423
bool mapBuilderHandler::readFrameAttr (const QXmlAttributes& a)
insilmaril@421
   424
{
insilmaril@421
   425
	if (lastOO)
insilmaril@421
   426
	{
insilmaril@421
   427
		if (!a.value( "frameType").isEmpty() ) 
insilmaril@421
   428
			lastOO->setFrameType (a.value("frameType"));
insilmaril@444
   429
		if (!a.value( "penColor").isEmpty() ) 
insilmaril@444
   430
			lastOO->setFramePenColor (a.value("penColor"));
insilmaril@444
   431
		if (!a.value( "brushColor").isEmpty() ) 
insilmaril@444
   432
			lastOO->setFrameBrushColor (a.value("brushColor"));
insilmaril@421
   433
	}		
insilmaril@421
   434
	return true;
insilmaril@421
   435
}
insilmaril@421
   436
insilmaril@246
   437
bool mapBuilderHandler::readOOAttr (const QXmlAttributes& a)
insilmaril@160
   438
{
insilmaril@246
   439
	if (lastOO)
insilmaril@160
   440
	{
insilmaril@246
   441
		bool okx,oky;
insilmaril@246
   442
		int x,y;
insilmaril@394
   443
		if (!a.value( "relPosX").isEmpty() ) 
insilmaril@388
   444
		{
insilmaril@388
   445
			if (!a.value( "relPosY").isEmpty() ) 
insilmaril@388
   446
			{
insilmaril@388
   447
				x=a.value("relPosX").toInt (&okx, 10);
insilmaril@388
   448
				y=a.value("relPosY").toInt (&oky, 10);
insilmaril@388
   449
				if (okx && oky  )
insilmaril@388
   450
				{
insilmaril@388
   451
					lastOO->setUseRelPos (true);
insilmaril@388
   452
					lastOO->move2RelPos (x,y);
insilmaril@388
   453
				}	
insilmaril@388
   454
				else
insilmaril@388
   455
					return false;   // Couldn't read relPos
insilmaril@388
   456
			}           
insilmaril@388
   457
		}           
insilmaril@246
   458
		if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2) 
insilmaril@246
   459
		{
insilmaril@246
   460
			if (!a.value( "absPosY").isEmpty() ) 
insilmaril@246
   461
			{
insilmaril@246
   462
				x=a.value("absPosX").toInt (&okx, 10);
insilmaril@246
   463
				y=a.value("absPosY").toInt (&oky, 10);
insilmaril@246
   464
				if (okx && oky  )
insilmaril@246
   465
					lastOO->move(x,y);
insilmaril@246
   466
				else
insilmaril@246
   467
					return false;   // Couldn't read absPos
insilmaril@246
   468
			}           
insilmaril@246
   469
		}           
insilmaril@246
   470
		if (!a.value( "url").isEmpty() ) 
insilmaril@246
   471
			lastOO->setURL (a.value ("url"));
insilmaril@246
   472
		if (!a.value( "vymLink").isEmpty() ) 
insilmaril@246
   473
			lastOO->setVymLink (a.value ("vymLink"));
insilmaril@246
   474
		if (!a.value( "hideInExport").isEmpty() ) 
insilmaril@246
   475
			if (a.value("hideInExport")=="true")
insilmaril@246
   476
				lastOO->setHideInExport(true);
insilmaril@246
   477
insilmaril@169
   478
		if (!a.value( "hideLink").isEmpty()) 
insilmaril@169
   479
		{
insilmaril@169
   480
			if (a.value ("hideLink") =="true")
insilmaril@246
   481
				lastOO->setHideLinkUnselected(true);
insilmaril@169
   482
			else	
insilmaril@246
   483
				lastOO->setHideLinkUnselected(false);
insilmaril@169
   484
		}	
insilmaril@169
   485
	}
insilmaril@160
   486
	return true;	
insilmaril@160
   487
}
insilmaril@160
   488
insilmaril@0
   489
bool mapBuilderHandler::readNoteAttr (const QXmlAttributes& a)
insilmaril@0
   490
{	// only for backward compatibility (<1.4.6). Use htmlnote now.
insilmaril@0
   491
	no.clear();
insilmaril@0
   492
	QString fn;
insilmaril@0
   493
	if (!a.value( "href").isEmpty() ) 
insilmaril@0
   494
	{
insilmaril@0
   495
		// Load note
insilmaril@0
   496
		fn=parseHREF(a.value ("href") );
insilmaril@0
   497
		QFile file (fn);
insilmaril@0
   498
		QString s;						// Reading a note
insilmaril@0
   499
insilmaril@366
   500
		if ( !file.open( QIODevice::ReadOnly) )
insilmaril@0
   501
		{
insilmaril@0
   502
			qWarning ("mapBuilderHandler::readNoteAttr:  Couldn't load "+fn);
insilmaril@0
   503
			return false;
insilmaril@0
   504
		}	
insilmaril@0
   505
		QTextStream stream( &file );
insilmaril@0
   506
		QString lines;
insilmaril@366
   507
		while ( !stream.atEnd() ) {
insilmaril@0
   508
			lines += stream.readLine()+"\n"; 
insilmaril@0
   509
		}
insilmaril@0
   510
		file.close();
insilmaril@407
   511
insilmaril@0
   512
		lines ="<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body>"+lines + "</p></body></html>";
insilmaril@0
   513
		no.setNote (lines);
insilmaril@0
   514
	}		
insilmaril@0
   515
	if (!a.value( "fonthint").isEmpty() ) 
insilmaril@0
   516
		no.setFontHint(a.value ("fonthint") );
insilmaril@421
   517
	lastBranch->setNote(no);
insilmaril@0
   518
	return true;
insilmaril@0
   519
}
insilmaril@0
   520
insilmaril@0
   521
bool mapBuilderHandler::readFloatImageAttr (const QXmlAttributes& a)
insilmaril@0
   522
{
insilmaril@246
   523
	lastOO=lastFloat;
insilmaril@160
   524
	
insilmaril@246
   525
	//if (!readOOAttr(a)) return false;
insilmaril@246
   526
insilmaril@0
   527
	if (!a.value( "useOrientation").isEmpty() ) 
insilmaril@0
   528
	{
insilmaril@0
   529
		if (a.value ("useOrientation") =="true")
insilmaril@0
   530
			lastFloat->setUseOrientation (true);
insilmaril@0
   531
		else	
insilmaril@0
   532
			lastFloat->setUseOrientation (false);
insilmaril@0
   533
	}	
insilmaril@0
   534
	if (!a.value( "href").isEmpty() )
insilmaril@0
   535
	{
insilmaril@0
   536
		// Load FloatImage
insilmaril@0
   537
		if (!lastFloat->load (parseHREF(a.value ("href") ) ))
insilmaril@0
   538
		{
insilmaril@0
   539
			QMessageBox::warning( 0, "Warning: " ,
insilmaril@0
   540
				"Couldn't load float image\n"+parseHREF(a.value ("href") ));
insilmaril@0
   541
			lastBranch->removeFloatImage(((FloatImageObj*)(lastFloat)));
insilmaril@0
   542
			lastFloat=NULL;
insilmaril@0
   543
			return true;
insilmaril@0
   544
		}
insilmaril@0
   545
		
insilmaril@0
   546
	}	
insilmaril@0
   547
	if (!a.value( "floatExport").isEmpty() ) 
insilmaril@0
   548
	{
insilmaril@246
   549
		// Only for compatibility. THis is not used since 1.7.11 
insilmaril@169
   550
		if (a.value ("floatExport") =="true")
insilmaril@246
   551
			lastFloat->setFloatExport(true);
insilmaril@0
   552
		else	
insilmaril@0
   553
			lastFloat->setFloatExport (false);
insilmaril@0
   554
	}	
insilmaril@0
   555
	if (!a.value( "zPlane").isEmpty() ) 
insilmaril@408
   556
		lastFloat->setZValue (a.value("zPlane").toInt ());
insilmaril@0
   557
    int x,y;
insilmaril@0
   558
    bool okx,oky;
insilmaril@0
   559
	if (!a.value( "relPosX").isEmpty() ) 
insilmaril@0
   560
	{
insilmaril@0
   561
		if (!a.value( "relPosY").isEmpty() ) 
insilmaril@0
   562
		{
insilmaril@0
   563
			// read relPos
insilmaril@0
   564
			x=a.value("relPosX").toInt (&okx, 10);
insilmaril@0
   565
			y=a.value("relPosY").toInt (&oky, 10);
insilmaril@0
   566
			if (okx && oky) 
insilmaril@246
   567
				
insilmaril@336
   568
				{
insilmaril@336
   569
					lastFloat->setRelPos (QPoint (x,y) );
insilmaril@336
   570
					// make sure floats in mapcenter are repositioned to relative pos
insilmaril@336
   571
					if (mc==lastBranch) mc->positionContents();
insilmaril@336
   572
				}
insilmaril@0
   573
			else
insilmaril@0
   574
				// Couldn't read relPos
insilmaril@0
   575
				return false;  
insilmaril@0
   576
		}           
insilmaril@0
   577
	}	
insilmaril@169
   578
	
insilmaril@246
   579
	if (!readOOAttr(a)) return false;
insilmaril@169
   580
insilmaril@336
   581
	if (!a.value ("orgName").isEmpty() )
insilmaril@336
   582
	{
insilmaril@336
   583
		((FloatImageObj*)(lastFloat))->setOriginalFilename (a.value("orgName"));
insilmaril@336
   584
	}
insilmaril@0
   585
	return true;
insilmaril@0
   586
}
insilmaril@0
   587
insilmaril@95
   588
bool mapBuilderHandler::readXLinkAttr (const QXmlAttributes& a)
insilmaril@95
   589
{
insilmaril@95
   590
	QColor col;
insilmaril@97
   591
	bool okx;
insilmaril@103
   592
	bool success=false;
insilmaril@408
   593
	XLinkObj *xlo=new XLinkObj (mc->getScene());
insilmaril@97
   594
	if (!a.value( "color").isEmpty() ) 
insilmaril@95
   595
	{
insilmaril@97
   596
		col.setNamedColor(a.value("color"));
insilmaril@95
   597
		xlo->setColor (col);
insilmaril@95
   598
	}
insilmaril@95
   599
insilmaril@97
   600
	if (!a.value( "width").isEmpty() ) 
insilmaril@97
   601
	{
insilmaril@97
   602
		xlo->setWidth(a.value ("width").toInt (&okx, 10));
insilmaril@97
   603
	}
insilmaril@97
   604
insilmaril@95
   605
	if (!a.value( "beginBranch").isEmpty() ) 
insilmaril@406
   606
	{ 
insilmaril@95
   607
		if (!a.value( "endBranch").isEmpty() ) 
insilmaril@95
   608
		{
insilmaril@106
   609
			LinkableMapObj *lmo=mc->findObjBySelect (a.value( "beginBranch"));
insilmaril@95
   610
			if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@95
   611
			{
insilmaril@406
   612
				xlo->setBegin ((BranchObj*)lmo);
insilmaril@106
   613
				lmo=mc->findObjBySelect (a.value( "endBranch"));
insilmaril@95
   614
				if (lmo && typeid (*lmo)==typeid (BranchObj))
insilmaril@95
   615
				{
insilmaril@95
   616
					xlo->setEnd ((BranchObj*)(lmo));
insilmaril@95
   617
					xlo->activate();
insilmaril@95
   618
				}
insilmaril@95
   619
			}
insilmaril@103
   620
			success=true; // Not all branches there yet, no error
insilmaril@95
   621
		}           
insilmaril@95
   622
	}	
insilmaril@104
   623
	if (!success) delete (xlo);
insilmaril@103
   624
	return success;
insilmaril@95
   625
}
insilmaril@95
   626
insilmaril@0
   627
bool mapBuilderHandler::readHtmlAttr (const QXmlAttributes& a)
insilmaril@0
   628
{
insilmaril@0
   629
	for (int i=1; i<=a.count(); i++)
insilmaril@0
   630
		htmldata+=" "+a.localName(i-1)+"=\""+a.value(i-1)+"\"";
insilmaril@0
   631
	return true;
insilmaril@0
   632
}
insilmaril@0
   633
insilmaril@0
   634
bool mapBuilderHandler::readSettingAttr (const QXmlAttributes& a)
insilmaril@0
   635
{
insilmaril@0
   636
	if (!a.value( "key").isEmpty() ) 
insilmaril@0
   637
	{
insilmaril@0
   638
		if (!a.value( "value").isEmpty() ) 
insilmaril@0
   639
			settings.setLocalEntry (me->getDestPath(), a.value ("key"), a.value ("value"));
insilmaril@0
   640
		else
insilmaril@0
   641
			return false;
insilmaril@0
   642
		
insilmaril@0
   643
	} else
insilmaril@0
   644
		return false;
insilmaril@0
   645
	
insilmaril@0
   646
	return true;
insilmaril@0
   647
}