| 
									
										
										
										
											2017-04-27 20:24:53 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2015-06-16 06:52:06 -07:00
										 |  |  | #include <QApplication>
 | 
					
						
							|  |  |  | #include <QNetworkProxy>
 | 
					
						
							|  |  |  | #include <QLibraryInfo>
 | 
					
						
							|  |  |  | #include <QTextCodec>
 | 
					
						
							|  |  |  | #include "helpers.h"
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:52:51 -03:00
										 |  |  | #include "core/subsurface-qt/SettingsObjectWrapper.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-16 06:52:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 06:17:02 -07:00
										 |  |  | char *settings_suffix = NULL; | 
					
						
							| 
									
										
										
										
											2016-05-01 21:27:35 -07:00
										 |  |  | QTranslator *qtTranslator, *ssrfTranslator; | 
					
						
							| 
									
										
										
										
											2016-04-29 06:17:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 06:52:06 -07:00
										 |  |  | void init_qt_late() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QApplication *application = qApp; | 
					
						
							|  |  |  | 	// tell Qt to use system proxies
 | 
					
						
							|  |  |  | 	// note: on Linux, "system" == "environment variables"
 | 
					
						
							|  |  |  | 	QNetworkProxyFactory::setUseSystemConfiguration(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// for Win32 and Qt5 we try to set the locale codec to UTF-8.
 | 
					
						
							|  |  |  | 	// this makes QFile::encodeName() work.
 | 
					
						
							|  |  |  | #ifdef Q_OS_WIN
 | 
					
						
							|  |  |  | 	QTextCodec::setCodecForLocale(QTextCodec::codecForMib(106)); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QCoreApplication::setOrganizationName("Subsurface"); | 
					
						
							|  |  |  | 	QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); | 
					
						
							| 
									
										
										
										
											2016-04-29 06:17:02 -07:00
										 |  |  | 	// enable user specific settings (based on command line argument)
 | 
					
						
							|  |  |  | 	if (settings_suffix) { | 
					
						
							|  |  |  | 		if (verbose) | 
					
						
							|  |  |  | 			qDebug() << "using custom config for" << QString("Subsurface-%1").arg(settings_suffix); | 
					
						
							|  |  |  | 		QCoreApplication::setApplicationName(QString("Subsurface-%1").arg(settings_suffix)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		QCoreApplication::setApplicationName("Subsurface"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-16 06:52:06 -07:00
										 |  |  | 	// find plugins installed in the application directory (without this SVGs don't work on Windows)
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:52:51 -03:00
										 |  |  | 	SettingsObjectWrapper::instance()->load(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 06:52:06 -07:00
										 |  |  | 	QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath()); | 
					
						
							|  |  |  | 	QLocale loc; | 
					
						
							|  |  |  | 	QString uiLang = uiLanguage(&loc); | 
					
						
							|  |  |  | 	QLocale::setDefault(loc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-22 03:38:09 -07:00
										 |  |  | 	qtTranslator = new QTranslator; | 
					
						
							|  |  |  | 	QString translationLocation; | 
					
						
							| 
									
										
										
										
											2016-05-04 13:51:55 -07:00
										 |  |  | #if defined(Q_OS_ANDROID)
 | 
					
						
							| 
									
										
										
										
											2017-06-22 03:38:09 -07:00
										 |  |  | 	translationLocation = QLatin1Literal("assets:/translations"); | 
					
						
							| 
									
										
										
										
											2016-05-04 13:51:55 -07:00
										 |  |  | #elif defined(Q_OS_IOS)
 | 
					
						
							| 
									
										
										
										
											2017-06-22 03:38:09 -07:00
										 |  |  | 	translationLocation = QLatin1Literal(":/translations/"); | 
					
						
							| 
									
										
										
										
											2016-05-03 17:20:53 -07:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2017-06-22 03:38:09 -07:00
										 |  |  | 	translationLocation = QLibraryInfo::location(QLibraryInfo::TranslationsPath); | 
					
						
							| 
									
										
										
										
											2016-05-03 17:20:53 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-06-22 03:38:09 -07:00
										 |  |  | 	if (qtTranslator->load(loc, "qt", "_", translationLocation)) { | 
					
						
							|  |  |  | 		application->installTranslator(qtTranslator); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-10-20 06:26:28 -04:00
										 |  |  | 		if (verbose && uiLang != "en_US" && uiLang != "en-US") | 
					
						
							| 
									
										
										
										
											2017-07-03 13:29:25 -07:00
										 |  |  | 			qDebug() << "can't find Qt localization for locale" << uiLang << "searching in" << translationLocation; | 
					
						
							| 
									
										
										
										
											2017-06-22 03:38:09 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	ssrfTranslator = new QTranslator; | 
					
						
							|  |  |  | 	if (ssrfTranslator->load(loc, "subsurface", "_") || | 
					
						
							|  |  |  | 	    ssrfTranslator->load(loc, "subsurface", "_", translationLocation) || | 
					
						
							|  |  |  | 	    ssrfTranslator->load(loc, "subsurface", "_", getSubsurfaceDataPath("translations")) || | 
					
						
							|  |  |  | 	    ssrfTranslator->load(loc, "subsurface", "_", getSubsurfaceDataPath("../translations"))) { | 
					
						
							|  |  |  | 		application->installTranslator(ssrfTranslator); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		qDebug() << "can't find Subsurface localization for locale" << uiLang; | 
					
						
							| 
									
										
										
										
											2015-06-16 06:52:06 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |