xml-vym.cpp
author insilmaril
Mon Jul 27 12:53:17 2009 +0000 (2009-07-27)
changeset 782 ffb02a9bb508
parent 780 fe839bdfd10c
child 785 5987f9f15bac
permissions -rw-r--r--
Playing with dbus, fixed name of TW translation file
insilmaril@576
     1
#include "xml-vym.h"
insilmaril@576
     2
insilmaril@576
     3
#include <QMessageBox>
insilmaril@576
     4
#include <QColor>
insilmaril@576
     5
#include <QTextStream>
insilmaril@576
     6
#include <iostream>
insilmaril@611
     7
#include <typeinfo>
insilmaril@576
     8
insilmaril@749
     9
#include "branchitem.h"
insilmaril@576
    10
#include "misc.h"
insilmaril@576
    11
#include "settings.h"
insilmaril@576
    12
#include "linkablemapobj.h"
insilmaril@742
    13
#include "mainwindow.h"
insilmaril@576
    14
#include "version.h"
insilmaril@576
    15
insilmaril@776
    16
static ImageItem *lastImageItem;
insilmaril@776
    17
static MapItem *lastMI;
insilmaril@576
    18
insilmaril@742
    19
extern Main *mainWindow;
insilmaril@576
    20
extern Settings settings;
insilmaril@576
    21
extern QString vymVersion;
insilmaril@576
    22
insilmaril@576
    23
bool parseVYMHandler::startDocument()
insilmaril@576
    24
{
insilmaril@576
    25
    errorProt = "";
insilmaril@576
    26
    state = StateInit;
insilmaril@576
    27
    laststate = StateInit;
insilmaril@576
    28
	stateStack.clear();
insilmaril@576
    29
	stateStack.append(StateInit);
insilmaril@576
    30
	htmldata="";
insilmaril@576
    31
	isVymPart=false;
insilmaril@576
    32
    return true;
insilmaril@576
    33
}
insilmaril@576
    34
insilmaril@576
    35
bool parseVYMHandler::startElement  ( const QString&, const QString&,
insilmaril@576
    36
                    const QString& eName, const QXmlAttributes& atts ) 
