[gnome-clocks/wip/exalm/split: 4/8] stopwatch: Split into multiple files



commit 57e1eebe972eaa1f514b0cba3a9674cef7c24798
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sat May 23 03:57:10 2020 +0500

    stopwatch: Split into multiple files
    
    Also fix ui file names.

 data/gnome-clocks.gresource.xml                    |  4 +-
 data/ui/{stopwatch.ui => stopwatch-face.ui}        |  0
 .../{stopwatchlapsrow.ui => stopwatch-laps-row.ui} |  0
 src/meson.build                                    |  4 +-
 src/{stopwatch.vala => stopwatch-face.vala}        | 81 +------------------
 src/stopwatch-lap.vala                             | 34 ++++++++
 src/stopwatch-laps-row.vala                        | 92 ++++++++++++++++++++++
 7 files changed, 132 insertions(+), 83 deletions(-)
---
diff --git a/data/gnome-clocks.gresource.xml b/data/gnome-clocks.gresource.xml
index 89ad9c4..aff772b 100644
--- a/data/gnome-clocks.gresource.xml
+++ b/data/gnome-clocks.gresource.xml
@@ -15,8 +15,8 @@
     <file preprocess="xml-stripblanks">ui/alarm-ringing-panel.ui</file>
     <file preprocess="xml-stripblanks">ui/alarm-row.ui</file>
     <file preprocess="xml-stripblanks">ui/alarm-setup-dialog.ui</file>
-    <file preprocess="xml-stripblanks">ui/stopwatch.ui</file>
-    <file preprocess="xml-stripblanks">ui/stopwatchlapsrow.ui</file>
+    <file preprocess="xml-stripblanks">ui/stopwatch-face.ui</file>
+    <file preprocess="xml-stripblanks">ui/stopwatch-laps-row.ui</file>
     <file preprocess="xml-stripblanks">ui/timer.ui</file>
     <file preprocess="xml-stripblanks">ui/timer_row.ui</file>
     <file preprocess="xml-stripblanks">ui/timer_setup.ui</file>
