feat(core): create investigation module

This commit is contained in:
grayTerminal-sh 2026-07-12 16:15:51 +02:00
parent aa2b903487
commit d8242f20ca
4 changed files with 212 additions and 8 deletions

View file

@ -0,0 +1,59 @@
/******************************************************************************
* @file investigation.h
* @brief Interface publique du module Investigation.
******************************************************************************/
#ifndef LABFY_INVESTIGATION_INVESTIGATION_H
#define LABFY_INVESTIGATION_INVESTIGATION_H
/**
* @brief Représentation opaque d'une enquête.
*
* La structure réelle est définie dans investigation.c.
* Les autres modules peuvent manipuler un pointeur vers Investigation,
* mais ne peuvent pas accéder directement à ses champs internes.
*/
typedef struct Investigation Investigation;
/**
* @brief Crée une nouvelle enquête à partir d'un dossier racine.
*
* @param root_path Chemin du dossier racine de l'enquête.
*
* @return Une nouvelle enquête, ou NULL si le chemin est invalide
* ou si l'allocation mémoire échoue.
*/
Investigation *investigation_new(const char *root_path);
/**
* @brief Libère toutes les ressources associées à une enquête.
*
* Cette fonction accepte NULL.
*
* @param investigation Enquête à libérer.
*/
void investigation_free(Investigation *investigation);
/**
* @brief Retourne le chemin racine de l'enquête.
*
* @param investigation Enquête à consulter.
*
* @return Le chemin racine en lecture seule, ou NULL si l'enquête est invalide.
*/
const char *investigation_get_root_path(
const Investigation *investigation
);
/**
* @brief Retourne le chemin de la base de données de l'enquête.
*
* @param investigation Enquête à consulter.
*
* @return Le chemin de la base en lecture seule, ou NULL si l'enquête est invalide.
*/
const char *investigation_get_database_path(
const Investigation *investigation
);
#endif

View file

@ -5,6 +5,7 @@
#include "core/application.h" #include "core/application.h"
#include "views/folder_dialog.h" #include "views/folder_dialog.h"
#include "core/investigation.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -47,20 +48,34 @@ static void application_on_folder_selected(
) )
{ {
GtkWindow *window = GTK_WINDOW(user_data); GtkWindow *window = GTK_WINDOW(user_data);
Investigation *investigation = NULL;
const char *root_path = NULL;
const char *database_path = NULL;
if (folder_path == NULL) if (folder_path == NULL)
{ {
gtk_window_set_title( g_print("Sélection annulée.\n");
window,
"Labfy Investigation — aucune enquête sélectionnée"
);
return; return;
} }
gtk_window_set_title(window, folder_path); investigation = investigation_new(folder_path);
}
if (investigation == NULL)
{
g_warning("Impossible de créer l'enquête à partir du dossier sélectionné.");
return;
}
root_path = investigation_get_root_path(investigation);
database_path = investigation_get_database_path(investigation);
g_print("Dossier racine : %s\n", root_path);
g_print("Base de données : %s\n", database_path);
investigation_free(investigation);
gtk_window_set_title(window, "Labfy Investigation");
}
static void application_on_activate(GtkApplication *gtk_application, static void application_on_activate(GtkApplication *gtk_application,
gpointer user_data) gpointer user_data)
{ {
@ -142,4 +157,3 @@ void application_free(Application *application)
g_free(application); g_free(application);
} }

View file

@ -0,0 +1,131 @@
/******************************************************************************
* @file investigation.c
* @brief Implémentation du module représentant une enquête.
******************************************************************************/
#include "core/investigation.h"
#include <stdbool.h>
#include <glib.h>
/**
* @brief Nom du dossier contenant la base de données d'une enquête.
*/
#define INVESTIGATION_DATABASE_DIRECTORY "00_BaseDeDonnees"
/**
* @brief Nom du fichier SQLite d'une enquête.
*/
#define INVESTIGATION_DATABASE_FILENAME "Enquete.sqlite"
/**
* @struct Investigation
* @brief Représentation interne d'une enquête.
*
* Cette structure est privée au module. Les autres fichiers connaissent
* uniquement le type opaque déclaré dans investigation.h.
*/
struct Investigation
{
char *root_path;
char *database_path;
};
/**
* @brief Vérifie qu'un chemin peut servir de dossier racine à une enquête.
*
* @param root_path Chemin à vérifier.
*
* @return true si le chemin désigne un dossier existant, sinon false.
*/
static bool investigation_root_path_is_valid(const char *root_path)
{
if (root_path == NULL)
{
return false;
}
if (root_path[0] == '\0')
{
return false;
}
if (!g_file_test(root_path, G_FILE_TEST_IS_DIR))
{
return false;
}
return true;
}
Investigation *investigation_new(const char *root_path)
{
Investigation *investigation = NULL;
if (!investigation_root_path_is_valid(root_path))
{
return NULL;
}
investigation = g_new0(Investigation, 1);
investigation->root_path = g_canonicalize_filename(root_path, NULL);
if (investigation->root_path == NULL)
{
investigation_free(investigation);
return NULL;
}
investigation->database_path = g_build_filename(
investigation->root_path,
INVESTIGATION_DATABASE_DIRECTORY,
INVESTIGATION_DATABASE_FILENAME,
NULL
);
if (investigation->database_path == NULL)
{
investigation_free(investigation);
return NULL;
}
return investigation;
}
void investigation_free(Investigation *investigation)
{
if (investigation == NULL)
{
return;
}
g_free(investigation->database_path);
g_free(investigation->root_path);
g_free(investigation);
}
const char *investigation_get_root_path(
const Investigation *investigation
)
{
if (investigation == NULL)
{
return NULL;
}
return investigation->root_path;
}
const char *investigation_get_database_path(
const Investigation *investigation
)
{
if (investigation == NULL)
{
return NULL;
}
return investigation->database_path;
}