[gnac/devel] Code refactoring



commit 2871e29e046016d42a428833e9a6cd0bf62f5c9b
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Thu Dec 29 11:56:47 2011 +0100

    Code refactoring

 src/gnac-ui-utils.c                          |   11 +----
 src/gnac-ui-utils.h                          |    5 --
 src/profiles/formats/gnac-profiles-unknown.c |    5 +-
 src/profiles/formats/gnac-profiles-wav.c     |    3 +-
 src/profiles/gnac-profiles-default.c         |    5 +-
 src/profiles/gnac-profiles-manager.c         |   66 ++++++++++++-------------
 src/profiles/gnac-profiles-properties.c      |   48 +++++++-----------
 src/profiles/gnac-profiles-properties.h      |    4 +-
 src/profiles/gnac-profiles-xml-engine.c      |   36 +++++---------
 src/profiles/gnac-profiles.c                 |    4 +-
 10 files changed, 75 insertions(+), 112 deletions(-)
---
diff --git a/src/gnac-ui-utils.c b/src/gnac-ui-utils.c
index 094159f..e52c67a 100644
--- a/src/gnac-ui-utils.c
+++ b/src/gnac-ui-utils.c
@@ -205,6 +205,7 @@ gnac_ui_utils_get_widget(GtkBuilder  *builder,
   return GTK_WIDGET(object);
 }
 
+
 GtkAction *
 gnac_ui_utils_get_action(GtkBuilder  *builder,
                          const gchar *action_name)
@@ -244,13 +245,3 @@ gnac_ui_utils_set_widget_sensitive(GtkBuilder  *builder,
   GtkWidget *widget = gnac_ui_utils_get_widget(builder, widget_name);
   if (widget) gtk_widget_set_sensitive(widget, activate);
 }
-
-
-void
-gnac_ui_utils_set_widget_visible(GtkBuilder  *builder,
-                                 const gchar *widget_name,
-                                 gboolean     visible)
-{
-  GtkAction *widget = gnac_ui_utils_get_action(builder, widget_name);
-  if (widget) gtk_action_set_visible(widget, visible);
-}
diff --git a/src/gnac-ui-utils.h b/src/gnac-ui-utils.h
index b4018a9..b4a9643 100644
--- a/src/gnac-ui-utils.h
+++ b/src/gnac-ui-utils.h
@@ -97,11 +97,6 @@ gnac_ui_utils_set_widget_sensitive(GtkBuilder  *builder,
                                    const gchar *widget_name,
                                    gboolean     activate);
 
-void
-gnac_ui_utils_set_widget_visible(GtkBuilder  *builder,
-                                 const gchar *widget_name,
-                                 gboolean     visible);
-
 G_END_DECLS
 
 #endif /* GNAC_UI_UTILS_H */
diff --git a/src/profiles/formats/gnac-profiles-unknown.c b/src/profiles/formats/gnac-profiles-unknown.c
index 2ab5ff7..a8c93c9 100644
--- a/src/profiles/formats/gnac-profiles-unknown.c
+++ b/src/profiles/formats/gnac-profiles-unknown.c
@@ -206,9 +206,8 @@ gnac_profiles_unknown_save_profile(gpointer data)
 
 
 static gpointer
-gnac_profiles_unknown_load_specific_properties(
-    XMLDoc              *doc G_GNUC_UNUSED,
-    AudioProfileGeneric *generic)
+gnac_profiles_unknown_load_specific_properties(XMLDoc              *doc,
+                                               AudioProfileGeneric *generic)
 {
   return generic;
 }
diff --git a/src/profiles/formats/gnac-profiles-wav.c b/src/profiles/formats/gnac-profiles-wav.c
index 5369979..2748244 100755
--- a/src/profiles/formats/gnac-profiles-wav.c
+++ b/src/profiles/formats/gnac-profiles-wav.c
@@ -70,8 +70,9 @@ gnac_profiles_wav_generate_pipeline(void)
 
 
 static void
-gnac_profiles_wav_fullfill_fields(gpointer data G_GNUC_UNUSED)
+gnac_profiles_wav_fullfill_fields(gpointer data)
 {
+  /* nothing to do */
 }
 
 
