/* 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.UI.StatusIcon : Gtk.StatusIcon
{
//private Notify.Notification _popup;
private ActionManager _action_manager;
public StatusIcon(ActionManager action_manager)
{
_action_manager = action_manager;
_action_manager.add_menu("status-icon", """
<menuitem action="play-pause"/>
<menuitem action="previous-track"/>
<menuitem action="next-track"/>
<separator/>
<menuitem action="shuffle"/>
<menu action="repeat-menu">
<menuitem action="repeat-off"/>
<separator/>
<menuitem action="repeat-all"/>
<menuitem action="repeat-single"/>
</menu>
<separator/>
<menuitem action="quit"/>
""");
this.set_from_icon_name("applications-multimedia");
this.set_tooltip("Not playing\nStopped");
Services.playback().track_changed += this.on_track_changed;
this.activate += this.on_click;
this.popup_menu += this.on_menu;
}
private void on_track_changed(PlaybackService playback_service, bool is_automatic)
{
// TODO when the mouse keeps the linotify popup open and the song stops, is there a way to close
// the popup if another song isn't about to play?
if (Services.playback().current_track != null)
this.set_tooltip("%s\nby %s from %s".printf(
Services.playback().current_track.title,
Services.playback().current_track.artist,
Services.playback().current_track.album));
else
this.set_tooltip("Not playing\nStopped");
// TODO libnotify doesn't seem to work at all
// if (is_automatic) {
// string summary = playback_manager.current_track.title;
// string body = GLib.Markup.printf_escaped("by <i>%s</i> from <i>%s</i>",
// playback_manager.current_track.artist,
// playback_manager.current_track.album);
//
// if (_libnotify_popup == null) {
// _libnotify_popup = new Notify.Notification.with_status_icon(
// summary, body, null, _status_icon);
// _libnotify_popup.add_action("previous", "Previous",
// (notify, action_id) => { PlaybackManager.get().prev(); }, null);
// _libnotify_popup.add_action("next", "Next",
// (notify, action_id) => { PlaybackManager.get().next(); }, null);
// }
// else
// _libnotify_popup.update(summary, body, null);
//
// _libnotify_popup.show();
// }
}
private void on_click(Gtk.StatusIcon status_icon)
{
if (Services.ui().main_window.visible)
Services.ui().main_window.hide();
else
Services.ui().main_window.show();
}
private void on_menu(Gtk.StatusIcon status_icon, uint button, uint time)
{
_action_manager.get_menu("status-icon").popup(null, null, null, button, time);
// TODO figure out how to fix the vapi to get this working
//_menu.popup(null, null, StatusIcon.position_menu, status_icon, button, time);
//_menu.popup(null, null, status_icon_position_menu, button, time);
}
}