[gnac/devel] Code refactoring



commit 142f551c6c5de3c4c1f0b3498013e9654a68c89d
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Sun Oct 23 14:12:28 2011 +0100

    Code refactoring

 src/gnac-prefs.c                             |   18 ++++++------------
 src/gnac-utils.c                             |    7 +++++++
 src/gnac-utils.h                             |    3 +++
 src/profiles/formats/gnac-profiles-unknown.c |    2 +-
 src/profiles/gnac-profiles-properties.c      |    2 +-
 src/profiles/gnac-profiles-utils.c           |    2 +-
 src/profiles/gnac-profiles-xml-engine.c      |    2 +-
 src/profiles/gnac-profiles.c                 |    7 +++----
 8 files changed, 23 insertions(+), 20 deletions(-)
---
diff --git a/src/gnac-prefs.c b/src/gnac-prefs.c
index afc9003..92b6a1d 100644
--- a/src/gnac-prefs.c
+++ b/src/gnac-prefs.c
@@ -426,28 +426,22 @@ gnac_prefs_update_example_label(GtkWidget *widget,
   label = gnac_prefs_get_widget("example_label");
 
   pattern_filename = gnac_prefs_entry_get_text("output_filename_entry");
-  if (pattern_filename && !g_str_equal(pattern_filename, ""))
+  if (!gnac_utils_string_is_null_or_empty(pattern_filename))
   {
     gnac_settings_set_string(GNAC_KEY_RENAME_PATTERN_PATTERN, pattern_filename);
   }
 
-  if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)) != 0)
-  {
+  if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)) != 0) {
     const gchar *pattern_folder;
     pattern_folder = gnac_prefs_entry_get_text("folder_hierarchy_entry");
-    if (pattern_folder && !g_str_equal(pattern_folder, ""))
-    {
+    if (gnac_utils_string_is_null_or_empty(pattern_folder)) {
+      pattern = g_strdup(pattern_filename);
+    } else {
       gnac_settings_set_string(GNAC_KEY_FOLDER_HIERARCHY_PATTERN,
           pattern_folder);
       pattern = g_strdup_printf("%s/%s", pattern_folder, pattern_filename);
     }
-    else
-    {
-      pattern = g_strdup(pattern_filename);
-    }
-  }
-  else
-  {
+  } else {
     pattern = g_strdup(pattern_filename);
   }
 
diff --git a/src/gnac-utils.c b/src/gnac-utils.c
index a0a73c0..5ecf023 100644
--- a/src/gnac-utils.c
+++ b/src/gnac-utils.c
@@ -288,3 +288,10 @@ gnac_utils_create_gtk_builder(const gchar *filename)
 
   return builder;
 }
+
+
+gboolean
+gnac_utils_string_is_null_or_empty(const gchar *string)
+{
+  return !string || g_str_equal(string, "");
+}
diff --git a/src/gnac-utils.h b/src/gnac-utils.h
index 86455a6..7e82f00 100644
--- a/src/gnac-utils.h
+++ b/src/gnac-utils.h
@@ -78,6 +78,9 @@ gnac_utils_event_is_single_right_click(GdkEventButton *event);
 GtkBuilder *
 gnac_utils_create_gtk_builder(const gchar *filename);
 
+gboolean
+gnac_utils_string_is_null_or_empty(const gchar *string);
+
 G_END_DECLS
 
 #endif /* GNAC_UTILS_H */
diff --git a/src/profiles/formats/gnac-profiles-unknown.c b/src/profiles/formats/gnac-profiles-unknown.c
index f7126d0..1597a0a 100644
--- a/src/profiles/formats/gnac-profiles-unknown.c
+++ b/src/profiles/formats/gnac-profiles-unknown.c
@@ -174,7 +174,7 @@ gnac_profiles_unknown_generate_audio_profile(GError **error)
   widget = GTK_WIDGET(gtk_builder_get_object(unknown_bfi.builder,
       "entry-extension"));
   extension = gtk_entry_get_text(GTK_ENTRY(widget));
-  if (!g_strcmp0(extension, "")) {
+  if (gnac_utils_string_is_null_or_empty(extension)) {
     if ((error) && (*error == NULL)) { 
       *error = g_error_new(g_quark_from_static_string("gnac"), 0,
           _("The extension field must be non-empty")); 
diff --git a/src/profiles/gnac-profiles-properties.c b/src/profiles/gnac-profiles-properties.c
index 6053215..8b36af5 100644
--- a/src/profiles/gnac-profiles-properties.c
+++ b/src/profiles/gnac-profiles-properties.c
@@ -506,7 +506,7 @@ gnac_profiles_properties_on_save(GtkWidget *widget,
     widget = gnac_profiles_properties_get_widget("name_entry");
     name = gtk_entry_get_text(GTK_ENTRY(widget));
 
-    if (!g_strcmp0(name, "")) {
+    if (gnac_utils_string_is_null_or_empty(name)) {
       gnac_profiles_properties_display_status_message(
           _("The profile name must be non-empty"));
     } else if (!gnac_profiles_properties_is_valid_filename_chars(name)) {
diff --git a/src/profiles/gnac-profiles-utils.c b/src/profiles/gnac-profiles-utils.c
index 94c5480..c2e1211 100755
--- a/src/profiles/gnac-profiles-utils.c
+++ b/src/profiles/gnac-profiles-utils.c
@@ -737,7 +737,7 @@ gnac_profiles_utils_add_pipes(gchar *pipeline,
   while (list_temp != NULL) {
     Value *v = list_temp->data;
     gchar *temp;
-    if (!g_strcmp0("", pipeline)) {
+    if (gnac_utils_string_is_null_or_empty(pipeline)) {
       temp = g_strconcat(v->value, NULL);
     } else {
       temp = g_strconcat(pipeline, " ! ", v->value, NULL);
diff --git a/src/profiles/gnac-profiles-xml-engine.c b/src/profiles/gnac-profiles-xml-engine.c
index 3ba1c44..cebec2b 100755
--- a/src/profiles/gnac-profiles-xml-engine.c
+++ b/src/profiles/gnac-profiles-xml-engine.c
@@ -433,7 +433,7 @@ gnac_profiles_xml_engine_add_values(XMLDoc      *dx,
     
     node = xmlNewNode(format_node->ns, name);
     node = xmlAddChild(format_node, node);
-    if (g_strcmp0("", value)) {
+    if (!gnac_utils_string_is_null_or_empty(value)) {
       gchar *formatted = gnac_profiles_xml_engine_format_text_to_xml(value);
       xmlNodeSetContent(node, BAD_CAST formatted);
       g_free(formatted);
diff --git a/src/profiles/gnac-profiles.c b/src/profiles/gnac-profiles.c
index 97fef1b..95dc93c 100755
--- a/src/profiles/gnac-profiles.c
+++ b/src/profiles/gnac-profiles.c
@@ -264,8 +264,9 @@ gnac_profiles_on_combo_profile_changed(GtkWidget *widget,
 
   profile = gnac_profiles_get_active_profile();
   if (profile != NULL) {
-    if ((profile->description != NULL) && g_strcmp0(profile->description, ""))
-    {
+    if (gnac_utils_string_is_null_or_empty(profile->description)) {
+      desc = g_strdup("No description");
+    } else {
       formatted = gnac_profiles_properties_filter_text_for_displaying(
           profile->description, MAX_DESCR_DISPLAY_SIZE);
       desc = gnac_profiles_xml_engine_format_text_to_xml(formatted);
@@ -273,8 +274,6 @@ gnac_profiles_on_combo_profile_changed(GtkWidget *widget,
       formatted = desc;
       desc = g_strconcat("<i>", formatted, "</i>", NULL);
       g_free(formatted);
-    } else {
-      desc = g_strdup("No description");
     }
      
     gtk_widget_set_tooltip_markup(widget, desc);



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