void QMLManager::saveCloudCredentials() { QSettings s; bool cloudCredentialsChanged = false; s.beginGroup("CloudStorage"); s.setValue("email", cloudUserName()); s.setValue("password", cloudPassword()); s.sync(); if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUserName()))) { free(prefs.cloud_storage_email); prefs.cloud_storage_email = strdup(qPrintable(cloudUserName())); cloudCredentialsChanged = true; } cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, qPrintable(cloudPassword())); if (!cloudCredentialsChanged) { // just go back to the dive list setCredentialStatus(oldStatus()); } if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()))) { free(prefs.cloud_storage_password); prefs.cloud_storage_password = strdup(qPrintable(cloudPassword())); } if (cloudUserName().isEmpty() || cloudPassword().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(); QString url; getCloudURL(url); manager()->clearAccessCache(); // remove any chached credentials clear_git_id(); // invalidate our remembered GIT SHA clear_dive_file_data(); DiveListModel::instance()->clear(); GpsListModel::instance()->clear(); setStartPageText(tr("Attempting to open cloud storage with new credentials")); // we therefore know that no one else is already accessing THIS git repo; // let's make sure we stay the only ones doing so alreadySaving = true; // since we changed credentials, we need to try to connect to the cloud, regardless // of whether we're in offline mode or not, to make sure the repository is synced currentGitLocalOnly = prefs.git_local_only; prefs.git_local_only = false; openLocalThenRemote(url); } else if (prefs.cloud_verification_status = CS_NEED_TO_VERIFY && !cloudPin().isEmpty()) { // the user entered a PIN? tryRetrieveDataFromBackend(); } }
void QMLManager::savePreferences() { QSettings s; bool cloudCredentialsChanged = false; s.beginGroup("LocationService"); s.setValue("time_threshold", timeThreshold() * 60); prefs.time_threshold = timeThreshold() * 60; s.setValue("distance_threshold", distanceThreshold()); prefs.distance_threshold = distanceThreshold(); s.endGroup(); s.beginGroup("CloudStorage"); s.setValue("email", cloudUserName()); s.setValue("save_password_local", saveCloudPassword()); if (saveCloudPassword()) s.setValue("password", cloudPassword()); s.sync(); if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUserName()))) { free(prefs.cloud_storage_email); prefs.cloud_storage_email = strdup(qPrintable(cloudUserName())); cloudCredentialsChanged = true; } if (saveCloudPassword() != prefs.save_password_local) prefs.save_password_local = saveCloudPassword(); cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, qPrintable(cloudPassword())); if (saveCloudPassword()) { if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()))) { free(prefs.cloud_storage_password); prefs.cloud_storage_password = strdup(qPrintable(cloudPassword())); } } // if the cloud credentials are valid, we should get the GPS Webservice ID as well if (!same_string(prefs.cloud_storage_email, "") && !same_string(prefs.cloud_storage_password, "")) { if (same_string(prefs.userid, "") || cloudCredentialsChanged) { QString userid = locationProvider->getUserid(prefs.cloud_storage_email, prefs.cloud_storage_password); if (!userid.isEmpty()) { // overwrite the existing userid free(prefs.userid); prefs.userid = strdup(qPrintable(userid)); s.setValue("subsurface_webservice_uid", prefs.userid); } } } }
void QMLManager::saveCloudCredentials() { QSettings s; bool cloudCredentialsChanged = false; s.beginGroup("CloudStorage"); s.setValue("email", cloudUserName()); s.setValue("password", cloudPassword()); s.sync(); if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUserName()))) { free(prefs.cloud_storage_email); prefs.cloud_storage_email = strdup(qPrintable(cloudUserName())); cloudCredentialsChanged = true; } cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, qPrintable(cloudPassword())); if (!cloudCredentialsChanged) { // just go back to the dive list setCredentialStatus(oldStatus()); } if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()))) { free(prefs.cloud_storage_password); prefs.cloud_storage_password = strdup(qPrintable(cloudPassword())); } if (cloudUserName().isEmpty() || cloudPassword().isEmpty()) { setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); } else if (cloudCredentialsChanged) { free(prefs.userid); prefs.userid = NULL; syncLoadFromCloud(); QString url; getCloudURL(url); manager()->clearAccessCache(); // remove any chached credentials clear_git_id(); // invalidate our remembered GIT SHA clear_dive_file_data(); DiveListModel::instance()->clear(); GpsListModel::instance()->clear(); setStartPageText(tr("Attempting to open cloud storage with new credentials")); // we therefore know that no one else is already accessing THIS git repo; // let's make sure we stay the only ones doing so alreadySaving = true; openLocalThenRemote(url); } }
void QMLManager::finishSetup() { // Initialize cloud credentials. setCloudUserName(prefs.cloud_storage_email); setCloudPassword(prefs.cloud_storage_password); // if the cloud credentials are valid, we should get the GPS Webservice ID as well QString url; if (!cloudUserName().isEmpty() && !cloudPassword().isEmpty() && getCloudURL(url) == 0) { // we know that we are the first ones to access git storage, so we don't need to test, // but we need to make sure we stay the only ones accessing git storage alreadySaving = true; openLocalThenRemote(url); } else { setCredentialStatus(INCOMPLETE); appendTextToLog(QStringLiteral("no cloud credentials")); setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); } setDistanceThreshold(prefs.distance_threshold); setTimeThreshold(prefs.time_threshold / 60); }
void QMLManager::finishSetup() { // Initialize cloud credentials. setCloudUserName(prefs.cloud_storage_email); setCloudPassword(prefs.cloud_storage_password); setSyncToCloud(!prefs.git_local_only); // if the cloud credentials are valid, we should get the GPS Webservice ID as well QString url; if (!cloudUserName().isEmpty() && !cloudPassword().isEmpty() && getCloudURL(url) == 0) { // we know that we are the first ones to access git storage, so we don't need to test, // but we need to make sure we stay the only ones accessing git storage alreadySaving = true; openLocalThenRemote(url); } else if (!same_string(existing_filename, "")) { setCredentialStatus(NOCLOUD); appendTextToLog(tr("working in no-cloud mode")); int error = parse_file(existing_filename); if (error) { // we got an error loading the local file appendTextToLog(QString("got error %2 when parsing file %1").arg(existing_filename, get_error_string())); set_filename(NULL, ""); } else { // successfully opened the local file, now add thigs to the dive list consumeFinishedLoad(0); setAccessingCloud(-1); appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(dive_table.nr).arg(existing_filename)); } } else { setCredentialStatus(INCOMPLETE); appendTextToLog(tr("no cloud credentials")); setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); } setDistanceThreshold(prefs.distance_threshold); setTimeThreshold(prefs.time_threshold / 60); }