insilmaril@576
    37
{
insilmaril@576
    38
    QColor col;
insilmaril@576
    39
	/* Testing
insilmaril@660
    40
	cout << "startElement <"<< qPrintable(eName)
insilmaril@576
    41
		<<">  state="<<state 
insilmaril@576
    42
		<<"  laststate="<<stateStack.last()
insilmaril@576
    43
		<<"   loadMode="<<loadMode
insilmaril@735
    44
	//	<<"       line="<<QXmlDefaultHandler::lineNumber()
insilmaril@576
    45
		<<endl;
insilmaril@736
    46
	*/	
insilmaril@576
    47
	stateStack.append (state);	
insilmaril@576
    48
    if ( state == StateInit && (eName == "vymmap")  ) 
insilmaril@576
    49
	{
insilmaril@576
    50
        state = StateMap;
insilmaril@742
    51
		branchesTotal=branchesCurrent=0;
insilmaril@647
    52
insilmaril@647
    53
		if (loadMode==NewMap )
insilmaril@576
    54
		{
insilmaril@647
    55
			// Create mapCenter
insilmaril@647
    56
			model->clear();
insilmaril@776
    57
			lastBranch=NULL;
insilmaril@647
    58
insilmaril@576
    59
			if (!atts.value( "author").isEmpty() )
insilmaril@647
    60
				model->setAuthor(atts.value( "author" ) );
insilmaril@576
    61
			if (!atts.value( "comment").isEmpty() )
insilmaril@647
    62
				model->setComment (atts.value( "comment" ) );
insilmaril@749
    63
			if (!atts.value( "branchCount").isEmpty() )
insilmaril@742
    64
			{
insilmaril@749
    65
				branchesTotal=atts.value("branchCount").toInt();
insilmaril@742
    66
				if (branchesTotal>10)
insilmaril@742
    67
				{
insilmaril@742
    68
					mainWindow->setProgressMinimum (0);
insilmaril@742
    69
					mainWindow->setProgressMaximum (branchesTotal);
insilmaril@742
    70
					mainWindow->setProgressValue(0);
insilmaril@742
    71
				}
insilmaril@742
    72
			} else
insilmaril@742
    73
			{
insilmaril@742
    74
				mainWindow->setProgressMinimum (0);
insilmaril@742
    75
				mainWindow->setProgressMaximum (0);
insilmaril@742
    76
				mainWindow->setProgressValue(0);
insilmaril@742
    77
			}
insilmaril@742
    78
insilmaril@742
    79
				
insilmaril@576
    80
			if (!atts.value( "backgroundColor").isEmpty() )
insilmaril@576
    81
			{
insilmaril@576
    82
				col.setNamedColor(atts.value("backgroundColor"));
insilmaril@647
    83
				model->getScene()->setBackgroundBrush(col);
insilmaril@576
    84
			}	    
insilmaril@576
    85
			if (!atts.value( "selectionColor").isEmpty() )
insilmaril@576
    86
			{
insilmaril@576
    87
				col.setNamedColor(atts.value("selectionColor"));
insilmaril@721
    88
				model->setSelectionColor(col);
insilmaril@576
    89
			}	    
insilmaril@576
    90
			if (!atts.value( "linkColorHint").isEmpty() ) 
insilmaril@576
    91
			{
insilmaril@576
    92
				if (atts.value("linkColorHint")=="HeadingColor")
insilmaril@721
    93
					model->setMapLinkColorHint(LinkableMapObj::HeadingColor);
insilmaril@576
    94
				else
insilmaril@721
    95
					model->setMapLinkColorHint(LinkableMapObj::DefaultColor);
insilmaril@576
    96
			}
insilmaril@576
    97
			if (!atts.value( "linkStyle").isEmpty() ) 
insilmaril@721
    98
				model->setMapLinkStyle(atts.value("linkStyle"));
insilmaril@576
    99
			if (!atts.value( "linkColor").isEmpty() ) 
insilmaril@576
   100
			{
insilmaril@576
   101
				col.setNamedColor(atts.value("linkColor"));
insilmaril@721
   102
				model->setMapDefLinkColor(col);
insilmaril@576
   103
			}	
insilmaril@576
   104
			if (!atts.value( "defXLinkColor").isEmpty() ) 
insilmaril@576
   105
			{
insilmaril@576
   106
				col.setNamedColor(atts.value("defXLinkColor"));
insilmaril@721
   107
				model->setMapDefXLinkColor(col);
insilmaril@576
   108
			}	
insilmaril@576
   109
			if (!atts.value( "defXLinkWidth").isEmpty() ) 
insilmaril@721
   110
				model->setMapDefXLinkWidth(atts.value("defXLinkWidth").toInt ());
insilmaril@576
   111
		}	
insilmaril@727
   112
		// Check version
insilmaril@727
   113
		if (!atts.value( "version").isEmpty() ) 
insilmaril@727
   114
		{
insilmaril@727
   115
			if (!checkVersion(atts.value("version")))
insilmaril@727
   116
				QMessageBox::warning( 0, "Warning: Version Problem" ,
insilmaril@727
   117
				   "<h3>Map is newer than VYM</h3>"
insilmaril@727
   118
				   "<p>The map you are just trying to load was "
insilmaril@727
   119
				   "saved using vym " +atts.value("version")+". "
insilmaril@727
   120
				   "The version of this vym is " + vymVersion + 
insilmaril@727
   121
				   ". If you run into problems after pressing "
insilmaril@727
   122
				   "the ok-button below, updating vym should help.");
insilmaril@727
   123
			else	   
insilmaril@727
   124
				model->setVersion(atts.value( "version" ));
insilmaril@727
   125
insilmaril@727
   126
		}
insilmaril@727
   127
insilmaril@576
   128
	} else if ( eName == "select" && state == StateMap ) 
insilmaril@576
   129
	{
insilmaril@576
   130
		state=StateMapSelect;
insilmaril@576
   131
	} else if ( eName == "setting" && state == StateMap ) 
insilmaril@576
   132
	{
insilmaril@576
   133
		state=StateMapSetting;
insilmaril@576
   134
		if (loadMode==NewMap)
insilmaril@576
   135
			readSettingAttr (atts);
insilmaril@576
   136
	} else if ( eName == "mapcenter" && state == StateMap ) 
insilmaril@576
   137
	{
insilmaril@576
   138
		state=StateMapCenter;
insilmaril@576
   139
		if (loadMode==NewMap)
insilmaril@576
   140
		{	
insilmaril@576
   141
			// Really use the found mapcenter as MCO in a new map
insilmaril@647
   142
insilmaril@776
   143
			lastBranch=model->createMapCenter(); 
insilmaril@576
   144
		} else
insilmaril@576
   145
		{
insilmaril@576
   146
			// Treat the found mapcenter as a branch 
insilmaril@576
   147
			// in an existing map
insilmaril@781
   148
			BranchItem *bi=model->getSelectedBranchItem();	//FIXME-3 selection is no longer used here...
insilmaril@753
   149
			if (bi)
insilmaril@576
   150
			{
insilmaril@776
   151
				lastBranch=bi;
insilmaril@576
   152
				if (loadMode==ImportAdd)
insilmaril@576
   153
				{
insilmaril@776
   154
					lastBranch=model->createBranch(lastBranch);
insilmaril@753
   155
				} //else
insilmaril@753
   156
					//FIXME-3 lastBranch->clear();
insilmaril@576
   157
			} else
insilmaril@576
   158
				return false;
insilmaril@576
   159
		}
insilmaril@576
   160
		readBranchAttr (atts);
insilmaril@576
   161
	} else if ( 
insilmaril@576
   162
		(eName == "standardflag" ||eName == "standardFlag") && 
insilmaril@576
   163
		(state == StateMapCenter || state==StateBranch)) 
insilmaril@576
   164
	{
insilmaril@576
   165
		state=StateStandardFlag;
insilmaril@576
   166
	} else if ( eName == "heading" && (state == StateMapCenter||state==StateBranch)) 
insilmaril@576
   167
	{
insilmaril@576
   168
		laststate=state;
insilmaril@576
   169
		state=StateHeading;
insilmaril@576
   170
		if (!atts.value( "textColor").isEmpty() ) 
insilmaril@576
   171
		{
insilmaril@576
   172
			col.setNamedColor(atts.value("textColor"));
insilmaril@776
   173
			lastBranch->setHeadingColor(col );
insilmaril@576
   174
		}	    
insilmaril@576
   175
	} else if ( eName == "note" && 
insilmaril@576
   176
				(state == StateMapCenter ||state==StateBranch))
insilmaril@576
   177
	{	// only for backward compatibility (<1.4.6). Use htmlnote now.
insilmaril@576
   178
		state=StateNote;
insilmaril@576
   179
		if (!readNoteAttr (atts) ) return false;
insilmaril@576
   180
	} else if ( eName == "htmlnote" && state == StateMapCenter) 
insilmaril@576
   181
	{
insilmaril@576
   182
		laststate=state;
insilmaril@576
   183
		state=StateHtmlNote;
insilmaril@576
   184
    } else if ( eName == "floatimage" && 
insilmaril@576
   185
				(state == StateMapCenter ||state==StateBranch)) 
insilmaril@576
   186
	{
insilmaril@776
   187
		state=StateImage;
insilmaril@776
   188
		lastImage=model->createImage(lastBranch);
insilmaril@776
   189
		if (!readImageAttr(atts)) return false;
insilmaril@576
   190
	} else if ( (eName == "branch"||eName=="floatimage") && state == StateMap) 
insilmaril@576
   191
	{
insilmaril@576
   192
		// This is used in vymparts, which have no mapcenter!
insilmaril@576
   193
		isVymPart=true;
insilmaril@781
   194
		TreeItem *ti=model->getSelectedItem();	//FIXME-3 selection is no longer used here...
insilmaril@753
   195
		if (!ti)
insilmaril@576
   196
		{
insilmaril@576
   197
			// If a vym part is _loaded_ (not imported), 
insilmaril@576
   198
			// selection==lmo==NULL
insilmaril@576
   199
			// Treat it like ImportAdd then...
insilmaril@576
   200
			loadMode=ImportAdd;
insilmaril@746
   201
			// FIXME-3 lmo=model->first()->getLMO();		
insilmaril@741
   202
			// Do we really have no MCO when loading?????
insilmaril@741
   203
			cout << "xml-vym aborted\n";
insilmaril@576
   204
		}	
insilmaril@753
   205
		if (ti && ti->isBranchLikeType() )
insilmaril@576
   206
		{
insilmaril@776
   207
			lastBranch=(BranchItem*)ti;
insilmaril@576
   208
			if (eName=="branch")
insilmaril@576
   209
			{
insilmaril@576
   210
				state=StateBranch;
insilmaril@576
   211
				if (loadMode==ImportAdd)
insilmaril@576
   212
				{
insilmaril@776
   213
					lastBranch=model->createBranch(lastBranch);
insilmaril@576
   214
					
insilmaril@576
   215
				} else
insilmaril@753
   216
					//FIXME-2 lastBranch->clear();
insilmaril@576
   217
				readBranchAttr (atts);
insilmaril@576
   218
			} else if (eName=="floatimage")
insilmaril@576
   219
			{
insilmaril@776
   220
				state=StateImage;
insilmaril@776
   221
				lastImage=model->createImage (lastBranch);
insilmaril@776
   222
				if (!readImageAttr(atts)) return false;
insilmaril@576
   223
			} else return false;
insilmaril@576
   224
		} else return false;
insilmaril@576
   225
	} else if ( eName == "branch" && state == StateMapCenter) 
insilmaril@576
   226
	{
insilmaril@576
   227
		state=StateBranch;
insilmaril@776
   228
		lastBranch=model->createBranch(lastBranch);
insilmaril@576
   229
		readBranchAttr (atts);
insilmaril@576
   230
	} else if ( eName == "htmlnote" && state == StateBranch) 
insilmaril@576
   231
	{
insilmaril@576
   232
		laststate=state;
insilmaril@576
   233
		state=StateHtmlNote;
insilmaril@576
   234
		no.clear();
insilmaril@576
   235
		if (!atts.value( "fonthint").isEmpty() ) 
insilmaril@576
   236
			no.setFontHint(atts.value ("fonthint") );
insilmaril@576
   237
	} else if ( eName == "frame" && (state == StateBranch||state==StateMapCenter)) 
insilmaril@576
   238
	{
insilmaril@576
   239
		laststate=state;
insilmaril@576
   240
		state=StateFrame;
insilmaril@576
   241
		if (!readFrameAttr(atts)) return false;
insilmaril@576
   242
    } else if ( eName == "xlink" && state == StateBranch ) 
insilmaril@576
   243
	{
insilmaril@576
   244
		state=StateBranchXLink;
insilmaril@576
   245
		if (!readXLinkAttr (atts)) return false;
insilmaril@576
   246
    } else if ( eName == "branch" && state == StateBranch ) 
insilmaril@576
   247
	{
insilmaril@776
   248
		lastBranch=model->createBranch(lastBranch);
insilmaril@576
   249
		readBranchAttr (atts);
insilmaril@576
   250
    } else if ( eName == "html" && state == StateHtmlNote ) 
insilmaril@576
   251
	{
insilmaril@576
   252
		state=StateHtml;
insilmaril@576
   253
		htmldata="<"+eName;
insilmaril@576
   254
		readHtmlAttr(atts);
insilmaril@576
   255
		htmldata+=">";
insilmaril@576
   256
    } else if ( state == StateHtml ) 
insilmaril@576
   257
	{
insilmaril@576
   258
		// accept all while in html mode,
insilmaril@576
   259
		htmldata+="<"+eName;
insilmaril@576
   260
		readHtmlAttr(atts);
insilmaril@576
   261
		htmldata+=">";
insilmaril@576
   262
    } else
insilmaril@576
   263
        return false;   // Error
insilmaril@576
   264
    return true;
insilmaril@576
   265
}
insilmaril@576
   266