diff --git a/src/profiles/gnac-profiles-default.c b/src/profiles/gnac-profiles-default.c
index 08663d2..102cf0e 100755
--- a/src/profiles/gnac-profiles-default.c
+++ b/src/profiles/gnac-profiles-default.c
@@ -194,9 +194,8 @@ gnac_profiles_default_save_profile(AudioProfileGeneric *profile,
 
 
 XMLDoc *
-gnac_profiles_default_load_generic_audio_profile(
-    const gchar          *filename,
-    AudioProfileGeneric **generic)
+gnac_profiles_default_load_generic_audio_profile(const gchar          *filename,
+                                                 AudioProfileGeneric **generic)
 {
   XMLDoc *doc = gnac_profiles_xml_engine_load_doc_xpath(filename);
   if (!doc) {
diff --git a/src/profiles/gnac-profiles-manager.c b/src/profiles/gnac-profiles-manager.c
index c00d072..4138037 100644
--- a/src/profiles/gnac-profiles-manager.c
+++ b/src/profiles/gnac-profiles-manager.c
@@ -361,9 +361,7 @@ gnac_profiles_mgr_populate(void)
     if (!g_file_make_directory_with_parents(dir, NULL, &error)) {
       const gchar *msg = N_("Unable to create the profiles directory");
       libgnac_warning("%s %s: %s",
-          msg,
-          _("You may not be able to save your profiles"),
-          error->message);
+          msg, _("You may not be able to save your profiles"), error->message);
       gnac_profiles_mgr_display_status_message(NULL, msg);
       g_clear_error(&error);
       return;
@@ -580,7 +578,7 @@ gnac_profiles_mgr_insert(gpointer profile)
   GtkListStore *model = GTK_LIST_STORE(
       gnac_profiles_mgr_get_object("liststore"));
   AudioProfileGeneric *generic = AUDIO_PROFILE_GET_GENERIC(profile);
-  gchar *formatted_name = gnac_profiles_properties_filter_text_for_displaying(
+  gchar *formatted_name = gnac_profiles_properties_filter_text_for_display(
       generic->name, MAX_NAME_DISPLAY_SIZE);
   GtkTreeIter iter;
 
@@ -758,14 +756,14 @@ gnac_profiles_mgr_display_status_message(const gchar *success_message,
 
 
 void
-gnac_profiles_mgr_on_drag_data_received(GtkWidget        *widget G_GNUC_UNUSED,
+gnac_profiles_mgr_on_drag_data_received(GtkWidget        *widget,
                                         GdkDragContext   *context,
-                                        gint              x G_GNUC_UNUSED,
-                                        gint              y G_GNUC_UNUSED,
+                                        gint              x,
+                                        gint              y,
                                         GtkSelectionData *selection_data,
                                         guint             info,
                                         guint             time,
-                                        gpointer          data G_GNUC_UNUSED)
+                                        gpointer          data)
 {
   gchar **uris = g_uri_list_extract_uris((const gchar *)
       gtk_selection_data_get_data(selection_data));
@@ -980,12 +978,12 @@ gnac_profiles_mgr_on_drag_profile_copied(goffset  current_num_bytes,
 
 
 void
-gnac_profiles_mgr_on_drag_data_get(GtkWidget        *widget G_GNUC_UNUSED,
-                                   GdkDragContext   *drag_context G_GNUC_UNUSED,
+gnac_profiles_mgr_on_drag_data_get(GtkWidget        *widget,
+                                   GdkDragContext   *drag_context,
                                    GtkSelectionData *data,
-                                   guint             info G_GNUC_UNUSED,
-                                   guint             time G_GNUC_UNUSED,
-                                   gpointer          user_data G_GNUC_UNUSED)
+                                   guint             info,
+                                   guint             time,
+                                   gpointer          user_data)
 {
   gchar **uris = gnac_profiles_mgr_get_selected_uris();
   gtk_selection_data_set_uris(data, uris);
@@ -1025,8 +1023,8 @@ gnac_profiles_mgr_get_selected_uris(void)
 
 
 void
-gnac_profiles_mgr_on_add(GtkWidget *widget G_GNUC_UNUSED,
-                         gpointer   data G_GNUC_UNUSED)
+gnac_profiles_mgr_on_add(GtkWidget *widget,
+                         gpointer   data)
 {
   gnac_profiles_properties_show(NULL, _("New Profile"),
       G_CALLBACK(gnac_profiles_mgr_on_new_profile));
@@ -1034,7 +1032,7 @@ gnac_profiles_mgr_on_add(GtkWidget *widget G_GNUC_UNUSED,
 
 
 static void
-gnac_profiles_mgr_on_new_profile(GtkWidget *widget G_GNUC_UNUSED,
+gnac_profiles_mgr_on_new_profile(GtkWidget *widget,
                                  gpointer   data)
 {
   gnac_profiles_mgr_insert(data); 
@@ -1043,8 +1041,8 @@ gnac_profiles_mgr_on_new_profile(GtkWidget *widget G_GNUC_UNUSED,
 
 
 void
-gnac_profiles_mgr_on_copy(GtkWidget *widget G_GNUC_UNUSED,
-                          gpointer   data G_GNUC_UNUSED)
+gnac_profiles_mgr_on_copy(GtkWidget *widget,
+                          gpointer   data)
 {
   GList *selected = gnac_profiles_mgr_get_selected_rows();
   if (!selected) return;
@@ -1113,8 +1111,8 @@ gnac_profiles_mgr_on_copy(GtkWidget *widget G_GNUC_UNUSED,
 
 
 void
-gnac_profiles_mgr_on_edit(GtkWidget *widget G_GNUC_UNUSED,
-                          gpointer   data G_GNUC_UNUSED)
+gnac_profiles_mgr_on_edit(GtkWidget *widget,
+                          gpointer   data)
 {
   GList *selected = gnac_profiles_mgr_get_selected_rows();
   if (!selected) return;
@@ -1132,7 +1130,7 @@ gnac_profiles_mgr_on_edit(GtkWidget *widget G_GNUC_UNUSED,
 
 
 static void
-gnac_profiles_mgr_on_edit_profile(GtkWidget *widget G_GNUC_UNUSED,
+gnac_profiles_mgr_on_edit_profile(GtkWidget *widget,
                                   gpointer   data)
 {
   GList *selected = gnac_profiles_mgr_get_selected_rows();
@@ -1151,7 +1149,7 @@ gnac_profiles_mgr_on_edit_profile(GtkWidget *widget G_GNUC_UNUSED,
     gnac_profiles_mgr_delete_profile_file(old_generic->name);
   }
 
-  gchar *formatted_name = gnac_profiles_properties_filter_text_for_displaying(
+  gchar *formatted_name = gnac_profiles_properties_filter_text_for_display(
       generic->name, MAX_NAME_DISPLAY_SIZE);
   gnac_profiles_mgr_set(reference,
       COL_NAME, formatted_name,
@@ -1171,8 +1169,8 @@ gnac_profiles_mgr_on_edit_profile(GtkWidget *widget G_GNUC_UNUSED,
 
 
 void
-gnac_profiles_mgr_on_remove(GtkWidget *widget G_GNUC_UNUSED,
-                            gpointer   data G_GNUC_UNUSED)
+gnac_profiles_mgr_on_remove(GtkWidget *widget,
+                            gpointer   data)
 {
   GList *selected = gnac_profiles_mgr_get_selected_rows();
   if (!selected) return;
@@ -1240,7 +1238,7 @@ gnac_profiles_mgr_on_treeselection_changed(void)
   AudioProfileGeneric *profile;
   gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
   GtkWidget *widget = gnac_profiles_mgr_get_widget("label-description-content");
-  gchar *descr = gnac_profiles_properties_filter_text_for_displaying(
+  gchar *descr = gnac_profiles_properties_filter_text_for_display(
       profile->generic->description, MAX_DESCR_DISPLAY_SIZE);
   gtk_label_set_text(GTK_LABEL(widget), descr);
 
@@ -1253,8 +1251,8 @@ gnac_profiles_mgr_on_treeselection_changed(void)
 
 
 void
-gnac_profiles_mgr_on_close(GtkWidget *widget G_GNUC_UNUSED,
-                           gpointer   data G_GNUC_UNUSED)
+gnac_profiles_mgr_on_close(GtkWidget *widget,
+                           gpointer   data)
 {
   GtkWidget *window = gnac_profiles_mgr_get_widget("profile_manager_window");
   gtk_widget_hide(window);
@@ -1263,9 +1261,9 @@ gnac_profiles_mgr_on_close(GtkWidget *widget G_GNUC_UNUSED,
 
 
 gboolean
-gnac_profiles_mgr_on_delete_event(GtkWidget *widget G_GNUC_UNUSED,
-                                  GdkEvent  *event G_GNUC_UNUSED,
-                                  gpointer   user_data G_GNUC_UNUSED)
+gnac_profiles_mgr_on_delete_event(GtkWidget *widget,
+                                  GdkEvent  *event,
+                                  gpointer   user_data)
 {
   gnac_profiles_mgr_on_close(NULL, NULL);
   return TRUE;
@@ -1273,9 +1271,9 @@ gnac_profiles_mgr_on_delete_event(GtkWidget *widget G_GNUC_UNUSED,
 
 
 gboolean
-gnac_profiles_mgr_list_on_key_pressed(GtkWidget   *widget G_GNUC_UNUSED,
+gnac_profiles_mgr_list_on_key_pressed(GtkWidget   *widget,
                                       GdkEventKey *event,
-                                      gpointer     data G_GNUC_UNUSED)
+                                      gpointer     data)
 {
   if (gnac_ui_utils_event_is_delete_key(event)) {
     gnac_profiles_mgr_on_remove(NULL, NULL);
@@ -1287,9 +1285,9 @@ gnac_profiles_mgr_list_on_key_pressed(GtkWidget   *widget G_GNUC_UNUSED,
 
 
 gboolean
-gnac_profiles_mgr_on_key_pressed(GtkWidget   *widget G_GNUC_UNUSED,
+gnac_profiles_mgr_on_key_pressed(GtkWidget   *widget,
                                  GdkEventKey *event,
-                                 gpointer     data G_GNUC_UNUSED)
+                                 gpointer     data)
 {
   if (gnac_ui_utils_event_is_escape_key(event)) {
     gnac_profiles_mgr_on_close(NULL, NULL);
diff --git a/src/profiles/gnac-profiles-properties.c b/src/profiles/gnac-profiles-properties.c
index 14a95bf..e1b25e0 100644
--- a/src/profiles/gnac-profiles-properties.c
+++ b/src/profiles/gnac-profiles-properties.c
@@ -86,12 +86,6 @@ static void
 gnac_profiles_properties_init_format(void);
 
 static void
-gnac_profiles_properties_name_set_text(const gchar *name);
-
-static void
-gnac_profiles_properties_description_set_text(const gchar *description);
-
-static void
 gnac_profiles_properties_display_status_message(const gchar *error);
 
 static gboolean
@@ -172,7 +166,7 @@ gnac_profiles_properties_init_format(void)
     g_hash_table_insert(formats, (gpointer) format_id, format_module);
     gtk_list_store_append(model, &iter);
 
-    // XXX This is a big hack to be sure that Custom Format will be at the end
+    // XXX hack to ensure 'Custom Format' is last in the combo
     const gchar *sort_key = gnac_utils_str_equal(format_id, "custom-format") ?
         "ZZZZZZZZZZZZZZZZZZZ" : format_name;
 
@@ -213,11 +207,9 @@ gnac_profiles_properties_show(gpointer     profile,
                               const gchar *title,
                               GCallback    call_back)
 {
-  GtkWidget *widget;
-  
   gnac_profiles_properties_reset();
 
-  widget = gnac_profiles_properties_get_widget("save-button");
+  GtkWidget *widget = gnac_profiles_properties_get_widget("save-button");
 
   g_signal_connect(G_OBJECT(widget), "clicked",
       G_CALLBACK(gnac_profiles_properties_on_save), call_back);
@@ -305,23 +297,21 @@ gnac_profiles_properties_destroy(void)
 
 
 void
-gnac_profiles_properties_combo_format_on_changed(GtkComboBox *widget,
+gnac_profiles_properties_combo_format_on_changed(GtkComboBox *combo,
                                                  gpointer     user_data)
 {
-  GtkTreeModel *model = gtk_combo_box_get_model(widget);
+  GtkTreeModel *model = gtk_combo_box_get_model(combo);
 
   GtkTreeIter iter;
-  if (!gtk_combo_box_get_active_iter(widget, &iter)) return;
+  if (!gtk_combo_box_get_active_iter(combo, &iter)) return;
 
   FormatModule *format_module;
   gtk_tree_model_get(model, &iter, 1, &format_module, -1);
 
   gnac_profiles_properties_display_status_message(NULL);
 
-  GtkWidget *properties;
-
   if (current_format_module && format_module != current_format_module) {
-    properties = current_format_module->funcs.get_widget();
+    GtkWidget *properties = current_format_module->funcs.get_widget();
     gtk_widget_hide(properties);
   }
 
@@ -337,8 +327,8 @@ gnac_profiles_properties_combo_format_on_changed(GtkComboBox *widget,
   GtkLabel *label = GTK_LABEL(
       gnac_profiles_properties_get_widget("format_decription_label"));
   gtk_label_set_markup(label, format_module->funcs.get_description());
-  properties = format_module->funcs.get_widget();
-  gtk_widget_show(properties);
+  GtkWidget *widget = format_module->funcs.get_widget();
+  gtk_widget_show(widget);
   format_module->funcs.generate_pipeline();
   current_format_module = format_module;
 }
@@ -393,15 +383,6 @@ gnac_profiles_properties_reset(void)
 
 
 static void
-gnac_profiles_properties_name_description_set_text(const gchar *name,
-                                                   const gchar *description)
-{ 
-  gnac_profiles_properties_name_set_text(name);
-  gnac_profiles_properties_description_set_text(description);
-}
-
-
-static void
 gnac_profiles_properties_name_set_text(const gchar *name)
 {
   if (!name) return;
@@ -425,6 +406,15 @@ gnac_profiles_properties_description_set_text(const gchar *description)
 
 
 static void
+gnac_profiles_properties_name_description_set_text(const gchar *name,
+                                                   const gchar *description)
+{
+  gnac_profiles_properties_name_set_text(name);
+  gnac_profiles_properties_description_set_text(description);
+}
+
+
+static void
 gnac_profiles_properties_on_save(GtkWidget *widget,
                                  gpointer   data)
 {
@@ -651,8 +641,8 @@ gnac_profiles_properties_save_profile(gpointer profile)
 
 
 gchar *
-gnac_profiles_properties_filter_text_for_displaying(const gchar *text,
-                                                    gint         chars_to_display)
+gnac_profiles_properties_filter_text_for_display(const gchar *text,
+                                                 gint         chars_to_display)
 {
   if (!text) return NULL;
 
diff --git a/src/profiles/gnac-profiles-properties.h b/src/profiles/gnac-profiles-properties.h
index 723fefd..844d6ef 100644
--- a/src/profiles/gnac-profiles-properties.h
+++ b/src/profiles/gnac-profiles-properties.h
@@ -76,8 +76,8 @@ gnac_profiles_properties_on_window_key_pressed(GtkWidget   *widget,
                                                gpointer     data);
 
 gchar *
-gnac_profiles_properties_filter_text_for_displaying(const gchar *text,
-                                                    gint         length);
+gnac_profiles_properties_filter_text_for_display(const gchar *text,
+                                                 gint         length);
 
 void
 gnac_profiles_properties_combo_format_on_changed(GtkComboBox *widget,
diff --git a/src/profiles/gnac-profiles-xml-engine.c b/src/profiles/gnac-profiles-xml-engine.c
index e50220d..0718ca1 100755
--- a/src/profiles/gnac-profiles-xml-engine.c
+++ b/src/profiles/gnac-profiles-xml-engine.c
@@ -33,26 +33,23 @@
 #include <libxml/xpath.h>
 
 #include "gnac-profiles-xml-engine.h"
+#include "gnac-profiles-utils.h"
 #include "gnac-utils.h"
 
 
 XMLDoc *
 gnac_profiles_xml_engine_load_doc_xpath(const gchar *filename)
 {
-  xmlDocPtr           doc;
-  xmlXPathContextPtr  xpath_context;
-  XMLDoc             *dx;
-  
-  doc = xmlParseFile(filename);
+  xmlDocPtr doc = xmlParseFile(filename);
   if (!doc) return NULL;
 
-  xpath_context = xmlXPathNewContext(doc);
+  xmlXPathContextPtr xpath_context = xmlXPathNewContext(doc);
   if (!xpath_context) {
     xmlFreeDoc(doc);
     return NULL;
   }
 
-  dx = g_malloc(sizeof(XMLDoc));
+  XMLDoc *dx = g_malloc(sizeof(XMLDoc));
   dx->doc = doc;
   dx->xpath_context = xpath_context;
 
@@ -340,22 +337,22 @@ gnac_profiles_xml_engine_get_slider_values(XMLDoc      *doc,
     else if (gnac_profiles_xml_engine_node_name_equal(current_node,
         "default-value"))
     {
-      default_value = g_ascii_strtod(content, NULL);
+      default_value = gnac_profiles_utils_gchararray_to_gdouble(content);
     }
     else if (gnac_profiles_xml_engine_node_name_equal(current_node,
         "min-value"))
     {
-      min = g_ascii_strtod(content, NULL);
+      min = gnac_profiles_utils_gchararray_to_gdouble(content);
     }
     else if (gnac_profiles_xml_engine_node_name_equal(current_node,
         "max-value"))
     {
-      max = g_ascii_strtod(content, NULL);
+      max = gnac_profiles_utils_gchararray_to_gdouble(content);
     }
     else if (gnac_profiles_xml_engine_node_name_equal(current_node,
         "step-value"))
     {
-      step = g_ascii_strtod(content, NULL);
+      step = gnac_profiles_utils_gchararray_to_gdouble(content);
     }
 
     g_free(content);
@@ -448,11 +445,10 @@ gnac_profiles_xml_engine_modify_values(XMLDoc      *doc,
   }
   
   va_list ap;
-  const gchar *value;
+  va_start(ap, expr);
 
   gint i;
-  va_start(ap, expr);
-  value = va_arg(ap, const gchar *);
+  const gchar *value = va_arg(ap, const gchar *);
 
   for (i = nodes->nodeNr-1; i >= 0; i--) {
     gchar *value_formatted = gnac_profiles_xml_engine_format_text_to_xml(value);
@@ -491,17 +487,11 @@ gnac_profiles_xml_engine_add_values(XMLDoc      *doc,
       g_strconcat((const gchar *) base_indent, "  ", NULL);
   xmlAddChild(format_node, xmlNewText(BAD_CAST "  "));
 
-  const xmlChar *name;
-  const gchar   *value;
-  xmlNodePtr     node;
-
-  name = va_arg(ap, const xmlChar *);
+  const xmlChar *name = va_arg(ap, const xmlChar *);
 
   while (name) {
-
-    value = va_arg(ap, const gchar *);
-    
-    node = xmlNewNode(format_node->ns, name);
+    const gchar *value = va_arg(ap, const gchar *);
+    xmlNodePtr node = xmlNewNode(format_node->ns, name);
     node = xmlAddChild(format_node, node);
 
     if (!gnac_utils_string_is_null_or_empty(value)) {
diff --git a/src/profiles/gnac-profiles.c b/src/profiles/gnac-profiles.c
index ea85a68..da68065 100755
--- a/src/profiles/gnac-profiles.c
+++ b/src/profiles/gnac-profiles.c
@@ -150,7 +150,7 @@ gnac_profiles_populate_combo(void)
 
   for (temp = profiles; temp; temp = g_list_next(temp)) {
     AudioProfileGeneric *profile = AUDIO_PROFILE_GET_GENERIC(temp->data);
-    gchar *formatted_name = gnac_profiles_properties_filter_text_for_displaying(
+    gchar *formatted_name = gnac_profiles_properties_filter_text_for_display(
         profile->name, MAX_NAME_DISPLAY_SIZE);
     gchar *name = gnac_profiles_utils_get_combo_format_name(formatted_name,
         profile->extension);
@@ -179,7 +179,7 @@ gnac_profiles_on_combo_profile_changed(GtkWidget *widget,
   if (gnac_utils_string_is_null_or_empty(profile->description)) {
     description = g_strdup(_("No description available"));
   } else {
-    gchar *formatted = gnac_profiles_properties_filter_text_for_displaying(
+    gchar *formatted = gnac_profiles_properties_filter_text_for_display(
         profile->description, MAX_DESCR_DISPLAY_SIZE);
     description = gnac_profiles_xml_engine_format_text_to_xml(formatted);
     g_free(formatted);



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