[gnac/devel] Code refactoring



commit ec632c438f4d9e7907487ad77dfb2d80024ab059
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Wed Dec 28 18:57:55 2011 +0100

    Code refactoring

 src/profiles/formats/gnac-profiles-lame.c    |    8 +--
 src/profiles/formats/gnac-profiles-speex.c   |    4 +-
 src/profiles/formats/gnac-profiles-vorbis.c  |    2 +-
 src/profiles/formats/gnac-profiles-wavpack.c |    2 +-
 src/profiles/gnac-profiles-utils.c           |   78 ++++++++++----------------
 src/profiles/gnac-profiles-utils.h           |    5 +-
 6 files changed, 38 insertions(+), 61 deletions(-)
---
diff --git a/src/profiles/formats/gnac-profiles-lame.c b/src/profiles/formats/gnac-profiles-lame.c
index 2de0a74..d004977 100755
--- a/src/profiles/formats/gnac-profiles-lame.c
+++ b/src/profiles/formats/gnac-profiles-lame.c
@@ -371,20 +371,18 @@ gnac_profiles_lame_fullfill_fields(gpointer data)
   {
     gnac_profiles_utils_set_values(&lame_bfi,
         "slider-mean-abr", profile->mean_abr, NULL);
-    gnac_profiles_utils_set_values_checked_combo(&lame_bfi,
+    gnac_profiles_utils_set_values_checked(&lame_bfi,
         "combo-min-vbr", "checkbutton-min-bitrate", profile->min_bitrate,
         "combo-max-vbr", "checkbutton-max-bitrate", profile->max_bitrate,
-        NULL );
+        NULL);
   }
   else if (profile->quality != -1)
   {
     gnac_profiles_utils_set_values(&lame_bfi,
         "slider-vbr-quality", profile->quality, NULL);
-    gnac_profiles_utils_set_values_checked_combo(&lame_bfi,
+    gnac_profiles_utils_set_values_checked(&lame_bfi,
         "combo-min-vbr", "checkbutton-min-bitrate", profile->min_bitrate,
         "combo-max-vbr", "checkbutton-max-bitrate", profile->max_bitrate,
-        NULL );
-    gnac_profiles_utils_set_values_checked_slider(&lame_bfi,
         "slider-mean-vbr", "checkbutton-mean-bitrate", profile->mean_bitrate,
         NULL);
   }
diff --git a/src/profiles/formats/gnac-profiles-speex.c b/src/profiles/formats/gnac-profiles-speex.c
index 337b1d7..e711c8f 100644
--- a/src/profiles/formats/gnac-profiles-speex.c
+++ b/src/profiles/formats/gnac-profiles-speex.c
@@ -342,7 +342,7 @@ gnac_profiles_speex_fullfill_fields(gpointer data)
 
   AudioProfileSpeex *profile = (AudioProfileSpeex *) data;
   gnac_profiles_default_init_fields(profile->generic, &speex_bfi);
-  gnac_profiles_utils_set_values_checked_slider(&speex_bfi,
+  gnac_profiles_utils_set_values_checked(&speex_bfi,
       "slider-complexity", "checkbutton-complexity",
       profile->complexity, NULL);
   gnac_profiles_utils_set_values(&speex_bfi,
@@ -359,7 +359,7 @@ gnac_profiles_speex_fullfill_fields(gpointer data)
         "slider-bitrate-cbr", profile->bitrate_cbr, NULL);
 
     if (profile->bitrate_cbr != 1) {
-      gnac_profiles_utils_set_values_checked_slider(&speex_bfi,
+      gnac_profiles_utils_set_values_checked(&speex_bfi,
           "slider-bitrate-cbr", "checkbutton-bitrate-cbr",
           profile->bitrate_cbr, NULL);
     }
diff --git a/src/profiles/formats/gnac-profiles-vorbis.c b/src/profiles/formats/gnac-profiles-vorbis.c
index b387947..fefb724 100755
--- a/src/profiles/formats/gnac-profiles-vorbis.c
+++ b/src/profiles/formats/gnac-profiles-vorbis.c
@@ -231,7 +231,7 @@ gnac_profiles_vorbis_fullfill_fields(gpointer data)
   } else {
     gnac_profiles_utils_set_values(&vorbis_bfi,
         "slider-quality", profile->quality, NULL);
-    gnac_profiles_utils_set_values_checked_combo(&vorbis_bfi,
+    gnac_profiles_utils_set_values_checked(&vorbis_bfi,
         "combo-min-vbr", "checkbutton-min-bitrate", profile->min_bitrate,
         "combo-max-vbr", "checkbutton-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 e0d13d9..ac430d5 100644
--- a/src/profiles/formats/gnac-profiles-wavpack.c
+++ b/src/profiles/formats/gnac-profiles-wavpack.c
@@ -280,7 +280,7 @@ gnac_profiles_wavpack_fullfill_fields(gpointer data)
       "combo-mode", profile->mode,
       "slider-extra-processing", profile->extra_processing,
       "checkbutton-md5", profile->md5, NULL);
-  gnac_profiles_utils_set_values_checked_combo(&wavpack_bfi,
+  gnac_profiles_utils_set_values_checked(&wavpack_bfi,
       "combo-joint-stereo-mode", "checkbutton-joint-stereo-mode",
       profile->joint_stereo_mode, NULL);
 
diff --git a/src/profiles/gnac-profiles-utils.c b/src/profiles/gnac-profiles-utils.c
index add6cbc..983a049 100755
--- a/src/profiles/gnac-profiles-utils.c
+++ b/src/profiles/gnac-profiles-utils.c
@@ -284,29 +284,42 @@ gnac_profiles_utils_reset_values(BasicFormatInfo *bfi, ...)
 
 
 void
-gnac_profiles_utils_set_values_checked_combo(BasicFormatInfo *bfi, ...)
+gnac_profiles_utils_set_values_checked(BasicFormatInfo *bfi, ...)
 {
   va_list      ap;
-  const gchar *name_combo;
-  const gchar *name_checkbox;
-  const gchar *value;
+  const gchar *widget_name;
+  const gchar *checkbox_name;
 
   va_start(ap, bfi);
-  name_combo = va_arg(ap, const gchar *);
-
-  while (name_combo) {
-    name_checkbox = va_arg(ap, const gchar *);
-    value = va_arg(ap, const gchar *);
-    
-    if (value) {
-      GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name_combo);
-      gnac_profiles_utils_set_value_combo(widget, value);
+  widget_name = va_arg(ap, const gchar *);
+
+  while (widget_name) {
+    checkbox_name = va_arg(ap, const gchar *);
+
+    gboolean active = FALSE;
+    GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, widget_name);
+
+    if (GTK_IS_COMBO_BOX(widget)) {
+      const gchar *value = va_arg(ap, const gchar *);
+      if (value) {
+        active = TRUE;
+        gnac_profiles_utils_set_value_combo(widget, value);
+      }
+    } else if (GTK_IS_RANGE(widget)) {
+      gdouble value = va_arg(ap, gdouble);
+      if (value != -1) {
+        active = TRUE;
+        gtk_range_set_value(GTK_RANGE(widget), value);
+      }
+    } else {
+      libgnac_debug("Unhandled widget type: %s",
+          g_type_name(G_OBJECT_TYPE(widget)));
     }
-    
-    GtkWidget *widget = gnac_profiles_utils_get_widget(bfi, name_checkbox);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), value != NULL);
 
-    name_combo = va_arg(ap, const gchar *);
+    widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), active);
+
+    widget_name = va_arg(ap, const gchar *);
   }
 
   va_end(ap);
@@ -374,37 +387,6 @@ gnac_profiles_utils_get_values_checked_combo_and_set(BasicFormatInfo *bfi, ...)
 
 
 void
-gnac_profiles_utils_set_values_checked_slider(BasicFormatInfo *bfi, ...)
-{
-  GtkWidget   *widget;
-  va_list      ap;
-  const gchar *name;
-  const gchar *checkbox_name;
-  gdouble      value;
-
-  va_start(ap, bfi);
-  name = va_arg(ap, const gchar *);
-
-  while (name) {
-    checkbox_name = va_arg(ap, const gchar *); 
-    value = va_arg(ap, gdouble);
-
-    if (value != -1) {
-      widget = gnac_profiles_utils_get_widget(bfi, name);
-      gtk_range_set_value(GTK_RANGE(widget), value);
-    }
-
-    widget = gnac_profiles_utils_get_widget(bfi, checkbox_name);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), (value != -1));
-
-    name = va_arg(ap, const gchar *);
-  }
-
-  va_end(ap);
-}
-
-
-void
 gnac_profiles_utils_get_values_slider_and_set(BasicFormatInfo *bfi, ...)
 {
   GtkWidget   *widget;
diff --git a/src/profiles/gnac-profiles-utils.h b/src/profiles/gnac-profiles-utils.h
index df0a434..c62918f 100755
--- a/src/profiles/gnac-profiles-utils.h
+++ b/src/profiles/gnac-profiles-utils.h
@@ -94,7 +94,7 @@ void
 gnac_profiles_utils_set_values(BasicFormatInfo *bfi, ...);
 
 void
-gnac_profiles_utils_set_values_checked_combo(BasicFormatInfo *bfi, ...);
+gnac_profiles_utils_set_values_checked(BasicFormatInfo *bfi, ...);
 
 gchar *
 gnac_profiles_utils_get_value_combo(GtkWidget *combo);
@@ -106,9 +106,6 @@ void
 gnac_profiles_utils_get_values_checked_combo_and_set(BasicFormatInfo *bfi, ...);
 
 void
-gnac_profiles_utils_set_values_checked_slider(BasicFormatInfo *bfi, ...);
-
-void
 gnac_profiles_utils_get_values_slider_and_set(BasicFormatInfo *bfi, ...);
 
 void



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