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