File indexing completed on 2024-04-28 11:20:30

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2016 Ivan Lakhtanov <ivan.lakhtanov@gmail.com>
0004 */
0005 #pragma once
0006 
0007 #include <QFile>
0008 #include <QStandardPaths>
0009 #include <QDebug>
0010 
0011 inline QString loadScript(const QString &scriptName)
0012 {
0013     QString file = QStandardPaths::locate(
0014         QStandardPaths::AppDataLocation,
0015         QString::fromLatin1("juliabackend/scripts/%1.jl").arg(scriptName)
0016     );
0017 
0018     if (file.isEmpty())
0019         file = QStandardPaths::locate(
0020             QStandardPaths::GenericDataLocation,
0021             QString::fromLatin1("cantor/juliabackend/scripts/%1.jl").arg(scriptName)
0022         );
0023 
0024     QFile text(file);
0025     if (text.open(QIODevice::ReadOnly))
0026         return QString::fromUtf8(text.readAll());
0027     else
0028     {
0029         qWarning() << "Cantor Julia script" << scriptName+QLatin1String(".jl") << "not found - something wrong";
0030         return QString();
0031     }
0032 }