[gnome-clocks] Split out ContentThumb as a separate interface



commit 4d7a09e6080ab8da804c58547026f4fb5145b9cb
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Apr 29 11:32:15 2017 +0200

    Split out ContentThumb as a separate interface
    
    In preparation for ContentItem also be used with FlowBor or ListBox
    we do not want to make implementing the IconView code mandatory.

 src/alarm.vala   |   40 +++++++++++++++++-----------------------
 src/widgets.vala |    8 +++++---
 src/world.vala   |   32 ++++++++++++++++----------------
 3 files changed, 38 insertions(+), 42 deletions(-)
---
diff --git a/src/alarm.vala b/src/alarm.vala
index b32c817..11a8c55 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -24,7 +24,7 @@ private struct AlarmTime {
     public int minute;
 }
 
-private class Item : Object, ContentItem {
+private class Item : Object, ContentItem, ContentThumb {
     const int SNOOZE_MINUTES = 9;
     const int RING_MINUTES = 3;
 
@@ -59,12 +59,6 @@ private class Item : Object, ContentItem {
 
     public Utils.Weekdays days { get; construct set; }
 
-    public string repeat_label {
-        owned get {
-            return days.get_label ();
-        }
-    }
-
     public State state { get; private set; }
 
     public string time_label {
@@ -231,22 +225,6 @@ private class Item : Object, ContentItem {
         return state != last_state;
     }
 
-    public void get_thumb_properties (out string text,
-                                      out string subtext,
-                                      out Gdk.Pixbuf? pixbuf,
-                                      out string css_class) {
-        if (state == State.SNOOZING) {
-            text = snooze_time_label;
-            subtext = "(%s)".printf(time_label);
-            css_class = "snoozing";
-        } else {
-            text = time_label;
-            subtext = repeat_label;
-            css_class = active ? "active" : "inactive";
-        }
-        pixbuf = null;
-    }
-
     public void serialize (GLib.VariantBuilder builder) {
         builder.open (new GLib.VariantType ("a{sv}"));
         builder.add ("{sv}", "name", new GLib.Variant.string (name));
@@ -289,6 +267,22 @@ private class Item : Object, ContentItem {
         }
         return null;
     }
+
+    public void get_thumb_properties (out string text,
+                                      out string subtext,
+                                      out Gdk.Pixbuf? pixbuf,
+                                      out string css_class) {
+        if (state == State.SNOOZING) {
+            text = snooze_time_label;
+            subtext = "(%s)".printf(time_label);
+            css_class = "snoozing";
+        } else {
+            text = time_label;
+            subtext = days.get_label ();;
+            css_class = active ? "active" : "inactive";
+        }
+        pixbuf = null;
+    }
 }
 
 [GtkTemplate (ui = "/org/gnome/clocks/ui/alarmsetupdialog.ui")]
diff --git a/src/widgets.vala b/src/widgets.vala
index b0065b0..a574885 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -260,12 +260,14 @@ public interface ContentItem : GLib.Object {
     public abstract bool selectable { get; set; default = true; }
     public abstract bool selected { get; set; default = false; }
 
+    public abstract void serialize (GLib.VariantBuilder builder);
+}
+
+public interface ContentThumb : GLib.Object {
     public abstract void get_thumb_properties (out string text,
                                                out string subtext,
                                                out Gdk.Pixbuf? pixbuf,
                                                out string css_class);
-
-    public abstract void serialize (GLib.VariantBuilder builder);
 }
 
 public class ContentStore : GLib.Object, GLib.ListModel {
@@ -456,7 +458,7 @@ private class IconView : Gtk.IconView {
                 string subtext;
                 Gdk.Pixbuf? pixbuf;
                 string css_class;
-                item.get_thumb_properties (out text, out subtext, out pixbuf, out css_class);
+                ((ContentThumb)item).get_thumb_properties (out text, out subtext, out pixbuf, out css_class);
                 renderer.selectable = item.selectable;
                 renderer.toggle_visible = (mode == Mode.SELECTION);
                 renderer.checked = item.selected;
diff --git a/src/world.vala b/src/world.vala
index 791f0f1..71a348e 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -19,7 +19,7 @@
 namespace Clocks {
 namespace World {
 
-public class Item : Object, ContentItem {
+public class Item : Object, ContentItem, ContentThumb {
     private static Gdk.Pixbuf? day_pixbuf = Utils.load_image ("day.png");
     private static Gdk.Pixbuf? night_pixbuf = Utils.load_image ("night.png");
 
@@ -162,21 +162,6 @@ public class Item : Object, ContentItem {
                                                    enabled_providers: GWeather.Provider.NONE);
     }
 
-    public void get_thumb_properties (out string text,
-                                      out string subtext,
-                                      out Gdk.Pixbuf? pixbuf,
-                                      out string css_class) {
-        text = time_label;
-        subtext = day_label;
-        if (is_daytime) {
-            pixbuf = day_pixbuf;
-            css_class = "light";
-        } else {
-            pixbuf = night_pixbuf;
-            css_class = "dark";
-        }
-    }
-
     public void serialize (GLib.VariantBuilder builder) {
         if (!automatic) {
             builder.open (new GLib.VariantType ("a{sv}"));
@@ -198,6 +183,21 @@ public class Item : Object, ContentItem {
         }
         return location != null ? new Item (location) : null;
     }
+
+    public void get_thumb_properties (out string text,
+                                      out string subtext,
+                                      out Gdk.Pixbuf? pixbuf,
+                                      out string css_class) {
+        text = time_label;
+        subtext = day_label;
+        if (is_daytime) {
+            pixbuf = day_pixbuf;
+            css_class = "light";
+        } else {
+            pixbuf = night_pixbuf;
+            css_class = "dark";
+        }
+    }
 }
 
 [GtkTemplate (ui = "/org/gnome/clocks/ui/worldlocationdialog.ui")]


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