Пример #1
0
void LocationInformationWidget::acceptChanges()
{
	char *uiString;
	currentDs->latitude = displayed_dive_site.latitude;
	currentDs->longitude = displayed_dive_site.longitude;
	uiString = ui.diveSiteName->text().toUtf8().data();
	if (!same_string(uiString, currentDs->name)) {
		free(currentDs->name);
		currentDs->name = copy_string(uiString);
	}
	uiString = ui.diveSiteDescription->text().toUtf8().data();
	if (!same_string(uiString, currentDs->description)) {
		free(currentDs->description);
		currentDs->description = copy_string(uiString);
	}
	uiString = ui.diveSiteNotes->document()->toPlainText().toUtf8().data();
	if (!same_string(uiString, currentDs->notes)) {
		free(currentDs->notes);
		currentDs->notes = copy_string(uiString);
	}
	if (dive_site_is_empty(currentDs)) {
		delete_dive_site(currentDs->uuid);
		displayed_dive.dive_site_uuid = 0;
		setLocationId(0);
	} else {
		setLocationId(currentDs->uuid);
	}
	mark_divelist_changed(true);
	resetState();
	emit informationManagementEnded();
	emit coordinatesChanged();
}
Пример #2
0
void QMLManager::retrieveUserid()
{
	if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) {
		appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: (%1) %2")
				.arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt())
				.arg(QString(reply->readAll())));
		setStartPageText(RED_FONT + tr("Cannot connect to cloud storage") + END_FONT);
		revertToNoCloudIfNeeded();
		return;
	}
	setCredentialStatus(VALID);
	QString userid(prefs.userid);
	if (userid.isEmpty()) {
		if (same_string(prefs.cloud_storage_email, "") || same_string(prefs.cloud_storage_password, "")) {
			appendTextToLog("cloud user name or password are empty, can't retrieve web user id");
			revertToNoCloudIfNeeded();
			return;
		}
		appendTextToLog(QStringLiteral("calling getUserid with user %1").arg(prefs.cloud_storage_email));
		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));
		QSettings s;
		s.setValue("subsurface_webservice_uid", prefs.userid);
		s.sync();
	}
	setCredentialStatus(VALID);
	setStartPageText("Cloud credentials valid, loading dives...");
	git_storage_update_progress(true, "load dives with valid credentials");
	// this only gets called with "alreadySaving" already locked
	loadDivesWithValidCredentials();
}
Пример #3
0
int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p)
{
	struct git_repository *git;
	const char *branch = NULL;

	char *current_sha = strdup(saved_git_id);
	git = is_git_repository(filename, &branch, NULL, false);
	if (git_p)
		*git_p = git;
	if (branch_p)
		*branch_p = branch;
	if (prefs.cloud_git_url &&
	    strstr(filename, prefs.cloud_git_url)
	    && git == dummy_git_repository) {
		/* opening the cloud storage repository failed for some reason,
		 * so we don't know if there is additional data in the remote */
		free(current_sha);
		return 1;
	}
	/* if this is a git repository, do we already have this exact state loaded ?
	 * get the SHA and compare with what we currently have */
	if (git && git != dummy_git_repository) {
		const char *sha = get_sha(git, branch);
		if (!same_string(sha, "") &&
		    same_string(sha, current_sha)) {
			fprintf(stderr, "already have loaded SHA %s - don't load again\n", sha);
			free(current_sha);
			return 0;
		}
	}
	free(current_sha);
	return 1;
}
void LocationInformationWidget::acceptChanges()
{
	emit stopFilterDiveSite();
	char *uiString;
	currentDs->latitude = displayed_dive_site.latitude;
	currentDs->longitude = displayed_dive_site.longitude;
	uiString = ui.diveSiteName->text().toUtf8().data();
	if (!same_string(uiString, currentDs->name)) {
		free(currentDs->name);
		currentDs->name = copy_string(uiString);
	}
	uiString = ui.diveSiteDescription->text().toUtf8().data();
	if (!same_string(uiString, currentDs->description)) {
		free(currentDs->description);
		currentDs->description = copy_string(uiString);
	}
	uiString = ui.diveSiteNotes->document()->toPlainText().toUtf8().data();
	if (!same_string(uiString, currentDs->notes)) {
		free(currentDs->notes);
		currentDs->notes = copy_string(uiString);
	}
	if (current_mode == CREATE_DIVE_SITE)
		displayed_dive.dive_site_uuid = currentDs->uuid;
	if (dive_site_is_empty(currentDs)) {
		LocationInformationModel::instance()->removeRow(get_divesite_idx(currentDs));
		displayed_dive.dive_site_uuid = 0;
	}

	mark_divelist_changed(true);
	resetState();
	emit informationManagementEnded();
	emit coordinatesChanged();
}
Пример #5
0
int main(int argc, char** argv) {
    int r;
    
    printf("%%SUITE_STARTING%% newsimpletest\n");
    printf("%%SUITE_STARTED%%\n");

    printf("%%TEST_STARTED%% test1 (compare \"string one\" and \"string completely different\")\n");
    r = same_string("string one", "string completely different");
    printf("result = %d\n", r);
    printf("%%TEST_FINISHED%% time=0 test1 (newsimpletest) \n");

    printf("%%TEST_STARTED%% test2 (compare \"same 1 length\" and \"same 2 length\")\n");
    r = same_string("same 1 length", "same 2 length");
    printf("result = %d\n", r);
    printf("%%TEST_FINISHED%% time=0 test2 (newsimpletest) \n");

    printf("%%TEST_STARTED%% test3 (compare \"same str\" and \"same str\")\n");
    r = same_string("same str", "same str");
    printf("result = %d\n", r);
    printf("%%TEST_FINISHED%% time=0 test3 (newsimpletest) \n");
    
    printf("%%SUITE_FINISHED%% time=0\n");

    return (EXIT_SUCCESS);
}
Пример #6
0
/* a uuid is always present - but if all the other fields are empty, the dive site is pointless */
bool dive_site_is_empty(struct dive_site *ds)
{
	return same_string(ds->name, "") &&
	       same_string(ds->description, "") &&
	       same_string(ds->notes, "") &&
	       ds->latitude.udeg == 0 &&
	       ds->longitude.udeg == 0;
}
Пример #7
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();
	}
}
Пример #8
0
extern "C" bool string_sequence_contains(const char *string_sequence, const char *text)
{
	if (same_string(text, "") || same_string(string_sequence, ""))
		return false;

	QString stringSequence(string_sequence);
	QStringList strings = stringSequence.split(",", QString::SkipEmptyParts);
	Q_FOREACH (const QString& string, strings) {
		if (string.trimmed().compare(QString(text).trimmed(), Qt::CaseInsensitive) == 0)
			return true;
	}
	return false;
}
Пример #9
0
void QMLManager::checkCredentialsAndExecute(execute_function_type execute)
{
	// if the cloud credentials are present, we should try to get the GPS Webservice ID
	// and (if we haven't done so) load the dive list
	if (!same_string(prefs.cloud_storage_email, "") &&
	    !same_string(prefs.cloud_storage_password, "")) {
		setAccessingCloud(0);
		setStartPageText(tr("Testing cloud credentials"));
		appendTextToLog("Have credentials, let's see if they are valid");
		CloudStorageAuthenticate *csa = new CloudStorageAuthenticate(this);
		csa->backend(prefs.cloud_storage_email, prefs.cloud_storage_password, cloudPin());
		// let's wait here for the signal to avoid too many more nested functions
		QTimer myTimer;
		myTimer.setSingleShot(true);
		QEventLoop loop;
		connect(csa, &CloudStorageAuthenticate::finishedAuthenticate, &loop, &QEventLoop::quit);
		connect(&myTimer, &QTimer::timeout, &loop, &QEventLoop::quit);
		myTimer.start(5000);
		loop.exec();
		if (!myTimer.isActive()) {
			// got no response from the server
			setStartPageText(RED_FONT + tr("No response from cloud server to validate the credentials") + END_FONT);
			revertToNoCloudIfNeeded();
			return;
		}
		myTimer.stop();
		setCloudPin("");
		if (prefs.cloud_verification_status != CS_VERIFIED) {
			// here we need to enter the PIN
			appendTextToLog(QStringLiteral("Need to verify the email address - enter PIN in desktop app"));
			setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - cloud account not verified") + END_FONT);
			revertToNoCloudIfNeeded();
			setShowPin(true);
			return;
		}
		if (showPin())
			setShowPin(false);

		// now check the redirect URL to make sure everything is set up on the cloud server
		connect(manager(), &QNetworkAccessManager::authenticationRequired, this, &QMLManager::provideAuth, Qt::UniqueConnection);
		QUrl url(CLOUDREDIRECTURL);
		request = QNetworkRequest(url);
		request.setRawHeader("User-Agent", getUserAgent().toUtf8());
		request.setRawHeader("Accept", "text/html");
		reply = manager()->get(request);
		connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(handleError(QNetworkReply::NetworkError)));
		connect(reply, &QNetworkReply::sslErrors, this, &QMLManager::handleSslErrors);
		connect(reply, &QNetworkReply::finished, this, execute, Qt::UniqueConnection);
	}
}
Пример #10
0
// copy the tanks from the current dive, or the default cylinder
// or an unknown cylinder
// setup the cylinder widget accordingly
void DivePlannerPointsModel::setupCylinders()
{
	int i;
	if (mode == PLAN && current_dive) {
		// take the displayed cylinders from the selected dive as starting point
		CylindersModel::instance()->copyFromDive(current_dive);
		copy_cylinders(current_dive, &displayed_dive, !prefs.display_unused_tanks);
		reset_cylinders(&displayed_dive, true);

		for (i = 0; i < MAX_CYLINDERS; i++)
			if (!cylinder_none(&(displayed_dive.cylinder[i])))
				return;		// We have at least one cylinder
	}
	if (!same_string(prefs.default_cylinder, "")) {
		fill_default_cylinder(&displayed_dive.cylinder[0]);
	}
	if (cylinder_none(&displayed_dive.cylinder[0])) {
		// roughly an AL80
		displayed_dive.cylinder[0].type.description = strdup(tr("unknown").toUtf8().constData());
		displayed_dive.cylinder[0].type.size.mliter = 11100;
		displayed_dive.cylinder[0].type.workingpressure.mbar = 207000;
	}
	reset_cylinders(&displayed_dive, false);
	CylindersModel::instance()->copyFromDive(&displayed_dive);
}
Пример #11
0
void LocationInformationWidget::on_diveSiteName_textChanged(const QString& text)
{
	if (!same_string(qPrintable(text), currentDs->name)) {
		free(displayed_dive_site.name);
		displayed_dive_site.name = copy_string(qPrintable(text));
		markChangedWidget(ui.diveSiteName);
		emit coordinatesChanged();
	}
}
Пример #12
0
int certificate_check_cb(git_cert *cert, int valid, const char *host, void *payload)
{
	if (same_string(host, "cloud.subsurface-divelog.org") && cert->cert_type == GIT_CERT_X509) {
		SHA_CTX ctx;
		unsigned char hash[21];
		git_cert_x509 *cert509 = (git_cert_x509 *)cert;
		SHA1_Init(&ctx);
		SHA1_Update(&ctx, cert509->data, cert509->len);
		SHA1_Final(hash, &ctx);
		hash[20] = 0;
		if (same_string((char *)hash, KNOWN_CERT)) {
			fprintf(stderr, "cloud certificate considered %s, forcing it valid\n",
				valid ? "valid" : "not valid");
			return 1;
		}
	}
	return valid;
}
Пример #13
0
int spe_idx(char *sname) {
	int i;
	for (i = 0; i < Spesz; i++)
		if (same_string(Spename[i], sname))
			break;
	if (i == Spesz)
		fatalf("unkonwn species %s", sname);
	return i;
}
Пример #14
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);
	}
}
Пример #15
0
void QMLManager::checkCredentialsAndExecute(execute_function_type execute)
{
	// if the cloud credentials are present, we should try to get the GPS Webservice ID
	// and (if we haven't done so) load the dive list
	if (!same_string(prefs.cloud_storage_email, "") &&
	    !same_string(prefs.cloud_storage_password, "")) {
		setAccessingCloud(0);
		setStartPageText(tr("Testing cloud credentials"));
		appendTextToLog("Have credentials, let's see if they are valid");
		connect(manager(), &QNetworkAccessManager::authenticationRequired, this, &QMLManager::provideAuth, Qt::UniqueConnection);
		connect(manager(), &QNetworkAccessManager::finished, this, execute, Qt::UniqueConnection);
		QUrl url(CLOUDREDIRECTURL);
		request = QNetworkRequest(url);
		request.setRawHeader("User-Agent", getUserAgent().toUtf8());
		request.setRawHeader("Accept", "text/html");
		reply = manager()->get(request);
		connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(handleError(QNetworkReply::NetworkError)));
		connect(reply, &QNetworkReply::sslErrors, this, &QMLManager::handleSslErrors);
	}
}
Пример #16
0
QMLManager::QMLManager() :
	m_locationServiceEnabled(false)
{
	// create location manager service
	locationProvider = new GpsLocation(&qmlUiShowMessage, this);

	// Initialize cloud credentials.
	setCloudUserName(prefs.cloud_storage_email);
	setCloudPassword(prefs.cloud_storage_password);
	setSaveCloudPassword(prefs.save_password_local);
	// 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, "") &&
	    same_string(prefs.userid, ""))
		locationProvider->getUserid(prefs.cloud_storage_email, prefs.cloud_storage_password);

	setDistanceThreshold(prefs.distance_threshold);
	setTimeThreshold(prefs.time_threshold / 60);
	if (!same_string(prefs.cloud_storage_email, "") && !same_string(prefs.cloud_storage_password, ""))
		loadDives();
}
void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString& text)
{
	if (!currentDs || !same_string(qPrintable(text), printGPSCoords(currentDs->latitude.udeg, currentDs->longitude.udeg))) {
		double latitude, longitude;
		if (parseGpsText(text, &latitude, &longitude)) {
			displayed_dive_site.latitude.udeg = latitude * 1000000;
			displayed_dive_site.longitude.udeg = longitude * 1000000;
			markChangedWidget(ui.diveSiteCoordinates);
			emit coordinatesChanged();
		}
	}
}
Пример #18
0
/* there could be multiple sites of the same name - return the first one */
uint32_t get_dive_site_uuid_by_name(const char *name, struct dive_site **dsp)
{
	int i;
	struct dive_site *ds;
	for_each_dive_site (i, ds) {
		if (same_string(ds->name, name)) {
			if (dsp)
				*dsp = ds;
			return ds->uuid;
		}
	}
	return 0;
}
Пример #19
0
Файл: table.c Проект: qiyao/xcc
static void
add_implicit_var (char *s)
{
	int i;
	for (i = 0; i < n_ivars; i++) {
		if (same_string(s, implicit_vars[i])) {
			/* already in list */
			return;
		}
	}
	strcpy(implicit_vars[n_ivars], s);
	n_ivars++;
}
Пример #20
0
static void save_picture_from_git(struct picture *picture)
{
	struct picture_entry_list *pic_entry = pel;

	while (pic_entry) {
		if (same_string(pic_entry->hash, picture->hash)) {
			savePictureLocal(picture, pic_entry->data, pic_entry->len);
			return;
		}
		pic_entry = pic_entry->next;
	}
	fprintf(stderr, "didn't find picture entry for %s\n", picture->filename);
}
void write_prog_to_whitespace_file(program *reg_prog, FILE **prog_file)
{

	int i, j, k, temp_num, num_tens, num_units;

	char *commands[TOTAL_NUM_INSTRUCTIONS] = {"{", "}", "FD", "LT", "RT", "SET", "DO", "FROM", "TO", ":=", ";", "+", "-", "*", "/", 
						  "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", 
						  "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};

	for(i = 0; i < reg_prog -> num_lines_in_file; ++i){

		if(sscanf(reg_prog -> prog_line[i], "%d", &temp_num) != 0){

			fprintf(*prog_file, "\t");

			num_tens = temp_num / WS_TRANS_CONST;
			num_units = temp_num - WS_TRANS_CONST * num_tens;

			for(k = 0; k < num_tens; ++k){

				fprintf(*prog_file, "\t");

			}
			for(k = 0; k < num_units; ++k){

				fprintf(*prog_file, " ");
			}

			fprintf(*prog_file, "\n");
		}

		else{
			
			for(j = 0; j < TOTAL_NUM_INSTRUCTIONS; ++j){

				if(same_string(reg_prog -> prog_line[i], commands[j])){ 						

					for(k = 0; k < j; ++k){

						fprintf(*prog_file, " ");
					}

					fprintf(*prog_file, "\n");
				}
			}

		}

	}

}
Пример #22
0
static void parse_dive_location(char *line, struct membuffer *str, void *_dive)
{
	uint32_t uuid;
	char *name = get_utf8(str);
	struct dive *dive = _dive;
	struct dive_site *ds = get_dive_site_for_dive(dive);
	if (!ds) {
		uuid = get_dive_site_uuid_by_name(name, NULL);
		if (!uuid)
			uuid = create_dive_site(name, dive->when);
		dive->dive_site_uuid = uuid;
	} else {
		// we already had a dive site linked to the dive
		if (same_string(ds->name, "")) {
			ds->name = strdup(name);
		} else {
			// and that dive site had a name. that's weird - if our name is different, add it to the notes
			if (!same_string(ds->name, name))
				ds->notes = add_to_string(ds->notes, translate("gettextFromC", "additional name for site: %s\n"), name);
		}
	}
	free(name);
}
Пример #23
0
void DownloadThread::run()
{
	auto internalData = m_data->internalData();
	internalData->descriptor = descriptorLookup[m_data->vendor() + m_data->product()];
	internalData->download_table = &downloadTable;
	internalData->btname = strdup(m_data->devBluetoothName().toUtf8());
#if defined(Q_OS_ANDROID)
	// on Android we either use BT, a USB device, or we download via FTDI cable
	if (!internalData->bluetooth_mode && (same_string(internalData->devname, "FTDI") || same_string(internalData->devname, "")))
		internalData->devname = "ftdi";
#endif
	qDebug() << "Starting download from " << (internalData->bluetooth_mode ? "BT" : internalData->devname);
	downloadTable.nr = 0;

	Q_ASSERT(internalData->download_table != nullptr);
	const char *errorText;
	import_thread_cancelled = false;
	error.clear();
	if (!strcmp(internalData->vendor, "Uemis"))
		errorText = do_uemis_import(internalData);
	else
		errorText = do_libdivecomputer_import(internalData);
	if (errorText) {
		error = str_error(errorText, internalData->devname, internalData->vendor, internalData->product);
		qDebug() << "Finishing download thread:" << error;
	} else {
		if (!downloadTable.nr)
			error = tr("No new dives downloaded from dive computer");
		qDebug() << "Finishing download thread:" << downloadTable.nr << "dives downloaded";
	}
	qPrefDiveComputer::set_vendor(internalData->vendor);
	qPrefDiveComputer::set_product(internalData->product);
	qPrefDiveComputer::set_device(internalData->devname);
	qPrefDiveComputer::set_device_name(m_data->devBluetoothName());

	updateRememberedDCs();
}
Пример #24
0
uint32_t find_or_create_dive_site_with_name(const char *name)
{
	int i;
	struct dive_site *ds;
	bool found = false;
	for_each_dive_site(i,ds) {
		if (same_string(name, ds->name)) {
			found = true;
			break;
		}
	}
	if (ds)
		return ds->uuid;
	return create_dive_site(name);
}
Пример #25
0
void DiveEventItem::setupPixmap()
{
	const IconMetrics& metrics = defaultIconMetrics();
	int sz_bigger = metrics.sz_med + metrics.sz_small; // ex 40px
	int sz_pix = sz_bigger/2; // ex 20px

#define EVENT_PIXMAP(PIX) QPixmap(QString(PIX)).scaled(sz_pix, sz_pix, Qt::KeepAspectRatio, Qt::SmoothTransformation)
#define EVENT_PIXMAP_BIGGER(PIX) QPixmap(QString(PIX)).scaled(sz_bigger, sz_bigger, Qt::KeepAspectRatio, Qt::SmoothTransformation)
	if (same_string(internalEvent->name, "")) {
		setPixmap(EVENT_PIXMAP(":warning"));
	} else if (internalEvent->type == SAMPLE_EVENT_BOOKMARK) {
		setPixmap(EVENT_PIXMAP(":flag"));
	} else if (strcmp(internalEvent->name, "heading") == 0 ||
		   (same_string(internalEvent->name, "SP change") && internalEvent->time.seconds == 0)) {
		// 2 cases:
		// a) some dive computers have heading in every sample
		// b) at t=0 we might have an "SP change" to indicate dive type
		// in both cases we want to get the right data into the tooltip but don't want the visual clutter
		// so set an "almost invisible" pixmap (a narrow but somewhat tall, basically transparent pixmap)
		// that allows tooltips to work when we don't want to show a specific
		// pixmap for an event, but want to show the event value in the tooltip
		QPixmap transparentPixmap(4, 20);
		transparentPixmap.fill(QColor::fromRgbF(1.0, 1.0, 1.0, 0.01));
		setPixmap(transparentPixmap);
	} else if (event_is_gaschange(internalEvent)) {
		if (internalEvent->gas.mix.he.permille)
			setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeTrimix"));
		else if (gasmix_is_air(&internalEvent->gas.mix))
			setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeAir"));
		else
			setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeNitrox"));
	} else {
		setPixmap(EVENT_PIXMAP(":warning"));
	}
#undef EVENT_PIXMAP
}
// we don't overwrite any existing GPS info in the dive
// so get the dive site and if there is none or there is one without GPS fix, add it
static void copy_gps_location(struct dive *from, struct dive *to)
{
	struct dive_site *ds = get_dive_site_for_dive(to);
	if (!ds || !dive_site_has_gps_location(ds)) {
		struct dive_site *gds = get_dive_site_for_dive(from);
		if (!ds) {
			// simply link to the one created for the fake dive
			to->dive_site_uuid = gds->uuid;
		} else {
			ds->latitude = gds->latitude;
			ds->longitude = gds->longitude;
			if (same_string(ds->name, ""))
				ds->name = copy_string(gds->name);
		}
	}
}
Пример #27
0
Файл: table.c Проект: qiyao/xcc
/* store src into tgt unless src == special */
static void
store_string(char *tgt, char *src, char *special)
{
	char *p;
	if (same_string(src, special)) {
		*tgt = NIL;
	} else if (*src != '{') {
		strcpy(tgt, src);
	} else {
		/* string surrounded by { }, can have white-spaces */
		strcpy(tgt, src);
		strcat(tgt, " ");
		p = strtok(NULL, "}");
		strcat(tgt, p);
		strcat(tgt, "}");
	}
}
Пример #28
0
void QMLManager::saveChangesLocal()
{
	if (unsaved_changes()) {
		git_storage_update_progress(true, "saving dives locally"); // reset the timers
		if (credentialStatus() == NOCLOUD) {
			if (same_string(existing_filename, "")) {
				char *filename = NOCLOUD_LOCALSTORAGE;
				if (git_create_local_repo(filename))
					appendTextToLog(get_error_string());
				set_filename(filename, true);
				GeneralSettingsObjectWrapper s(this);
				s.setDefaultFilename(filename);
				s.setDefaultFileBehavior(LOCAL_DEFAULT_FILE);
				qDebug() << "setting default file to" << filename;
			}
		} else if (!loadFromCloud()) {
			// this seems silly, but you need a common ancestor in the repository in
			// order to be able to merge che changes later
			appendTextToLog("Don't save dives without loading from the cloud, first.");
			return;
		}
		if (alreadySaving) {
			appendTextToLog("save operation already in progress, can't save locally");
			return;
		}
		alreadySaving = true;
		bool glo = prefs.git_local_only;
		prefs.git_local_only = true;
		if (save_dives(existing_filename)) {
			appendTextToLog(get_error_string());
			set_filename(NULL, true);
			setAccessingCloud(-1);
			prefs.git_local_only = glo;
			alreadySaving = false;
			return;
		}
		prefs.git_local_only = glo;
		mark_divelist_changed(false);
		git_storage_update_progress(false, "done with local save");
		alreadySaving = false;
	} else {
		appendTextToLog("local save requested with no unsaved changes");
	}
}
Пример #29
0
Файл: table.c Проект: qiyao/xcc
static option_list_t *
create_option_list (char **sp, int index)
{
	/* have to return current pointer in sp after strtoks */
	char *s = *sp;
	option_list_t *olist;
	option_list_t *olist_head;
	s = strtok(NULL, DQUOTE_SPACE);
	*sp = s;
	if (s == NULL) {
		return NULL;
	} else if (*s == FIELD_DIVIDER) {
		return NULL;
	} else {
		olist = (option_list_t *) malloc(sizeof(option_list_t));
		olist->next = NULL;
		olist_head = olist;
		if (same_string(s, "self")) {
			strcpy(olist->name, options[index].name);
			olist->info_index = index;
		} else {
			strcpy(olist->name, s);
			olist->info_index = UNDEFINED;
		}
	}
	s = strtok(NULL, DQUOTE_SPACE);
	while (s != NULL && *s != FIELD_DIVIDER) {
		if (s[0] != '-') {
			/* append to previous item, with a space */
			strcat(olist->name, " ");
			strcat(olist->name, s);
		} else {
			olist = (option_list_t *) malloc(sizeof(option_list_t));
			strcpy(olist->name, s);
			olist->info_index = UNDEFINED;
			/* prepend, so in reverse order */
			olist->next = olist_head;
			olist_head = olist;
		}
		s = strtok(NULL, DQUOTE_SPACE);
	}
	*sp = s;
	return olist_head;
}
Пример #30
0
/* Helper for the reading_hotspots() function below. */
static void
mark_string_hotspot_values(float values[BOARDMAX],
			   int m, int n, float contribution)
{
  int i, j, k;
  
  /* If p[m][n] is EMPTY, we just give the contribution to close empty
   * vertices. This is a rough simplification.
   */
  if (BOARD(m, n) == EMPTY) {
    for (i = -1; i <= 1; i++)
      for (j = -1; j <= 1; j++)
	if (BOARD(m+i, n+j) == EMPTY)
	  values[POS(m+i, n+j)] += contribution;
    return;
  }
  
  /* Otherwise we give contribution to liberties and diagonal
   * neighbors of the string at (m, n).
   */
  for (i = 0; i < board_size; i++)
    for (j = 0; j < board_size; j++) {
      if (BOARD(i, j) != EMPTY)
	continue;
      for (k = 0; k < 8; k++) {
	int di = deltai[k];
	int dj = deltaj[k];
	if (IS_STONE(BOARD(i+di, j+dj))
	    && same_string(POS(i+di, j+dj), POS(m, n))) {
	  if (k < 4) {
	    values[POS(i, j)] += contribution;
	    break;
	  }
	  else {
	    if (BOARD(i+di, j) == EMPTY || countlib(POS(i+di, j)) <= 2
		|| BOARD(i, j+dj) == EMPTY || countlib(POS(i, j+dj)) <= 2)
	      values[POS(i, j)] += contribution;
	    break;
	  }
	}
      }
    }
}