aboutsummaryrefslogtreecommitdiff
path: root/src/scrub-widget.c
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-07-22 19:56:43 +0200
committerConor Curran <conor.curran@canonical.com>2010-07-22 19:56:43 +0200
commitcf97680d74aa9ab00cd55359d9e16acdad9f057f (patch)
tree5a96a46ad8617c0fc7f24870f4d3840078b7a50d /src/scrub-widget.c
parent928fbf4bab7659ec523ae16adc052ca42fece589 (diff)
downloadayatana-indicator-sound-cf97680d74aa9ab00cd55359d9e16acdad9f057f.tar.gz
ayatana-indicator-sound-cf97680d74aa9ab00cd55359d9e16acdad9f057f.tar.bz2
ayatana-indicator-sound-cf97680d74aa9ab00cd55359d9e16acdad9f057f.zip
trying to set the time line
Diffstat (limited to 'src/scrub-widget.c')
-rw-r--r--src/scrub-widget.c120
1 files changed, 99 insertions, 21 deletions
diff --git a/src/scrub-widget.c b/src/scrub-widget.c
index 925acb3..fa290e0 100644
--- a/src/scrub-widget.c
+++ b/src/scrub-widget.c
@@ -34,6 +34,7 @@ struct _ScrubWidgetPrivate
DbusmenuMenuitem* twin_item;
GtkWidget* ido_scrub_bar;
IdoTimeline* time_line;
+ gboolean scrubbing;
};
#define SCRUB_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SCRUB_WIDGET_TYPE, ScrubWidgetPrivate))
@@ -63,6 +64,12 @@ static void scrub_widget_timeline_started_cb(IdoTimeline *timeline,
gpointer userdata);
static void scrub_widget_timeline_finished_cb(IdoTimeline *timeline,
gpointer userdata);
+static gdouble scrub_widget_calculate_progress(ScrubWidget* widget);
+static void scrub_widget_check_play_state(ScrubWidget* self);
+static void scrub_widget_slider_grabbed(GtkWidget *widget, gpointer user_data);
+static void scrub_widget_slider_released(GtkWidget *widget, gpointer user_data);
+
+
G_DEFINE_TYPE (ScrubWidget, scrub_widget, G_TYPE_OBJECT);
@@ -87,8 +94,8 @@ scrub_widget_init (ScrubWidget *self)
priv->time_line = ido_timeline_new(0);
ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), IDO_SCALE_MENU_ITEM_STYLE_LABEL);
- //ido_timeline_set_fps(priv->time_line, 0.000001f);
g_object_set(priv->ido_scrub_bar, "reverse-scroll-events", TRUE, NULL);
+ priv->scrubbing = FALSE;
// register slider changes listening on the range
GtkWidget* scrub_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar);
@@ -96,7 +103,8 @@ scrub_widget_init (ScrubWidget *self)
g_signal_connect(priv->time_line, "frame", G_CALLBACK(scrub_widget_timeline_frame_cb), self);
g_signal_connect(priv->time_line, "started", G_CALLBACK(scrub_widget_timeline_started_cb), self);
g_signal_connect(priv->time_line, "finished", G_CALLBACK(scrub_widget_timeline_finished_cb), self);
-
+ g_signal_connect(priv->ido_scrub_bar, "slider-grabbed", G_CALLBACK(scrub_widget_slider_grabbed), self);
+ g_signal_connect(priv->ido_scrub_bar, "slider-released", G_CALLBACK(scrub_widget_slider_released), self);
}
static void
@@ -125,34 +133,51 @@ scrub_widget_property_update(DbusmenuMenuitem* item, gchar* property,
g_debug("scrub-widget::update length = %i", g_value_get_int(value));
ido_scale_menu_item_set_secondary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar),
scrub_widget_format_time(g_value_get_int(value)));
+
ido_timeline_set_duration(priv->time_line, g_value_get_int(value) * 1000);
+ ido_timeline_rewind(priv->time_line);
+ scrub_widget_check_play_state(mitem);
g_debug("timeline is running: %i", (gint)ido_timeline_is_running(priv->time_line));
g_debug("timeline duration = %i", ido_timeline_get_duration(priv->time_line));
+
scrub_widget_set_ido_position(mitem,
dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_POSITION)/1000,
dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION));
}
else if(g_ascii_strcasecmp(DBUSMENU_SCRUB_MENUITEM_POSITION, property) == 0){
g_debug("scrub-widget::update position = %i", g_value_get_int(value));
+ ido_timeline_pause(priv->time_line);
ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar),
scrub_widget_format_time(g_value_get_int(value)/1000));
- scrub_widget_set_ido_position(mitem,
- dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_POSITION)/1000,
- dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION));
+
+ ido_timeline_set_progress(priv->time_line, scrub_widget_calculate_progress(mitem)*1000);
+ scrub_widget_set_ido_position(mitem, g_value_get_int(value)/1000,
+ dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION));
+ ido_timeline_start(priv->time_line);
}
else if(g_ascii_strcasecmp(DBUSMENU_SCRUB_MENUITEM_PLAY_STATE, property) == 0){
- if(g_value_get_int(value) == 0){
- g_debug("START TIMELINE");
- ido_timeline_start(priv->time_line);
- }
- else{
- g_debug("PAUSE TIMELINE");
- ido_timeline_pause(priv->time_line);
- }
+ scrub_widget_check_play_state(mitem);
}
}
+static void
+scrub_widget_check_play_state(ScrubWidget* self)
+{
+ ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(self);
+ gint play_state = dbusmenu_menuitem_property_get_int(priv->twin_item,
+ DBUSMENU_SCRUB_MENUITEM_PLAY_STATE);
+
+ if(play_state == 0){
+ g_debug("START TIMELINE");
+ ido_timeline_start(priv->time_line);
+ }
+ else{
+ g_debug("PAUSE TIMELINE");
+ ido_timeline_pause(priv->time_line);
+ }
+}
+
static void
scrub_widget_set_twin_item(ScrubWidget* self,
DbusmenuMenuitem* twin_item)
@@ -167,8 +192,8 @@ scrub_widget_set_twin_item(ScrubWidget* self,
gchar* right_text = scrub_widget_format_time(dbusmenu_menuitem_property_get_int(priv->twin_item,
DBUSMENU_SCRUB_MENUITEM_DURATION));
scrub_widget_set_ido_position(self,
- dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_POSITION)/1000,
- dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION));
+ dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_POSITION)/1000,
+ dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION));
ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), left_text);
ido_scale_menu_item_set_secondary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), right_text);
@@ -182,7 +207,7 @@ scrub_widget_change_value_cb (GtkRange *range,
gdouble new_value,
gpointer user_data)
{
- g_return_val_if_fail (IS_SCRUB_WIDGET (user_data), FALSE);
+ /*g_return_val_if_fail (IS_SCRUB_WIDGET (user_data), FALSE);
ScrubWidget* mitem = SCRUB_WIDGET(user_data);
ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem);
@@ -190,8 +215,13 @@ scrub_widget_change_value_cb (GtkRange *range,
g_value_init(&value, G_TYPE_DOUBLE);
gdouble clamped = CLAMP(new_value, 0, 100);
g_value_set_double(&value, clamped);
- g_debug("scrub-widget-change-value callback - = %f", clamped);
- dbusmenu_menuitem_handle_event (priv->twin_item, "scrubbing", &value, 0);
+ //g_debug("scrub-widget-change-value callback - = %f", clamped);
+ if(priv->scrubbing == FALSE){
+ dbusmenu_menuitem_handle_event (priv->twin_item, "scrubbing", &value, 0);
+ }
+ else{
+ g_debug("blocking scrubbing because the slider is still grabbed"
+ }*/
return FALSE;
}
@@ -232,15 +262,36 @@ scrub_widget_set_ido_position(ScrubWidget* self,
gtk_range_set_value(range, ido_position);
}
+static gdouble
+scrub_widget_calculate_progress(ScrubWidget* widget)
+{
+ ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(widget);
+ gint position = dbusmenu_menuitem_property_get_int(priv->twin_item,
+ DBUSMENU_SCRUB_MENUITEM_POSITION)/1000;
+ gint duration = dbusmenu_menuitem_property_get_int(priv->twin_item,
+ DBUSMENU_SCRUB_MENUITEM_DURATION);
+ gdouble ido_position = position/(gdouble)duration;
+ g_debug("scrub_widget_calculate_progress %f", ido_position);
+
+ return ido_position;
+}
+
+
static void
scrub_widget_timeline_frame_cb( IdoTimeline *timeline,
gdouble progress,
gpointer user_data)
{
- g_debug("Timeline CB : %f", progress);
+
+ //g_debug("Timeline CB : %f", progress);
g_return_if_fail (IS_SCRUB_WIDGET (user_data));
ScrubWidget* mitem = SCRUB_WIDGET(user_data);
ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem);
+ if(priv->scrubbing == TRUE)
+ {
+ //g_debug("don't update the slider or timeline, slider is being scrubbed");
+ return;
+ }
gint position = progress * dbusmenu_menuitem_property_get_int(priv->twin_item,
DBUSMENU_SCRUB_MENUITEM_DURATION);
gchar* left_text = scrub_widget_format_time(position);
@@ -249,13 +300,39 @@ scrub_widget_timeline_frame_cb( IdoTimeline *timeline,
GtkRange *range = (GtkRange*)slider;
gtk_range_set_value(range, progress * 100);
- g_debug("position in seconds %i and in words %s", position, left_text);
+ /*g_debug("position in seconds %i and in words %s", position, left_text);
g_debug("timeline is running: %i", (gint)ido_timeline_is_running(priv->time_line));
g_debug("timeline duration = %i", ido_timeline_get_duration(priv->time_line));
-
+ */
g_free(left_text);
}
+
+static void
+scrub_widget_slider_released(GtkWidget *widget, gpointer user_data)
+{
+ ScrubWidget* mitem = SCRUB_WIDGET(user_data);
+ ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem);
+ priv->scrubbing = FALSE;
+ GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar);
+ gdouble new_value = gtk_range_get_value(GTK_RANGE(slider));
+ g_debug("okay set the scrub position with %f", new_value);
+ GValue value = {0};
+ g_value_init(&value, G_TYPE_DOUBLE);
+ gdouble clamped = CLAMP(new_value, 0, 100);
+ g_value_set_double(&value, clamped);
+ dbusmenu_menuitem_handle_event (priv->twin_item, "scrubbing", &value, 0);
+}
+
+static void
+scrub_widget_slider_grabbed(GtkWidget *widget, gpointer user_data)
+{
+ ScrubWidget* mitem = SCRUB_WIDGET(user_data);
+ ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem);
+ priv->scrubbing = TRUE;
+
+}
+
static void
scrub_widget_timeline_started_cb( IdoTimeline *timeline,
gpointer user_data)
@@ -286,3 +363,4 @@ scrub_widget_new(DbusmenuMenuitem *item)
return widget;
}
+