~jcowgill/ubuntu/trusty/easytag/bug-1295882

« back to all changes in this revision

Viewing changes to src/msgbox.c

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2008-09-08 21:44:11 UTC
  • mfrom: (3.1.10 hardy)
  • Revision ID: james.westby@ubuntu.com-20080908214411-v237hcgn5d97ecut
Tags: 2.1.4-1.1
* Non-maintainer upload.
* Warn user when ogg vorbis tags will be lost, fix handling of multiple same
  ogg vorbis tags (Closes: #460247).
* Fix lintian warnings:
  - Add watch file.
  - Install icon for menu file (Closes: #477456).
  - Fix section in menu file.
  - Drop version from NAME section of man page to `apropos' and `whatis'
    happy.
  - Include copyright information in debian/copyright.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "setting.h"
33
33
 
34
34
 
35
 
static void msg_box_class_init (MsgBoxClass *class);
36
 
static void msg_box_init (MsgBox *mb);
37
 
 
38
 
static void msg_box_show (GtkWidget *widget);
39
 
static gint msg_box_delete_event (GtkWidget *widget, GdkEventAny *event);
40
 
static void msg_box_button_clicked (GtkButton *button, gpointer data);
41
 
void        check_button_toggled (GtkCheckButton *checkbutton, gpointer data);
42
 
 
43
 
 
44
 
static GtkDialogClass *parent_klass = NULL;
45
 
 
46
 
 
47
 
GType msg_box_get_type(void)
48
 
{
49
 
    static GType mb_type = 0;
50
 
 
51
 
    if (!mb_type)
52
 
    {
53
 
        GTypeInfo mb_info = 
54
 
        {
55
 
            sizeof(MsgBoxClass),
56
 
            NULL,
57
 
            NULL,
58
 
            (GClassInitFunc) msg_box_class_init,
59
 
            NULL,
60
 
            NULL,
61
 
            sizeof(MsgBox),
62
 
            0,
63
 
            (GInstanceInitFunc) msg_box_init
64
 
        };
65
 
        mb_type = g_type_register_static(GTK_TYPE_DIALOG, "MsgBox", &mb_info, 0);
66
 
    }
67
 
    return mb_type;
68
 
}
69
 
 
70
 
 
71
 
static void msg_box_button_clicked (GtkButton *button, gpointer data)
72
 
{
73
 
    MsgBox *mb;
74
 
 
75
 
    g_return_if_fail( (mb = MSG_BOX(data)) );
76
 
 
77
 
    mb->button_clicked = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"button_value"));
78
 
 
79
 
    if (gtk_main_level()>1)
80
 
        gtk_main_quit();
81
 
}
82
 
 
83
 
 
84
 
static void msg_box_class_init (MsgBoxClass *class)
85
 
{
86
 
    GtkObjectClass *object_class;
87
 
    GtkWidgetClass *widget_class;
88
 
    GtkDialogClass *dialog_class;
89
 
 
90
 
    object_class = (GtkObjectClass*) class;
91
 
    widget_class = (GtkWidgetClass*) class;
92
 
    dialog_class = (GtkDialogClass*) class;
93
 
 
94
 
    parent_klass = gtk_type_class(gtk_dialog_get_type());
95
 
 
96
 
    object_class->destroy      = msg_box_destroy;
97
 
    widget_class->delete_event = msg_box_delete_event;
98
 
    widget_class->show         = msg_box_show;
99
 
}
100
 
 
101
 
 
102
 
static void msg_box_init (MsgBox *mb)
103
 
{
104
 
    g_return_if_fail(mb != NULL);
105
 
    g_return_if_fail(IS_MSG_BOX(mb));
106
 
 
107
 
    mb->icon                = -1;
108
 
    mb->check_button        = NULL;
109
 
    mb->check_button_state  = 0;
110
 
 
111
 
}
 
35
GtkWidget *msg_box_new (gchar *title, GtkWindow *parent, GtkWidget **check_button, GtkDialogFlags flags, gchar *message, const gchar *icon, ...);
 
36
 
112
37
 
113
38
 
114
39
/*
115
 
 * Create a new message box
 
40
 * Create a new message box to display a message and a check button (for some actions).
 
41
 * The first button passed as parameter will have the focus
116
42
 */
117
 
GtkWidget *msg_box_new (gchar *title, gchar *message, const gchar *stock_id, 
118
 
            /* Put all the buttons to display, and terminate by 0 */
119
 
            ...)
 
43
GtkWidget *msg_box_new (gchar *title, 
 
44
                        GtkWindow *parent,
 
45
                        GtkWidget **check_button, 
 
46
                        GtkDialogFlags flags,
 
47
                        gchar *message,
 
48
                        const gchar *stock_id,
 
49
                        /* Put all the buttons to display, and terminate by 0 */
 
50
                        ...)
