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, void (*callback)(GtkToggleButton *, gpointer), gpointer callback_data,
42  GtkWidget *vbox)
43 {
44  GtkWidget *new_radio_button =
45  gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio_button), text);
46  gtk_box_pack_start(GTK_BOX(vbox), new_radio_button, FALSE, FALSE, 0);
47 
48  if (callback)
49  {
50  g_signal_connect(GTK_TOGGLE_BUTTON(new_radio_button), "toggled", G_CALLBACK(callback),
51  callback_data);
52  }
53 
54  g_object_set_data(G_OBJECT(new_radio_button), "value", GINT_TO_POINTER(value));
55 
56  return new_radio_button;
57 }
58 
59 gint rh_get_active_value(GtkWidget *radio_button)
60 {
61  gint active_value = -1;
62  GSList *radio_button_list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button));
63 
64  gint i = 0;
65  for(i = 0; i < g_slist_length(radio_button_list);i++)
66  {
67  GtkRadioButton *current_radio = (GtkRadioButton *) g_slist_nth_data(radio_button_list, i);
68  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(current_radio)))
69  {
70  active_value = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(current_radio), "value"));
71  break;
72  }
73  }
74 
75  return active_value;
76 }
77 
78 GtkWidget *rh_get_radio_from_value(GtkWidget *radio_button, gint value)
79 {
80  GtkWidget *radio = NULL;
81  GSList *radio_button_list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button));
82 
83  gint i = 0;
84  for(i = 0; i < g_slist_length(radio_button_list);i++)
85  {
86  GtkRadioButton *current_radio = (GtkRadioButton *) g_slist_nth_data(radio_button_list, i);
87  gint current_value = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(current_radio), "value"));
88  if (current_value == value)
89  {
90  radio = GTK_WIDGET(current_radio);
91  break;
92  }
93  }
94 
95  return radio;
96 }
97