summaryrefslogtreecommitdiff
path: root/src/gui/core/panels.c
blob: 4c113b84496c191c762dc774f2552a938284955c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

/* Chrysalide - Outil d'analyse de fichiers binaires
 * panels.c - gestion d'ensemble de tous les panneaux graphiques du framework
 *
 * Copyright (C) 2016-2025 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  Chrysalide 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.
 *
 *  Chrysalide 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include "panels.h"


#include <assert.h>
#include <malloc.h>
#include <string.h>


#include <i18n.h>


#include "../panels/binary.h"
#include "../panels/binary-params.h"
#include "../panels/welcome.h"
#include "../../gtkext/launcher.h"



/* Définition générique complète d'un panneau */
typedef struct _ext_panel_info_t
{
    /* Début des champs copiés de panel_info_t */

    char *category;                         /* Groupe de rassemblement     */

    char *image;                            /* Eventuelle image associée   */
    char *title;                            /* Désignation humaine         */
    char *desc;                             /* Description humaine         */

    FrameworkPanelPersonality personality;  /* Comportement attendu        */

    GType panel_type;                       /* Type du panneau représenté  */
    GType params_type;                      /* Composant de paramètre      */

    /* Fin des champs copiés de panel_info_t */

    GtkTiledPanel *singleton;               /* Conservation des allocations*/

} ext_panel_info_t;


/* Liste des panneaux disponibles */
static ext_panel_info_t **_panels_list = NULL;
static size_t _panels_count = 0;


/* Copie une définition basique de panneau graphqiue. */
static ext_panel_info_t *copy_panel_info(const panel_info_t *);

/* Efface une définition étendue de panneau graphique. */
static void delete_panel_info(ext_panel_info_t *);