insilmaril@576
   267
bool parseVYMHandler::endElement  ( const QString&, const QString&, const QString &eName)
insilmaril@576
   268
{
insilmaril@576
   269
	/* Testing
insilmaril@660
   270
	cout << "endElement </" <<qPrintable(eName)
insilmaril@576
   271
		<<">  state=" <<state 
insilmaril@781
   272
	//	<<"  laststate=" <<laststate
insilmaril@781
   273
	//	<<"  stateStack="<<stateStack.last() 
insilmaril@781
   274
		<<"  selString="<<model->getSelectString().toStdString()
insilmaril@576
   275
		<<endl;
insilmaril@576
   276
	*/
insilmaril@576
   277
    switch ( state ) 
insilmaril@576
   278
	{
insilmaril@742
   279
		case StateMap:
insilmaril@742
   280
			mainWindow->removeProgressBar();
insilmaril@742
   281
			break;
insilmaril@768
   282
        case StateMapCenter: 
insilmaril@776
   283
			model->emitDataHasChanged (lastBranch);
insilmaril@776
   284
			lastBranch=(BranchItem*)(lastBranch->parent());
insilmaril@776
   285
			lastBranch->setLastSelectedBranch (0);	// Reset last selected to first child branch
insilmaril@768
   286
            break;
insilmaril@576
   287
        case StateBranch: 
insilmaril@781
   288
			// Empty branches may not be scrolled 
insilmaril@781
   289
			// (happens if bookmarks are imported)
insilmaril@781
   290
			if (lastBranch->isScrolled() && lastBranch->branchCount()==0) 
insilmaril@781
   291
				lastBranch->unScroll();
insilmaril@776
   292
			model->emitDataHasChanged (lastBranch);
insilmaril@781
   293
insilmaril@776
   294
			lastBranch=(BranchItem*)(lastBranch->parent());
insilmaril@776
   295
			lastBranch->setLastSelectedBranch (0);	// Reset last selected to first child branch
insilmaril@576
   296
            break;
insilmaril@576
   297
        case StateHtml: 
insilmaril@576
   298
			htmldata+="</"+eName+">";
insilmaril@576
   299
			if (eName=="html")
insilmaril@576
   300
			{
insilmaril@576
   301
				state=StateHtmlNote;  
insilmaril@576
   302
				htmldata.replace ("<br></br>","<br />");
insilmaril@576
   303
				no.setNote (htmldata);
insilmaril@776
   304
				lastBranch->setNoteObj (no);
insilmaril@576
   305
			}	
insilmaril@576
   306
			break;
insilmaril@576
   307
		default: 
insilmaril@576
   308
			break;
insilmaril@576
   309
    }  
insilmaril@576
   310
	state=stateStack.takeLast();	
insilmaril@576
   311
	return true;
insilmaril@576
   312
}
insilmaril@576
   313
