From 56c6e2f621e161abab9bed476c8e696850f0a704 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 17 Oct 2005 08:30:37 +0000 Subject: [PATCH] fix bug 2086 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10556 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 4 ++++ src/frontends/qt2/QLyXKeySym.C | 30 ++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0ceab6d4a9..daf9c5ab85 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,7 @@ +2005-10-16 Georg Baum + + * QLyXKeySym.C (initEncodings): prevent crash when no codec found + 2005-10-07 Martin Vermeer * QContentPane.C (QContentPane): make times 50 msec instead of 25, diff --git a/src/frontends/qt2/QLyXKeySym.C b/src/frontends/qt2/QLyXKeySym.C index b64ae1bc37..d15b87d747 100644 --- a/src/frontends/qt2/QLyXKeySym.C +++ b/src/frontends/qt2/QLyXKeySym.C @@ -45,20 +45,23 @@ char const encode(string const & encoding, QString const & str) EncodingMap::const_iterator cit = encoding_map.find(encoding); if (cit == encoding_map.end()) { - if (lyxerr.debugging()) - lyxerr[Debug::KEY] << "Unrecognised encoding " - << encoding << endl; + lyxerr[Debug::KEY] << "Unrecognised encoding '" << encoding + << "'." << endl; codec = encoding_map.find("")->second; } else { codec = cit->second; } - if (lyxerr.debugging()) - lyxerr[Debug::KEY] << "Using codec " << fromqstr(codec->name()) << endl; + if (!codec) { + lyxerr[Debug::KEY] << "No codec for encoding '" << encoding + << "' found." << endl; + return 0; + } + + lyxerr[Debug::KEY] << "Using codec " << fromqstr(codec->name()) << endl; if (!codec->canEncode(str)) { - if (lyxerr.debugging()) - lyxerr[Debug::KEY] << "Oof. Can't encode the text !" << endl; + lyxerr[Debug::KEY] << "Oof. Can't encode the text !" << endl; return 0; } @@ -84,7 +87,7 @@ void initEncodings() s = "C"; } } - + if (s.find("UTF") != string::npos || s.find("utf") != string::npos) //if (contains(c, "UTF") || contains(c, "utf")) lyxerr << "Warning: this system's locale uses Unicode." << endl; @@ -112,17 +115,16 @@ void initEncodings() encoding_map["pt154"] = 0; // There are lots more codecs in Qt too ... - + // when no document open // use the appropriate encoding for the system language lyxerr << "Language code:" << s << endl; for (Languages::const_iterator it=languages.begin(); it != languages.end(); ++it) { //lyxerr << it->second.code() << ":" << it->second.encodingStr() << ":" << it->second.encoding() << endl; - if (it->second.code() == s) - { - s = it->second.encodingStr(); - break; - } + if (it->second.code() == s) { + s = it->second.encodingStr(); + break; + } } lyxerr << "Setting new locale for Qt:" << s << endl; QTextCodec * defaultCodec = encoding_map[s]; -- 2.39.2