diff --git a/src/Application.vala b/src/Application.vala index 6324cc9..4cca6fd 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -21,54 +21,54 @@ */ public class Tomato : Gtk.Application { - public MainWindow main_window; + public MainWindow main_window; - public Tomato () { - Object ( - application_id: "io.github.ellie_commons.tomato", - flags: ApplicationFlags.FLAGS_NONE - ); - } + public Tomato () { + Object ( + application_id: "io.github.ellie_commons.tomato", + flags: ApplicationFlags.FLAGS_NONE + ); + } - protected override void startup () { - base.startup (); + protected override void startup () { + base.startup (); - Granite.init (); + Granite.init (); - Intl.setlocale (LocaleCategory.ALL, ""); - Intl.bindtextdomain (Build.GETTEXT_PACKAGE, Build.LOCALEDIR); - Intl.bind_textdomain_codeset (Build.GETTEXT_PACKAGE, "UTF-8"); - Intl.textdomain (Build.GETTEXT_PACKAGE); + Intl.setlocale (LocaleCategory.ALL, ""); + Intl.bindtextdomain (Build.GETTEXT_PACKAGE, Build.LOCALEDIR); + Intl.bind_textdomain_codeset (Build.GETTEXT_PACKAGE, "UTF-8"); + Intl.textdomain (Build.GETTEXT_PACKAGE); - var quit_action = new SimpleAction ("quit", null); + var quit_action = new SimpleAction ("quit", null); - add_action (quit_action); - set_accels_for_action ("app.quit", {"q"}); + add_action (quit_action); + set_accels_for_action ("app.quit", {"q"}); - quit_action.activate.connect (quit); - } + quit_action.activate.connect (quit); + } - protected override void activate () { - if (main_window != null) { + protected override void activate () { + if (main_window != null) { main_window.present (); return; } - var main_window = new MainWindow (this); + var main_window = new MainWindow (this); - // Use Css - var provider = new Gtk.CssProvider (); - provider.load_from_resource ("/io/github/ellie_commons/tomato/Application.css"); + // Use Css + var provider = new Gtk.CssProvider (); + provider.load_from_resource ("/io/github/ellie_commons/tomato/Application.css"); - Gtk.StyleContext.add_provider_for_display ( - Gdk.Display.get_default (), - provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION - ); + Gtk.StyleContext.add_provider_for_display ( + Gdk.Display.get_default (), + provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + ); - main_window.present (); - } + main_window.present (); + } - public static int main (string[] args) { - return new Tomato ().run (args); - } -} \ No newline at end of file + public static int main (string[] args) { + return new Tomato ().run (args); + } +} diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala index 48e4e40..a293d95 100644 --- a/src/Dialogs/PreferencesDialog.vala +++ b/src/Dialogs/PreferencesDialog.vala @@ -22,293 +22,293 @@ public class Dialogs.PreferencesDialog : Granite.Dialog { - //stacks - private Gtk.Stack stack; - private Gtk.StackSwitcher stackswitcher; - - //options - scales - private Widgets.ValueRange pomodoro_scale; - private Widgets.ValueRange short_break_scale; - private Widgets.ValueRange long_break_scale; - private Widgets.ValueRange long_break_delay_scale; - - //options - switches - private Gtk.Switch reset_work_everyday; - private Gtk.Switch pause_after_break; - private Gtk.Switch auto_stop_enabled; - private Gtk.Switch pomodoro_sound_enabled; - private Gtk.Switch debug_switch; - - //options - button - private Gtk.Button reset_timings; - private Gtk.Button reset_work; - - //signals - public signal void reset_work_clicked (); - public signal void pomodoro_changed (); - public signal void short_break_changed (); - public signal void long_break_changed (); - public signal void long_break_delay_changed (); - - Services.Preferences preferences { get; default = Services.Preferences.instance (); } - Services.Settings settings { get; default = Services.Settings.instance (); } - Services.SavedState saved { get; default = Services.SavedState.instance (); } - - public PreferencesDialog (Gtk.Window? parent) { - Object ( - transient_for: parent, - title: _("Preferences"), - resizable: false, - modal: true, - deletable: false - ); - } - - construct { - stack = new Gtk.Stack (); - stackswitcher = new Gtk.StackSwitcher (); - - stackswitcher.set_stack (stack); - stackswitcher.set_halign (Gtk.Align.CENTER); - - bind_and_init_options (); - create_ui (); - update_timing_sensitivity (); - update_work_sensitivity (); - connect_signals (); - } - - private void bind_and_init_options () { - /* ** options - scales ** */ - //pomodoro_scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 5, 60, 1); - pomodoro_scale = new Widgets.ValueRange (5, 60, 1, _("minute"), _("minutes")); - settings.schema.bind ("pomodoro-duration", pomodoro_scale, "current-value", SettingsBindFlags.DEFAULT); - - short_break_scale = new Widgets.ValueRange (1, 10, 1, _("minute"), _("minutes")); - settings.schema.bind ("short-break-duration", short_break_scale, "current-value", SettingsBindFlags.DEFAULT); - - long_break_scale = new Widgets.ValueRange (10, 30, 1, _("minute"), _("minutes")); - settings.schema.bind ("long-break-duration", long_break_scale, "current-value", SettingsBindFlags.DEFAULT); - - long_break_delay_scale = new Widgets.ValueRange (2, 8, 1, _("pomodoro"), _("pomodoros")); - settings.schema.bind ("long-break-delay", long_break_delay_scale, "current-value", SettingsBindFlags.DEFAULT); - - /* ** options - switches ** */ - reset_work_everyday = new Gtk.Switch (); - preferences.schema.bind ("reset-work-everyday", reset_work_everyday, "active", SettingsBindFlags.DEFAULT); - - pause_after_break = new Gtk.Switch (); - preferences.schema.bind ("pause-after-break", pause_after_break, "active", SettingsBindFlags.DEFAULT); - - auto_stop_enabled = new Gtk.Switch (); - preferences.schema.bind ("auto-stop", auto_stop_enabled, "active", SettingsBindFlags.DEFAULT); - - pomodoro_sound_enabled = new Gtk.Switch (); - preferences.schema.bind ("pomodoro-sound-enabled", pomodoro_sound_enabled, "active", SettingsBindFlags.DEFAULT); - - if (preferences.debug_mode) { - pomodoro_scale = new Widgets.ValueRange (1, 60, 1, _("minute"), _("minutes")); - settings.schema.bind ("pomodoro-duration", pomodoro_scale, "current-value", SettingsBindFlags.DEFAULT); - - long_break_scale = new Widgets.ValueRange (2, 30, 1, _("minute"), _("minutes")); - settings.schema.bind ("long-break-duration", long_break_scale, "current-value", SettingsBindFlags.DEFAULT); + //stacks + private Gtk.Stack stack; + private Gtk.StackSwitcher stackswitcher; + + //options - scales + private Widgets.ValueRange pomodoro_scale; + private Widgets.ValueRange short_break_scale; + private Widgets.ValueRange long_break_scale; + private Widgets.ValueRange long_break_delay_scale; + + //options - switches + private Gtk.Switch reset_work_everyday; + private Gtk.Switch pause_after_break; + private Gtk.Switch auto_stop_enabled; + private Gtk.Switch pomodoro_sound_enabled; + private Gtk.Switch debug_switch; + + //options - button + private Gtk.Button reset_timings; + private Gtk.Button reset_work; + + //signals + public signal void reset_work_clicked (); + public signal void pomodoro_changed (); + public signal void short_break_changed (); + public signal void long_break_changed (); + public signal void long_break_delay_changed (); + + Services.Preferences preferences { get; default = Services.Preferences.instance (); } + Services.Settings settings { get; default = Services.Settings.instance (); } + Services.SavedState saved { get; default = Services.SavedState.instance (); } + + public PreferencesDialog (Gtk.Window? parent) { + Object ( + transient_for: parent, + title: _("Preferences"), + resizable: false, + modal: true, + deletable: false + ); + } + + construct { + stack = new Gtk.Stack (); + stackswitcher = new Gtk.StackSwitcher (); + + stackswitcher.set_stack (stack); + stackswitcher.set_halign (Gtk.Align.CENTER); + + bind_and_init_options (); + create_ui (); + update_timing_sensitivity (); + update_work_sensitivity (); + connect_signals (); + } + + private void bind_and_init_options () { + /* ** options - scales ** */ + //pomodoro_scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 5, 60, 1); + pomodoro_scale = new Widgets.ValueRange (5, 60, 1, _("minute"), _("minutes")); + settings.schema.bind ("pomodoro-duration", pomodoro_scale, "current-value", SettingsBindFlags.DEFAULT); + + short_break_scale = new Widgets.ValueRange (1, 10, 1, _("minute"), _("minutes")); + settings.schema.bind ("short-break-duration", short_break_scale, "current-value", SettingsBindFlags.DEFAULT); + + long_break_scale = new Widgets.ValueRange (10, 30, 1, _("minute"), _("minutes")); + settings.schema.bind ("long-break-duration", long_break_scale, "current-value", SettingsBindFlags.DEFAULT); + + long_break_delay_scale = new Widgets.ValueRange (2, 8, 1, _("pomodoro"), _("pomodoros")); + settings.schema.bind ("long-break-delay", long_break_delay_scale, "current-value", SettingsBindFlags.DEFAULT); + + /* ** options - switches ** */ + reset_work_everyday = new Gtk.Switch (); + preferences.schema.bind ("reset-work-everyday", reset_work_everyday, "active", SettingsBindFlags.DEFAULT); + + pause_after_break = new Gtk.Switch (); + preferences.schema.bind ("pause-after-break", pause_after_break, "active", SettingsBindFlags.DEFAULT); + + auto_stop_enabled = new Gtk.Switch (); + preferences.schema.bind ("auto-stop", auto_stop_enabled, "active", SettingsBindFlags.DEFAULT); + + pomodoro_sound_enabled = new Gtk.Switch (); + preferences.schema.bind ("pomodoro-sound-enabled", pomodoro_sound_enabled, "active", SettingsBindFlags.DEFAULT); + + if (preferences.debug_mode) { + pomodoro_scale = new Widgets.ValueRange (1, 60, 1, _("minute"), _("minutes")); + settings.schema.bind ("pomodoro-duration", pomodoro_scale, "current-value", SettingsBindFlags.DEFAULT); + + long_break_scale = new Widgets.ValueRange (2, 30, 1, _("minute"), _("minutes")); + settings.schema.bind ("long-break-duration", long_break_scale, "current-value", SettingsBindFlags.DEFAULT); - debug_switch = new Gtk.Switch (); - preferences.schema.bind ("debug-mode", debug_switch, "active", SettingsBindFlags.DEFAULT); - } - - /* ** options - buttons ** */ - reset_timings = new Gtk.Button.with_label (_("Default Settings")); - reset_work = new Gtk.Button.with_label (_("Reset Work")); - } - - private void create_ui () { - - stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT); - //create timing tab - - stack.add_titled (get_timing_box (), "timing", _("Timing")); - - //create misc tab - - stack.add_titled (get_misc_box (), "misc", _("Preferences")); - - //creat future tabs here - - //close button - var close_button = new Gtk.Button.with_label (_("Close")); - close_button.clicked.connect (() => { - destroy (); - }); - - //button box - var button_box = new Gtk.Box (HORIZONTAL, 0) { - hexpand = true, - halign = END, - margin_end = 12 - }; - button_box.append (close_button); - - //puts everything into a grid - var main_grid = new Gtk.Grid (); - main_grid.attach (stackswitcher, 0, 0, 1, 1); - main_grid.attach ( - stack, 0, 1, 1, 1); - main_grid.attach (button_box, 0, 2, 1, 1); - - //add the grid to the dialog - get_content_area ().append (main_grid); - } - - private Gtk.Widget get_timing_box () { - //setup the grid for the timing Box - var grid = make_grid (); - var row = 0; - - //pomodoro Scale - var label = new Gtk.Label (_("Pomodoro duration:")); - add_option (grid, label, pomodoro_scale, ref row); - - //short break scale - label = new Gtk.Label (_("Short break duration:")); - add_option (grid, label, short_break_scale, ref row); - - //long break scale - label = new Gtk.Label (_("Long break duration:")); - add_option (grid, label, long_break_scale, ref row); - - //long break delay scale - label = new Gtk.Label (_("Long break delay:")); - add_option (grid, label, long_break_delay_scale, ref row); - - //reset buttons - var reset_grid = new Gtk.Box (HORIZONTAL, 6); - reset_grid.append (reset_timings); - reset_grid.append (reset_work); - label = new Gtk.Label (_("Reset:")); - add_option (grid, label, reset_grid, ref row, 15); - - return grid; - } - - private Gtk.Widget get_misc_box () { - //setup the grid for the timing Box - var grid = make_grid (); - - var row = 0; - - add_section (grid, new Granite.HeaderLabel (_("Behavior:")), ref row); - - var label = new Gtk.Label (_("Reset work everyday:")); - add_option (grid, label, reset_work_everyday, ref row); - - label = new Gtk.Label (_("Start new pomodoro manually:")); - add_option (grid, label, pause_after_break, ref row); - - label = new Gtk.Label (_("Auto stop:")); - add_option (grid, label, auto_stop_enabled, ref row); - - add_section (grid, new Granite.HeaderLabel (_("Sound:")), ref row); - - label = new Gtk.Label (_("Pomodoro sound:")); - add_option (grid, label, pomodoro_sound_enabled, ref row); - - if (preferences.debug_mode) { - add_section (grid, new Granite.HeaderLabel (_("Extras:")), ref row); - add_option (grid, new Granite.HeaderLabel (_("Debug mode")), debug_switch, ref row); - } - - return grid; - } - - private void reset_scales () { - pomodoro_scale.current_value = Default.POMODORO_DURATION; - short_break_scale.current_value = Default.SHORT_BREAK_DURATION; - long_break_scale.current_value = Default.LONG_BREAK_DURATION; - long_break_delay_scale.current_value = Default.LONG_BREAK_DELAY; - } - - public void update_timing_sensitivity () { - var sensitive = false; - if (pomodoro_scale.current_value != Default.POMODORO_DURATION) { - sensitive = true; - } else if (short_break_scale.current_value != Default.SHORT_BREAK_DURATION) { - sensitive = true; - } else if (long_break_scale.current_value != Default.LONG_BREAK_DURATION) { - sensitive = true; - } else if (long_break_delay_scale.current_value != Default.LONG_BREAK_DELAY) { - sensitive = true; - } - - reset_timings.sensitive = sensitive; - } - - public void update_work_sensitivity () { - var sensitive = false; - if (saved.pomodoro_count != 0) { - sensitive = true; - } else if (saved.total_time != 0) { - sensitive = true; - } else if (saved.status != Status.START) { - sensitive = true; - } - reset_work.sensitive = sensitive; - } - - private void add_section (Gtk.Grid grid, Gtk.Widget name, ref int row) { - grid.attach (name, 0, row, 1, 1); - row++; - } - - private void add_option (Gtk.Grid grid, Gtk.Widget label, Gtk.Widget switcher, ref int row, int margin_top = 0) { - label.halign = END; - - if (switcher is Widgets.ValueRange) { - label.margin_top = 12; - label.halign = END; - } - - grid.attach (label, 0, row, 1, 1); - grid.attach_next_to (switcher, label, Gtk.PositionType.RIGHT, 3, 1); - - row++; - } - - private Gtk.Grid make_grid () { - var grid = new Gtk.Grid () { - row_spacing = 6, - column_spacing = 12, - margin_start = 12, - margin_end = 12, - margin_top = 12, - margin_bottom = 12 - }; - - return grid; - } - - private void connect_signals () { - pomodoro_scale.changed.connect (() => { - pomodoro_changed (); - }); - - short_break_scale.changed.connect (() => { - short_break_changed (); - }); - - long_break_scale.changed.connect (() => { - long_break_changed (); - }); - - long_break_delay_scale.changed.connect (() => { - long_break_delay_changed (); - }); - - reset_timings.clicked.connect (reset_scales); - - reset_work.clicked.connect (() => { - reset_work_clicked (); - }); - - } -} \ No newline at end of file + debug_switch = new Gtk.Switch (); + preferences.schema.bind ("debug-mode", debug_switch, "active", SettingsBindFlags.DEFAULT); + } + + /* ** options - buttons ** */ + reset_timings = new Gtk.Button.with_label (_("Default Settings")); + reset_work = new Gtk.Button.with_label (_("Reset Work")); + } + + private void create_ui () { + + stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT); + //create timing tab + + stack.add_titled (get_timing_box (), "timing", _("Timing")); + + //create misc tab + + stack.add_titled (get_misc_box (), "misc", _("Preferences")); + + //creat future tabs here + + //close button + var close_button = new Gtk.Button.with_label (_("Close")); + close_button.clicked.connect (() => { + destroy (); + }); + + //button box + var button_box = new Gtk.Box (HORIZONTAL, 0) { + hexpand = true, + halign = END, + margin_end = 12 + }; + button_box.append (close_button); + + //puts everything into a grid + var main_grid = new Gtk.Grid (); + main_grid.attach (stackswitcher, 0, 0, 1, 1); + main_grid.attach ( + stack, 0, 1, 1, 1); + main_grid.attach (button_box, 0, 2, 1, 1); + + //add the grid to the dialog + get_content_area ().append (main_grid); + } + + private Gtk.Widget get_timing_box () { + //setup the grid for the timing Box + var grid = make_grid (); + var row = 0; + + //pomodoro Scale + var label = new Gtk.Label (_("Pomodoro duration:")); + add_option (grid, label, pomodoro_scale, ref row); + + //short break scale + label = new Gtk.Label (_("Short break duration:")); + add_option (grid, label, short_break_scale, ref row); + + //long break scale + label = new Gtk.Label (_("Long break duration:")); + add_option (grid, label, long_break_scale, ref row); + + //long break delay scale + label = new Gtk.Label (_("Long break delay:")); + add_option (grid, label, long_break_delay_scale, ref row); + + //reset buttons + var reset_grid = new Gtk.Box (HORIZONTAL, 6); + reset_grid.append (reset_timings); + reset_grid.append (reset_work); + label = new Gtk.Label (_("Reset:")); + add_option (grid, label, reset_grid, ref row, 15); + + return grid; + } + + private Gtk.Widget get_misc_box () { + //setup the grid for the timing Box + var grid = make_grid (); + + var row = 0; + + add_section (grid, new Granite.HeaderLabel (_("Behavior:")), ref row); + + var label = new Gtk.Label (_("Reset work everyday:")); + add_option (grid, label, reset_work_everyday, ref row); + + label = new Gtk.Label (_("Start new pomodoro manually:")); + add_option (grid, label, pause_after_break, ref row); + + label = new Gtk.Label (_("Auto stop:")); + add_option (grid, label, auto_stop_enabled, ref row); + + add_section (grid, new Granite.HeaderLabel (_("Sound:")), ref row); + + label = new Gtk.Label (_("Pomodoro sound:")); + add_option (grid, label, pomodoro_sound_enabled, ref row); + + if (preferences.debug_mode) { + add_section (grid, new Granite.HeaderLabel (_("Extras:")), ref row); + add_option (grid, new Granite.HeaderLabel (_("Debug mode")), debug_switch, ref row); + } + + return grid; + } + + private void reset_scales () { + pomodoro_scale.current_value = Default.POMODORO_DURATION; + short_break_scale.current_value = Default.SHORT_BREAK_DURATION; + long_break_scale.current_value = Default.LONG_BREAK_DURATION; + long_break_delay_scale.current_value = Default.LONG_BREAK_DELAY; + } + + public void update_timing_sensitivity () { + var sensitive = false; + if (pomodoro_scale.current_value != Default.POMODORO_DURATION) { + sensitive = true; + } else if (short_break_scale.current_value != Default.SHORT_BREAK_DURATION) { + sensitive = true; + } else if (long_break_scale.current_value != Default.LONG_BREAK_DURATION) { + sensitive = true; + } else if (long_break_delay_scale.current_value != Default.LONG_BREAK_DELAY) { + sensitive = true; + } + + reset_timings.sensitive = sensitive; + } + + public void update_work_sensitivity () { + var sensitive = false; + if (saved.pomodoro_count != 0) { + sensitive = true; + } else if (saved.total_time != 0) { + sensitive = true; + } else if (saved.status != Status.START) { + sensitive = true; + } + reset_work.sensitive = sensitive; + } + + private void add_section (Gtk.Grid grid, Gtk.Widget name, ref int row) { + grid.attach (name, 0, row, 1, 1); + row++; + } + + private void add_option (Gtk.Grid grid, Gtk.Widget label, Gtk.Widget switcher, ref int row, int margin_top = 0) { + label.halign = END; + + if (switcher is Widgets.ValueRange) { + label.margin_top = 12; + label.halign = END; + } + + grid.attach (label, 0, row, 1, 1); + grid.attach_next_to (switcher, label, Gtk.PositionType.RIGHT, 3, 1); + + row++; + } + + private Gtk.Grid make_grid () { + var grid = new Gtk.Grid () { + row_spacing = 6, + column_spacing = 12, + margin_start = 12, + margin_end = 12, + margin_top = 12, + margin_bottom = 12 + }; + + return grid; + } + + private void connect_signals () { + pomodoro_scale.changed.connect (() => { + pomodoro_changed (); + }); + + short_break_scale.changed.connect (() => { + short_break_changed (); + }); + + long_break_scale.changed.connect (() => { + long_break_changed (); + }); + + long_break_delay_scale.changed.connect (() => { + long_break_delay_changed (); + }); + + reset_timings.clicked.connect (reset_scales); + + reset_work.clicked.connect (() => { + reset_work_clicked (); + }); + + } +} diff --git a/src/Enums.vala b/src/Enums.vala index d4f98ea..93740c3 100644 --- a/src/Enums.vala +++ b/src/Enums.vala @@ -21,23 +21,23 @@ */ public enum Status { - START, - POMODORO, - SHORT_BREAK, - LONG_BREAK + START, + POMODORO, + SHORT_BREAK, + LONG_BREAK } private int break_messages_index = 0; private const string[] break_messages = { - N_("Go have a coffee"), - N_("Drink some water"), - N_("Get up and dance!"), - N_("Have a break, have a tomato"), - N_("Get up! Stand up! Fight for your fingers!"), - N_("Take a break, save a life"), - N_("Woot! Break time, baby!"), - N_("It's coffee time!"), - N_("What about a beer?"), - N_("Take a walk outside"), - N_("Step away from the machine!") -}; \ No newline at end of file + N_("Go have a coffee"), + N_("Drink some water"), + N_("Get up and dance!"), + N_("Have a break, have a tomato"), + N_("Get up! Stand up! Fight for your fingers!"), + N_("Take a break, save a life"), + N_("Woot! Break time, baby!"), + N_("It's coffee time!"), + N_("What about a beer?"), + N_("Take a walk outside"), + N_("Step away from the machine!") +}; diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 0d400f6..6d8717e 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -21,430 +21,430 @@ */ public class MainWindow : Gtk.ApplicationWindow { - private const string COLOR_PRIMARY = """ - @define-color colorPrimary %s; - """; + private const string COLOR_PRIMARY = """ + @define-color colorPrimary %s; + """; + + private Gtk.Label countdown_label; + private Gtk.Label total_time_label; + + private Gtk.Button start_button; + private Gtk.Button resume_button; + private Gtk.Button pause_button; + private Gtk.Button stop_button; + private Gtk.Button skip_button; + + private Gtk.Stack resume_pause_stack; + private Gtk.Stack buttons_stack; + + private Gtk.Button appmenu; + + private int stop_countdown = 14; + private bool paused = true; + private bool stopped = true; + + private const uint TIME = 1000; + private uint work_timeout_id = 0; + private uint stop_timeout_id = 0; + + private Managers.WorkManager work; + private Managers.NotificationManager notification; + private Managers.LauncherManager launcher; + + private Services.SavedState saved { get; default = Services.SavedState.instance (); } + private Services.Preferences preferences { get; default = Services.Preferences.instance (); } + + private Dialogs.PreferencesDialog pref_dialog; + + public MainWindow (Gtk.Application application) { + Object ( + application: application, + default_height: 250, + default_width: 300, + resizable: false, + icon_name: "io.github.ellie_commons.tomato", + title: "Tomato" + ); + } + + static construct { + weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_for_display (Gdk.Display.get_default ()); + default_theme.add_resource_path ("io/github/ellie_commons/tomato/"); + } + + construct { + var headerbar = new Adw.HeaderBar () { + decoration_layout = "close:" + }; + + appmenu = new Gtk.Button.from_icon_name ("open-menu-symbolic") { + tooltip_text = _("Preferences") + }; + appmenu.add_css_class (Granite.STYLE_CLASS_FLAT); + appmenu.add_css_class ("menu"); + + headerbar.pack_end (appmenu); + + countdown_label = new Gtk.Label (null); + countdown_label.add_css_class ("countdown"); + + total_time_label = new Gtk.Label (null) { + margin_top = 12 + }; + total_time_label.add_css_class ("total-time"); + + start_button = new Gtk.Button.with_label (_("Start")) { + width_request = 125, + halign = CENTER + }; + start_button.add_css_class ("pomodoro-button"); + + resume_button = new Gtk.Button.with_label (_("Resume")); + resume_button.add_css_class ("pomodoro-button"); + + pause_button = new Gtk.Button.with_label (_("Pause")); + pause_button.add_css_class ("pomodoro-button"); + + resume_pause_stack = new Gtk.Stack () { + transition_type = CROSSFADE + }; + + resume_pause_stack.add_child (resume_button); + resume_pause_stack.add_child (pause_button); + + stop_button = new Gtk.Button.with_label (_("Stop")); + stop_button.add_css_class ("pomodoro-button"); + + var action_buttons_box = new Gtk.Box (HORIZONTAL, 6) { + homogeneous = true + }; + action_buttons_box.append (resume_pause_stack); + action_buttons_box.append (stop_button); + + skip_button = new Gtk.Button.with_label (_("Skip")) { + width_request = 125, + halign = CENTER + }; + skip_button.add_css_class ("pomodoro-button"); + + buttons_stack = new Gtk.Stack () { + vexpand = true, + valign = END, + transition_type = CROSSFADE + }; + buttons_stack.add_named (start_button, "start"); + buttons_stack.add_named (skip_button, "break"); + buttons_stack.add_named (action_buttons_box, "pomodoro"); + + var container = new Gtk.Box (VERTICAL, 0) { + vexpand = true, + margin_top = 24, + margin_end = 24, + margin_bottom = 24, + margin_start = 24 + }; + container.append (countdown_label); + container.append (total_time_label); + container.append (buttons_stack); + + var toolbar_view = new Adw.ToolbarView () { + content = new Gtk.WindowHandle () { + child = container + } + }; + toolbar_view.add_top_bar (headerbar); + + var null_title = new Gtk.Grid () { + visible = false + }; + set_titlebar (null_title); + + child = toolbar_view; + add_css_class ("main-window"); + + // Instantiating tomato managers + work = new Managers.WorkManager (); + notification = new Managers.NotificationManager (); + launcher = new Managers.LauncherManager (work); + + update_progress (); + next_status (); + + start_button.clicked.connect (on_start_clicked); + pause_button.clicked.connect (on_pause_clicked); + resume_button.clicked.connect (on_resume_clicked); + stop_button.clicked.connect (on_stop_clicked); + skip_button.clicked.connect (on_skip_clicked); + + var gesture_focus = new Gtk.EventControllerFocus (); + ((Gtk.Widget) this).add_controller (gesture_focus); + gesture_focus.enter.connect (() => { + launcher.hide_progress (); + }); + + gesture_focus.leave.connect (() => { + if (!paused) { + launcher.show_progress (); + } + }); + + appmenu.clicked.connect (() => { + pref_dialog = new Dialogs.PreferencesDialog (this); + pref_dialog.show (); + + connect_pref_signals (); + }); + } + + private void update_style (string view) { + string color_primary; + + switch (view) { + case "start": + color_primary = "#8ea5af"; + break; + case "pomodoro": + color_primary = "#df4b4b"; + break; + case "break": + color_primary = "#05B560"; + break; + default: + color_primary = "#8ea5af"; + break; + } + + var provider = new Gtk.CssProvider (); + + try { + var colored_css = COLOR_PRIMARY.printf (color_primary); + provider.load_from_string (colored_css); + Gtk.StyleContext.add_provider_for_display ( + Gdk.Display.get_default (), provider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + ); + } catch (GLib.Error e) { + critical (e.message); + } + } + + private void on_start_clicked () { + work.start (); + next_status (); + update_progress (); + play (); + } - private Gtk.Label countdown_label; - private Gtk.Label total_time_label; + private void on_resume_clicked () { + if (preferences.auto_stop && stop_timeout_id != 0 && !stopped) { + finish_auto_stop (); + } - private Gtk.Button start_button; - private Gtk.Button resume_button; - private Gtk.Button pause_button; - private Gtk.Button stop_button; - private Gtk.Button skip_button; + play (); + } - private Gtk.Stack resume_pause_stack; - private Gtk.Stack buttons_stack; + private void on_pause_clicked () { + pause (); + update_progress (); + /* Show a notification when the app is paused for a long period */ + if (preferences.auto_stop && saved.status == Status.POMODORO) { + message ("Auto stop countdown started"); + stop_timeout_id = Timeout.add (TIME, start_auto_stop); + } else { + stop_timeout_id = 0; + } + } - private Gtk.Button appmenu; + private void on_stop_clicked () { + stop (); + work.stop (); + work.reset_countdown (); + next_status (); - private int stop_countdown = 14; - private bool paused = true; - private bool stopped = true; + if (preferences.auto_stop && stop_timeout_id != 0 && stopped) { + finish_auto_stop (); + } + } - private const uint TIME = 1000; - private uint work_timeout_id = 0; - private uint stop_timeout_id = 0; + private void on_skip_clicked () { + on_stop_clicked (); + } - private Managers.WorkManager work; - private Managers.NotificationManager notification; - private Managers.LauncherManager launcher; + private void play () { + set_pause (false); - private Services.SavedState saved { get; default = Services.SavedState.instance (); } - private Services.Preferences preferences { get; default = Services.Preferences.instance (); } + if (work_timeout_id != 0) { + Source.remove (work_timeout_id); + } - private Dialogs.PreferencesDialog pref_dialog; + work_timeout_id = Timeout.add (TIME, update_time); + } - public MainWindow (Gtk.Application application) { - Object ( - application: application, - default_height: 250, - default_width: 300, - resizable: false, - icon_name: "io.github.ellie_commons.tomato", - title: "Tomato" - ); - } + private void pause () { + set_pause (true); + launcher.hide_progress (); - static construct { - weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_for_display (Gdk.Display.get_default ()); - default_theme.add_resource_path ("io/github/ellie_commons/tomato/"); + if (work_timeout_id != 0) { + Source.remove (work_timeout_id); + work_timeout_id = 0; + } } - construct { - var headerbar = new Adw.HeaderBar () { - decoration_layout = "close:" - }; - - appmenu = new Gtk.Button.from_icon_name ("open-menu-symbolic") { - tooltip_text = _("Preferences") - }; - appmenu.add_css_class (Granite.STYLE_CLASS_FLAT); - appmenu.add_css_class ("menu"); - - headerbar.pack_end (appmenu); - - countdown_label = new Gtk.Label (null); - countdown_label.add_css_class ("countdown"); - - total_time_label = new Gtk.Label (null) { - margin_top = 12 - }; - total_time_label.add_css_class ("total-time"); - - start_button = new Gtk.Button.with_label (_("Start")) { - width_request = 125, - halign = CENTER - }; - start_button.add_css_class ("pomodoro-button"); - - resume_button = new Gtk.Button.with_label (_("Resume")); - resume_button.add_css_class ("pomodoro-button"); - - pause_button = new Gtk.Button.with_label (_("Pause")); - pause_button.add_css_class ("pomodoro-button"); - - resume_pause_stack = new Gtk.Stack () { - transition_type = CROSSFADE - }; - - resume_pause_stack.add_child (resume_button); - resume_pause_stack.add_child (pause_button); - - stop_button = new Gtk.Button.with_label (_("Stop")); - stop_button.add_css_class ("pomodoro-button"); - - var action_buttons_box = new Gtk.Box (HORIZONTAL, 6) { - homogeneous = true - }; - action_buttons_box.append (resume_pause_stack); - action_buttons_box.append (stop_button); - - skip_button = new Gtk.Button.with_label (_("Skip")) { - width_request = 125, - halign = CENTER - }; - skip_button.add_css_class ("pomodoro-button"); - - buttons_stack = new Gtk.Stack () { - vexpand = true, - valign = END, - transition_type = CROSSFADE - }; - buttons_stack.add_named (start_button, "start"); - buttons_stack.add_named (skip_button, "break"); - buttons_stack.add_named (action_buttons_box, "pomodoro"); - - var container = new Gtk.Box (VERTICAL, 0) { - vexpand = true, - margin_top = 24, - margin_end = 24, - margin_bottom = 24, - margin_start = 24 - }; - container.append (countdown_label); - container.append (total_time_label); - container.append (buttons_stack); - - var toolbar_view = new Adw.ToolbarView () { - content = new Gtk.WindowHandle () { - child = container - } - }; - toolbar_view.add_top_bar (headerbar); - - var null_title = new Gtk.Grid () { - visible = false - }; - set_titlebar (null_title); - - child = toolbar_view; - add_css_class ("main-window"); - - // Instantiating tomato managers - work = new Managers.WorkManager (); - notification = new Managers.NotificationManager (); - launcher = new Managers.LauncherManager (work); - - update_progress (); - next_status (); - - start_button.clicked.connect (on_start_clicked); - pause_button.clicked.connect (on_pause_clicked); - resume_button.clicked.connect (on_resume_clicked); - stop_button.clicked.connect (on_stop_clicked); - skip_button.clicked.connect (on_skip_clicked); - - var gesture_focus = new Gtk.EventControllerFocus (); - ((Gtk.Widget) this).add_controller (gesture_focus); - gesture_focus.enter.connect (() => { - launcher.hide_progress (); - }); - - gesture_focus.leave.connect (() => { - if (!paused) { - launcher.show_progress (); - } - }); - - appmenu.clicked.connect (() => { - pref_dialog = new Dialogs.PreferencesDialog (this); - pref_dialog.show (); - - connect_pref_signals (); - }); - } - - private void update_style (string view) { - string color_primary; - - switch (view) { - case "start": - color_primary = "#8ea5af"; - break; - case "pomodoro": - color_primary = "#df4b4b"; - break; - case "break": - color_primary = "#05B560"; - break; - default: - color_primary = "#8ea5af"; - break; - } - - var provider = new Gtk.CssProvider (); - - try { - var colored_css = COLOR_PRIMARY.printf (color_primary); - provider.load_from_string (colored_css); - Gtk.StyleContext.add_provider_for_display ( - Gdk.Display.get_default (), provider, - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION - ); - } catch (GLib.Error e) { - critical (e.message); - } - } - - private void on_start_clicked () { - work.start (); - next_status (); - update_progress (); - play (); - } - - private void on_resume_clicked () { - if (preferences.auto_stop && stop_timeout_id != 0 && !stopped) { - finish_auto_stop (); - } - - play (); - } - - private void on_pause_clicked () { - pause (); - update_progress (); - /* Show a notification when the app is paused for a long period */ - if (preferences.auto_stop && saved.status == Status.POMODORO) { - message ("Auto stop countdown started"); - stop_timeout_id = Timeout.add (TIME, start_auto_stop); - } else { - stop_timeout_id = 0; - } - } - - private void on_stop_clicked () { - stop (); - work.stop (); - work.reset_countdown (); - next_status (); - - if (preferences.auto_stop && stop_timeout_id != 0 && stopped) { - finish_auto_stop (); - } - } - - private void on_skip_clicked () { - on_stop_clicked (); - } - - private void play () { - set_pause (false); - - if (work_timeout_id != 0) { - Source.remove (work_timeout_id); - } - - work_timeout_id = Timeout.add (TIME, update_time); - } - - private void pause () { - set_pause (true); - launcher.hide_progress (); - - if (work_timeout_id != 0) { - Source.remove (work_timeout_id); - work_timeout_id = 0; - } - } - - private void stop () { - stopped = true; - pause (); - } - - private void set_pause (bool topause = true) { - paused = topause; - if (!paused) { - stopped = paused; - } - - window_set_pause (topause); - } - - private bool update_time () { - var rand = new Rand (); - if (!paused) { - work.tick (); - if (work.time_is_over ()) { - break_messages_index = rand.int_range (0, break_messages.length); - notification.show_status (); - next_status (); - if (preferences.pause_after_break && saved.status == Status.POMODORO) { - on_stop_clicked (); - return false; - } - } - - update_progress (); - } - - return !paused; - } - - public void next_status () { - if (saved.status == Status.START) { - buttons_stack.visible_child_name = "start"; - update_style ("start"); - title = "Pomodoro %d".printf (saved.pomodoro_count + 1); - appmenu.sensitive = true; - } else if (saved.status == Status.SHORT_BREAK) { - buttons_stack.visible_child_name = "break"; - update_style ("break"); - title = _("Short Break"); - appmenu.sensitive = true; - } else if (saved.status == Status.LONG_BREAK) { - buttons_stack.visible_child_name = "break"; - update_style ("break"); - title = _("Long Break"); - appmenu.sensitive = true; - } else { - buttons_stack.visible_child_name = "pomodoro"; - update_style ("pomodoro"); - title = "Pomodoro %d".printf (saved.pomodoro_count + 1); - appmenu.sensitive = false; - } - - update_progress (); - } - - public void update_progress () { - update_countdown (); - update_total_time (); - launcher.update_progress (); - } - - public void update_countdown () { - countdown_label.label = work.formatted_countdown (); - } - - public void update_total_time () { - if ((saved.status == Status.START || saved.status == Status.SHORT_BREAK || saved.status == Status.LONG_BREAK || paused) && saved.total_time != 0) { - total_time_label.label = work.formatted_total_time () + _(" of work"); - } else { - total_time_label.label = ""; - } - } - - private void window_set_pause (bool topause = true) { - paused = topause; - if (!paused) { - stopped = paused; - } - - if (topause) { - resume_pause_stack.visible_child = resume_button; - resume_button.grab_focus (); - } else { - resume_pause_stack.visible_child = pause_button; - pause_button.grab_focus (); - } - } - - private bool start_auto_stop () { - if (paused && !stopped) { - update_stop (_("Stopping in ") + "%d".printf (stop_countdown)); - stop_countdown -= 1; - if (stop_countdown == -1) { - on_stop_clicked (); - stop_countdown = 14; - notification.show (_("Pomodoro was interrupted"), _("Tomato was paused for a long time. You might have lost focus. Try a new pomodoro!")); - } - } - - return paused; - } - - private void finish_auto_stop () { - Source.remove (stop_timeout_id); - stop_timeout_id = 0; - stop_countdown = 14; - update_stop (_("Stop")); - message ("Finished auto stop"); - } - - public void update_stop (string text) { - stop_button.label = text; - } - - private void connect_pref_signals () { - /* Watch for change in settings*/ - pref_dialog.pomodoro_changed.connect (() => { - if (saved.status == Status.START) { - work.reset_countdown (); - update_progress (); - } - pref_dialog.update_timing_sensitivity (); - message ("Pomodoro scale changed"); - }); - - pref_dialog.short_break_changed.connect (() => { - pref_dialog.update_timing_sensitivity (); - message ("Short break scale changed"); - }); - - pref_dialog.long_break_changed.connect (() => { - pref_dialog.update_timing_sensitivity (); - message ("Long break scale changed"); - }); - - pref_dialog.long_break_delay_changed.connect (() => { - pref_dialog.update_timing_sensitivity (); - }); - - //watch for change in preferences - preferences.schema.changed.connect (() => { - pref_dialog.update_timing_sensitivity (); - pref_dialog.update_work_sensitivity (); - }); - - //watch for reset action - pref_dialog.reset_work_clicked.connect (() => { - work.reset (); - on_stop_clicked (); - pref_dialog.update_work_sensitivity (); - }); - } -} \ No newline at end of file + private void stop () { + stopped = true; + pause (); + } + + private void set_pause (bool topause = true) { + paused = topause; + if (!paused) { + stopped = paused; + } + + window_set_pause (topause); + } + + private bool update_time () { + var rand = new Rand (); + if (!paused) { + work.tick (); + if (work.time_is_over ()) { + break_messages_index = rand.int_range (0, break_messages.length); + notification.show_status (); + next_status (); + if (preferences.pause_after_break && saved.status == Status.POMODORO) { + on_stop_clicked (); + return false; + } + } + + update_progress (); + } + + return !paused; + } + + public void next_status () { + if (saved.status == Status.START) { + buttons_stack.visible_child_name = "start"; + update_style ("start"); + title = "Pomodoro %d".printf (saved.pomodoro_count + 1); + appmenu.sensitive = true; + } else if (saved.status == Status.SHORT_BREAK) { + buttons_stack.visible_child_name = "break"; + update_style ("break"); + title = _("Short Break"); + appmenu.sensitive = true; + } else if (saved.status == Status.LONG_BREAK) { + buttons_stack.visible_child_name = "break"; + update_style ("break"); + title = _("Long Break"); + appmenu.sensitive = true; + } else { + buttons_stack.visible_child_name = "pomodoro"; + update_style ("pomodoro"); + title = "Pomodoro %d".printf (saved.pomodoro_count + 1); + appmenu.sensitive = false; + } + + update_progress (); + } + + public void update_progress () { + update_countdown (); + update_total_time (); + launcher.update_progress (); + } + + public void update_countdown () { + countdown_label.label = work.formatted_countdown (); + } + + public void update_total_time () { + if ((saved.status == Status.START || saved.status == Status.SHORT_BREAK || saved.status == Status.LONG_BREAK || paused) && saved.total_time != 0) { + total_time_label.label = work.formatted_total_time () + _(" of work"); + } else { + total_time_label.label = ""; + } + } + + private void window_set_pause (bool topause = true) { + paused = topause; + if (!paused) { + stopped = paused; + } + + if (topause) { + resume_pause_stack.visible_child = resume_button; + resume_button.grab_focus (); + } else { + resume_pause_stack.visible_child = pause_button; + pause_button.grab_focus (); + } + } + + private bool start_auto_stop () { + if (paused && !stopped) { + update_stop (_("Stopping in ") + "%d".printf (stop_countdown)); + stop_countdown -= 1; + if (stop_countdown == -1) { + on_stop_clicked (); + stop_countdown = 14; + notification.show (_("Pomodoro was interrupted"), _("Tomato was paused for a long time. You might have lost focus. Try a new pomodoro!")); + } + } + + return paused; + } + + private void finish_auto_stop () { + Source.remove (stop_timeout_id); + stop_timeout_id = 0; + stop_countdown = 14; + update_stop (_("Stop")); + message ("Finished auto stop"); + } + + public void update_stop (string text) { + stop_button.label = text; + } + + private void connect_pref_signals () { + /* Watch for change in settings*/ + pref_dialog.pomodoro_changed.connect (() => { + if (saved.status == Status.START) { + work.reset_countdown (); + update_progress (); + } + pref_dialog.update_timing_sensitivity (); + message ("Pomodoro scale changed"); + }); + + pref_dialog.short_break_changed.connect (() => { + pref_dialog.update_timing_sensitivity (); + message ("Short break scale changed"); + }); + + pref_dialog.long_break_changed.connect (() => { + pref_dialog.update_timing_sensitivity (); + message ("Long break scale changed"); + }); + + pref_dialog.long_break_delay_changed.connect (() => { + pref_dialog.update_timing_sensitivity (); + }); + + //watch for change in preferences + preferences.schema.changed.connect (() => { + pref_dialog.update_timing_sensitivity (); + pref_dialog.update_work_sensitivity (); + }); + + //watch for reset action + pref_dialog.reset_work_clicked.connect (() => { + work.reset (); + on_stop_clicked (); + pref_dialog.update_work_sensitivity (); + }); + } +} diff --git a/src/Managers/LauncherManager.vala b/src/Managers/LauncherManager.vala index 6b00766..cdd75ce 100644 --- a/src/Managers/LauncherManager.vala +++ b/src/Managers/LauncherManager.vala @@ -21,58 +21,58 @@ */ public class Managers.LauncherManager : GLib.Object { - public Managers.WorkManager work { get; construct; } + public Managers.WorkManager work { get; construct; } - private Services.SavedState saved; - private Services.Settings settings; + private Services.SavedState saved; + private Services.Settings settings; - public LauncherManager (Managers.WorkManager work) { - Object (work: work); - } + public LauncherManager (Managers.WorkManager work) { + Object (work: work); + } - construct { - saved = Services.SavedState.instance (); - settings = Services.Settings.instance (); + construct { + saved = Services.SavedState.instance (); + settings = Services.Settings.instance (); - update_progress (); - } + update_progress (); + } - public void update_progress () { - double duration; - if (saved.status == Status.SHORT_BREAK) { - duration = settings.short_break_duration * 60.0; - } else if (saved.status == Status.LONG_BREAK) { - duration = settings.long_break_duration * 60.0; - } else { - duration = settings.pomodoro_duration * 60.0; - } + public void update_progress () { + double duration; + if (saved.status == Status.SHORT_BREAK) { + duration = settings.short_break_duration * 60.0; + } else if (saved.status == Status.LONG_BREAK) { + duration = settings.long_break_duration * 60.0; + } else { + duration = settings.pomodoro_duration * 60.0; + } - Granite.Services.Application.set_progress.begin (1 - work.raw_countdown () / duration, (obj, res) => { - try { - Granite.Services.Application.set_progress.end (res); - } catch (GLib.Error e) { - critical (e.message); - } - }); - } + Granite.Services.Application.set_progress.begin (1 - work.raw_countdown () / duration, (obj, res) => { + try { + Granite.Services.Application.set_progress.end (res); + } catch (GLib.Error e) { + critical (e.message); + } + }); + } - public void show_progress () { - Granite.Services.Application.set_progress_visible.begin (true, (obj, res) => { - try { - Granite.Services.Application.set_progress_visible.end (res); - } catch (GLib.Error e) { - critical (e.message); - } - }); - } + public void show_progress () { + Granite.Services.Application.set_progress_visible.begin (true, (obj, res) => { + try { + Granite.Services.Application.set_progress_visible.end (res); + } catch (GLib.Error e) { + critical (e.message); + } + }); + } - public void hide_progress () { - Granite.Services.Application.set_progress_visible.begin (false, (obj, res) => { - try { - Granite.Services.Application.set_progress_visible.end (res); - } catch (GLib.Error e) { - critical (e.message); - } - }); - } -} \ No newline at end of file + public void hide_progress () { + Granite.Services.Application.set_progress_visible.begin (false, (obj, res) => { + try { + Granite.Services.Application.set_progress_visible.end (res); + } catch (GLib.Error e) { + critical (e.message); + } + }); + } +} diff --git a/src/Managers/NotificationManager.vala b/src/Managers/NotificationManager.vala index fa260a7..050bda8 100644 --- a/src/Managers/NotificationManager.vala +++ b/src/Managers/NotificationManager.vala @@ -21,39 +21,39 @@ */ public class Managers.NotificationManager { - private SoundManager sound; - private Services.SavedState saved; - private Services.Preferences preferences; + private SoundManager sound; + private Services.SavedState saved; + private Services.Preferences preferences; - public NotificationManager () { - sound = new SoundManager (); - saved = Services.SavedState.instance (); - preferences = Services.Preferences.instance (); - } + public NotificationManager () { + sound = new SoundManager (); + saved = Services.SavedState.instance (); + preferences = Services.Preferences.instance (); + } - public void show_status () { - string title, body; - if (saved.status == Status.POMODORO) { - title = _("Pomodoro Time"); - body = _("Get back to work!"); - } else if (saved.status == Status.SHORT_BREAK) { - title = _("Short Break"); - body = _(break_messages[break_messages_index]); - } else { - title = _("Long Break!"); - body = _(break_messages[break_messages_index]); - } - if (preferences.pomodoro_sound_enabled) { - sound.play (); - } + public void show_status () { + string title, body; + if (saved.status == Status.POMODORO) { + title = _("Pomodoro Time"); + body = _("Get back to work!"); + } else if (saved.status == Status.SHORT_BREAK) { + title = _("Short Break"); + body = _(break_messages[break_messages_index]); + } else { + title = _("Long Break!"); + body = _(break_messages[break_messages_index]); + } + if (preferences.pomodoro_sound_enabled) { + sound.play (); + } - show (title, body); - } + show (title, body); + } - public void show (string title, string body) { - var notification = new GLib.Notification (title); - notification.set_body (body); - notification.set_icon (new ThemedIcon ("io.github.ellie_commons.tomato")); - GLib.Application.get_default ().send_notification ("com.github.tomatoers.tomato", notification); - } -} \ No newline at end of file + public void show (string title, string body) { + var notification = new GLib.Notification (title); + notification.set_body (body); + notification.set_icon (new ThemedIcon ("io.github.ellie_commons.tomato")); + GLib.Application.get_default ().send_notification ("com.github.tomatoers.tomato", notification); + } +} diff --git a/src/Managers/SoundManager.vala b/src/Managers/SoundManager.vala index 437e75c..1cc290c 100644 --- a/src/Managers/SoundManager.vala +++ b/src/Managers/SoundManager.vala @@ -21,26 +21,26 @@ */ public class Managers.SoundManager { - private Canberra.Context? player; - private string sound_id; + private Canberra.Context? player; + private string sound_id; - public SoundManager () { - this.with_custom_sound ("complete"); - } + public SoundManager () { + this.with_custom_sound ("complete"); + } - public SoundManager.with_custom_sound (string sound_id) { - if (Canberra.Context.create (out player) < 0) { - warning ("Sound will not be available"); - player = null; - } + public SoundManager.with_custom_sound (string sound_id) { + if (Canberra.Context.create (out player) < 0) { + warning ("Sound will not be available"); + player = null; + } - this.sound_id = sound_id; - } + this.sound_id = sound_id; + } - public void play () { - if (player != null) { - player.play (1, Canberra.PROP_EVENT_ID, sound_id, - Canberra.PROP_MEDIA_ROLE, "alarm"); - } - } -} \ No newline at end of file + public void play () { + if (player != null) { + player.play (1, Canberra.PROP_EVENT_ID, sound_id, + Canberra.PROP_MEDIA_ROLE, "alarm"); + } + } +} diff --git a/src/Managers/WorkManager.vala b/src/Managers/WorkManager.vala index 4a45998..77a0e43 100644 --- a/src/Managers/WorkManager.vala +++ b/src/Managers/WorkManager.vala @@ -21,139 +21,139 @@ */ public class Managers.WorkManager : GLib.Object { - private Utils.Countdown countdown; - private Utils.Timer total_time; - - int ticks = 1; - private Services.SavedState saved; - private Services.Settings settings; - private Services.Preferences preferences; - - static GLib.Once _instance; - public static unowned Managers.WorkManager instance () { - return _instance.once (() => { - return new Managers.WorkManager (); - }); - } - - construct { - saved = Services.SavedState.instance (); - settings = Services.Settings.instance (); - preferences = Services.Preferences.instance (); - - countdown = new Utils.Countdown (); - total_time = new Utils.Timer (); - - if (!saved.is_date_today () && preferences.reset_work_everyday) { - reset (); - } else { - set_countdown (saved.countdown); - set_total_time (saved.total_time); - } - - saved.update_date (); - } - - public int raw_countdown () { - return countdown.get_current_time (); - } - - public string formatted_countdown () { - return countdown.get_current_ftime (); - } - - public string formatted_total_time () { - return total_time.get_current_ftime (); - } - - public void start () { - set_status (Status.POMODORO); - } - - public void stop () { - set_status (Status.START); - message ("New status -> Start"); - } - - public void tick () { - saved.countdown = countdown.tick (); - - if (saved.status == Status.POMODORO) { - if (ticks == 60) { - saved.total_time = total_time.tick (); - ticks = 1; - message ("+1 minute worked"); - } else { - ticks += 1; - } - } - } - - public void set_status (Status status) { - saved.status = status; - } - - public bool time_is_over () { - bool is_over = countdown.is_over (); - if (is_over) { - if (saved.status == Status.POMODORO) - saved.pomodoro_count += 1; - update_status (); - reset_countdown (); - } - return is_over; - } - - public void reset () { - stop (); - ticks = 1; - - reset_countdown (); - set_total_time (0); - - saved.pomodoro_count = 0; - } - - public void reset_countdown () { - switch (saved.status) { - case Status.START: - case Status.POMODORO: - set_countdown (settings.pomodoro_duration * 60); - break; - case Status.SHORT_BREAK: - set_countdown (settings.short_break_duration * 60); - break; - case Status.LONG_BREAK: - set_countdown (settings.long_break_duration * 60); - break; - } - - if (preferences.debug_mode) { - set_countdown (10); - } - } - - private void set_countdown (int time) { - countdown.set_current_time (time); - saved.countdown = time; - } - - private void set_total_time (int time) { - total_time.set_current_time (time); - saved.total_time = time; - } - - private void update_status () { - if (saved.status == Status.POMODORO && saved.pomodoro_count % settings.long_break_delay == 0) { - set_status (Status.LONG_BREAK); - message ("New status -> Long Break"); - } else if (saved.status == Status.POMODORO && saved.pomodoro_count % settings.long_break_delay != 0) { - set_status (Status.SHORT_BREAK); - message ("New status -> Short Break"); - } else { - set_status (Status.POMODORO); - message ("New status -> Pomodoro"); - } - } - -} \ No newline at end of file + private Utils.Countdown countdown; + private Utils.Timer total_time; + + int ticks = 1; + private Services.SavedState saved; + private Services.Settings settings; + private Services.Preferences preferences; + + static GLib.Once _instance; + public static unowned Managers.WorkManager instance () { + return _instance.once (() => { + return new Managers.WorkManager (); + }); + } + + construct { + saved = Services.SavedState.instance (); + settings = Services.Settings.instance (); + preferences = Services.Preferences.instance (); + + countdown = new Utils.Countdown (); + total_time = new Utils.Timer (); + + if (!saved.is_date_today () && preferences.reset_work_everyday) { + reset (); + } else { + set_countdown (saved.countdown); + set_total_time (saved.total_time); + } + + saved.update_date (); + } + + public int raw_countdown () { + return countdown.get_current_time (); + } + + public string formatted_countdown () { + return countdown.get_current_ftime (); + } + + public string formatted_total_time () { + return total_time.get_current_ftime (); + } + + public void start () { + set_status (Status.POMODORO); + } + + public void stop () { + set_status (Status.START); + message ("New status -> Start"); + } + + public void tick () { + saved.countdown = countdown.tick (); + + if (saved.status == Status.POMODORO) { + if (ticks == 60) { + saved.total_time = total_time.tick (); + ticks = 1; + message ("+1 minute worked"); + } else { + ticks += 1; + } + } + } + + public void set_status (Status status) { + saved.status = status; + } + + public bool time_is_over () { + bool is_over = countdown.is_over (); + if (is_over) { + if (saved.status == Status.POMODORO) + saved.pomodoro_count += 1; + update_status (); + reset_countdown (); + } + return is_over; + } + + public void reset () { + stop (); + ticks = 1; + + reset_countdown (); + set_total_time (0); + + saved.pomodoro_count = 0; + } + + public void reset_countdown () { + switch (saved.status) { + case Status.START: + case Status.POMODORO: + set_countdown (settings.pomodoro_duration * 60); + break; + case Status.SHORT_BREAK: + set_countdown (settings.short_break_duration * 60); + break; + case Status.LONG_BREAK: + set_countdown (settings.long_break_duration * 60); + break; + } + + if (preferences.debug_mode) { + set_countdown (10); + } + } + + private void set_countdown (int time) { + countdown.set_current_time (time); + saved.countdown = time; + } + + private void set_total_time (int time) { + total_time.set_current_time (time); + saved.total_time = time; + } + + private void update_status () { + if (saved.status == Status.POMODORO && saved.pomodoro_count % settings.long_break_delay == 0) { + set_status (Status.LONG_BREAK); + message ("New status -> Long Break"); + } else if (saved.status == Status.POMODORO && saved.pomodoro_count % settings.long_break_delay != 0) { + set_status (Status.SHORT_BREAK); + message ("New status -> Short Break"); + } else { + set_status (Status.POMODORO); + message ("New status -> Pomodoro"); + } + } + +} diff --git a/src/Services/Preferences.vala b/src/Services/Preferences.vala index 8201715..77f6136 100644 --- a/src/Services/Preferences.vala +++ b/src/Services/Preferences.vala @@ -21,88 +21,88 @@ */ public class Services.Preferences : GLib.Object { - bool _reset_work_everyday; - public bool reset_work_everyday { - get { - _reset_work_everyday = schema.get_boolean ("reset-work-everyday"); - return _reset_work_everyday; - } + bool _reset_work_everyday; + public bool reset_work_everyday { + get { + _reset_work_everyday = schema.get_boolean ("reset-work-everyday"); + return _reset_work_everyday; + } - set { - schema.set_boolean ("reset-work-everyday", value); - } - } + set { + schema.set_boolean ("reset-work-everyday", value); + } + } - bool _pause_after_break; - public bool pause_after_break { - get { - _pause_after_break = schema.get_boolean ("pause-after-break"); - return _pause_after_break; - } + bool _pause_after_break; + public bool pause_after_break { + get { + _pause_after_break = schema.get_boolean ("pause-after-break"); + return _pause_after_break; + } - set { - schema.set_boolean ("pause-after-break", value); - } - } + set { + schema.set_boolean ("pause-after-break", value); + } + } - bool _auto_stop; - public bool auto_stop { - get { - _auto_stop = schema.get_boolean ("auto-stop"); - return _auto_stop; - } + bool _auto_stop; + public bool auto_stop { + get { + _auto_stop = schema.get_boolean ("auto-stop"); + return _auto_stop; + } - set { - schema.set_boolean ("auto-stop", value); - } - } + set { + schema.set_boolean ("auto-stop", value); + } + } - bool _pomodoro_sound_enabled; - public bool pomodoro_sound_enabled { - get { - _pomodoro_sound_enabled = schema.get_boolean ("pomodoro-sound-enabled"); - return _pomodoro_sound_enabled; - } + bool _pomodoro_sound_enabled; + public bool pomodoro_sound_enabled { + get { + _pomodoro_sound_enabled = schema.get_boolean ("pomodoro-sound-enabled"); + return _pomodoro_sound_enabled; + } - set { - schema.set_boolean ("pomodoro-sound-enabled", value); - } - } + set { + schema.set_boolean ("pomodoro-sound-enabled", value); + } + } - bool _notifications_blocked; - public bool notifications_blocked { - get { - _notifications_blocked = schema.get_boolean ("notifications-blocked"); - return _notifications_blocked; - } + bool _notifications_blocked; + public bool notifications_blocked { + get { + _notifications_blocked = schema.get_boolean ("notifications-blocked"); + return _notifications_blocked; + } - set { - schema.set_boolean ("notifications-blocked", value); - } - } + set { + schema.set_boolean ("notifications-blocked", value); + } + } - bool _debug_mode; - public bool debug_mode { - get { - _debug_mode = schema.get_boolean ("debug-mode"); - return _debug_mode; - } + bool _debug_mode; + public bool debug_mode { + get { + _debug_mode = schema.get_boolean ("debug-mode"); + return _debug_mode; + } - set { - schema.set_boolean ("debug-mode", value); - } - } + set { + schema.set_boolean ("debug-mode", value); + } + } - static GLib.Once _instance; - public static unowned Services.Preferences instance () { - return _instance.once (() => { - return new Services.Preferences (); - }); - } + static GLib.Once _instance; + public static unowned Services.Preferences instance () { + return _instance.once (() => { + return new Services.Preferences (); + }); + } - public GLib.Settings schema; + public GLib.Settings schema; - construct { - schema = new GLib.Settings ("io.github.ellie_commons.tomato.preferences"); - } -} \ No newline at end of file + construct { + schema = new GLib.Settings ("io.github.ellie_commons.tomato.preferences"); + } +} diff --git a/src/Services/SavedState.vala b/src/Services/SavedState.vala index a9ffb5f..3f4df51 100644 --- a/src/Services/SavedState.vala +++ b/src/Services/SavedState.vala @@ -21,85 +21,85 @@ */ public class Services.SavedState : GLib.Object { - string _date; - public string date { - get { - _date = schema.get_string ("date"); - return _date; - } + string _date; + public string date { + get { + _date = schema.get_string ("date"); + return _date; + } - set { - schema.set_string ("date", value); - } - } + set { + schema.set_string ("date", value); + } + } - Status _status; - public Status status { - get { - _status = (Status) schema.get_enum ("status"); - return _status; - } + Status _status; + public Status status { + get { + _status = (Status) schema.get_enum ("status"); + return _status; + } - set { - schema.set_enum ("status", value); - } - } + set { + schema.set_enum ("status", value); + } + } - int _countdown; - public int countdown { - get { - _countdown = schema.get_int ("countdown"); - return _countdown; - } + int _countdown; + public int countdown { + get { + _countdown = schema.get_int ("countdown"); + return _countdown; + } - set { - schema.set_int ("countdown", value); - } - } + set { + schema.set_int ("countdown", value); + } + } - int _total_time; - public int total_time { - get { - _total_time = schema.get_int ("total-time"); - return _total_time; - } + int _total_time; + public int total_time { + get { + _total_time = schema.get_int ("total-time"); + return _total_time; + } - set { - schema.set_int ("total-time", value); - } - } + set { + schema.set_int ("total-time", value); + } + } - int _pomodoro_count; - public int pomodoro_count { - get { - _pomodoro_count = schema.get_int ("pomodoro-count"); - return _pomodoro_count; - } + int _pomodoro_count; + public int pomodoro_count { + get { + _pomodoro_count = schema.get_int ("pomodoro-count"); + return _pomodoro_count; + } - set { - schema.set_int ("pomodoro-count", value); - } - } + set { + schema.set_int ("pomodoro-count", value); + } + } - public bool is_date_today () { - var dt = new DateTime.now_local (); - return date == dt.format ("%Y-%m-%d"); - } + public bool is_date_today () { + var dt = new DateTime.now_local (); + return date == dt.format ("%Y-%m-%d"); + } - public void update_date () { - date = (new DateTime.now_local ()).format ("%Y-%m-%d"); - } + public void update_date () { + date = (new DateTime.now_local ()).format ("%Y-%m-%d"); + } - static GLib.Once _instance; - public static unowned Services.SavedState instance () { - return _instance.once (() => { - return new Services.SavedState (); - }); - } + static GLib.Once _instance; + public static unowned Services.SavedState instance () { + return _instance.once (() => { + return new Services.SavedState (); + }); + } - public GLib.Settings schema; + public GLib.Settings schema; - construct { - schema = new GLib.Settings ("io.github.ellie_commons.tomato.saved"); - } -} \ No newline at end of file + construct { + schema = new GLib.Settings ("io.github.ellie_commons.tomato.saved"); + } +} diff --git a/src/Services/Settings.vala b/src/Services/Settings.vala index 0b0de3e..861c8f3 100644 --- a/src/Services/Settings.vala +++ b/src/Services/Settings.vala @@ -21,64 +21,64 @@ */ public class Services.Settings : GLib.Object { - int _pomodoro_duration; - public int pomodoro_duration { - get { - _pomodoro_duration = schema.get_int ("pomodoro-duration"); - return _pomodoro_duration; - } + int _pomodoro_duration; + public int pomodoro_duration { + get { + _pomodoro_duration = schema.get_int ("pomodoro-duration"); + return _pomodoro_duration; + } - set { - schema.set_int ("pomodoro-duration", value); - } - } + set { + schema.set_int ("pomodoro-duration", value); + } + } - int _short_break_duration; - public int short_break_duration { - get { - _short_break_duration = schema.get_int ("short-break-duration"); - return _short_break_duration; - } + int _short_break_duration; + public int short_break_duration { + get { + _short_break_duration = schema.get_int ("short-break-duration"); + return _short_break_duration; + } - set { - schema.set_int ("short-break-duration", value); - } - } + set { + schema.set_int ("short-break-duration", value); + } + } - int _long_break_duration; - public int long_break_duration { - get { - _long_break_duration = schema.get_int ("long-break-duration"); - return _long_break_duration; - } + int _long_break_duration; + public int long_break_duration { + get { + _long_break_duration = schema.get_int ("long-break-duration"); + return _long_break_duration; + } - set { - schema.set_int ("long-break-duration", value); - } - } + set { + schema.set_int ("long-break-duration", value); + } + } - int _long_break_delay; - public int long_break_delay { - get { - _long_break_delay = schema.get_int ("long-break-delay"); - return _long_break_delay; - } + int _long_break_delay; + public int long_break_delay { + get { + _long_break_delay = schema.get_int ("long-break-delay"); + return _long_break_delay; + } - set { - schema.set_int ("long-break-delay", value); - } - } + set { + schema.set_int ("long-break-delay", value); + } + } - static GLib.Once _instance; - public static unowned Services.Settings instance () { - return _instance.once (() => { - return new Services.Settings (); - }); - } + static GLib.Once _instance; + public static unowned Services.Settings instance () { + return _instance.once (() => { + return new Services.Settings (); + }); + } - public GLib.Settings schema; + public GLib.Settings schema; - construct { - schema = new GLib.Settings ("io.github.ellie_commons.tomato.settings"); - } -} \ No newline at end of file + construct { + schema = new GLib.Settings ("io.github.ellie_commons.tomato.settings"); + } +} diff --git a/src/Utils/Countdown.vala b/src/Utils/Countdown.vala index a7eb8b2..7252f07 100644 --- a/src/Utils/Countdown.vala +++ b/src/Utils/Countdown.vala @@ -21,55 +21,55 @@ */ public class Utils.Countdown { - private Services.Settings settings { get; default = Services.Settings.instance (); } + private Services.Settings settings { get; default = Services.Settings.instance (); } - struct Time { - int hours; - int minutes; - int seconds; - } + struct Time { + int hours; + int minutes; + int seconds; + } - private int current_time; + private int current_time; - public Countdown () { - set_current_time (settings.pomodoro_duration * 60); - } + public Countdown () { + set_current_time (settings.pomodoro_duration * 60); + } - public Countdown.with_time (int time) { - set_current_time (time); - } + public Countdown.with_time (int time) { + set_current_time (time); + } - public int tick () { - set_current_time (current_time - 1); - return current_time; - } + public int tick () { + set_current_time (current_time - 1); + return current_time; + } - public int get_current_time () { - return current_time; - } + public int get_current_time () { + return current_time; + } - public void set_current_time (int time) { - if (time >= 0) - current_time = time; - } + public void set_current_time (int time) { + if (time >= 0) + current_time = time; + } - public string get_current_ftime (bool without_hours = true) { - Time t = parse_time (current_time); - if (without_hours && t.hours == 0) { - return "%02d:%02d".printf (t.minutes, t.seconds); - } return "%02d:%02d:%02d".printf (t.hours, t.minutes, t.seconds); - } + public string get_current_ftime (bool without_hours = true) { + Time t = parse_time (current_time); + if (without_hours && t.hours == 0) { + return "%02d:%02d".printf (t.minutes, t.seconds); + } return "%02d:%02d:%02d".printf (t.hours, t.minutes, t.seconds); + } - public bool is_over () { - return current_time == 0; - } + public bool is_over () { + return current_time == 0; + } - private Time parse_time (int time) { - Time t = Time (); - t.hours = time / 3600; - time %= 3600; - t.minutes = time / 60; - t.seconds = time % 60; - return t; - } -} \ No newline at end of file + private Time parse_time (int time) { + Time t = Time (); + t.hours = time / 3600; + time %= 3600; + t.minutes = time / 60; + t.seconds = time % 60; + return t; + } +} diff --git a/src/Utils/Timer.vala b/src/Utils/Timer.vala index 28ed43d..b08d2de 100644 --- a/src/Utils/Timer.vala +++ b/src/Utils/Timer.vala @@ -21,49 +21,49 @@ */ public class Utils.Timer { - private struct Time { - int hours; - int minutes; - } + private struct Time { + int hours; + int minutes; + } - private int current_time; //in minutes - private string[] hours = {"", N_("hour"), N_("hours")}; - private string[] mins = {"", N_("minute"), N_("minutes")}; + private int current_time; //in minutes + private string[] hours = {"", N_("hour"), N_("hours")}; + private string[] mins = {"", N_("minute"), N_("minutes")}; - public Timer () { - set_current_time (0); - } + public Timer () { + set_current_time (0); + } - public void set_current_time (int time) { - current_time = time; - } + public void set_current_time (int time) { + current_time = time; + } - public int get_current_time () { - return current_time; - } + public int get_current_time () { + return current_time; + } - public string get_current_ftime () { - var t = parse_time (current_time); + public string get_current_ftime () { + var t = parse_time (current_time); - int hour_index = t.hours == 0 || t.hours == 1 ? t.hours : 2; - int minute_index = t.minutes == 0 || t.minutes == 1 ? t.minutes : 2; + int hour_index = t.hours == 0 || t.hours == 1 ? t.hours : 2; + int minute_index = t.minutes == 0 || t.minutes == 1 ? t.minutes : 2; - string time_label = t.hours == 0 ? "" : "%d %s".printf (t.hours, _(hours[hour_index])); - time_label += time_label != "" && t.minutes != 0 ? _(" and ") : ""; - time_label += t.minutes == 0 ? "" : "%d %s".printf (t.minutes, _(mins[minute_index])); + string time_label = t.hours == 0 ? "" : "%d %s".printf (t.hours, _(hours[hour_index])); + time_label += time_label != "" && t.minutes != 0 ? _(" and ") : ""; + time_label += t.minutes == 0 ? "" : "%d %s".printf (t.minutes, _(mins[minute_index])); - return time_label; - } + return time_label; + } - public int tick () { - set_current_time (current_time + 1); - return current_time; - } + public int tick () { + set_current_time (current_time + 1); + return current_time; + } - private Time parse_time (int time) { - var t = Time (); - t.hours = time / 60; - t.minutes = time %= 60; - return t; - } -} \ No newline at end of file + private Time parse_time (int time) { + var t = Time (); + t.hours = time / 60; + t.minutes = time %= 60; + return t; + } +} diff --git a/src/Widgets/ValueRange.vala b/src/Widgets/ValueRange.vala index 3cea6a1..9a7498e 100644 --- a/src/Widgets/ValueRange.vala +++ b/src/Widgets/ValueRange.vala @@ -21,49 +21,49 @@ */ public class Widgets.ValueRange : Adw.Bin { - public signal void changed (); + public signal void changed (); - //scale object - private Gtk.Scale scale; + //scale object + private Gtk.Scale scale; - //current value getter and setter methods - public int current_value { - get { - return (int) scale.get_value (); - } + //current value getter and setter methods + public int current_value { + get { + return (int) scale.get_value (); + } - set { - scale.set_value (value); - } - } + set { + scale.set_value (value); + } + } - //constructor - public ValueRange (double min, double max, double step, string? display = null, string? plural = null) { - //init scale and add it to this - scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, min, max, step) { - hexpand = true, - draw_value = true - }; + //constructor + public ValueRange (double min, double max, double step, string? display = null, string? plural = null) { + //init scale and add it to this + scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, min, max, step) { + hexpand = true, + draw_value = true + }; - child = scale; + child = scale; - //set optional display string - if (display != null) { - scale.set_format_value_func ((scale, val) => { - if (val == 1) { - return "%.0f %s".printf (val, display); - } - if (plural != null) { - return "%.0f %s".printf (val, plural); - } - return "%.0f".printf (val); - }); - } + //set optional display string + if (display != null) { + scale.set_format_value_func ((scale, val) => { + if (val == 1) { + return "%.0f %s".printf (val, display); + } + if (plural != null) { + return "%.0f %s".printf (val, plural); + } + return "%.0f".printf (val); + }); + } - //connect signals so that the scale updates its value on move - scale.value_changed.connect (() => { - current_value = current_value; - changed (); - }); - } -} \ No newline at end of file + //connect signals so that the scale updates its value on move + scale.value_changed.connect (() => { + current_value = current_value; + changed (); + }); + } +}