diff --git a/core/qt-gui.h b/core/qt-gui.h index a1e608122..9bfe0e001 100644 --- a/core/qt-gui.h +++ b/core/qt-gui.h @@ -6,7 +6,6 @@ void init_qt_late(); void init_ui(); void run_ui(); -void register_qml_types(); void exit_ui(); void set_non_bt_addresses(); diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp index b37024f32..61561a188 100644 --- a/core/settings/qPref.cpp +++ b/core/settings/qPref.cpp @@ -2,8 +2,7 @@ #include "qPref.h" #include "qPrefPrivate.h" -#include -#include +#include #include qPref::qPref(QObject *parent) : QObject(parent) @@ -39,28 +38,34 @@ void qPref::loadSync(bool doSync) qPrefUpdateManager::loadSync(doSync); } -#define REGISTER_QPREF(useClass, useQML) \ - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, useQML); \ - if (rc < 0) \ - qWarning() << "ERROR: Cannot register " << useQML << ", QML will not work!!"; - -void qPref::registerQML() +Q_DECLARE_METATYPE(deco_mode); +Q_DECLARE_METATYPE(def_file_behavior); +Q_DECLARE_METATYPE(taxonomy_category); +void qPref::registerQML(QQmlEngine *engine) { - int rc; + if (engine) { + QQmlContext *ct = engine->rootContext(); - REGISTER_QPREF(qPref, "SsrfPrefs"); - REGISTER_QPREF(qPrefCloudStorage, "SsrfCloudStoragePrefs"); - REGISTER_QPREF(qPrefDisplay, "SsrfDisplayPrefs"); - REGISTER_QPREF(qPrefDiveComputer, "SsrfDiveComputerPrefs"); - REGISTER_QPREF(qPrefDivePlanner, "SsrfDivePlannerPrefs"); - REGISTER_QPREF(qPrefFacebook, "SsrfFacebookPrefs"); - REGISTER_QPREF(qPrefGeneral, "SsrfGeneralPrefs"); - REGISTER_QPREF(qPrefGeocoding, "SsrfGeocodingPrefs"); - REGISTER_QPREF(qPrefLanguage, "SsrfLanguagePrefs"); - REGISTER_QPREF(qPrefLocationService, "SsrfLocationServicePrefs"); - REGISTER_QPREF(qPrefPartialPressureGas, "SsrfPartialPressureGasPrefs"); - REGISTER_QPREF(qPrefProxy, "SsrfProxyPrefs"); - REGISTER_QPREF(qPrefTechnicalDetails, "SsrfTechnicalDetailsPrefs"); - REGISTER_QPREF(qPrefUnits, "SsrfUnitPrefs"); - REGISTER_QPREF(qPrefUpdateManager, "SsrfUpdateManagerPrefs"); + ct->setContextProperty("Pref", qPref::instance()); + ct->setContextProperty("PrefCloudStorage", qPrefCloudStorage::instance()); + ct->setContextProperty("PrefDisplay", qPrefDisplay::instance()); + ct->setContextProperty("PrefDiveComputer", qPrefDiveComputer::instance()); + ct->setContextProperty("PrefDivePlanner", qPrefDivePlanner::instance()); + ct->setContextProperty("PrefFacebook", qPrefFacebook::instance()); + ct->setContextProperty("PrefGeneral", qPrefGeneral::instance()); + ct->setContextProperty("PrefGeocoding", qPrefGeocoding::instance()); + ct->setContextProperty("PrefLanguage", qPrefLanguage::instance()); + ct->setContextProperty("PrefLocationService", qPrefLocationService::instance()); + ct->setContextProperty("PrefPartialPressureGas", qPrefPartialPressureGas::instance()); + ct->setContextProperty("PrefProxy", qPrefProxy::instance()); + ct->setContextProperty("PrefTechnicalDetails", qPrefTechnicalDetails::instance()); + ct->setContextProperty("PrefUnits", qPrefUnits::instance()); + ct->setContextProperty("PrefUpdateManager", qPrefUpdateManager::instance()); + } + + // Register special types + qmlRegisterUncreatableType("org.subsurfacedivelog.mobile",1,0,"CloudStatus","Enum is not a type"); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); } diff --git a/core/settings/qPref.h b/core/settings/qPref.h index f62a5eec4..e42e2b96b 100644 --- a/core/settings/qPref.h +++ b/core/settings/qPref.h @@ -5,6 +5,7 @@ #include "ssrf-version.h" #include +#include #include "qPrefCloudStorage.h" #include "qPrefDisplay.h" @@ -23,7 +24,6 @@ class qPref : public QObject { Q_OBJECT - Q_ENUMS(cloud_status); Q_PROPERTY(QString canonical_version READ canonical_version); Q_PROPERTY(QString mobile_version READ mobile_version); @@ -36,7 +36,7 @@ public: static void sync() { loadSync(true); } // Register QML - void registerQML(); + void registerQML(QQmlEngine *engine); public: enum cloud_status { @@ -46,6 +46,7 @@ public: CS_VERIFIED, CS_NOCLOUD }; + Q_ENUM(cloud_status); static const QString canonical_version() { return QString(CANONICAL_VERSION_STRING); } static const QString mobile_version() { return QString(MOBILE_VERSION_STRING); } diff --git a/mobile-widgets/qml/CloudCredentials.qml b/mobile-widgets/qml/CloudCredentials.qml index 7869303e7..688c356ac 100644 --- a/mobile-widgets/qml/CloudCredentials.qml +++ b/mobile-widgets/qml/CloudCredentials.qml @@ -144,7 +144,7 @@ Item { text: qsTr("No cloud mode") onClicked: { manager.syncToCloud = false - prefs.credentialStatus = SsrfPrefs.CS_NOCLOUD + prefs.credentialStatus = CloudStatus.CS_NOCLOUD manager.saveCloudCredentials() manager.openNoCloudRepo() } diff --git a/mobile-widgets/qml/DiveList.qml b/mobile-widgets/qml/DiveList.qml index 86d4a9c1a..7ca5ec493 100644 --- a/mobile-widgets/qml/DiveList.qml +++ b/mobile-widgets/qml/DiveList.qml @@ -23,7 +23,7 @@ Kirigami.ScrollablePage { supportsRefreshing: true onRefreshingChanged: { if (refreshing) { - if (prefs.credentialStatus === SsrfPrefs.CS_VERIFIED) { + if (prefs.credentialStatus === CloudStatus.CS_VERIFIED) { console.log("User pulled down dive list - syncing with cloud storage") detailsWindow.endEditMode() manager.saveChangesCloud(true) @@ -339,8 +339,8 @@ Kirigami.ScrollablePage { StartPage { id: startPage anchors.fill: parent - opacity: credentialStatus === SsrfPrefs.CS_NOCLOUD || - (credentialStatus === SsrfPrefs.CS_VERIFIED) ? 0 : 1 + opacity: credentialStatus === CloudStatus.CS_NOCLOUD || + (credentialStatus === CloudStatus.CS_VERIFIED) ? 0 : 1 visible: opacity > 0 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } } function setupActions() { @@ -348,8 +348,8 @@ Kirigami.ScrollablePage { page.actions.main = null page.actions.right = null page.title = qsTr("Cloud credentials") - } else if (prefs.credentialStatus === SsrfPrefs.CS_VERIFIED || - prefs.credentialStatus === SsrfPrefs.CS_NOCLOUD) { + } else if (prefs.credentialStatus === CloudStatus.CS_VERIFIED || + prefs.credentialStatus === CloudStatus.CS_NOCLOUD) { page.actions.main = page.downloadFromDCAction page.actions.right = page.addDiveAction page.title = qsTr("Dive list") @@ -440,7 +440,7 @@ Kirigami.ScrollablePage { onBackRequested: { if (startPage.visible && diveListView.count > 0 && - prefs.credentialStatus !== SsrfPrefs.CS_INCORRECT_USER_PASSWD) { + prefs.credentialStatus !== CloudStatus.CS_INCORRECT_USER_PASSWD) { prefs.credentialStatus = oldStatus event.accepted = true; } diff --git a/mobile-widgets/qml/Settings.qml b/mobile-widgets/qml/Settings.qml index 45b588c93..4ba414adf 100644 --- a/mobile-widgets/qml/Settings.qml +++ b/mobile-widgets/qml/Settings.qml @@ -45,7 +45,7 @@ Kirigami.ScrollablePage { Layout.preferredHeight: Kirigami.Units.gridUnit * 2 } Controls.Label { - text: prefs.credentialStatus === SsrfPrefs.CS_NOCLOUD ? qsTr("Not applicable") : prefs.cloudUserName + text: prefs.credentialStatus === CloudStatus.CS_NOCLOUD ? qsTr("Not applicable") : prefs.cloudUserName Layout.alignment: Qt.AlignRight Layout.preferredWidth: gridWidth * 0.60 Layout.preferredHeight: Kirigami.Units.gridUnit * 2 @@ -333,7 +333,7 @@ Kirigami.ScrollablePage { inputMethodHints: Qt.ImhNoPredictiveText Layout.fillWidth: true onActivated: { - general.set_default_cylinder(defaultCylinderBox.currentText) + PrefGeneral.set_default_cylinder(defaultCylinderBox.currentText) } } } diff --git a/mobile-widgets/qml/main.qml b/mobile-widgets/qml/main.qml index fb1d8606b..1120750e8 100644 --- a/mobile-widgets/qml/main.qml +++ b/mobile-widgets/qml/main.qml @@ -102,7 +102,7 @@ Kirigami.ApplicationWindow { detailsWindow.cylinderModel2 = manager.cylinderInit detailsWindow.cylinderModel3 = manager.cylinderInit detailsWindow.cylinderModel4 = manager.cylinderInit - detailsWindow.cylinderIndex0 = general.default_cylinder == "" ? -1 : detailsWindow.cylinderModel0.indexOf(general.default_cylinder) + detailsWindow.cylinderIndex0 = PrefGeneral.default_cylinder == "" ? -1 : detailsWindow.cylinderModel0.indexOf(PrefGeneral.default_cylinder) detailsWindow.usedCyl = ["",] detailsWindow.weight = "" detailsWindow.usedGas = [] @@ -192,10 +192,10 @@ Kirigami.ApplicationWindow { text: qsTr("Dive list") onTriggered: { manager.appendTextToLog("requested dive list with credential status " + prefs.credentialStatus) - if (prefs.credentialStatus == SsrfPrefs.CS_UNKNOWN) { + if (prefs.credentialStatus == CloudStatus.CS_UNKNOWN) { // the user has asked to change credentials - if the credentials before that // were valid, go back to dive list - if (oldStatus == SsrfPrefs.CS_VERIFIED) { + if (oldStatus == CloudStatus.CS_VERIFIED) { prefs.credentialStatus = oldStatus } } @@ -222,8 +222,8 @@ Kirigami.ApplicationWindow { name: ":/icons/ic_add.svg" } text: qsTr("Add dive manually") - enabled: prefs.credentialStatus === SsrfPrefs.CS_VERIFIED || - prefs.credentialStatus === SsrfPrefs.CS_NOCLOUD + enabled: prefs.credentialStatus === CloudStatus.CS_VERIFIED || + prefs.credentialStatus === CloudStatus.CS_NOCLOUD onTriggered: { globalDrawer.close() returnTopPage() // otherwise odd things happen with the page stack @@ -257,14 +257,14 @@ Kirigami.ApplicationWindow { name: ":/icons/cloud_sync.svg" } text: qsTr("Manual sync with cloud") - enabled: prefs.credentialStatus === SsrfPrefs.CS_VERIFIED || - prefs.credentialStatus === SsrfPrefs.CS_NOCLOUD + enabled: prefs.credentialStatus === CloudStatus.CS_VERIFIED || + prefs.credentialStatus === CloudStatus.CS_NOCLOUD onTriggered: { - if (prefs.credentialStatus === SsrfPrefs.CS_NOCLOUD) { + if (prefs.credentialStatus === CloudStatus.CS_NOCLOUD) { returnTopPage() oldStatus = prefs.credentialStatus manager.startPageText = "Enter valid cloud storage credentials" - prefs.credentialStatus = SsrfPrefs.CS_UNKNOWN + prefs.credentialStatus = CloudStatus.CS_UNKNOWN globalDrawer.close() } else { globalDrawer.close() @@ -279,7 +279,7 @@ Kirigami.ApplicationWindow { name: syncToCloud ? ":/icons/ic_cloud_off.svg" : ":/icons/ic_cloud_done.svg" } text: syncToCloud ? qsTr("Disable auto cloud sync") : qsTr("Enable auto cloud sync") - enabled: prefs.credentialStatus !== SsrfPrefs.CS_NOCLOUD + enabled: prefs.credentialStatus !== CloudStatus.CS_NOCLOUD onTriggered: { syncToCloud = !syncToCloud if (!syncToCloud) { @@ -351,7 +351,7 @@ if you have network connectivity and want to sync your data to cloud storage."), onTriggered: { globalDrawer.close() settingsWindow.defaultCylinderModel = manager.cylinderInit - general.default_cylinder === "" ? defaultCylinderIndex = "-1" : defaultCylinderIndex = settingsWindow.defaultCylinderModel.indexOf(general.default_cylinder) + PrefGeneral.default_cylinder === "" ? defaultCylinderIndex = "-1" : defaultCylinderIndex = settingsWindow.defaultCylinderModel.indexOf(PrefGeneral.default_cylinder) stackView.push(settingsWindow) detailsWindow.endEditMode() } @@ -600,10 +600,6 @@ if you have network connectivity and want to sync your data to cloud storage."), visible: false } - SsrfGeneralPrefs { - id: general - } - onPluggedInDeviceNameChanged: { if (detailsWindow.state === 'edit' || detailsWindow.state === 'add') { /* we're in the middle of editing / adding a dive */ diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp index 38601ddf3..f261f3e1f 100644 --- a/subsurface-helper.cpp +++ b/subsurface-helper.cpp @@ -35,7 +35,6 @@ static void register_meta_types(); void init_ui() { init_qt_late(); - register_qml_types(); register_meta_types(); #ifndef SUBSURFACE_MOBILE PluginManager::instance().loadPlugins(); @@ -60,11 +59,15 @@ double get_screen_dpi() return mydesk->physicalDpiX(); } +// Forward declaration +static void register_qml_types(QQmlEngine *); + void run_ui() { #ifdef SUBSURFACE_MOBILE QQmlApplicationEngine engine; + register_qml_types(&engine); LOG_STP("run_ui qml engine started"); KirigamiPlugin::getInstance().registerTypes(); #if defined(__APPLE__) && !defined(Q_OS_IOS) @@ -135,6 +138,7 @@ void run_ui() qml_window->show(); LOG_STP("run_ui running exec"); #else + register_qml_types(NULL); MainWindow::instance()->show(); #endif // SUBSURFACE_MOBILE qApp->exec(); @@ -152,16 +156,14 @@ static void register_meta_types() if (rc < 0) \ qWarning() << "ERROR: Cannot register " << useQML << ", QML will not work!!"; -void register_qml_types() +void register_qml_types(QQmlEngine *engine) { - int rc; - - (void)rc; - // register qPref* - qPref::instance()->registerQML(); + qPref::instance()->registerQML(engine); #ifndef SUBSURFACE_TEST_DATA + int rc; + #ifdef SUBSURFACE_MOBILE REGISTER_TYPE(QMLManager, "QMLManager"); REGISTER_TYPE(QMLPrefs, "QMLPrefs"); diff --git a/tests/testqml.cpp b/tests/testqml.cpp index 9f66d216f..14aa0bf5c 100644 --- a/tests/testqml.cpp +++ b/tests/testqml.cpp @@ -37,7 +37,7 @@ int main(int argc, char **argv) argc--; // Register types - qPref::instance()->registerQML(); + qPref::instance()->registerQML(NULL); // Run all tst_*.qml files return quick_test_main(argc, argv, "TestQML", tst_dir);