diff options
Diffstat (limited to 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qml/DownloadFromDiveComputer.qml | 24 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 31 |
2 files changed, 45 insertions, 10 deletions
diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml index b7f000a46..9086a2e0f 100644 --- a/mobile-widgets/qml/DownloadFromDiveComputer.qml +++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml @@ -26,7 +26,7 @@ Kirigami.Page { deviceData.product : comboProduct.currentText //TODO: make this dynamic? - deviceData.devName : "/tmp/ttyS1" + deviceData.devName : comboConnection.currentText //TODO: Make this the default on the C++ deviceData.bluetoothMode : isBluetooth.checked @@ -82,10 +82,32 @@ Kirigami.Page { Layout.fillWidth: true model: null currentIndex: productidx + onCurrentTextChanged: { + var newIdx = downloadThread.data().getMatchingAddress(comboVendor.currentText, currentText) + if (newIdx != -1) + comboConnection.currentIndex = newIdx + } + onModelChanged: { currentIndex = productidx } } + Kirigami.Label { text: qsTr(" Connection:") } + ComboBox { + id: comboConnection + Layout.fillWidth: true + model: connectionListModel + currentIndex: -1 + onCurrentTextChanged: { + // pattern that matches BT addresses + var btAddr = /[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]/ ; + if (btAddr.test(currentText)) + isBluetooth.checked = true + else + isBluetooth.checked = false + } + } + Kirigami.Label { text: btEnabled ? qsTr("Bluetooth download:") : qsTr("No Bluetooth support detected")} CheckBox { id: isBluetooth diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 5b526362a..5066c589a 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -278,33 +278,46 @@ void QMLManager::saveCloudCredentials() { QSettings s; bool cloudCredentialsChanged = false; + // make sure we only have letters, numbers, and +-_. in password and email address + QRegularExpression regExp("^[a-zA-Z0-9@.+_-]+$"); + QString cloudPwd = cloudPassword(); + QString cloudUser = cloudUserName(); + if (cloudPwd.isEmpty() || !regExp.match(cloudPwd).hasMatch() || !regExp.match(cloudUser).hasMatch()) { + setStartPageText(RED_FONT + tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.") + END_FONT); + return; + } + // use the same simplistic regex as the backend to check email addresses + regExp = QRegularExpression("^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.+_-]+\\.[a-zA-Z0-9]+"); + if (!regExp.match(cloudUser).hasMatch()) { + setStartPageText(RED_FONT + tr("Invalid format for email address") + END_FONT); + return; + } s.beginGroup("CloudStorage"); - s.setValue("email", cloudUserName()); - s.setValue("password", cloudPassword()); + s.setValue("email", cloudUser); + s.setValue("password", cloudPwd); s.sync(); - if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUserName()))) { + if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUser))) { free(prefs.cloud_storage_email); - prefs.cloud_storage_email = strdup(qPrintable(cloudUserName())); + prefs.cloud_storage_email = strdup(qPrintable(cloudUser)); cloudCredentialsChanged = true; } - cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, qPrintable(cloudPassword())); + cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, qPrintable(cloudPwd)); if (!cloudCredentialsChanged) { // just go back to the dive list setCredentialStatus(oldStatus()); } - if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()))) { + if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPwd))) { free(prefs.cloud_storage_password); - prefs.cloud_storage_password = strdup(qPrintable(cloudPassword())); + prefs.cloud_storage_password = strdup(qPrintable(cloudPwd)); } - if (cloudUserName().isEmpty() || cloudPassword().isEmpty()) { + if (cloudUser.isEmpty() || cloudPwd.isEmpty()) { setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); } else if (cloudCredentialsChanged) { // let's make sure there are no unsaved changes saveChangesLocal(); - free(prefs.userid); prefs.userid = NULL; syncLoadFromCloud(); |