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