More security and less unexpected behaviour. #8

Merged
andrewlalis merged 7 commits from development into master 2018-03-30 14:20:54 +00:00
5 changed files with 24 additions and 2 deletions
Showing only changes of commit 8fee8c0cdb - Show all commits

View File

@ -38,7 +38,7 @@ void OpenRecipeDialog::on_deleteRecipeButton_clicked(){
return;
}
vector<int> rows;
QModelIndexList indexes = selectModel->selectedIndexes();
QModelIndexList indexes = selectModel->selectedRows();
for (int i = 0; i < indexes.count(); i++){
rows.push_back(indexes.at(i).row());
}

View File

@ -4,10 +4,11 @@
#include "model/database/database.h"
#include "model/database/recipedatabase.h"
#include "utils/fileutils.h"
int main(int argc, char *argv[])
{
RecipeDatabase recipeDB("recipes");
RecipeDatabase recipeDB(QString(FileUtils::appDataPath+"recipes.db").toStdString());
QApplication a(argc, argv);
MainWindow w(&recipeDB);
w.show();

View File

@ -255,6 +255,8 @@ bool RecipeDatabase::deleteRecipe(int recipeId){
bool tagsDeleted = this->deleteFrom("recipeTag", "WHERE recipeId="+idString);
bool recipeIngredientDeleted = this->deleteFrom("recipeIngredient", "WHERE recipeId="+idString);
bool recipeDeleted = this->deleteFrom("recipe", "WHERE recipeId="+idString);
bool instructionDeleted = FileUtils::deleteInstruction(recipeId);
bool imageDeleted = FileUtils::deleteImage(recipeId);
if (tagsDeleted && recipeIngredientDeleted && recipeDeleted){
this->executeSQL("COMMIT;");
return true;

View File

@ -61,4 +61,18 @@ QImage loadImage(int nr){
return img;
}
bool deleteInstruction(int nr){
ensureAppDataFolderExists();
QString filename = appDataPath + QString::fromStdString(std::to_string(nr)) +".html";
QFile file(filename);
return file.remove();
}
bool deleteImage(int nr){
ensureAppDataFolderExists();
QString filename = appDataPath + QString::fromStdString(std::to_string(nr)) +".png";
QFile file(filename);
return file.remove();
}
}

View File

@ -6,6 +6,7 @@
#include <QDir>
#include <QTextStream>
#include <QImage>
#include <stdio.h>
#include "model/recipe/instruction.h"
@ -19,9 +20,13 @@ namespace FileUtils{
Instruction loadInstruction(int nr);
bool deleteInstruction(int nr);
bool saveImage(int nr, QImage image);
QImage loadImage(int nr);
bool deleteImage(int nr);
}
#endif // FILEUTILS_H