2 * app_music - zavai music player UI functions
4 * Copyright (C) 2010 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 public class PlayPauseButton : Gtk.Button
29 protected Gtk.Image img_play;
30 protected Gtk.Image img_pause;
31 protected bool is_play;
35 img_play = new Gtk.Image.from_stock(Gtk.STOCK_MEDIA_PLAY, Gtk.IconSize.BUTTON);
36 img_pause = new Gtk.Image.from_stock(Gtk.STOCK_MEDIA_PAUSE, Gtk.IconSize.BUTTON);
38 clicked += on_clicked;
40 is_play = audio.musicplayer.get_state() == Gst.State.PAUSED;
42 audio.musicplayer.state_changed += (state) => {
43 if (is_play != (state == Gst.State.PAUSED))
53 protected void update_image()
63 void on_clicked(Gtk.Button b)
66 audio.musicplayer.pause();
68 audio.musicplayer.resume();
72 public class Player : Gtk.VBox
74 protected Gtk.Label l_status;
75 protected PlayPauseButton b_playpause;
76 //protected Gtk.Button b_stop;
77 protected Gtk.Button b_prev;
78 protected Gtk.Button b_next;
82 l_status = new Gtk.Label("");
83 //l_date.modify_font(Pango.FontDescription.from_string("Sans 40"));
84 b_playpause = new PlayPauseButton();
85 //b_stop = new Gtk.Button.from_stock(Gtk.STOCK_MEDIA_STOP);
86 //b_stop.clicked += (b) => { audio.musicplayer.stop(); };
87 b_prev = new Gtk.Button.from_stock(Gtk.STOCK_MEDIA_PREVIOUS);
88 b_next = new Gtk.Button.from_stock(Gtk.STOCK_MEDIA_NEXT);
89 pack_start(l_status, false, false, 0);
90 var buttons = new Gtk.HButtonBox();
92 buttons.add(b_playpause);
93 //buttons.add(b_stop);
95 pack_start(buttons, false, false, 0);
97 //zavai.clock.clock.minute_changed += on_minute_changed;
98 //zavai.clock.clock.schedule_changed += on_schedule_changed;
99 //on_schedule_changed(zavai.clock.clock.next_alarm());
103 private void on_date_clicked(Gtk.Button b)
105 zavai.app.push_applet(zavai.ui.calendar.calendar);
108 private void on_schedule_changed(zavai.clock.Alarm? next)
113 last_deadline_label = "";
115 last_deadline = next.ev.deadline;
116 last_deadline_label = next.label;
118 on_minute_changed((long)last_time, last_time_type);
121 private void on_minute_changed(long ts, zavai.clock.SourceType type)
123 last_time = (time_t)ts;
124 last_time_type = type;
126 string typetag = "unknown";
129 case zavai.clock.SourceType.GPS:
132 case zavai.clock.SourceType.SYSTEM:
137 var t = Time.local((time_t)ts);
138 l_date.set_text(t.format("%a %d %b"));
139 l_time.set_text("%2d:%02d (%s)".printf(t.hour, t.minute, typetag));
141 if (last_deadline == 0)
142 l_deadline.set_text("");
145 int remaining = (int)(last_deadline - last_time);
146 int hours = remaining / 3600;
147 int minutes = (remaining % 3600) / 60;
148 if (hours == 0 && minutes == 0)
149 l_deadline.set_text(last_deadline_label + "\nanytime now");
151 l_deadline.set_text("%s\nin %02dh %02dm".printf(last_deadline_label, hours, minutes));
157 public Player player = null;
161 player = new Player();
163 //zavai.menu_gsm.add_service_toggle(zavai.gsm.gsm, "Start GSM", "Stop GSM");
164 //zavai.menu_gsm.add_service_toggle(zavai.gsm.gprs, "Start GPRS", "Stop GPRS");