コード例 #1
0
ファイル: qmlmanager.cpp プロジェクト: lehoon/subsurface
void QMLManager::revertToNoCloudIfNeeded()
{
	if (currentGitLocalOnly) {
		// we tried to connect to the cloud for the first time and that failed
		currentGitLocalOnly = false;
		prefs.git_local_only = true;
	}
	if (oldStatus() == NOCLOUD) {
		// we tried to switch to a cloud account and had previously used local data,
		// but connecting to the cloud account (and subsequently merging the local
		// and cloud data) failed - so let's delete the cloud credentials and go
		// back to NOCLOUD mode in order to prevent us from losing the locally stored
		// dives
		if (syncToCloud() == false) {
			appendTextToLog(QStringLiteral("taking things back offline since sync with cloud failed"));
			prefs.git_local_only = syncToCloud();
		}
		free(prefs.cloud_storage_email);
		prefs.cloud_storage_email = NULL;
		free(prefs.cloud_storage_password);
		prefs.cloud_storage_password = NULL;
		setCloudUserName("");
		setCloudPassword("");
		setCredentialStatus(INCOMPLETE);
		set_filename(NOCLOUD_LOCALSTORAGE, true);
		setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT);
	}
	setAccessingCloud(-1);
	alreadySaving = false;
}
コード例 #2
0
ファイル: qmlmanager.cpp プロジェクト: lehoon/subsurface
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
ファイル: Server.C プロジェクト: gechen/IQmol
void Server::queryFinished()
{
   ServerTask::Query* query(qobject_cast<ServerTask::Query*>(sender()));
   if (!query) return;

   Process* process(query->process());
   Process::Status oldStatus(process->status());
   Process::Status newStatus(query->newStatus());

   // Check for any error and bail cos, really, we don't know what's going on
   QString msg(query->errorMessage());
   if (!msg.isEmpty()) {
      process->setComment(msg);
      process->setStatus(Process::Unknown);
#ifndef Q_WS_WIN32
      query->deleteLater();
#endif
      return;
   }

   if (oldStatus == Process::Queued    || 
       oldStatus == Process::Running   || 
       oldStatus == Process::Suspended ||
       oldStatus == Process::Unknown) {

      if (newStatus == Process::Unknown) {
         ServerTask::Base* task(cleanUp(process));
         if (task) {
            connect(task, SIGNAL(finished()), this, SLOT(cleanUpFinished()));
            task->start();
         }
         removeFromWatchList(process);
#ifndef Q_WS_WIN32
         query->deleteLater();
#endif
         return;
      }else if (newStatus == Process::Queued    || 
                newStatus == Process::Running   || 
                newStatus == Process::Suspended) {
         process->setStatus(newStatus);
      }else {
         process->setStatus(newStatus);
         removeFromWatchList(process);
         QLOG_WARN() << "Inactive process found in Server::queryFinished";
      }
      
   }else {
      removeFromWatchList(process);
   }
#ifndef Q_WS_WIN32
   query->deleteLater();
#endif
}
コード例 #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);
	}
}
コード例 #5
0
ファイル: qmlmanager.cpp プロジェクト: lehoon/subsurface
void QMLManager::openLocalThenRemote(QString url)
{
	clear_dive_file_data();
	QByteArray fileNamePrt = QFile::encodeName(url);
	bool glo = prefs.git_local_only;
	prefs.git_local_only = true;
	int error = parse_file(fileNamePrt.data());
	setAccessingCloud(-1);
	prefs.git_local_only = glo;
	if (error) {
		appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error));
	} else {
		// if we can load from the cache, we know that we have at least a valid email
		if (credentialStatus() == UNKNOWN)
			setCredentialStatus(VALID_EMAIL);
		prefs.unit_system = informational_prefs.unit_system;
		if (informational_prefs.unit_system == IMPERIAL)
			informational_prefs.units = IMPERIAL_units;
		prefs.units = informational_prefs.units;
		process_dives(false, false);
		DiveListModel::instance()->clear();
		DiveListModel::instance()->addAllDives();
		appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(dive_table.nr));
	}
	if (oldStatus() == NOCLOUD) {
		// if we switch to credentials from NOCLOUD, we take things online temporarily
		prefs.git_local_only = false;
		appendTextToLog(QStringLiteral("taking things online to be able to switch to cloud account"));
	}
	set_filename(fileNamePrt.data(), true);
	if (prefs.git_local_only) {
		appendTextToLog(QStringLiteral("have cloud credentials, but user asked not to connect to network"));
		alreadySaving = false;
	} else {
		appendTextToLog(QStringLiteral("have cloud credentials, trying to connect"));
		tryRetrieveDataFromBackend();
	}
}
コード例 #6
0
ファイル: Server.C プロジェクト: baneofblabs/IQmol
void Server::queryFinished()
{
    ServerTask::Query* task = qobject_cast<ServerTask::Query*>(sender());
    if (!task) return;

    Process* process(task->process());
    Process::Status oldStatus(process->status());
    Process::Status newStatus(task->newStatus());
    task->deleteLater();

    if (oldStatus == Process::Queued    ||
            oldStatus == Process::Running   ||
            oldStatus == Process::Suspended ||
            oldStatus == Process::Unknown) {

        if (newStatus == Process::Unknown) {
            ServerTask::Base* task(cleanUp(process));
            if (task) {
                connect(task, SIGNAL(finished()), this, SLOT(cleanUpFinished()));
                task->start();
            }
            removeFromWatchList(process);
            return;
        } else if (newStatus == Process::Queued    ||
                   newStatus == Process::Running   ||
                   newStatus == Process::Suspended) {
            process->setStatus(newStatus);
        } else {
            process->setStatus(newStatus);
            removeFromWatchList(process);
            QLOG_WARN() << "Inactive process found in Server::queryFinished";
        }

    } else {
        removeFromWatchList(process);
    }
}
コード例 #7
0
ファイル: qmlmanager.cpp プロジェクト: lehoon/subsurface
void QMLManager::loadDivesWithValidCredentials()
{
	QString url;
	timestamp_t currentDiveTimestamp = selectedDiveTimestamp();
	if (getCloudURL(url)) {
		QString errorString(get_error_string());
		appendTextToLog(errorString);
		setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(errorString) + END_FONT);
		revertToNoCloudIfNeeded();
		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");
		goto successful_exit;
	}
	appendTextToLog("Cloud sync brought newer data, reloading the dive list");

	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);
		revertToNoCloudIfNeeded();
		return;
	}
	consumeFinishedLoad(currentDiveTimestamp);

successful_exit:
	alreadySaving = false;
	setLoadFromCloud(true);
	// if we came from local storage mode, let's merge the local data into the local cache
	// for the remote data - which then later gets merged with the remote data if necessary
	if (oldStatus() == NOCLOUD) {
		git_storage_update_progress(false, "import dives from nocloud local storage");
		dive_table.preexisting = dive_table.nr;
		mergeLocalRepo();
		DiveListModel::instance()->clear();
		DiveListModel::instance()->addAllDives();
		appendTextToLog(QStringLiteral("%1 dives loaded after importing nocloud local storage").arg(dive_table.nr));
		saveChangesLocal();
		if (syncToCloud() == false) {
			appendTextToLog(QStringLiteral("taking things back offline now that storage is synced"));
			prefs.git_local_only = syncToCloud();
		}
	}
	setAccessingCloud(-1);
	// if we got here just for an initial connection to the cloud, reset to offline
	if (currentGitLocalOnly) {
		currentGitLocalOnly = false;
		prefs.git_local_only = true;
	}
	return;
}