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