-
-
Notifications
You must be signed in to change notification settings - Fork 210
/
main.cpp
220 lines (186 loc) · 7.64 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/***************************************************************************
main.cpp - main for qgis mobileapp
based on src/browser/main.cpp
-------------------
begin : Wed Apr 04 10:48:28 CET 2012
copyright : (C) 2012 by Marco Bernasocchi
email : marco@bernawebdesign.ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "platformutilities.h"
#include "qfield.h"
#include "qgismobileapp.h"
#if WITH_SENTRY
#include "sentry_wrapper.h"
#endif
#if defined( Q_OS_ANDROID )
#include "qfieldservice.h"
#endif
#include <qgsapplication.h>
#include <qgslogger.h>
#include <qgsprojutils.h>
#ifdef WITH_SPIX
#include <Spix/AnyRpcServer.h>
#include <Spix/QtQmlBot.h>
#endif
#include <QApplication>
#include <QDialog>
#include <QDir>
#include <QEventLoop>
#include <QLabel>
#include <QLocale>
#include <QMainWindow>
#include <QSettings>
#include <QStandardPaths>
#include <QTranslator>
#include <QtWebView/QtWebView>
#include <proj.h>
#if HAVE_STATIC_QCA_PLUGINS
#include <QtPlugin>
Q_IMPORT_PLUGIN( opensslPlugin )
#endif
void initGraphics()
{
#ifdef WITH_SPIX
// Set antialiasing method to vertex to get same antialiasing across environments
qputenv( "QSG_ANTIALIASING_METHOD", "vertex" );
#endif
#if not defined( Q_OS_ANDROID )
// Enables antialiasing in QML scenes
// Avoid enabling on Android OS as it leads to serious regressions on old devices
QSurfaceFormat format;
format.setSamples( 4 );
QSurfaceFormat::setDefaultFormat( format );
#endif
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
QGuiApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
#endif
}
int main( int argc, char **argv )
{
if ( argc > 1 && strcmp( argv[1], "--service" ) == 0 )
{
QCoreApplication::setOrganizationName( "OPENGIS.ch" );
QCoreApplication::setOrganizationDomain( "opengis.ch" );
QCoreApplication::setApplicationName( qfield::appName );
#if defined( Q_OS_ANDROID )
// For now the service only deals with background attachment uploads and will terminate once all uploads are done
QFieldService app( argc, argv );
#endif
return 0;
}
initGraphics();
// Read settings, use a dummy app to get access to QSettings
QCoreApplication *dummyApp = new QCoreApplication( argc, argv );
QCoreApplication::setOrganizationName( "OPENGIS.ch" );
QCoreApplication::setOrganizationDomain( "opengis.ch" );
QCoreApplication::setApplicationName( qfield::appName );
const QSettings settings;
const QString customLanguage = settings.value( "/customLanguage", QString() ).toString();
#if WITH_SENTRY
const bool enableSentry = settings.value( "/enableInfoCollection", true ).toBool();
if ( enableSentry )
sentry_wrapper::init();
// Make sure everything flushes when exiting the app
auto sentryClose = qScopeGuard( [] { sentry_wrapper::close(); } );
#endif
Q_INIT_RESOURCE( qml );
QtWebView::initialize();
PlatformUtilities *platformUtils = PlatformUtilities::instance();
platformUtils->initSystem();
// Let's make sure we have a writable path for the qgis_profile on every platform
const QString profilePath = platformUtils->systemLocalDataLocation( QStringLiteral( "/qgis_profile" ) );
QDir().mkdir( profilePath );
delete dummyApp;
QgsApplication app( argc, argv, true, profilePath, QStringLiteral( "mobile" ) );
if ( !customLanguage.isEmpty() )
{
QLocale customLocale( customLanguage );
QLocale::setDefault( customLocale );
QgsApplication::setTranslation( customLanguage );
// Set locale to emit QgsApplication's localeChanged signal
QgsApplication::setLocale( QLocale() );
}
const QString qfieldFont( qgetenv( "QFIELD_FONT_TTF" ) );
if ( !qfieldFont.isEmpty() )
{
const QString qfieldFontName( qgetenv( "QFIELD_FONT_NAME" ) );
const int qfieldFontSize = QString( qgetenv( "QFIELD_FONT_SIZE" ) ).toInt();
QFontDatabase::addApplicationFont( qfieldFont );
app.setFont( QFont( qfieldFontName, qfieldFontSize ) );
}
QStringList projSearchPaths = QgsProjUtils::searchPaths();
#ifdef RELATIVE_PREFIX_PATH
qputenv( "SSL_CERT_FILE", QDir::toNativeSeparators( PlatformUtilities::instance()->systemSharedDataLocation() + "/cacert.pem" ).toLocal8Bit() );
qputenv( "GDAL_DATA", QDir::toNativeSeparators( PlatformUtilities::instance()->systemSharedDataLocation() + "/gdal" ).toLocal8Bit() );
projSearchPaths << QDir::toNativeSeparators( PlatformUtilities::instance()->systemSharedDataLocation() + "/proj" );
qInfo() << "Proj path: " << projSearchPaths.constLast();
#else
app.setPrefixPath( QGIS_PREFIX_PATH, true );
qInfo() << "Proj path: {System}";
#endif
// add extra proj search path to allow copying of transformation grid files
const QStringList dataDirs = PlatformUtilities::instance()->appDataDirs();
for ( const QString &dataDir : dataDirs )
{
projSearchPaths << QStringLiteral( "%1/proj/" ).arg( dataDir );
}
if ( !projSearchPaths.isEmpty() )
{
char **newPaths = new char *[projSearchPaths.count()];
for ( int i = 0; i < projSearchPaths.count(); ++i )
{
newPaths[i] = strdup( projSearchPaths.at( i ).toUtf8().constData() );
}
proj_context_set_search_paths( nullptr, static_cast<int>( projSearchPaths.count() ), newPaths );
for ( int i = 0; i < projSearchPaths.count(); ++i )
{
free( newPaths[i] );
}
delete[] newPaths;
}
#if WITH_SENTRY
sentry_wrapper::install_message_handler();
#endif
app.initQgis();
app.setThemeName( settings.value( "/Themes", "default" ).toString() );
#ifdef RELATIVE_PREFIX_PATH
app.setPkgDataPath( PlatformUtilities::instance()->systemSharedDataLocation() + QStringLiteral( "/qgis" ) );
#endif
app.createDatabase();
QSettings::setDefaultFormat( QSettings::NativeFormat );
// Set up the QSettings environment must be done after qapp is created
QCoreApplication::setOrganizationName( "OPENGIS.ch" );
QCoreApplication::setOrganizationDomain( "opengis.ch" );
QCoreApplication::setApplicationName( qfield::appName );
QTranslator qfieldTranslator;
QTranslator qtTranslator;
bool qfieldTranslatorLoaded = false;
bool qtTranslatorLoaded = false;
if ( !customLanguage.isEmpty() )
{
qfieldTranslatorLoaded = qfieldTranslator.load( QStringLiteral( "qfield_%1" ).arg( customLanguage ), QStringLiteral( ":/i18n/" ), "_" );
qtTranslatorLoaded = qtTranslator.load( QStringLiteral( "qt_%1" ).arg( customLanguage ), QStringLiteral( ":/i18n/" ), "_" );
}
if ( !qfieldTranslatorLoaded || qfieldTranslator.isEmpty() )
( void ) qfieldTranslator.load( QLocale(), "qfield", "_", ":/i18n/" );
if ( !qtTranslatorLoaded || qtTranslator.isEmpty() )
( void ) qtTranslator.load( QLocale(), "qt", "_", ":/i18n/" );
app.installTranslator( &qtTranslator );
app.installTranslator( &qfieldTranslator );
qputenv( "QT_QUICK_CONTROLS_STYLE", QByteArray( "Material" ) );
QgisMobileapp mApp( &app );
#ifdef WITH_SPIX
spix::AnyRpcServer server;
auto bot = new spix::QtQmlBot();
bot->runTestServer( server );
#endif
return app.exec();
}