2017-04-27 18:27:59 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-09-09 08:59:03 +00:00
|
|
|
/* main.c */
|
|
|
|
#include <locale.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2018-07-26 01:36:40 +00:00
|
|
|
#include <string.h>
|
2013-09-09 08:59:03 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2020-05-01 11:43:52 +00:00
|
|
|
#include "core/dive.h"
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
#include "core/divelog.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/color.h"
|
2017-04-27 18:24:14 +00:00
|
|
|
#include "core/downloadfromdcthread.h"
|
2020-06-14 09:55:06 +00:00
|
|
|
#include "core/parse.h"
|
2018-07-26 01:36:40 +00:00
|
|
|
#include "core/qt-gui.h"
|
|
|
|
#include "core/qthelper.h"
|
|
|
|
#include "core/subsurfacestartup.h"
|
2018-08-14 08:12:32 +00:00
|
|
|
#include "core/settings/qPref.h"
|
2018-09-08 17:46:11 +00:00
|
|
|
#include "core/settings/qPrefDisplay.h"
|
2019-05-30 16:29:36 +00:00
|
|
|
#include "core/tag.h"
|
2018-09-26 10:07:01 +00:00
|
|
|
#include "core/settings/qPrefCloudStorage.h"
|
cloudstorage: try to pick between multiple cloud servers
The backend infrastructure will soon be able to support more than one
cloud server which automagically stay in sync with each other.
One critical requirement for that to work is that once a session was
started with one of the servers, the complete session happens with that
server - we must not switch from server to server while doing a git
transaction. To make sure that's the case, we aren't trying to use DNS
tricks to make this load balancing scheme work, but instead try to
determine at program start which server is the best one to use.
Right now this is super simplistic. Two servers, one in the US, one in
Europe. By default we use the European server (most of our users appear
to be in Europe), but if we can figure out that the client is actually
in the Americas, use the US server. We might improve that heuristic over
time, but as a first attempt it seems not entirely bogus.
The way this is implemented is a simple combination of two free
webservices that together appear to give us a very reliable estimate
which continent the user is located on.
api.ipify.org gives us our external IP address
ip-api.com gives us the continent that IP address is on
If any of this fails or takes too long to respond, we simply ignore it
since either server will work. One oddity is that if we decide to change
servers we only change the settings that are stored on disk, not the
runtime preferences. This goes back to the comment above that we have to
avoid changing servers in mid sync.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-04-11 01:03:08 +00:00
|
|
|
#include "core/checkcloudconnection.h"
|
2013-09-09 08:59:03 +00:00
|
|
|
|
2015-06-16 13:52:06 +00:00
|
|
|
#include <QApplication>
|
2021-01-15 01:08:13 +00:00
|
|
|
#include <QFont>
|
2021-01-15 14:02:18 +00:00
|
|
|
#include <QFontMetrics>
|
2017-12-03 13:04:45 +00:00
|
|
|
#include <QLocale>
|
2018-07-26 01:36:40 +00:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
#include <QStringList>
|
2014-03-31 20:37:41 +00:00
|
|
|
#include <git2.h>
|
2013-09-09 08:59:03 +00:00
|
|
|
|
2018-05-28 14:25:39 +00:00
|
|
|
// Implementation of STP logging
|
|
|
|
|
2013-09-09 08:59:03 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2017-03-31 14:15:14 +00:00
|
|
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2015-07-06 14:11:02 +00:00
|
|
|
QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
|
2018-05-21 18:57:10 +00:00
|
|
|
|
|
|
|
// Start application
|
2019-09-29 11:21:12 +00:00
|
|
|
std::unique_ptr<QApplication> app(new QApplication(argc, argv));
|
2018-05-21 18:57:10 +00:00
|
|
|
|
|
|
|
// and get comand line arguments
|
2013-10-08 09:48:46 +00:00
|
|
|
QStringList arguments = QCoreApplication::arguments();
|
2014-03-25 14:55:56 +00:00
|
|
|
|
2017-11-02 23:51:33 +00:00
|
|
|
subsurface_console_init();
|
2014-03-25 14:55:56 +00:00
|
|
|
|
2024-03-25 19:33:30 +00:00
|
|
|
for (int i = 1; i < arguments.length(); i++) {
|
2013-10-08 09:48:46 +00:00
|
|
|
QString a = arguments.at(i);
|
2016-06-17 11:10:34 +00:00
|
|
|
if (!a.isEmpty() && a.at(0) == '-') {
|
2018-02-25 12:51:41 +00:00
|
|
|
parse_argument(qPrintable(a));
|
2013-09-09 08:59:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-12-06 13:49:57 +00:00
|
|
|
git_libgit2_init();
|
2014-03-19 16:23:43 +00:00
|
|
|
setup_system_prefs();
|
2017-12-03 13:04:45 +00:00
|
|
|
if (QLocale().measurementSystem() == QLocale::MetricSystem)
|
|
|
|
default_prefs.units = SI_units;
|
|
|
|
else
|
2016-01-06 07:43:05 +00:00
|
|
|
default_prefs.units = IMPERIAL_units;
|
2017-11-25 08:22:19 +00:00
|
|
|
copy_prefs(&default_prefs, &prefs);
|
cloudstorage: try to pick between multiple cloud servers
The backend infrastructure will soon be able to support more than one
cloud server which automagically stay in sync with each other.
One critical requirement for that to work is that once a session was
started with one of the servers, the complete session happens with that
server - we must not switch from server to server while doing a git
transaction. To make sure that's the case, we aren't trying to use DNS
tricks to make this load balancing scheme work, but instead try to
determine at program start which server is the best one to use.
Right now this is super simplistic. Two servers, one in the US, one in
Europe. By default we use the European server (most of our users appear
to be in Europe), but if we can figure out that the client is actually
in the Americas, use the US server. We might improve that heuristic over
time, but as a first attempt it seems not entirely bogus.
The way this is implemented is a simple combination of two free
webservices that together appear to give us a very reliable estimate
which continent the user is located on.
api.ipify.org gives us our external IP address
ip-api.com gives us the continent that IP address is on
If any of this fails or takes too long to respond, we simply ignore it
since either server will work. One oddity is that if we decide to change
servers we only change the settings that are stored on disk, not the
runtime preferences. This goes back to the comment above that we have to
avoid changing servers in mid sync.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-04-11 01:03:08 +00:00
|
|
|
CheckCloudConnection ccc;
|
|
|
|
ccc.pickServer();
|
2017-04-27 18:24:14 +00:00
|
|
|
fill_computer_list();
|
2024-05-03 21:18:45 +00:00
|
|
|
reset_tank_info_table(tank_info_table);
|
2017-04-27 18:24:14 +00:00
|
|
|
|
2014-03-19 16:23:43 +00:00
|
|
|
parse_xml_init();
|
|
|
|
taglist_init_global();
|
2021-01-15 01:08:13 +00:00
|
|
|
|
|
|
|
// grab the system font size before we overwrite this when we load preferences
|
|
|
|
double initial_font_size = QGuiApplication::font().pointSizeF();
|
2021-01-15 14:02:18 +00:00
|
|
|
if (initial_font_size < 0.0) {
|
|
|
|
// The OS provides a default font in pixels, not points; doing some crude math
|
|
|
|
// to reverse engineer that information by measuring the height of a 10pt font in pixels
|
|
|
|
QFont testFont;
|
|
|
|
testFont.setPointSizeF(10.0);
|
|
|
|
QFontMetrics fm(testFont);
|
|
|
|
initial_font_size = QGuiApplication::font().pixelSize() * 10.0 / fm.height();
|
|
|
|
}
|
2014-03-19 16:23:43 +00:00
|
|
|
init_ui();
|
2016-04-22 13:57:08 +00:00
|
|
|
if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE)
|
2024-03-16 15:06:39 +00:00
|
|
|
existing_filename = prefs.default_filename;
|
2016-04-27 13:01:07 +00:00
|
|
|
else
|
2024-03-16 15:06:39 +00:00
|
|
|
existing_filename.clear();
|
2016-04-22 13:57:08 +00:00
|
|
|
|
2016-03-28 00:18:48 +00:00
|
|
|
// some hard coded settings
|
2018-09-26 10:07:01 +00:00
|
|
|
qPrefCloudStorage::set_save_password_local(true);
|
2016-02-06 07:36:42 +00:00
|
|
|
|
2016-03-28 00:18:48 +00:00
|
|
|
// always show the divecomputer reported ceiling in red
|
2016-02-06 07:36:42 +00:00
|
|
|
prefs.redceiling = 1;
|
|
|
|
|
2015-11-14 17:38:18 +00:00
|
|
|
init_proxy();
|
2015-10-05 22:52:39 +00:00
|
|
|
|
2013-11-02 19:00:16 +00:00
|
|
|
if (!quit)
|
2021-01-15 01:08:13 +00:00
|
|
|
run_mobile_ui(initial_font_size);
|
2013-09-09 08:59:03 +00:00
|
|
|
exit_ui();
|
2014-03-19 16:23:43 +00:00
|
|
|
parse_xml_exit();
|
2014-03-25 14:55:56 +00:00
|
|
|
subsurface_console_exit();
|
2018-08-14 08:12:32 +00:00
|
|
|
|
|
|
|
// Sync struct preferences to disk
|
|
|
|
qPref::sync();
|
|
|
|
|
2014-12-18 07:47:42 +00:00
|
|
|
free_prefs();
|
2013-09-09 08:59:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-07-11 10:54:00 +00:00
|
|
|
|
2018-07-26 01:36:40 +00:00
|
|
|
void set_non_bt_addresses()
|
|
|
|
{
|
2020-03-15 14:35:39 +00:00
|
|
|
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
2018-07-11 10:54:00 +00:00
|
|
|
connectionListModel.addAddress("/dev/ttyS0");
|
|
|
|
connectionListModel.addAddress("/dev/ttyS1");
|
|
|
|
connectionListModel.addAddress("/dev/ttyS2");
|
|
|
|
connectionListModel.addAddress("/dev/ttyS3");
|
|
|
|
// this makes debugging so much easier - use the simulator
|
|
|
|
connectionListModel.addAddress("/tmp/ttyS1");
|
|
|
|
#endif
|
2020-03-05 21:38:33 +00:00
|
|
|
#if defined(SERIAL_FTDI)
|
|
|
|
connectionListModel.addAddress("FTDI");
|
|
|
|
#endif
|
2018-07-11 10:54:00 +00:00
|
|
|
}
|