120
51
{
121
 
    MsgBox *mb;
 
52
    GtkWidget *dialog;
122
53
    GtkWidget *Table;
123
54
    GtkWidget *Pixmap;
124
55
    GtkWidget *Label;
125
 
    GtkWidget *ButtonBox;
126
 
    GtkWidget *Button = NULL;
127
 
    va_list cursor;
128
 
    gint cursor_value;
129
 
 
 
56
    GtkWidget *Button;
 
57
    gboolean first_button = TRUE;
 
58
    va_list args;
 
59
    
130
60
 
131
61
    g_return_val_if_fail(message!=NULL, NULL);
132
 
 
133
 
    mb = MSG_BOX(g_object_new(TYPE_MSG_BOX, NULL));
134
 
    //mb->icon = icon;
135
 
    mb->check_button = gtk_check_button_new_with_label(_("Repeat action for the rest of the files")); /* Can save or cancel all files */
136
 
 
137
 
    /* Window configuration */
138
 
    gtk_window_set_title(GTK_WINDOW(mb),title);
139
 
    gtk_window_set_transient_for(GTK_WINDOW(mb),GTK_WINDOW(MainWindow));
140
 
    gtk_window_set_modal(GTK_WINDOW(mb),TRUE);
141
 
 
 
62
    
 
63
    //dialog = GTK_DIALOG(gtk_dialog_new_empty (title, parent, flags));
 
64
    dialog = gtk_dialog_new_with_buttons(title,parent,flags,NULL);
 
65
 
 
66
    // Position of the dialog window
142
67
    if (MESSAGE_BOX_POSITION_NONE)
143
 
        gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_NONE);
 
68
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_NONE);
144
69
    else if (MESSAGE_BOX_POSITION_CENTER)
145
 
        gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_CENTER);
 
70
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
146
71
    else if (MESSAGE_BOX_POSITION_MOUSE)
147
 
        gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_MOUSE);
 
72
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_MOUSE);
148
73
    else if (MESSAGE_BOX_POSITION_CENTER_ON_PARENT)
149
 
        gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_CENTER_ON_PARENT);
150
 
 
151
 
 
152
 
    /* Table to put: the pixmap, the message and the check button */
 
74
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ON_PARENT);
 
75
    
 
76
 
 
77
    // Table to insert: the pixmap, the message and the check button
153
78
    Table = gtk_table_new(2,2,FALSE);
154
 
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mb)->vbox),Table,TRUE,TRUE,0);
 
79
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),Table,TRUE,TRUE,0);
155
80
    gtk_container_set_border_width(GTK_CONTAINER(Table),4);
156
81
    gtk_widget_show(Table);
157
82
 
158
 
    /* The Pixmap */
 
83
    // The pixmap
159
84
    Pixmap = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_DIALOG);
160
85
    gtk_table_attach_defaults(GTK_TABLE(Table),Pixmap,0,1,0,1);
161
86
    //gtk_table_attach(GTK_TABLE(Table),Pixmap,0,1,0,1,GTK_FILL,GTK_FILL,0,0);
162
87
    gtk_misc_set_padding(GTK_MISC(Pixmap),6,6);
163
88
    gtk_widget_show(Pixmap);
164
89
 
165
 
    /* The Message */
166
 
    Label = gtk_label_new (message);
 
90
    // The message
 
91
    Label = gtk_label_new(message);
167
92
    gtk_table_attach_defaults(GTK_TABLE(Table),Label,1,2,0,1);
168
93
    gtk_misc_set_padding(GTK_MISC(Label),6,6);
169
94
    gtk_label_set_justify(GTK_LABEL(Label),GTK_JUSTIFY_CENTER);
170
95
    //gtk_label_set_line_wrap(GTK_LABEL(Label),TRUE);
171
96
    gtk_widget_show(Label);
172
97
 
173
 
    /* The Check Button */
174
 
    gtk_table_attach_defaults(GTK_TABLE(Table),mb->check_button,0,2,1,2);
175
 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mb->check_button),mb->check_button_state);
176
 
    g_signal_connect(G_OBJECT(mb->check_button),"toggled",G_CALLBACK(check_button_toggled),mb);
177
 
    gtk_widget_show(mb->check_button);
178
 
 
179
 
 
180
 
    /* Buttons */
181
 
    ButtonBox = gtk_hbutton_box_new();
182
 
    gtk_box_set_spacing(GTK_BOX(ButtonBox), 15);
183
 
    gtk_button_box_set_layout(GTK_BUTTON_BOX(ButtonBox), GTK_BUTTONBOX_END);
184
 
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(mb)->action_area),ButtonBox);
185
 
 
186
 
    /* Read buttons from variable arguments */
187
 
    va_start (cursor,stock_id);
188
 
    while ( (cursor_value = va_arg(cursor,gint)) != 0 )
