@@ -15,41 +15,38 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using Granite;
using Gtk;
using GLib;

namespace StopClock {
class StopClockApp : Granite.Application {
private Window window;

construct {
program_name = "StopClock";
exec_name = "stopclock";
app_years = "2015 - 2016";
app_launcher = "stopclock.desktop";
application_id = "com.github.nine-h.stopclock";
main_url = "https://github.com/Nine-H/stopclock";
bug_url = "https://github.com/Nine-H/stopclock/issues";
about_authors = { "Nine H <nine.gentooman@gmail.com>" };
about_license_type = Gtk.License.GPL_3_0;
about_comments = "It's right TWICE a day :D";
}

public StopClockApp () {
Granite.Services.Logger.initialize ("StopClockApp");
Granite.Services.Logger.DisplayLevel = Granite.Services.LogLevel.DEBUG;
}

public override void activate () {
window = new Window ();
}
class StopClockApp : Granite.Application {
private Window window;

construct {
program_name = "StopClock";
exec_name = "stopclock";
app_years = "2015 - 2016";
app_launcher = "stopclock.desktop";
application_id = "com.github.nine-h.stopclock";
main_url = "https://github.com/Nine-H/stopclock";
bug_url = "https://github.com/Nine-H/stopclock/issues";
about_authors = { "Nine H <nine.gentooman@gmail.com>" };
about_license_type = Gtk.License.GPL_3_0;
about_comments = "It's right TWICE a day :D";
}

public StopClockApp () {
Granite.Services.Logger.initialize ("StopClockApp");
Granite.Services.Logger.DisplayLevel = Granite.Services.LogLevel.DEBUG;
}

public override void activate () {
window = new Window ();
}


public static int main (string [] args) {
Gtk.init (ref args);
var app = new StopClockApp ();
return app.run (args);
}

public static int main ( string [] args ) {
Gtk.init (ref args);
var app = new StopClockApp ();
return app.run (args);
}
}

@@ -18,112 +18,109 @@
using Gtk;
using GLib;

namespace StopClock {
namespace StopWatch {
public class StopWatch : Gtk.Box {
//Global vars
private Gtk.Label readout;
private Gtk.Label miliseconds;
private Gtk.TreeView laps;
private Gtk.Button button_startstop;
private GLib.Timer timer;
private bool cleared;
private Gtk.ListStore laplist;
private Gtk.TreeIter iter;

public StopWatch (Gtk.Orientation orientation, int spacing) {
Object(orientation: orientation, spacing: spacing);

var controls = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
controls.set_border_width (12);

var readout_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 2);
readout_box.set_halign(Gtk.Align.CENTER);

readout = new Gtk.Label("");
readout.get_style_context().add_class("h1");
miliseconds = new Gtk.Label("");
miliseconds.get_style_context().add_class("h2");

timer = new GLib.Timer();

laplist = new Gtk.ListStore (2, typeof (string), typeof (string));

laps = new Gtk.TreeView.with_model ( laplist );
Gtk.CellRendererText cell = new Gtk.CellRendererText ();
laps.insert_column_with_attributes (-1, "Lap", cell, "text", 0);
laps.insert_column_with_attributes (-1, "Time", cell, "text", 0);


button_startstop = new Gtk.Button.with_label ("Start");
button_startstop.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
button_startstop.clicked.connect (start_stop);

var button_lap = new Gtk.Button.with_label ("Lap");
button_lap.clicked.connect (lap);

var button_reset = new Gtk.Button.with_label ("Reset");
button_reset.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
button_reset.clicked.connect (clear);

readout_box.add (readout);
readout_box.add (miliseconds);
controls.pack_start (button_lap);
controls.pack_start (button_reset);
controls.pack_end (button_startstop);
controls.set_homogeneous (true);
this.pack_start (readout_box, false, false, 0);
this.pack_start (laps, true, true, 0);
this.pack_end (controls, false, false, 0);

update ();
clear ();
Timeout.add (10, update);

}

private void start_stop (Gtk.Button btn) {
if (btn.get_label () == "Start") {
if (cleared == true) {
timer.start ();
cleared = false;
} else {
timer.@continue ();
}
btn.label = "Pause";
} else {
timer.stop ();
btn.label = "Start";
}
}

private void clear () {
button_startstop.set_label ("Start");
timer.reset ();
timer.stop ();
laplist.clear ();
cleared = true;
readout.set_label ("0.00");
}

private void lap () {
int h, m, s, ms = 0;
Utils.time_to_hms (timer.elapsed (), out h, out m, out s, out ms);
string elapsed = @"$h:$m:$s.$ms";
laplist.append ( out iter );
laplist.set ( iter, 0, elapsed, 1, elapsed );
}

private bool update () {
int h, m, s, ms = 0;
Utils.time_to_hms (timer.elapsed (), out h, out m, out s, out ms);
if (h != 0)
readout.set_label (@"$h:$m:$s.$ms");
else
readout.set_label ("%i∶%02i".printf (m, s));
miliseconds.set_label (".%02i".printf (ms));
return true;
public class StopWatch : Gtk.Box {
//Global vars
private Gtk.Label readout;
private Gtk.Label miliseconds;
private Gtk.TreeView laps;
private Gtk.Button button_startstop;
private GLib.Timer timer;
private bool cleared;
private Gtk.ListStore laplist;
private Gtk.TreeIter iter;

public StopWatch (Gtk.Orientation orientation, int spacing) {
Object(orientation: orientation, spacing: spacing);

var controls = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
controls.set_border_width (12);

var readout_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 2);
readout_box.set_halign(Gtk.Align.CENTER);

readout = new Gtk.Label("");
readout.get_style_context().add_class("h1");
miliseconds = new Gtk.Label("");
miliseconds.get_style_context().add_class("h2");

timer = new GLib.Timer();

laplist = new Gtk.ListStore (2, typeof (string), typeof (string));

laps = new Gtk.TreeView.with_model ( laplist );
Gtk.CellRendererText cell = new Gtk.CellRendererText ();
laps.insert_column_with_attributes (-1, "Lap", cell, "text", 0);
laps.insert_column_with_attributes (-1, "Time", cell, "text", 0);


button_startstop = new Gtk.Button.with_label ("Start");
button_startstop.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
button_startstop.clicked.connect (start_stop);

var button_lap = new Gtk.Button.with_label ("Lap");
button_lap.clicked.connect (lap);

var button_reset = new Gtk.Button.with_label ("Reset");
button_reset.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
button_reset.clicked.connect (clear);

readout_box.add (readout);
readout_box.add (miliseconds);
controls.pack_start (button_lap);
controls.pack_start (button_reset);
controls.pack_end (button_startstop);
controls.set_homogeneous (true);
this.pack_start (readout_box, false, false, 0);
this.pack_start (laps, true, true, 0);
this.pack_end (controls, false, false, 0);

update ();
clear ();
Timeout.add (10, update);

}

private void start_stop (Gtk.Button btn) {
if (btn.get_label () == "Start") {
if (cleared == true) {
timer.start ();
cleared = false;
} else {
timer.@continue ();
}
btn.label = "Pause";
} else {
timer.stop ();
btn.label = "Start";
}
}

private void clear () {
button_startstop.set_label ("Start");
timer.reset ();
timer.stop ();
laplist.clear ();
cleared = true;
readout.set_label ("0.00");
}

private void lap () {
int h, m, s, ms = 0;
Utils.time_to_hms (timer.elapsed (), out h, out m, out s, out ms);
string elapsed = @"$h:$m:$s.$ms";
laplist.append ( out iter );
laplist.set ( iter, 0, elapsed, 1, elapsed );
}

private bool update () {
int h, m, s, ms = 0;
Utils.time_to_hms (timer.elapsed (), out h, out m, out s, out ms);
if (h != 0)
readout.set_label (@"$h:$m:$s.$ms");
else
readout.set_label ("%i∶%02i".printf (m, s));
miliseconds.set_label (".%02i".printf (ms));
return true;
}
}

@@ -15,23 +15,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace StopClock {
namespace Utils {

public void time_to_hms (double t, out int h, out int m, out int s, out int ms) {
double r;
h = (int) t / 3600;
t %= 3600;
m = (int) t / 60;
t %= 60;
s = (int) t;
r = t - s;
ms = (int) (r * 100);
}
namespace Utils {

public void hms_to_double (int h, int m, int s, out double t) {
t = s + (m * 60) + (h * 3600);
}
public void time_to_hms (double t, out int h, out int m, out int s, out int ms) {
double r;
h = (int) t / 3600;
t %= 3600;
m = (int) t / 60;
t %= 60;
s = (int) t;
r = t - s;
ms = (int) (r * 100);
}

public void hms_to_double (int h, int m, int s, out double t) {
t = s + (m * 60) + (h * 3600);
}

}
}
@@ -18,79 +18,48 @@
using Gtk;
using GLib;

namespace StopClock {
class Window : Gtk.Window {

class Window : Gtk.Window {

public Window () {
this.set_position (Gtk.WindowPosition.CENTER);
this.set_default_size (350, 500);
this.destroy.connect (Gtk.main_quit);
this.get_style_context ().add_class ("rounded");

var view = new Gtk.Stack ();
var stopwatch = new StopWatch(Gtk.Orientation.VERTICAL, 0);
view.add_titled ( stopwatch, "stopwatch", "stopwatch");
view.child_set_property (stopwatch, "icon-name", "stopclock-symbolic");

var eggtimer = new EggTimer(Gtk.Orientation.VERTICAL, 0);
view.add_titled (eggtimer, "eggtimer", "eggtimer");
view.child_set_property (eggtimer, "icon-name", "emblem-important-symbolic");

var alarm = new Alarm(Gtk.Orientation.VERTICAL, 0);
view.add_titled (alarm, "alarm", "alarm");
view.child_set_property (alarm, "icon-name","alarm-symbolic");

var reminder = new Reminder(Gtk.Orientation.VERTICAL, 0);
view.add_titled (reminder, "reminder", "reminder");
view.child_set_property (reminder, "icon-name", "media-playlist-repeat-symbolic");

public Window () {
// window specifics
this.title = "StopClock";
this.set_position (Gtk.WindowPosition.CENTER);
this.set_default_size (350, 500);
this.destroy.connect (Gtk.main_quit);
this.get_style_context ().add_class ("rounded");

var headerbar = new Gtk.HeaderBar();
this.set_titlebar (headerbar);
headerbar.set_show_close_button (true);
//var settings = new Gtk.Button.from_icon_name ("application-menu-symbolic");
//headerbar.pack_end(settings);

var layout = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);

var selector = new Gtk.StackSwitcher ();
selector.icon_size = 16;
selector.halign = Gtk.Align.CENTER;
selector.set_border_width (12);

var view = new Gtk.Stack ();

var stopwatch = new StopWatch.StopWatch(Gtk.Orientation.VERTICAL, 0);
view.add_titled ( stopwatch, "stopwatch", "stopwatch");
view.child_set_property (stopwatch, "icon-name", "stopclock-symbolic");

var eggtimer = new EggTimer.EggTimer(Gtk.Orientation.VERTICAL, 0);
view.add_titled (eggtimer, "eggtimer", "eggtimer");
view.child_set_property (eggtimer, "icon-name", "emblem-important-symbolic");

var alarm = new Alarm.Alarm(Gtk.Orientation.VERTICAL, 0);
view.add_titled (alarm, "alarm", "alarm");
view.child_set_property (alarm, "icon-name","alarm-symbolic");

var reminder = new Reminder.Reminder(Gtk.Orientation.VERTICAL, 0);
view.add_titled (reminder, "reminder", "reminder");
view.child_set_property (reminder, "icon-name", "media-playlist-repeat-symbolic");

var worldclock = new WorldClock.WorldClock(Gtk.Orientation.VERTICAL, 0);
view.add_titled (worldclock, "worldclock", "worldclock");
view.child_set_property (worldclock, "icon-name", "text-html-symbolic");

selector.stack = view;

headerbar.set_custom_title (selector);
layout.pack_end (view, true, true, 0);
add (layout);

show_all();
Gtk.main ();
}
/*
public static int main (string[] args) {
var css_provider = new Gtk.CssProvider();
string css_path = "/usr/local/share/stopclock/stopclock.css";
try {
css_provider.load_from_path (css_path);
} catch (GLib.Error e) {
warning("%s", e.message);
}
StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
}
*/
var worldclock = new WorldClock(Gtk.Orientation.VERTICAL, 0);
view.add_titled (worldclock, "worldclock", "worldclock");
view.child_set_property (worldclock, "icon-name", "text-html-symbolic");

var selector = new Gtk.StackSwitcher ();
selector.stack = view;

var headerbar = new Gtk.HeaderBar();
this.set_titlebar (headerbar);
headerbar.set_show_close_button (true);
headerbar.set_custom_title (selector);

add (view);

show_all();
Gtk.main ();
}
}

@@ -16,13 +16,10 @@
*/

using Gtk;
namespace StopClock {
namespace WorldClock {
public class WorldClock : Gtk.Box {
public WorldClock (Gtk.Orientation orientation, int spacing) {
Object(orientation: orientation, spacing: spacing);
this.add (new Gtk.Label ("World Clocks"));
}
}

public class WorldClock : Gtk.Box {
public WorldClock (Gtk.Orientation orientation, int spacing) {
Object(orientation: orientation, spacing: spacing);
this.add (new Gtk.Label ("Where the fugg am I ??? D:"));
}
}