[gnome-boxes/wip/less-dialogs2: 3/14] properties: Refactor PageWidget into its own class/module
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/less-dialogs2: 3/14] properties: Refactor PageWidget into its own class/module
- Date: Thu, 4 Dec 2014 23:26:29 +0000 (UTC)
commit 6b2e1875e3734a799b07f3e816801af99482895e
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Nov 27 15:25:57 2014 +0000
properties: Refactor PageWidget into its own class/module
Lets avoid confusing (to code readers) nested classes and move PageWidget
out of Properties class into its own module with a new name,
PropertiesPageWidget.
src/Makefile.am | 1 +
src/properties-page-widget.vala | 95 +++++++++++++++++++++++++++++++++++++
src/properties.vala | 99 +-------------------------------------
3 files changed, 99 insertions(+), 96 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4c20224..6ddb52f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -124,6 +124,7 @@ gnome_boxes_SOURCES = \
os-database.vala \
properties.vala \
properties-window.vala \
+ properties-page-widget.vala \
properties-toolbar.vala \
remote-machine.vala \
searchbar.vala \
diff --git a/src/properties-page-widget.vala b/src/properties-page-widget.vala
new file mode 100644
index 0000000..a77c4e3
--- /dev/null
+++ b/src/properties-page-widget.vala
@@ -0,0 +1,95 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+
+private class Boxes.ProperitesPageWidget: Gtk.Box {
+ public bool empty;
+
+ private Gtk.Grid grid;
+ private List<Boxes.Property> properties;
+
+ public signal void refresh_properties ();
+
+ public ProperitesPageWidget (PropertiesPage page, Machine machine) {
+ switch (page) {
+ case PropertiesPage.GENERAL:
+ name = _("General");
+ break;
+
+ case PropertiesPage.SYSTEM:
+ name = _("System");
+ break;
+
+ case PropertiesPage.DEVICES:
+ name = _("Devices");
+ break;
+
+ case PropertiesPage.SNAPSHOTS:
+ name = _("Snapshots");
+ break;
+ }
+
+ get_style_context ().add_class ("content-bg");
+ get_style_context ().add_class ("transparent-bg");
+
+ grid = new Gtk.Grid ();
+ grid.margin = 20;
+ grid.row_spacing = 10;
+ grid.column_spacing = 20;
+ grid.valign = Gtk.Align.START;
+ var scrolled_win = new Gtk.ScrolledWindow (null, null);
+ scrolled_win.min_content_height = 480;
+ scrolled_win.margin_start = 20;
+ scrolled_win.margin_end = 20;
+ scrolled_win.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
+ scrolled_win.add (grid);
+ pack_end (scrolled_win, true, true);
+
+ PropertyCreationFlag flags = PropertyCreationFlag.NONE;
+ properties = machine.get_properties (page, ref flags);
+ empty = properties.length () == 0;
+ if (!empty) {
+ int current_row = 1;
+ foreach (var property in properties) {
+ if (property.description != null) {
+ var label_name = new Gtk.Label (property.description);
+ label_name.get_style_context ().add_class ("boxes-property-name-label");
+ label_name.halign = Gtk.Align.START;
+ label_name.hexpand = false;
+ grid.attach (label_name, 0, current_row, 1, 1);
+ var widget = property.widget;
+ widget.hexpand = true;
+ grid.attach (widget, 1, current_row, 1, 1);
+ } else {
+ var widget = property.widget;
+ widget.hexpand = true;
+ grid.attach (widget, 0, current_row, 2, 1);
+ }
+
+ var widget = property.extra_widget;
+ if (widget != null) {
+ current_row += 1;
+ widget.hexpand = true;
+ grid.attach (widget, 0, current_row, 2, 1);
+ }
+
+ property.refresh_properties.connect (() => {
+ this.refresh_properties ();
+ });
+ current_row += 1;
+ }
+ }
+
+ show_all ();
+ }
+
+ public bool flush_changes () {
+ var reboot_required = false;
+
+ foreach (var property in properties) {
+ property.flush ();
+ reboot_required |= property.reboot_required;
+ }
+
+ return reboot_required;
+ }
+}
diff --git a/src/properties.vala b/src/properties.vala
index 51fc62a..6511de4 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -19,99 +19,6 @@ private class Boxes.Properties: Gtk.Notebook, Boxes.UI {
private ulong stats_id;
private bool restore_fullscreen;
- private class PageWidget: Gtk.Box {
- public bool empty;
-
- private Gtk.Grid grid;
- private List<Boxes.Property> properties;
-
- public signal void refresh_properties ();
-
- public PageWidget (PropertiesPage page, Machine machine) {
- switch (page) {
- case PropertiesPage.GENERAL:
- name = _("General");
- break;
-
- case PropertiesPage.SYSTEM:
- name = _("System");
- break;
-
- case PropertiesPage.DEVICES:
- name = _("Devices");
- break;
-
- case PropertiesPage.SNAPSHOTS:
- name = _("Snapshots");
- break;
- }
-
- get_style_context ().add_class ("content-bg");
- get_style_context ().add_class ("transparent-bg");
-
- grid = new Gtk.Grid ();
- grid.margin = 20;
- grid.row_spacing = 10;
- grid.column_spacing = 20;
- grid.valign = Gtk.Align.START;
- var scrolled_win = new Gtk.ScrolledWindow (null, null);
- scrolled_win.min_content_height = 480;
- scrolled_win.margin_start = 20;
- scrolled_win.margin_end = 20;
- scrolled_win.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
- scrolled_win.add (grid);
- pack_end (scrolled_win, true, true);
-
- PropertyCreationFlag flags = PropertyCreationFlag.NONE;
- properties = machine.get_properties (page, ref flags);
- empty = properties.length () == 0;
- if (!empty) {
- int current_row = 1;
- foreach (var property in properties) {
- if (property.description != null) {
- var label_name = new Gtk.Label (property.description);
- label_name.get_style_context ().add_class ("boxes-property-name-label");
- label_name.halign = Gtk.Align.START;
- label_name.hexpand = false;
- grid.attach (label_name, 0, current_row, 1, 1);
- var widget = property.widget;
- widget.hexpand = true;
- grid.attach (widget, 1, current_row, 1, 1);
- } else {
- var widget = property.widget;
- widget.hexpand = true;
- grid.attach (widget, 0, current_row, 2, 1);
- }
-
- var widget = property.extra_widget;
- if (widget != null) {
- current_row += 1;
- widget.hexpand = true;
- grid.attach (widget, 0, current_row, 2, 1);
- }
-
- property.refresh_properties.connect (() => {
- this.refresh_properties ();
- });
- current_row += 1;
- }
- }
-
- show_all ();
- }
-
- public bool flush_changes () {
- var reboot_required = false;
-
- foreach (var property in properties) {
- property.flush ();
- reboot_required |= property.reboot_required;
- }
-
- return reboot_required;
- }
- }
-
construct {
notify["ui-state"].connect (ui_state_changed);
}
@@ -127,10 +34,10 @@ private class Boxes.Properties: Gtk.Notebook, Boxes.UI {
return;
for (var i = 0; i < PropertiesPage.LAST; i++) {
- var page = new PageWidget (i, machine);
+ var page = new ProperitesPageWidget (i, machine);
var label = new Gtk.Label (page.name);
insert_page (page, label, i);
- set_data<PageWidget> (@"boxes-property-$i", page);
+ set_data<ProperitesPageWidget> (@"boxes-property-$i", page);
page.refresh_properties.connect (() => {
var current_page = this.page;
@@ -166,7 +73,7 @@ private class Boxes.Properties: Gtk.Notebook, Boxes.UI {
var reboot_required = false;
for (var i = 0; i < PropertiesPage.LAST; i++) {
- var page = get_data<PageWidget> (@"boxes-property-$i");
+ var page = get_data<ProperitesPageWidget> (@"boxes-property-$i");
reboot_required |= page.flush_changes ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]