insilmaril@576
   314
bool parseVYMHandler::characters   ( const QString& ch)
insilmaril@576
   315
{
insilmaril@761
   316
	//cout << "characters \""<<ch.toStdString()<<"\"  state="<<state <<"  laststate="<<laststate<<endl;
insilmaril@576
   317
insilmaril@576
   318
	QString ch_org=quotemeta (ch);
insilmaril@576
   319
    QString ch_simplified=ch.simplifyWhiteSpace();
insilmaril@576
   320
    if ( ch_simplified.isEmpty() ) return true;
insilmaril@576
   321
insilmaril@576
   322
    switch ( state ) 
insilmaril@576
   323
    {
insilmaril@576
   324
        case StateInit: break;
insilmaril@576
   325
        case StateMap: break; 
insilmaril@576
   326
		case StateMapSelect:
insilmaril@647
   327
			model->select(ch_simplified);
insilmaril@576
   328
			break;
insilmaril@576
   329
		case StateMapSetting:break;
insilmaril@576
   330
        case StateMapCenter: break;
insilmaril@576
   331
        case StateNote:
insilmaril@776
   332
			lastBranch->setNote(ch_simplified);
insilmaril@576
   333
			break;
insilmaril@576
   334
        case StateBranch: break;
insilmaril@576
   335
        case StateStandardFlag: 
insilmaril@776
   336
            lastBranch->activateStandardFlag(ch_simplified); 
insilmaril@576
   337
            break;
insilmaril@776
   338
        case StateImage: break;
insilmaril@576
   339
        case StateHtmlNote: break;
insilmaril@576
   340
        case StateHtml:
insilmaril@576
   341
			htmldata+=ch_org;
insilmaril@576
   342
			break;
insilmaril@576
   343
        case StateHeading: 
insilmaril@776
   344
            lastBranch->setHeading(ch_simplified);
insilmaril@576
   345
            break;
insilmaril@576
   346
        default: 
insilmaril@576
   347
			return false;
insilmaril@576
   348
    }
insilmaril@576
   349
    return true;
insilmaril@576
   350
}
insilmaril@576
   351