diff --git a/data/ui/stopwatch.ui b/data/ui/stopwatch-face.ui
similarity index 100%
rename from data/ui/stopwatch.ui
rename to data/ui/stopwatch-face.ui
diff --git a/data/ui/stopwatchlapsrow.ui b/data/ui/stopwatch-laps-row.ui
similarity index 100%
rename from data/ui/stopwatchlapsrow.ui
rename to data/ui/stopwatch-laps-row.ui
diff --git a/src/meson.build b/src/meson.build
index 8dd7a87..2079382 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -15,7 +15,9 @@ clocks_vala_sources = [
   'headerbar.vala',
   'main.vala',
   'search-provider.vala',
-  'stopwatch.vala',
+  'stopwatch-face.vala',
+  'stopwatch-lap.vala',
+  'stopwatch-laps-row.vala',
   'timer.vala',
   'utils.vala',
   'widgets.vala',
diff --git a/src/stopwatch.vala b/src/stopwatch-face.vala
similarity index 76%
rename from src/stopwatch.vala
rename to src/stopwatch-face.vala
index d8196b2..a98799e 100644
--- a/src/stopwatch.vala
+++ b/src/stopwatch-face.vala
@@ -20,86 +20,7 @@
 namespace Clocks {
 namespace Stopwatch {
 
-private string render_duration (double duration) {
-    int h;
-    int m;
-    int s;
-    double r;
-    Utils.time_to_hms (Math.floor (duration * 100) / 100, out h, out m, out s, out r);
-    int cs = (int) (r * 10);
-    return "%02i\u200E ∶ %02i\u200E ∶ %02i. %i".printf (h.abs (), m.abs (), s.abs (), cs.abs ());
-}
-
-public class Lap : GLib.Object {
-    public int index; // Starts at #1
-    public double duration;
-
-    public Lap (int index, double duration) {
-        this.index = index;
-        this.duration = duration;
-    }
-}
-
-
-[GtkTemplate (ui = "/org/gnome/clocks/ui/stopwatchlapsrow.ui")]
-private class LapsRow : Gtk.ListBoxRow {
-    [GtkChild]
-    private Gtk.Label index_label;
-    [GtkChild]
-    private Gtk.Label difference_label;
-    [GtkChild]
-    private Gtk.Label duration_label;
-
-    private Lap current;
-    private Lap? before;
-
-    public LapsRow (Lap current, Lap? before) {
-        this.current = current;
-        this.before = before;
-        index_label.label = _("Lap %i").printf (this.current.index);
-        duration_label.label = this.get_duration_label ();
-
-        if (this.before != null) {
-            // So get_delta_label() can be null, but Vala doesn't
-            // know that .label can be as well
-            difference_label.label = (string) this.get_delta_label ();
-
-            var difference = this.get_delta_duration ();
-            if (difference > 0) {
-                difference_label.get_style_context ().add_class ("negative-lap");
-            } else if (difference < 0) {
-                difference_label.get_style_context ().add_class ("positive-lap");
-            }
-        }
-    }
-
-    private string get_duration_label () {
-        return render_duration (this.current.duration);
-    }
-
-    private double get_delta_duration () {
-        if (this.before != null) {
-            return this.current.duration - ((Lap) this.before).duration;
-        }
-        return 0;
-    }
-
-    private string? get_delta_label () {
-        if (this.before != null) {
-            var difference = this.current.duration - ((Lap) this.before).duration;
-            var delta_label = render_duration (difference);
-            string sign = "+";
-            if (difference < 0) {
-                sign = "-";
-            }
-
-            return "%s %s".printf (sign, delta_label);
-        }
-        return null;
-    }
-}
-
-[GtkTemplate (ui = "/org/gnome/clocks/ui/stopwatch.ui")]
+[GtkTemplate (ui = "/org/gnome/clocks/ui/stopwatch-face.ui")]
 public class Face : Gtk.Box, Clocks.Clock {
     public enum State {
         RESET,
diff --git a/src/stopwatch-lap.vala b/src/stopwatch-lap.vala
new file mode 100644
index 0000000..6415cea
--- /dev/null
+++ b/src/stopwatch-lap.vala
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2013  Paolo Borelli <pborelli gnome org>
+ * Copyright (C) 2020  Bilal Elmoussaoui <bil elmoussaoui gnome org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+namespace Clocks {
+namespace Stopwatch {
+
+public class Lap : GLib.Object {
+    public int index; // Starts at #1
+    public double duration;
+
+    public Lap (int index, double duration) {
+        this.index = index;
+        this.duration = duration;
+    }
+}
+
+} // namespace Stopwatch
+} // namespace Clocks
diff --git a/src/stopwatch-laps-row.vala b/src/stopwatch-laps-row.vala
new file mode 100644
index 0000000..60f6d43
--- /dev/null
+++ b/src/stopwatch-laps-row.vala
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2013  Paolo Borelli <pborelli gnome org>
+ * Copyright (C) 2020  Bilal Elmoussaoui <bil elmoussaoui gnome org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+namespace Clocks {
+namespace Stopwatch {
+
+private string render_duration (double duration) {
+    int h;
+    int m;
+    int s;
+    double r;
+    Utils.time_to_hms (Math.floor (duration * 100) / 100, out h, out m, out s, out r);
+    int cs = (int) (r * 10);
+    return "%02i\u200E ∶ %02i\u200E ∶ %02i. %i".printf (h.abs (), m.abs (), s.abs (), cs.abs ());
+}
+
+[GtkTemplate (ui = "/org/gnome/clocks/ui/stopwatch-laps-row.ui")]
+private class LapsRow : Gtk.ListBoxRow {
+    [GtkChild]
+    private Gtk.Label index_label;
+    [GtkChild]
+    private Gtk.Label difference_label;
+    [GtkChild]
+    private Gtk.Label duration_label;
+
+    private Lap current;
+    private Lap? before;
+
+    public LapsRow (Lap current, Lap? before) {
+        this.current = current;
+        this.before = before;
+        index_label.label = _("Lap %i").printf (this.current.index);
+        duration_label.label = this.get_duration_label ();
+
+        if (this.before != null) {
+            // So get_delta_label() can be null, but Vala doesn't
+            // know that .label can be as well
+            difference_label.label = (string) this.get_delta_label ();
+
+            var difference = this.get_delta_duration ();
+            if (difference > 0) {
+                difference_label.get_style_context ().add_class ("negative-lap");
+            } else if (difference < 0) {
+                difference_label.get_style_context ().add_class ("positive-lap");
+            }
+        }
+    }
+
+    private string get_duration_label () {
+        return render_duration (this.current.duration);
+    }
+
+    private double get_delta_duration () {
+        if (this.before != null) {
+            return this.current.duration - ((Lap) this.before).duration;
+        }
+        return 0;
+    }
+
+    private string? get_delta_label () {
+        if (this.before != null) {
+            var difference = this.current.duration - ((Lap) this.before).duration;
+            var delta_label = render_duration (difference);
+            string sign = "+";
+            if (difference < 0) {
+                sign = "-";
+            }
+
+            return "%s %s".printf (sign, delta_label);
+        }
+        return null;
+    }
+}
+
+} // namespace Stopwatch
+} // namespace Clocks


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]