Commit 32c3f13f authored by Floréal Cabanettes's avatar Floréal Cabanettes

Check JSON is correct on recipe opening Fix #4

parent c85749bf
......@@ -857,28 +857,37 @@ QMap<QString, QStringList> Functions::loadRecipe(QString fileName)
return result;
}
QJsonDocument jsonDoc = QJsonDocument::fromJson(file->readAll());
QJsonObject json = jsonDoc.object();
map = json.toVariantMap();
result["titre"] = QStringList(map["title"].toString());
result["categories"] = map["categories"].toStringList();
result["image"] = QStringList(map["picture"].toString());
result["tpsPrep"] = map["tpsPrep"].toString().split("h");
result["tpsCuis"] = map["tpsCuis"].toString().split("h");
result["tpsRep"] = map["tpsRep"].toString().split(QRegExp("[jh]"));
result["nbPers"] = QStringList(map["nbPers"].toString());
result["precision"] = QStringList(map["precision"].toString());
result["description"] = QStringList(map["description"].toString());
result["ingredients"] = map["ingredients"].toStringList();
result["materiel"] = map["materiel"].toStringList();
result["preparation"] = map["preparation"].toStringList();
result["conseils"] = map["conseils"].toStringList();
result["coupDeCoeur"] = QStringList(map["coupDeCoeur"].toString());
result["idRecipe"] = QStringList(map["idRecipe"].toString());
result["liens"] = map["liens"].toStringList();
QJsonParseError *error = new QJsonParseError();
QJsonDocument jsonDoc = QJsonDocument::fromJson(file->readAll(), error);
if (jsonDoc.isObject()) {
QJsonObject json = jsonDoc.object();
map = json.toVariantMap();
result["titre"] = QStringList(map["title"].toString());
result["categories"] = map["categories"].toStringList();
result["image"] = QStringList(map["picture"].toString());
result["tpsPrep"] = map["tpsPrep"].toString().split("h");
result["tpsCuis"] = map["tpsCuis"].toString().split("h");
result["tpsRep"] = map["tpsRep"].toString().split(QRegExp("[jh]"));
result["nbPers"] = QStringList(map["nbPers"].toString());
result["precision"] = QStringList(map["precision"].toString());
result["description"] = QStringList(map["description"].toString());
result["ingredients"] = map["ingredients"].toStringList();
result["materiel"] = map["materiel"].toStringList();
result["preparation"] = map["preparation"].toStringList();
result["conseils"] = map["conseils"].toStringList();
result["coupDeCoeur"] = QStringList(map["coupDeCoeur"].toString());
result["idRecipe"] = QStringList(map["idRecipe"].toString());
result["liens"] = map["liens"].toStringList();
return result;
return result;
}
else {
QMessageBox::critical(NULL, QDialog::tr("Une erreur est survenue"),
QDialog::tr("Impossible d'ouvrir la recette : ") + error->errorString());
return QMap<QString, QStringList>();
}
}
/**
......
......@@ -2090,7 +2090,7 @@ void QRecipeWriter::saveVariables(QString ingr, QString mat, QString prep, QStri
void QRecipeWriter::loadRecipe(QString fileName, bool testReadyToSend) {
QStringList ingrdt, matl, prept, consl;
QMap<QString, QStringList> rct = Functions::loadRecipe(fileName);
if (rct.size() > 0)
if (!rct.isEmpty())
{
//Load titre:
if (rct.keys().contains("titre"))
......
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