insilmaril@576
   352
QString parseVYMHandler::errorString() 
insilmaril@576
   353
{
insilmaril@576
   354
    return "the document is not in the VYM file format";
insilmaril@576
   355
}
insilmaril@576
   356
insilmaril@753
   357
bool parseVYMHandler::readBranchAttr (const QXmlAttributes& a)	//FIXME-2
insilmaril@576
   358
{
insilmaril@772
   359
	mainWindow->setProgressValue (branchesCurrent++);
insilmaril@749
   360
insilmaril@776
   361
	lastMI=lastBranch;
insilmaril@776
   362
insilmaril@756
   363
	if (!readOOAttr(a)) return false;
insilmaril@576
   364
insilmaril@576
   365
	if (!a.value( "scrolled").isEmpty() )
insilmaril@779
   366
		lastBranch->toggleScroll();	//FIXME-3 in endElement unscroll again, if branch is still empty 
insilmaril@779
   367
		// (interesting for import of KDE bookmarks)
insilmaril@763
   368
/*
insilmaril@576
   369
	if (!a.value( "frameType").isEmpty() ) 
insilmaril@576
   370
		lastOO->setFrameType (a.value("frameType")); //Compatibility 1.8.1
insilmaril@576
   371
insilmaril@576
   372
	if (!a.value( "incImgV").isEmpty() ) 
insilmaril@576
   373
	{	
insilmaril@576
   374
		if (a.value("incImgV")=="true")
insilmaril@576
   375
			lastBranch->setIncludeImagesVer(true);
insilmaril@576
   376
		else	
insilmaril@576
   377
			lastBranch->setIncludeImagesVer(false);
insilmaril@576
   378
	}	
insilmaril@576
   379
	if (!a.value( "incImgH").isEmpty() ) 
insilmaril@576
   380
	{	
insilmaril@576
   381
		if (a.value("incImgH")=="true")
insilmaril@576
   382
			lastBranch->setIncludeImagesHor(true);
insilmaril@576
   383
		else	
insilmaril@576
   384
			lastBranch->setIncludeImagesHor(false);
insilmaril@576
   385
	}	
insilmaril@753
   386
*/	
insilmaril@576
   387
	return true;	
insilmaril@576
   388
}
insilmaril@576
   389
insilmaril@777
   390
