View Issue Details

IDProjectCategoryView StatusLast Update
0002518ScribusInternalpublic2005-09-08 08:54
ReporterringercAssigned Toringerc 
PriorityhighSeverityblockReproducibilityalways
Status closedResolutionfixed 
Platformx86 LinuxOSFedora CoreOS Version3
Product Version1.2.3cvs 
Fixed in Version1.2.3cvs 
Summary0002518: Prefs corruption in 1.2.x
DescriptionThis bug is the 1.2.x version of 0000349. It turns out that the 1.2.2.1 bug is somewhat different, but it boils down to the same thing - in a utf-8 locale, preferences are corrupted due to incorrect use of Qt string functions and the reliance on implicit conversions between character and byte strings.

In 1.2.2.1 the prefs are just corrupted differently. Colour and recent document names are being corrupted on write. Colour names are not being loaded correctly either, so they get more and more mangled. There's no correct old loading code to retain - we just load them with the new, corrected code. If they're uncorrupted, life goes on. If they are corrupted, they'll generally still load fine, just with the corrupted text in some names etc ... not much to be done about it.

Here's the plan:

1.2.3 will look first for scribus123.rc and load that by preference. If it does not find that file, it'll look for scribus.rc and load that. Both are loaded using the same code, as scribus123.rc is always valid, and scribus.rc is either valid, or unrecoverably mangled. There's no point in retaining the old loading code. [DONE]

1.3.x must then be tweaked to know to look for scribus123.rc in preference to scribus12.rc . [TODO]

Note that nothing much can be done for the 1.2.2.1 prefs if they were saved under a unicode locale - they're corrupt, and they're not coming back.
Additional InformationThis will mean that uses switching back to <= 1.2.2.1 after using >= 1.2.3 will be not see prefs changes made by the newer version. I don't see that as a major issue - most uses will only be upgrading, and their prefs will be imported when doing so. It's better than corrupting their clean 1.2.3 prefs if they run 1.2.2.1 .
TagsNo tags attached.
Patch

Relationships

related to 0000349 closedringerc If a file is saved under a default name under a non-English locale it does not show up in the "Recent documents" submenu. 
child of 0002215 closedjghali Audit and fix text encoding handling 

Activities

ringerc

2005-09-02 09:51

reporter   ~0006340

Proposed fix attached.

2005-09-02 09:57

 

encoding.diff (3,762 bytes)   
? Document-1.pdf
? doc/en/tutorials/short-words/Makefile
? doc/en/tutorials/short-words/Makefile.in
? plugins/gettext/odtim/.deps
? plugins/gettext/odtim/.libs
? plugins/gettext/odtim/Makefile
? plugins/gettext/odtim/Makefile.in
? plugins/gettext/odtim/contentreader.lo
? plugins/gettext/odtim/libodtimplugin.la
? plugins/gettext/odtim/odtdia.lo
? plugins/gettext/odtim/odtdia.moc
? plugins/gettext/odtim/odtim.lo
? plugins/gettext/odtim/stylereader.lo
? plugins/scriptplugin/editmacrodialog.cpp
? plugins/scriptplugin/editmacrodialog.h
? plugins/scriptplugin/managemacrosdialog.cpp
? plugins/scriptplugin/managemacrosdialog.h
? plugins/scriptplugin/samples/Makefile
? plugins/scriptplugin/samples/Makefile.in
? plugins/scriptplugin/scripts/Makefile
? plugins/scriptplugin/scripts/Makefile.in
Index: scribus.cpp
===================================================================
RCS file: /cvs/Scribus/scribus/scribus.cpp,v
retrieving revision 1.292
diff -u -r1.292 scribus.cpp
--- scribus.cpp	29 Aug 2005 20:55:09 -0000	1.292
+++ scribus.cpp	2 Sep 2005 09:56:49 -0000
@@ -7145,7 +7145,7 @@
 	Prefs.PrinterFile = PDef.Dname;
 	Prefs.PrinterCommand = PDef.Command;
 	ScriXmlDoc *ss = new ScriXmlDoc();
-	ss->WritePref(&Prefs, PrefsPfad+"/scribus.rc");
+	ss->WritePref(&Prefs, PrefsPfad+"/scribus123.rc");
 	delete ss;
 	//Continue with new Prefs Format
 	SavePrefsXML();
