MicroBreakType.vala 2.99 KB
Newer Older
1
/*
2
 * This file is part of GNOME Break Timer.
3
 * 
4
 * GNOME Break Timer is free software: you can redistribute it and/or modify
5 6 7 8
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
9
 * GNOME Break Timer is distributed in the hope that it will be useful,
10 11 12 13 14
 * 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
15
 * along with GNOME Break Timer.  If not, see <http://www.gnu.org/licenses/>.
16 17
 */

18
public class MicroBreakType : TimerBreakType {
19 20 21
	public MicroBreakType () {
		Settings settings = new Settings ("org.gnome.break-timer.microbreak");
		base ("microbreak", settings);
22

23 24
		this.interval_options = { 240, 300, 360, 480, 600 };
		this.duration_options = { 15, 30, 45, 60 };
25
	}
26

27 28
	protected override BreakInfoPanel get_info_panel () {
		return new MicroBreakInfoPanel (this);
29
	}
30

31 32
	protected override BreakStatusPanel get_status_panel () {
		return new MicroBreakStatusPanel (this);
33
	}
34
	
35 36
	protected override BreakSettingsPanel get_settings_panel () {
		return new MicroBreakSettingsPanel (this);
37 38 39
	}
}

40
class MicroBreakInfoPanel : BreakInfoPanel {
41
	private TimerBreakStatus? status;
42

43 44
	public MicroBreakInfoPanel (MicroBreakType break_type) {
		base (
45 46 47 48
			break_type,
			_("Microbreak")
		);

49
		break_type.timer_status_changed.connect (this.timer_status_changed_cb);
50 51
	}

52
	private void timer_status_changed_cb (TimerBreakStatus? status) {
53
		this.status = status;
54
		this.update_description ();
55 56
	}

57
	private void update_description () {
58
		if (this.status == null) return;
59

60 61 62 63 64 65 66 67 68 69 70 71 72
		int time_remaining_value;
		string time_remaining_text = NaturalTime.instance.get_countdown_for_seconds_with_start (
			this.status.time_remaining, this.status.current_duration, out time_remaining_value);
		string description_text = ngettext (
			/* %s will be replaced with a string that describes a time interval, such as "2 minutes", "40 seconds" or "1 hour" */
			"Take a break from typing and look away from the screen for %s.",
			"Take a break from typing and look away from the screen for %s.",
			time_remaining_value
		).printf (time_remaining_text);

		this.set_heading ( _("It’s microbreak time"));
		this.set_description (description_text);
		this.set_detail (_("I'll chime when it’s time to use the computer again."));
73 74 75
	}
}

76
class MicroBreakStatusPanel : TimerBreakStatusPanel {
77 78
	public MicroBreakStatusPanel (MicroBreakType break_type) {
		base (
79
			break_type,
80
			/* Label that explains a countdown timer, which shows a string such as "5 minutes" */
81 82 83 84 85 86 87
			_("Your next microbreak is in"),
			_("It's time for a microbreak")
		);
	}
}

class MicroBreakSettingsPanel : TimerBreakSettingsPanel {
88 89
	public MicroBreakSettingsPanel (MicroBreakType break_type) {
		base (
90
			break_type,
91
			_("Microbreak"),
92 93 94
			_("Pause frequently to relax your eyes")
		);
	}
95
}