Skip to content
Snippets Groups Projects
Commit 192c1545 authored by Janis Born's avatar Janis Born
Browse files

fall back to local library file if download fails

parent a2eb4531
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -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());
......@@ -101,9 +101,14 @@ void DidYouKnowWidget::updateTips()
mTips.clear();
QFile libraryFile(libraryFileName());
if (!libraryFile.open(QIODevice::ReadOnly)) {
// 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);
if (!libraryDoc.isObject()) {
......
<RCC>
<qresource prefix="Plugin-DidYouKnow">
<file>Library/tips.json</file>
</qresource>
</RCC>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment