changeset 4682:f6ea8f18c241

add position slider
author Tomasz Mon <desowin@gmail.com>
date Fri, 04 Jul 2008 22:57:07 +0200
parents 7453f5365b8c
children 86e2ba287242
files src/audacious/ui_new.c
diffstat 1 files changed, 54 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/ui_new.c	Thu Jul 03 01:07:07 2008 +0200
+++ b/src/audacious/ui_new.c	Fri Jul 04 22:57:07 2008 +0200
@@ -27,6 +27,10 @@
 #include "ui_new.h"
 
 static GtkWidget *label_prev, *label_current, *label_next;
+static GtkWidget *slider;
+
+gulong slider_change_handler_id;
+static gint update_song_timeout_source = 0;
 
 static gboolean
 window_delete()
@@ -84,6 +88,46 @@
     g_free(title);
 }
 
+static gboolean
+update_song_info(gpointer hook_data, gpointer user_data)
+{
+    if (!playback_get_playing())
+        return FALSE;
+
+    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), (gdouble)0, (gdouble)length);
+    gtk_range_set_value(GTK_RANGE(slider), (gdouble)time);
+    g_signal_handler_unblock(slider, slider_change_handler_id);
+
+    return TRUE;
+}
+
+static gboolean
+ui_slider_value_changed_cb(GtkRange *range, GtkScrollType scroll,
+                             gdouble value, gpointer user_data)
+{
+    playback_seek(value/1000);
+
+    return TRUE;
+}
+
+static void
+ui_playback_begin(gpointer hook_data, gpointer user_data)
+{
+    update_song_timeout_source = g_timeout_add_seconds(1, (GSourceFunc) update_song_info, NULL);
+}
+
+static void
+ui_playback_stop(gpointer hook_data, gpointer user_data)
+{
+    if (update_song_timeout_source) {
+        g_source_remove(update_song_timeout_source);
+        update_song_timeout_source = 0;
+    }
+}
 
 static GtkToolItem *
 gtk_toolbar_button_add(GtkWidget *toolbar, void(*callback)(), const gchar *stock_id)
@@ -120,7 +164,6 @@
     GtkToolItem *button_open, *button_add,
                 *button_play, *button_previous, *button_next;
 
-
     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     g_signal_connect(G_OBJECT(window), "delete_event",
                      G_CALLBACK(window_delete), NULL);
@@ -162,7 +205,17 @@
 
     gtk_box_pack_start(GTK_BOX(vbox), pcnbox, TRUE, TRUE, 0);
 
+    slider = gtk_hscale_new(NULL);
+    gtk_scale_set_draw_value(GTK_SCALE(slider), FALSE);
+    gtk_range_set_update_policy(GTK_RANGE(slider), GTK_UPDATE_DISCONTINUOUS);
+    gtk_box_pack_end(GTK_BOX(cvbox), slider, TRUE, TRUE, 0);
+
     hook_associate("title change", set_song_title, NULL);
+    hook_associate("playback seek", (HookFunction) update_song_info, NULL);
+    hook_associate("playback begin", (HookFunction) ui_playback_begin, NULL);
+    hook_associate("playback stop", (HookFunction) ui_playback_stop, NULL);
+
+    slider_change_handler_id = g_signal_connect(slider, "value-changed", G_CALLBACK(ui_slider_value_changed_cb), NULL);
 
     gtk_widget_show_all(window);
     gtk_main();