/******************************************************************************
*                                                                             *
*  Paramètres  : info = information de base à copier.                         *
*                                                                             *
*  Description : Copie une définition basique de panneau graphqiue.           *
*                                                                             *
*  Retour      : Structure mémorisant l'ensemble des informations.            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static ext_panel_info_t *copy_panel_info(const panel_info_t *info)
{
    ext_panel_info_t *result;               /* Structure à retourner       */

    result = calloc(1, sizeof(ext_panel_info_t));

    if (info->category != NULL)
        result->category = strdup(info->category);

    if (info->image != NULL)
        result->image = strdup(info->image);

    result->title = strdup(info->title);

    if (info->desc != NULL)
        result->desc = strdup(info->desc);

    result->personality = info->personality;

    result->panel_type = info->panel_type;
    result->params_type = info->params_type;

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : info = informations à supprimer de la mémoire.               *
*                                                                             *
*  Description : Efface une définition étendue de panneau graphique.          *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void delete_panel_info(ext_panel_info_t *info)
{
    if (info->category != NULL)
        free(info->category);

    if (info->image != NULL)
        free(info->image);

    free(info->title);

    if (info->desc != NULL)
        free(info->desc);

    if (info->singleton != NULL)
    {
        assert(info->personality & FPP_SINGLETON);
        unref_object(info->singleton);
    }

    free(info);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : -                                                            *
*                                                                             *
*  Description : Charge les définitions des principaux panneaux du framework. *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool load_main_framework_panel_definitions(void)
{
    bool result;                            /* Bilan à retourner           */
    panel_info_t info;                      /* Infos d'enregistrement      */

    // TODO register_panel_item(G_TYPE_LOG_PANEL, config);

    /* Chargement du panneau de rapport au plus tôt */
    // TODO panel = g_panel_item_new(G_TYPE_LOG_PANEL, NULL);

    info.category = "Main";

    info.image = "binfile-symbolic";
    info.title = _("Binary analysis");
    info.desc = _("Load a binary content and parse its format if recognized");

    info.personality = FPP_MAIN_PANEL;

    info.panel_type = GTK_TYPE_BINARY_PANEL;
    info.params_type = GTK_TYPE_BINARY_PARAMETERS;

    result = register_framework_panel_definition(&info);
    if (!result) goto done;

    info.category = NULL;

    info.image = NULL;
    info.title = _("Welcome");
    info.desc = NULL;

    info.personality = FPP_MAIN_PANEL | FPP_SINGLETON;

    info.panel_type = GTK_TYPE_WELCOME_PANEL;
    info.params_type = G_TYPE_INVALID;

    result = register_framework_panel_definition(&info);
    if (!result) goto done;

 done:

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : -                                                            *
*                                                                             *
*  Description : Décharge tous les panneaux graphiques du framework.          *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void unload_all_framework_panel_definitions(void)
{
    size_t i;                               /* Boucle de parcours          */

    for (i = 0; i < _panels_count; i++)
        delete_panel_info(_panels_list[i]);

    _panels_list = NULL;
    _panels_count = 0;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : info = information de base à copier.                         *
*                                                                             *
*  Description : Enregistre la définition d'un panneau graphique.             *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool register_framework_panel_definition(const panel_info_t *info)
{
    bool result;                            /* Bilan à retourner           */
    size_t i;                               /* Boucle de parcours          */
    ext_panel_info_t *ext_info;             /* Informations conservées     */

    result = false;

    /* Validation */

    for (i = 0; i < _panels_count; i++)
        if (_panels_list[i]->panel_type == info->panel_type)
            break;

    if (i < _panels_count)
        goto done;

    /* Enregistrement */

    ext_info = copy_panel_info(info);

    _panels_list = realloc(_panels_list, ++_panels_count * sizeof(ext_panel_info_t *));

    _panels_list[_panels_count - 1] = ext_info;

    result = true;

 done:

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : target = type de définition de panneau recherchée.           *
*                                                                             *
*  Description : Met en place (au besoin) un panneau graphique unique.        *
*                                                                             *
*  Retour      : Instance de définition identifiée ou NULL en cas d'échec.    *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GtkTiledPanel *get_framework_panel_singleton(GType target)
{
    GtkTiledPanel *result;                  /* Instance à renvoyer         */
    size_t i;                               /* Boucle de parcours          */
    ext_panel_info_t *info;                 /* Informations conservées     */

    result = NULL;

    for (i = 0; i < _panels_count; i++)
    {
        info = _panels_list[i];

        if (info->panel_type == target)
        {
            if (info->singleton == NULL)
                info->singleton = g_object_new(target, NULL);

            result = info->singleton;
            ref_object(result);
            break;

        }

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : list = liste à compléter.                                    *
*                                                                             *
*  Description : Intègre une définition de panneau enregistrée.               *
*                                                                             *
*  Retour      : true pour un parcours complet de la liste des définitions.   *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void populate_framework_panel_launcher_list(GtkListBox *list)
{
    size_t i;                               /* Boucle de parcours          */
    ext_panel_info_t *info;                 /* Informations conservées     */
    GtkPanelLauncher *launcher;             /* Lanceur à intégrer          */

    for (i = 0; i < _panels_count; i++)
    {
        info = _panels_list[i];

        if (info->category == NULL)
            continue;

        launcher = gtk_panel_launcher_new(info->image, info->title, info->desc);

        g_object_set_data(G_OBJECT(launcher), "panel_type", GSIZE_TO_POINTER(info->panel_type));

        gtk_list_box_append(list, GTK_WIDGET(launcher));

    }

}


/******************************************************************************
*                                                                             *
*  Paramètres  : row = lanceur sélectionné.                                   *
*                                                                             *
*  Description : Fournit un composant d'édition de paramètres de panneau.     *
*                                                                             *
*  Retour      : Composant d'édition de paramètres ou NULL.                   *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GtkWidget *get_framework_panel_parameters(GtkListBoxRow *row)
{
    GtkWidget *result;                      /* Composant à retourner       */
    gpointer *data;                         /* Valeur incrustée            */
    GType target;                           /* Type de panneau recherché   */
    ext_panel_info_t *info;                 /* Informations conservées     */
    size_t i;                               /* Boucle de parcours          */

    data = g_object_get_data(G_OBJECT(row), "panel_type");
    assert(data != NULL);

    target = GPOINTER_TO_SIZE(data);

    info = NULL;

    for (i = 0; i < _panels_count; i++)
    {
        info = _panels_list[i];

        if (info->panel_type == target)
            break;

    }

    assert(info != NULL);
    assert(i < _panels_count);

    if (info->params_type == G_TYPE_INVALID)
        result = NULL;
    else
        result = g_object_new(info->params_type, NULL);

    return result;

}