@@ -7167,7 +7167,13 @@
 void ScribusApp::ReadPrefs()
 {
 	ScriXmlDoc *ss = new ScriXmlDoc();
-	bool erg = ss->ReadPref(&Prefs, PrefsPfad+"/scribus.rc", splash);
+	QString loadPrefsFileName(PrefsPfad+"/scribus123.rc");
+	if (!QFile::exists(loadPrefsFileName))
+		// Import potentially mangled prefs generated by 1.2.2.1 and older
+		// These will either be valid utf-8, or damaged in ways that let
+		// us still load them but with 8-bit text mangled.
+		loadPrefsFileName = PrefsPfad+"/scribus.rc";
+	bool erg = ss->ReadPref(&Prefs, loadPrefsFileName, splash);
 	delete ss;
 	if (!erg)
 		return;
@@ -7183,11 +7189,11 @@
 	uint max = QMIN(Prefs.RecentDCount, Prefs.RecentDocs.count());
 	for (uint m = 0; m < max; ++m)
 	{
-		QFileInfo fd(QString::fromUtf8(Prefs.RecentDocs[m]));
+		QFileInfo fd(Prefs.RecentDocs[m]);
 		if (fd.exists())
 		{
-			RecentDocs.append(QString::fromUtf8(Prefs.RecentDocs[m]));
-			recentMenu->insertItem(QString::fromUtf8(Prefs.RecentDocs[m]));
+			RecentDocs.append(Prefs.RecentDocs[m]);
+			recentMenu->insertItem(Prefs.RecentDocs[m]);
 		}
 	}
 	MaPal->move(Prefs.Mapalx, Prefs.Mapaly);
Index: scribusXml.cpp
===================================================================
RCS file: /cvs/Scribus/scribus/scribusXml.cpp,v
retrieving revision 1.104
diff -u -r1.104 scribusXml.cpp
--- scribusXml.cpp	5 Jul 2005 00:10:31 -0000	1.104
+++ scribusXml.cpp	2 Sep 2005 09:56:50 -0000
@@ -3190,7 +3190,8 @@
 	if(!f.open(IO_WriteOnly))
 		return;
 	QTextStream s(&f);
-	s<<docu.toCString();
+	s.setEncoding(QTextStream::UnicodeUTF8);
+	s<<docu.toString();
 	f.close();
 }
 
@@ -3200,8 +3201,13 @@
 	QFile f(ho);
 	if(!f.open(IO_ReadOnly))
 		return false;
-	if(!docu.setContent(&f))
+	QTextStream ts(&f);
+	ts.setEncoding(QTextStream::UnicodeUTF8);
+	QString errorMsg;
+	int errorLine = 0, errorColumn = 0;
+	if( !docu.setContent(ts.read(), &errorMsg, &errorLine, &errorColumn) )
 	{
+		qDebug("Failed to read prefs XML: %s at line %i, col %i", errorMsg.local8Bit().data(), errorLine, errorColumn);
 		f.close();
 		return false;
 	}
@@ -3469,7 +3475,7 @@
 				lf.setNamedColor(dc.attribute("CMYK"));
 			else
 				lf.fromQColor(QColor(dc.attribute("RGB")));
-		  Vorein->DColors[dc.attribute("NAME")] = lf;
+			Vorein->DColors[dc.attribute("NAME")] = lf;
 		}
 		if (dc.tagName()=="Substitute")
 		  Vorein->GFontSub[dc.attribute("Name")] = dc.attribute("Replace");
encoding.diff (3,762 bytes)   

ringerc

2005-09-02 10:00

reporter   ~0006341

My theory on why we haven't had many reports of this is simply that many people who use 8-bit text still don't use utf-8 locales. It is, after all, not trivial to convert to a utf-8 locale, and if you have existing filesystems, documents etc in the old encoding it's often easier to just stick with that.

Users with utf-8 locales will tend to be those using modern distros who don't have much in the way of 8-bit text that'll be affected by a locale change. These folks, of course, mostly won't notice the problems.

ringerc

2005-09-02 10:55

reporter   ~0006344

Changes checked in. Please test and close if this fixes the issue.

A matching change to load the new scribus123.rc in preference to scribus.rc has been checked into 1.3.1cvs.

plinnell

2005-09-02 12:25

viewer   ~0006349

the prefs are saving fine in my testing

Issue History

Date Modified Username Field Change
2005-09-02 08:21 ringerc New Issue
2005-09-02 08:59 ringerc Description Updated
2005-09-02 09:51 ringerc File Added: encoding.diff
2005-09-02 09:51 ringerc Note Added: 0006340
2005-09-02 09:57 ringerc File Deleted: encoding.diff
2005-09-02 09:57 ringerc File Added: encoding.diff
2005-09-02 09:57 ringerc Relationship added related to 0000349
2005-09-02 09:58 ringerc Relationship added child of 0002215
2005-09-02 10:00 ringerc Note Added: 0006341
2005-09-02 10:06 plinnell Relationship added related to 0002519
2005-09-02 10:55 ringerc Status assigned => resolved
2005-09-02 10:55 ringerc Fixed in Version => 1.2.3
2005-09-02 10:55 ringerc Resolution open => fixed
2005-09-02 10:55 ringerc Note Added: 0006344
2005-09-02 10:55 ringerc Relationship deleted related to 0002519
2005-09-02 12:25 plinnell Note Added: 0006349
2005-09-02 12:25 plinnell Fixed in Version 1.2.3 => 1.2.3cvs
2005-09-08 08:54 ringerc Status resolved => closed