mp3splt-gtk
radio_helper.c
Go to the documentation of this file.
1 /**********************************************************
2  *
3  * mp3splt-gtk -- utility based on mp3splt,
4  * for mp3/ogg splitting without decoding
5  *
6  * Copyright: (C) 2005-2012 Alexandru Munteanu
7  * Contact: io_fx@yahoo.fr
8  *
9  * http://mp3splt.sourceforge.net/
10  *
11  *********************************************************/
12 
13 /**********************************************************
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28  * USA.
29  *
30  *********************************************************/
31 
32 /*!********************************************************
33  * \file
34  *
35  * this file contains the code for the radio button helpers.
36  ********************************************************/
37 
38 #include "radio_helper.h"
39 
40 GtkWidget *rh_append_radio_to_vbox(GtkWidget *radio_button, const gchar *text,
41  gint value,
42  void (*callback)(GtkToggleButton *, gpointer),
43  GtkWidget *vbox)
44 {
45  GtkWidget *new_radio_button =
46  gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio_button), text);
47  gtk_box_pack_start(GTK_BOX(vbox), new_radio_button, FALSE, FALSE, 0);
48 
49  if (callback)
50  {
51  g_signal_connect(GTK_TOGGLE_BUTTON(new_radio_button), "toggled", G_CALLBACK(callback),
52  NULL);
53  }
54 
55  g_object_set_data(G_OBJECT(new_radio_button), "value", GINT_TO_POINTER(value));
56 
57  return new_radio_button;
58 }
59 
60 gint rh_get_active_value(GtkWidget *radio_button)
61 {
62  gint active_value = -1;
63  GSList *radio_button_list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button));
64 
65  gint i = 0;
66  for(i = 0; i < g_slist_length(radio_button_list);i++)
67  {
68  GtkRadioButton *current_radio = (GtkRadioButton *) g_slist_nth_data(radio_button_list, i);
69  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(current_radio)))
70  {
71  active_value = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(current_radio), "value"));
72  break;
73  }
74  }
75 
76  return active_value;
77 }
78 
79 GtkWidget *rh_get_radio_from_value(GtkWidget *radio_button, gint value)
80 {
81  GtkWidget *radio = NULL;
82  GSList *radio_button_list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button));
83 
84  gint i = 0;
85  for(i = 0; i < g_slist_length(radio_button_list);i++)
86  {
87  GtkRadioButton *current_radio = (GtkRadioButton *) g_slist_nth_data(radio_button_list, i);
88  gint current_value = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(current_radio), "value"));
89  if (current_value == value)
90  {
91  radio = GTK_WIDGET(current_radio);
92  break;
93  }
94  }
95 
96  return radio;
97 }
98