changeset 4698:cfc8d1e0c78b

- update time info during slider movement - update slider more often (4 times a second; results in more fluent movement) - made functions ui_hooks_associate() and ui_hooks_disassociate() - indentation - several other small changes
author mf0102 <0102@gmx.at>
date Sun, 06 Jul 2008 13:55:23 +0200
parents 3b4400ab7397
children 7bf9affe88b6 3a56d2786063
files src/audacious/ui_new.c
diffstat 1 files changed, 65 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/ui_new.c	Sun Jul 06 12:47:54 2008 +0200
+++ b/src/audacious/ui_new.c	Sun Jul 06 13:55:23 2008 +0200
@@ -85,12 +85,15 @@
 }
 
 static void
-ui_set_current_song_title(gchar *text, gpointer user_data)
+ui_set_song_info(gchar *text, gpointer user_data)
 {
     gchar *esc_title = g_markup_escape_text(text, -1);
     gchar *title = g_strdup_printf("<big>%s</big>", esc_title);
 
+    gint length = playback_get_length();
+
     gtk_label_set_markup(GTK_LABEL(label_current), title);
+    gtk_range_set_range(GTK_RANGE(slider), 0.0, (gdouble)length);
 
     g_free(esc_title);
     g_free(title);
@@ -100,15 +103,29 @@
 ui_playlist_update(Playlist *playlist, gpointer user_data)
 {
     gchar *text = playlist_get_info_text(playlist);
-    ui_set_current_song_title(text, NULL);
+    ui_set_song_info(text, NULL);
     g_free(text);
 }
 
+static void
+ui_update_time_info(gint time)
+{
+    gchar text[128];
+    gint length = playback_get_length();
+
+    time /= 1000;
+    length /= 1000;
+
+    g_snprintf(text, sizeof(text)/sizeof(gchar),
+               "<tt><b>%d:%.2d/%d:%.2d</b></tt>",
+               time / 60, time % 60,
+               length / 60, length % 60);
+    gtk_label_set_markup(GTK_LABEL(label_time), text);
+}
+
 static gboolean
 ui_update_song_info(gpointer hook_data, gpointer user_data)
 {
-    gchar text[128];
-
     if (!playback_get_playing())
     {
         gtk_range_set_value(GTK_RANGE(slider), (gdouble)0);
@@ -119,20 +136,12 @@
         return TRUE;
 
     gint time = playback_get_time();
-    gint length = playback_get_length();
 
     g_signal_handler_block(slider, slider_change_handler_id);
-    gtk_range_set_range(GTK_RANGE(slider), 0.0, (gdouble)length);
     gtk_range_set_value(GTK_RANGE(slider), (gdouble)time);
     g_signal_handler_unblock(slider, slider_change_handler_id);
 
-    time /= 1000;
-    length /= 1000;
-
-    g_snprintf(text, 128, "<tt><b>%d:%.2d/%d:%.2d</b></tt>",
-               time / 60, time % 60,
-               length / 60, length % 60);
-    gtk_label_set_markup(GTK_LABEL(label_time), text);
+    ui_update_time_info(time);
 
     return TRUE;
 }
@@ -148,14 +157,23 @@
 }
 
 static gboolean
-ui_slider_button_press_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
+ui_slider_change_value_cb(GtkRange *range, GtkScrollType scroll)
+{
+    ui_update_time_info(gtk_range_get_value(range));
+    return FALSE;
+}
+
+static gboolean
+ui_slider_button_press_cb(GtkWidget *widget, GdkEventButton *event,
+                          gpointer user_data)
 {
     slider_is_moving = TRUE;
     return FALSE;
 }
 
 static gboolean
-ui_slider_button_release_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
+ui_slider_button_release_cb(GtkWidget *widget, GdkEventButton *event,
+                            gpointer user_data)
 {
     slider_is_moving = FALSE;
     return FALSE;
@@ -165,8 +183,10 @@
 ui_playback_begin(gpointer hook_data, gpointer user_data)
 {
     ui_update_song_info(NULL, NULL);
+
+    /* update song info 4 times a second */
     update_song_timeout_source =
-        g_timeout_add_seconds(1, (GSourceFunc) ui_update_song_info, NULL);
+        g_timeout_add(250, (GSourceFunc) ui_update_song_info, NULL);
 }
 
 static void
@@ -185,7 +205,8 @@
 }
 
 static GtkToolItem *
-gtk_toolbar_button_add(GtkWidget *toolbar, void(*callback)(), const gchar *stock_id)
+gtk_toolbar_button_add(GtkWidget *toolbar, void(*callback)(),
+                       const gchar *stock_id)
 {
     GtkToolItem *button = gtk_tool_button_new_from_stock(stock_id);
     gtk_toolbar_insert(GTK_TOOLBAR(toolbar), button, -1);
@@ -202,6 +223,28 @@
     return label;
 }
 
+static void
+ui_hooks_associate()
+{
+    hook_associate("title change", (HookFunction) ui_set_song_info, NULL);
+    hook_associate("playback seek", (HookFunction) ui_update_song_info, NULL);
+    hook_associate("playback begin", (HookFunction) ui_playback_begin, NULL);
+    hook_associate("playback stop", (HookFunction) ui_playback_stop, NULL);
+    hook_associate("playback end", (HookFunction) ui_playback_end, NULL);
+    hook_associate("playlist update", (HookFunction) ui_playlist_update, NULL);
+}
+
+static void
+ui_hooks_disassociate()
+{
+    hook_dissociate("title change", (HookFunction) ui_set_song_info);
+    hook_dissociate("playback seek", (HookFunction) ui_update_song_info);
+    hook_dissociate("playback begin", (HookFunction) ui_playback_begin);
+    hook_dissociate("playback stop", (HookFunction) ui_playback_stop);
+    hook_dissociate("playback end", (HookFunction) ui_playback_end);
+    hook_dissociate("playlist update", (HookFunction) ui_playlist_update);
+}
+
 static gboolean
 _ui_initialize(void)
 {
@@ -275,23 +318,20 @@
     slider = gtk_hscale_new(NULL);
     gtk_scale_set_draw_value(GTK_SCALE(slider), FALSE);
     /* TODO: make this configureable */
-    gtk_range_set_update_policy(GTK_RANGE(slider), GTK_UPDATE_DELAYED);
+    gtk_range_set_update_policy(GTK_RANGE(slider), GTK_UPDATE_DISCONTINUOUS);
     gtk_box_pack_start(GTK_BOX(shbox), slider, TRUE, TRUE, 0);
 
     label_time = gtk_markup_label_new("<tt><b>0:00/0:00</b></tt>");
     gtk_box_pack_start(GTK_BOX(shbox), label_time, FALSE, FALSE, 0);
 
-    hook_associate("title change", (HookFunction) ui_set_current_song_title, NULL);
-    hook_associate("playback seek", (HookFunction) ui_update_song_info, NULL);
-    hook_associate("playback begin", (HookFunction) ui_playback_begin, NULL);
-    hook_associate("playback stop", (HookFunction) ui_playback_stop, NULL);
-    hook_associate("playback end", (HookFunction) ui_playback_end, NULL);
-    hook_associate("playlist update", (HookFunction) ui_playlist_update, NULL);
+    ui_hooks_associate();
 
     slider_change_handler_id =
         g_signal_connect(slider, "value-changed",
                          G_CALLBACK(ui_slider_value_changed_cb), NULL);
 
+    g_signal_connect(slider, "change-value",
+                     G_CALLBACK(ui_slider_change_value_cb), NULL);
     g_signal_connect(slider, "button-press-event",
                      G_CALLBACK(ui_slider_button_press_cb), NULL);
     g_signal_connect(slider, "button-release-event",
@@ -308,13 +348,7 @@
 static gboolean
 _ui_finalize(void)
 {
-    hook_dissociate("title change", (HookFunction) ui_set_current_song_title);
-    hook_dissociate("playback seek", (HookFunction) ui_update_song_info);
-    hook_dissociate("playback begin", (HookFunction) ui_playback_begin);
-    hook_dissociate("playback stop", (HookFunction) ui_playback_stop);
-    hook_dissociate("playback end", (HookFunction) ui_playback_end);
-    hook_dissociate("playlist update", (HookFunction) ui_playlist_update);
-
+    ui_hooks_disassociate();
     return TRUE;
 }