hythmbox-2.98/widgets/test-rb-segmented-bar.c

No issues found

 1 /*
 2  *  Copyright (C) 2008 Christophe Fergeau <teuf@gnome.org>
 3  *
 4  *  This program is free software; you can redistribute it and/or modify
 5  *  it under the terms of the GNU General Public License as published by
 6  *  the Free Software Foundation; either version 2 of the License, or
 7  *  (at your option) any later version.
 8  *
 9  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
10  *  GStreamer plugins to be used and distributed together with GStreamer
11  *  and Rhythmbox. This permission is above and beyond the permissions granted
12  *  by the GPL license by which Rhythmbox is covered. If you modify this code
13  *  you may extend this exception to your version of the code, but you are not
14  *  obligated to do so. If you do not wish to do so, delete this exception
15  *  statement from your version.
16  *
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
25  *
26  */
27 
28 /* compile with:
29  gcc -o test-rb-segmented-bar -I. $(pkg-config --cflags --libs gtk+-2.0)
30     ./rb-segmented-bar.c ./test-rb-segmented-bar.c
31  */
32 #include <gtk/gtk.h>
33 #include <rb-segmented-bar.h>
34 
35 static void window_destroyed_cb (void)
36 {
37     	gtk_main_quit ();
38 }
39 
40 static gchar *value_formatter (gdouble percent, gpointer data)
41 {
42 	gsize total_size = GPOINTER_TO_SIZE (data);
43 
44 	return g_format_size (percent * total_size*1024*1024*1024);
45 }
46 
47 int main (int argc, char **argv)
48 {
49 	GtkWidget *window;
50 	RBSegmentedBar *bar;
51 	const gsize total_size = 100; /* in GB */
52 
53 	gtk_init (&argc, &argv);
54 
55 	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
56 	bar = RB_SEGMENTED_BAR (rb_segmented_bar_new ());
57 	g_object_set (G_OBJECT (bar),
58 		      "show-reflection", TRUE,
59 		      "show-labels", TRUE,
60 		      NULL);
61 
62 	rb_segmented_bar_add_segment (bar, "audio", 0.61, 0.2 , 0.4 , 0.65, 1);
63 	rb_segmented_bar_add_segment (bar, "video", 0.11, 0.96, 0.47, 0   , 1);
64 	rb_segmented_bar_add_segment (bar, "other", 0.05, 0.45, 0.82, 0.08, 1);
65 	rb_segmented_bar_add_segment_default_color (bar, "empty", 0.23);
66 	rb_segmented_bar_set_value_formatter (bar, value_formatter,
67 					      GSIZE_TO_POINTER (total_size));
68 
69 	g_signal_connect(G_OBJECT (window), "destroy",
70 			 G_CALLBACK (window_destroyed_cb), NULL);
71 	gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (bar));
72 	gtk_widget_show_all (GTK_WIDGET (window));
73 	gtk_main ();
74 
75 	return 0;
76 }