Skip to content

Commit

Permalink
3.5.1 - Fix timer bug for good.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lains committed Aug 13, 2021
1 parent 615eb14 commit 9c94d90
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
8 changes: 4 additions & 4 deletions data/ui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<object class="GtkBox">
<property name="spacing">12</property>
<child>
<object class="GtkButton" id="column_play_button">
<object class="GtkButton" id="timer_button">
<property name="label" translatable="yes">Start Timer</property>
<property name="tooltip-text" translatable="yes">Starts a log's timer</property>
<style>
Expand All @@ -110,7 +110,7 @@
</object>
</child>
<child>
<object class="GtkButton" id="column_button">
<object class="GtkButton" id="add_log_button">
<property name="label" translatable="yes">Add Log</property>
<property name="tooltip-text" translatable="yes">Adds a log to the list</property>
<style>
Expand Down Expand Up @@ -202,8 +202,8 @@
</template>
<object class="GtkSizeGroup" id="column_buttons">
<widgets>
<widget name="column_play_button"/>
<widget name="column_button"/>
<widget name="add_log_button"/>
<widget name="timer_button"/>
</widgets>
</object>
</interface>
Expand Down
50 changes: 26 additions & 24 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace Khronos {
[GtkChild]
public unowned Gtk.Label column_time_label;
[GtkChild]
public unowned Gtk.Button column_button;
public unowned Gtk.Button add_log_button;
[GtkChild]
public unowned Gtk.Button column_play_button;
public unowned Gtk.Button timer_button;
[GtkChild]
public unowned Gtk.MenuButton menu_button;
[GtkChild]
Expand Down Expand Up @@ -210,7 +210,7 @@ namespace Khronos {
});
});

column_button.clicked.connect (() => {
add_log_button.clicked.connect (() => {
var log = new Log ();
log.name = column_entry.text;
log.timedate = "%s\n%s%s".printf(column_time_label.label,
Expand All @@ -226,38 +226,42 @@ namespace Khronos {
liststore.append (log);
tm.save_to_file (liststore);
reset_timer ();
if (start != true) {
dt = null;
}
is_modified = true;
column_entry.text = "";
placeholder.set_visible(false);
});

column_play_button.clicked.connect (() => {
timer_button.clicked.connect (() => {
if (start != true) {
start = true;
dt = new GLib.DateTime.now_local ();
// For some reason, add() is closer to real time than add_seconds()
timer_id = GLib.Timeout.add (1000, () => {
timer ();
return true;
});;
column_play_button.label = _("Stop Timer");
column_play_button.get_style_context ().remove_class ("suggested-action");
column_play_button.get_style_context ().add_class ("destructive-action");
column_button.sensitive = false;
timer_button.label = _("Stop Timer");
timer_button.get_style_context ().remove_class ("suggested-action");
timer_button.get_style_context ().add_class ("destructive-action");
add_log_button.sensitive = false;
} else {
start = false;
GLib.Source.remove(timer_id);
column_play_button.label = _("Start Timer");
column_play_button.get_style_context ().remove_class ("destructive-action");
column_play_button.get_style_context ().add_class ("suggested-action");
column_button.sensitive = true;
timer_button.label = _("Start Timer");
timer_button.get_style_context ().remove_class ("destructive-action");
timer_button.get_style_context ().add_class ("suggested-action");
add_log_button.sensitive = true;
}
});

column_entry.changed.connect (() => {
if (column_entry.text_length != 0) {
column_play_button.sensitive = true;
timer_button.sensitive = true;
} else {
column_play_button.sensitive = false;
timer_button.sensitive = false;
}
column.unselect_all ();
});
Expand Down Expand Up @@ -335,7 +339,8 @@ namespace Khronos {
min = 0;
hrs = 0;
column_time_label.label = "<span font_features='tnum'>%02u%02u%02u</span>".printf(hrs, min, sec);
column_button.sensitive = false;
add_log_button.sensitive = false;
timer_button.sensitive = true;
column_entry.text = "";
}

Expand All @@ -349,7 +354,6 @@ namespace Khronos {

public void timer () {
if (start) {
dt = new GLib.DateTime.now_local ();
sec += 1;
column_time_label.label = "<span font_features='tnum'>%02u%02u%02u</span>".printf(hrs, min, sec);
if (sec >= 60) {
Expand All @@ -362,8 +366,6 @@ namespace Khronos {
column_time_label.label = "<span font_features='tnum'>%02u%02u%02u</span>".printf(hrs, min, sec);
}
}
} else {
dt = null;
}
}

Expand All @@ -387,16 +389,16 @@ namespace Khronos {
});
id3 = Timeout.add_seconds (Khronos.Application.gsettings.get_int("notification-delay")*2, () => {
notification3 ();
GLib.Source.remove (this.id2);
GLib.Source.remove (this.id1);
GLib.Source.remove (this.id2);
GLib.Source.remove (this.id4);
GLib.Source.remove (this.id5);
return true;
});
id4 = Timeout.add_seconds ((int) GLib.Math.floor (Khronos.Application.gsettings.get_int("notification-delay")*2.5), () => {
notification4 ();
GLib.Source.remove (this.id2);
GLib.Source.remove (this.id1);
GLib.Source.remove (this.id2);
GLib.Source.remove (this.id3);
GLib.Source.remove (this.id5);
return true;
Expand All @@ -423,7 +425,7 @@ namespace Khronos {

public void notification2 () {
var notification2 = new GLib.Notification ("%i minutes have passed".printf((int) GLib.Math.floor (Khronos.Application.gsettings.get_int("notification-delay")*1.5)));
notification2.set_body (_("Go rest for a while before continuing."));
notification2.set_body (_("Maybe grab a snack before continuing."));
var icon = new GLib.ThemedIcon ("appointment-symbolic");
notification2.set_icon (icon);

Expand All @@ -432,7 +434,7 @@ namespace Khronos {

public void notification3 () {
var notification3 = new GLib.Notification ("%i minutes have passed".printf(Khronos.Application.gsettings.get_int("notification-delay")*2));
notification3.set_body (_("Go rest for a while before continuing."));
notification3.set_body (_("Perhaps go get some coffee or tea before continuing."));
var icon = new GLib.ThemedIcon ("appointment-symbolic");
notification3.set_icon (icon);

Expand All @@ -441,7 +443,7 @@ namespace Khronos {

public void notification4 () {
var notification4 = new GLib.Notification ("%i minutes have passed".printf((int) GLib.Math.floor (Khronos.Application.gsettings.get_int("notification-delay")*2.5)));
notification4.set_body (_("Go rest for a while before continuing."));
notification4.set_body (_("That's a big task. Let's rest a bit before continuing."));
var icon = new GLib.ThemedIcon ("appointment-symbolic");
notification4.set_icon (icon);

Expand All @@ -450,7 +452,7 @@ namespace Khronos {

public void notification5 () {
var notification5 = new GLib.Notification ("%i minutes have passed".printf(Khronos.Application.gsettings.get_int("notification-delay")*3));
notification5.set_body (_("Go rest for a while before continuing."));
notification5.set_body (_("Amazing work! But please rest a bit before continuing."));
var icon = new GLib.ThemedIcon ("appointment-symbolic");
notification5.set_icon (icon);

Expand Down

0 comments on commit 9c94d90

Please sign in to comment.