Commit 0b45b267 authored by Tristan Matthews's avatar Tristan Matthews

* #14412: seekslider: cleanup

parent d9746cd8
......@@ -62,19 +62,19 @@
#define SEEKSLIDER_PAGEINCREMENT 1.0
#define SEEKSLIDER_PAGESIZE 1.0
static void sfl_seekslider_class_init (SFLSeekSliderClass *klass);
static void sfl_seekslider_init (SFLSeekSlider *seekslider);
static void sfl_seekslider_finalize (GObject *object);
static void sfl_seekslider_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void sfl_seekslider_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static void sfl_seekslider_class_init(SFLSeekSliderClass *klass);
static void sfl_seekslider_init(SFLSeekSlider *seekslider);
static void sfl_seekslider_finalize(GObject *object);
static void sfl_seekslider_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void sfl_seekslider_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static gboolean on_playback_scale_value_changed_cb(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer user_data);
static gboolean on_playback_scale_pressed_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
static gboolean on_playback_scale_released_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
static gboolean on_playback_scale_moved_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data);
static gboolean on_playback_scale_scrolled_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data);
static void sfl_seekslider_play_playback_record_cb (GtkButton *button G_GNUC_UNUSED, gpointer user_data);
static void sfl_seekslider_stop_playback_record_cb (GtkButton *button G_GNUC_UNUSED, gpointer user_data);
static void sfl_seekslider_play_playback_record_cb(GtkButton *button G_GNUC_UNUSED, gpointer user_data);
static void sfl_seekslider_stop_playback_record_cb(GtkButton *button G_GNUC_UNUSED, gpointer user_data);
struct SFLSeekSliderPrivate
{
......@@ -99,90 +99,72 @@ enum
PROP_0,
};
G_DEFINE_TYPE (SFLSeekSlider, sfl_seekslider, GTK_TYPE_HBOX)
G_DEFINE_TYPE(SFLSeekSlider, sfl_seekslider, GTK_TYPE_HBOX)
static void
sfl_seekslider_class_init (SFLSeekSliderClass *klass)
sfl_seekslider_class_init(SFLSeekSliderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->finalize = sfl_seekslider_finalize;
object_class->set_property = sfl_seekslider_set_property;
object_class->get_property = sfl_seekslider_get_property;
g_type_class_add_private (klass, sizeof (SFLSeekSliderPrivate));
g_type_class_add_private(klass, sizeof(SFLSeekSliderPrivate));
}
static void
sfl_seekslider_init (SFLSeekSlider *seekslider)
sfl_seekslider_init(SFLSeekSlider *seekslider)
{
seekslider->priv = G_TYPE_INSTANCE_GET_PRIVATE (seekslider, SFL_TYPE_SEEKSLIDER, SFLSeekSliderPrivate);
seekslider->priv = G_TYPE_INSTANCE_GET_PRIVATE(seekslider, SFL_TYPE_SEEKSLIDER, SFLSeekSliderPrivate);
gdouble init_value = SEEKSLIDER_INIT_VALUE;
gdouble min_value = SEEKSLIDER_MIN_VALUE;
gdouble max_value = SEEKSLIDER_MAX_VALUE;
gdouble init_value = SEEKSLIDER_INIT_VALUE;
gdouble min_value = SEEKSLIDER_MIN_VALUE;
gdouble max_value = SEEKSLIDER_MAX_VALUE;
gdouble stepincrement = SEEKSLIDER_STEPINCREMENT;
gdouble pageincrement = SEEKSLIDER_PAGEINCREMENT;
gdouble pagesize = SEEKSLIDER_PAGESIZE;
gdouble pagesize = SEEKSLIDER_PAGESIZE;
GtkAdjustment *adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(init_value, min_value, max_value, stepincrement, pageincrement, pagesize));
if (adjustment == NULL)
WARN("Invalid adjustment value for horizontal scale in seekslider");
GtkAdjustment *adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(init_value,
min_value, max_value, stepincrement, pageincrement, pagesize));
seekslider->priv->hscale = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, adjustment);
if (seekslider->priv->hscale == NULL)
WARN("Could not create new horizontal scale for seekslider");
seekslider->priv->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
if(seekslider->priv->hbox == NULL)
WARN("Could not create new horizontal box for seekslider");
seekslider->priv->playRecordImage = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON);
seekslider->priv->playRecordWidget = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(seekslider->priv->playRecordWidget), seekslider->priv->playRecordImage);
if(seekslider->priv->playRecordWidget == NULL)
WARN("Could not create new playback button for seekslider");
seekslider->priv->stopRecordImage = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_BUTTON);
seekslider->priv->stopRecordWidget = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(seekslider->priv->stopRecordWidget), seekslider->priv->stopRecordImage);
if(seekslider->priv->stopRecordWidget == NULL)
WARN("Could not create mew pause button for seekslider");
seekslider->priv->separator = gtk_separator_new(GTK_ORIENTATION_VERTICAL);
if(seekslider->priv->separator == NULL)
WARN("Could not create the separator for seekslider");
seekslider->priv->timeLabel = gtk_label_new("");
if(seekslider->priv->timeLabel == NULL)
WARN("Could not create the time label");
seekslider->priv->separatorAlign = gtk_alignment_new(1.0, 0.75, 1.0, 1.0);
if(seekslider->priv->separatorAlign == NULL)
WARN("Could not create the separator's alignment");
g_signal_connect(G_OBJECT(seekslider->priv->hscale), "change-value",
G_CALLBACK(on_playback_scale_value_changed_cb), seekslider);
g_signal_connect_object(G_OBJECT (seekslider->priv->hscale), "button-press-event",
G_CALLBACK (on_playback_scale_pressed_cb), seekslider, 0);
G_CALLBACK(on_playback_scale_pressed_cb), seekslider, 0);
g_signal_connect_object(G_OBJECT (seekslider->priv->hscale), "button-release-event",
G_CALLBACK (on_playback_scale_released_cb), seekslider, 0);
G_CALLBACK(on_playback_scale_released_cb), seekslider, 0);
g_signal_connect_object(G_OBJECT (seekslider->priv->hscale), "motion-notify-event",
G_CALLBACK (on_playback_scale_moved_cb), seekslider, 0);
G_CALLBACK(on_playback_scale_moved_cb), seekslider, 0);
g_signal_connect_object (G_OBJECT (seekslider->priv->hscale), "scroll-event",
G_CALLBACK (on_playback_scale_scrolled_cb), seekslider, 0);
G_CALLBACK(on_playback_scale_scrolled_cb), seekslider, 0);
g_object_set(G_OBJECT(seekslider->priv->hscale), "draw-value", FALSE, NULL);
g_signal_connect_object (G_OBJECT (seekslider->priv->playRecordWidget), "pressed",
g_signal_connect_object(G_OBJECT(seekslider->priv->playRecordWidget), "pressed",
G_CALLBACK(sfl_seekslider_play_playback_record_cb), seekslider, 0);
g_signal_connect_object (G_OBJECT (seekslider->priv->stopRecordWidget), "pressed",
g_signal_connect_object(G_OBJECT(seekslider->priv->stopRecordWidget), "pressed",
G_CALLBACK(sfl_seekslider_stop_playback_record_cb), seekslider, 0);
gtk_container_add(GTK_CONTAINER(seekslider->priv->separatorAlign), seekslider->priv->separator);
......@@ -192,12 +174,12 @@ sfl_seekslider_init (SFLSeekSlider *seekslider)
gtk_box_pack_start(GTK_BOX(seekslider->priv->hbox), seekslider->priv->hscale, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(seekslider->priv->hbox), seekslider->priv->timeLabel, FALSE, TRUE, 0);
gtk_widget_show (seekslider->priv->hbox);
gtk_widget_show (seekslider->priv->hscale);
gtk_widget_show (seekslider->priv->separatorAlign);
gtk_widget_show (seekslider->priv->separator);
gtk_widget_hide (seekslider->priv->playRecordWidget);
gtk_widget_hide (seekslider->priv->stopRecordWidget);
gtk_widget_show(seekslider->priv->hbox);
gtk_widget_show(seekslider->priv->hscale);
gtk_widget_show(seekslider->priv->separatorAlign);
gtk_widget_show(seekslider->priv->separator);
gtk_widget_hide(seekslider->priv->playRecordWidget);
gtk_widget_hide(seekslider->priv->stopRecordWidget);
gtk_box_pack_start(GTK_BOX(&seekslider->parent), seekslider->priv->hbox, TRUE, TRUE, 0);
......@@ -210,38 +192,30 @@ sfl_seekslider_init (SFLSeekSlider *seekslider)
}
static void
sfl_seekslider_finalize (GObject *object)
sfl_seekslider_finalize(GObject *object)
{
SFLSeekSlider *seekslider;
g_return_if_fail (object != NULL);
g_return_if_fail (SFL_IS_SEEKSLIDER (object));
g_return_if_fail(object != NULL);
g_return_if_fail(SFL_IS_SEEKSLIDER(object));
seekslider = SFL_SEEKSLIDER (object);
g_return_if_fail (seekslider->priv != NULL);
seekslider = SFL_SEEKSLIDER(object);
g_return_if_fail(seekslider->priv != NULL);
G_OBJECT_CLASS (sfl_seekslider_parent_class)->finalize (object);
G_OBJECT_CLASS(sfl_seekslider_parent_class)->finalize(object);
}
static void
sfl_seekslider_set_property (GObject *object, guint prop_id, const GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
{
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
static void
sfl_seekslider_get_property (GObject *object, guint prop_id, GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
{
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
/**
......@@ -256,11 +230,9 @@ sfl_seekslider_get_property (GObject *object, guint prop_id, GValue *value G_GNU
SFLSeekSlider *
sfl_seekslider_new ()
{
SFLSeekSlider *seekslider;
SFLSeekSlider *seekslider = SFL_SEEKSLIDER(g_object_new(SFL_TYPE_SEEKSLIDER, NULL));
seekslider = SFL_SEEKSLIDER (g_object_new (SFL_TYPE_SEEKSLIDER, NULL));
g_return_val_if_fail (seekslider->priv != NULL, NULL);
g_return_val_if_fail(seekslider->priv != NULL, NULL);
return seekslider;
}
......@@ -268,11 +240,11 @@ sfl_seekslider_new ()
static gboolean
on_playback_scale_value_changed_cb(GtkRange *range G_GNUC_UNUSED, GtkScrollType scroll G_GNUC_UNUSED, gdouble value, gpointer user_data G_GNUC_UNUSED)
{
SFLSeekSlider *seekslider = (SFLSeekSlider *)user_data;
SFLSeekSlider *seekslider = SFL_SEEKSLIDER(user_data);
dbus_set_record_playback_seek(value);
guint updated_current = (guint)((seekslider->priv->size * value) / 100.0);
guint updated_current = (guint) ((seekslider->priv->size * value) / 100.0);
sfl_seekslider_update_timelabel(seekslider, updated_current, seekslider->priv->size);
return FALSE;
......@@ -284,9 +256,8 @@ on_playback_scale_pressed_cb(GtkWidget *widget G_GNUC_UNUSED, GdkEventButton *ev
if (event->button == 1)
event->button = 2;
SFLSeekSlider *seekslider = (SFLSeekSlider *)user_data;
SFLSeekSlider *seekslider = SFL_SEEKSLIDER(user_data);
seekslider->priv->can_update_scale = FALSE;
seekslider->priv->is_dragging = TRUE;
return FALSE;
......@@ -298,7 +269,7 @@ on_playback_scale_released_cb(GtkWidget *widget G_GNUC_UNUSED, GdkEventButton *e
if (event->button == 1)
event->button = 2;
SFLSeekSlider *seekslider = (SFLSeekSlider *)user_data;
SFLSeekSlider *seekslider = SFL_SEEKSLIDER(user_data);
seekslider->priv->can_update_scale = TRUE;
seekslider->priv->is_dragging = FALSE;
......@@ -309,9 +280,9 @@ on_playback_scale_released_cb(GtkWidget *widget G_GNUC_UNUSED, GdkEventButton *e
static gboolean
on_playback_scale_moved_cb(GtkWidget *widget, GdkEvent *event G_GNUC_UNUSED, gpointer user_data)
{
SFLSeekSlider *seekslider = (SFLSeekSlider *)user_data;
SFLSeekSlider *seekslider = SFL_SEEKSLIDER(user_data);
if(seekslider->priv->is_dragging == FALSE)
if (seekslider->priv->is_dragging == FALSE)
return FALSE;
gdouble value = gtk_range_get_value(GTK_RANGE(widget));
......@@ -330,7 +301,7 @@ on_playback_scale_scrolled_cb(GtkWidget *widget G_GNUC_UNUSED, GdkEvent *event G
static void sfl_seekslider_play_playback_record_cb (GtkButton *button G_GNUC_UNUSED, gpointer user_data)
{
SFLSeekSlider *seekslider = (SFLSeekSlider *)user_data;
SFLSeekSlider *seekslider = SFL_SEEKSLIDER(user_data);
callable_obj_t *selectedCall = calltab_get_selected_call(history_tab);
if (selectedCall == NULL)
......@@ -346,7 +317,7 @@ static void sfl_seekslider_play_playback_record_cb (GtkButton *button G_GNUC_UNU
static void sfl_seekslider_stop_playback_record_cb (GtkButton *button G_GNUC_UNUSED, gpointer user_data)
{
SFLSeekSlider *seekslider = (SFLSeekSlider *) user_data;
SFLSeekSlider *seekslider = SFL_SEEKSLIDER(user_data);
callable_obj_t *selectedCall = calltab_get_selected_call(history_tab);
if (selectedCall == NULL)
......@@ -373,10 +344,10 @@ void sfl_seekslider_update_timelabel(SFLSeekSlider *seekslider, guint current, g
current_sec = current_sec % 60;
size_sec = size_sec % 60;
if(seekslider == NULL)
if (seekslider == NULL)
return;
if(size > 0)
if (size > 0)
g_snprintf(buf, 20, "%d:%02d / %d:%02d", current_min, current_sec, size_min, size_sec);
else
g_snprintf(buf, 20, "%s", "");
......@@ -386,7 +357,7 @@ void sfl_seekslider_update_timelabel(SFLSeekSlider *seekslider, guint current, g
void sfl_seekslider_update_scale(SFLSeekSlider *seekslider, guint current, guint size)
{
if(seekslider == NULL)
if (seekslider == NULL)
return;
if (size == 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment