コード例 #1
0
ファイル: qmlmanager.cpp プロジェクト: lehoon/subsurface
void QMLManager::consumeFinishedLoad(timestamp_t currentDiveTimestamp)
{
	prefs.unit_system = informational_prefs.unit_system;
	if (informational_prefs.unit_system == IMPERIAL)
		informational_prefs.units = IMPERIAL_units;
	prefs.units = informational_prefs.units;
	DiveListModel::instance()->clear();
	process_dives(false, false);
	DiveListModel::instance()->addAllDives();
	if (currentDiveTimestamp)
		setUpdateSelectedDive(dlSortModel->getIdxForId(get_dive_id_closest_to(currentDiveTimestamp)));
	appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr));
	if (dive_table.nr == 0)
		setStartPageText(tr("Cloud storage open successfully. No dives in dive list."));
	alreadySaving = false;
}
コード例 #2
0
ファイル: qmlmanager.cpp プロジェクト: tcanabrava/subsurface
void QMLManager::loadDivesWithValidCredentials()
{
	QString url;
	if (getCloudURL(url)) {
		QString errorString(get_error_string());
		appendTextToLog(errorString);
		setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(errorString) + END_FONT);
		setAccessingCloud(-1);
		alreadySaving = false;
		return;
	}
	QByteArray fileNamePrt = QFile::encodeName(url);
	git_repository *git;
	const char *branch;
	int error;
	if (check_git_sha(fileNamePrt.data(), &git, &branch) == 0) {
		qDebug() << "local cache was current, no need to modify dive list";
		appendTextToLog("Cloud sync shows local cache was current");
		setLoadFromCloud(true);
		setAccessingCloud(-1);
		alreadySaving = false;
		return;
	}
	appendTextToLog("Cloud sync brought newer data, reloading the dive list");
	timestamp_t currentDiveTimestamp = selectedDiveTimestamp();

	clear_dive_file_data();
	if (git != dummy_git_repository) {
		appendTextToLog(QString("have repository and branch %1").arg(branch));
		error = git_load_dives(git, branch);
	} else {
		appendTextToLog(QString("didn't receive valid git repo, try again"));
		error = parse_file(fileNamePrt.data());
	}
	setAccessingCloud(-1);
	if (!error) {
		report_error("filename is now %s", fileNamePrt.data());
		const char *error_string = get_error_string();
		appendTextToLog(error_string);
		set_filename(fileNamePrt.data(), true);
	} else {
		report_error("failed to open file %s", fileNamePrt.data());
		QString errorString(get_error_string());
		appendTextToLog(errorString);
		setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(errorString) + END_FONT);
		alreadySaving = false;
		return;
	}
	prefs.unit_system = informational_prefs.unit_system;
	if (informational_prefs.unit_system == IMPERIAL)
		informational_prefs.units = IMPERIAL_units;
	prefs.units = informational_prefs.units;
	DiveListModel::instance()->clear();
	process_dives(false, false);
	DiveListModel::instance()->addAllDives();
	if (currentDiveTimestamp)
		setUpdateSelectedDive(dlSortModel->getIdxForId(get_dive_id_closest_to(currentDiveTimestamp)));
	else
		setUpdateSelectedDive(0);
	appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr));
	if (dive_table.nr == 0)
		setStartPageText(tr("Cloud storage open successfully. No dives in dive list."));
	setLoadFromCloud(true);
	alreadySaving = false;
}