[gnac/devel] Code refactoring



commit eac751797efa916d2f99f0e9cb63aa4ab6f5c041
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Fri Nov 4 16:16:33 2011 +0000

    Code refactoring

 src/profiles/formats/gnac-profiles-lame.c    |  112 ++++++++++++++++++++------
 src/profiles/formats/gnac-profiles-speex.c   |   89 +++++++++++----------
 src/profiles/formats/gnac-profiles-vorbis.c  |   59 +++++++++-----
 src/profiles/formats/gnac-profiles-wavpack.c |   48 ++++++++---
 4 files changed, 205 insertions(+), 103 deletions(-)
---
diff --git a/src/profiles/formats/gnac-profiles-lame.c b/src/profiles/formats/gnac-profiles-lame.c
index d59f280..e80f0ba 100755
--- a/src/profiles/formats/gnac-profiles-lame.c
+++ b/src/profiles/formats/gnac-profiles-lame.c
@@ -228,22 +228,47 @@ gnac_profiles_lame_init(UpdateTextBufferFunc call_back)
 
 
 static void
-gnac_profiles_lame_vbr_on_changed(GtkComboBox *widget)
+gnac_profiles_lame_show_abr_widgets(gboolean show)
 {
+  GtkWidget *abr_widgets[] = {
+    gnac_profiles_utils_get_widget(&lame_bfi, "label-mean-bitrate"),
+    gnac_profiles_utils_get_widget(&lame_bfi, "slider-mean-abr"),
+    gnac_profiles_utils_get_widget(&lame_bfi, "checkbutton-min-bitrate"),
+    gnac_profiles_utils_get_widget(&lame_bfi, "combo-min-vbr"),
+    gnac_profiles_utils_get_widget(&lame_bfi, "checkbutton-max-bitrate"),
+    gnac_profiles_utils_get_widget(&lame_bfi, "combo-max-vbr")
+  };
+
   guint i;
-  EncodingMode encoding_mode;
+  for (i = 0; i < G_N_ELEMENTS(abr_widgets); i++) {
+    if (show) gtk_widget_show_all(abr_widgets[i]);
+    else gtk_widget_hide(abr_widgets[i]);
+  }
+}
 
-  GtkWidget *widgets_tab[] = {
-    gnac_profiles_utils_get_widget(&lame_bfi, "label-vbr"),
-    gnac_profiles_utils_get_widget(&lame_bfi, "hbox-vbr"),
+
+static void
+gnac_profiles_lame_show_cbr_widgets(gboolean show)
+{
+  GtkWidget *cbr_widgets[] = {
     gnac_profiles_utils_get_widget(&lame_bfi, "label-cbr"),
     gnac_profiles_utils_get_widget(&lame_bfi, "hbox-bitrate"),
-    gnac_profiles_utils_get_widget(&lame_bfi, "label-preset"),
-    gnac_profiles_utils_get_widget(&lame_bfi, "hbox-preset"),
-    gnac_profiles_utils_get_widget(&lame_bfi, "label-compression-ratio"),
-    gnac_profiles_utils_get_widget(&lame_bfi, "slider-compression-ratio"),
-    gnac_profiles_utils_get_widget(&lame_bfi, "label-mean-bitrate"),
-    gnac_profiles_utils_get_widget(&lame_bfi, "slider-mean-abr"),
+  };
+
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(cbr_widgets); i++) {
+    if (show) gtk_widget_show_all(cbr_widgets[i]);
+    else gtk_widget_hide(cbr_widgets[i]);
+  }
+}
+
+
+static void
+gnac_profiles_lame_show_vbr_widgets(gboolean show)
+{
+  GtkWidget *vbr_widgets[] = {
+    gnac_profiles_utils_get_widget(&lame_bfi, "label-vbr"),
+    gnac_profiles_utils_get_widget(&lame_bfi, "hbox-vbr"),
     gnac_profiles_utils_get_widget(&lame_bfi, "checkbutton-mean-bitrate"),
     gnac_profiles_utils_get_widget(&lame_bfi, "slider-mean-vbr"),
     gnac_profiles_utils_get_widget(&lame_bfi, "checkbutton-min-bitrate"),
@@ -251,25 +276,62 @@ gnac_profiles_lame_vbr_on_changed(GtkComboBox *widget)
     gnac_profiles_utils_get_widget(&lame_bfi, "checkbutton-max-bitrate"),
     gnac_profiles_utils_get_widget(&lame_bfi, "combo-max-vbr")
   };
-  
-  encoding_mode = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
 
-  for (i = 0; i < G_N_ELEMENTS(widgets_tab); ++i) {
-    if ((encoding_mode == VARIABLE_BITRATE && (i >= 10 || i <= 1)) ||
-        (encoding_mode == CONSTANT_BITRATE && (i == 2 || i == 3)) ||
-        (encoding_mode == AVERAGE_BITRATE && (i > 11 || i == 8 || i == 9)) ||
-        (encoding_mode == PRESETS && (i == 4 || i == 5)) ||
-        (encoding_mode == COMPRESSION_RATIO && (i == 6 || i == 7)))
-    {
-      gtk_widget_show(widgets_tab[i]);
-    } else {
-      gtk_widget_hide(widgets_tab[i]);
-    }
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(vbr_widgets); i++) {
+    if (show) gtk_widget_show_all(vbr_widgets[i]);
+    else gtk_widget_hide(vbr_widgets[i]);
   }
 }
 
 
 static void
