[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 12:18:53 +0000 (UTC)
commit 79bd81f998cb7815be066d3cb4fdd453a982f1a8
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Sun Oct 30 12:18:47 2011 +0000
Code refactoring
src/gnac-properties.c | 118 ++++++++++++++++++-------------------------------
src/gnac-properties.h | 3 -
2 files changed, 43 insertions(+), 78 deletions(-)
---
diff --git a/src/gnac-properties.c b/src/gnac-properties.c
index 83f3b54..bb1ac24 100644
--- a/src/gnac-properties.c
+++ b/src/gnac-properties.c
@@ -108,6 +108,9 @@ static void
gnac_properties_reset_properties_tab(void);
static void
+gnac_properties_update_display(GtkTreeRowReference *reference);
+
+static void
gnac_properties_set_property(const gchar *name,
const GValue *value);
@@ -322,7 +325,6 @@ gnac_properties_set_entry(const gchar *entry_name,
const GValue *entry_value)
{
GtkWidget *widget = NULL;
- gdouble value;
widget = gnac_properties_get_widget(entry_name);
if (!widget) {
@@ -348,11 +350,13 @@ gnac_properties_set_entry(const gchar *entry_name,
gtk_entry_set_text(GTK_ENTRY(widget), g_value_get_string(entry_value));
return;
- case G_TYPE_UINT:
+ case G_TYPE_UINT: {
+ gdouble value;
value = (gdouble) g_value_get_uint(entry_value);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), value);
gtk_spin_button_set_range(GTK_SPIN_BUTTON(widget), value, value);
return;
+ }
default:
gtk_entry_set_text(GTK_ENTRY(widget),
@@ -495,17 +499,26 @@ gnac_properties_window_new(void)
}
-void
-gnac_properties_update_display(GFile *file)
+static void
+gnac_properties_update_display(GtkTreeRowReference *reference)
{
- if (properties_displayed)
- {
- tags = libgnac_metadata_extract(metadata, file, NULL);
- gnac_properties_reset_properties();
- if (tags)
- {
- g_hash_table_foreach(tags, (GHFunc)gnac_properties_set_entry, NULL);
- }
+ if (!properties_displayed) return;
+
+ gchar *uri;
+ GFile *file;
+
+ if (!gnac_file_list_get(reference, &uri)) return;
+
+ file = g_file_new_for_uri(uri);
+ g_free(uri);
+
+ tags = libgnac_metadata_extract(metadata, file, NULL);
+ g_object_unref(file);
+
+ gnac_properties_reset_properties();
+
+ if (tags) {
+ g_hash_table_foreach(tags, (GHFunc)gnac_properties_set_entry, NULL);
}
}
@@ -549,7 +562,7 @@ gnac_properties_update_backward_arrow(void)
static void
gnac_properties_reset_spin_if_empty(const gchar *name)
{
- GtkWidget *spin = NULL;
+ GtkWidget *spin;
spin = gnac_properties_get_widget(name);
@@ -562,7 +575,6 @@ gnac_properties_reset_spin_if_empty(const gchar *name)
void
gnac_properties_window_show(void)
{
- gchar *file_uri;
GtkWidget *notebook;
if (!gnac_properties_window) {
@@ -573,17 +585,9 @@ gnac_properties_window_show(void)
properties_displayed = TRUE;
- if (gnac_file_list_get_current_row(¤t_ref))
- {
+ if (gnac_file_list_get_current_row(¤t_ref)) {
gnac_properties_update_arrows();
- if (gnac_file_list_get(current_ref, &file_uri))
- {
- GFile *uri;
- uri = g_file_new_for_uri(file_uri);
- gnac_properties_update_display(uri);
- g_object_unref(uri);
- g_free(file_uri);
- }
+ gnac_properties_update_display(current_ref);
}
gtk_widget_show_all(gnac_properties_window);
@@ -612,27 +616,15 @@ gnac_properties_window_hide(void)
void
gnac_properties_set_row(GtkTreeRowReference *current)
{
- gchar *file_uri;
-
gtk_tree_row_reference_free(current_ref);
current_ref = NULL;
- if (gtk_tree_row_reference_valid(current))
- {
- current_ref = gtk_tree_row_reference_copy(current);
- gnac_properties_update_arrows();
- gnac_file_list_select_row_and_follow(current_ref);
- if (gnac_file_list_get(current_ref, &file_uri))
- {
- GFile *uri;
-
- uri = g_file_new_for_uri(file_uri);
- gnac_properties_update_display(uri);
- g_object_unref(uri);
+ if (!gtk_tree_row_reference_valid(current)) return;
- g_free(file_uri);
- }
- }
+ current_ref = gtk_tree_row_reference_copy(current);
+ gnac_properties_update_arrows();
+ gnac_file_list_select_row_and_follow(current_ref);
+ gnac_properties_update_display(current_ref);
}
@@ -642,28 +634,16 @@ gnac_on_back(GtkWidget *widget,
{
GtkTreeRowReference *old_ref;
- gchar *file_uri;
-
old_ref = gtk_tree_row_reference_copy(current_ref);
- if (gnac_file_list_get_prev_row(¤t_ref))
+ if (gnac_file_list_get_prev_row(¤t_ref))
{
gnac_file_list_select_row_and_follow(current_ref);
-
- if (gnac_file_list_get(current_ref, &file_uri))
- {
- GFile *uri;
-
- uri = g_file_new_for_uri(file_uri);
- gnac_properties_update_display(uri);
- g_object_unref(uri);
-
- g_free(file_uri);
- }
-
+ gnac_properties_update_display(current_ref);
gtk_tree_row_reference_free(old_ref);
-
- } else {
+ }
+ else
+ {
gtk_tree_row_reference_free(current_ref);
current_ref = old_ref;
}
@@ -678,28 +658,16 @@ gnac_on_forward(GtkWidget *widget,
{
GtkTreeRowReference *old_ref;
- gchar *file_uri;
-
old_ref = gtk_tree_row_reference_copy(current_ref);
- if (gnac_file_list_get_next_row(¤t_ref))
+ if (gnac_file_list_get_next_row(¤t_ref))
{
gnac_file_list_select_row_and_follow(current_ref);
-
- if (gnac_file_list_get(current_ref, &file_uri))
- {
- GFile *uri;
-
- uri = g_file_new_for_uri(file_uri);
- gnac_properties_update_display(uri);
- g_object_unref(uri);
-
- g_free(file_uri);
- }
-
+ gnac_properties_update_display(current_ref);
gtk_tree_row_reference_free(old_ref);
-
- } else {
+ }
+ else
+ {
gtk_tree_row_reference_free(current_ref);
current_ref = old_ref;
}
diff --git a/src/gnac-properties.h b/src/gnac-properties.h
index 713d5c0..7498f07 100644
--- a/src/gnac-properties.h
+++ b/src/gnac-properties.h
@@ -58,9 +58,6 @@ void
gnac_properties_window_hide(void);
void
-gnac_properties_update_display(GFile *file);
-
-void
gnac_properties_set_row(GtkTreeRowReference *current);
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]