diff --git a/.gitignore b/.gitignore index 267eb4d..f9453ef 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ *.o *.a *.so -labfy-investigation # SQLite *.sqlite-wal diff --git a/docs/tickets/open/TICKET-001.md b/docs/tickets/open/TICKET-001.md new file mode 100644 index 0000000..3edd3d3 --- /dev/null +++ b/docs/tickets/open/TICKET-001.md @@ -0,0 +1,37 @@ +# Ticket #001 + +## Titre + +Créer le module Application. + +## Objectif + +Créer le point d’entrée applicatif chargé de gérer le cycle de vie de GTK. + +## Responsabilités + +- créer l’objet GtkApplication ; +- lancer la boucle principale GTK ; +- libérer proprement les ressources ; +- afficher une fenêtre minimale au signal `activate`. + +## Hors périmètre + +- SQLite ; +- ouverture d’une enquête ; +- sélecteur de dossier ; +- logique métier. + +## Critères d’acceptation + +- [ ] Le projet compile en C17. +- [ ] Aucun warning. +- [ ] Aucun état global. +- [ ] Les fonctions publiques sont documentées avec Doxygen. +- [ ] Une fenêtre GTK minimale s’affiche. +- [ ] La fermeture de l’application est propre. + +## Commit attendu + +```text +feat(core): create application lifecycle diff --git a/labfy-investigation/.gitignore b/labfy-investigation/.gitignore new file mode 100644 index 0000000..3fedcb4 --- /dev/null +++ b/labfy-investigation/.gitignore @@ -0,0 +1,11 @@ +# Build +enquete-gui +*.o + +# SQLite temporaires +*.sqlite-shm +*.sqlite-wal + +# Neovim / LSP +.cache/ +compile_commands.json diff --git a/labfy-investigation/Makefile b/labfy-investigation/Makefile new file mode 100644 index 0000000..6cd3a68 --- /dev/null +++ b/labfy-investigation/Makefile @@ -0,0 +1,33 @@ +CC = gcc + +PKG_CONFIG = pkg-config + +CFLAGS = -std=c17 \ + -Wall \ + -Wextra \ + -Werror \ + -g \ + -Iinclude \ + $(shell $(PKG_CONFIG) --cflags gtk4 sqlite3) + +LDFLAGS = $(shell $(PKG_CONFIG) --libs gtk4 sqlite3) + +SRC := $(shell find src -name "*.c") + +OBJ := $(SRC:.c=.o) + +TARGET = labfy-investigation + +$(TARGET): $(OBJ) + $(CC) $(OBJ) -o $@ $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) $(TARGET) + +run: $(TARGET) + ./$(TARGET) + +.PHONY: clean run diff --git a/labfy-investigation/compile_flags.txt b/labfy-investigation/compile_flags.txt new file mode 100644 index 0000000..0d77def --- /dev/null +++ b/labfy-investigation/compile_flags.txt @@ -0,0 +1,22 @@ +-I/usr/include/gtk-4.0 +-I/usr/include/pango-1.0 +-I/usr/include/fribidi +-I/usr/include/harfbuzz +-I/usr/include/gdk-pixbuf-2.0 +-I/usr/include/glycin-2 +-I/usr/include/cairo +-I/usr/include/freetype2 +-I/usr/include/libpng16 +-I/usr/include/pixman-1 +-I/usr/include/graphene-1.0 +-I/usr/lib/graphene-1.0/include +-mfpmath=sse +-msse +-msse2 +-I/usr/include/glib-2.0 +-I/usr/lib/glib-2.0/include +-I/usr/include/libmount +-I/usr/include/blkid +-I/usr/include/sysprof-6 +-pthread +-Iinclude diff --git a/labfy-investigation/database/init.sql b/labfy-investigation/database/init.sql new file mode 100644 index 0000000..e69de29 diff --git a/labfy-investigation/database/schema.sql b/labfy-investigation/database/schema.sql new file mode 100644 index 0000000..e69de29 diff --git a/labfy-investigation/include/core/application.h b/labfy-investigation/include/core/application.h new file mode 100644 index 0000000..f0c8eeb --- /dev/null +++ b/labfy-investigation/include/core/application.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * @file application.h + * @brief Interface publique du cycle de vie de l'application. + ******************************************************************************/ + +#ifndef LABFY_INVESTIGATION_APPLICATION_H +#define LABFY_INVESTIGATION_APPLICATION_H + +/** + * @brief Représentation opaque de l'application. + * + * Les détails GTK sont volontairement masqués au reste du programme. + */ +typedef struct Application Application; + +/** + * @brief Crée et initialise une application Labfy Investigation. + * + * @return Une nouvelle application, ou NULL en cas d'échec. + */ +Application *application_new(void); + +/** + * @brief Lance la boucle principale de l'application. + * + * @param application Application à exécuter. + * @param argc Nombre d'arguments de la ligne de commande. + * @param argv Tableau des arguments de la ligne de commande. + * + * @return Code de sortie retourné par GTK. + */ +int application_run(Application *application, int argc, char **argv); + +/** + * @brief Libère les ressources possédées par l'application. + * + * Cette fonction accepte NULL. + * + * @param application Application à libérer. + */ +void application_free(Application *application); + +#endif diff --git a/labfy-investigation/labfy-investigation b/labfy-investigation/labfy-investigation new file mode 100755 index 0000000..5c17dac Binary files /dev/null and b/labfy-investigation/labfy-investigation differ diff --git a/labfy-investigation/src/core/application.c b/labfy-investigation/src/core/application.c new file mode 100644 index 0000000..79e6288 --- /dev/null +++ b/labfy-investigation/src/core/application.c @@ -0,0 +1,115 @@ +/****************************************************************************** + * @file application.c + * @brief Implémentation du cycle de vie de l'application GTK. + ******************************************************************************/ + +#include "core/application.h" + +#include + +/** + * @brief Identifiant unique utilisé par GLib pour l'application. + */ +#define APPLICATION_ID "com.labfytools.investigation" + +/** + * @brief Dimensions initiales de la fenêtre principale. + */ +#define DEFAULT_WINDOW_WIDTH 1000 +#define DEFAULT_WINDOW_HEIGHT 650 + +/** + * @struct Application + * @brief État interne de l'application. + * + * Cette structure reste privée à ce module afin d'empêcher les autres + * composants de manipuler directement les objets GTK. + */ +struct Application +{ + GtkApplication *gtk_application; +}; + +/** + * @brief Crée la fenêtre minimale lors de l'activation de l'application. + * + * Cette fonction est privée au module. Elle est appelée par GTK lorsque + * l'application reçoit le signal "activate". + * + * @param gtk_application Application GTK ayant reçu le signal. + * @param user_data Données utilisateur associées au signal. + */ +static void application_on_activate(GtkApplication *gtk_application, + gpointer user_data) +{ + GtkWidget *window = NULL; + + (void)user_data; + + window = gtk_application_window_new(gtk_application); + + gtk_window_set_title(GTK_WINDOW(window), "Labfy Investigation"); + gtk_window_set_default_size( + GTK_WINDOW(window), + DEFAULT_WINDOW_WIDTH, + DEFAULT_WINDOW_HEIGHT + ); + + gtk_window_present(GTK_WINDOW(window)); +} + +Application *application_new(void) +{ + Application *application = NULL; + + application = g_new0(Application, 1); + + application->gtk_application = gtk_application_new( + APPLICATION_ID, + G_APPLICATION_DEFAULT_FLAGS + ); + + if (application->gtk_application == NULL) + { + g_free(application); + return NULL; + } + + g_signal_connect( + application->gtk_application, + "activate", + G_CALLBACK(application_on_activate), + application + ); + + return application; +} + +int application_run(Application *application, int argc, char **argv) +{ + if (application == NULL || application->gtk_application == NULL) + { + return 1; + } + + return g_application_run( + G_APPLICATION(application->gtk_application), + argc, + argv + ); +} + +void application_free(Application *application) +{ + if (application == NULL) + { + return; + } + + if (application->gtk_application != NULL) + { + g_object_unref(application->gtk_application); + } + + g_free(application); +} diff --git a/labfy-investigation/src/main.c b/labfy-investigation/src/main.c new file mode 100644 index 0000000..8ce50aa --- /dev/null +++ b/labfy-investigation/src/main.c @@ -0,0 +1,27 @@ +/****************************************************************************** + * @file main.c + * @brief Point d'entrée de Labfy Investigation. + ******************************************************************************/ + +#include "core/application.h" + +#include + +int main(int argc, char **argv) +{ + Application *application = NULL; + int exit_status = EXIT_FAILURE; + + application = application_new(); + + if (application == NULL) + { + return EXIT_FAILURE; + } + + exit_status = application_run(application, argc, argv); + + application_free(application); + + return exit_status; +}