changeset 4736:e14398ef0868

remove some code duplication
author mf0102 <0102@gmx.at>
date Thu, 17 Jul 2008 20:21:52 +0200
parents cc107c7ec07f
children 2d69832b7136
files src/audacious/ui_playlist_widget.c
diffstat 1 files changed, 26 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/ui_playlist_widget.c	Thu Jul 17 20:17:32 2008 +0200
+++ b/src/audacious/ui_playlist_widget.c	Thu Jul 17 20:21:52 2008 +0200
@@ -40,35 +40,38 @@
         playback_initiate();
 }
 
+static void
+ui_playlist_widget_set_title_active(GtkTreeModel *model, gint pos,
+                                    gboolean active)
+{
+    GtkTreeIter iter;
+    GtkTreePath *path;
+    gchar *path_str;
+    
+    path_str = g_strdup_printf("%d", pos);
+    path = gtk_tree_path_new_from_string(path_str);
+    gtk_tree_model_get_iter(model, &iter, path);
+
+    gtk_list_store_set(GTK_LIST_STORE(model), &iter,
+                       3, active ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL, -1);
+
+    g_free(path_str);
+    gtk_tree_path_free(path);
+}
+
 void
 ui_playlist_widget_set_current(GtkWidget *treeview, gint pos)
 {
     GtkTreeModel *model;
-    GtkTreeIter iter;
-    GtkTreePath *path;
-    gchar *p;
-
+    gint old_pos;
+    
     model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
-
-    gint old_pos = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(treeview), "current"));
+    old_pos = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(treeview), "current"));
 
-    if (old_pos != -1) {
-        p = g_strdup_printf("%d", old_pos);
-        path = gtk_tree_path_new_from_string(p);
-        gtk_tree_model_get_iter(model, &iter, path);
-        gtk_list_store_set(GTK_LIST_STORE(model), &iter, 3, PANGO_WEIGHT_NORMAL, -1);
-        g_free(p);
-        gtk_tree_path_free(path);
-    }
-
-    if (pos != -1) {
-        p = g_strdup_printf("%d", pos);
-        path = gtk_tree_path_new_from_string(p);
-        gtk_tree_model_get_iter(model, &iter, path);
-        gtk_list_store_set(GTK_LIST_STORE(model), &iter, 3, PANGO_WEIGHT_BOLD, -1);
-        g_free(p);
-        gtk_tree_path_free(path);
-    }
+    if (old_pos != -1)
+        ui_playlist_widget_set_title_active(model, old_pos, FALSE);
+    if (pos != -1)
+        ui_playlist_widget_set_title_active(model, pos, TRUE);
 
     g_object_set_data(G_OBJECT(treeview), "current", GINT_TO_POINTER(pos));
 }