r13760 by jghali - - fix retrieval of master page names when importing master pages - fix crash on page/master page import

scribus-commit scribus-commit at lists.scribus.net
Wed Jul 8 23:00:28 CEST 2009


Revision: 13760
Author: jghali
Date: 2009-07-08T21:01:59.162070Z
Commit message: - fix retrieval of master page names when importing master pages
- fix crash on page/master page import

Changeset: 
M  /trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
M  /trunk/Scribus/scribus/scxmlstreamreader.h
M  /trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
M  /trunk/Scribus/scribus/scxmlstreamreader.cpp

Diffs:
Index: scribus/scxmlstreamreader.h
===================================================================
--- scribus/scxmlstreamreader.h	(revision 13759)
+++ scribus/scxmlstreamreader.h	(revision 13760)
@@ -52,6 +52,8 @@
 public:
 	ScXmlStreamReader(const QString& string) : QXmlStreamReader(string) {};
 	ScXmlStreamAttributes scAttributes(void) const;
+
+	void readToElementEnd(void);
 };
 
 #endif
Index: scribus/scxmlstreamreader.cpp
===================================================================
--- scribus/scxmlstreamreader.cpp	(revision 13759)
+++ scribus/scxmlstreamreader.cpp	(revision 13760)
@@ -159,3 +159,22 @@
 	ScXmlStreamAttributes attrs(attributes());
 	return attrs;
 }
+
+void ScXmlStreamReader::readToElementEnd(void)
+{
+	if (!isStartElement())
+		return;
+	int count = 1;
+	QStringRef tagName = name();
+	while(!atEnd() && !hasError())
+	{
+		readNext();
+		if (isStartElement() && (name() == tagName))
+			++count;
+		if (isEndElement() && (name() == tagName))
+			--count;
+		if (count == 0)
+			break;
+	}
+}
+
Index: scribus/plugins/fileloader/scribus150format/scribus150format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(revision 13759)
+++ scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(revision 13760)
@@ -2919,12 +2919,8 @@
 			if ((Mpage && tagName != "MASTEROBJECT") || (!Mpage && tagName == "MASTEROBJECT"))
 			{
 				// Go to end of node
-				while(!reader.atEnd() && !reader.hasError())
-				{
-					reader.readNext();
-					if (reader.isEndElement() && reader.name() == tagName)
-						break;
-				}
+				reader.readToElementEnd();
+				continue;
 			}
 			if (attrs.valueAsInt("OwnPage") != pageNumber)
 			{			
@@ -2932,6 +2928,7 @@
 					itemRemap[itemCount++] = -1;
 				else if (tagName == "MASTEROBJECT")
 					itemRemapM[itemCountM++] = -1;
+				reader.readToElementEnd();
 			}
 			else
 			{
@@ -3307,7 +3304,7 @@
 
 bool Scribus150Format::readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames)
 {
-	QString PgNam;
+	QString pageName;
 	int counter = 0;
 	int counter2 = 0;
 	QString f(readSLA(fileName));
@@ -3338,8 +3335,12 @@
 			counter++;
 		if(tagName == "MASTERPAGE")
 		{
-			counter2++;
-			masterPageNames.append(PgNam);
+			pageName = reader.scAttributes().valueAsString("NAM");
+			if (!pageName.isEmpty())
+			{
+				counter2++;
+				masterPageNames.append(pageName);
+			}
 		}
 	}
 	*num1 = counter;
Index: scribus/plugins/fileloader/scribus134format/scribus134format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus134format/scribus134format.cpp	(revision 13759)
+++ scribus/plugins/fileloader/scribus134format/scribus134format.cpp	(revision 13760)
@@ -2962,12 +2962,8 @@
 			if ((Mpage && tagName != "MASTEROBJECT") || (!Mpage && tagName == "MASTEROBJECT"))
 			{
 				// Go to end of node
-				while(!reader.atEnd() && !reader.hasError())
-				{
-					reader.readNext();
-					if (reader.isEndElement() && reader.name() == tagName)
-						break;
-				}
+				reader.readToElementEnd();
+				continue;
 			}
 			if (attrs.valueAsInt("OwnPage") != pageNumber)
 			{			
@@ -2975,6 +2971,7 @@
 					itemRemap[itemCount++] = -1;
 				else if (tagName == "MASTEROBJECT")
 					itemRemapM[itemCountM++] = -1;
+				reader.readToElementEnd();
 			}
 			else
 			{
@@ -3350,7 +3347,7 @@
 
 bool Scribus134Format::readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames)
 {
-	QString PgNam;
+	QString pageName;
 	int counter = 0;
 	int counter2 = 0;
 	QString f(readSLA(fileName));
@@ -3381,8 +3378,12 @@
 			counter++;
 		if(tagName == "MASTERPAGE")
 		{
-			counter2++;
-			masterPageNames.append(PgNam);
+			pageName = reader.scAttributes().valueAsString("NAM");
+			if (!pageName.isEmpty())
+			{
+				counter2++;
+				masterPageNames.append(pageName);
+			}
 		}
 	}
 	*num1 = counter;




More information about the scribus-commit mailing list