diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/divelogimportdialog.cpp | 53 | ||||
-rw-r--r-- | qt-ui/divelogimportdialog.h | 2 | ||||
-rw-r--r-- | qt-ui/diveplanner.cpp | 6 | ||||
-rw-r--r-- | qt-ui/preferences.cpp | 40 | ||||
-rw-r--r-- | qt-ui/preferences.h | 1 | ||||
-rw-r--r-- | qt-ui/preferences.ui | 11 | ||||
-rw-r--r-- | qt-ui/subsurfacewebservices.cpp | 14 | ||||
-rw-r--r-- | qt-ui/subsurfacewebservices.h | 3 |
8 files changed, 101 insertions, 29 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index ea783b093..d799bf17f 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -13,7 +13,8 @@ const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = // time, depth, temperature, po2, sensor1, sensor2, sensor3, cns, ndl, tts, stopdepth, pressure, setpoint // indices are 0 based, -1 means the column doesn't exist { "Manual import", }, - { "APD Log Viewer", 0, 1, 15, 6, 3, 4, 5, 17, -1, -1, 18, -1, 2, "Tab" }, + { "APD Log Viewer - DC1", 0, 1, 15, 6, 3, 4, 5, 17, -1, -1, 18, -1, 2, "Tab" }, + { "APD Log Viewer - DC2", 0, 1, 15, 6, 7, 8, 9, 17, -1, -1, 18, -1, 2, "Tab" }, { "XP5", 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Tab" }, { "SensusCSV", 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "," }, { "Seabear CSV", 0, 1, 5, -1, -1, -1, -1, -1, 2, 3, 4, 6, -1, ";" }, @@ -21,6 +22,16 @@ const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = { NULL, } }; +static enum { + MANUAL, + APD, + APD2, + XP5, + SENSUS, + SEABEAR, + SUBSURFACE +} known; + ColumnNameProvider::ColumnNameProvider(QObject *parent) : QAbstractListModel(parent) { columnNames << tr("Dive #") << tr("Date") << tr("Time") << tr("Duration") << tr("Location") << tr("GPS") << tr("Weight") << tr("Cyl. size") << tr("Start pressure") << @@ -387,7 +398,7 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) while ((firstLine = f.readLine()).length() > 3 && !f.atEnd()) { if (firstLine.contains("//Log interval: ")) - delta = firstLine.remove(QString::fromLatin1("//Log interval: ")).trimmed(); + delta = firstLine.remove(QString::fromLatin1("//Log interval: ")).trimmed().remove(QString::fromLatin1(" s")); } /* @@ -416,6 +427,8 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) headers.append("Sample sensor3 pO₂"); } else if (columnText == "Ceiling") { headers.append("Sample ceiling"); + } else if (columnText == "Tank pressure") { + headers.append("Sample pressure"); } else { // We do not know about this value qDebug() << "Seabear import found an un-handled field: " << columnText; @@ -437,13 +450,13 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) } // Special handling for APD Log Viewer - if ((triggeredBy == KNOWNTYPES && value == 1) || (triggeredBy == INITIAL && fileNames.first().endsWith(".apd", Qt::CaseInsensitive))) { + if ((triggeredBy == KNOWNTYPES && (value == APD || value == APD2)) || (triggeredBy == INITIAL && fileNames.first().endsWith(".apd", Qt::CaseInsensitive))) { apd=true; - firstLine = "Sample time\tSample depth\tSample setpoint\t\t\t\tSample pO₂\t\t\t\t\t\t\t\t\tSample temperature\t\tSample CNS\tSample stopdepth"; + firstLine = "Sample time\tSample depth\tSample setpoint\tSample sensor1 pO₂\tSample sensor2 pO₂\tSample sensor3 pO₂\tSample pO₂\t\t\t\t\t\t\t\t\tSample temperature\t\tSample CNS\tSample stopdepth"; blockSignals(true); ui->CSVSeparator->setCurrentText(tr("Tab")); if (triggeredBy == INITIAL && fileNames.first().contains(".apd", Qt::CaseInsensitive)) - ui->knownImports->setCurrentText("APD Log Viewer"); + ui->knownImports->setCurrentText("APD Log Viewer - DC1"); blockSignals(false); } @@ -467,13 +480,21 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) currColumns = firstLine.split(separator); } } - if (triggeredBy == INITIAL || (triggeredBy == KNOWNTYPES && value == 0) || triggeredBy == SEPARATOR) { + if (triggeredBy == INITIAL || (triggeredBy == KNOWNTYPES && value == MANUAL) || triggeredBy == SEPARATOR) { // now try and guess the columns Q_FOREACH (QString columnText, currColumns) { - columnText.replace("\"", ""); - columnText.replace("number", "#", Qt::CaseInsensitive); - columnText.replace("2", "₂", Qt::CaseInsensitive); - columnText.replace("cylinder", "cyl.", Qt::CaseInsensitive); + /* + * We have to skip the conversion of 2 to ₂ for APD Log + * viewer as that would mess up the sensor numbering. We + * also know that the column headers do not need this + * conversion. + */ + if (triggeredBy == KNOWNTYPES && value != APD) { + columnText.replace("\"", ""); + columnText.replace("number", "#", Qt::CaseInsensitive); + columnText.replace("2", "₂", Qt::CaseInsensitive); + columnText.replace("cylinder", "cyl.", Qt::CaseInsensitive); + } int idx = provider->mymatch(columnText); if (idx >= 0) { QString foundHeading = provider->data(provider->index(idx, 0), Qt::DisplayRole).toString(); @@ -493,9 +514,9 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) } } } - if (triggeredBy == KNOWNTYPES && value != 0) { + if (triggeredBy == KNOWNTYPES && value != MANUAL) { // an actual known type - if (value == 5) { + if (value == SUBSURFACE) { /* * Subsurface CSV file needs separator detection * as we used to default to comma but switched @@ -530,11 +551,11 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) headers.replace(CSVApps[value].temperature, tr("Sample temperature")); if (CSVApps[value].po2 > -1 && CSVApps[value].po2 < currColumns.count()) headers.replace(CSVApps[value].po2, tr("Sample pO₂")); - if (CSVApps[value].po2 > -1 && CSVApps[value].po2 < currColumns.count()) + if (CSVApps[value].sensor1 > -1 && CSVApps[value].sensor1 < currColumns.count()) headers.replace(CSVApps[value].sensor1, tr("Sample sensor1 pO₂")); - if (CSVApps[value].po2 > -1 && CSVApps[value].po2 < currColumns.count()) + if (CSVApps[value].sensor2 > -1 && CSVApps[value].sensor2 < currColumns.count()) headers.replace(CSVApps[value].sensor2, tr("Sample sensor2 pO₂")); - if (CSVApps[value].po2 > -1 && CSVApps[value].po2 < currColumns.count()) + if (CSVApps[value].sensor3 > -1 && CSVApps[value].sensor3 < currColumns.count()) headers.replace(CSVApps[value].sensor3, tr("Sample sensor3 pO₂")); if (CSVApps[value].cns > -1 && CSVApps[value].cns < currColumns.count()) headers.replace(CSVApps[value].cns, tr("Sample CNS")); @@ -601,7 +622,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() r.indexOf(tr("Sample stopdepth")), r.indexOf(tr("Sample pressure")), ui->CSVSeparator->currentIndex(), - specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv", + "csv", ui->CSVUnits->currentIndex(), delta.toUtf8().data() ) < 0) { diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h index c5c750973..050090f97 100644 --- a/qt-ui/divelogimportdialog.h +++ b/qt-ui/divelogimportdialog.h @@ -114,7 +114,7 @@ private: QString separator; }; -#define CSVAPPS 7 +#define CSVAPPS 8 static const CSVAppConfig CSVApps[CSVAPPS]; }; diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index f6f6c3894..efa75ddec 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -256,7 +256,7 @@ PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f) ui.setupUi(this); QSettings s; - QStringList rebreater_modes; + QStringList rebreather_modes; s.beginGroup("Planner"); prefs.last_stop = s.value("last_stop", prefs.last_stop).toBool(); prefs.verbatim_plan = s.value("verbatim_plan", prefs.verbatim_plan).toBool(); @@ -302,8 +302,8 @@ PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f) ui.vpmb_deco->setChecked(prefs.deco_mode == VPMB); // should be the same order as in dive_comp_type! - rebreater_modes << tr("Open circuit") << tr("CCR") << tr("pSCR"); - ui.rebreathermode->insertItems(0, rebreater_modes); + rebreather_modes << tr("Open circuit") << tr("CCR") << tr("pSCR"); + ui.rebreathermode->insertItems(0, rebreather_modes); modeMapper = new QSignalMapper(this); connect(modeMapper, SIGNAL(mapped(int)) , plannerModel, SLOT(setDecoMode(int))); diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index b30e76e03..04fb3a825 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -110,6 +110,10 @@ void PreferencesDialog::cloudPinNeeded() ui.cloud_storage_pin->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); ui.cloud_storage_pin_label->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); ui.cloud_storage_pin_label->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui.cloud_storage_new_passwd->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui.cloud_storage_new_passwd->setVisible(prefs.cloud_verification_status == CS_VERIFIED); + ui.cloud_storage_new_passwd_label->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui.cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); if (prefs.cloud_verification_status == CS_VERIFIED) { ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); ui.cloudDefaultFile->setEnabled(true); @@ -408,10 +412,29 @@ void PreferencesDialog::syncSettings() s.beginGroup("CloudStorage"); QString email = ui.cloud_storage_email->text(); QString password = ui.cloud_storage_password->text(); - if (prefs.cloud_verification_status == CS_UNKNOWN || - prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || - email != prefs.cloud_storage_email || - password != prefs.cloud_storage_password) { + QString newpassword = ui.cloud_storage_new_passwd->text(); + if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) { + // deal with password change + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull())); + QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword); + ui.cloud_storage_new_passwd->setText(""); + free(prefs.cloud_storage_newpassword); + prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword)); + } + } + } else if (prefs.cloud_verification_status == CS_UNKNOWN || + prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || + email != prefs.cloud_storage_email || + password != prefs.cloud_storage_password) { + // different credentials - reset verification status prefs.cloud_verification_status = CS_UNKNOWN; if (!email.isEmpty() && !password.isEmpty()) { @@ -422,7 +445,7 @@ void PreferencesDialog::syncSettings() } else { CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->authenticate(email, password); + QNetworkReply *reply = cloudAuth->backend(email, password); } } } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) { @@ -435,7 +458,7 @@ void PreferencesDialog::syncSettings() } CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->authenticate(email, password, pin); + QNetworkReply *reply = cloudAuth->backend(email, password, pin); } } SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); @@ -666,6 +689,11 @@ void PreferencesDialog::on_resetSettings_clicked() } } +void PreferencesDialog::passwordUpdateSuccessfull() +{ + ui.cloud_storage_password->setText(prefs.cloud_storage_password); +} + void PreferencesDialog::emitSettingsChanged() { emit settingsChanged(); diff --git a/qt-ui/preferences.h b/qt-ui/preferences.h index 2402a7964..326b1f964 100644 --- a/qt-ui/preferences.h +++ b/qt-ui/preferences.h @@ -40,6 +40,7 @@ slots: void facebookLoggedIn(); void facebookDisconnect(); void cloudPinNeeded(); + void passwordUpdateSuccessfull(); private: explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); void setUiFromPrefs(); diff --git a/qt-ui/preferences.ui b/qt-ui/preferences.ui index 1b59e77a5..dc0d04a5a 100644 --- a/qt-ui/preferences.ui +++ b/qt-ui/preferences.ui @@ -1374,6 +1374,13 @@ </property> </widget> </item> + <item row="0" column="3"> + <widget class="QLabel" name="cloud_storage_new_passwd_label"> + <property name="text"> + <string>New password</string> + </property> + </widget> + </item> <item row="1" column="0"> <widget class="QLineEdit" name="cloud_storage_email"> <property name="toolTip"> @@ -1391,6 +1398,10 @@ </property> </widget> </item> + <item row="1" column="3"> + <widget class="QLineEdit" name="cloud_storage_new_passwd"> + </widget> + </item> <item row="2" column="0"> <widget class="QCheckBox" name="cloud_background_sync"> <property name="text"> diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index fd9f2fad1..8154ce5fb 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -988,13 +988,17 @@ CloudStorageAuthenticate::CloudStorageAuthenticate(QObject *parent) : #define CLOUDURL QString(prefs.cloud_base_url) #define CLOUDBACKENDSTORAGE CLOUDURL + "/storage" #define CLOUDBACKENDVERIFY CLOUDURL + "/verify" +#define CLOUDBACKENDUPDATE CLOUDURL + "/update" -QNetworkReply* CloudStorageAuthenticate::authenticate(QString email, QString password, QString pin) +QNetworkReply* CloudStorageAuthenticate::backend(QString email, QString password, QString pin, QString newpasswd) { QString payload(email + " " + password); QUrl requestUrl; - if (pin == "") { + if (pin == "" && newpasswd == "") { requestUrl = QUrl(CLOUDBACKENDSTORAGE); + } else if (newpasswd != "") { + requestUrl = QUrl(CLOUDBACKENDUPDATE); + payload += " " + newpasswd; } else { requestUrl = QUrl(CLOUDBACKENDVERIFY); payload += " " + pin; @@ -1025,6 +1029,12 @@ void CloudStorageAuthenticate::uploadFinished() myLastError.clear(); } else if (cloudAuthReply == "[VERIFY]") { prefs.cloud_verification_status = CS_NEED_TO_VERIFY; + } else if (cloudAuthReply == "[PASSWDCHANGED]") { + free(prefs.cloud_storage_password); + prefs.cloud_storage_password = prefs.cloud_storage_newpassword; + prefs.cloud_storage_newpassword = NULL; + emit passwordChangeSuccessful(); + return; } else { prefs.cloud_verification_status = CS_INCORRECT_USER_PASSWD; myLastError = cloudAuthReply; diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h index e4866c529..2b454ebc7 100644 --- a/qt-ui/subsurfacewebservices.h +++ b/qt-ui/subsurfacewebservices.h @@ -114,10 +114,11 @@ slots: class CloudStorageAuthenticate : public QObject { Q_OBJECT public: - QNetworkReply* authenticate(QString email, QString password, QString pin = ""); + QNetworkReply* backend(QString email, QString password, QString pin = "", QString newpasswd = ""); explicit CloudStorageAuthenticate(QObject *parent); signals: void finishedAuthenticate(); + void passwordChangeSuccessful(); private slots: void uploadError(QNetworkReply::NetworkError error); |