Commit 3f8a170a authored by Dylan McCall's avatar Dylan McCall

Ruthlessly cutting things from the Settings dialog, and adding a Gd.HeaderBar....

Ruthlessly cutting things from the Settings dialog, and adding a Gd.HeaderBar. Most of these changes are superficial.
parent 741e1397
......@@ -21,7 +21,6 @@ fi
# git submodule update --init --recursive
# We don't use git, yet, so we're going to pretend to have a git submodule for libgd
mkdir
if test ! -d libgd; then
git clone git://git.gnome.org/libgd
else
......
......@@ -15,46 +15,38 @@
* along with Brain Break. If not, see <http://www.gnu.org/licenses/>.
*/
public abstract class BreakPanel : Panel {
// FIXME: we're only exposing this so we can use GSettings.bind to its active property
public Gtk.Switch toggle_switch;
public signal void toggled(bool enabled);
public BreakPanel(string title, string? description) {
public abstract class BreakSettingsPanel : SettingsPanel {
public BreakSettingsPanel(BreakType break_type, string title, string? description) {
base();
Gtk.Container header = this.get_header();
Gtk.Grid title_grid = new Gtk.Grid();
var title_grid = new Gtk.Grid();
this.set_header(title_grid);
title_grid.set_orientation(Gtk.Orientation.VERTICAL);
title_grid.set_row_spacing(4);
header.add(title_grid);
Gtk.Label title_label = new Gtk.Label(title);
var title_label = new Gtk.Label(title);
title_label.set_halign(Gtk.Align.START);
title_label.get_style_context().add_class("_settings-title");
title_grid.add(title_label);
Gtk.Label description_label = new Gtk.Label("<small>%s</small>".printf(description));
var description_label = new Gtk.Label("<small>%s</small>".printf(description));
description_label.set_use_markup(true);
description_label.set_halign(Gtk.Align.START);
description_label.get_style_context().add_class("_settings-description");
title_grid.add(description_label);
this.toggle_switch = new Gtk.Switch();
var toggle_switch = new Gtk.Switch();
this.set_header_action(toggle_switch);
toggle_switch.set_hexpand(true);
toggle_switch.set_halign(Gtk.Align.END);
toggle_switch.set_valign(Gtk.Align.CENTER);
header.add(toggle_switch);
this.show_all();
break_type.settings.bind("enabled", toggle_switch, "active", SettingsBindFlags.DEFAULT);
this.toggle_switch.notify["active"].connect((s, p) => {
this.toggled(this.toggle_switch.active);
});
this.toggled.connect((enabled) => {
this.get_content().sensitive = this.toggle_switch.active;
toggle_switch.notify["active"].connect((s, p) => {
bool enabled = toggle_switch.active;
this.set_editable(enabled);
});
this.show_all();
}
}
......@@ -16,29 +16,16 @@
*/
public abstract class BreakType : Object {
protected Settings settings;
private BreakPanel settings_panel;
public string name {get; private set;}
public bool enabled {get; set; default=true;}
public string id {get; private set;}
public Settings settings;
public BreakType(string name, Settings settings) {
this.name = name;
public BreakType(string id, Settings settings) {
this.id = id;
this.settings = settings;
this.settings_panel = this.make_settings_panel();
this.settings.bind("enabled", this, "enabled", SettingsBindFlags.DEFAULT);
}
protected abstract BreakPanel make_settings_panel();
public BreakPanel get_settings_panel() {
return this.settings_panel;
}
protected void bind_to_settings_panel(BreakPanel panel) {
this.settings.bind("enabled", panel.toggle_switch, "active", SettingsBindFlags.DEFAULT);
}
public abstract Gtk.Widget get_status_panel();
public abstract Gtk.Widget get_settings_panel();
}
......@@ -10,17 +10,16 @@ bin_PROGRAMS = \
brainbreak_settings_SOURCES = \
ApplicationPanel.vala \
BreakPanel.vala \
BreakSettingsPanel.vala \
BreakType.vala \
main.vala \
MainWindow.vala \
MicroBreakType.vala \
Panel.vala \
QuietMode.vala \
QuietModePanel.vala \
RestBreakType.vala \
SettingsDialog.vala \
SettingsPanel.vala \
TimeChooser.vala \
TimerBreakPanel.vala \
TimerBreakSettingsPanel.vala \
TimerBreakType.vala
brainbreak_settings_VALAFLAGS = $(BRAINBREAK_VALAFLAGS) \
......
......@@ -16,22 +16,28 @@
*/
public class MicroBreakType : TimerBreakType {
static string title = _("Micro Break");
static string description = _("Pause frequently to relax your eyes");
public MicroBreakType() {
Settings settings = new Settings("org.brainbreak.breaks.microbreak");
base("microbreak", settings);
this.interval_options = {240, 360, 480, 600};
this.duration_options = {15, 20, 25, 30, 45};
}
protected override BreakPanel make_settings_panel() {
int[] interval_options = {240, 360, 480, 600};
int[] duration_options = {15, 20, 25, 30, 45};
TimerBreakPanel panel = new TimerBreakPanel(title, description, interval_options, duration_options);
this.bind_to_settings_panel(panel);
public override Gtk.Widget get_status_panel() {
var panel = new Gtk.Grid();
var label = new Gtk.Label("Micro Break");
panel.add(label);
panel.show_all();
return panel;
}
public override Gtk.Widget get_settings_panel() {
return new TimerBreakSettingsPanel(
this,
_("Micro Break"),
_("Pause frequently to relax your eyes")
);
}
}
/*
* 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 class QuietMode : Object {
private Settings settings;
private Gtk.Widget settings_panel;
public bool active {get; set;}
public int64 expire_time {get; set;}
public QuietMode() {
this.settings = new Settings("org.brainbreak.breaks");
this.settings_panel = this.make_settings_panel();
this.settings.bind("quiet-mode", this, "active", SettingsBindFlags.DEFAULT);
this.settings.bind("quiet-mode-expire-time", this, "expire-time", SettingsBindFlags.DEFAULT);
}
protected Gtk.Widget make_settings_panel() {
QuietModePanel panel = new QuietModePanel();
this.settings.bind("quiet-mode", panel.toggle_switch, "active", SettingsBindFlags.DEFAULT);
this.settings.bind("quiet-mode-expire-time", panel, "expire-time", SettingsBindFlags.DEFAULT);
panel.toggled.connect((enabled) => {
if (enabled) {
DateTime now = new DateTime.now_utc();
DateTime later = now.add_hours(1);
this.expire_time = later.to_unix();
panel.start_countdown();
} else {
this.expire_time = 0;
panel.end_countdown();
}
});
return panel;
}
public Gtk.Widget get_settings_panel() {
return this.settings_panel;
}
}
/*
* 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 class QuietModePanel : Panel {
public int64 expire_time {get; set;}
public Gtk.ToggleButton toggle_switch;
public signal void toggled(bool enabled);
private Gtk.Label countdown_label;
private uint countdown_source_id;
public QuietModePanel() {
base();
Gtk.Container header = this.get_header();
Gtk.Label title_label = new Gtk.Label(_("Quiet Mode"));
title_label.set_halign(Gtk.Align.START);
title_label.get_style_context().add_class("_settings-title");
header.add(title_label);
this.countdown_label = new Gtk.Label(null);
this.countdown_label.set_hexpand(true);
this.countdown_label.set_halign(Gtk.Align.END);
header.add(this.countdown_label);
Gtk.Container content = this.get_content();
this.toggle_switch = new Gtk.CheckButton.with_label(_("Please don't interrupt me. I'm doing something important"));
content.add(this.toggle_switch);
this.show_all();
this.toggle_switch.notify["active"].connect((s, p) => {
this.toggled(this.toggle_switch.active);
});
this.countdown_source_id = 0;
this.notify["expire-time"].connect((s, p) => {
if (this.toggle_switch.active == true) {
this.start_countdown();
} else {
this.end_countdown();
}
});
}
public void start_countdown() {
this.countdown_source_id = Timeout.add_seconds(1, this.countdown_timeout);
this.countdown_timeout();
}
public void end_countdown() {
this.countdown_label.set_markup("");
this.toggle_switch.active = false;
if (this.countdown_source_id > 0) {
Source.remove(this.countdown_source_id);
this.countdown_source_id = 0;
}
}
private bool countdown_timeout() {
DateTime now = new DateTime.now_utc();
int64 time_remaining = this.expire_time - now.to_unix();
if (time_remaining > 0) {
string countdown = NaturalTime.instance.get_countdown_for_seconds((int)time_remaining);
this.countdown_label.set_markup(_("<small>Turns off in %s</small>").printf(countdown));
} else {
this.end_countdown();
return false;
}
return true;
}
}
......@@ -16,22 +16,28 @@
*/
public class RestBreakType : TimerBreakType {
static string title = _("Rest Break");
static string description = _("And take some longer breaks to stretch your legs");
public RestBreakType() {
Settings settings = new Settings("org.brainbreak.breaks.restbreak");
base("restbreak", settings);
this.interval_options = {1800, 2400, 3000, 3600};
this.duration_options = {300, 360, 420, 480, 540, 600};
}
protected override BreakPanel make_settings_panel() {
int[] interval_options = {1800, 2400, 3000, 3600};
int[] duration_options = {300, 360, 420, 480, 540, 600};
TimerBreakPanel panel = new TimerBreakPanel(title, description, interval_options, duration_options);
this.bind_to_settings_panel(panel);
public override Gtk.Widget get_status_panel() {
var panel = new Gtk.Grid();
var label = new Gtk.Label("Rest Break");
panel.add(label);
panel.show_all();
return panel;
}
public override Gtk.Widget get_settings_panel() {
return new TimerBreakSettingsPanel(
this,
_("Rest Break"),
_("And take some longer breaks to stretch your legs")
);
}
}
......@@ -19,80 +19,42 @@ public class SettingsDialog : Gtk.Dialog {
private ApplicationPanel application_panel;
private Gtk.Grid breaks_grid;
private Gee.Map<string, BreakType> break_types;
private static const int ABOUT_BUTTON_RESPONSE = 5;
public SettingsDialog() {
public SettingsDialog(Application application) {
Object();
this.break_types = new Gee.HashMap<string, BreakType>();
this.set_title(_("Break Settings"));
this.set_title(_("Choose Your Break Preferences"));
this.set_resizable(false);
this.delete_event.connect(this.hide_on_delete);
Gtk.Widget about_button = this.add_button(Gtk.Stock.ABOUT, Gtk.ResponseType.HELP);
Gtk.Widget close_button = this.add_button(Gtk.Stock.CLOSE, Gtk.ResponseType.CLOSE);
this.response.connect(this.response_cb);
Gtk.Box content = (Gtk.Box) this.get_content_area();
this.application_panel = new ApplicationPanel();
Gtk.Widget status_widget = application_panel.get_status_widget();
content.add(this.application_panel);
this.breaks_grid = new Gtk.Grid();
this.breaks_grid.set_orientation(Gtk.Orientation.VERTICAL);
this.breaks_grid.margin = 12;
this.breaks_grid.set_row_spacing(18);
content.add(this.breaks_grid);
foreach (BreakType break_type in application.breaks) {
this.add_break_type(break_type);
}
Gtk.Grid extra_grid = new Gtk.Grid();
extra_grid.set_orientation(Gtk.Orientation.VERTICAL);
extra_grid.margin = 12;
extra_grid.set_row_spacing(18);
content.add(extra_grid);
QuietMode quiet_mode = new QuietMode();
Gtk.Widget quiet_panel = quiet_mode.get_settings_panel();
extra_grid.add(quiet_panel);
extra_grid.show();
breaks_grid.show();
content.show_all();
}
public void add_break_type(BreakType break_type) {
this.break_types.set(break_type.name, break_type);
break_type.notify["enabled"].connect((s, p) => {
this.on_break_disabled();
});
private void add_break_type(BreakType break_type) {
Gtk.Widget settings_panel = break_type.get_settings_panel();
breaks_grid.add(settings_panel);
// update the master switch with any changes made externally
this.on_break_disabled();
}
private void on_break_disabled() {
bool any_enabled = false;
foreach (BreakType break_type in this.break_types.values) {
if (break_type.enabled) any_enabled = true;
}
this.application_panel.master_enabled = any_enabled;
}
private void response_cb(int response_id) {
if (response_id == Gtk.ResponseType.CLOSE) {
this.destroy ();
} else if (response_id == Gtk.ResponseType.HELP) {
Gtk.show_about_dialog(this,
"program-name", _("Brain Break"),
"comments", _("Computer break reminders for active minds"),
"copyright", _("Copyright © Dylan McCall"),
"website", "http://launchpad.net/brainbreak",
"website-label", _("Brain Break Website")
);
this.hide();
}
}
}
......
......@@ -15,36 +15,43 @@
* along with Brain Break. If not, see <http://www.gnu.org/licenses/>.
*/
public abstract class Panel : Gtk.Grid {
public abstract class SettingsPanel : Gtk.Grid {
private Gtk.Grid header;
private Gtk.Grid content;
private Gtk.Grid details;
public Panel() {
public SettingsPanel() {
Object();
this.set_orientation(Gtk.Orientation.VERTICAL);
this.set_row_spacing(12);
this.header = new Gtk.Grid();
this.header.set_orientation(Gtk.Orientation.HORIZONTAL);
this.header.set_column_spacing(12);
this.add(header);
this.content = new Gtk.Grid();
this.content.set_orientation(Gtk.Orientation.HORIZONTAL);
this.content.set_column_spacing(6);
this.content.set_margin_left(12);
this.add(this.content);
this.details = new Gtk.Grid();
this.details.set_margin_left(12);
this.add(this.details);
this.show_all();
}
public virtual Gtk.Container get_header() {
return this.header;
public void set_header(Gtk.Widget content) {
this.header.attach(content, 0, 0, 1, 1);
}
public void set_header_action(Gtk.Widget content) {
this.header.attach(content, 1, 0, 1, 1);
content.set_halign(Gtk.Align.END);
content.set_valign(Gtk.Align.CENTER);
}
public virtual Gtk.Container get_content() {
return this.content;
public void set_details(Gtk.Widget content) {
this.details.add(content);
}
public void set_editable(bool sensitive) {
this.details.sensitive = sensitive;
}
}
......@@ -15,50 +15,33 @@
* along with Brain Break. If not, see <http://www.gnu.org/licenses/>.
*/
public class TimerBreakPanel : BreakPanel {
public TimeChooser interval_chooser;
public TimeChooser duration_chooser;
protected int[] interval_options;
protected int[] duration_options;
private string title;
public TimerBreakPanel(string title, string? description, int[] interval_options, int[] duration_options) {
base(title, description);
public class TimerBreakSettingsPanel : BreakSettingsPanel {
public TimerBreakSettingsPanel(TimerBreakType break_type, string title, string? description) {
base(break_type, title, description);
this.title = title;
this.interval_options = interval_options;
this.duration_options = duration_options;
Gtk.Grid details_grid = this.build_details_grid();
this.get_content().add(details_grid);
}
private inline Gtk.Grid build_details_grid() {
Gtk.Grid details_grid = new Gtk.Grid();
var details_grid = new Gtk.Grid();
this.set_details(details_grid);
details_grid.set_column_spacing(8);
details_grid.set_row_spacing(8);
Gtk.Label interval_label = new Gtk.Label.with_mnemonic(_("Every"));
var interval_label = new Gtk.Label.with_mnemonic(_("Every"));
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 frequency").printf(this.title));
details_grid.attach_next_to(this.interval_chooser, interval_label, Gtk.PositionType.RIGHT, 1, 1);
var interval_chooser = new TimeChooser(break_type.interval_options, _("%s frequency").printf(title));
details_grid.attach_next_to(interval_chooser, interval_label, Gtk.PositionType.RIGHT, 1, 1);
break_type.settings.bind("interval-seconds", interval_chooser, "time-seconds", SettingsBindFlags.DEFAULT);
Gtk.Label duration_label = new Gtk.Label.with_mnemonic(_("For"));
var 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.title));
details_grid.attach_next_to(this.duration_chooser, duration_label, Gtk.PositionType.RIGHT, 1, 1);
var duration_chooser = new TimeChooser(break_type.duration_options, _("%s duration").printf(title));
details_grid.attach_next_to(duration_chooser, duration_label, Gtk.PositionType.RIGHT, 1, 1);
break_type.settings.bind("duration-seconds", duration_chooser, "time-seconds", SettingsBindFlags.DEFAULT);
details_grid.show_all();
return details_grid;
}
}
......@@ -16,20 +16,11 @@
*/
public abstract class TimerBreakType : BreakType {
public int interval {get; set;}
public int duration {get; set;}
public int[] interval_options;
public int[] duration_options;
public TimerBreakType(string name, Settings settings) {
base(name, settings);
this.settings.bind("interval-seconds", this, "interval", SettingsBindFlags.DEFAULT);
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);
}
}
......@@ -16,31 +16,25 @@
*/
public class Application : Gtk.Application {
const string app_id = "org.brainbreak.Settings";
const string app_name = _("Break Settings");
static const string STYLE_DATA =
"""
GtkLabel._settings-title {
font-weight:bold;
}
""";
private const string app_id = "org.brainbreak.Settings";
private static const string STYLE_DATA =
"""
GtkLabel._settings-title {
font-weight:bold;
}
""";
public BreakType[] breaks {public get; private set;}
private MainWindow main_window;
public Application() {
Object(application_id: app_id, flags: ApplicationFlags.FLAGS_NONE);
GLib.Environment.set_application_name(app_name);
}
public override void activate() {
base.activate();
foreach (Gtk.Window window in this.get_windows()) {
window.present();
}
}
public override void startup() {
base.startup();
/* set up custom gtk style for application */
Gdk.Screen screen = Gdk.Screen.get_default();
Gtk.CssProvider style_provider = new Gtk.CssProvider();
......@@ -56,12 +50,36 @@ public class Application : Gtk.Application {
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
SettingsDialog dialog = new SettingsDialog();
dialog.add_break_type(new MicroBreakType());
dialog.add_break_type(new RestBreakType());
this.add_window(dialog);
dialog.show();
this.breaks = {
new MicroBreakType(),
new RestBreakType()
};
this.main_window = new MainWindow(this);
this.add_window(this.main_window);
SimpleAction about_action = new SimpleAction("about", null);
this.add_action(about_action);
about_action.activate.connect(this.on_about_activate_cb);
SimpleAction quit_action = new SimpleAction("quit", null);
this.add_action(quit_action);
quit_action.activate.connect(this.quit);
Menu app_menu = new Menu();
app_menu.append(_("About"), "app.about");
app_menu.append(_("Quit"), "app.quit");
this.set_app_menu(app_menu);
this.main_window.present();
}
public override void startup() {
base.startup();
}
private void on_about_activate_cb() {
this.main_window.show_about_dialog();
}
}
......
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