source: subsurface/subsurface-mobile-helper.cpp

Last change on this file was dd14e27, checked in by Dirk Hohndel <dirk@…>, 6 weeks ago

BLE: try to enable on iOS

We can't use the localBtDevice on iOS, so hack around that and go straight to
discovery.

Signed-off-by: Dirk Hohndel <dirk@…>

  • Property mode set to 100644
File size: 4.8 KB
Line 
1// SPDX-License-Identifier: GPL-2.0
2/* qt-gui.cpp */
3/* Qt UI implementation */
4#include "core/dive.h"
5#include "core/display.h"
6#include "core/helpers.h"
7
8#include <QApplication>
9#include <QDesktopWidget>
10#include <QNetworkProxy>
11#include <QLibraryInfo>
12
13#include "core/qt-gui.h"
14
15#include <QQuickWindow>
16#include <QScreen>
17#include <QQmlApplicationEngine>
18#include <QQmlContext>
19#include <QSortFilterProxyModel>
20#include "mobile-widgets/qmlmanager.h"
21#include "qt-models/divelistmodel.h"
22#include "qt-models/gpslistmodel.h"
23#include "mobile-widgets/qmlprofile.h"
24#include "core/downloadfromdcthread.h"
25#include "core/connectionlistmodel.h"
26#include "qt-models/diveimportedmodel.h"
27#include "qt-models/messagehandlermodel.h"
28
29#include "mobile-widgets/qml/kirigami/src/kirigamiplugin.h"
30
31QObject *qqWindowObject = NULL;
32
33void set_non_bt_addresses() {
34#if defined(Q_OS_ANDROID)
35        connectionListModel.addAddress("FTDI");
36#elif defined(Q_OS_LINUX) // since this is in the else, it does NOT include Android
37        connectionListModel.addAddress("/dev/ttyS0");
38        connectionListModel.addAddress("/dev/ttyS1");
39        connectionListModel.addAddress("/dev/ttyS2");
40        connectionListModel.addAddress("/dev/ttyS3");
41        // this makes debugging so much easier - use the simulator
42        connectionListModel.addAddress("/tmp/ttyS1");
43#endif
44}
45
46void init_ui()
47{
48        init_qt_late();
49}
50
51void run_ui()
52{
53        qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
54        qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
55
56        qmlRegisterType<DCDeviceData>("org.subsurfacedivelog.mobile", 1, 0, "DCDeviceData");
57        qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread");
58        qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel");
59
60        QQmlApplicationEngine engine;
61        KirigamiPlugin::getInstance().registerTypes();
62#if defined(__APPLE__) && !defined(Q_OS_IOS)
63        // when running the QML UI on a Mac the deployment of the QML Components seems
64        // to fail and the search path for the components is rather odd - simply the
65        // same directory the executable was started from <bundle>/Contents/MacOS/
66        // To work around this we need to manually copy the components at install time
67        // to Contents/Frameworks/qml and make sure that we add the correct import path
68        QStringList importPathList = engine.importPathList();
69        Q_FOREACH(QString importPath, importPathList) {
70                if (importPath.contains("MacOS"))
71                        engine.addImportPath(importPath.replace("MacOS", "Frameworks"));
72        }
73        qDebug() << "QML import path" << engine.importPathList();
74#endif
75        engine.addImportPath("qrc://imports");
76        DiveListModel diveListModel;
77        DiveListSortModel *sortModel = new DiveListSortModel(0);
78        sortModel->setSourceModel(&diveListModel);
79        sortModel->setDynamicSortFilter(true);
80        sortModel->setSortRole(DiveListModel::DiveDateRole);
81        sortModel->sort(0, Qt::DescendingOrder);
82        GpsListModel gpsListModel;
83        QSortFilterProxyModel *gpsSortModel = new QSortFilterProxyModel(0);
84        gpsSortModel->setSourceModel(&gpsListModel);
85        gpsSortModel->setDynamicSortFilter(true);
86        gpsSortModel->setSortRole(GpsListModel::GpsWhenRole);
87        gpsSortModel->sort(0, Qt::DescendingOrder);
88        QQmlContext *ctxt = engine.rootContext();
89        ctxt->setContextProperty("diveModel", sortModel);
90        ctxt->setContextProperty("gpsModel", gpsSortModel);
91        ctxt->setContextProperty("vendorList", vendorList);
92        set_non_bt_addresses();
93
94        ctxt->setContextProperty("connectionListModel", &connectionListModel);
95        ctxt->setContextProperty("logModel", MessageHandlerModel::self());
96
97        engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
98        qqWindowObject = engine.rootObjects().value(0);
99        if (!qqWindowObject) {
100                fprintf(stderr, "can't create window object\n");
101                exit(1);
102        }
103        QQuickWindow *qml_window = qobject_cast<QQuickWindow *>(qqWindowObject);
104        qml_window->setIcon(QIcon(":/subsurface-mobile-icon"));
105        qqWindowObject->setProperty("messageText", QVariant("Subsurface-mobile startup"));
106        qDebug() << "qqwindow devicePixelRatio" << qml_window->devicePixelRatio() << qml_window->screen()->devicePixelRatio();
107        QScreen *screen = qml_window->screen();
108        QObject::connect(qml_window, &QQuickWindow::screenChanged, QMLManager::instance(), &QMLManager::screenChanged);
109        QMLManager *manager = QMLManager::instance();
110        manager->setDevicePixelRatio(qml_window->devicePixelRatio(), qml_window->screen());
111        manager->dlSortModel = sortModel;
112        manager->screenChanged(screen);
113        qDebug() << "qqwindow screen has ldpi/pdpi" << screen->logicalDotsPerInch() << screen->physicalDotsPerInch();
114#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
115        qml_window->setHeight(1200);
116        qml_window->setWidth(800);
117#endif
118        qml_window->show();
119        qApp->exec();
120}
121
122void exit_ui()
123{
124        delete qApp;
125        free((void *)existing_filename);
126}
127
128double get_screen_dpi()
129{
130        QDesktopWidget *mydesk = qApp->desktop();
131        return mydesk->physicalDpiX();
132}
133
134bool haveFilesOnCommandLine()
135{
136        return false;
137}
Note: See TracBrowser for help on using the repository browser.