/* vim: set noexpandtab tabstop=4 shiftwidth=4 nowrap textwidth=100
*
* Echo Media Player
* Copyright (C) 2008 Shane O'Connell
*
* [ The original file includes a copyright header in this location describing
* the file as being released under the terms of the GNU General Public
* License. It has been removed in order to display the file as part of the
* archive. ]
*/
using Echo.Core;
using Echo.Playback;
using Echo.UI;
public class Echo.Controller.Actions.PlaybackActions : GLib.Object
{
public PlaybackActions()
{
// Playback menu
Services.ui().get_action("play-pause").activate += this.on_play_pause;
Services.ui().get_action("next-track").activate += this.on_next_track;
Services.ui().get_action("previous-track").activate += this.on_previous_track;
//_action_group.add_action(new Gtk.Action("stop-when-finished", "Stop When _Finished", null, null));
// Repeat menu
//((Gtk.RadioAction)Services.ui().get_action("repeat-off")).changed += this.on_set_repeat;
// Shuffle menu
((Gtk.ToggleAction)Services.ui().get_action("shuffle")).activate += this.on_set_shuffle;
// Connect signals that update actions:
Services.playback().state_changed += this.on_playback_state_changed;
}
private void on_play_pause(Gtk.Action action)
{
// TODO vala bug: the .current_state line cannot be used in the switch() directly
var state = Services.playback().current_state;
switch (state)
{
case PlaybackState.PLAYING:
case PlaybackState.BUFFERING:
Services.playback().pause();
break;
case PlaybackState.PAUSED:
Services.playback().unpause();
break;
case PlaybackState.STOPPED:
break; // TODO make this do something
default:
assert_not_reached(); // Should never happen unless a new playback state is added
}
}
private void on_next_track(Gtk.Action action)
{
Services.playback().next();
}
private void on_previous_track(Gtk.Action action)
{
Services.playback().prev();
}
private void on_set_shuffle(Gtk.ToggleAction action)
{
var next_track_action = Services.ui().get_action("next-track");
if (action.active) {
Services.playback().set_shuffle(ShuffleType.ALL);
next_track_action.set("stock-id", null);
next_track_action.set("icon-name", "media-playlist-shuffle");
}
else {
Services.playback().set_shuffle(ShuffleType.NONE);
next_track_action.set("stock-id", "gtk-media-next");
next_track_action.set("icon-name", null);
}
/*
switch(action.get_current_value())
{
case UIService.ShuffleValue.OFF:
Services.playback().set_shuffle(ShuffleType.NONE);
next_track_action.set("stock-id", "gtk-media-next");
next_track_action.set("icon-name", null);
break;
case UIService.ShuffleValue.ALL:
case UIService.ShuffleValue.BY_ARTIST:
case UIService.ShuffleValue.BY_ALBUM:
Services.playback().set_shuffle(ShuffleType.ALL);
next_track_action.set("stock-id", null);
next_track_action.set("icon-name", "media-playlist-shuffle");
break;
default:
assert_not_reached();
}*/
}
private void on_playback_state_changed(PlaybackService playback_service)
{
// FIXME vala bug prevents us from using the property in the switch() directly
var state = Services.playback().current_state;
switch (state)
{
case PlaybackState.PLAYING:
case PlaybackState.BUFFERING:
Services.ui().get_action("play-pause").set("stock-id", "gtk-media-pause");
break;
case PlaybackState.PAUSED:
case PlaybackState.STOPPED:
Services.ui().get_action("play-pause").set("stock-id", "gtk-media-play");
break;
default:
assert_not_reached(); // Should never happen unless a new playback state is added
}
}
}