summaryrefslogtreecommitdiff
path: root/src/gui/dialogs/about.c
blob: 7868e190d2344aad3f45929f21200750d77c9724 (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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * about.h - boîte de dialogue d'information sur le programme
 *
 * Copyright (C) 2015-2017 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "about.h"


#include <math.h>
#include <stdio.h>
#include <gdk/gdkkeysyms.h>


#include <config.h>
#include <i18n.h>


#include "../../gtkext/easygtk.h"
#include "../../gtkext/support.h"



/* Réagit à l'appui d'une touche sur la fenêtre 'A propos'. */
static gboolean close_about_window_on_escape(GtkWidget *, GdkEventKey *, gpointer);



/******************************************************************************
*                                                                             *
*  Paramètres  : parent = fenêtre parente à surpasser.                        *
*                                                                             *
*  Description : Construit la fenêtre d'informations sur le logiciel.         *
*                                                                             *
*  Retour      : Adresse de la fenêtre mise en place.                         *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GtkWidget *create_about_dialog(GtkWindow *parent)
{
    GtkWidget *result;                      /* Fenêtre à renvoyer          */
    GdkRGBA color;                          /* Couleur de fond noire       */
    GtkWidget *fixed;                       /* Support global              */
    gchar *filename;                        /* Chemin d'accès au fichier   */
    GtkWidget *image;                       /* Image chargée               */
    unsigned int revision;                  /* Numéro de révision          */
    unsigned int max;                       /* Nbre. de boucles à effectuer*/
    unsigned int i;                         /* Boucle de parcours          */
    unsigned int level;                     /* Unité la plus importante    */
    char buffer[16];                        /* Nom d'image à forger        */
    GtkWidget *label;                       /* Etiquette inférieure        */

    result = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request(result, 350, 430);
    gtk_container_set_border_width(GTK_CONTAINER(result), 0);
    gtk_window_set_title(GTK_WINDOW(result), _("About"));
    gtk_window_set_transient_for(GTK_WINDOW(result), parent);
    gtk_window_set_default_size(GTK_WINDOW(result), 350, 430);
    gtk_window_set_type_hint(GTK_WINDOW(result), GDK_WINDOW_TYPE_HINT_DIALOG);

    g_signal_connect(result, "key_press_event", G_CALLBACK(close_about_window_on_escape), NULL);

    gdk_rgba_parse(&color, "black");
    gtk_widget_override_background_color(GTK_WIDGET(result), GTK_STATE_FLAG_NORMAL, &color);

    fixed = gtk_fixed_new();
    gtk_widget_show(fixed);
    gtk_container_add(GTK_CONTAINER(result), fixed);

    /* Images principales */

    filename = find_pixmap_file("chrysalide-full.png");
    image = qck_create_image(NULL, NULL, filename);
    gtk_fixed_put(GTK_FIXED(fixed), image, 10, 10);
    gtk_widget_set_size_request(image, 330, 300);

    filename = find_pixmap_file("chrysalide_text.png");
    image = qck_create_image(NULL, NULL, filename);
    gtk_fixed_put(GTK_FIXED(fixed), image, 48, 324);
    gtk_widget_set_size_request(image, 253, 42);

    /* Numéro de révision */

    filename = find_pixmap_file("revision.png");
    image = qck_create_image(NULL, NULL, filename);
    gtk_fixed_put(GTK_FIXED(fixed), image, 149, 360);
    gtk_widget_set_size_request(image, 14, 18);

    revision = REVISION;
    max = log(revision) / log(10);

    for (i = 0; i <= max; i++)
    {
        level = pow(10, max - i);

        snprintf(buffer, 16, "revision_%u.png", revision / level);

        filename = find_pixmap_file(buffer);
        image = qck_create_image(NULL, NULL, filename);
        gtk_fixed_put(GTK_FIXED(fixed), image, 163 + i * 14, 360);
        gtk_widget_set_size_request(image, 14, 18);

        revision %= level;

    }

    /* Copyright */

    label = qck_create_label(NULL, NULL, "<span fgcolor='white'>Copyright (C) 2008-2017 Cyrille Bagard</span>");
    gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
    gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
    gtk_fixed_put(GTK_FIXED(fixed), label, 0, 400);
    gtk_widget_set_size_request(label, 350, 20);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : window = fenêtre visée par la procédure.                     *
*                event  = informations liées à l'événement.                   *
*                dummy  = donnée non utilisée ici.                            *
*                                                                             *
*  Description : Réagit à l'appui d'une touche sur la fenêtre 'A propos'.     *
*                                                                             *
*  Retour      : TRUE pour poursuivre la propagation, FALSE autrement.        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static gboolean close_about_window_on_escape(GtkWidget *widget, GdkEventKey *event, gpointer dummy)
{
    gboolean result;                        /* Ordre à retourner           */

    if (event->keyval == GDK_KEY_Escape)
    {
        gtk_widget_destroy(widget);
        result = TRUE;
    }
    else result = FALSE;

    return result;

}