189
 
    {
190
 
        Button = Create_Button_With_Pixmap(cursor_value);
191
 
        gtk_container_add(GTK_CONTAINER(ButtonBox),Button);
 
98
    // The check button
 
99
    if (check_button)
 
100
    {
 
101
        *check_button = gtk_check_button_new_with_label(_("Repeat action for the rest of the files")); // Can save or cancel all files
 
102
        gtk_table_attach_defaults(GTK_TABLE(Table),*check_button,0,2,1,2);
 
103
    }
 
104
 
 
105
    // Read buttons from variable arguments
 
106
    va_start(args, stock_id);
 
107
    for (;;)
 
108
    {
 
109
        const gchar *button_text = NULL;
 
110
        gint response_id = 0;
 
111
        
 
112
        button_text = va_arg (args, const gchar *);
 
113
        if (button_text == NULL)
 
114
            break;
 
115
        response_id = va_arg (args, gint);
 
116
        if (response_id == 0)
 
117
            break;
 
118
        
 
119
        Button = gtk_dialog_add_button(GTK_DIALOG(dialog),button_text,response_id);
192
120
        GTK_WIDGET_SET_FLAGS(Button,GTK_CAN_DEFAULT);
193
 
        g_signal_connect(G_OBJECT(Button),"destroy", G_CALLBACK(gtk_widget_destroyed),&Button);
194
 
        g_signal_connect(G_OBJECT(Button),"clicked", G_CALLBACK(msg_box_button_clicked),mb);
195
 
        g_object_set_data(G_OBJECT(Button),"button_value", GINT_TO_POINTER(cursor_value));
 
121
        
 
122
        // To focus to the first button
 
123
        if (first_button)
 
124
            gtk_widget_grab_default(Button);
 
125
        first_button = FALSE;
196
126
    }
197
 
    va_end(cursor);
198
 
    gtk_widget_grab_default(Button);
199
 
    gtk_widget_show_all(ButtonBox);
200
 
 
201
 
    return GTK_WIDGET(mb);
202
 
}
203
 
 
204
 
 
205
 
void msg_box_destroy (GtkObject *object)
206
 
{
207
 
    MsgBox *mb;
208
 
 
209
 
    g_return_if_fail( (mb = MSG_BOX(object)) );
210
 
 
211
 
    if (mb->check_button)
212
 
        gtk_widget_destroy(mb->check_button);
213
 
 
214
 
/* FIXME: causes segfault in some cases (when callin gtk_widget_destroy(msgbox) ) */
215
 
/*    if (GTK_OBJECT_CLASS(parent_klass)->destroy)
216
 
 *        (* GTK_OBJECT_CLASS(parent_klass)->destroy) (object);
217
 
 */
218
 
}
219
 
 
220
 
 
221
 
static gint msg_box_delete_event (GtkWidget *widget, GdkEventAny *event)
222
 
223
 
    MsgBox *mb;
224
 
 
225
 
    g_return_val_if_fail((mb = MSG_BOX(widget)), FALSE);
226
 
 
227
 
    /* If the window is closed whitout pressing a button, we return -1 */
228
 
    mb->button_clicked = -1;
229
 
 
230
 
    if (gtk_main_level()>1)
231
 
        gtk_main_quit(); 
232
 
 
233
 
    return TRUE;
234
 
}
235
 
 
236
 
 
237
 
/*
238
 
 * "Run" and show the msgbox, and send which button was pressed (or not a button)
239
 
 */
240
 
gint msg_box_run (MsgBox *msgbox)
241
 
{
242
 
    MsgBox *mb;
243
 
 
244
 
    g_return_val_if_fail((mb = MSG_BOX(msgbox)),0);
245
 
 
246
 
    gtk_widget_show(GTK_WIDGET(mb));
247
 
    gtk_main();
248
 
    gtk_widget_hide(GTK_WIDGET(mb));
249
 
    gtk_window_set_modal(GTK_WINDOW(mb),FALSE);
250
 
 
251
 
    return (MSG_BOX(mb)->button_clicked);
252
 
}
253
 
 
254
 
 
255
 
static void msg_box_show (GtkWidget *widget)
256
 
{
257
 
    if (GTK_WIDGET_CLASS(parent_klass)->show)
258
 
        (* (GTK_WIDGET_CLASS(parent_klass)->show))(widget);
259
 
}
260
 
 
261
 
 
262
 
/*
263
 
 * Callback when the check_button is pressed
264
 
 */
265
 
void check_button_toggled (GtkCheckButton *checkbutton, gpointer data)
266
 
{
267
 
    MsgBox *mb;
268
 
 
269
 
    g_return_if_fail((mb = MSG_BOX(data)));
270
 
 
271
 
    mb->check_button_state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton));
272
 
}
273
 
 
274
 
 
275
 
/*
276
 
 * Set the check_button to the 'is_active' state
277
 
 */
278
 
void msg_box_check_button_set_active (MsgBox *msgbox, gboolean is_active)
279
 
{
280
 
    MsgBox *mb;
281
 
 
282
 
    g_return_if_fail((mb = MSG_BOX(msgbox)));
283
 
 
284
 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mb->check_button),is_active);
285
 
    mb->check_button_state = is_active;
286
 
}
287
 
 
288
 
 
289
 
/*
290
 
 * Hide the check_button.
291
 
 */
292
 
void msg_box_hide_check_button (MsgBox *msgbox)
293
 
{
294
 
    MsgBox *mb;
295
 
 
296
 
    g_return_if_fail((mb = MSG_BOX(msgbox)));
297
 
 
298
 
    gtk_widget_hide(mb->check_button);
 
127
    va_end(args);
 
128
    
 
129
    gtk_widget_show_all(dialog);
 
130
    
 
131
    return GTK_WIDGET(dialog);
299
132
}