]> Pileus Git - ~andy/gtk/blob - tests/testvolumebutton.c
Add a second volume button.
[~andy/gtk] / tests / testvolumebutton.c
1 /* testvolumebutton.c
2  * Copyright (C) 2007  Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gtk/gtk.h>
21
22 static void
23 value_changed (GtkWidget *button,
24                gdouble volume,
25                gpointer user_data)
26 {
27         g_message ("volume changed to %f", volume);
28 }
29
30 static void
31 response_cb (GtkDialog *dialog,
32              gint       arg1,
33              gpointer   user_data)
34 {
35         gtk_widget_destroy (GTK_WIDGET (dialog));
36 }
37
38 static gboolean
39 show_error (gpointer data)
40 {
41         GtkWindow *window = (GtkWindow *) data;
42         GtkWidget *dialog;
43
44         g_message ("showing error");
45
46         dialog = gtk_message_dialog_new (window,
47                                          GTK_DIALOG_MODAL,
48                                          GTK_MESSAGE_INFO,
49                                          GTK_BUTTONS_CLOSE,
50                                          "This should have unbroken the grab");
51         g_signal_connect (G_OBJECT (dialog),
52                           "response",
53                           G_CALLBACK (response_cb), NULL);
54         gtk_widget_show (dialog);
55
56         return FALSE;
57 }
58
59 int main (int argc, char **argv)
60 {
61         GtkWidget *window;
62         GtkWidget *button;
63         GtkWidget *button2;
64         GtkWidget *box;
65
66         gtk_init (&argc, &argv);
67
68         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
69         button = gtk_volume_button_new ();
70         button2 = gtk_volume_button_new ();
71         box = gtk_hbox_new (FALSE, 0);      
72   
73         g_signal_connect (G_OBJECT (button),
74                           "value-changed",
75                           G_CALLBACK (value_changed), NULL);
76         gtk_container_add (GTK_CONTAINER (window), box);
77         gtk_container_add (GTK_CONTAINER (box), button);
78         gtk_container_add (GTK_CONTAINER (box), button2);
79
80         gtk_widget_show_all (window);
81         gtk_button_clicked (GTK_BUTTON (button));
82         g_timeout_add (4000, (GSourceFunc) show_error, window);
83
84         gtk_main ();
85
86         return 0;
87 }
88