bool parseVYMHandler::readFrameAttr (const QXmlAttributes& a)	// FIXME-4 does not work if there is no lmo for treeitem
insilmaril@576
   391
{
insilmaril@777
   392
	if (lastMI)
insilmaril@576
   393
	{
insilmaril@777
   394
		OrnamentedObj* oo=(OrnamentedObj*)(lastMI->getLMO()); 
insilmaril@777
   395
		if (oo)
insilmaril@576
   396
		{
insilmaril@777
   397
			bool ok;
insilmaril@777
   398
			int x;
insilmaril@777
   399
			{
insilmaril@777
   400
				if (!a.value( "frameType").isEmpty() ) 
insilmaril@777
   401
					oo->setFrameType (a.value("frameType"));
insilmaril@777
   402
				if (!a.value( "penColor").isEmpty() ) 
insilmaril@777
   403
					oo->setFramePenColor (a.value("penColor"));
insilmaril@777
   404
				if (!a.value( "brushColor").isEmpty() ) 
insilmaril@777
   405
					oo->setFrameBrushColor (a.value("brushColor"));
insilmaril@777
   406
				if (!a.value( "padding").isEmpty() ) 
insilmaril@777
   407
				{
insilmaril@777
   408
					x=a.value("padding").toInt(&ok);
insilmaril@777
   409
					if (ok) oo->setFramePadding(x);
insilmaril@777
   410
				}	
insilmaril@777
   411
				if (!a.value( "borderWidth").isEmpty() ) 
insilmaril@777
   412
				{
insilmaril@777
   413
					x=a.value("borderWidth").toInt(&ok);
insilmaril@777
   414
					if (ok) oo->setFrameBorderWidth(x);
insilmaril@777
   415
				}	
insilmaril@777
   416
			}		
insilmaril@777
   417
			return true;
insilmaril@777
   418
		}
insilmaril@777
   419
	}
insilmaril@777
   420
	return false;
insilmaril@576
   421
}
insilmaril@576
   422
insilmaril@576
   423
bool parseVYMHandler::readOOAttr (const QXmlAttributes& a)
insilmaril@576
   424
{
insilmaril@780
   425
	if (lastMI)
insilmaril@576
   426
	{
insilmaril@576
   427
		bool okx,oky;
insilmaril@585
   428
		float x,y;
insilmaril@576
   429
		if (!a.value( "relPosX").isEmpty() ) 
insilmaril@576
   430
		{
insilmaril@576
   431
			if (!a.value( "relPosY").isEmpty() ) 
insilmaril@576
   432
			{
insilmaril@585
   433
				x=a.value("relPosX").toFloat (&okx);
insilmaril@585
   434
				y=a.value("relPosY").toFloat (&oky);
insilmaril@576
   435
				if (okx && oky  )
insilmaril@780
   436
					lastMI->setRelPos (QPointF(x,y));
insilmaril@576
   437
				else
insilmaril@576
   438
					return false;   // Couldn't read relPos
insilmaril@576
   439
			}           
insilmaril@576
   440
		}           
insilmaril@652
   441
		if (!a.value( "absPosX").isEmpty() && loadMode==NewMap ) 
insilmaril@576
   442
		{
insilmaril@576
   443
			if (!a.value( "absPosY").isEmpty() ) 
insilmaril@576
   444
			{
insilmaril@585
   445
				x=a.value("absPosX").toFloat (&okx);
insilmaril@585
   446
				y=a.value("absPosY").toFloat (&oky);
insilmaril@576
   447
				if (okx && oky  )
insilmaril@780
   448
					lastMI->setAbsPos (QPointF(x,y));
insilmaril@576
   449
				else
insilmaril@576
   450
					return false;   // Couldn't read absPos
insilmaril@576
   451
			}           
insilmaril@576
   452
		}           
insilmaril@768
   453
		//if (!a.value( "id").isEmpty() ) 
insilmaril@780
   454
		//	lastMI->setID (a.value ("id"));		// FIXME-3
insilmaril@768
   455
			
insilmaril@576
   456
		if (!a.value( "url").isEmpty() ) 
insilmaril@780
   457
			lastMI->setURL (a.value ("url"));
insilmaril@576
   458
		if (!a.value( "vymLink").isEmpty() ) 
insilmaril@780
   459
			lastMI->setVymLink (a.value ("vymLink"));
insilmaril@576
   460
		if (!a.value( "hideInExport").isEmpty() ) 
insilmaril@576
   461
			if (a.value("hideInExport")=="true")
insilmaril@780
   462
				lastMI->setHideInExport(true);
insilmaril@576
   463
insilmaril@576
   464
		if (!a.value( "hideLink").isEmpty()) 
insilmaril@576
   465
		{
insilmaril@576
   466
			if (a.value ("hideLink") =="true")
insilmaril@779
   467
				lastMI->setHideLinkUnselected(true);
insilmaril@576
   468
			else	
insilmaril@779
   469
				lastMI->setHideLinkUnselected(false);
insilmaril@576
   470
		}	
insilmaril@576
   471
	}
insilmaril@576
   472
	return true;	
insilmaril@576
   473
}
insilmaril@576
   474
