]> git.lyx.org Git - features.git/commitdiff
fix bug 2086
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 17 Oct 2005 08:30:37 +0000 (08:30 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 17 Oct 2005 08:30:37 +0000 (08:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10556 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/QLyXKeySym.C

index 0ceab6d4a98e86ba00ae802f4676ba4e6996a083..daf9c5ab85cd9752857e27670f3518a3804cb966 100644 (file)
@@ -1,3 +1,7 @@
+2005-10-16  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * QLyXKeySym.C (initEncodings): prevent crash when no codec found
+
 2005-10-07  Martin Vermeer  <martin.vermeer@hut.fi>
 
        * QContentPane.C (QContentPane): make times 50 msec instead of 25,
index b64ae1bc3756c8208ac0621e09be010095a53fcd..d15b87d747b062a2e3ef1978755fcef7ebbfecee 100644 (file)
@@ -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];