diff options
author | Edwin Mons <edwin.mons@isode.com> | 2016-02-05 15:37:04 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2016-02-15 11:42:11 (GMT) |
commit | 3f6006ce6e97dacf2100fdb8aacb827316353869 (patch) | |
tree | f5c02513cf919edc1e0513816ac57a9d10d6059f | |
parent | c3ca881c2f08930c0fd280bc2f41af89986770a8 (diff) | |
download | swift-3f6006ce6e97dacf2100fdb8aacb827316353869.zip swift-3f6006ce6e97dacf2100fdb8aacb827316353869.tar.bz2 |
Move QApplication instantiation in QtUI/main.cpp down
If there is no X11 display set, bits in libqxcb as used by the plaform
integration bits called by QApplication will trigger an abort. Moving
this down to just before where the app object is needed allows --help or
--version even if there's no DISPLAY, and also improves runtime of these
GUI-less operations quite a bit.
Test-Information:
Test platform Debian 8 x64 with Qt5
Starting swift-im with DISPLAY set works as expected
Asking for --version or --help without DISPLAY now works
Actually starting the UI still aborts.
Change-Id: Id8eeee90598fe2a8e3b26ba042835a0ea928932f
-rw-r--r-- | Swift/QtUI/main.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Swift/QtUI/main.cpp b/Swift/QtUI/main.cpp index e4efce9..2b8716c 100644 --- a/Swift/QtUI/main.cpp +++ b/Swift/QtUI/main.cpp @@ -1,98 +1,99 @@ /* * Copyright (c) 2010 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <boost/program_options/options_description.hpp> #include <boost/program_options/variables_map.hpp> #include <boost/program_options.hpp> #include <boost/version.hpp> #include <iostream> #include <QApplication> #include <QTextCodec> #include <QTranslator> #include <QLocale> #include <QStringList> #include <Swift/Controllers/Translator.h> #include <Swift/Controllers/ApplicationInfo.h> #include <Swift/Controllers/BuildVersion.h> #include <SwifTools/Application/PlatformApplicationPathProvider.h> #include <SwifTools/CrashReporter.h> #include <stdlib.h> #include <Swiften/Base/Path.h> #include "QtSwift.h" #include "QtTranslator.h" #include "QtSwiftUtil.h" int main(int argc, char* argv[]) { - QApplication app(argc, argv); - Swift::PlatformApplicationPathProvider applicationPathProvider(SWIFT_APPLICATION_NAME); Swift::CrashReporter crashReporter(applicationPathProvider.getDataDir() / "crashes"); #if QT_VERSION < 0x050000 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); #endif // Parse program options boost::program_options::options_description desc = Swift::QtSwift::getOptionsDescription(); boost::program_options::variables_map vm; try { boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); } 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 if (vm.count("language") > 0) { qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(vm["language"].as<std::string>()), 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); Swift::QtSwift swift(vm); int result = app.exec(); Swift::Translator::setInstance(NULL); return result; } |