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