From 38375e2651805c356c15e82f64335faf8521ccc7 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Sun, 14 Mar 2010 22:49:32 +0100 Subject: [PATCH] Forgot to add new source --- src/app_music.vala | 169 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 src/app_music.vala diff --git a/src/app_music.vala b/src/app_music.vala new file mode 100644 index 0000000..d066e3c --- /dev/null +++ b/src/app_music.vala @@ -0,0 +1,169 @@ +/* + * app_music - zavai music player UI functions + * + * Copyright (C) 2010 Enrico Zini + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +using GLib; + +namespace zavai { +namespace ui { +namespace music { + +public class PlayPauseButton : Gtk.Button +{ + protected Gtk.Image img_play; + protected Gtk.Image img_pause; + protected bool is_play; + + construct + { + img_play = new Gtk.Image.from_stock(Gtk.STOCK_MEDIA_PLAY, Gtk.IconSize.BUTTON); + img_pause = new Gtk.Image.from_stock(Gtk.STOCK_MEDIA_PAUSE, Gtk.IconSize.BUTTON); + + clicked += on_clicked; + + is_play = audio.musicplayer.get_state() == Gst.State.PAUSED; + + audio.musicplayer.state_changed += (state) => { + if (is_play != (state == Gst.State.PAUSED)) + { + is_play = !is_play; + update_image(); + } + }; + + update_image(); + } + + protected void update_image() + { + if (is_play) + { + set_image(img_play); + } else { + set_image(img_pause); + } + } + + void on_clicked(Gtk.Button b) + { + if (is_play) + audio.musicplayer.pause(); + else + audio.musicplayer.resume(); + } +} + +public class Player : Gtk.VBox +{ + protected Gtk.Label l_status; + protected PlayPauseButton b_playpause; + protected Gtk.Button b_stop; + protected Gtk.Button b_prev; + protected Gtk.Button b_next; + + construct + { + l_status = new Gtk.Label(""); + //l_date.modify_font(Pango.FontDescription.from_string("Sans 40")); + b_playpause = new PlayPauseButton(); + b_stop = new Gtk.Button.from_stock(Gtk.STOCK_MEDIA_STOP); + b_stop.clicked += (b) => { audio.musicplayer.stop(); }; + b_prev = new Gtk.Button.from_stock(Gtk.STOCK_MEDIA_PREVIOUS); + b_next = new Gtk.Button.from_stock(Gtk.STOCK_MEDIA_NEXT); + pack_start(l_status, false, false, 0); + var buttons = new Gtk.HButtonBox(); + buttons.add(b_prev); + buttons.add(b_playpause); + buttons.add(b_stop); + buttons.add(b_next); + pack_start(buttons, false, false, 0); + + //zavai.clock.clock.minute_changed += on_minute_changed; + //zavai.clock.clock.schedule_changed += on_schedule_changed; + //on_schedule_changed(zavai.clock.clock.next_alarm()); + } + +#if 0 + private void on_date_clicked(Gtk.Button b) + { + zavai.app.push_applet(zavai.ui.calendar.calendar); + } + + private void on_schedule_changed(zavai.clock.Alarm? next) + { + if (next == null) + { + last_deadline = 0; + last_deadline_label = ""; + } else { + last_deadline = next.ev.deadline; + last_deadline_label = next.label; + } + on_minute_changed((long)last_time, last_time_type); + } + + private void on_minute_changed(long ts, zavai.clock.SourceType type) + { + last_time = (time_t)ts; + last_time_type = type; + + string typetag = "unknown"; + switch (type) + { + case zavai.clock.SourceType.GPS: + typetag = "gps"; + break; + case zavai.clock.SourceType.SYSTEM: + typetag = "sys"; + break; + } + + var t = Time.local((time_t)ts); + l_date.set_text(t.format("%a %d %b")); + l_time.set_text("%2d:%02d (%s)".printf(t.hour, t.minute, typetag)); + + if (last_deadline == 0) + l_deadline.set_text(""); + else + { + int remaining = (int)(last_deadline - last_time); + int hours = remaining / 3600; + int minutes = (remaining % 3600) / 60; + if (hours == 0 && minutes == 0) + l_deadline.set_text(last_deadline_label + "\nanytime now"); + else + l_deadline.set_text("%s\nin %02dh %02dm".printf(last_deadline_label, hours, minutes)); + } + } +#endif +} + +public Player player = null; + +public void init() +{ + player = new Player(); + // Menus + //zavai.menu_gsm.add_service_toggle(zavai.gsm.gsm, "Start GSM", "Stop GSM"); + //zavai.menu_gsm.add_service_toggle(zavai.gsm.gprs, "Start GPRS", "Stop GPRS"); +} + +} +} +} -- 2.39.5