aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/msgbox.c
blob: 82953f9daf781b15de6a39047ab931d3e0cb6274 (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
/* msgbox.c - 2000/10/13 */
/*
 *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
 *  Copyright (C) 2000-2003  Jerome Couderc <easytag@gmail.com>
 *
 *  This program 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 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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.
 */
/* Note: Some pieces of codes come from gnome-dialog.c
 */

#include <config.h>

#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <stdarg.h>

#include "msgbox.h"
#include "easytag.h"
#include "misc.h"
#include "setting.h"


GtkWidget *msg_box_new (gchar *title, GtkWindow *parent, GtkWidget **check_button, GtkDialogFlags flags, gchar *message, const gchar *icon, ...);



/*
 * Create a new message box to display a message and a check button (for some actions).
 * The first button passed as parameter will have the focus
 */
GtkWidget *msg_box_new (gchar *title, 
                        GtkWindow *parent,
                        GtkWidget **check_button, 
                        GtkDialogFlags flags,
                        gchar *message,
                        const gchar *stock_id,
                        /* Put all the buttons to display, and terminate by 0 */
                        ...)
{
    GtkWidget *dialog;
    GtkWidget *Table;
    GtkWidget *Pixmap;
    GtkWidget *Label;
    GtkWidget *Button;
    gboolean first_button = TRUE;
    va_list args;
    

    g_return_val_if_fail(message!=NULL, NULL);
    
    //dialog = GTK_DIALOG(gtk_dialog_new_empty (title, parent, flags));
    dialog = gtk_dialog_new_with_buttons(title,parent,flags,NULL);

    // Position of the dialog window
    if (MESSAGE_BOX_POSITION_NONE)
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_NONE);
    else if (MESSAGE_BOX_POSITION_CENTER)
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
    else if (MESSAGE_BOX_POSITION_MOUSE)
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_MOUSE);
    else if (MESSAGE_BOX_POSITION_CENTER_ON_PARENT)
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ON_PARENT);
    

    // Table to insert: the pixmap, the message and the check button
    Table = gtk_table_new(2,2,FALSE);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),Table,TRUE,TRUE,0);
    gtk_container_set_border_width(GTK_CONTAINER(Table),4);
    gtk_widget_show(Table);

    // The pixmap
    Pixmap = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_DIALOG);
    gtk_table_attach_defaults(GTK_TABLE(Table),Pixmap,0,1,0,1);
    //gtk_table_attach(GTK_TABLE(Table),Pixmap,0,1,0,1,GTK_FILL,GTK_FILL,0,0);
    gtk_misc_set_padding(GTK_MISC(Pixmap),6,6);
    gtk_widget_show(Pixmap);

    // The message
    Label = gtk_label_new(message);
    gtk_table_attach_defaults(GTK_TABLE(Table),Label,1,2,0,1);
    gtk_misc_set_padding(GTK_MISC(Label),6,6);
    gtk_label_set_justify(GTK_LABEL(Label),GTK_JUSTIFY_CENTER);
    //gtk_label_set_line_wrap(GTK_LABEL(Label),TRUE);
    gtk_widget_show(Label);

    // The check button
    if (check_button)
    {
        *check_button = gtk_check_button_new_with_label(_("Repeat action for the rest of the files")); // Can save or cancel all files
        gtk_table_attach_defaults(GTK_TABLE(Table),*check_button,0,2,1,2);
    }

    // Read buttons from variable arguments
    va_start(args, stock_id);
    for (;;)
    {
        const gchar *button_text = NULL;
        gint response_id = 0;
        
        button_text = va_arg (args, const gchar *);
        if (button_text == NULL)
            break;
        response_id = va_arg (args, gint);
        if (response_id == 0)
            break;
        
        Button = gtk_dialog_add_button(GTK_DIALOG(dialog),button_text,response_id);
        GTK_WIDGET_SET_FLAGS(Button,GTK_CAN_DEFAULT);
        
        // To focus to the first button
        if (first_button)
            gtk_widget_grab_default(Button);
        first_button = FALSE;
    }
    va_end(args);
    
    gtk_widget_show_all(dialog);
    
    return GTK_WIDGET(dialog);
}