[gnome-boxes/wip/props-ui-files: 32/37] props-page-widget: Add add_size_property()
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/props-ui-files: 32/37] props-page-widget: Add add_size_property()
- Date: Wed, 13 Jul 2016 13:30:02 +0000 (UTC)
commit 08e8b015ab14ed0965a18793b7ddc483dc94bca1
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Wed Jun 1 21:13:24 2016 +0100
props-page-widget: Add add_size_property()
Add a method that adds a size (RAM and storage) property. Like the
previous patch, this ignores the Property hierarchy intentionally to allow
for smooth transition from Property hierarchy to (yet to be created)
PropertyPageWidget hierarchy
src/properties-page-widget.vala | 77 +++++++++++++++++++++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/src/properties-page-widget.vala b/src/properties-page-widget.vala
index 2d60b3d..e664448 100644
--- a/src/properties-page-widget.vala
+++ b/src/properties-page-widget.vala
@@ -11,8 +11,26 @@ private class Boxes.PropertiesPageWidget: Gtk.Box {
public signal void refresh_properties ();
+ public delegate void SizePropertyChanged (uint64 value);
+
private int num_rows = 0;
+ private static void set_size_value_label_msg (Gtk.Label label,
+ uint64 size,
+ uint64 allocation,
+ FormatSizeFlags format_flags) {
+ var capacity = format_size (size, format_flags);
+
+ if (allocation == 0) {
+ label.set_text (capacity);
+ } else {
+ var allocation_str = format_size (allocation, format_flags);
+
+ // Translators: This is memory or disk size. E.g. "2 GB (1 GB used)".
+ label.set_markup (_("%s <span color=\"grey\">(%s used)</span>").printf (capacity,
allocation_str));
+ }
+ }
+
public PropertiesPageWidget (PropertiesPage page, Machine machine) {
deferred_changes = new List<DeferredChange> ();
@@ -126,4 +144,63 @@ private class Boxes.PropertiesPageWidget: Gtk.Box {
num_rows++;
}
}
+
+ public void add_size_property (string name,
+ uint64 size,
+ uint64 min,
+ uint64 max,
+ uint64 allocation,
+ uint64 step,
+ SizePropertyChanged changed,
+ uint64 recommended = -1,
+ FormatSizeFlags format_flags = FormatSizeFlags.DEFAULT) {
+ var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
+ var name_label = new Gtk.Label.with_mnemonic (name);
+ name_label.halign = Gtk.Align.START;
+ name_label.get_style_context ().add_class ("dim-label");
+ box.add (name_label);
+ var value_label = new Gtk.Label ("");
+ set_size_value_label_msg (value_label, size, allocation, format_flags);
+ value_label.halign = Gtk.Align.START;
+ box.add (value_label);
+
+ var scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, min, max, step);
+ name_label.mnemonic_widget = scale;
+
+ var size_str = format_size (min, format_flags);
+ size_str = "<small>" + size_str + "</small>";
+ scale.add_mark (min, Gtk.PositionType.BOTTOM, size_str);
+
+ // Translators: This is memory or disk size. E.g. "1 GB (maximum)".
+ size_str = "<small>" + _("%s (maximum)").printf (format_size (max, format_flags)) + "</small>";
+ scale.add_mark (max, Gtk.PositionType.BOTTOM, size_str);
+
+ scale.set_show_fill_level (true);
+ scale.set_restrict_to_fill_level (false);
+ scale.set_value (size);
+ scale.set_fill_level (size);
+ scale.set_draw_value (false);
+ scale.hexpand = true;
+ scale.margin_bottom = 20;
+
+ add_property (null, box, scale);
+
+ if (recommended > 0 &&
+ // FIXME: Better way to ensure recommended mark is not too close to min and max marks?
+ recommended >= (scale.adjustment.lower + Osinfo.GIBIBYTES) &&
+ recommended <= (scale.adjustment.upper - Osinfo.GIBIBYTES)) {
+
+ // Translators: This is memory or disk size. E.g. "1 GB (recommended)".
+ var str = "<small>" + _("%s (recommended)").printf (format_size (recommended, format_flags)) +
"</small>";
+ scale.add_mark (recommended, Gtk.PositionType.BOTTOM, str);
+ }
+
+ scale.value_changed.connect (() => {
+ uint64 v = (uint64) scale.get_value ();
+ set_size_value_label_msg (value_label, v, allocation, format_flags);
+ scale.set_fill_level (v);
+
+ changed ((uint64) scale.get_value ());
+ });
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]