summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2017-03-31 07:07:02 (GMT)
committerTobias Markmann <tm@ayena.de>2017-03-31 07:07:02 (GMT)
commit4d0391d824aaf94fbe152778581d51fecd588f6c (patch)
tree87fd793d0c60309cfcb0d5e54d5c2626378f9dd8
parent3611f7cbdcc1a9c96a542d40a439712cf5c3818a (diff)
downloadswift-4d0391d824aaf94fbe152778581d51fecd588f6c.zip
swift-4d0391d824aaf94fbe152778581d51fecd588f6c.tar.bz2
Handle potential boost::bad_any_cast exception
Coverity raised this issue. Test-Information: Builds and unit tests pass on macOS 10.12.4. Switching different application languages via --language parameter still works and passing numbers as languages has it correctly fallback to the default system language. Change-Id: Ide1ffdba7a13c27856304aa96b78067147568a95
-rw-r--r--Swift/QtUI/main.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/Swift/QtUI/main.cpp b/Swift/QtUI/main.cpp
index 472c99a..81dc670 100644
--- a/Swift/QtUI/main.cpp
+++ b/Swift/QtUI/main.cpp
@@ -1,32 +1,32 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <cstdlib>
#include <iostream>
#include <locale>
#include <memory>
#include <sstream>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/program_options.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/version.hpp>
#include <QApplication>
#include <QLocale>
#include <QStringList>
#include <QTextCodec>
#include <QTranslator>
#include <Swiften/Base/Path.h>
#include <Swift/Controllers/ApplicationInfo.h>
#include <Swift/Controllers/BuildVersion.h>
#include <Swift/Controllers/Translator.h>
#include <SwifTools/Application/PlatformApplicationPathProvider.h>
#include <SwifTools/CrashReporter.h>
@@ -62,62 +62,69 @@ int main(int argc, char* argv[]) {
} catch (const boost::program_options::unknown_option& option) {
#if BOOST_VERSION >= 104200
std::cout << "Ignoring unknown option " << option.get_option_name() << " but continuing." << std::endl;
#else
std::cout << "Error: " << option.what() << " (continuing)" << std::endl;
#endif
}
boost::program_options::notify(vm);
if (vm.count("help") > 0) {
std::cout << SWIFT_APPLICATION_NAME << " is an instant messaging client for the XMPP network." << std::endl;
std::cout << std::endl;
std::cout << "Usage: " << argv[0] << " [OPTIONS]..." << std::endl;
std::cout << std::endl;
std::cout << desc << std::endl;
return 1;
}
if (vm.count("version") > 0) {
std::cout << SWIFT_APPLICATION_NAME << " " << buildVersion << std::endl;
return 0;
}
// Translation
#if QT_VERSION < 0x050000
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
#endif
boost::filesystem::path someTranslationPath = applicationPathProvider.getResourcePath("/translations/swift_en.qm");
QTranslator qtTranslator;
if (!someTranslationPath.empty()) {
#if QT_VERSION >= 0x040800
+ std::string language;
if (vm.count("language") > 0) {
- qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(vm["language"].as<std::string>()), P2QSTRING(Swift::pathToString(someTranslationPath.parent_path())));
+ try {
+ language = vm["language"].as<std::string>();
+ } catch (const boost::bad_any_cast&) {
+ }
+ }
+ if (!language.empty()) {
+ qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(language), P2QSTRING(Swift::pathToString(someTranslationPath.parent_path())));
}
else {
qtTranslator.load(QLocale::system(), QString(SWIFT_APPLICATION_NAME).toLower(), "_", P2QSTRING(Swift::pathToString(someTranslationPath)));
}
#else
//std::cout << "Loading " << std::string(QLocale::system().name().toUtf8()) << std::endl;
qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + QLocale::system().name(), P2QSTRING(Swift::pathToString(someTranslationPath)));
#endif
}
QApplication app(argc, argv);
app.installTranslator(&qtTranslator);
QtTranslator swiftTranslator;
Swift::Translator::setInstance(&swiftTranslator);
#if QT_VERSION < 0x050501
/* According to Qt documenation, Qt is suppsoed to set the applications layout
* direction based on the translatable QT_LAYOUT_DIRECTION string. There is a
* bug in Qt prior version 5.5.1, i.e. QTBUG-43447, thus we set the layout
* direction manually based on the tranlsated QT_LAYOUT_DIRECTION string.
*/
app.setLayoutDirection(QGuiApplication::tr("QT_LAYOUT_DIRECTION") == QLatin1String("RTL") ? Qt::RightToLeft : Qt::LeftToRight);
#endif
Swift::QtSwift swift(vm);
int result = app.exec();
Swift::Translator::setInstance(nullptr);