Commit 2b4c4e0a authored by Dylan McCall's avatar Dylan McCall

Split BreakPanel and BreakType in a way that mirrors the break helper.

parent 43e30eae
......@@ -70,13 +70,15 @@ targets:
input:
- ApplicationPanel.vala
- BreakPanel.vala
- BreakType.vala
- main.vala
- MicroBreakPanel.vala
- MicroBreakType.vala
- NaturalTime.vala
- RestBreakPanel.vala
- RestBreakType.vala
- SettingsDialog.vala
- TimeChooser.vala
- TimerBreakPanel.vala
- TimerBreakType.vala
defines:
- GETTEXT_PACKAGE="brainbreak"
packages:
......
......@@ -24,10 +24,10 @@ public class ApplicationPanel : Gtk.Grid {
private Gtk.InfoBar app_not_running_info_bar;
public ApplicationPanel(Settings settings) {
public ApplicationPanel() {
Object();
this.settings = settings;
this.settings = new Settings("org.brainbreak.breaks");
this.app_not_running_info_bar = new AppNotRunningInfoBar();
......
......@@ -15,30 +15,20 @@
* along with Brain Break. If not, see <http://www.gnu.org/licenses/>.
*/
// FIXME: break this into model / view
public abstract class BreakPanel : Gtk.Grid {
public string break_name {get; private set;}
public string break_id {get; private set;}
public bool enabled {get; set; default=true;}
protected Settings settings;
protected BreakType break_type;
protected int[] interval_options;
private Gtk.Widget header_grid;
private Gtk.Switch break_switch;
private Gtk.Container details_grid;
public BreakPanel(Settings settings, string break_id, string break_name, int[] interval_options) {
public Gtk.Switch toggle_switch;
public BreakPanel(BreakType break_type, int[] interval_options) {
Object();
this.settings = settings;
this.break_id = break_id;
this.break_name = break_name;
this.break_type = break_type;
this.interval_options = interval_options;
this.set_row_spacing(4);
......@@ -51,17 +41,15 @@ public abstract class BreakPanel : Gtk.Grid {
this.details_grid.set_margin_left(12);
this.attach_next_to(this.details_grid, this.header_grid, Gtk.PositionType.BOTTOM, 1, 1);
this.notify["enabled"].connect((s, p) => {
this.details_grid.set_sensitive(this.enabled);
this.break_switch.set_active(this.enabled);
});
this.settings.bind("enabled", this, "enabled", SettingsBindFlags.DEFAULT);
this.show_all();
this.toggle_switch.notify["active"].connect((s, p) => {
this.details_grid.sensitive = this.toggle_switch.active;
this.toggle_switch.active = this.toggle_switch.active;
});
}
public Gtk.Widget get_settings_widget() {
public Gtk.Widget get_break_type_widget() {
return this;
}
......@@ -72,24 +60,18 @@ public abstract class BreakPanel : Gtk.Grid {
private Gtk.Widget build_header_grid_widget() {
Gtk.Grid header_grid = new Gtk.Grid();
Gtk.Label break_label = new Gtk.Label.with_mnemonic(this.break_name);
Gtk.Label break_label = new Gtk.Label.with_mnemonic(this.break_type.name);
break_label.set_halign(Gtk.Align.END);
break_label.set_margin_right(12);
break_label.get_style_context().add_class("brainbreak-settings-break-title");
header_grid.attach(break_label, 0, 0, 1, 1);
Gtk.Switch break_switch = new Gtk.Switch();
this.break_switch = break_switch;
break_switch.set_hexpand(true);
break_switch.set_halign(Gtk.Align.END);
header_grid.attach_next_to(break_switch, break_label, Gtk.PositionType.RIGHT, 1, 1);
break_label.set_mnemonic_widget(break_switch);
// FIXME: note the horror of having all these enabled properties in one place
// this is best fixed by splitting BreakPanel from its back-end settings
this.break_switch.notify["active"].connect((s, p) => {
this.enabled = this.break_switch.active;
});
Gtk.Switch toggle_switch = new Gtk.Switch();
this.toggle_switch = toggle_switch;
toggle_switch.set_hexpand(true);
toggle_switch.set_halign(Gtk.Align.END);
header_grid.attach_next_to(toggle_switch, break_label, Gtk.PositionType.RIGHT, 1, 1);
break_label.set_mnemonic_widget(toggle_switch);
header_grid.show_all();
......
/*
* This file is part of Brain Break.
*
* Brain Break 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 3 of the License, or
* (at your option) any later version.
*
* Brain Break 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 Brain Break. If not, see <http://www.gnu.org/licenses/>.
*/
public abstract class BreakType : Object {
protected Settings settings;
public string name {get; private set;}
public bool enabled {get; set; default=true;}
public int interval {get; set;}
public BreakType(Settings settings, string name) {
this.settings = settings;
this.name = name;
this.settings.bind("enabled", this, "enabled", SettingsBindFlags.DEFAULT);
this.settings.bind("interval-seconds", this, "interval", SettingsBindFlags.DEFAULT);
}
public abstract Gtk.Widget make_settings_panel();
protected void bind_to_settings_panel(BreakPanel panel) {
this.settings.bind("enabled", panel.toggle_switch, "active", SettingsBindFlags.DEFAULT);
}
}
......@@ -15,13 +15,21 @@
* along with Brain Break. If not, see <http://www.gnu.org/licenses/>.
*/
public class MicroBreakPanel : TimerBreakPanel {
public MicroBreakPanel(Settings breaks_settings) {
Settings settings = breaks_settings.get_child("microbreak");
public class MicroBreakType : TimerBreakType {
public MicroBreakType() {
Settings settings = new Settings("org.brainbreak.breaks.microbreak");
string name = _("Micro break");
base(settings, name);
}
public override Gtk.Widget make_settings_panel() {
int[] interval_options = {480, 600, 720, 900};
int[] duration_options = {15, 20, 30, 45, 60};
TimerBreakPanel panel = new TimerBreakPanel(this, interval_options, duration_options);
this.bind_to_settings_panel(panel);
base(settings, "microbreak", _("Micro break"),
{480, 600, 720, 900},
{15, 20, 30, 45, 60});
return panel;
}
}
......@@ -15,13 +15,21 @@
* along with Brain Break. If not, see <http://www.gnu.org/licenses/>.
*/
public class RestBreakPanel : TimerBreakPanel {
public RestBreakPanel(Settings breaks_settings) {
Settings settings = breaks_settings.get_child("restbreak");
public class RestBreakType : TimerBreakType {
public RestBreakType() {
Settings settings = new Settings("org.brainbreak.breaks.restbreak");
string name = _("Rest break");
base(settings, name);
}
public override Gtk.Widget make_settings_panel() {
int[] interval_options = {1800, 2400, 3000, 3600};
int[] duration_options = {300, 360, 420, 480, 540, 600};
TimerBreakPanel panel = new TimerBreakPanel(this, interval_options, duration_options);
this.bind_to_settings_panel(panel);
base(settings, "restbreak", _("Rest break"),
{1800, 2400, 3000, 3600},
{300, 360, 420, 480, 540, 600});
return panel;
}
}
......@@ -16,17 +16,15 @@
*/
public class SettingsDialog : Gtk.Dialog {
private Settings settings;
private ApplicationPanel application_panel;
private BreakPanel[] break_panels;
private BreakType[] break_types;
private static const int ABOUT_BUTTON_RESPONSE = 5;
public SettingsDialog(Settings settings) {
public SettingsDialog(BreakType[] break_types) {
Object();
this.settings = settings;
this.break_types = break_types;
this.set_title(_("Break Settings"));
this.set_resizable(false);
......@@ -37,7 +35,7 @@ public class SettingsDialog : Gtk.Dialog {
Gtk.Box content = (Gtk.Box) this.get_content_area();
this.application_panel = new ApplicationPanel(settings);
this.application_panel = new ApplicationPanel();
Gtk.Widget status_widget = application_panel.get_status_widget();
content.add(this.application_panel);
......@@ -47,16 +45,13 @@ public class SettingsDialog : Gtk.Dialog {
content.add(breaks_grid);
int insert_row = 0;
this.break_panels = {
new RestBreakPanel(settings),
new MicroBreakPanel(settings)
};
foreach (BreakPanel panel in this.break_panels) {
panel.notify["enabled"].connect((s, p) => {
foreach (BreakType break_type in this.break_types) {
break_type.notify["enabled"].connect((s, p) => {
this.on_break_disabled();
});
Gtk.Widget settings_widget = panel.get_settings_widget();
breaks_grid.attach(settings_widget, 0, insert_row, 1, 1);
Gtk.Widget settings_panel = break_type.make_settings_panel();
breaks_grid.attach(settings_panel, 0, insert_row, 1, 1);
insert_row += 1;
}
......@@ -68,8 +63,8 @@ public class SettingsDialog : Gtk.Dialog {
private void on_break_disabled() {
bool any_enabled = false;
foreach (BreakPanel panel in this.break_panels) {
if (panel.enabled) any_enabled = true;
foreach (BreakType break_type in this.break_types) {
if (break_type.enabled) any_enabled = true;
}
this.application_panel.master_enabled = any_enabled;
}
......
......@@ -18,12 +18,11 @@
public class TimerBreakPanel : BreakPanel {
protected int[] duration_options;
TimeChooser interval_chooser;
TimeChooser duration_chooser;
public TimeChooser interval_chooser;
public TimeChooser duration_chooser;
public TimerBreakPanel(Settings settings, string break_id, string break_name, int[] interval_options,
int[] duration_options) {
base(settings, break_id, break_name, interval_options);
public TimerBreakPanel(BreakType break_type, int[] interval_options, int[] duration_options) {
base(break_type, interval_options);
this.duration_options = duration_options;
......@@ -41,16 +40,14 @@ public class TimerBreakPanel : BreakPanel {
interval_label.set_halign(Gtk.Align.END);
details_grid.attach(interval_label, 0, 1, 1, 1);
this.interval_chooser = new TimeChooser(this.interval_options, _("%s interval").printf(this.break_name));
this.settings.bind("interval-seconds", this.interval_chooser, "time-seconds", SettingsBindFlags.DEFAULT);
this.interval_chooser = new TimeChooser(this.interval_options, _("%s interval").printf(this.break_type.name));
details_grid.attach_next_to(this.interval_chooser, interval_label, Gtk.PositionType.RIGHT, 1, 1);
Gtk.Label duration_label = new Gtk.Label.with_mnemonic("For");
duration_label.set_halign(Gtk.Align.END);
details_grid.attach(duration_label, 0, 2, 1, 1);
this.duration_chooser = new TimeChooser(this.duration_options, _("%s duration").printf(this.break_name));
this.settings.bind("duration-seconds", this.duration_chooser, "time-seconds", SettingsBindFlags.DEFAULT);
this.duration_chooser = new TimeChooser(this.duration_options, _("%s duration").printf(this.break_type.name));
details_grid.attach_next_to(this.duration_chooser, duration_label, Gtk.PositionType.RIGHT, 1, 1);
details_grid.show_all();
......
/*
* This file is part of Brain Break.
*
* Brain Break 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 3 of the License, or
* (at your option) any later version.
*
* Brain Break 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 Brain Break. If not, see <http://www.gnu.org/licenses/>.
*/
public abstract class TimerBreakType : BreakType {
public int duration {get; set;}
protected int[] interval_options;
protected int[] duration_options;
public TimerBreakType(Settings settings, string name) {
base(settings, name);
this.settings.bind("duration-seconds", this, "duration", SettingsBindFlags.DEFAULT);
}
protected new void bind_to_settings_panel(TimerBreakPanel panel) {
base.bind_to_settings_panel(panel);
this.settings.bind("interval-seconds", panel.interval_chooser, "time-seconds", SettingsBindFlags.DEFAULT);
this.settings.bind("duration-seconds", panel.duration_chooser, "time-seconds", SettingsBindFlags.DEFAULT);
}
}
......@@ -46,8 +46,11 @@ public class Application : Gtk.Application {
NaturalTime.initialize();
Settings breaks_settings = new Settings("org.brainbreak.breaks");
SettingsDialog dialog = new SettingsDialog(breaks_settings);
BreakType[] break_types = {
new RestBreakType(),
new MicroBreakType()
};
SettingsDialog dialog = new SettingsDialog(break_types);
this.add_window(dialog);
dialog.show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment