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