/* * main.c * * Copyright 2024 Michael Rasmussen * * This program 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 2 of the License, or * (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * */ #ifdef HAVE_CONFIG_H # include #endif #include #include "database.h" #include "lens.h" #include "lensmaker.h" #include "sqlite-storage.h" int main(int argc, char **argv) { gchar* path; gint id; gchar* sn; gchar* data; gchar* notes; gchar* date; gchar* maker; GError* error = NULL; Database* database = NULL; Lens* lens = NULL; LensMaker* lensmaker = NULL; const gchar* db_path = "/home/mir/git/gtk_lensdatabase"; database = database_new(db_path, &error); g_object_get(database, "path", &path, NULL); fprintf(stdout, "path: %s\n", path); g_free(path); database_add_lens_maker(database, "Lumix", &error); if (error) { fprintf(stderr, "%s: Failed to add maker [%s]\n", error->message, "Lumix"); g_error_free(error); error = NULL; } database_add_lens_maker(database, "Fake", &error); if (error) { fprintf(stderr, "%s: Failed to add maker [%s]\n", error->message, "Fake"); g_error_free(error); error = NULL; } database_print_lens_makers(database); database_remove_lens_maker(database, "Fake", &error); if (error) { fprintf(stderr, "%s: Failed to remove maker [%s]\n", error->message, "Fake"); g_error_free(error); error = NULL; } database_print_lens_makers(database); g_object_unref(database); lens = lens_new(12, "1234", "Some data", &error); if (error) { fprintf(stderr, "Failed to add lens [%s]\n", error->message); g_error_free(error); error = NULL; } g_object_set(lens, "notes", "Some notes", NULL); g_object_get(lens, "id", &id, "sn", &sn, "data", &data, "notes", ¬es, "date", &date, NULL); g_object_unref(lens); fprintf(stdout, "id: %d sn: %s data: %s notes: %s date: %s\n", id, sn, data, notes, date); g_free(sn); g_free(data); g_free(notes); g_free(date); lensmaker = lens_maker_new(1); g_object_set(lensmaker, "lensmaker", "Some Maker", NULL); g_object_get(lensmaker, "lensmaker", &maker, NULL); g_object_unref(lensmaker); fprintf(stdout, "maker: %s\n", maker); g_free(maker); database = database_new(db_path, &error); database_add_lens_maker(database, "Lumix", &error); lensmaker = database_get_lens_maker(database, "Lumix", &error); if (error) { fprintf(stderr, "Failed to add lens [%s]\n", error->message); g_error_free(error); error = NULL; } lens = lens_new(12, "1234", "Some data", &error); if (error) { fprintf(stderr, "Failed to add lens [%s]\n", error->message); g_error_free(error); error = NULL; } lens_maker_add_lens(lensmaker, lens, &error); if (error) { fprintf(stderr, "Failed to add lens [%s]\n", error->message); g_error_free(error); error = NULL; } id = lens_get_id(lens, &error); if (error) { fprintf(stderr, "Failed to add lens [%s]\n", error->message); g_error_free(error); error = NULL; } Lens* l = lens_maker_get_lens(lensmaker, id, &error); if (error) { fprintf(stderr, "Failed to add lens [%s]\n", error->message); g_error_free(error); error = NULL; } gchar* s = lens_to_string(l); fprintf(stderr, "%s\n", s); g_free(s); lens_maker_remove_lens(lensmaker, lens, &error); if (error) { fprintf(stderr, "Failed to add lens [%s]\n", error->message); g_error_free(error); error = NULL; } g_object_unref(lensmaker); s = lens_to_string(l); fprintf(stderr, "%s\n", s); g_free(s); g_object_unref(l); g_object_unref(database); return 0; }