insilmaril@576
   475
bool parseVYMHandler::readNoteAttr (const QXmlAttributes& a)
insilmaril@576
   476
{	// only for backward compatibility (<1.4.6). Use htmlnote now.
insilmaril@576
   477
	no.clear();
insilmaril@576
   478
	QString fn;
insilmaril@576
   479
	if (!a.value( "href").isEmpty() ) 
insilmaril@576
   480
	{
insilmaril@576
   481
		// Load note
insilmaril@576
   482
		fn=parseHREF(a.value ("href") );
insilmaril@576
   483
		QFile file (fn);
insilmaril@576
   484
		QString s;						// Reading a note
insilmaril@576
   485
insilmaril@576
   486
		if ( !file.open( QIODevice::ReadOnly) )
insilmaril@576
   487
		{
insilmaril@576
   488
			qWarning ("parseVYMHandler::readNoteAttr:  Couldn't load "+fn);
insilmaril@576
   489
			return false;
insilmaril@576
   490
		}	
insilmaril@576
   491
		QTextStream stream( &file );
insilmaril@576
   492
		QString lines;
insilmaril@576
   493
		while ( !stream.atEnd() ) {
insilmaril@576
   494
			lines += stream.readLine()+"\n"; 
insilmaril@576
   495
		}
insilmaril@576
   496
		file.close();
insilmaril@576
   497
insilmaril@576
   498
		lines ="<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body>"+lines + "</p></body></html>";
insilmaril@576
   499
		no.setNote (lines);
insilmaril@576
   500
	}		
insilmaril@576
   501
	if (!a.value( "fonthint").isEmpty() ) 
insilmaril@576
   502
		no.setFontHint(a.value ("fonthint") );
insilmaril@776
   503
	lastBranch->setNoteObj(no);
insilmaril@576
   504
	return true;
insilmaril@576
   505
}
insilmaril@576
   506
insilmaril@776
   507
bool parseVYMHandler::readImageAttr (const QXmlAttributes& a)
insilmaril@576
   508
{
insilmaril@776
   509
	lastMI=lastImage;
insilmaril@576
   510
	
insilmaril@780
   511
	//if (!readOOAttr(a)) return false;   FIXME-3
insilmaril@576
   512
insilmaril@576
   513
	if (!a.value( "href").isEmpty() )
insilmaril@576
   514
	{
insilmaril@776
   515
		// Load Image
insilmaril@776
   516
		if (!lastImage->load (parseHREF(a.value ("href") ) ))
insilmaril@576
   517
		{
insilmaril@576
   518
			QMessageBox::warning( 0, "Warning: " ,
insilmaril@776
   519
				"Couldn't load image\n"+parseHREF(a.value ("href") ));
insilmaril@776
   520
			lastImage=NULL;
insilmaril@576
   521
			return true;
insilmaril@576
   522
		}
insilmaril@576
   523
		
insilmaril@576
   524
	}	
insilmaril@576
   525
	if (!a.value( "zPlane").isEmpty() ) 
insilmaril@776
   526
		lastImage->setZValue (a.value("zPlane").toInt ());
insilmaril@596
   527
    float x,y;
insilmaril@576
   528
    bool okx,oky;
insilmaril@576
   529
	if (!a.value( "relPosX").isEmpty() ) 
insilmaril@576
   530
	{
insilmaril@576
   531
		if (!a.value( "relPosY").isEmpty() ) 
insilmaril@576
   532
		{
insilmaril@576
   533
			// read relPos
insilmaril@585
   534
			x=a.value("relPosX").toFloat (&okx);
insilmaril@585
   535
			y=a.value("relPosY").toFloat (&oky);
insilmaril@576
   536
			if (okx && oky) 
insilmaril@777
   537
				lastImage->setRelPos (QPointF (x,y) );
insilmaril@576
   538
			else
insilmaril@576
   539
				// Couldn't read relPos
insilmaril@576
   540
				return false;  
insilmaril@576
   541
		}           
insilmaril@576
   542
	}	
insilmaril@576
   543
	
insilmaril@777
   544
	//FIXME-3 if (!readOOAttr(a)) return false;
insilmaril@576
   545
insilmaril@776
   546
	if (!a.value ("originalName").isEmpty() )
insilmaril@576
   547
	{
insilmaril@776
   548
		lastImage->setOriginalFilename (a.value("originalName"));
insilmaril@576
   549
	}
insilmaril@576
   550
	return true;
insilmaril@576
   551
}
insilmaril@576
   552
insilmaril@576
   553
bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a)
insilmaril@576
   554
{
insilmaril@576
   555
	QColor col;
insilmaril@576
   556
	bool okx;
insilmaril@576
   557
	bool success=false;
insilmaril@647
   558
	XLinkObj *xlo=new XLinkObj (model->getScene());
insilmaril@576
   559
	if (!a.value( "color").isEmpty() ) 
insilmaril@576
   560
	{
insilmaril@576
   561
		col.setNamedColor(a.value("color"));
insilmaril@576
   562
		xlo->setColor (col);
insilmaril@576
   563
	}
insilmaril@576
   564
insilmaril@576
   565
	if (!a.value( "width").isEmpty() ) 
insilmaril@576
   566
	{
insilmaril@576
   567
		xlo->setWidth(a.value ("width").toInt (&okx, 10));
insilmaril@576
   568
	}
insilmaril@576
   569
insilmaril@576
   570
	// Connecting by select string for compatibility with version < 1.8.76
insilmaril@576
   571
	if (!a.value( "beginBranch").isEmpty() ) 
insilmaril@576
   572
	{ 
insilmaril@576
   573
		if (!a.value( "endBranch").isEmpty() ) 
insilmaril@576
   574
		{
insilmaril@754
   575
			TreeItem *ti=model->findBySelectString (a.value( "beginBranch"));
insilmaril@754
   576
			if (ti && ti->isBranchLikeType())
insilmaril@576
   577
			{
insilmaril@754
   578
			/* FIXME-2 xLinks
insilmaril@576
   579
				xlo->setBegin ((BranchObj*)lmo);
insilmaril@754
   580
				lmo=model->findBySelectString (a.value( "endBranch"));
insilmaril@773
   581
				if (lmo && typid (*lmo)==typid (BranchObj))
insilmaril@576
   582
				{
insilmaril@576
   583
					xlo->setEnd ((BranchObj*)(lmo));
insilmaril@576
   584
					xlo->activate();
insilmaril@596
   585
					success=true;
insilmaril@576
   586
				}
insilmaril@754
   587
			*/
insilmaril@576
   588
			}
insilmaril@576
   589
		}           
insilmaril@576
   590
	}	
insilmaril@576
   591
insilmaril@576
   592
	// object ID is used starting in version 1.8.76
insilmaril@754
   593
	/* FIXME-2 xLinks
insilmaril@576
   594
	if (!a.value( "beginID").isEmpty() ) 
insilmaril@576
   595
	{ 
insilmaril@576
   596
		if (!a.value( "endID").isEmpty() ) 
insilmaril@576
   597
		{
insilmaril@647
   598
			LinkableMapObj *lmo=model->findID (a.value( "beginID"));
insilmaril@773
   599
			if (lmo && typid (*lmo)==typid (BranchObj))
insilmaril@576
   600
			{
insilmaril@576
   601
				xlo->setBegin ((BranchObj*)lmo);
insilmaril@647
   602
				lmo=model->findID (a.value( "endID"));
insilmaril@773
   603
				if (lmo && typid (*lmo)==typid (BranchObj))
insilmaril@576
   604
				{
insilmaril@576
   605
					xlo->setEnd ((BranchObj*)(lmo));
insilmaril@576
   606
					xlo->activate();
insilmaril@596
   607
					success=true;
insilmaril@576
   608
				}
insilmaril@576
   609
			}
insilmaril@576
   610
		}           
insilmaril@576
   611
	}	
insilmaril@754
   612
	*/
insilmaril@576
   613
	if (!success) delete (xlo);
insilmaril@596
   614
	return true;	// xLinks can only be established at the "end branch", return true
insilmaril@576
   615
}
insilmaril@576
   616
insilmaril@576
   617
bool parseVYMHandler::readHtmlAttr (const QXmlAttributes& a)
insilmaril@576
   618
{
insilmaril@576
   619
	for (int i=1; i<=a.count(); i++)
insilmaril@576
   620
		htmldata+=" "+a.localName(i-1)+"=\""+a.value(i-1)+"\"";
insilmaril@576
   621
	return true;
insilmaril@576
   622
}
insilmaril@576
   623
insilmaril@576
   624
bool parseVYMHandler::readSettingAttr (const QXmlAttributes& a)
insilmaril@576
   625
{
insilmaril@576
   626
	if (!a.value( "key").isEmpty() ) 
insilmaril@576
   627
	{
insilmaril@576
   628
		if (!a.value( "value").isEmpty() ) 
insilmaril@721
   629
			settings.setLocalEntry (model->getDestPath(), a.value ("key"), a.value ("value"));
insilmaril@576
   630
		else
insilmaril@576
   631
			return false;
insilmaril@576
   632
		
insilmaril@576
   633
	} else
insilmaril@576
   634
		return false;
insilmaril@576
   635
	
insilmaril@576
   636
	return true;
insilmaril@576
   637
}