[gnome-boxes/polish-snapshot-preferences: 5/6] preferences, snapshot-list-row: Add DateTime to row "subtitle"




commit 1f5234ee9ea21b9e416c185e145273befcdd28e8
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Jan 4 16:20:38 2022 +0100

    preferences, snapshot-list-row: Add DateTime to row "subtitle"
    
    If the snapshot has been renamed, we show the DateTime of its
    creation as a "subtitle" for the SnapshotListRow.

 data/ui/preferences/snapshot-list-row.ui | 37 ++++++++++++++++++++++++++------
 src/preferences/snapshot-list-row.vala   | 17 +++++++++++++--
 2 files changed, 46 insertions(+), 8 deletions(-)
---
diff --git a/data/ui/preferences/snapshot-list-row.ui b/data/ui/preferences/snapshot-list-row.ui
index 7daf18da..0fec01fe 100644
--- a/data/ui/preferences/snapshot-list-row.ui
+++ b/data/ui/preferences/snapshot-list-row.ui
@@ -36,14 +36,39 @@
             <property name="can_focus">False</property>
 
             <child>
-              <object class="GtkLabel" id="name_label">
+              <object class="GtkBox" id="title_box">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="hexpand">True</property>
-                <property name="vexpand">True</property>
-                <property name="halign">start</property>
+                <property name="can-focus">False</property>
+                <property name="orientation">vertical</property>
                 <property name="valign">center</property>
-                <property name="ellipsize">end</property>
+
+                <child>
+                  <object class="GtkLabel" id="name_label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="hexpand">True</property>
+                    <property name="vexpand">True</property>
+                    <property name="halign">start</property>
+                    <property name="valign">center</property>
+                    <property name="ellipsize">end</property>
+                    <property name="xalign">0</property>
+                    <style>
+                      <class name="title"/>
+                    </style>
+                  </object>
+                </child>
+
+                <child>
+                  <object class="GtkLabel" id="description_label">
+                    <property name="can-focus">False</property>
+                    <property name="hexpand">True</property>
+                    <property name="halign">start</property>
+                    <property name="xalign">0</property>
+                    <style>
+                      <class name="subtitle"/>
+                    </style>
+                  </object>
+                </child>
               </object>
             </child>
 
diff --git a/src/preferences/snapshot-list-row.vala b/src/preferences/snapshot-list-row.vala
index a9574608..639603df 100644
--- a/src/preferences/snapshot-list-row.vala
+++ b/src/preferences/snapshot-list-row.vala
@@ -11,6 +11,8 @@
     [GtkChild]
     private unowned Gtk.Label name_label;
     [GtkChild]
+    private unowned Gtk.Label description_label;
+    [GtkChild]
     private unowned Gtk.Stack mode_stack;
     [GtkChild]
     private unowned Gtk.Entry name_entry;
@@ -45,7 +47,7 @@ public SnapshotListRow (GVir.DomainSnapshot snapshot,
         this.machine = machine;
 
         try {
-            name_label.label = snapshot.get_config (0).get_description ();
+            setup_labels (snapshot.get_config (0));
         } catch (GLib.Error e) {
             critical (e.message);
         }
@@ -55,6 +57,17 @@ public SnapshotListRow (GVir.DomainSnapshot snapshot,
         this.insert_action_group ("snap", action_group);
     }
 
+    private void setup_labels (GVirConfig.DomainSnapshot config, string? name = null) {
+        name_label.label = (name == null) ? config.get_description () : name;
+
+        var date = new DateTime.from_unix_local (config.get_creation_time ());
+        var date_string = date.format ("%x, %X");
+        if (date_string != config.get_description ()) {
+            description_label.visible = true;
+            description_label.label = date_string;
+        }
+    }
+
     [GtkCallback]
     private void on_save_name_button_clicked () {
         var name = name_entry.text;
@@ -63,7 +76,7 @@ private void on_save_name_button_clicked () {
             var config = snapshot.get_config (0);
             config.set_description (name);
             snapshot.set_config (config);
-            name_label.label = name;
+            setup_labels (config, name);
             mode_stack.visible_child = show_name_box;
         } catch (GLib.Error e) {
             warning ("Failed to change name of snapshot to %s: %s", name, e.message);


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