summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ctor.cc4
-rw-r--r--src/database.cc159
-rw-r--r--src/database.h15
-rw-r--r--src/database_gourmet.cc186
-rw-r--r--src/database_gourmet.h47
-rw-r--r--src/database_krecipes.cc346
-rw-r--r--src/database_krecipes.h47
-rw-r--r--src/mainwindow.cc17
-rw-r--r--src/qookie.cc7
9 files changed, 652 insertions, 176 deletions
diff --git a/ctor.cc b/ctor.cc
index 72c5cbb..058506f 100644
--- a/ctor.cc
+++ b/ctor.cc
@@ -12,6 +12,8 @@ BuildConfigurations myConfigs()
.sources = {
"src/qookie.cc",
"src/database.cc",
+ "src/database_gourmet.cc",
+ "src/database_krecipes.cc",
"src/mainwindow.cc",
"src/moc_mainwindow.cc",
"src/viewer.cc",
@@ -24,6 +26,8 @@ BuildConfigurations myConfigs()
"-I/usr/include/qt5/QtGui",
"-I/usr/include/qt5/QtWidgets",
"-fPIC",
+ "-Wall", "-Werror", "-Wextra",// "-Wconversion",
+ "-g",
},
.ldflags = {
"-lQt5Core",
diff --git a/src/database.cc b/src/database.cc
index 60b8814..207a114 100644
--- a/src/database.cc
+++ b/src/database.cc
@@ -25,162 +25,3 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "database.h"
-
-#include <sqlite3.h>
-#include <iostream>
-
-// https://www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm
-
-Database::Database(const std::string& file)
-{
- auto rc = sqlite3_open(file.data(), &db); // https://sqlite.org/c3ref/open.html
- if(rc)
- {
- std::cerr << "Can't open database: " << sqlite3_errmsg(db) << '\n';
- return;
- }
- else
- {
- std::cout << "Opened database successfully\n";
- }
-}
-
-Database::~Database()
-{
- sqlite3_close(db);
-}
-
-namespace
-{
-std::string getString(sqlite3_stmt *statement, int index)
-{
- int size = sqlite3_column_bytes(statement, index);
- std::string str;
- str.append((const char*)sqlite3_column_blob(statement, index), size);
- return str;
-}
-} // ::
-
-std::deque<RecipeItem> Database::getRecipes()
-{
- std::deque<RecipeItem> items;
-
- std::string sql = "select id, title, image from recipe";
- sqlite3_stmt *statement;
- if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
- {
- std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
- return {};
- }
-
- int result = 0;
- while(true)
- {
- RecipeItem item;
- result = sqlite3_step(statement);
-
- if(result == SQLITE_ROW)
- {
- item.id = sqlite3_column_int(statement, 0);
-
- item.title = getString(statement, 1);
- item.image = getString(statement, 2);
- }
- else
- {
- break;
- }
- items.push_back(item);
- }
-
- return items;
-}
-
-Recipe Database::getRecipe(int id)
-{
- bool found{false};
- Recipe recipe;
-
- {
- std::string sql =
- "select id, title, description, image, instructions, source, link, cuisine, cooktime, preptime, yields, yield_unit, modifications from recipe where id=" +
- std::to_string(id);
- sqlite3_stmt *statement;
- if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
- {
- std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
- return {};
- }
-
- int result = 0;
- while(true)
- {
- result = sqlite3_step(statement);
-
- if(result == SQLITE_ROW)
- {
- recipe.id = sqlite3_column_int(statement, 0);
- recipe.title = getString(statement, 1);
- recipe.description = getString(statement, 2);
- recipe.image = getString(statement, 3);
- recipe.instructions = getString(statement, 4);
- recipe.source = getString(statement, 5);
- if(!recipe.source.empty())
- {
- recipe.source += " ";
- }
- recipe.source += getString(statement, 6);
- recipe.cuisine = getString(statement, 7);
- recipe.cooktime = sqlite3_column_int(statement, 8);
- recipe.preptime = sqlite3_column_int(statement, 9);
- recipe.yields = sqlite3_column_double(statement, 10);
- recipe.yield_unit = getString(statement, 11);
- recipe.tags.push_back(getString(statement, 12));
- }
- else
- {
- break;
- }
- found = true;
- }
- }
-
- if(!found)
- {
- std::cerr << "id " << id << " not found\n";
- return {};
- }
-
- {
- std::string sql =
- "select amount, unit, item from ingredients where recipe_id=" +
- std::to_string(id);// + " order by position asc";
- sqlite3_stmt *statement;
- if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
- {
- std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
- return {};
- }
-
- int result = 0;
- while(true)
- {
- Ingredient ingredient;
- result = sqlite3_step(statement);
-
- if(result == SQLITE_ROW)
- {
- ingredient.amount = sqlite3_column_double(statement, 0);
- ingredient.unit = getString(statement, 1);
- ingredient.item = getString(statement, 2);
- recipe.ingredients.push_back(ingredient);
- }
- else
- {
- break;
- }
- }
- }
-
- return recipe;
-}
diff --git a/src/database.h b/src/database.h
index 449f40e..8291334 100644
--- a/src/database.h
+++ b/src/database.h
@@ -26,23 +26,18 @@
*/
#pragma once
-#include <string>
#include <deque>
-#include <string>
+#include <cstdint>
#include "recipe.h"
-struct sqlite3;
-
class Database
{
public:
- Database(const std::string& file);
- ~Database();
+ virtual ~Database() = default;
- std::deque<RecipeItem> getRecipes();
- Recipe getRecipe(int id);
+ virtual std::uint64_t id() const = 0;
-private:
- sqlite3 *db{nullptr};
+ virtual std::deque<RecipeItem> getRecipes() = 0;
+ virtual Recipe getRecipe(std::uint64_t id) = 0;
};
diff --git a/src/database_gourmet.cc b/src/database_gourmet.cc
new file mode 100644
index 0000000..e556440
--- /dev/null
+++ b/src/database_gourmet.cc
@@ -0,0 +1,186 @@
+/* -*- c++ -*- */
+/***************************************************************************
+ * database_gourmet.cc
+ *
+ * Sun Apr 24 18:27:56 CEST 2022
+ * Copyright 2022 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Qookie.
+ *
+ * Qookie is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qookie is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qookie; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "database_gourmet.h"
+
+#include <sqlite3.h>
+#include <iostream>
+
+// https://www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm
+
+DatabaseGourmet::DatabaseGourmet(const std::string& file)
+{
+ auto rc = sqlite3_open(file.data(), &db); // https://sqlite.org/c3ref/open.html
+ if(rc)
+ {
+ std::cerr << "Can't open database: " << sqlite3_errmsg(db) << '\n';
+ return;
+ }
+ else
+ {
+ std::cout << "Opened database successfully\n";
+ }
+}
+
+DatabaseGourmet::~DatabaseGourmet()
+{
+ sqlite3_close(db);
+}
+
+namespace
+{
+std::string getString(sqlite3_stmt *statement, int index)
+{
+ int size = sqlite3_column_bytes(statement, index);
+ std::string str;
+ str.append((const char*)sqlite3_column_blob(statement, index), size);
+ return str;
+}
+} // ::
+
+std::deque<RecipeItem> DatabaseGourmet::getRecipes()
+{
+ std::deque<RecipeItem> items;
+
+ std::string sql = "select id, title, image from recipe";
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ RecipeItem item;
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ item.id = sqlite3_column_int(statement, 0);
+
+ item.title = getString(statement, 1);
+ item.image = getString(statement, 2);
+ }
+ else
+ {
+ break;
+ }
+ items.push_back(item);
+ }
+
+ return items;
+}
+
+Recipe DatabaseGourmet::getRecipe(std::uint64_t id)
+{
+ bool found{false};
+ Recipe recipe;
+
+ {
+ std::string sql =
+ "select id, title, description, image, instructions, source, link, cuisine, cooktime, preptime, yields, yield_unit, modifications from recipe where id=" +
+ std::to_string(id);
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ recipe.id = sqlite3_column_int(statement, 0);
+ recipe.title = getString(statement, 1);
+ recipe.description = getString(statement, 2);
+ recipe.image = getString(statement, 3);
+ recipe.instructions = getString(statement, 4);
+ recipe.source = getString(statement, 5);
+ if(!recipe.source.empty())
+ {
+ recipe.source += " ";
+ }
+ recipe.source += getString(statement, 6);
+ recipe.cuisine = getString(statement, 7);
+ recipe.cooktime = sqlite3_column_int(statement, 8);
+ recipe.preptime = sqlite3_column_int(statement, 9);
+ recipe.yields = sqlite3_column_double(statement, 10);
+ recipe.yield_unit = getString(statement, 11);
+ recipe.tags.push_back(getString(statement, 12));
+ }
+ else
+ {
+ break;
+ }
+ found = true;
+ }
+ }
+
+ if(!found)
+ {
+ std::cerr << "id " << id << " not found\n";
+ return {};
+ }
+
+ {
+ std::string sql =
+ "select amount, unit, item from ingredients where recipe_id=" +
+ std::to_string(id) + " order by position asc";
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ Ingredient ingredient;
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ ingredient.amount = sqlite3_column_double(statement, 0);
+ ingredient.unit = getString(statement, 1);
+ ingredient.item = getString(statement, 2);
+ recipe.ingredients.push_back(ingredient);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ return recipe;
+}
diff --git a/src/database_gourmet.h b/src/database_gourmet.h
new file mode 100644
index 0000000..70ee04d
--- /dev/null
+++ b/src/database_gourmet.h
@@ -0,0 +1,47 @@
+/* -*- c++ -*- */
+/***************************************************************************
+ * database_gourmet.h
+ *
+ * Sun Apr 24 18:27:56 CEST 2022
+ * Copyright 2022 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Qookie.
+ *
+ * Qookie is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qookie is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qookie; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#pragma once
+
+#include "database.h"
+
+struct sqlite3;
+
+class DatabaseGourmet
+ : public Database
+{
+public:
+ DatabaseGourmet(const std::string& file);
+ ~DatabaseGourmet();
+
+ std::uint64_t id() const override { return 1UL << 63; }
+
+ std::deque<RecipeItem> getRecipes() override;
+ Recipe getRecipe(std::uint64_t id) override;
+
+private:
+ sqlite3 *db{nullptr};
+};
diff --git a/src/database_krecipes.cc b/src/database_krecipes.cc
new file mode 100644
index 0000000..fceb59c
--- /dev/null
+++ b/src/database_krecipes.cc
@@ -0,0 +1,346 @@
+/* -*- c++ -*- */
+/***************************************************************************
+ * database_krecipes.cc
+ *
+ * Sun Apr 24 18:28:00 CEST 2022
+ * Copyright 2022 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Qookie.
+ *
+ * Qookie is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qookie is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qookie; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "database_krecipes.h"
+
+#include <sqlite3.h>
+#include <iostream>
+
+// https://www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm
+
+DatabaseKrecipes::DatabaseKrecipes(const std::string& file)
+{
+ auto rc = sqlite3_open(file.data(), &db); // https://sqlite.org/c3ref/open.html
+ if(rc)
+ {
+ std::cerr << "Can't open database: " << sqlite3_errmsg(db) << '\n';
+ return;
+ }
+ else
+ {
+ std::cout << "Opened database successfully\n";
+ }
+}
+
+DatabaseKrecipes::~DatabaseKrecipes()
+{
+ sqlite3_close(db);
+}
+
+namespace
+{
+std::string getString(sqlite3_stmt *statement, int index)
+{
+ int size = sqlite3_column_bytes(statement, index);
+ std::string str;
+ str.append((const char*)sqlite3_column_blob(statement, index), size);
+ return str;
+}
+} // ::
+
+std::deque<RecipeItem> DatabaseKrecipes::getRecipes()
+{
+ std::deque<RecipeItem> items;
+
+ std::string sql = "select id, title, photo from recipes";
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ RecipeItem item;
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ item.id = sqlite3_column_int(statement, 0);
+
+ item.title = getString(statement, 1);
+ item.image = getString(statement, 2);
+ }
+ else
+ {
+ break;
+ }
+ items.push_back(item);
+ }
+
+ return items;
+}
+
+Recipe DatabaseKrecipes::getRecipe(std::uint64_t id)
+{
+ bool found{false};
+ Recipe recipe;
+
+ {
+ std::string sql =
+ "select id, title, photo, instructions, prep_time, yield_amount, yield_type_id from recipes where id=" +
+ std::to_string(id);
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ recipe.id = sqlite3_column_int(statement, 0);
+ recipe.title = getString(statement, 1);
+ recipe.description = {}; // not used by krecipes
+ recipe.image = getString(statement, 2);
+ recipe.instructions = getString(statement, 3);
+ recipe.source = {}; // set later
+ recipe.cuisine = {}; // not used by krecipes
+ recipe.cooktime = {}; // not used by krecipes
+ recipe.preptime = 0;
+ std::string duration = getString(statement, 4); // "hh:mm:ss" format
+ try
+ {
+ int h = std::stoi(duration.substr(0, 2));
+ int m = std::stoi(duration.substr(3, 2));
+ int s = std::stoi(duration.substr(6, 2));
+ recipe.preptime = s + m * 60 + h * 60 * 60;
+ }
+ catch(...)
+ {
+ }
+ recipe.yields = sqlite3_column_double(statement, 5);
+ recipe.yield_unit = getString(statement, 6); // indirection set later
+ recipe.tags.push_back("N/A"); // not used by krecipes
+ }
+ else
+ {
+ break;
+ }
+ found = true;
+ }
+ }
+
+ if(!found)
+ {
+ std::cerr << "id " << id << " not found\n";
+ return {};
+ }
+
+ //
+ // Get auhors list
+ //
+ {
+ std::string sql =
+ "select author_id from author_list where recipe_id=" +
+ std::to_string(id);
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ int author_id = sqlite3_column_int(statement, 0);
+ {
+ std::string sql =
+ "select name from authors where id=" + std::to_string(author_id);
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ if(!recipe.source.empty())
+ {
+ recipe.source += ", ";
+ }
+ recipe.source += getString(statement, 0);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ //
+ // Get yield unit
+ //
+ {
+ std::string sql =
+ "select name from yield_types where id=" + recipe.yield_unit;
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ recipe.yield_unit = getString(statement, 0);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ if(recipe.yield_unit == "-1")
+ {
+ recipe.yield_unit = "";
+ }
+
+ //
+ // Get ingredients
+ //
+ {
+ std::string sql =
+ "select ingredient_id, amount, unit_id, group_id from ingredient_list where recipe_id=" + std::to_string(id) + " order by order_index asc";
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ Ingredient ingredient;
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ ingredient.item = getString(statement, 0);
+ ingredient.amount = sqlite3_column_double(statement, 1);
+ ingredient.unit = getString(statement, 2);
+
+ //
+ // Get ingredient name
+ //
+ {
+ std::string sql =
+ "select name from ingredients where id=" + ingredient.item;
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ ingredient.item = getString(statement, 0);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ //
+ // Get ingredient amount unit
+ //
+ {
+ std::string sql =
+ "select name from units where id=" + ingredient.unit;
+ sqlite3_stmt *statement;
+ if(sqlite3_prepare_v2(db, sql.data(), sql.length(), &statement, 0) != SQLITE_OK)
+ {
+ std::cerr << "sqlite3_prepare_v2 failed: " << sqlite3_errmsg(db) << '\n';
+ return {};
+ }
+
+ int result = 0;
+ while(true)
+ {
+ result = sqlite3_step(statement);
+
+ if(result == SQLITE_ROW)
+ {
+ ingredient.unit = getString(statement, 0);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ recipe.ingredients.push_back(ingredient);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ return recipe;
+}
diff --git a/src/database_krecipes.h b/src/database_krecipes.h
new file mode 100644
index 0000000..5f15a47
--- /dev/null
+++ b/src/database_krecipes.h
@@ -0,0 +1,47 @@
+/* -*- c++ -*- */
+/***************************************************************************
+ * database_krecipes.h
+ *
+ * Sun Apr 24 18:28:00 CEST 2022
+ * Copyright 2022 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Qookie.
+ *
+ * Qookie is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qookie is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qookie; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#pragma once
+
+#include "database.h"
+
+struct sqlite3;
+
+class DatabaseKrecipes
+ : public Database
+{
+public:
+ DatabaseKrecipes(const std::string& file);
+ ~DatabaseKrecipes();
+
+ std::uint64_t id() const override { return 1UL << 63; }
+
+ std::deque<RecipeItem> getRecipes() override;
+ Recipe getRecipe(std::uint64_t id) override;
+
+private:
+ sqlite3 *db{nullptr};
+};
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index eae86d0..f5c9d9d 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -47,13 +47,13 @@ MainWindow::MainWindow(Database& db)
// Create the toolbar
//
QToolBar *toolbar = new QToolBar("A toolbar");
-
+ /*
QAction *act_load = toolbar->addAction("Load");
// connect(act_load, SIGNAL(triggered()), &document, SLOT(load()));
QAction *act_save = toolbar->addAction("Save");
// connect(act_save, SIGNAL(triggered()), &document, SLOT(save()));
-
+ */
//
// Create the browser docking widget
//
@@ -97,7 +97,16 @@ void MainWindow::readDatabase()
if(!item.image.empty())
{
QIcon icon;
- QImage image = QImage::fromData((const uchar*)item.image.data(), item.image.size());
+ QImage image;
+ if(item.image.substr(0, 4) == "/9j/") // Image is base64 encoded
+ {
+ QByteArray data = QByteArray::fromBase64(QByteArray(item.image.data(), item.image.size()));
+ image = QImage::fromData(data);
+ }
+ else
+ {
+ image = QImage::fromData((const uchar*)item.image.data(), item.image.size());
+ }
icon.addPixmap(QPixmap::fromImage(image));
listItem->setIcon(icon);
}
@@ -114,7 +123,7 @@ void MainWindow::readDatabase()
}
}
-void MainWindow::itemChanged(int row)
+void MainWindow::itemChanged(int)
{
auto item = listWidget->currentItem();
auto id = item->data(Qt::UserRole).toInt();
diff --git a/src/qookie.cc b/src/qookie.cc
index a6b48b0..1f6f9d8 100644
--- a/src/qookie.cc
+++ b/src/qookie.cc
@@ -29,14 +29,15 @@
#include <iostream>
#include "mainwindow.h"
-#include "database.h"
+#include "database_gourmet.h"
+#include "database_krecipes.h"
int main(int argc, char *argv[])
{
QApplication qapp(argc, argv);
- Database db("/mnt/atuin/docs/tine/Fritid/Mad/recipes.db");
- //Database db("/mnt/atuin/docs/tine/Fritid/Mad/krecipes.krecdb");
+ //DatabaseGourmet db("/mnt/atuin/docs/tine/Fritid/Mad/recipes.db");
+ DatabaseKrecipes db("/mnt/atuin/docs/tine/Fritid/Mad/krecipes.krecdb");
MainWindow mainwindow(db);
mainwindow.resize(1280, 768);