feat(core): create application lifecycle
This commit is contained in:
parent
919bd1b7ad
commit
6236e80cbb
11 changed files with 288 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,7 +2,6 @@
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
*.so
|
*.so
|
||||||
labfy-investigation
|
|
||||||
|
|
||||||
# SQLite
|
# SQLite
|
||||||
*.sqlite-wal
|
*.sqlite-wal
|
||||||
|
|
|
||||||
37
docs/tickets/open/TICKET-001.md
Normal file
37
docs/tickets/open/TICKET-001.md
Normal file
|
|
@ -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
|
||||||
11
labfy-investigation/.gitignore
vendored
Normal file
11
labfy-investigation/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Build
|
||||||
|
enquete-gui
|
||||||
|
*.o
|
||||||
|
|
||||||
|
# SQLite temporaires
|
||||||
|
*.sqlite-shm
|
||||||
|
*.sqlite-wal
|
||||||
|
|
||||||
|
# Neovim / LSP
|
||||||
|
.cache/
|
||||||
|
compile_commands.json
|
||||||
33
labfy-investigation/Makefile
Normal file
33
labfy-investigation/Makefile
Normal file
|
|
@ -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
|
||||||
22
labfy-investigation/compile_flags.txt
Normal file
22
labfy-investigation/compile_flags.txt
Normal file
|
|
@ -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
|
||||||
0
labfy-investigation/database/init.sql
Normal file
0
labfy-investigation/database/init.sql
Normal file
0
labfy-investigation/database/schema.sql
Normal file
0
labfy-investigation/database/schema.sql
Normal file
43
labfy-investigation/include/core/application.h
Normal file
43
labfy-investigation/include/core/application.h
Normal file
|
|
@ -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
|
||||||
BIN
labfy-investigation/labfy-investigation
Executable file
BIN
labfy-investigation/labfy-investigation
Executable file
Binary file not shown.
115
labfy-investigation/src/core/application.c
Normal file
115
labfy-investigation/src/core/application.c
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* @file application.c
|
||||||
|
* @brief Implémentation du cycle de vie de l'application GTK.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "core/application.h"
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
27
labfy-investigation/src/main.c
Normal file
27
labfy-investigation/src/main.c
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* @file main.c
|
||||||
|
* @brief Point d'entrée de Labfy Investigation.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "core/application.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue