Commit 192c1545 authored by Janis Born's avatar Janis Born

fall back to local library file if download fails

parent a2eb4531
Pipeline #1369 skipped
......@@ -66,7 +66,7 @@ void DidYouKnowWidget::updateTips()
{
// Number of seconds after which the local tips library is considered outdated
const int outdatedSeconds = 1 * 24 * 60 * 60;
const QUrl libraryURL("https://graphics.rwth-aachen.de:9000/Staff/TipOfTheDayLibrary/raw/master/tips.json");
const QUrl libraryURL("https://graphics.rwth-aachen.de:9000/born/Plugin-DidYouKnow/raw/master/Library/tips.json");
// Check for existing local library file
QFileInfo libraryFileInfo(libraryFileName());
......@@ -102,7 +102,12 @@ void DidYouKnowWidget::updateTips()
mTips.clear();
QFile libraryFile(libraryFileName());
if (!libraryFile.open(QIODevice::ReadOnly)) {
throw ConfigError("Could not open " + libraryFile.fileName().toStdString());
// Try library file from local repository as fallback
std::cout << "Could not open " << libraryFile.fileName().toStdString() << ". Falling back to local library." << std::endl;
libraryFile.setFileName(":Plugin-DidYouKnow/Library/tips.json");
if (!libraryFile.open(QIODevice::ReadOnly)) {
throw ConfigError("Could not open " + libraryFile.fileName().toStdString());
}
}
QByteArray libraryData = libraryFile.readAll();
QJsonDocument libraryDoc = QJsonDocument::fromJson(libraryData);
......
<RCC>
<qresource prefix="Plugin-DidYouKnow">
<file>Library/tips.json</file>
</qresource>
</RCC>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment