mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Whitespace change
This is just the indentation change for the code that was inside the loop before. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
09b02aae4e
commit
9162dee8a1
1 changed files with 118 additions and 118 deletions
|
@ -43,134 +43,134 @@ void ReverseGeoLookupThread::run() {
|
||||||
request.setRawHeader("User-Agent", getUserAgent().toUtf8());
|
request.setRawHeader("User-Agent", getUserAgent().toUtf8());
|
||||||
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
||||||
|
|
||||||
struct dive_site *ds = &displayed_dive_site;
|
struct dive_site *ds = &displayed_dive_site;
|
||||||
|
|
||||||
// first check the findNearbyPlaces API from geonames - that should give us country, state, city
|
// first check the findNearbyPlaces API from geonames - that should give us country, state, city
|
||||||
request.setUrl(geonamesURL.arg(uiLanguage(NULL)).arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0));
|
request.setUrl(geonamesURL.arg(uiLanguage(NULL)).arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0));
|
||||||
|
|
||||||
QNetworkReply *reply = rgl->get(request);
|
QNetworkReply *reply = rgl->get(request);
|
||||||
timer.setSingleShot(true);
|
timer.setSingleShot(true);
|
||||||
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
timer.start(5000); // 5 secs. timeout
|
timer.start(5000); // 5 secs. timeout
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
if(timer.isActive()) {
|
if(timer.isActive()) {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
if(reply->error() > 0) {
|
if(reply->error() > 0) {
|
||||||
report_error("got error accessing geonames.org: %s", qPrintable(reply->errorString()));
|
report_error("got error accessing geonames.org: %s", qPrintable(reply->errorString()));
|
||||||
goto clear_reply;
|
goto clear_reply;
|
||||||
}
|
}
|
||||||
int v = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int v = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
if (v < 200 || v >= 300)
|
if (v < 200 || v >= 300)
|
||||||
goto clear_reply;
|
goto clear_reply;
|
||||||
QByteArray fullReply = reply->readAll();
|
QByteArray fullReply = reply->readAll();
|
||||||
QJsonParseError errorObject;
|
QJsonParseError errorObject;
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(fullReply, &errorObject);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(fullReply, &errorObject);
|
||||||
if (errorObject.error != QJsonParseError::NoError) {
|
if (errorObject.error != QJsonParseError::NoError) {
|
||||||
report_error("error parsing geonames.org response: %s", qPrintable(errorObject.errorString()));
|
report_error("error parsing geonames.org response: %s", qPrintable(errorObject.errorString()));
|
||||||
goto clear_reply;
|
goto clear_reply;
|
||||||
}
|
}
|
||||||
QJsonObject obj = jsonDoc.object();
|
QJsonObject obj = jsonDoc.object();
|
||||||
QVariant geoNamesObject = obj.value("geonames").toVariant();
|
QVariant geoNamesObject = obj.value("geonames").toVariant();
|
||||||
QVariantList geoNames = geoNamesObject.toList();
|
QVariantList geoNames = geoNamesObject.toList();
|
||||||
if (geoNames.count() > 0) {
|
if (geoNames.count() > 0) {
|
||||||
QVariantMap firstData = geoNames.at(0).toMap();
|
QVariantMap firstData = geoNames.at(0).toMap();
|
||||||
int ri = 0, l3 = -1, lt = -1;
|
int ri = 0, l3 = -1, lt = -1;
|
||||||
if (ds->taxonomy.category == NULL) {
|
if (ds->taxonomy.category == NULL) {
|
||||||
ds->taxonomy.category = alloc_taxonomy();
|
ds->taxonomy.category = alloc_taxonomy();
|
||||||
} else {
|
|
||||||
// clear out the data (except for the ocean data)
|
|
||||||
int ocean;
|
|
||||||
if ((ocean = taxonomy_index_for_category(&ds->taxonomy, TC_OCEAN)) > 0) {
|
|
||||||
ds->taxonomy.category[0] = ds->taxonomy.category[ocean];
|
|
||||||
ds->taxonomy.nr = 1;
|
|
||||||
} else {
|
|
||||||
// ocean is -1 if there is no such entry, and we didn't copy above
|
|
||||||
// if ocean is 0, so the following gets us the correct count
|
|
||||||
ds->taxonomy.nr = ocean + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// get all the data - OCEAN is special, so start at COUNTRY
|
|
||||||
for (int j = TC_COUNTRY; j < TC_NR_CATEGORIES; j++) {
|
|
||||||
if (firstData[taxonomy_api_names[j]].isValid()) {
|
|
||||||
ds->taxonomy.category[ri].category = j;
|
|
||||||
ds->taxonomy.category[ri].origin = taxonomy_origin::GEOCODED;
|
|
||||||
free((void*)ds->taxonomy.category[ri].value);
|
|
||||||
ds->taxonomy.category[ri].value = copy_string(qPrintable(firstData[taxonomy_api_names[j]].toString()));
|
|
||||||
ri++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ds->taxonomy.nr = ri;
|
|
||||||
l3 = taxonomy_index_for_category(&ds->taxonomy, TC_ADMIN_L3);
|
|
||||||
lt = taxonomy_index_for_category(&ds->taxonomy, TC_LOCALNAME);
|
|
||||||
if (l3 == -1 && lt != -1) {
|
|
||||||
// basically this means we did get a local name (what we call town), but just like most places
|
|
||||||
// we didn't get an adminName_3 - which in some regions is the actual city that town belongs to,
|
|
||||||
// then we copy the town into the city
|
|
||||||
ds->taxonomy.category[ri].value = copy_string(ds->taxonomy.category[lt].value);
|
|
||||||
ds->taxonomy.category[ri].origin = taxonomy_origin::GEOCOPIED;
|
|
||||||
ds->taxonomy.category[ri].category = TC_ADMIN_L3;
|
|
||||||
ds->taxonomy.nr++;
|
|
||||||
}
|
|
||||||
mark_divelist_changed(true);
|
|
||||||
} else {
|
} else {
|
||||||
report_error("geonames.org did not provide reverse lookup information");
|
// clear out the data (except for the ocean data)
|
||||||
qDebug() << "no reverse geo lookup; geonames returned\n" << fullReply;
|
int ocean;
|
||||||
}
|
if ((ocean = taxonomy_index_for_category(&ds->taxonomy, TC_OCEAN)) > 0) {
|
||||||
} else {
|
ds->taxonomy.category[0] = ds->taxonomy.category[ocean];
|
||||||
report_error("timeout accessing geonames.org");
|
ds->taxonomy.nr = 1;
|
||||||
disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
} else {
|
||||||
reply->abort();
|
// ocean is -1 if there is no such entry, and we didn't copy above
|
||||||
}
|
// if ocean is 0, so the following gets us the correct count
|
||||||
// next check the oceans API to figure out the body of water
|
ds->taxonomy.nr = ocean + 1;
|
||||||
request.setUrl(geonamesOceanURL.arg(uiLanguage(NULL)).arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0));
|
|
||||||
reply = rgl->get(request);
|
|
||||||
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
|
||||||
timer.start(5000); // 5 secs. timeout
|
|
||||||
loop.exec();
|
|
||||||
if(timer.isActive()) {
|
|
||||||
timer.stop();
|
|
||||||
if(reply->error() > 0) {
|
|
||||||
report_error("got error accessing oceans API of geonames.org: %s", qPrintable(reply->errorString()));
|
|
||||||
goto clear_reply;
|
|
||||||
}
|
|
||||||
int v = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
||||||
if (v < 200 || v >= 300)
|
|
||||||
goto clear_reply;
|
|
||||||
QByteArray fullReply = reply->readAll();
|
|
||||||
QJsonParseError errorObject;
|
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(fullReply, &errorObject);
|
|
||||||
if (errorObject.error != QJsonParseError::NoError) {
|
|
||||||
report_error("error parsing geonames.org response: %s", qPrintable(errorObject.errorString()));
|
|
||||||
goto clear_reply;
|
|
||||||
}
|
|
||||||
QJsonObject obj = jsonDoc.object();
|
|
||||||
QVariant oceanObject = obj.value("ocean").toVariant();
|
|
||||||
QVariantMap oceanName = oceanObject.toMap();
|
|
||||||
if (oceanName["name"].isValid()) {
|
|
||||||
int idx;
|
|
||||||
if (ds->taxonomy.category == NULL)
|
|
||||||
ds->taxonomy.category = alloc_taxonomy();
|
|
||||||
idx = taxonomy_index_for_category(&ds->taxonomy, TC_OCEAN);
|
|
||||||
if (idx == -1)
|
|
||||||
idx = ds->taxonomy.nr;
|
|
||||||
if (idx < TC_NR_CATEGORIES) {
|
|
||||||
ds->taxonomy.category[idx].category = TC_OCEAN;
|
|
||||||
ds->taxonomy.category[idx].origin = taxonomy_origin::GEOCODED;
|
|
||||||
ds->taxonomy.category[idx].value = copy_string(qPrintable(oceanName["name"].toString()));
|
|
||||||
if (idx == ds->taxonomy.nr)
|
|
||||||
ds->taxonomy.nr++;
|
|
||||||
}
|
}
|
||||||
mark_divelist_changed(true);
|
|
||||||
}
|
}
|
||||||
|
// get all the data - OCEAN is special, so start at COUNTRY
|
||||||
|
for (int j = TC_COUNTRY; j < TC_NR_CATEGORIES; j++) {
|
||||||
|
if (firstData[taxonomy_api_names[j]].isValid()) {
|
||||||
|
ds->taxonomy.category[ri].category = j;
|
||||||
|
ds->taxonomy.category[ri].origin = taxonomy_origin::GEOCODED;
|
||||||
|
free((void*)ds->taxonomy.category[ri].value);
|
||||||
|
ds->taxonomy.category[ri].value = copy_string(qPrintable(firstData[taxonomy_api_names[j]].toString()));
|
||||||
|
ri++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ds->taxonomy.nr = ri;
|
||||||
|
l3 = taxonomy_index_for_category(&ds->taxonomy, TC_ADMIN_L3);
|
||||||
|
lt = taxonomy_index_for_category(&ds->taxonomy, TC_LOCALNAME);
|
||||||
|
if (l3 == -1 && lt != -1) {
|
||||||
|
// basically this means we did get a local name (what we call town), but just like most places
|
||||||
|
// we didn't get an adminName_3 - which in some regions is the actual city that town belongs to,
|
||||||
|
// then we copy the town into the city
|
||||||
|
ds->taxonomy.category[ri].value = copy_string(ds->taxonomy.category[lt].value);
|
||||||
|
ds->taxonomy.category[ri].origin = taxonomy_origin::GEOCOPIED;
|
||||||
|
ds->taxonomy.category[ri].category = TC_ADMIN_L3;
|
||||||
|
ds->taxonomy.nr++;
|
||||||
|
}
|
||||||
|
mark_divelist_changed(true);
|
||||||
} else {
|
} else {
|
||||||
report_error("timeout accessing geonames.org");
|
report_error("geonames.org did not provide reverse lookup information");
|
||||||
disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
qDebug() << "no reverse geo lookup; geonames returned\n" << fullReply;
|
||||||
reply->abort();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
report_error("timeout accessing geonames.org");
|
||||||
|
disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
|
reply->abort();
|
||||||
|
}
|
||||||
|
// next check the oceans API to figure out the body of water
|
||||||
|
request.setUrl(geonamesOceanURL.arg(uiLanguage(NULL)).arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0));
|
||||||
|
reply = rgl->get(request);
|
||||||
|
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
|
timer.start(5000); // 5 secs. timeout
|
||||||
|
loop.exec();
|
||||||
|
if(timer.isActive()) {
|
||||||
|
timer.stop();
|
||||||
|
if(reply->error() > 0) {
|
||||||
|
report_error("got error accessing oceans API of geonames.org: %s", qPrintable(reply->errorString()));
|
||||||
|
goto clear_reply;
|
||||||
|
}
|
||||||
|
int v = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
if (v < 200 || v >= 300)
|
||||||
|
goto clear_reply;
|
||||||
|
QByteArray fullReply = reply->readAll();
|
||||||
|
QJsonParseError errorObject;
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(fullReply, &errorObject);
|
||||||
|
if (errorObject.error != QJsonParseError::NoError) {
|
||||||
|
report_error("error parsing geonames.org response: %s", qPrintable(errorObject.errorString()));
|
||||||
|
goto clear_reply;
|
||||||
|
}
|
||||||
|
QJsonObject obj = jsonDoc.object();
|
||||||
|
QVariant oceanObject = obj.value("ocean").toVariant();
|
||||||
|
QVariantMap oceanName = oceanObject.toMap();
|
||||||
|
if (oceanName["name"].isValid()) {
|
||||||
|
int idx;
|
||||||
|
if (ds->taxonomy.category == NULL)
|
||||||
|
ds->taxonomy.category = alloc_taxonomy();
|
||||||
|
idx = taxonomy_index_for_category(&ds->taxonomy, TC_OCEAN);
|
||||||
|
if (idx == -1)
|
||||||
|
idx = ds->taxonomy.nr;
|
||||||
|
if (idx < TC_NR_CATEGORIES) {
|
||||||
|
ds->taxonomy.category[idx].category = TC_OCEAN;
|
||||||
|
ds->taxonomy.category[idx].origin = taxonomy_origin::GEOCODED;
|
||||||
|
ds->taxonomy.category[idx].value = copy_string(qPrintable(oceanName["name"].toString()));
|
||||||
|
if (idx == ds->taxonomy.nr)
|
||||||
|
ds->taxonomy.nr++;
|
||||||
|
}
|
||||||
|
mark_divelist_changed(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
report_error("timeout accessing geonames.org");
|
||||||
|
disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
|
reply->abort();
|
||||||
|
}
|
||||||
|
|
||||||
clear_reply:
|
clear_reply:
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
rgl->deleteLater();
|
rgl->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue