[gnac/devel] Code refactoring
- From: BenoÃt Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/devel] Code refactoring
- Date: Sun, 30 Oct 2011 14:05:24 +0000 (UTC)
commit 75095a522ca1f70b6a3bb0a7fddd407ced1a6fa5
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Sun Oct 30 14:05:17 2011 +0000
Code refactoring
data/profiles/ui/gnac-profiles-manager.xml | 2 -
data/ui/gnac-pref-window.xml | 2 +-
data/ui/gnac-properties-window.xml | 6 +-
src/gnac-file-list.c | 1 -
src/gnac-prefs.c | 8 +-
src/gnac-prefs.h | 2 +-
src/gnac-properties.c | 12 +-
src/gnac-properties.h | 16 +--
src/gnac-ui.c | 8 +-
src/gnac-utils.c | 22 +++
src/gnac-utils.h | 12 ++
src/profiles/gnac-profiles-manager.c | 44 +-----
src/profiles/gnac-profiles-manager.h | 11 --
src/profiles/gnac-profiles-properties.c | 230 ++++++++++++++--------------
src/profiles/gnac-profiles-utils.c | 20 +--
src/profiles/gnac-profiles-xml-engine.c | 10 +-
16 files changed, 193 insertions(+), 213 deletions(-)
---
diff --git a/data/profiles/ui/gnac-profiles-manager.xml b/data/profiles/ui/gnac-profiles-manager.xml
index 3372287..cbd4f8c 100644
--- a/data/profiles/ui/gnac-profiles-manager.xml
+++ b/data/profiles/ui/gnac-profiles-manager.xml
@@ -13,8 +13,6 @@
<!-- column-name Profile -->
<column type="gpointer"/>
</columns>
- <signal name="row_deleted" handler="gnac_profiles_mgr_on_row_deleted"/>
- <signal name="row_inserted" handler="gnac_profiles_mgr_on_row_inserted"/>
</object>
<object class="GtkWindow" id="profile_manager_window">
<property name="title" translatable="yes">Profile Manager</property>
diff --git a/data/ui/gnac-pref-window.xml b/data/ui/gnac-pref-window.xml
index eced97c..0f8f8c3 100644
--- a/data/ui/gnac-pref-window.xml
+++ b/data/ui/gnac-pref-window.xml
@@ -577,7 +577,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
- <signal name="clicked" handler="gnac_on_close_prefs"/>
+ <signal name="clicked" handler="gnac_prefs_on_close"/>
</object>
<packing>
<property name="expand">False</property>
diff --git a/data/ui/gnac-properties-window.xml b/data/ui/gnac-properties-window.xml
index fbf68c2..2abcfd1 100644
--- a/data/ui/gnac-properties-window.xml
+++ b/data/ui/gnac-properties-window.xml
@@ -483,7 +483,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
- <signal name="clicked" handler="gnac_on_back"/>
+ <signal name="clicked" handler="gnac_properties_on_back"/>
</object>
<packing>
<property name="expand">False</property>
@@ -498,7 +498,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
- <signal name="clicked" handler="gnac_on_forward"/>
+ <signal name="clicked" handler="gnac_properties_on_forward"/>
</object>
<packing>
<property name="expand">False</property>
@@ -523,7 +523,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
- <signal name="clicked" handler="gnac_on_close_properties"/>
+ <signal name="clicked" handler="gnac_properties_on_close"/>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/gnac-file-list.c b/src/gnac-file-list.c
index 01bc5ea..c60dfe4 100644
--- a/src/gnac-file-list.c
+++ b/src/gnac-file-list.c
@@ -23,7 +23,6 @@
* Boston, MA 02110-1301 USA
*/
-#include <gdk/gdkkeysyms.h>
#include <glib-object.h>
#include "gnac-bars.h"
diff --git a/src/gnac-prefs.c b/src/gnac-prefs.c
index d0f6be5..e62faaa 100644
--- a/src/gnac-prefs.c
+++ b/src/gnac-prefs.c
@@ -319,8 +319,7 @@ gnac_prefs_get_rename_pattern_as_str(void)
g_assert(index >= 0 && index <= size);
- if (index == size)
- {
+ if (index == size) {
return g_settings_get_string(settings, GNAC_KEY_RENAME_PATTERN_PATTERN);
}
@@ -336,8 +335,7 @@ gnac_prefs_get_folder_hierarchy_as_str(void)
g_assert(index >= 0 && index <= size);
- if (index == size)
- {
+ if (index == size) {
return g_settings_get_string(settings, GNAC_KEY_FOLDER_HIERARCHY_PATTERN);
}
@@ -591,7 +589,7 @@ gnac_prefs_window_hide(void)
void
-gnac_on_close_prefs(GtkWidget *widget,
+gnac_prefs_on_close(GtkWidget *widget,
gpointer data)
{
gnac_prefs_window_hide();
diff --git a/src/gnac-prefs.h b/src/gnac-prefs.h
index ef96c7d..dcf9208 100644
--- a/src/gnac-prefs.h
+++ b/src/gnac-prefs.h
@@ -88,7 +88,7 @@ gnac_prefs_query_tooltip_cb(GtkWidget *widget,
gpointer user_data);
void
-gnac_on_close_prefs(GtkWidget *widget,
+gnac_prefs_on_close(GtkWidget *widget,
gpointer data);
void
diff --git a/src/gnac-properties.c b/src/gnac-properties.c
index bb1ac24..0351f84 100644
--- a/src/gnac-properties.c
+++ b/src/gnac-properties.c
@@ -629,8 +629,8 @@ gnac_properties_set_row(GtkTreeRowReference *current)
void
-gnac_on_back(GtkWidget *widget,
- gpointer data)
+gnac_properties_on_back(GtkWidget *widget,
+ gpointer data)
{
GtkTreeRowReference *old_ref;
@@ -653,8 +653,8 @@ gnac_on_back(GtkWidget *widget,
void
-gnac_on_forward(GtkWidget *widget,
- gpointer data)
+gnac_properties_on_forward(GtkWidget *widget,
+ gpointer data)
{
GtkTreeRowReference *old_ref;
@@ -677,7 +677,7 @@ gnac_on_forward(GtkWidget *widget,
void
-gnac_on_close_properties(GtkWidget *widget,
+gnac_properties_on_close(GtkWidget *widget,
gpointer data)
{
gnac_properties_window_hide();
@@ -689,7 +689,7 @@ gnac_properties_on_delete_event(GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
- gnac_on_close_properties(widget, data);
+ gnac_properties_on_close(widget, data);
/* do not send the "destroy" signal */
return TRUE;
}
diff --git a/src/gnac-properties.h b/src/gnac-properties.h
index 7498f07..2b4e131 100644
--- a/src/gnac-properties.h
+++ b/src/gnac-properties.h
@@ -31,9 +31,6 @@
#include "libgnac-metadata.h"
-#define GNAC_PROPERTIES_HEIGHT 380
-#define GNAC_PROPERTIES_WIDTH 300
-
G_BEGIN_DECLS
enum {
@@ -44,9 +41,6 @@ enum {
PROPERTY_COLS
};
-/**
- * Prototypes
- */
GtkWidget *
gnac_properties_window_new(void);
@@ -64,15 +58,15 @@ void
gnac_properties_update_arrows(void);
void
-gnac_on_back(GtkWidget *widget,
- gpointer data);
+gnac_properties_on_back(GtkWidget *widget,
+ gpointer data);
void
-gnac_on_forward(GtkWidget *widget,
- gpointer data);
+gnac_properties_on_forward(GtkWidget *widget,
+ gpointer data);
void
-gnac_on_close_properties(GtkWidget *widget,
+gnac_properties_on_close(GtkWidget *widget,
gpointer data);
gboolean
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index 8f69e1a..ad03241 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -27,7 +27,6 @@
#include "config.h"
#endif
-#include <gdk/gdkkeysyms.h>
#include <glib/gi18n.h>
#include <glib/gprintf.h>
@@ -351,6 +350,7 @@ gnac_ui_file_chooser_foreach(gpointer data,
list = (GSList**) user_data;
file = g_file_new_for_uri((gchar*)data);
*list = g_slist_append(*list, file);
+
g_free(data);
}
@@ -410,8 +410,7 @@ gnac_remove_track(gpointer data,
file = g_file_new_for_uri(uri);
libgnac_converter_remove(converter, file, &error);
- if (error)
- {
+ if (error) {
g_printerr("%s: %s\n", _("Error"), error->message);
g_clear_error(&error);
}
@@ -556,6 +555,7 @@ gnac_ui_file_chooser_response_cb(GtkDialog *dialog,
default:
break;
}
+
gtk_widget_hide(GTK_WIDGET(dialog));
}
@@ -574,7 +574,7 @@ gnac_ui_file_chooser_key_press_event_cb(GtkWidget *widget,
GdkEventKey *event,
gpointer user_data)
{
- if (event->type == GDK_KEY_PRESS && event->keyval == GDK_Return) {
+ if (gnac_utils_event_is_return_key(event)) {
gnac_ui_file_chooser_response_cb(GTK_DIALOG(widget),
GTK_RESPONSE_NONE, NULL);
return TRUE;
diff --git a/src/gnac-utils.c b/src/gnac-utils.c
index 48b72ff..97fc9f1 100644
--- a/src/gnac-utils.c
+++ b/src/gnac-utils.c
@@ -27,6 +27,7 @@
#include "config.h"
#endif
+#include <gdk/gdkkeysyms.h>
#include <gio/gio.h>
#include <glib.h>
#include <glib/gi18n.h>
@@ -277,6 +278,27 @@ gnac_utils_event_is_single_right_click(GdkEventButton *event)
}
+gboolean
+gnac_utils_event_is_delete_key(GdkEventKey *event)
+{
+ return event->keyval == GDK_KEY_Delete;
+}
+
+
+gboolean
+gnac_utils_event_is_escape_key(GdkEventKey *event)
+{
+ return event->keyval == GDK_KEY_Escape;
+}
+
+
+gboolean
+gnac_utils_event_is_return_key(GdkEventKey *event)
+{
+ return event->keyval == GDK_KEY_Return;
+}
+
+
GtkBuilder *
gnac_utils_create_gtk_builder(const gchar *filename)
{
diff --git a/src/gnac-utils.h b/src/gnac-utils.h
index 2e63908..b41a41e 100644
--- a/src/gnac-utils.h
+++ b/src/gnac-utils.h
@@ -78,6 +78,18 @@ gnac_utils_event_is_double_left_click(GdkEventButton *event);
gboolean
gnac_utils_event_is_single_right_click(GdkEventButton *event);
+gboolean
+gnac_utils_event_is_key_press(GdkEventKey *event);
+
+gboolean
+gnac_utils_event_is_delete_key(GdkEventKey *event);
+
+gboolean
+gnac_utils_event_is_escape_key(GdkEventKey *event);
+
+gboolean
+gnac_utils_event_is_return_key(GdkEventKey *event);
+
GtkBuilder *
gnac_utils_create_gtk_builder(const gchar *filename);
diff --git a/src/profiles/gnac-profiles-manager.c b/src/profiles/gnac-profiles-manager.c
index d8acd37..1dc9f53 100644
--- a/src/profiles/gnac-profiles-manager.c
+++ b/src/profiles/gnac-profiles-manager.c
@@ -27,7 +27,6 @@
#include "config.h"
#endif
-#include <gdk/gdkkeysyms.h>
#include <gio/gio.h>
#include <glib/gi18n.h>
#include <stdlib.h>
@@ -1329,25 +1328,6 @@ gnac_profiles_mgr_delete_profile_file(const gchar *name)
}
-void
-gnac_profiles_mgr_on_row_inserted(GtkTreeModel *tree_model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data)
-{
-
-}
-
-
-void
-gnac_profiles_mgr_on_row_deleted(GtkTreeModel *tree_model,
- GtkTreePath *path,
- gpointer user_data)
-{
-
-}
-
-
static void
gnac_profiles_mgr_on_treeselection_changed(void)
{
@@ -1406,14 +1386,9 @@ gnac_profiles_mgr_list_on_key_pressed(GtkWidget *widget,
GdkEventKey *event,
gpointer data)
{
- switch (event->keyval)
- {
- case GDK_Delete:
- gnac_profiles_mgr_on_remove(NULL, NULL);
- break;
-
- default:
- break;
+ if (gnac_utils_event_is_delete_key(event)) {
+ gnac_profiles_mgr_on_remove(NULL, NULL);
+ return TRUE;
}
return FALSE;
@@ -1425,15 +1400,10 @@ gnac_profiles_mgr_on_key_pressed(GtkWidget *widget,
GdkEventKey *event,
gpointer data)
{
- switch (event->keyval)
- {
- case GDK_Escape:
- widget = gnac_profiles_mgr_get_widget("close_button");
- gtk_button_clicked(GTK_BUTTON(widget));
- return TRUE;
-
- default:
- break;
+ if (gnac_utils_event_is_escape_key(event)) {
+ widget = gnac_profiles_mgr_get_widget("close_button");
+ gtk_button_clicked(GTK_BUTTON(widget));
+ return TRUE;
}
return FALSE;
diff --git a/src/profiles/gnac-profiles-manager.h b/src/profiles/gnac-profiles-manager.h
index b006f59..684aa2d 100644
--- a/src/profiles/gnac-profiles-manager.h
+++ b/src/profiles/gnac-profiles-manager.h
@@ -92,17 +92,6 @@ gnac_profiles_mgr_on_remove(GtkWidget *widget,
gpointer data);
void
-gnac_profiles_mgr_on_row_inserted(GtkTreeModel *tree_model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data);
-
-void
-gnac_profiles_mgr_on_row_deleted(GtkTreeModel *tree_model,
- GtkTreePath *path,
- gpointer user_data);
-
-void
gnac_profiles_mgr_on_close(GtkWidget *widget,
gpointer data);
diff --git a/src/profiles/gnac-profiles-properties.c b/src/profiles/gnac-profiles-properties.c
index 8b36af5..2b35a05 100644
--- a/src/profiles/gnac-profiles-properties.c
+++ b/src/profiles/gnac-profiles-properties.c
@@ -51,13 +51,11 @@
#define NB_PLUGINS 8
#ifdef G_OS_WIN32
-static const guint nb_forbidden_chars = 11;
static const gchar forbidden_chars[] = {
'\\', '/', ':', '*', '?', '"', '<', '>', '|', '{', '}'
};
static const gchar *forbidden_chars_string = "\\ / : * ? \" < > | { }";
#else
-static const guint nb_forbidden_chars = 3;
static const guint forbidden_chars_keys[] = { GDK_KEY_slash };
static const gchar forbidden_chars[] = { '/', '\n', '\t' };
static const gchar *forbidden_chars_string = " /, <return>, <tab>";
@@ -416,20 +414,21 @@ gnac_profiles_properties_display_status_message(const gchar *error)
GtkWidget *widget;
widget = gnac_profiles_properties_get_widget("hbox-properties-status");
- if (error != NULL) {
- gtk_widget_show_all(widget);
- widget = gnac_profiles_properties_get_widget("label-properties-status-error");
- gtk_label_set_text(GTK_LABEL(widget), error);
-
- } else {
+ if (!error) {
gtk_widget_hide(widget);
+ return;
}
+
+ gtk_widget_show_all(widget);
+ widget = gnac_profiles_properties_get_widget("label-properties-status-error");
+ gtk_label_set_text(GTK_LABEL(widget), error);
}
static void
-gnac_profiles_properties_reinit() {
+gnac_profiles_properties_reinit(void)
+{
GList *list;
GList *temp;
@@ -482,64 +481,71 @@ gnac_profiles_properties_on_save(GtkWidget *widget,
window = gnac_profiles_properties_get_widget("window1");
profile = current_format_module->funcs.generate_audio_profile(&error);
- if (profile == NULL) {
+ if (!profile) {
if (error) {
gnac_profiles_properties_display_status_message(error->message);
g_error_free(error);
}
- } else {
- GtkWidget *text_view;
- GtkTextBuffer *pipeline_text_buffer;
+ return;
+ }
- text_view = gnac_profiles_properties_get_widget("gstreamer_pipeline_text_view");
- pipeline_text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
+ GtkWidget *text_view;
+ GtkTextBuffer *pipeline_text_buffer;
- generic = ((AudioProfileGeneric*) profile)->generic;
-
- if (generic->pipeline == NULL) {
- gtk_text_buffer_get_start_iter(pipeline_text_buffer, &start);
- gtk_text_buffer_get_end_iter(pipeline_text_buffer, &end);
- generic->pipeline = gtk_text_buffer_get_text(pipeline_text_buffer,
- &start, &end, FALSE);
- }
-
- widget = gnac_profiles_properties_get_widget("name_entry");
- name = gtk_entry_get_text(GTK_ENTRY(widget));
+ text_view = gnac_profiles_properties_get_widget("gstreamer_pipeline_text_view");
+ pipeline_text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
+
+ generic = ((AudioProfileGeneric*) profile)->generic;
+
+ if (generic->pipeline == NULL) {
+ gtk_text_buffer_get_start_iter(pipeline_text_buffer, &start);
+ gtk_text_buffer_get_end_iter(pipeline_text_buffer, &end);
+ generic->pipeline = gtk_text_buffer_get_text(pipeline_text_buffer,
+ &start, &end, FALSE);
+ }
+
+ widget = gnac_profiles_properties_get_widget("name_entry");
+ name = gtk_entry_get_text(GTK_ENTRY(widget));
- if (gnac_utils_string_is_null_or_empty(name)) {
+ if (gnac_utils_string_is_null_or_empty(name)) {
+ gnac_profiles_properties_display_status_message(
+ _("The profile name must be non-empty"));
+ return;
+ }
+
+ if (!gnac_profiles_properties_is_valid_filename_chars(name)) {
+ gchar *message;
+ message = g_strconcat(
+ _("The profile name cannot contain the following characters:"),
+ " ", forbidden_chars_string, NULL);
+ gnac_profiles_properties_display_status_message(message);
+ g_free(message);
+ return;
+ }
+
+ if (g_str_equal(current_profile_name, name)
+ && gnac_profiles_properties_saved_profiles_contain_name(name, TRUE))
+ {
gnac_profiles_properties_display_status_message(
- _("The profile name must be non-empty"));
- } else if (!gnac_profiles_properties_is_valid_filename_chars(name)) {
- gchar *message;
-
- message = g_strconcat(
- _("The profile name cannot contain the following characters:"),
- " ", forbidden_chars_string, NULL);
- gnac_profiles_properties_display_status_message(message);
- g_free(message);
- } else if (g_strcmp0(current_profile_name, name)
- && (gnac_profiles_properties_saved_profiles_contain_name(name, TRUE)))
- {
- gnac_profiles_properties_display_status_message(
- _("This name is already used by another profile."));
- } else {
- gnac_profiles_properties_display_status_message(NULL);
-
- generic->name = g_strdup(name);
- widget = gnac_profiles_properties_get_widget("profile_description_text_view");
- text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
- gtk_text_buffer_get_start_iter(text_buffer, &start);
- gtk_text_buffer_get_end_iter(text_buffer, &end);
- generic->description = gtk_text_buffer_get_text(text_buffer,
- &start, &end, FALSE);
-
- current_format_module->funcs.save_profile_in_file(profile);
-
- call_back(widget, profile);
-
- gtk_widget_hide(window);
- }
+ _("This name is already used by another profile."));
+ return;
}
+
+ gnac_profiles_properties_display_status_message(NULL);
+
+ generic->name = g_strdup(name);
+ widget = gnac_profiles_properties_get_widget("profile_description_text_view");
+ text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
+ gtk_text_buffer_get_start_iter(text_buffer, &start);
+ gtk_text_buffer_get_end_iter(text_buffer, &end);
+ generic->description = gtk_text_buffer_get_text(text_buffer,
+ &start, &end, FALSE);
+
+ current_format_module->funcs.save_profile_in_file(profile);
+
+ call_back(widget, profile);
+
+ gtk_widget_hide(window);
}
@@ -548,25 +554,26 @@ gnac_profiles_properties_on_name_entry_key_pressed(GtkWidget *widget,
GdkEventKey *event,
gpointer data)
{
- if (event->keyval == GDK_Return) {
+ if (gnac_utils_event_is_return_key(event)) {
GtkWidget *widget;
-
widget = gnac_profiles_properties_get_widget("save-button");
gtk_button_clicked(GTK_BUTTON(widget));
return TRUE;
- } else if (gnac_profiles_properties_is_valid_filename_char(event->keyval)) {
+ }
+
+ if (gnac_profiles_properties_is_valid_filename_char(event->keyval)) {
gnac_profiles_properties_display_status_message(NULL);
return FALSE;
- } else {
- gchar *message;
-
- message = g_strconcat(
- _("Profile name cannot contain the following characters:"),
- " ", forbidden_chars_string, NULL);
- gnac_profiles_properties_display_status_message(message);
- g_free(message);
- return TRUE;
}
+
+ gchar *message;
+ message = g_strconcat(
+ _("Profile name cannot contain the following characters:"),
+ " ", forbidden_chars_string, NULL);
+ gnac_profiles_properties_display_status_message(message);
+ g_free(message);
+
+ return TRUE;
}
@@ -575,15 +582,14 @@ gnac_profiles_properties_on_window_key_pressed(GtkWidget *widget,
GdkEventKey *event,
gpointer data)
{
- if (event->keyval == GDK_Escape) {
+ if (gnac_utils_event_is_escape_key(event)) {
GtkWidget *widget;
-
widget = gnac_profiles_properties_get_widget("cancel-button");
gtk_button_clicked(GTK_BUTTON(widget));
return TRUE;
- } else {
- return FALSE;
}
+
+ return FALSE;
}
@@ -592,7 +598,7 @@ gnac_profiles_properties_is_valid_filename_char(guint keyval)
{
guint i;
- for (i = 0; i < nb_forbidden_chars; ++i) {
+ for (i = 0; i < G_N_ELEMENTS(forbidden_chars_keys); ++i) {
if (keyval == forbidden_chars_keys[i]) {
return FALSE;
}
@@ -603,14 +609,14 @@ gnac_profiles_properties_is_valid_filename_char(guint keyval)
static gboolean
-gnac_profiles_properties_is_valid_filename_chars(const gchar *chars) {
+gnac_profiles_properties_is_valid_filename_chars(const gchar *chars)
+{
glong len;
- gint i;
- gint j;
+ guint i, j;
len = g_utf8_strlen(chars, -1);
- for (i = 0; i < len; ++i) {
- for (j = 0; j < nb_forbidden_chars; ++j) {
+ for (i = 0; i < len; i++) {
+ for (j = 0; j < G_N_ELEMENTS(forbidden_chars); j++) {
if (chars[i] == forbidden_chars[j]) {
return FALSE;
}
@@ -626,7 +632,6 @@ gnac_profiles_properties_on_cancel(GtkWidget *widget,
gpointer data)
{
GtkWidget *window;
-
window = gnac_profiles_properties_get_widget("window1");
gtk_widget_hide(window);
}
@@ -644,20 +649,16 @@ gnac_profiles_properties_load_profile_from_file(const gchar *path,
FormatModule *format_module;
doc = gnac_profiles_default_load_generic_audio_profile(path, &profile);
- if ((doc == NULL) || (profile->format_id == NULL)) {
- if ((error) && (*error == NULL)) {
- *error = g_error_new(g_quark_from_static_string("gnac"), 0,
- _("File \"%s\" is not a valid profile file."), filename);
- }
+ if (!doc || !(profile->format_id)) {
+ *error = g_error_new(g_quark_from_static_string("gnac"), 0,
+ _("File \"%s\" is not a valid profile file."), filename);
} else {
format_module = g_hash_table_lookup(formats, profile->format_id);
- if (format_module == NULL) {
- if ((error) && (*error == NULL)) {
- *error = g_error_new(g_quark_from_static_string("gnac"), 0,
- _("Format defined by id \"%s\" in file \"%s\" is not supported."),
- profile->format_id, filename);
- }
+ if (!format_module) {
+ *error = g_error_new(g_quark_from_static_string("gnac"), 0,
+ _("Format defined by id \"%s\" in file \"%s\" is not supported."),
+ profile->format_id, filename);
gnac_profiles_utils_free_audio_profile_generic(profile);
profile = NULL;
} else {
@@ -665,7 +666,8 @@ gnac_profiles_properties_load_profile_from_file(const gchar *path,
}
}
- if (doc != NULL) gnac_profiles_xml_engine_free_doc_xpath(doc);
+ gnac_profiles_xml_engine_free_doc_xpath(doc);
+
return profile;
}
@@ -701,35 +703,35 @@ gnac_profiles_properties_save_profile(gpointer profile)
FormatModule *format_module;
format_id = ((AudioProfileGeneric*)profile)->generic->format_id;
- if (format_id) {
- format_module = g_hash_table_lookup(formats, format_id);
- if (format_module != NULL) {
- format_module->funcs.save_profile_in_file(profile);
- }
+ if (!format_id) return;
+
+ format_module = g_hash_table_lookup(formats, format_id);
+ if (format_module) {
+ format_module->funcs.save_profile_in_file(profile);
}
}
gchar *
gnac_profiles_properties_filter_text_for_displaying(const gchar *text,
- gint length)
+ gint chars_to_display)
{
- gchar *str1;
- gchar *str2;
- glong len;
+ if (!text) return NULL;
+
+ gchar *filtered;
+ glong length;
- if (text != NULL) {
- len = g_utf8_strlen(text, -1);
- if (len > length) {
- str2 = g_strndup(text, length);
- str1 = g_strconcat(str2, "...", NULL);
- g_free(str2);
- } else {
- str1 = g_strdup(text);
- }
- g_strdelimit(str1, "\n\t\r\b\f", ' ');
- return str1;
+ length = g_utf8_strlen(text, -1);
+ if (length > chars_to_display) {
+ gchar *prefix;
+ prefix = g_strndup(text, length);
+ filtered = g_strconcat(prefix, "...", NULL);
+ g_free(prefix);
} else {
- return NULL;
+ filtered = g_strdup(text);
}
+
+ g_strdelimit(filtered, "\n\t\r\b\f", ' ');
+
+ return filtered;
}
diff --git a/src/profiles/gnac-profiles-utils.c b/src/profiles/gnac-profiles-utils.c
index 48a4b13..b8ee319 100755
--- a/src/profiles/gnac-profiles-utils.c
+++ b/src/profiles/gnac-profiles-utils.c
@@ -49,7 +49,6 @@ gnac_profiles_utils_init_name_extension(XMLDoc *doc,
*extension = gnac_profiles_xml_engine_get_text_node(doc,
xpath_query_extension);
- /* Cleanup */
g_free(xpath_query_name);
g_free(xpath_query_extension);
}
@@ -75,7 +74,6 @@ gnac_profiles_utils_init_description(XMLDoc *doc,
raw_desc = gnac_profiles_xml_engine_get_text_node(doc, xpath_query);
desc = g_strconcat("<i>", raw_desc, "</i>", NULL);
- /* Cleanup */
g_free(xpath_query);
g_free(raw_desc);
@@ -92,7 +90,7 @@ gnac_profiles_utils_all_in_one_for_combo(BasicFormatInfo *bfi,
GtkWidget *widget;
widget = GTK_WIDGET(gtk_builder_get_object(bfi->builder, combo_name));
- if (widget != NULL) {
+ if (widget) {
gnac_profiles_utils_register_combo(widget, bfi->doc, xpath_query,
call_back, NULL);
} else {
@@ -112,7 +110,7 @@ gnac_profiles_utils_all_in_one_for_slider(BasicFormatInfo *bfi,
GtkWidget *widget;
widget = GTK_WIDGET(gtk_builder_get_object(bfi->builder, slider_name));
- if (widget != NULL) {
+ if (widget) {
gnac_profiles_utils_register_slider(widget, bfi->doc, xpath_query,
call_back, NULL);
} else {
@@ -132,7 +130,7 @@ gnac_profiles_utils_all_in_one_for_check(BasicFormatInfo *bfi,
GtkWidget *widget;
widget = GTK_WIDGET(gtk_builder_get_object(bfi->builder, check_name));
- if (widget != NULL) {
+ if (widget) {
gnac_profiles_utils_register_check(widget, bfi->doc, xpath_query,
call_back, NULL);
} else {
@@ -146,14 +144,12 @@ gnac_profiles_utils_all_in_one_for_check(BasicFormatInfo *bfi,
GtkWidget *
gnac_profiles_utils_add_toggle_signal(BasicFormatInfo *bfi,
const gchar *check,
- GCallback f,
+ GCallback callback,
gpointer user_data)
{
GtkWidget *widget;
-
widget = GTK_WIDGET(gtk_builder_get_object(bfi->builder, check));
- g_signal_connect(G_OBJECT(widget), "toggled", f, user_data);
-
+ g_signal_connect(G_OBJECT(widget), "toggled", callback, user_data);
return widget;
}
@@ -244,7 +240,7 @@ gnac_profiles_utils_register_advanced_channels(GtkBuilder *builder,
GtkWidget *widget = NULL;
widget = GTK_WIDGET(gtk_builder_get_object(builder, "combo-channels"));
- if (widget != NULL) {
+ if (widget) {
gnac_profiles_utils_register_combo(widget, doc,
"//variable[ id='channels']/*", call_back, user_data);
} else {
@@ -264,7 +260,7 @@ gnac_profiles_utils_register_advanced_sample_rate(GtkBuilder *builder,
GtkWidget *widget = NULL;
widget = GTK_WIDGET(gtk_builder_get_object(builder, "combo-sample-rate"));
- if (widget != NULL) {
+ if (widget) {
gnac_profiles_utils_register_combo(widget, doc,
"//variable[ id='sample-rate']/*", call_back, user_data);
} else {
@@ -285,7 +281,7 @@ gnac_profiles_utils_add_values_combo(GtkWidget *combo,
GList *list_values;
list_names = values->names;
- list_values= values->values;
+ list_values = values->values;
while (list_names != NULL) {
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo),
diff --git a/src/profiles/gnac-profiles-xml-engine.c b/src/profiles/gnac-profiles-xml-engine.c
index 63e98ad..1028e66 100755
--- a/src/profiles/gnac-profiles-xml-engine.c
+++ b/src/profiles/gnac-profiles-xml-engine.c
@@ -523,12 +523,12 @@ gnac_profiles_xml_engine_save_doc(XMLDoc *dx,
void
-gnac_profiles_xml_engine_free_doc_xpath(XMLDoc *dx)
+gnac_profiles_xml_engine_free_doc_xpath(XMLDoc *doc)
{
- if (dx) {
- xmlXPathFreeContext(dx->xpath_context);
- xmlFreeDoc(dx->doc);
- g_free(dx);
+ if (doc) {
+ xmlXPathFreeContext(doc->xpath_context);
+ xmlFreeDoc(doc->doc);
+ g_free(doc);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]