/* 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.Interfaces;
using Echo.UI;
using Echo.UI.Tabs;
using Echo.UI.Widgets;
public class Echo.Controller.Tabs.PlaySourceTabController
{
private static PlaySourceView _view;
public static PlaySourceTab create_tab(IPlaySource source)
{
var tab = new PlaySourceTab(source);
tab.view.context_menu.pre_popup += on_pre_popup_menu;
tab.view.context_menu.get_action("delete").activate += (action) =>
{ on_delete_pressed(_view); };
tab.view.context_menu.get_action("rating-1").activate += on_rate;
tab.view.context_menu.get_action("rating-2").activate += on_rate;
tab.view.context_menu.get_action("rating-3").activate += on_rate;
tab.view.context_menu.get_action("rating-4").activate += on_rate;
tab.view.context_menu.get_action("rating-5").activate += on_rate;
tab.view.context_menu.get_action("rating-6").activate += on_rate;
tab.view.context_menu.get_action("rating-7").activate += on_rate;
tab.view.context_menu.get_action("rating-8").activate += on_rate;
tab.view.context_menu.get_action("rating-9").activate += on_rate;
tab.view.context_menu.get_action("rating-10").activate += on_rate;
tab.view.context_menu.get_action("select-all").activate += (action) =>
{ _view.select_all(); };
tab.view.delete_pressed += on_delete_pressed;
return tab;
}
private static void on_pre_popup_menu(ContextMenu menu, GLib.Object context)
{
assert(context is PlaySourceView);
_view = (PlaySourceView)context;
var selected_tracks = _view.get_selected_indexes();
bool on_track = (selected_tracks.length > 0);
bool multiple_tracks = (selected_tracks.length > 1);
_view.context_menu.get_action("play").set_sensitive(on_track);
_view.context_menu.get_action("play").set_visible(!multiple_tracks);
_view.context_menu.get_action("play-multiple").set_visible(multiple_tracks);
_view.context_menu.get_action("add-to-playlist").set_sensitive(on_track);
_view.context_menu.get_action("delete").set_sensitive(on_track && _view.source is IModPlaySource);
_view.context_menu.get_action("open-album").set_sensitive(on_track);
_view.context_menu.get_action("open-album-in-new-tab").set_sensitive(on_track);
_view.context_menu.get_action("open-artist").set_sensitive(on_track);
_view.context_menu.get_action("open-artist-in-new-tab").set_sensitive(on_track);
_view.context_menu.get_action("select-all").set_sensitive(_view.source.get_num_tracks() > 0);
_view.context_menu.get_action("select-album").set_sensitive(on_track && !multiple_tracks);
_view.context_menu.get_action("select-artist").set_sensitive(on_track && !multiple_tracks);
}
private static void on_delete_pressed(PlaySourceView view)
{
if (_view.source is IModPlaySource) {
var indexes = view.get_selected_indexes();
for (int i = indexes.length-1; i >= 0; i--)
((IModPlaySource)view.source).remove_track(indexes[i]);
}
}
private static void on_rate(Gtk.Action action)
{
foreach(int index in _view.get_selected_indexes()) {
if (_view.source.get_track(index) is IRateableTrack) {
var track = (IRateableTrack)_view.source.get_track(index);
string actionname = action.name;
switch(actionname)
{
case "rating-1":
track.rating = 1;
break;
case "rating-2":
track.rating = 2;
break;
case "rating-3":
track.rating = 3;
break;
case "rating-4":
track.rating = 4;
break;
case "rating-5":
track.rating = 5;
break;
case "rating-6":
track.rating = 6;
break;
case "rating-7":
track.rating = 7;
break;
case "rating-8":
track.rating = 8;
break;
case "rating-9":
track.rating = 9;
break;
case "rating-10":
track.rating = 10;
break;
default:
assert_not_reached();
}
}
}
}
}