[gnac/devel] Code refactoring
- From: BenoÃt Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/devel] Code refactoring
- Date: Thu, 29 Dec 2011 10:57:27 +0000 (UTC)
commit f966c19f7cf2db51898bb7febfc75da8087839fb
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Thu Dec 29 09:33:54 2011 +0100
Code refactoring
src/profiles/formats/gnac-profiles-aac.c | 7 +-
src/profiles/formats/gnac-profiles-flac.c | 2 +-
src/profiles/formats/gnac-profiles-lame.c | 9 +-
src/profiles/formats/gnac-profiles-speex.c | 12 +-
src/profiles/formats/gnac-profiles-vorbis.c | 5 +-
src/profiles/formats/gnac-profiles-wavpack.c | 8 +-
src/profiles/gnac-profiles-default.c | 2 +-
src/profiles/gnac-profiles-utils.c | 235 +++++++++-----------------
src/profiles/gnac-profiles-utils.h | 8 +-
9 files changed, 101 insertions(+), 187 deletions(-)
---
diff --git a/src/profiles/formats/gnac-profiles-aac.c b/src/profiles/formats/gnac-profiles-aac.c
index 3eef9b0..b5169be 100755
--- a/src/profiles/formats/gnac-profiles-aac.c
+++ b/src/profiles/formats/gnac-profiles-aac.c
@@ -235,10 +235,9 @@ static void
gnac_profiles_aac_clean_up(void)
{
gnac_profiles_default_clean_up(&aac_bfi);
- gnac_profiles_utils_free_combo_values(&aac_bfi,
- "combo-bitrate", "combo-outputformat", "combo-profile", NULL);
- gnac_profiles_utils_free_check_values(&aac_bfi,
- "checkbutton-tns", NULL);
+ gnac_profiles_utils_free_values(&aac_bfi,
+ "combo-bitrate", "combo-outputformat",
+ "combo-profile", "checkbutton-tns", NULL);
gnac_profiles_utils_free_basic_format_info_content(&aac_bfi);
}
diff --git a/src/profiles/formats/gnac-profiles-flac.c b/src/profiles/formats/gnac-profiles-flac.c
index b1dcffa..6a7ff5d 100755
--- a/src/profiles/formats/gnac-profiles-flac.c
+++ b/src/profiles/formats/gnac-profiles-flac.c
@@ -189,7 +189,7 @@ static void
gnac_profiles_flac_clean_up(void)
{
gnac_profiles_default_clean_up(&flac_bfi);
- gnac_profiles_utils_free_slider_values(&flac_bfi, "slider-compression", NULL);
+ gnac_profiles_utils_free_values(&flac_bfi, "slider-compression", NULL);
gnac_profiles_utils_free_basic_format_info_content(&flac_bfi);
}
diff --git a/src/profiles/formats/gnac-profiles-lame.c b/src/profiles/formats/gnac-profiles-lame.c
index d004977..677bceb 100755
--- a/src/profiles/formats/gnac-profiles-lame.c
+++ b/src/profiles/formats/gnac-profiles-lame.c
@@ -611,12 +611,11 @@ static void
gnac_profiles_lame_clean_up(void)
{
gnac_profiles_default_clean_up(&lame_bfi);
- gnac_profiles_utils_free_combo_values(&lame_bfi,
+ gnac_profiles_utils_free_values(&lame_bfi,
"combo-mode", "combo-bitrate", "combo-min-vbr", "combo-max-vbr",
- "combo-preset", "combo-encoding-mode", NULL);
- gnac_profiles_utils_free_slider_values(&lame_bfi,
- "slider-vbr-quality", "slider-compression-ratio",
- "slider-mean-vbr", "slider-mean-abr", NULL);
+ "combo-preset", "combo-encoding-mode", "slider-vbr-quality",
+ "slider-compression-ratio", "slider-mean-vbr", "slider-mean-abr",
+ NULL);
gnac_profiles_utils_free_basic_format_info_content(&lame_bfi);
}
diff --git a/src/profiles/formats/gnac-profiles-speex.c b/src/profiles/formats/gnac-profiles-speex.c
index e711c8f..5430d2a 100644
--- a/src/profiles/formats/gnac-profiles-speex.c
+++ b/src/profiles/formats/gnac-profiles-speex.c
@@ -590,13 +590,11 @@ static void
gnac_profiles_speex_clean_up(void)
{
gnac_profiles_default_clean_up(&speex_bfi);
- gnac_profiles_utils_free_combo_values(&speex_bfi,
- "combo-mode", "combo-bitrate-mode", NULL);
- gnac_profiles_utils_free_slider_values(&speex_bfi,
- "slider-quality-cbr", "slider-quality-vbr", "slider-bitrate-cbr",
- "slider-bitrate-abr", "slider-complexity", NULL);
- gnac_profiles_utils_free_check_values(&speex_bfi,
- "checkbutton-vad", "checkbutton-dtx", "checkbutton-vbr", NULL);
+ gnac_profiles_utils_free_values(&speex_bfi,
+ "combo-mode", "combo-bitrate-mode", "slider-quality-cbr",
+ "slider-quality-vbr", "slider-bitrate-cbr", "slider-bitrate-abr",
+ "slider-complexity", "checkbutton-vad", "checkbutton-dtx",
+ "checkbutton-vbr", NULL);
gnac_profiles_utils_free_basic_format_info_content(&speex_bfi);
}
diff --git a/src/profiles/formats/gnac-profiles-vorbis.c b/src/profiles/formats/gnac-profiles-vorbis.c
index fefb724..467c20f 100755
--- a/src/profiles/formats/gnac-profiles-vorbis.c
+++ b/src/profiles/formats/gnac-profiles-vorbis.c
@@ -359,10 +359,9 @@ static void
gnac_profiles_vorbis_clean_up(void)
{
gnac_profiles_default_clean_up(&vorbis_bfi);
- gnac_profiles_utils_free_combo_values(&vorbis_bfi,
+ gnac_profiles_utils_free_values(&vorbis_bfi,
"combo-bitrate", "combo-min-vbr", "combo-max-vbr",
- "combo-encoding-mode", NULL);
- gnac_profiles_utils_free_slider_values(&vorbis_bfi, "slider-quality", NULL);
+ "combo-encoding-mode", "slider-quality", NULL);
gnac_profiles_utils_free_basic_format_info_content(&vorbis_bfi);
}
diff --git a/src/profiles/formats/gnac-profiles-wavpack.c b/src/profiles/formats/gnac-profiles-wavpack.c
index ac430d5..109e109 100644
--- a/src/profiles/formats/gnac-profiles-wavpack.c
+++ b/src/profiles/formats/gnac-profiles-wavpack.c
@@ -466,11 +466,9 @@ static void
gnac_profiles_wavpack_clean_up(void)
{
gnac_profiles_default_clean_up(&wavpack_bfi);
- gnac_profiles_utils_free_combo_values(&wavpack_bfi,
- "combo-bitrate-control", "combo-mode", "combo-joint-stereo-mode", NULL);
- gnac_profiles_utils_free_check_values(&wavpack_bfi, "checkbutton-md5", NULL);
- gnac_profiles_utils_free_slider_values(&wavpack_bfi,
- "slider-bitrate", "slider-bits-per-sample",
+ gnac_profiles_utils_free_values(&wavpack_bfi,
+ "combo-bitrate-control", "combo-mode", "combo-joint-stereo-mode",
+ "checkbutton-md5", "slider-bitrate", "slider-bits-per-sample",
"slider-extra-processing", NULL);
gnac_profiles_utils_free_basic_format_info_content(&wavpack_bfi);
}
diff --git a/src/profiles/gnac-profiles-default.c b/src/profiles/gnac-profiles-default.c
index c52203c..08663d2 100755
--- a/src/profiles/gnac-profiles-default.c
+++ b/src/profiles/gnac-profiles-default.c
@@ -232,6 +232,6 @@ gnac_profiles_default_clean_up(BasicFormatInfo *bfi)
widget = gnac_profiles_default_get_properties_alignment(bfi);
gtk_widget_destroy(widget);
- gnac_profiles_utils_free_combo_values(bfi,
+ gnac_profiles_utils_free_values(bfi,
"combo-channels", "combo-sample-rate", NULL);
}
diff --git a/src/profiles/gnac-profiles-utils.c b/src/profiles/gnac-profiles-utils.c
index 983a049..e0a4695 100755
--- a/src/profiles/gnac-profiles-utils.c
+++ b/src/profiles/gnac-profiles-utils.c
@@ -201,7 +201,6 @@ void
gnac_profiles_utils_set_values(BasicFormatInfo *bfi, ...)
{
va_list ap;
-
va_start(ap, bfi);
const gchar *name = va_arg(ap, const gchar *);
@@ -258,8 +257,8 @@ void
gnac_profiles_utils_reset_values(BasicFormatInfo *bfi, ...)
{
va_list ap;
-
va_start(ap, bfi);
+
const gchar *name = va_arg(ap, const gchar *);
while (name) {
@@ -286,17 +285,14 @@ gnac_profiles_utils_reset_values(BasicFormatInfo *bfi, ...)
void
gnac_profiles_utils_set_values_checked(BasicFormatInfo *bfi, ...)
{
- va_list ap;
- const gchar *widget_name;
- const gchar *checkbox_name;
-
+ va_list ap;
va_start(ap, bfi);
- widget_name = va_arg(ap, const gchar *);
- while (widget_name) {
- checkbox_name = va_arg(ap, const gchar *);
+ const gchar *widget_name = va_arg(ap, const gchar *);
+ while (widget_name) {
gboolean active = FALSE;
+ const gchar *checkbox_name = va_arg(ap, const gchar *);
GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, widget_name);
if (GTK_IS_COMBO_BOX(widget)) {
@@ -338,17 +334,14 @@ gnac_profiles_utils_get_value_combo(GtkWidget *combo)
void
gnac_profiles_utils_get_values_combo_and_set(BasicFormatInfo *bfi, ...)
{
- GtkWidget *widget;
- va_list ap;
- const gchar *name;
- gchar **value;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- value = va_arg(ap, gchar **);
- widget = gnac_profiles_utils_get_widget(bfi, name);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name);
+ gchar **value = va_arg(ap, gchar **);
*value = gnac_profiles_utils_get_value_combo(widget);
name = va_arg(ap, const gchar *);
}
@@ -360,19 +353,15 @@ gnac_profiles_utils_get_values_combo_and_set(BasicFormatInfo *bfi, ...)
void
gnac_profiles_utils_get_values_checked_combo_and_set(BasicFormatInfo *bfi, ...)
{
- GtkWidget *widget;
- va_list ap;
- const gchar *name;
- const gchar *checkbox_name;
- const gchar **value;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- checkbox_name = va_arg(ap, const gchar *);
- value = va_arg(ap, const gchar **);
- widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
+ const gchar *checkbox_name = va_arg(ap, const gchar *);
+ const gchar **value = va_arg(ap, const gchar **);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
widget = gnac_profiles_utils_get_widget(bfi, name);
@@ -389,17 +378,14 @@ gnac_profiles_utils_get_values_checked_combo_and_set(BasicFormatInfo *bfi, ...)
void
gnac_profiles_utils_get_values_slider_and_set(BasicFormatInfo *bfi, ...)
{
- GtkWidget *widget;
- va_list ap;
- const gchar *name;
- gdouble *value;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- value = va_arg(ap, gdouble *);
- widget = gnac_profiles_utils_get_widget(bfi, name);
+ gdouble *value = va_arg(ap, gdouble *);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name);
*value = gtk_range_get_value(GTK_RANGE(widget));
name = va_arg(ap, const gchar *);
}
@@ -411,19 +397,15 @@ gnac_profiles_utils_get_values_slider_and_set(BasicFormatInfo *bfi, ...)
void
gnac_profiles_utils_get_values_checked_slider_and_set(BasicFormatInfo *bfi, ...)
{
- GtkWidget *widget;
- va_list ap;
- const gchar *name;
- const gchar *checkbox_name;
- gdouble *value;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- checkbox_name = va_arg(ap, const gchar *);
- value = va_arg(ap, gdouble *);
- widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
+ const gchar *checkbox_name = va_arg(ap, const gchar *);
+ gdouble *value = va_arg(ap, gdouble *);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
widget = gnac_profiles_utils_get_widget(bfi, name);
@@ -440,17 +422,14 @@ gnac_profiles_utils_get_values_checked_slider_and_set(BasicFormatInfo *bfi, ...)
void
gnac_profiles_utils_get_values_check_and_set(BasicFormatInfo *bfi, ...)
{
- GtkWidget *widget;
- va_list ap;
- const gchar *name;
- const gchar **value;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- value = va_arg(ap, const gchar **);
- widget = gnac_profiles_utils_get_widget(bfi, name);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name);
+ const gchar **value = va_arg(ap, const gchar **);
*value = g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) ?
"true" : "false");
name = va_arg(ap, const gchar *);
@@ -473,10 +452,9 @@ gnac_profiles_utils_add_description_tooltip(BasicFormatInfo *bfi,
}
va_list ap;
- GtkWidget *widget;
-
va_start(ap, xpath_query);
- widget = va_arg(ap, GtkWidget *);
+
+ GtkWidget *widget = va_arg(ap, GtkWidget *);
while (widget) {
gtk_widget_set_tooltip_markup(widget, description);
@@ -514,13 +492,11 @@ gnac_profiles_utils_get_basepipeline(const gchar *channels,
gchar *
-gnac_profiles_utils_add_pipe(gchar *pipeline,
+gnac_profiles_utils_add_pipe(gchar *pipeline,
const gchar *new_pipe)
{
gchar *temp = g_strconcat(pipeline, " ! ", new_pipe, NULL);
-
g_free(pipeline);
-
return temp;
}
@@ -577,15 +553,13 @@ gnac_profiles_utils_add_properties_combo(gchar *pipeline,
BasicFormatInfo *bfi,
...)
{
- GtkWidget *widget;
- va_list ap;
- const gchar *name;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- widget = gnac_profiles_utils_get_widget(bfi, name);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name);
pipeline = gnac_profiles_utils_add_property_combo(pipeline, widget);
name = va_arg(ap, const gchar *);
}
@@ -601,17 +575,14 @@ gnac_profiles_utils_add_properties_checked_combo(gchar *pipeline,
BasicFormatInfo *bfi,
...)
{
- GtkWidget *widget;
- va_list ap;
- const gchar *name;
- const gchar *checkbox_name;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- checkbox_name = va_arg(ap, const gchar *);
- widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
+ const gchar *checkbox_name = va_arg(ap, const gchar *);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
widget = gnac_profiles_utils_get_widget(bfi, name);
@@ -655,15 +626,13 @@ gnac_profiles_utils_add_properties_slider(gchar *pipeline,
const gchar *format,
...)
{
- GtkWidget *widget;
- va_list ap;
- const gchar *name;
-
+ va_list ap;
va_start(ap, format);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- widget = gnac_profiles_utils_get_widget(bfi, name);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name);
pipeline = gnac_profiles_utils_add_property_slider(pipeline, format, 1,
widget);
name = va_arg(ap, const gchar *);
@@ -680,17 +649,14 @@ gnac_profiles_utils_add_properties_checked_slider(gchar *pipeline,
BasicFormatInfo *bfi,
...)
{
- GtkWidget *widget;
- va_list ap;
- const gchar *name;
- const gchar *checkbox_name;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- checkbox_name = va_arg(ap, const gchar *);
- widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
+ const gchar *checkbox_name = va_arg(ap, const gchar *);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
widget = gnac_profiles_utils_get_widget(bfi, name);
@@ -731,11 +697,10 @@ gnac_profiles_utils_add_properties_check(gchar *pipeline,
BasicFormatInfo *bfi,
...)
{
- va_list ap;
- const gchar *name;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
pipeline = gnac_profiles_utils_add_property_check(bfi, name, pipeline);
@@ -753,14 +718,13 @@ gnac_profiles_utils_set_active_toggle_button(BasicFormatInfo *bfi,
gboolean active,
...)
{
- GtkWidget *widget;
- va_list ap;
-
+ va_list ap;
va_start(ap, active);
+
const gchar *name = va_arg(ap, const gchar *);
while (name) {
- widget = gnac_profiles_utils_get_widget(bfi, name);
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), active);
name = va_arg(ap, const gchar *);
}
@@ -792,17 +756,14 @@ gnac_profiles_utils_load_saved_profile(XMLDoc *doc,
const gchar *base_query,
...)
{
- const gchar *spec_query;
- gchar *query;
- gchar **value;
- va_list ap;
-
+ va_list ap;
va_start(ap, base_query);
- spec_query = va_arg(ap, const gchar *);
+
+ const gchar *spec_query = va_arg(ap, const gchar *);
while (spec_query) {
- value = va_arg(ap, gchar **);
- query = g_strconcat(base_query, spec_query, NULL);
+ gchar **value = va_arg(ap, gchar **);
+ gchar *query = g_strconcat(base_query, spec_query, NULL);
*value = gnac_profiles_xml_engine_get_text_node(doc, query);
g_free(query);
spec_query = va_arg(ap, const gchar *);
@@ -868,64 +829,30 @@ gnac_profiles_utils_free_basic_format_info_content(BasicFormatInfo *bfi)
void
-gnac_profiles_utils_free_combo_values(BasicFormatInfo *bfi, ...)
+gnac_profiles_utils_free_values(BasicFormatInfo *bfi, ...)
{
- va_list ap;
- GtkWidget *widget;
- const gchar *name;
- ComboValues *values;
-
+ va_list ap;
va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
-
- while (name) {
- widget = gnac_profiles_utils_get_widget(bfi, name);
- values = g_object_get_data(G_OBJECT(widget), "combo-values");
- gnac_profiles_xml_engine_free_combo_values(values);
- name = va_arg(ap, const gchar *);
- }
-
- va_end(ap);
-}
-
-void
-gnac_profiles_utils_free_slider_values(BasicFormatInfo *bfi, ...)
-{
- va_list ap;
- GtkWidget *widget;
- const gchar *name;
- SliderValues *values;
-
- va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+ const gchar *name = va_arg(ap, const gchar *);
while (name) {
- widget = gnac_profiles_utils_get_widget(bfi, name);
- values = g_object_get_data(G_OBJECT(widget), "slider-values");
- gnac_profiles_xml_engine_free_slider_values(values);
- name = va_arg(ap, const gchar *);
- }
-
- va_end(ap);
-}
-
-
-void
-gnac_profiles_utils_free_check_values(BasicFormatInfo *bfi, ...)
-{
- va_list ap;
- GtkWidget *widget;
- const gchar *name;
- CheckValues *values;
+ GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name);
- va_start(ap, bfi);
- name = va_arg(ap, const gchar *);
+ if (GTK_IS_COMBO_BOX(widget)) {
+ ComboValues *values = g_object_get_data(G_OBJECT(widget), "combo-values");
+ gnac_profiles_xml_engine_free_combo_values(values);
+ } else if (GTK_IS_CHECK_BUTTON(widget)) {
+ CheckValues *values = g_object_get_data(G_OBJECT(widget), "check-values");
+ gnac_profiles_xml_engine_free_check_values(values);
+ } else if (GTK_IS_RANGE(widget)) {
+ SliderValues *values = g_object_get_data(G_OBJECT(widget), "slider-values");
+ gnac_profiles_xml_engine_free_slider_values(values);
+ } else {
+ libgnac_debug("Unhandled widget type: %s",
+ g_type_name(G_OBJECT_TYPE(widget)));
+ }
- while (name) {
- widget = gnac_profiles_utils_get_widget(bfi, name);
- values = g_object_get_data(G_OBJECT(widget), "check-values");
- gnac_profiles_xml_engine_free_check_values(values);
name = va_arg(ap, const gchar *);
}
diff --git a/src/profiles/gnac-profiles-utils.h b/src/profiles/gnac-profiles-utils.h
index c62918f..d391a1f 100755
--- a/src/profiles/gnac-profiles-utils.h
+++ b/src/profiles/gnac-profiles-utils.h
@@ -193,13 +193,7 @@ void
gnac_profiles_utils_free_basic_format_info_content(BasicFormatInfo *bfi);
void
-gnac_profiles_utils_free_combo_values(BasicFormatInfo *bfi, ...);
-
-void
-gnac_profiles_utils_free_slider_values(BasicFormatInfo *bfi, ...);
-
-void
-gnac_profiles_utils_free_check_values(BasicFormatInfo *bfi, ...);
+gnac_profiles_utils_free_values(BasicFormatInfo *bfi, ...);
gchar *
gnac_profiles_utils_gdouble_to_gchararray(gdouble value);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]