Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add button repeat #400

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/gmpv_control_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct _GmpvControlBox
GtkWidget *volume_button;
GtkWidget *fullscreen_button;
GtkWidget *seek_bar;
GtkWidget *repeat_button;
gboolean skip_enabled;
gdouble duration;
gboolean enabled;
Expand Down Expand Up @@ -240,6 +241,7 @@ static void simple_signal_handler(GtkWidget *widget, gpointer data)
signal_map[]
= { {box->play_button, "button-clicked", "play"},
{box->stop_button, "button-clicked", "stop"},
{box->repeat_button, "button-clicked", "repeat"},
{box->forward_button, "button-clicked", "forward"},
{box->rewind_button, "button-clicked", "rewind"},
{box->previous_button, "button-clicked", "previous"},
Expand All @@ -264,6 +266,7 @@ static void set_enabled(GmpvControlBox *box, gboolean enabled)
gtk_widget_set_sensitive(box->play_button, enabled);
gtk_widget_set_sensitive(box->forward_button, enabled);
gtk_widget_set_sensitive(box->next_button, enabled);
gtk_widget_set_sensitive(box->repeat_button, enabled);
}

static void set_skip_enabled(GmpvControlBox *box, gboolean enabled)
Expand Down Expand Up @@ -419,6 +422,7 @@ static void gmpv_control_box_init(GmpvControlBox *box)
box->previous_button = gtk_button_new();
box->fullscreen_button = gtk_button_new();
box->volume_button = gtk_volume_button_new();
box->repeat_button = gtk_button_new();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
box->repeat_button = gtk_button_new();
box->repeat_button = gtk_toggle_button_new();

Use toggle button here so that the user can see whether or not looping is currently enabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't looping be tri-state, loop-off, loop-current, and loop-playlist?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it's enough to have loop-off and loop-playlist for this button. This seems to be what most media players do (and presumably the most common use case).

box->seek_bar = gmpv_seek_bar_new();
box->skip_enabled = FALSE;
box->duration = 0.0;
Expand Down Expand Up @@ -446,6 +450,9 @@ static void gmpv_control_box_init(GmpvControlBox *box)
init_button( box->previous_button,
"media-skip-backward-symbolic",
_("Previous Chapter") );
init_button( box->repeat_button,
"media-playlist-repeat",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"media-playlist-repeat",
"media-playlist-repeat-symbolic",

Use tabs to indent. Also, explicitly use symbolic variant of the icon.

_("repeat") );
init_button( box->fullscreen_button,
"view-fullscreen-symbolic",
_("Toggle Fullscreen") );
Expand All @@ -463,10 +470,10 @@ static void gmpv_control_box_init(GmpvControlBox *box)
gtk_container_add(GTK_CONTAINER(box), box->stop_button);
gtk_container_add(GTK_CONTAINER(box), box->forward_button);
gtk_container_add(GTK_CONTAINER(box), box->next_button);
gtk_container_add(GTK_CONTAINER(box), box->repeat_button);
gtk_box_pack_start(GTK_BOX(box), box->seek_bar, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(box), box->volume_button);
gtk_container_add(GTK_CONTAINER(box), box->fullscreen_button);

g_object_bind_property_full( box->volume_button, "value",
box, "volume",
G_BINDING_BIDIRECTIONAL,
Expand Down Expand Up @@ -511,6 +518,10 @@ static void gmpv_control_box_init(GmpvControlBox *box)
"clicked",
G_CALLBACK(simple_signal_handler),
box );
g_signal_connect( box->repeat_button,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using click signal here, it would be better to create a new property and bind it with the loop-playlist property in GmpvModel. We can then bind the repeat button's active property to this property.

"clicked",
G_CALLBACK(simple_signal_handler),
box );
g_signal_connect( box->volume_button,
"value-changed",
G_CALLBACK(volume_changed_handler),
Expand Down
12 changes: 11 additions & 1 deletion src/gmpv_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ static void fullscreen_handler( GObject *object,
GParamSpec *pspec,
gpointer data );
static void play_button_handler(GtkButton *button, gpointer data);
static void repeat_button_handler(GtkButton *button, gpointer data);
static void stop_button_handler(GtkButton *button, gpointer data);
static void forward_button_handler(GtkButton *button, gpointer data);
static void rewind_button_handler(GtkButton *button, gpointer data);
Expand Down Expand Up @@ -496,6 +497,10 @@ static void connect_signals(GmpvController *controller)
"button-clicked::play",
G_CALLBACK(play_button_handler),
controller );
g_signal_connect( controller->view,
"button-clicked::repeat",
G_CALLBACK(repeat_button_handler),
controller );
g_signal_connect( controller->view,
"button-clicked::stop",
G_CALLBACK(stop_button_handler),
Expand Down Expand Up @@ -886,6 +891,12 @@ static void play_button_handler(GtkButton *button, gpointer data)
}
}

static void repeat_button_handler(GtkButton *button, gpointer data)
{
GmpvModel *model = GMPV_CONTROLLER(data)->model;
gmpv_model_toggle_repeat(model);
}

static void stop_button_handler(GtkButton *button, gpointer data)
{
gmpv_model_stop(GMPV_CONTROLLER(data)->model);
Expand Down Expand Up @@ -1067,4 +1078,3 @@ GmpvModel *gmpv_controller_get_model(GmpvController *controller)
{
return controller->model;
}

7 changes: 6 additions & 1 deletion src/gmpv_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,12 @@ void gmpv_model_stop(GmpvModel *model)
gmpv_mpv_command(GMPV_MPV(model->player), cmd);
}

void gmpv_model_toggle_repeat(GmpvModel *model)
{
gboolean looping = gmpv_mpv_get_property_flag(GMPV_MPV(model->player), "loop-file");
gmpv_mpv_set_property_flag(GMPV_MPV(model->player), "loop-file", !looping);
}

void gmpv_model_forward(GmpvModel *model)
{
const gchar *cmd[] = {"seek", "10", NULL};
Expand Down Expand Up @@ -1165,4 +1171,3 @@ gchar *gmpv_model_get_current_path(GmpvModel *model)

return buf;
}

1 change: 1 addition & 0 deletions src/gmpv_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void gmpv_model_reset_keys(GmpvModel *model);
void gmpv_model_play(GmpvModel *model);
void gmpv_model_pause(GmpvModel *model);
void gmpv_model_stop(GmpvModel *model);
void gmpv_model_toggle_repeat(GmpvModel *model);
void gmpv_model_forward(GmpvModel *model);
void gmpv_model_rewind(GmpvModel *model);
void gmpv_model_next_chapter(GmpvModel *model);
Expand Down