r22150 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Fri Sep 1 10:44:11 UTC 2017
Author: jghali
Date: Fri Sep 1 10:44:10 2017
New Revision: 22150
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22150
Log:
fix potential crashes in charstyle widget caused by unexpected languages strings such as "fr_FR.UTF-8"
Modified:
trunk/Scribus/scribus/langmgr.cpp
trunk/Scribus/scribus/langmgr.h
trunk/Scribus/scribus/prefsmanager.cpp
trunk/Scribus/scribus/scribusapp.cpp
trunk/Scribus/scribus/ui/smcstylewidget.cpp
trunk/Scribus/scribus/util.cpp
trunk/Scribus/scribus/util.h
Modified: trunk/Scribus/scribus/langmgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22150&path=/trunk/Scribus/scribus/langmgr.cpp
==============================================================================
--- trunk/Scribus/scribus/langmgr.cpp (original)
+++ trunk/Scribus/scribus/langmgr.cpp Fri Sep 1 10:44:10 2017
@@ -829,12 +829,56 @@
return "";
}
+const QString LanguageManager::getShortAbbrevFromAbbrevDecomposition(QString langAbbrev)
+{
+ int tIndex = langTableIndex(langAbbrev);
+ if (tIndex >= 0)
+ return m_langTable[tIndex].m_priAbbrev;
+
+ QStringList abbrevs = getAbbrevDecomposition(langAbbrev);
+ for (int i = 1; i < abbrevs.count(); ++i)
+ {
+ tIndex = langTableIndex(abbrevs.at(i));
+ if (tIndex >= 0)
+ return m_langTable[tIndex].m_priAbbrev;
+ }
+
+ return "";
+}
+
const QString LanguageManager::getAlternativeAbbrevfromAbbrev(QString langAbbrev)
{
int i=langTableIndex(langAbbrev);
if (i!=-1)
return m_langTable[i].m_altAbbrev;
return "";
+}
+
+QStringList LanguageManager::getAbbrevDecomposition(QString langAbbrev)
+{
+ QStringList abbrevs;
+ abbrevs.append(langAbbrev);
+
+ QString curAbbrev = langAbbrev;
+ QString delimiters = QString::fromLatin1("_.");
+
+ while (true)
+ {
+ int rightMost = 0;
+ for (int i = 0; i < delimiters.length(); i++)
+ {
+ int k = curAbbrev.lastIndexOf(delimiters[i]);
+ if (k > rightMost)
+ rightMost = k;
+ }
+
+ if (rightMost == 0)
+ break;
+
+ curAbbrev.truncate(rightMost);
+ abbrevs.append(curAbbrev);
+ }
+ return abbrevs;
}
void LanguageManager::fillInstalledStringList(QStringList *stringListToFill)
Modified: trunk/Scribus/scribus/langmgr.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22150&path=/trunk/Scribus/scribus/langmgr.h
==============================================================================
--- trunk/Scribus/scribus/langmgr.h (original)
+++ trunk/Scribus/scribus/langmgr.h Fri Sep 1 10:44:10 2017
@@ -51,7 +51,9 @@
const QString getLangFromTransLang(QString transLang);
const QString getTransLangFromLang(QString lang);
const QString getShortAbbrevFromAbbrev(QString langAbbrev);
+ const QString getShortAbbrevFromAbbrevDecomposition(QString langAbbrev);
const QString getAlternativeAbbrevfromAbbrev(QString langAbbrev);
+ QStringList getAbbrevDecomposition(QString langAbbrev);
void fillInstalledStringList(QStringList *stringListToFill);
void fillInstalledGUIStringList(QStringList *stringListToFill);
void fillInstalledHyphStringList(QStringList *stringListToFill);
Modified: trunk/Scribus/scribus/prefsmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22150&path=/trunk/Scribus/scribus/prefsmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/prefsmanager.cpp (original)
+++ trunk/Scribus/scribus/prefsmanager.cpp Fri Sep 1 10:44:10 2017
@@ -54,6 +54,7 @@
#include "scribusstructs.h"
#include "sctextstream.h"
#include "units.h"
+#include "util.h"
#include "util_color.h"
#include "util_file.h"
#include "util_ghostscript.h"
@@ -321,7 +322,9 @@
appPrefs.scrapbookPrefs.writePreviews = true;
appPrefs.scrapbookPrefs.numScrapbookCopies = 10;
appPrefs.displayPrefs.marginColored = false;
- appPrefs.docSetupPrefs.language = ScQApp->currGUILanguage();
+ appPrefs.docSetupPrefs.language = LanguageManager::instance()->getShortAbbrevFromAbbrevDecomposition(ScQApp->currGUILanguage());
+ if (appPrefs.docSetupPrefs.language.isEmpty())
+ appPrefs.docSetupPrefs.language = "en_GB";
appPrefs.docSetupPrefs.pageSize = LocaleManager::instance()->pageSizeForLocale(ScQApp->currGUILanguage());
appPrefs.docSetupPrefs.pageOrientation = 0;
PageSize defaultPageSize(appPrefs.docSetupPrefs.pageSize);
@@ -2001,6 +2004,9 @@
if (dc.tagName()=="DocumentSetup")
{
appPrefs.docSetupPrefs.language = dc.attribute("Language", "en_GB");
+ appPrefs.docSetupPrefs.language = LanguageManager::instance()->getShortAbbrevFromAbbrevDecomposition(appPrefs.docSetupPrefs.language);
+ if (appPrefs.docSetupPrefs.language.isEmpty())
+ appPrefs.docSetupPrefs.language = "en_GB";
appPrefs.docSetupPrefs.docUnitIndex = dc.attribute("UnitIndex", "0").toInt();
appPrefs.docSetupPrefs.pageSize = dc.attribute("PageSize","A4");
appPrefs.docSetupPrefs.pageOrientation = dc.attribute("PageOrientation", "0").toInt();
Modified: trunk/Scribus/scribus/scribusapp.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22150&path=/trunk/Scribus/scribus/scribusapp.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusapp.cpp (original)
+++ trunk/Scribus/scribus/scribusapp.cpp Fri Sep 1 10:44:10 2017
@@ -49,6 +49,7 @@
#include "scpaths.h"
#include "scribuscore.h"
#include "upgradechecker.h"
+#include "util.h"
#ifdef WITH_TESTS
#include "tests/runtests.h"
@@ -410,6 +411,7 @@
if (userprefsContext)
{
QString prefslang = userprefsContext->get("gui_language","");
+ prefslang = cleanupLang(prefslang);
if (!prefslang.isEmpty())
langs.append(prefslang);
}
@@ -420,21 +422,27 @@
if (!(lang = ::getenv("LANG")).isEmpty())
{
+ lang = cleanupLang(lang);
if (lang=="C")
lang="en";
- langs.append(lang);
+ if (!lang.isEmpty())
+ langs.append(lang);
}
if (!(lang = ::getenv("LC_MESSAGES")).isEmpty())
{
+ lang = cleanupLang(lang);
if (lang=="C")
lang="en";
- langs.append(lang);
+ if (!lang.isEmpty())
+ langs.append(lang);
}
if (!(lang = ::getenv("LC_ALL")).isEmpty())
{
+ lang = cleanupLang(lang);
if (lang=="C")
lang="en";
- langs.append(lang);
+ if (!lang.isEmpty())
+ langs.append(lang);
}
#if defined(_WIN32)
@@ -458,7 +466,7 @@
}
#endif
- langs.append(QString(QLocale::system().name()));
+ langs.append(QLocale::system().name());
// remove duplicate entries...
QStringList::Iterator it = langs.end();
Modified: trunk/Scribus/scribus/ui/smcstylewidget.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22150&path=/trunk/Scribus/scribus/ui/smcstylewidget.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smcstylewidget.cpp (original)
+++ trunk/Scribus/scribus/ui/smcstylewidget.cpp Fri Sep 1 10:44:10 2017
@@ -309,10 +309,10 @@
}
QString defaultLang(defLang.isEmpty() ? "en_GB" : defLang);
- QString clang(cstyle->language().isNull() || cstyle->language().isEmpty() ? defaultLang : cstyle->language());
+ QString clang(cstyle->language().isEmpty() ? defaultLang : cstyle->language());
QString plang(QString::null);
if (hasParent)
- plang = parent->language().isNull() || parent->language().isEmpty() ? defaultLang : parent->language();
+ plang = parent->language().isEmpty() ? defaultLang : parent->language();
int ci = -1, pi = -1, di = -1;
QString tl = LanguageManager::instance()->getAbbrevFromLang(defaultLang, false);
Modified: trunk/Scribus/scribus/util.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22150&path=/trunk/Scribus/scribus/util.cpp
==============================================================================
--- trunk/Scribus/scribus/util.cpp (original)
+++ trunk/Scribus/scribus/util.cpp Fri Sep 1 10:44:10 2017
@@ -49,6 +49,16 @@
#endif
using namespace std;
+
+QString cleanupLang(const QString& lang)
+{
+ int dotIndex = lang.indexOf(QChar('.'));
+ if (dotIndex < 0)
+ return lang;
+
+ QString cleanLang = lang.left(dotIndex);
+ return cleanLang;
+}
int System(const QString exename, const QStringList & args, const QString fileStdErr, const QString fileStdOut, bool* cancel)
{
Modified: trunk/Scribus/scribus/util.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22150&path=/trunk/Scribus/scribus/util.h
==============================================================================
--- trunk/Scribus/scribus/util.h (original)
+++ trunk/Scribus/scribus/util.h Fri Sep 1 10:44:10 2017
@@ -34,7 +34,10 @@
class ScribusDoc;
class ScribusView;
-// class Foi;
+/*!
+\brief Cleanup language strings from extensions such as ".UTF-8" we can get from environment variables
+*/
+QString cleanupLang(const QString& lang);
/*! \brief Compare double values by pre-multiplying by 10000 and converting to long if possible.
If premultiplication does not allow to store result in a long value, perform a standard comparison.
More information about the scribus-commit
mailing list