r15439 by craig - Another attempt at fixing render frame default command code.. nuke your latex commands from prefs to fix

scribus-commit scribus-commit at lists.scribus.net
Mon Aug 23 22:51:11 CEST 2010


Author: craig
Date: Mon Aug 23 20:51:11 2010
New Revision: 15439

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15439
Log:
Another attempt at fixing render frame default command code.. nuke your latex commands from prefs to fix

Modified:
    trunk/Scribus/scribus/latexhelpers.cpp
    trunk/Scribus/scribus/latexhelpers.h
    trunk/Scribus/scribus/prefsmanager.cpp
    trunk/Scribus/scribus/scribus.cpp

Modified: trunk/Scribus/scribus/latexhelpers.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15439&path=/trunk/Scribus/scribus/latexhelpers.cpp
==============================================================================
--- trunk/Scribus/scribus/latexhelpers.cpp (original)
+++ trunk/Scribus/scribus/latexhelpers.cpp Mon Aug 23 20:51:11 2010
@@ -45,17 +45,22 @@
 	if (disable_highlighting) return;
 
 	if (!rules) return;
-	foreach (LatexHighlighterRule *rule, *rules) {
+	foreach (LatexHighlighterRule *rule, *rules)
+	{
 		int index = text.indexOf(rule->regex);
 		while (index >= 0) {
 			int length;
-			if (rule->regex.numCaptures() == 0) {
+			if (rule->regex.numCaptures() == 0)
+			{
 				length = rule->regex.matchedLength();
-			} else {
+			}
+			else
+			{
 				length = rule->regex.cap(1).length();
 				index = rule->regex.pos(1);
 			}
-			if (length == 0) {
+			if (length == 0)
+			{
 				qWarning() << "Highlighter pattern" << rule->regex.pattern() << "matched a zero length string. This would lead to an infinite loop. Aborting. Please fix this pattern!";
 				break;
 			}
@@ -81,11 +86,10 @@
 QString LatexConfigParser::absoluteFilename(QString fn)
 {
 	QFileInfo fi(fn);
-	if (!fi.exists()) {
+	if (!fi.exists())
 		return configBase() + fn;
-	} else {
+	else
 		return fn;
-	}
 }
 
 //TODO: Pass this information to LatexEditor, so the second parser can be removed
@@ -95,7 +99,8 @@
 	m_error = "";
 	m_filename = fn;
 	QFile f(fn);
-	if (!f.open(QIODevice::ReadOnly)) {
+	if (!f.open(QIODevice::ReadOnly))
+	{
 		QMessageBox::critical(0, QObject::tr("Error"), "<qt>" + 
 				QObject::tr("Opening the configfile %1 failed! %2").arg(
 						fn, f.errorString())
@@ -103,38 +108,39 @@
 	}
 	xml.setDevice(&f);
 	
-	while (!xml.atEnd()) {
+	while (!xml.atEnd())
+	{
 		xml.readNext();
-		if (xml.isWhitespace() || xml.isComment() || xml.isStartDocument() || xml.isEndDocument()) continue;
-		if (xml.isStartElement() && xml.name() == "editorsettings") {
+		if (xml.isWhitespace() || xml.isComment() || xml.isStartDocument() || xml.isEndDocument())
+			continue;
+		if (xml.isStartElement() && xml.name() == "editorsettings")
+		{
 			m_description = xml.attributes().value("description").toString();
 			m_icon = xml.attributes().value("icon").toString();
-			if (m_description.isEmpty()) {
+			if (m_description.isEmpty())
 				m_description = fn;
-			}
 			parseElements();
-		} else {
-			formatError("Unexpected element at root level"+xml.name().toString()+", Token String: "+
-								 xml.tokenString());
-		}
-	}
-	if (xml.hasError()) {
+		}
+		else
+			formatError("Unexpected element at root level"+xml.name().toString()+", Token String: "+ xml.tokenString());
+	}
+	if (xml.hasError())
 		formatError(xml.errorString());
-	}
 	f.close();
-	if (!m_error.isEmpty()) {
+	if (!m_error.isEmpty())
 		return false;
-	}
 	return true;
 }
 
 void LatexConfigParser::parseElements()
 {
-	while (!xml.atEnd()) {
+	while (!xml.atEnd())
+	{
 		xml.readNext();
 		if (xml.isEndElement() && xml.name() == "editorsettings") break;
 		if (xml.isWhitespace() || xml.isComment() || xml.isEndElement()) continue;
-		if (!xml.isStartElement()) {
+		if (!xml.isStartElement())
+		{
 			formatError("Unexpected element in <editorsettings>"+xml.name().toString()+", Token String: "+
 								 xml.tokenString());
 			continue;
@@ -170,24 +176,29 @@
 
 bool LatexConfigParser::StrRefToBool(const QStringRef &str) const
 {
-	if (str == "1" || str == "true") return true;
-	if (str == "0" || str == "false" || str.isEmpty()) return false;
+	if (str == "1" || str == "true")
+		return true;
+	if (str == "0" || str == "false" || str.isEmpty())
+		return false;
 	qWarning() << "Invalid bool string:" << str.toString();
 	return false;
 }
 
 void LatexConfigParser::parseHighlighter()
 {
-	foreach (LatexHighlighterRule *rule, highlighterRules) {
+	foreach (LatexHighlighterRule *rule, highlighterRules)
 		delete rule;
-	}
 	highlighterRules.clear();
 	while (!xml.atEnd()) {
 		xml.readNext();
-		if (xml.isWhitespace() || xml.isComment()) continue;
-		if (xml.isEndElement() && xml.name() == "highlighter") break;
-		if (xml.isEndElement() && xml.name() == "rule") continue;
-		if (!xml.isStartElement() || xml.name() != "rule") {
+		if (xml.isWhitespace() || xml.isComment())
+			continue;
+		if (xml.isEndElement() && xml.name() == "highlighter")
+			break;
+		if (xml.isEndElement() && xml.name() == "rule")
+			continue;
+		if (!xml.isStartElement() || xml.name() != "rule")
+		{
 			formatError("Unexpected element in <highlighter>: "+
 				xml.name().toString()+", Token String: "+
 				xml.tokenString());
@@ -200,7 +211,8 @@
 		bool minimal = StrRefToBool(xml.attributes().value("minimal"));
 		QString colorStr = xml.attributes().value("color").toString();
 		QColor color(colorStr);
-		if (!color.isValid()) {
+		if (!color.isValid())
+		{
 			color.fromRgb(0, 0, 0); //Black
 			if (!colorStr.isEmpty())
 				qWarning() << "Invalid color:" << colorStr;
@@ -208,9 +220,8 @@
 		LatexHighlighterRule *newRule = new LatexHighlighterRule();
 		newRule->format.setForeground(color);
 		newRule->format.setFontItalic(italic);
-		if (bold) {
+		if (bold)
 			newRule->format.setFontWeight(QFont::Bold);
-		}
 		newRule->format.setFontUnderline(underline);
 		newRule->regex.setPattern(regex);
 		newRule->regex.setMinimal(minimal);
@@ -226,61 +237,65 @@
 	QString title = "";
 	QString name, text, default_value;
 	
-	while (!xml.atEnd()) {
+	while (!xml.atEnd())
+	{
 		xml.readNext();
 		if (xml.isWhitespace() || xml.isComment()) continue;
 		if (xml.isEndElement() && xml.name() == "tab") break;
-		if (!xml.isStartElement()) {
+		if (!xml.isStartElement())
+		{
 			formatError("Unexpected element in <tab>: "+xml.name().toString()+", Token String: "+
 								 xml.tokenString());
 			continue;
 		}
-		if (xml.name() == "title") {
-			if (!title.isEmpty()) {
+		if (xml.name() == "title")
+		{
+			if (!title.isEmpty())
 				formatError("Second <title> tag in <tab>");
-			}
 			title = xml.readI18nText();
-		} else if (xml.name() == "item") {
-			if (!itemstab) {
+		}
+		else if (xml.name() == "item")
+		{
+			if (!itemstab)
 				formatError("Found <item> in a 'settings'-tab!");
-			}
 			QString value = xml.attributes().value("value").toString();
 			QString img = xml.attributes().value("image").toString();
 			text = xml.readI18nText();
-		} else if (xml.name() == "comment" || xml.name() == "font" 
-						 || xml.name() == "spinbox" || xml.name() == "color" 
-								 || xml.name() == "text" || xml.name() == "list") {
+		}
+		else if (xml.name() == "comment" || xml.name() == "font"
+				|| xml.name() == "spinbox" || xml.name() == "color"
+				|| xml.name() == "text" || xml.name() == "list")
+		{
 			//TODO: Store this + attributes in a list
-							 QString tagname = xml.name().toString();
-							 name = xml.attributes().value("name").toString();
-							 default_value = xml.attributes().value("default").toString();
-							 if (xml.name() != "list") {
-								 text = xml.readI18nText();
-							 } else {
-								 ignoreList();
-							 }
-							 if (!name.isEmpty()) {
-								 if (properties.contains(name)) {
-									 formatError("Redeclared setting with name: " + name);
-								 } else {
-									 properties.insert(name, default_value);
-								 }
-							 }
-							 //TODO: qDebug() << "For future use:" << tagname << name << text << default_value;
-								 } else {
-									 formatError("Unexpected element in <tab>: " + xml.name().toString());
-								 }
+			QString tagname = xml.name().toString();
+			name = xml.attributes().value("name").toString();
+			default_value = xml.attributes().value("default").toString();
+			if (xml.name() != "list")
+				text = xml.readI18nText();
+			else
+				ignoreList();
+			if (!name.isEmpty())
+			{
+				if (properties.contains(name))
+					formatError("Redeclared setting with name: " + name);
+				else
+					properties.insert(name, default_value);
+			}
+			//TODO: qDebug() << "For future use:" << tagname << name << text << default_value;
+		}
+		else
+			formatError("Unexpected element in <tab>: " + xml.name().toString());
 	}
 	
-	if (title.isEmpty()) {
+	if (title.isEmpty())
 		formatError("Tab ended here, but no title was found!");
-	}
 }
 
 void LatexConfigParser::ignoreList()
 {
 	//TODO: Quick hack to avoid real parsing
-	while (!xml.atEnd()) {
+	while (!xml.atEnd())
+	{
 		xml.readNext();
 		if (xml.isEndElement() && xml.name() == "list") break;
 	}
@@ -291,11 +306,10 @@
 	QFileInfo f(m_filename);
 	QString fileName=f.fileName();
 	QString command = PrefsManager::instance()->latexCommands()[fileName];
-	if (command.isEmpty()) {
+	if (command.isEmpty())
 		return m_executable;
-	} else {
+	else
 		return command;
-	}
 }
 
 QString I18nXmlStreamReader::readI18nText(bool unindent)
@@ -384,23 +398,24 @@
 
 LatexConfigCache* LatexConfigCache::instance()
 {
-	if (!_instance) {
+	if (!_instance)
 		_instance = new LatexConfigCache();
-	}
 	return _instance;
 }
 
 LatexConfigParser* LatexConfigCache::parser(QString filename, bool warnOnError)
 {
-	if (parsers.contains(filename)) {
-		if (warnOnError && error[filename]) {
+	if (parsers.contains(filename))
+	{
+		if (warnOnError && error[filename])
+		{
 			//Recreate element as error might have been fixed.
 			delete parsers[filename];
 			createParser(filename, warnOnError);
 		}
-	} else {
+	}
+	else
 		createParser(filename, warnOnError);
-	}
 	return parsers[filename];
 }
 
@@ -411,7 +426,8 @@
 	bool hasError = !parser->parseConfigFile(filename);
 	parsers[filename] = parser;
 	error[filename] = hasError;
-	if (hasError) {
+	if (hasError)
+	{
 		QMessageBox::critical(0, QObject::tr("Error"), "<qt>" + 
 				QObject::tr("Parsing the configfile %1 failed! Depending on the type of the error "
 						"render frames might not work correctly!\n%2").arg(
@@ -422,9 +438,8 @@
 
 bool LatexConfigCache::hasError(QString filename)
 {
-	if (!error.contains(filename)) {
+	if (!error.contains(filename))
 		return true;
-	}
 	return error[filename];
 }
 
@@ -435,11 +450,25 @@
 	files = dir.entryList(QStringList("*.xml"));
 	files.sort();
 	int i;
-	for (i = 0; i < files.size(); i++) {
-		if (files[i].compare("sample.xml",Qt::CaseInsensitive)==0) {
+	for (i = 0; i < files.size(); i++)
+	{
+		if (files[i].compare("sample.xml",Qt::CaseInsensitive)==0)
+		{
 			files.removeAt(i);
 			i--;
 		}
 	}
 	return files;
 }
+
+QMap<QString, QString> LatexConfigCache::defaultCommands()
+{
+	QStringList configFiles = PrefsManager::instance()->latexConfigs();
+	QMap<QString, QString> configCmds;
+	foreach (QString configFile, configFiles)
+	{
+		LatexConfigParser *config = LatexConfigCache::instance()->parser(configFile);
+		configCmds.insert(configFile, config->executable());
+	}
+	return configCmds;
+}

Modified: trunk/Scribus/scribus/latexhelpers.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15439&path=/trunk/Scribus/scribus/latexhelpers.h
==============================================================================
--- trunk/Scribus/scribus/latexhelpers.h (original)
+++ trunk/Scribus/scribus/latexhelpers.h Mon Aug 23 20:51:11 2010
@@ -96,6 +96,7 @@
 	public:
 		static LatexConfigCache* instance();
 		static QStringList defaultConfigs();
+		static QMap<QString, QString> defaultCommands();
 		LatexConfigCache() {}
 		LatexConfigParser* parser(QString filename, bool warnOnError = false);
 		bool hasError(QString filename);

Modified: trunk/Scribus/scribus/prefsmanager.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15439&path=/trunk/Scribus/scribus/prefsmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/prefsmanager.cpp (original)
+++ trunk/Scribus/scribus/prefsmanager.cpp Mon Aug 23 20:51:11 2010
@@ -320,7 +320,7 @@
 	appPrefs.extToolPrefs.extBrowserExecutable = "";
 	appPrefs.extToolPrefs.uniconvExecutable = "uniconv";
 	appPrefs.extToolPrefs.latexConfigs = LatexConfigCache::defaultConfigs();
-	appPrefs.extToolPrefs.latexCommands.clear();
+	appPrefs.extToolPrefs.latexCommands = LatexConfigCache::defaultCommands();
 	appPrefs.extToolPrefs.latexEditorExecutable = "";
 	appPrefs.extToolPrefs.latexResolution = 72;
 	appPrefs.extToolPrefs.latexForceDpi = true;
@@ -999,8 +999,10 @@
 		return false;
 	bool foundAny=false;
 	foreach (QString cmd, appPrefs.extToolPrefs.latexCommands)
+	{
 		if (fileInPath(cmd))
 			foundAny=true;
+	}
 	return foundAny;
 }
 

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15439&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Mon Aug 23 20:51:11 2010
@@ -6172,13 +6172,13 @@
 void ScribusMainWindow::setAppModeByToggle(bool isOn, int newMode)
 {
 	keyrep=false;
-	/*
+
 	if (newMode==modeDrawLatex && !prefsManager->renderFrameConfigured())
 	{
 		QMessageBox::critical(this, "Render Frames Not Configured", "Scribus Preferences do not contain valid Render Frame configuration, please check these settings");
 		return;
 	}
-	*/
+
 	if (doc && isOn)
 		view->requestMode(newMode);
 	else




More information about the scribus-commit mailing list