示例#1
0
QMLManager::QMLManager() : m_locationServiceEnabled(false),
	m_verboseEnabled(false),
	reply(0),
	deletedDive(0),
	deletedTrip(0),
	m_updateSelectedDive(-1),
	m_selectedDiveTimestamp(0),
	m_credentialStatus(UNKNOWN),
	m_lastDevicePixelRatio(1.0),
	alreadySaving(false)
{
	m_instance = this;
	connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged);
	appendTextToLog(getUserAgent());
	appendTextToLog(QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion()));
	qDebug() << "Starting" << getUserAgent();
	qDebug() << QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion());
	setStartPageText(tr("Starting..."));
	setAccessingCloud(-1);
	setShowPin(false);
	// create location manager service
	locationProvider = new GpsLocation(&appendTextToLogStandalone, this);
	connect(locationProvider, SIGNAL(haveSourceChanged()), this, SLOT(hasLocationSourceChanged()));
	setLocationServiceAvailable(locationProvider->hasLocationsSource());
	set_git_update_cb(&gitProgressCB);

	// make sure we know if the current cloud repo has been successfully synced
	syncLoadFromCloud();
}
示例#2
0
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();
	}
}
示例#3
0
QMLManager::QMLManager() : m_locationServiceEnabled(false),
	m_verboseEnabled(false),
	m_credentialStatus(UNKNOWN),
	reply(0)
{
	m_instance = this;
	appendTextToLog(getUserAgent());
	appendTextToLog(QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion()));
	qDebug() << "Starting" << getUserAgent();
	qDebug() << QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion());
	setStartPageText(tr("Starting..."));
	// create location manager service
	locationProvider = new GpsLocation(&appendTextToLogStandalone, this);
	set_git_update_cb(&gitProgressCB);

	// make sure we know if the current cloud repo has been successfully synced
	syncLoadFromCloud();
}
示例#4
0
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);
	}
}