2013-05-03 18:04:51 +00:00
|
|
|
/* qt-gui.cpp */
|
|
|
|
/* Qt UI implementation */
|
2011-09-20 19:40:34 +00:00
|
|
|
#include "dive.h"
|
|
|
|
#include "display.h"
|
2013-04-07 22:20:43 +00:00
|
|
|
#include "qt-ui/mainwindow.h"
|
2013-05-23 06:24:33 +00:00
|
|
|
#include "helpers.h"
|
2011-09-20 19:40:34 +00:00
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
#include <QApplication>
|
2013-05-10 16:24:06 +00:00
|
|
|
#include <QDesktopWidget>
|
2013-07-13 12:42:26 +00:00
|
|
|
#include <QNetworkProxy>
|
2013-10-09 05:25:02 +00:00
|
|
|
#include <QLibraryInfo>
|
2015-02-23 20:31:25 +00:00
|
|
|
#include <QTextCodec>
|
2013-04-07 22:20:43 +00:00
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
static QApplication *application = NULL;
|
2013-09-18 15:27:24 +00:00
|
|
|
static MainWindow *window = NULL;
|
2013-04-02 16:49:17 +00:00
|
|
|
|
2014-03-19 16:23:43 +00:00
|
|
|
void init_qt(int *argcp, char ***argvp)
|
2011-09-20 19:40:34 +00:00
|
|
|
{
|
2013-04-22 13:45:57 +00:00
|
|
|
application = new QApplication(*argcp, *argvp);
|
2014-03-19 16:23:43 +00:00
|
|
|
}
|
2013-04-25 22:28:31 +00:00
|
|
|
|
2014-03-19 16:23:43 +00:00
|
|
|
void init_ui(void)
|
|
|
|
{
|
2013-09-09 07:46:02 +00:00
|
|
|
// tell Qt to use system proxies
|
|
|
|
// note: on Linux, "system" == "environment variables"
|
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
2013-07-13 12:42:26 +00:00
|
|
|
|
2013-04-25 22:28:31 +00:00
|
|
|
#if QT_VERSION < 0x050000
|
|
|
|
// ask QString in Qt 4 to interpret all char* as UTF-8,
|
|
|
|
// like Qt 5 does.
|
|
|
|
// 106 is "UTF-8", this is faster than lookup by name
|
|
|
|
// [http://www.iana.org/assignments/character-sets/character-sets.xml]
|
|
|
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForMib(106));
|
2014-04-30 17:37:55 +00:00
|
|
|
// and for reasons I can't understand, I need to do the same again for tr
|
|
|
|
// even though that clearly uses C strings as well...
|
|
|
|
QTextCodec::setCodecForTr(QTextCodec::codecForMib(106));
|
2014-02-28 04:09:57 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2013-12-20 01:02:34 +00:00
|
|
|
QFile::setDecodingFunction(decodeUtf8);
|
|
|
|
QFile::setEncodingFunction(encodeUtf8);
|
2014-02-28 04:09:57 +00:00
|
|
|
#endif
|
2014-10-29 16:14:42 +00:00
|
|
|
#else
|
|
|
|
// 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
|
2013-04-25 22:28:31 +00:00
|
|
|
#endif
|
2013-05-22 03:31:56 +00:00
|
|
|
QCoreApplication::setOrganizationName("Subsurface");
|
|
|
|
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
|
|
|
QCoreApplication::setApplicationName("Subsurface");
|
2013-11-21 23:51:41 +00:00
|
|
|
// find plugins installed in the application directory (without this SVGs don't work on Windows)
|
|
|
|
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath());
|
2013-12-06 19:48:38 +00:00
|
|
|
QLocale loc;
|
2014-06-06 19:10:34 +00:00
|
|
|
QString uiLang = uiLanguage(&loc);
|
2014-07-16 16:35:22 +00:00
|
|
|
QLocale::setDefault(loc);
|
2013-10-10 19:26:03 +00:00
|
|
|
|
2013-10-10 00:55:31 +00:00
|
|
|
// we don't have translations for English - if we don't check for this
|
|
|
|
// Qt will proceed to load the second language in preference order - not what we want
|
|
|
|
// on Linux this tends to be en-US, but on the Mac it's just en
|
2014-04-30 16:45:01 +00:00
|
|
|
if (!uiLang.startsWith("en") || uiLang.startsWith("en-GB")) {
|
2013-10-09 05:25:02 +00:00
|
|
|
qtTranslator = new QTranslator;
|
2014-02-28 04:09:57 +00:00
|
|
|
if (qtTranslator->load(loc, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
|
2013-10-09 05:25:02 +00:00
|
|
|
application->installTranslator(qtTranslator);
|
|
|
|
} else {
|
2014-02-28 04:09:57 +00:00
|
|
|
qDebug() << "can't find Qt localization for locale" << uiLang << "searching in" << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
2013-10-09 05:25:02 +00:00
|
|
|
}
|
|
|
|
ssrfTranslator = new QTranslator;
|
2014-02-28 04:09:57 +00:00
|
|
|
if (ssrfTranslator->load(loc, "subsurface", "_") ||
|
|
|
|
ssrfTranslator->load(loc, "subsurface", "_", getSubsurfaceDataPath("translations")) ||
|
|
|
|
ssrfTranslator->load(loc, "subsurface", "_", getSubsurfaceDataPath("../translations"))) {
|
2013-10-09 05:25:02 +00:00
|
|
|
application->installTranslator(ssrfTranslator);
|
|
|
|
} else {
|
2013-10-10 19:26:03 +00:00
|
|
|
qDebug() << "can't find Subsurface localization for locale" << uiLang;
|
2013-10-09 05:25:02 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 15:27:24 +00:00
|
|
|
window = new MainWindow();
|
2013-09-09 08:59:03 +00:00
|
|
|
if (existing_filename && existing_filename[0] != '\0')
|
|
|
|
window->setTitle(MWTF_FILENAME);
|
|
|
|
else
|
|
|
|
window->setTitle(MWTF_DEFAULT);
|
2011-09-20 19:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void run_ui(void)
|
|
|
|
{
|
2014-03-11 21:11:34 +00:00
|
|
|
window->show();
|
2013-04-01 10:57:51 +00:00
|
|
|
application->exec();
|
2011-09-20 19:40:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 17:03:48 +00:00
|
|
|
void exit_ui(void)
|
|
|
|
{
|
2013-09-18 15:27:24 +00:00
|
|
|
delete window;
|
2013-04-01 10:57:51 +00:00
|
|
|
delete application;
|
2014-05-12 17:58:15 +00:00
|
|
|
free((void *)existing_filename);
|
2014-12-18 18:47:00 +00:00
|
|
|
free((void *)default_dive_computer_vendor);
|
|
|
|
free((void *)default_dive_computer_product);
|
2014-05-12 17:58:15 +00:00
|
|
|
free((void *)default_dive_computer_device);
|
2012-05-02 17:03:48 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 16:24:06 +00:00
|
|
|
double get_screen_dpi()
|
|
|
|
{
|
|
|
|
QDesktopWidget *mydesk = application->desktop();
|
|
|
|
return mydesk->physicalDpiX();
|
|
|
|
}
|
2013-05-23 06:24:33 +00:00
|
|
|
|
2013-05-30 21:26:08 +00:00
|
|
|
|