+gnac_profiles_lame_show_presets_widgets(gboolean show)
+{
+  GtkWidget *presets_widgets[] = {
+    gnac_profiles_utils_get_widget(&lame_bfi, "label-preset"),
+    gnac_profiles_utils_get_widget(&lame_bfi, "hbox-preset"),
+  };
+
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(presets_widgets); i++) {
+    if (show) gtk_widget_show_all(presets_widgets[i]);
+    else gtk_widget_hide(presets_widgets[i]);
+  }
+}
+
+
+static void
+gnac_profiles_lame_show_compression_ratio_widgets(gboolean show)
+{
+  GtkWidget *compression_ratio_widgets[] = {
+    gnac_profiles_utils_get_widget(&lame_bfi, "label-compression-ratio"),
+    gnac_profiles_utils_get_widget(&lame_bfi, "slider-compression-ratio"),
+  };
+
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(compression_ratio_widgets); i++) {
+    if (show) gtk_widget_show_all(compression_ratio_widgets[i]);
+    else gtk_widget_hide(compression_ratio_widgets[i]);
+  }
+}
+
+
+static void
+gnac_profiles_lame_vbr_on_changed(GtkComboBox *widget)
+{
+  EncodingMode encoding_mode = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+
+  gnac_profiles_lame_show_abr_widgets(encoding_mode == AVERAGE_BITRATE);
+  gnac_profiles_lame_show_cbr_widgets(encoding_mode == CONSTANT_BITRATE);
+  gnac_profiles_lame_show_vbr_widgets(encoding_mode == VARIABLE_BITRATE);
+  gnac_profiles_lame_show_presets_widgets(encoding_mode == PRESETS);
+  gnac_profiles_lame_show_compression_ratio_widgets(
+      encoding_mode == COMPRESSION_RATIO);
+}
+
+
+static void
 gnac_profiles_lame_generate_pipeline(GtkWidget *w)
 {
   EncodingMode  encoding_mode;
diff --git a/src/profiles/formats/gnac-profiles-speex.c b/src/profiles/formats/gnac-profiles-speex.c
index 396fe30..3892b81 100644
--- a/src/profiles/formats/gnac-profiles-speex.c
+++ b/src/profiles/formats/gnac-profiles-speex.c
@@ -237,60 +237,63 @@ gnac_profiles_speex_init(UpdateTextBufferFunc call_back)
 
 
 static void
-gnac_profiles_speex_bitrate_on_changed(GtkComboBox *widget)
+gnac_profiles_speex_show_abr_widgets(gboolean show)
 {
-  
-  GtkWidget *widgets_tab[] = {
+  GtkWidget *abr_widgets[] = {
+    gnac_profiles_utils_get_widget(&speex_bfi, "label-bitrate-abr"),
+    gnac_profiles_utils_get_widget(&speex_bfi, "slider-bitrate-abr"),
+  };
+
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(abr_widgets); i++) {
+    if (show) gtk_widget_show_all(abr_widgets[i]);
+    else gtk_widget_hide(abr_widgets[i]);
+  }
+}
+
+
+static void
+gnac_profiles_speex_show_cbr_widgets(gboolean show)
+{
+  GtkWidget *cbr_widgets[] = {
     gnac_profiles_utils_get_widget(&speex_bfi, "checkbutton-bitrate-cbr"),
     gnac_profiles_utils_get_widget(&speex_bfi, "slider-bitrate-cbr"),
     gnac_profiles_utils_get_widget(&speex_bfi, "label-quality-cbr"),
     gnac_profiles_utils_get_widget(&speex_bfi, "hbox-quality-cbr"),
-    gnac_profiles_utils_get_widget(&speex_bfi, "label-bitrate-abr"),
-    gnac_profiles_utils_get_widget(&speex_bfi, "slider-bitrate-abr"),
+  };
+
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(cbr_widgets); i++) {
+    if (show) gtk_widget_show_all(cbr_widgets[i]);
+    else gtk_widget_hide(cbr_widgets[i]);
+  }
+}
+
+
+static void
+gnac_profiles_speex_show_vbr_widgets(gboolean show)
+{
+  GtkWidget *vbr_widgets[] = {
     gnac_profiles_utils_get_widget(&speex_bfi, "label-quality-vbr"),
     gnac_profiles_utils_get_widget(&speex_bfi, "hbox-quality-vbr"),
   };
-  
-  guint start_index_of_abr_widgets = 4;
-  guint start_index_of_vbr_widgets = 6;
-
-  BitrateMode bitrate_mode = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
 
   guint i;
-  for (i = 0; i < G_N_ELEMENTS(widgets_tab); i++) {
-    switch (bitrate_mode) {
-
-      case CONSTANT_BITRATE:
-        if (i < start_index_of_abr_widgets) {
-          gtk_widget_show(widgets_tab[i]);
-        } else {
-          gtk_widget_hide(widgets_tab[i]);
-        }
-        break;
-
-      case AVERAGE_BITRATE:
-        if (i >= start_index_of_abr_widgets &&
-            i < start_index_of_vbr_widgets)
-        {
-          gtk_widget_show(widgets_tab[i]);
-        } else {
-          gtk_widget_hide(widgets_tab[i]);
-        }
-        break;
-
-      case VARIABLE_BITRATE:
-        if (i >= start_index_of_vbr_widgets) {
-          gtk_widget_show(widgets_tab[i]);
-        } else {
-          gtk_widget_hide(widgets_tab[i]);
-        }
-        break;
-
-      default:
-        libgnac_debug("Unrecognised bitrate mode: %d\n", bitrate_mode);
-        break;
-    }
+  for (i = 0; i < G_N_ELEMENTS(vbr_widgets); i++) {
+    if (show) gtk_widget_show_all(vbr_widgets[i]);
+    else gtk_widget_hide(vbr_widgets[i]);
   }
+}
+
+
+static void
+gnac_profiles_speex_bitrate_on_changed(GtkComboBox *widget)
+{
+  BitrateMode bitrate_mode = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+
+  gnac_profiles_speex_show_abr_widgets(bitrate_mode == AVERAGE_BITRATE);
+  gnac_profiles_speex_show_cbr_widgets(bitrate_mode == CONSTANT_BITRATE);
+  gnac_profiles_speex_show_vbr_widgets(bitrate_mode == VARIABLE_BITRATE);
 
   gnac_profiles_speex_display_vad(bitrate_mode);
 }
diff --git a/src/profiles/formats/gnac-profiles-vorbis.c b/src/profiles/formats/gnac-profiles-vorbis.c
index 254f38c..718368c 100755
--- a/src/profiles/formats/gnac-profiles-vorbis.c
+++ b/src/profiles/formats/gnac-profiles-vorbis.c
@@ -132,6 +132,42 @@ gnac_profiles_vorbis_get_funcs(void)
 }
 
 
+static void
+gnac_profiles_vorbis_show_cbr_widgets(gboolean show)
+{
+  GtkWidget *cbr_widgets[] = {
+    gnac_profiles_utils_get_widget(&vorbis_bfi, "label-bitrate"),
+    gnac_profiles_utils_get_widget(&vorbis_bfi, "hbox-bitrate"),
+  };
+
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(cbr_widgets); i++) {
+    if (show) gtk_widget_show_all(cbr_widgets[i]);
+    else gtk_widget_hide(cbr_widgets[i]);
+  }
+}
+
+
+static void
+gnac_profiles_vorbis_show_vbr_widgets(gboolean show)
+{
+  GtkWidget *vbr_widgets[] = {
+    gnac_profiles_utils_get_widget(&vorbis_bfi, "label-quality"),
+    gnac_profiles_utils_get_widget(&vorbis_bfi, "hbox-quality"),
+    gnac_profiles_utils_get_widget(&vorbis_bfi, "checkbutton-min-bitrate"),
+    gnac_profiles_utils_get_widget(&vorbis_bfi, "checkbutton-max-bitrate"),
+    gnac_profiles_utils_get_widget(&vorbis_bfi, "combo-max-vbr"),
+    gnac_profiles_utils_get_widget(&vorbis_bfi, "combo-min-vbr")
+  };
+
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(vbr_widgets); i++) {
+    if (show) gtk_widget_show_all(vbr_widgets[i]);
+    else gtk_widget_hide(vbr_widgets[i]);
+  }
+}
+
+
 static const gchar *
 gnac_profiles_vorbis_init(UpdateTextBufferFunc call_back)
 {
@@ -188,29 +224,10 @@ gnac_profiles_vorbis_init(UpdateTextBufferFunc call_back)
 static void
 gnac_profiles_vorbis_vbr_on_changed(GtkComboBox *widget)
 {
-  GtkWidget *widgets_tab[] = {
-    gnac_profiles_utils_get_widget(&vorbis_bfi, "label-quality"),
-    gnac_profiles_utils_get_widget(&vorbis_bfi, "hbox-quality"),
-    gnac_profiles_utils_get_widget(&vorbis_bfi, "label-bitrate"),
-    gnac_profiles_utils_get_widget(&vorbis_bfi, "hbox-bitrate"),
-    gnac_profiles_utils_get_widget(&vorbis_bfi, "checkbutton-min-bitrate"),
-    gnac_profiles_utils_get_widget(&vorbis_bfi, "checkbutton-max-bitrate"),
-    gnac_profiles_utils_get_widget(&vorbis_bfi, "combo-max-vbr"),
-    gnac_profiles_utils_get_widget(&vorbis_bfi, "combo-min-vbr")
-  };
-  
   EncodingMode encoding_mode = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
 
-  guint i;
-  for (i = 0; i < G_N_ELEMENTS(widgets_tab); ++i) {
-    if ((encoding_mode == VARIABLE_BITRATE && (i >= 4 || i <= 1)) ||
-        (encoding_mode == CONSTANT_BITRATE && (i == 2 || i == 3)))
-    {
-      gtk_widget_show(widgets_tab[i]);
-    } else {
-      gtk_widget_hide(widgets_tab[i]);
-    }
-  }
+  gnac_profiles_vorbis_show_cbr_widgets(encoding_mode == CONSTANT_BITRATE);
+  gnac_profiles_vorbis_show_vbr_widgets(encoding_mode == VARIABLE_BITRATE);
 }
 
 
diff --git a/src/profiles/formats/gnac-profiles-wavpack.c b/src/profiles/formats/gnac-profiles-wavpack.c
index 6dd93b6..3b291bb 100644
--- a/src/profiles/formats/gnac-profiles-wavpack.c
+++ b/src/profiles/formats/gnac-profiles-wavpack.c
@@ -208,31 +208,51 @@ gnac_profiles_wavpack_init(UpdateTextBufferFunc call_back)
 
 
 static void
-gnac_profiles_wavpack_bitrate_control_on_changed(GtkComboBox *widget)
+gnac_profiles_wavpack_show_abr_widgets(gboolean show)
 {
-  GtkWidget *widgets_tab[] = {
+  GtkWidget *abr_widgets[] = {
     gnac_profiles_utils_get_widget(&wavpack_bfi, "label-bitrate"),
     gnac_profiles_utils_get_widget(&wavpack_bfi, "slider-bitrate"),
     gnac_profiles_utils_get_widget(&wavpack_bfi, "label-bits-per-sample"),
     gnac_profiles_utils_get_widget(&wavpack_bfi, "slider-bits-per-sample"),
   };
-  
+
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(abr_widgets); i++) {
+    if (show) gtk_widget_show_all(abr_widgets[i]);
+    else gtk_widget_hide(abr_widgets[i]);
+  }
+}
+
+
+static void
+gnac_profiles_wavpack_show_bps_widgets(gboolean show)
+{
+  GtkWidget *bps_widgets[] = {
+    gnac_profiles_utils_get_widget(&wavpack_bfi, "label-bits-per-sample"),
+    gnac_profiles_utils_get_widget(&wavpack_bfi, "slider-bits-per-sample"),
+  };
+
+  guint i;
+  for (i = 0; i < G_N_ELEMENTS(bps_widgets); i++) {
+    if (show) gtk_widget_show_all(bps_widgets[i]);
+    else gtk_widget_hide(bps_widgets[i]);
+  }
+}
+
+
+static void
+gnac_profiles_wavpack_bitrate_control_on_changed(GtkComboBox *widget)
+{
   GtkToggleButton *bitrate_ctrl_btn = GTK_TOGGLE_BUTTON(
       gnac_profiles_utils_get_widget(&wavpack_bfi, "checkbutton-bitrate-control"));
   gboolean bitrate_ctrl_enabled = gtk_toggle_button_get_active(bitrate_ctrl_btn);
   ControlMethod control_method = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
   
-  guint i;
-  for (i = 0; i < G_N_ELEMENTS(widgets_tab); ++i) {
-    if (bitrate_ctrl_enabled &&
-        ((control_method == AVERAGE_BITRATE && i < 2) ||
-         (control_method == BITS_PER_SAMPLE && i >= 2)))
-    {
-      gtk_widget_show(widgets_tab[i]);
-    } else {
-      gtk_widget_hide(widgets_tab[i]);
-    }
-  }
+  gnac_profiles_wavpack_show_abr_widgets(
+      bitrate_ctrl_enabled && control_method == AVERAGE_BITRATE);
+  gnac_profiles_wavpack_show_bps_widgets(
+      bitrate_ctrl_enabled && control_method == BITS_PER_SAMPLE);
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]