[gnac/devel] Code refactoring
- From: BenoÃt Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/devel] Code refactoring
- Date: Fri, 30 Dec 2011 09:31:21 +0000 (UTC)
commit 793158ab6369c53cd6fdba367511aa433add3810
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Fri Dec 30 00:49:35 2011 +0100
Code refactoring
src/profiles/formats/gnac-profiles-aac.c | 9 +--
src/profiles/formats/gnac-profiles-flac.c | 2 +-
src/profiles/formats/gnac-profiles-lame.c | 14 ++--
src/profiles/formats/gnac-profiles-speex.c | 16 ++---
src/profiles/formats/gnac-profiles-vorbis.c | 4 +-
src/profiles/formats/gnac-profiles-wavpack.c | 6 +-
src/profiles/gnac-profiles-utils.c | 83 +++++++++----------------
src/profiles/gnac-profiles-utils.h | 14 +----
src/profiles/gnac-profiles-xml-engine.c | 8 ++-
src/profiles/gnac-profiles-xml-engine.h | 4 +-
10 files changed, 63 insertions(+), 97 deletions(-)
---
diff --git a/src/profiles/formats/gnac-profiles-aac.c b/src/profiles/formats/gnac-profiles-aac.c
index 119566f..98deea7 100755
--- a/src/profiles/formats/gnac-profiles-aac.c
+++ b/src/profiles/formats/gnac-profiles-aac.c
@@ -96,10 +96,9 @@ void
gnac_profiles_aac_generate_pipeline(void)
{
gchar *pipeline = gnac_profiles_default_generate_pipeline(&aac_bfi);
- pipeline = gnac_profiles_utils_add_properties_combo(pipeline, &aac_bfi,
- "combo-bitrate", "combo-outputformat", "combo-profile", NULL);
- pipeline = gnac_profiles_utils_add_properties_check(pipeline, &aac_bfi,
- "checkbutton-tns", NULL);
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &aac_bfi,
+ "combo-bitrate", "combo-outputformat",
+ "combo-profile", "checkbutton-tns", NULL);
gnac_profiles_properties_update_textbuffer(pipeline);
@@ -196,7 +195,7 @@ gnac_profiles_aac_save_profile(gpointer data)
AudioProfileAAC *profile = (AudioProfileAAC *) data;
XMLDoc *doc = gnac_profiles_default_save_profile(profile->generic, &aac_bfi);
- gnac_profiles_utils_save_specific_properties_in_file(doc,
+ gnac_profiles_xml_engine_add_values(doc,
"bitrate", profile->bitrate,
"outputformat", profile->outputformat,
"profile", profile->profile,
diff --git a/src/profiles/formats/gnac-profiles-flac.c b/src/profiles/formats/gnac-profiles-flac.c
index 1a56e96..3e1c7d5 100755
--- a/src/profiles/formats/gnac-profiles-flac.c
+++ b/src/profiles/formats/gnac-profiles-flac.c
@@ -155,7 +155,7 @@ gnac_profiles_flac_save_profile(gpointer data)
AudioProfileFlac *profile = (AudioProfileFlac *) data;
gchar *quality = gnac_profiles_utils_gdouble_to_gchararray(profile->quality);
XMLDoc *doc = gnac_profiles_default_save_profile(profile->generic, &flac_bfi);
- gnac_profiles_utils_save_specific_properties_in_file(doc,
+ gnac_profiles_xml_engine_add_values(doc,
"quality", quality, NULL);
gnac_profiles_xml_engine_save_doc(doc, profile->generic->name);
gnac_profiles_xml_engine_free_doc_xpath(doc);
diff --git a/src/profiles/formats/gnac-profiles-lame.c b/src/profiles/formats/gnac-profiles-lame.c
index a461aea..850f453 100755
--- a/src/profiles/formats/gnac-profiles-lame.c
+++ b/src/profiles/formats/gnac-profiles-lame.c
@@ -261,18 +261,18 @@ gnac_profiles_lame_generate_pipeline(void)
EncodingMode encoding_mode = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
// Mode
- pipeline = gnac_profiles_utils_add_properties_combo(pipeline, &lame_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &lame_bfi,
"combo-mode", NULL);
switch (encoding_mode)
{
case CONSTANT_BITRATE:
- pipeline = gnac_profiles_utils_add_properties_combo(pipeline, &lame_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &lame_bfi,
"combo-encoding-mode", "combo-bitrate", NULL);
break;
case AVERAGE_BITRATE:
- pipeline = gnac_profiles_utils_add_properties_combo(pipeline, &lame_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &lame_bfi,
"combo-encoding-mode", NULL);
pipeline = gnac_profiles_utils_add_properties_slider(pipeline, &lame_bfi,
"%.0f", "slider-mean-abr", NULL);
@@ -284,7 +284,7 @@ gnac_profiles_lame_generate_pipeline(void)
break;
case VARIABLE_BITRATE:
- pipeline = gnac_profiles_utils_add_properties_combo(pipeline, &lame_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &lame_bfi,
"combo-encoding-mode", NULL);
pipeline = gnac_profiles_utils_add_properties_slider(pipeline, &lame_bfi,
"%.0f", "slider-vbr-quality", NULL);
@@ -298,12 +298,12 @@ gnac_profiles_lame_generate_pipeline(void)
break;
case PRESETS:
- pipeline = gnac_profiles_utils_add_properties_combo(pipeline, &lame_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &lame_bfi,
"combo-preset", NULL);
break;
case COMPRESSION_RATIO:
- pipeline = gnac_profiles_utils_add_properties_slider(pipeline, &lame_bfi,
+ pipeline = gnac_profiles_utils_add_properties_slider(pipeline, &lame_bfi,
"%.0f", "slider-compression-ratio", NULL);
break;
@@ -538,7 +538,7 @@ gnac_profiles_lame_save_profile(gpointer data)
}
XMLDoc *doc = gnac_profiles_default_save_profile(profile->generic, &lame_bfi);
- gnac_profiles_utils_save_specific_properties_in_file(doc,
+ gnac_profiles_xml_engine_add_values(doc,
"encoding-mode", profile->encoding_mode,
"bitrate", profile->bitrate,
"quality", quality,
diff --git a/src/profiles/formats/gnac-profiles-speex.c b/src/profiles/formats/gnac-profiles-speex.c
index 10bd2b0..f5dd839 100644
--- a/src/profiles/formats/gnac-profiles-speex.c
+++ b/src/profiles/formats/gnac-profiles-speex.c
@@ -251,12 +251,12 @@ gnac_profiles_speex_generate_pipeline(void)
"%.0f", 1024, widget);
}
- pipeline = gnac_profiles_utils_add_properties_check(pipeline, &speex_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &speex_bfi,
"checkbutton-vad", NULL);
widget = gnac_profiles_utils_get_widget(&speex_bfi, "checkbutton-vad");
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
- pipeline = gnac_profiles_utils_add_properties_check(pipeline,
+ pipeline = gnac_profiles_utils_add_properties(pipeline,
&speex_bfi, "checkbutton-dtx", NULL);
}
break;
@@ -265,23 +265,21 @@ gnac_profiles_speex_generate_pipeline(void)
widget = gnac_profiles_utils_get_widget(&speex_bfi, "slider-bitrate-abr");
pipeline = gnac_profiles_utils_add_property_slider(pipeline,
"%.0f", 1024, widget);
- pipeline = gnac_profiles_utils_add_properties_check(pipeline, &speex_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &speex_bfi,
"checkbutton-dtx", NULL);
break;
case VARIABLE_BITRATE:
pipeline = gnac_profiles_utils_add_properties_slider(pipeline,
&speex_bfi, "%.2f", "slider-quality-vbr", NULL);
- pipeline = gnac_profiles_utils_add_properties_check(pipeline, &speex_bfi,
- "checkbutton-vbr", NULL);
- pipeline = gnac_profiles_utils_add_properties_check(pipeline, &speex_bfi,
- "checkbutton-dtx", NULL);
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &speex_bfi,
+ "checkbutton-vbr", "checkbutton-dtx", NULL);
break;
}
pipeline = gnac_profiles_utils_add_properties_checked_slider(pipeline,
&speex_bfi, "slider-complexity", "checkbutton-complexity", NULL);
- pipeline = gnac_profiles_utils_add_properties_combo(pipeline, &speex_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &speex_bfi,
"combo-mode", NULL);
pipeline = gnac_profiles_utils_add_pipe(pipeline,
speex_bfi.pipeline_multiplexers);
@@ -512,7 +510,7 @@ gnac_profiles_speex_save_profile(gpointer data)
}
XMLDoc *doc = gnac_profiles_default_save_profile(profile->generic, &speex_bfi);
- gnac_profiles_utils_save_specific_properties_in_file(doc,
+ gnac_profiles_xml_engine_add_values(doc,
"bitrate-cbr", bitrate_cbr, "quality-cbr", quality_cbr,
"bitrate-abr", bitrate_abr, "quality-vbr", quality_vbr,
"mode", profile->mode, "complexity", complexity,
diff --git a/src/profiles/formats/gnac-profiles-vorbis.c b/src/profiles/formats/gnac-profiles-vorbis.c
index f52b501..2cf8353 100755
--- a/src/profiles/formats/gnac-profiles-vorbis.c
+++ b/src/profiles/formats/gnac-profiles-vorbis.c
@@ -168,7 +168,7 @@ gnac_profiles_vorbis_generate_pipeline(void)
EncodingMode encoding_mode = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
if (encoding_mode == CONSTANT_BITRATE) {
- pipeline = gnac_profiles_utils_add_properties_combo(pipeline,
+ pipeline = gnac_profiles_utils_add_properties(pipeline,
&vorbis_bfi, "combo-bitrate", NULL);
} else if (encoding_mode == VARIABLE_BITRATE) {
pipeline = gnac_profiles_utils_add_properties_slider(pipeline,
@@ -319,7 +319,7 @@ gnac_profiles_vorbis_save_profile(gpointer data)
gchar *quality = gnac_profiles_utils_gdouble_to_gchararray_format(
profile->quality, "%.1f");
XMLDoc *doc = gnac_profiles_default_save_profile(profile->generic, &vorbis_bfi);
- gnac_profiles_utils_save_specific_properties_in_file(doc,
+ gnac_profiles_xml_engine_add_values(doc,
"quality", quality, "bitrate", profile->bitrate,
"min-bitrate", profile->min_bitrate,
"max-bitrate", profile->max_bitrate, NULL);
diff --git a/src/profiles/formats/gnac-profiles-wavpack.c b/src/profiles/formats/gnac-profiles-wavpack.c
index 01d91c2..f1cac83 100644
--- a/src/profiles/formats/gnac-profiles-wavpack.c
+++ b/src/profiles/formats/gnac-profiles-wavpack.c
@@ -189,7 +189,7 @@ gnac_profiles_wavpack_generate_pipeline(void)
GtkWidget *widget = gnac_profiles_utils_get_widget(&wavpack_bfi,
"combo-bitrate-control");
- pipeline = gnac_profiles_utils_add_properties_combo(pipeline, &wavpack_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &wavpack_bfi,
"combo-mode", NULL);
pipeline = gnac_profiles_utils_add_properties_slider(pipeline, &wavpack_bfi,
"%.0f", "slider-extra-processing", NULL);
@@ -197,7 +197,7 @@ gnac_profiles_wavpack_generate_pipeline(void)
&wavpack_bfi,
"combo-joint-stereo-mode", "checkbutton-joint-stereo-mode",
NULL);
- pipeline = gnac_profiles_utils_add_properties_check(pipeline, &wavpack_bfi,
+ pipeline = gnac_profiles_utils_add_properties(pipeline, &wavpack_bfi,
"checkbutton-md5", NULL);
GtkWidget *check = gnac_profiles_utils_get_widget(&wavpack_bfi,
"checkbutton-bitrate-control");
@@ -406,7 +406,7 @@ gnac_profiles_wavpack_save_profile(gpointer data)
XMLDoc *doc = gnac_profiles_default_save_profile(profile->generic,
&wavpack_bfi);
- gnac_profiles_utils_save_specific_properties_in_file(doc,
+ gnac_profiles_xml_engine_add_values(doc,
"mode", profile->mode,
"bitrate", bitrate,
"bits-per-sample", bits_per_sample,
diff --git a/src/profiles/gnac-profiles-utils.c b/src/profiles/gnac-profiles-utils.c
index e14126e..9bea5a9 100755
--- a/src/profiles/gnac-profiles-utils.c
+++ b/src/profiles/gnac-profiles-utils.c
@@ -523,10 +523,27 @@ gnac_profiles_utils_add_property_combo(gchar *pipeline,
}
+static gchar *
+gnac_profiles_utils_add_property_check(gchar *pipeline,
+ GtkWidget *widget)
+{
+ gboolean checked = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+ CheckValues *values = g_object_get_data(G_OBJECT(widget), "check-values");
+ if (!values) return pipeline;
+
+ gchar *temp = g_strconcat(pipeline, " ",
+ values->variable_name, "=", checked ? "true" : "false", NULL);
+
+ g_free(pipeline);
+
+ return temp;
+}
+
+
gchar *
-gnac_profiles_utils_add_properties_combo(gchar *pipeline,
- BasicFormatInfo *bfi,
- ...)
+gnac_profiles_utils_add_properties(gchar *pipeline,
+ BasicFormatInfo *bfi,
+ ...)
{
va_list ap;
va_start(ap, bfi);
@@ -535,7 +552,16 @@ gnac_profiles_utils_add_properties_combo(gchar *pipeline,
while (name) {
GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name);
- pipeline = gnac_profiles_utils_add_property_combo(pipeline, widget);
+
+ if (GTK_IS_COMBO_BOX(widget)) {
+ pipeline = gnac_profiles_utils_add_property_combo(pipeline, widget);
+ } else if (GTK_IS_CHECK_BUTTON(widget)) {
+ pipeline = gnac_profiles_utils_add_property_check(pipeline, widget);
+ } else {
+ libgnac_debug("Unhandled widget type: %s",
+ g_type_name(G_OBJECT_TYPE(widget)));
+ }
+
name = va_arg(ap, const gchar *);
}
@@ -648,46 +674,6 @@ gnac_profiles_utils_add_properties_checked_slider(gchar *pipeline,
}
-static gchar *
-gnac_profiles_utils_add_property_check(BasicFormatInfo *bfi,
- const gchar *widget_name,
- gchar *pipeline)
-{
- GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, widget_name);
- gboolean checked = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
- CheckValues *values = g_object_get_data(G_OBJECT(widget), "check-values");
- if (!values) return pipeline;
-
- gchar *temp = g_strconcat(pipeline, " ",
- values->variable_name, "=", checked ? "true" : "false", NULL);
-
- g_free(pipeline);
-
- return temp;
-}
-
-
-gchar *
-gnac_profiles_utils_add_properties_check(gchar *pipeline,
- BasicFormatInfo *bfi,
- ...)
-{
- va_list ap;
- va_start(ap, bfi);
-
- const gchar *name = va_arg(ap, const gchar *);
-
- while (name) {
- pipeline = gnac_profiles_utils_add_property_check(bfi, name, pipeline);
- name = va_arg(ap, const gchar *);
- }
-
- va_end(ap);
-
- return pipeline;
-}
-
-
void
gnac_profiles_utils_set_active_toggle_button(BasicFormatInfo *bfi,
gboolean active,
@@ -718,15 +704,6 @@ gnac_profiles_utils_on_toggle_optionnal_property(GtkToggleButton *togglebutton,
void
-gnac_profiles_utils_save_specific_properties_in_file(XMLDoc *doc, ...)
-{
- va_list ap;
- va_start(ap, doc);
- gnac_profiles_xml_engine_add_values(doc, "/audio-profile/format-specific", ap);
-}
-
-
-void
gnac_profiles_utils_load_saved_profile(XMLDoc *doc,
const gchar *base_query,
...)
diff --git a/src/profiles/gnac-profiles-utils.h b/src/profiles/gnac-profiles-utils.h
index 2ed8ec3..9e6608d 100755
--- a/src/profiles/gnac-profiles-utils.h
+++ b/src/profiles/gnac-profiles-utils.h
@@ -129,9 +129,9 @@ gnac_profiles_utils_add_pipes(gchar *pipeline,
GList *values);
gchar *
-gnac_profiles_utils_add_properties_combo(gchar *pipeline,
- BasicFormatInfo *bfi,
- ...);
+gnac_profiles_utils_add_properties(gchar *pipeline,
+ BasicFormatInfo *bfi,
+ ...);
gchar *
gnac_profiles_utils_add_properties_checked_combo(gchar *pipeline,
@@ -155,11 +155,6 @@ gnac_profiles_utils_add_properties_checked_slider(gchar *pipeline,
BasicFormatInfo *bfi,
...);
-gchar *
-gnac_profiles_utils_add_properties_check(gchar *pipeline,
- BasicFormatInfo *bfi,
- ...);
-
void
gnac_profiles_utils_set_active_toggle_button(BasicFormatInfo *bfi,
gboolean active,
@@ -170,9 +165,6 @@ gnac_profiles_utils_on_toggle_optionnal_property(GtkToggleButton *togglebutton,
gpointer user_data);
void
-gnac_profiles_utils_save_specific_properties_in_file(XMLDoc *doc, ...);
-
-void
gnac_profiles_utils_load_saved_profile(XMLDoc *doc,
const gchar *base_query,
...);
diff --git a/src/profiles/gnac-profiles-xml-engine.c b/src/profiles/gnac-profiles-xml-engine.c
index 0718ca1..fbe9851 100755
--- a/src/profiles/gnac-profiles-xml-engine.c
+++ b/src/profiles/gnac-profiles-xml-engine.c
@@ -467,10 +467,9 @@ gnac_profiles_xml_engine_modify_values(XMLDoc *doc,
void
-gnac_profiles_xml_engine_add_values(XMLDoc *doc,
- const gchar *expr,
- va_list ap)
+gnac_profiles_xml_engine_add_values(XMLDoc *doc, ...)
{
+ const gchar *expr = "/audio-profile/format-specific";
xmlXPathObjectPtr xpath_obj = gnac_profiles_xml_engine_evaluate_query(
expr, doc->xpath_context);
if (!xpath_obj) return;
@@ -487,6 +486,9 @@ gnac_profiles_xml_engine_add_values(XMLDoc *doc,
g_strconcat((const gchar *) base_indent, " ", NULL);
xmlAddChild(format_node, xmlNewText(BAD_CAST " "));
+ va_list ap;
+ va_start(ap, doc);
+
const xmlChar *name = va_arg(ap, const xmlChar *);
while (name) {
diff --git a/src/profiles/gnac-profiles-xml-engine.h b/src/profiles/gnac-profiles-xml-engine.h
index 3819fee..dcf3de5 100755
--- a/src/profiles/gnac-profiles-xml-engine.h
+++ b/src/profiles/gnac-profiles-xml-engine.h
@@ -123,9 +123,7 @@ gnac_profiles_xml_engine_modify_values(XMLDoc *doc,
...);
void
-gnac_profiles_xml_engine_add_values(XMLDoc *doc,
- const gchar *expr,
- va_list ap);
+gnac_profiles_xml_engine_add_values(XMLDoc *doc, ...);
void
gnac_profiles_xml_engine_save_doc(XMLDoc *doc,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]