3
This file is part of LoggerOuter.
5
LoggerOuter is free software: you can redistribute it and/or modify it under the
6
terms of the GNU Lesser General Public License as published by the Free Software
7
Foundation, either version 3 of the License, or (at your option) any later
10
LoggerOuter is distributed in the hope that it will be useful, but WITHOUT
11
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13
License for more details.
15
You should have received a copy of the GNU Lessel General Public License
16
along with LoggerOuter. If not, see <https://www.gnu.org/licenses/>.
19
public class LO.Timer : Gtk.Window {
23
Gtk.Label timer_label;
26
Gtk.Button close_button;
48
public delegate void ReturnCallback (ExitCode exit_code);
49
ReturnCallback callback;
53
this.width_request = 100;
54
this.height_request = 100;
55
this.resizable = false;
57
layout = new Gtk.Box (Gtk.Orientation.VERTICAL, 5) {
62
button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
68
timer_label = new Gtk.Label ("Time Remanining: 0") {
72
text_label = new Gtk.Label (this.text) {
76
layout.append (text_label);
77
layout.append (timer_label);
79
close_button = new Gtk.Button.with_label ("Cancel");
80
close_button.clicked.connect (() => {
81
return_to_caller (ExitCode.CANCEL);
83
button_box.append (close_button);
85
ok_button = new Gtk.Button.with_label ("OK");
86
ok_button.clicked.connect (() => {
87
return_to_caller (ExitCode.OK);
89
button_box.append (ok_button);
91
layout.append (button_box);
97
public Timer (string text, int time, owned ReturnCallback callback) {
100
this.callback = (owned) callback;
102
this.text_label.set_text (this.text);
106
public enum ExitCode {
111
public string to_string () {
120
assert_not_reached ();
125
private bool label_update () {
127
return_to_caller (ExitCode.OK);
133
string text = @"Time Remanining: $(this._time)";
134
this.timer_label.set_text (text);
140
private void start_timer () {
142
GLib.Timeout.add_seconds (1, label_update);
145
private void return_to_caller (ExitCode e) {
146
assert (this.callback != null);
153
static int main (string[] args) {
155
Gtk.Application app = new Gtk.Application ("com.foobar.test", GLib.ApplicationFlags.FLAGS_NONE);
156
app.activate.connect (() => {
157
LO.Timer t = new LO.Timer ("Shutting down", 30, (e) => {
158
print (@"Got: $(e)\n");
159
if (e == LO.Timer.ExitCode.OK) {