| 12
 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
 
 | #include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <gtk/gtk.h>
 
const gchar *nom_fichier;
 
int main(int argc, char **argv)
{
    /* déclaration du widget */
    GtkWidget *file_selection;
    /* déclaration des fonctions call back */
    void OnDestroy(GtkWidget *pWidget, gpointer pData); /* fonction call back destroy */
    void recuperer_chemin(GtkWidget *bouton, GtkWidget *file_selection); /* fonction call back file selection */
    void suite(GtkWidget *bouton, GtkWidget *file_selection); /* fonction call back après récup chemin */
 
    /* Initialisation de GTK+ */
    gtk_init(&argc, &argv);
    /* creation du file_selection*/
    file_selection=gtk_file_selection_new("choix fichier");
    /* on interdit la possibilité de selection plusieurs fichiers */
    gtk_file_selection_set_select_multiple(GTK_FILE_SELECTION(file_selection), FALSE);
    /* on vire les boutons de création de directory, deletion, rename, etc.. */
    gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(file_selection));
    /* on centre la fenetre sur l'écran */
    gtk_window_set_position(GTK_WINDOW(file_selection), GTK_WIN_POS_CENTER);
    /* Connexion des signaux */
    g_signal_connect(GTK_FILE_SELECTION(file_selection)->ok_button, "clicked", G_CALLBACK(recuperer_chemin), file_selection); /* recup nom fichier */
    g_signal_connect(GTK_FILE_SELECTION(file_selection)->ok_button, "clicked", G_CALLBACK(suite), file_selection);
    g_signal_connect(G_OBJECT(file_selection), "delete-event", G_CALLBACK(OnDestroy), NULL);
    g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(file_selection)->cancel_button), "clicked", G_CALLBACK(OnDestroy), file_selection);
    /* affichage du sélecteur de fichier */
    gtk_widget_show(file_selection);
    /* Demarrage de la boucle evenementielle */
    gtk_main();
    return EXIT_SUCCESS;
}
 
 
void OnDestroy(GtkWidget *pWidget, gpointer pData)
{
    /* Arret de la boucle evenementielle */
    gtk_main_quit();
    return;
}
 
 
void recuperer_chemin(GtkWidget *bouton, GtkWidget *file_selection)
{
    /* recupération du nom du fichier */
    nom_fichier=gtk_file_selection_get_filename(GTK_FILE_SELECTION(file_selection));
    return;
}
 
 
void suite(GtkWidget *bouton, GtkWidget *file_selection)
{
    /* suite après que le nom du fichier ait été récupérer */
    char tempo[2000];
    GError *error = NULL;
    gboolean flag;
 
    (void)sprintf(tempo,"del \"\%s\"",nom_fichier);
    (void)printf("%s\n",tempo);
    flag=g_spawn_command_line_async(tempo, &error);
    if(!flag)
    {
        g_printerr("%s\n", error->message);
        g_error_free(error);
        error = NULL;
    }
    gtk_widget_destroy(file_selection);
    gtk_main_quit();
    return;
} |