Skip to content

Commit

Permalink
Added code to automatic updating the TLE sources from Celestrack webs…
Browse files Browse the repository at this point in the history
…ite (fix #3588)
  • Loading branch information
alex-w committed Jan 12, 2024
1 parent 27f2ec9 commit 1109ac8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/Satellites/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET(SATELLITES_VERSION "0.13.4")
SET(SATELLITES_VERSION "0.13.5")

ADD_DEFINITIONS(-DSATELLITES_PLUGIN_VERSION="${SATELLITES_VERSION}")
ADD_DEFINITIONS(-DSATELLITES_PLUGIN_LICENSE="GNU GPLv2 or later")
Expand Down
38 changes: 37 additions & 1 deletion plugins/Satellites/src/Satellites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ void Satellites::loadSettings()
// if (conf->contains("tle_url0")) // This can skip some operations...
static const QRegularExpression keyRE("^tle_url\\d+$");
QStringList urls;
bool urlWasUpdated = false;
for (const auto& key : conf->childKeys())
{
if (keyRE.match(key).hasMatch())
Expand All @@ -767,7 +768,18 @@ void Satellites::loadSettings()

// celestrak.com moved to celestrak.org
if (url.contains("celestrak.com", Qt::CaseInsensitive))
{
url.replace("celestrak.com", "celestrak.org", Qt::CaseInsensitive);
urlWasUpdated = true;
}

// simple text files are removed
if (url.contains("celestrak.org", Qt::CaseInsensitive) && url.endsWith(".txt", Qt::CaseInsensitive))
{
url.replace("NORAD/elements/", "NORAD/elements/gp.php?GROUP=", Qt::CaseInsensitive);
url.replace(".txt", "&FORMAT=TLE", Qt::CaseInsensitive);
urlWasUpdated = true;
}

urls << url;
}
Expand All @@ -776,12 +788,18 @@ void Satellites::loadSettings()
if (!urls.isEmpty())
{
conf->endGroup();
setTleSources(urls);
setTleSources(urls);
if (urlWasUpdated)
{
saveTleSources(urls);
qWarning() << "[Satellites] updated an old-style array of TLE sources";
}
conf->beginGroup("Satellites");
}
else
{
int size = conf->beginReadArray("tle_sources");
bool urlWasUpdated = false;
for (int i = 0; i < size; i++)
{
conf->setArrayIndex(i);
Expand All @@ -790,14 +808,32 @@ void Satellites::loadSettings()
{
// celestrak.com moved to celestrak.org
if (url.contains("celestrak.com", Qt::CaseInsensitive))
{
url.replace("celestrak.com", "celestrak.org", Qt::CaseInsensitive);
urlWasUpdated = true;
}

// simple text files are removed
if (url.contains("celestrak.org", Qt::CaseInsensitive) && url.endsWith(".txt", Qt::CaseInsensitive))
{
url.replace("NORAD/elements/", "NORAD/elements/gp.php?GROUP=", Qt::CaseInsensitive);
url.replace(".txt", "&FORMAT=TLE", Qt::CaseInsensitive);
urlWasUpdated = true;
}

if (conf->value("add_new").toBool())
url.prepend("1,");
updateUrls.append(url);
}
}
conf->endArray();
if (urlWasUpdated)
{
conf->endGroup();
saveTleSources(updateUrls);
qWarning() << "[Satellites] updated list of TLE sources";
conf->beginGroup("Satellites");
}
}

// NOTE: Providing default values AND using restoreDefaultSettings() to create the section seems redundant. --BM
Expand Down

0 comments on commit 1109ac8

Please sign in to comment.