[gnome-boxes] sidebar: Split-out properties code into its own module
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] sidebar: Split-out properties code into its own module
- Date: Tue, 12 Aug 2014 17:40:34 +0000 (UTC)
commit 63ab4a48b8dbd859b04c1ca78872049fe8aa9908
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Aug 12 18:32:34 2014 +0100
sidebar: Split-out properties code into its own module
Lets have separate class/module for properties sidebar.
data/gnome-boxes.gresource.xml | 1 +
data/ui/properties-sidebar.ui | 206 ++++++++++++++++++++++++++++++++++++++++
data/ui/sidebar.ui | 201 +--------------------------------------
src/Makefile.am | 1 +
src/machine.vala | 4 +-
src/properties-sidebar.vala | 48 +++++++++
src/properties.vala | 17 ++--
src/sidebar.vala | 36 +-------
8 files changed, 271 insertions(+), 243 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 6c53ff6..2d67f92 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -15,6 +15,7 @@
<file preprocess="xml-stripblanks">ui/editable-entry.ui</file>
<file preprocess="xml-stripblanks">ui/mini-graph.ui</file>
<file preprocess="xml-stripblanks">ui/notification.ui</file>
+ <file preprocess="xml-stripblanks">ui/properties-sidebar.ui</file>
<file preprocess="xml-stripblanks">ui/properties-toolbar.ui</file>
<file preprocess="xml-stripblanks">ui/searchbar.ui</file>
<file preprocess="xml-stripblanks">ui/selectionbar.ui</file>
diff --git a/data/ui/properties-sidebar.ui b/data/ui/properties-sidebar.ui
new file mode 100644
index 0000000..92c38aa
--- /dev/null
+++ b/data/ui/properties-sidebar.ui
@@ -0,0 +1,206 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.9 -->
+
+ <template class="BoxesPropertiesSidebar" parent="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">10</property>
+
+ <child>
+ <object class="GtkTreeView" id="tree_view">
+ <property name="visible">True</property>
+ <property name="headers-visible">False</property>
+ <property name="activate-on-single-click">True</property>
+ <property name="model">model_filter</property>
+ <signal name="row_activated" handler="on_row_activated"/>
+ <style>
+ <class name="boxes-bg"/>
+ </style>
+
+ <child>
+ <object class="GtkTreeViewColumn" id="text-column">
+ <property name="title"></property>
+ <child>
+ <object class="GtkCellRendererText" id="text-renderer">
+ <property name="visible">True</property>
+ <property name="xpad">20</property>
+ <property name="weight">700</property>
+ </object>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+
+ <child internal-child="selection">
+ <object class="GtkTreeSelection" id="selection">
+ <property name="mode">browse</property>
+ </object>
+ </child>
+ </object>
+
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="padding">0</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkGrid" id="grid">
+ <property name="visible">True</property>
+ <property name="column-homogeneous">False</property>
+ <property name="column-spacing">2</property>
+ <property name="row-spacing">10</property>
+ <property name="margin-start">10</property>
+ <property name="margin-end">10</property>
+ <property name="margin-top">10</property>
+ <property name="margin-bottom">30</property>
+
+ <child>
+ <object class="GtkImage" id="screenshot">
+ <property name="visible">True</property>
+ <property name="width-request">180</property>
+ <property name="height-request">134</property>
+ </object>
+
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ <property name="width">6</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkLabel" id="cpu_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">CPU:</property>
+ <style>
+ <class name="boxes-graph-label"/>
+ </style>
+ </object>
+
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="BoxesMiniGraph" id="cpu_graph">
+ <property name="visible">True</property>
+ <property name="ymax">100</property>
+ <property name="npoints">20</property>
+ </object>
+
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkLabel" id="io_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">I/O:</property>
+ <style>
+ <class name="boxes-graph-label"/>
+ </style>
+ </object>
+
+ <packing>
+ <property name="left-attach">2</property>
+ <property name="top-attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="BoxesMiniGraph" id="io_graph">
+ <property name="visible">True</property>
+ <property name="ymax">20</property>
+ </object>
+
+ <packing>
+ <property name="left-attach">3</property>
+ <property name="top-attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkLabel" id="net_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Net:</property>
+ <style>
+ <class name="boxes-graph-label"/>
+ </style>
+ </object>
+
+ <packing>
+ <property name="left-attach">4</property>
+ <property name="top-attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="BoxesMiniGraph" id="net_graph">
+ <property name="visible">True</property>
+ <property name="ymax">20</property>
+ </object>
+
+ <packing>
+ <property name="left-attach">5</property>
+ <property name="top-attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkButton" id="shutdown_button">
+ <property name="visible">True</property>
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">Force Shutdown</property>
+ <signal name="clicked" handler="on_shutdown_button_clicked"/>
+ </object>
+
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">2</property>
+ <property name="width">6</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">0</property>
+ </packing>
+ </child>
+ </template>
+
+ <object class="GtkListStore" id="listmodel">
+ <columns>
+ <column type="gchararray"/>
+ <column type="gboolean"/>
+ </columns>
+ </object>
+
+ <object class="GtkTreeModelFilter" id="model_filter">
+ <property name="child-model">listmodel</property>
+ </object>
+</interface>
diff --git a/data/ui/sidebar.ui b/data/ui/sidebar.ui
index d00cb6f..d35e6e1 100644
--- a/data/ui/sidebar.ui
+++ b/data/ui/sidebar.ui
@@ -32,209 +32,12 @@
<!-- Properties -->
<child>
- <object class="GtkBox" id="props_vbox">
+ <object class="BoxesPropertiesSidebar" id="props_sidebar">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">10</property>
-
- <child>
- <object class="GtkTreeView" id="props_tree_view">
- <property name="visible">True</property>
- <property name="headers-visible">False</property>
- <property name="activate-on-single-click">True</property>
- <property name="model">props_model_filter</property>
- <signal name="row_activated" handler="on_props_row_activated"/>
- <style>
- <class name="boxes-bg"/>
- </style>
-
- <child>
- <object class="GtkTreeViewColumn" id="text-column">
- <property name="title"></property>
- <child>
- <object class="GtkCellRendererText" id="text-renderer">
- <property name="visible">True</property>
- <property name="xpad">20</property>
- <property name="weight">700</property>
- </object>
- <attributes>
- <attribute name="text">0</attribute>
- </attributes>
- </child>
- </object>
- </child>
-
- <child internal-child="selection">
- <object class="GtkTreeSelection" id="props_selection">
- <property name="mode">browse</property>
- </object>
- </child>
- </object>
-
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="padding">0</property>
- </packing>
- </child>
-
- <child>
- <object class="GtkGrid" id="props_grid">
- <property name="visible">True</property>
- <property name="column-homogeneous">False</property>
- <property name="column-spacing">2</property>
- <property name="row-spacing">10</property>
- <property name="margin-start">10</property>
- <property name="margin-end">10</property>
- <property name="margin-top">10</property>
- <property name="margin-bottom">30</property>
-
- <child>
- <object class="GtkImage" id="screenshot">
- <property name="visible">True</property>
- <property name="width-request">180</property>
- <property name="height-request">134</property>
- </object>
-
- <packing>
- <property name="left-attach">0</property>
- <property name="top-attach">0</property>
- <property name="width">6</property>
- <property name="height">1</property>
- </packing>
- </child>
-
- <child>
- <object class="GtkLabel" id="cpu_label">
- <property name="visible">True</property>
- <property name="label" translatable="yes">CPU:</property>
- <style>
- <class name="boxes-graph-label"/>
- </style>
- </object>
-
- <packing>
- <property name="left-attach">0</property>
- <property name="top-attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
-
- <child>
- <object class="BoxesMiniGraph" id="cpu_graph">
- <property name="visible">True</property>
- <property name="ymax">100</property>
- <property name="npoints">20</property>
- </object>
-
- <packing>
- <property name="left-attach">1</property>
- <property name="top-attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
-
- <child>
- <object class="GtkLabel" id="io_label">
- <property name="visible">True</property>
- <property name="label" translatable="yes">I/O:</property>
- <style>
- <class name="boxes-graph-label"/>
- </style>
- </object>
-
- <packing>
- <property name="left-attach">2</property>
- <property name="top-attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
-
- <child>
- <object class="BoxesMiniGraph" id="io_graph">
- <property name="visible">True</property>
- <property name="ymax">20</property>
- </object>
-
- <packing>
- <property name="left-attach">3</property>
- <property name="top-attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
-
- <child>
- <object class="GtkLabel" id="net_label">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Net:</property>
- <style>
- <class name="boxes-graph-label"/>
- </style>
- </object>
-
- <packing>
- <property name="left-attach">4</property>
- <property name="top-attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
-
- <child>
- <object class="BoxesMiniGraph" id="net_graph">
- <property name="visible">True</property>
- <property name="ymax">20</property>
- </object>
-
- <packing>
- <property name="left-attach">5</property>
- <property name="top-attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
-
- <child>
- <object class="GtkButton" id="shutdown_button">
- <property name="visible">True</property>
- <property name="use-underline">True</property>
- <property name="label" translatable="yes">Force Shutdown</property>
- <signal name="clicked" handler="on_shutdown_button_clicked"/>
- </object>
-
- <packing>
- <property name="left-attach">0</property>
- <property name="top-attach">2</property>
- <property name="width">6</property>
- <property name="height">1</property>
- </packing>
- </child>
- </object>
-
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="padding">0</property>
- </packing>
- </child>
</object>
</child>
+
</object>
</child>
</template>
-
- <object class="GtkListStore" id="props_listmodel">
- <columns>
- <column type="gchararray"/>
- <column type="gboolean"/>
- </columns>
- </object>
-
- <object class="GtkTreeModelFilter" id="props_model_filter">
- <property name="child-model">props_listmodel</property>
- </object>
</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 15eef87..e43d96b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -122,6 +122,7 @@ gnome_boxes_SOURCES = \
notificationbar.vala \
os-database.vala \
properties.vala \
+ properties-sidebar.vala \
properties-toolbar.vala \
remote-machine.vala \
searchbar.vala \
diff --git a/src/machine.vala b/src/machine.vala
index ceb6cf2..549bf05 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -377,7 +377,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
orig_pixbuf = small_screenshot;
pixbuf = draw_vm (small_screenshot, SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT);
if (window.current_item == this)
- window.sidebar.screenshot.set_from_pixbuf (pixbuf);
+ window.sidebar.props_sidebar.screenshot.set_from_pixbuf (pixbuf);
if (save)
save_pixbuf_as_screenshot (small_screenshot);
@@ -538,7 +538,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
} else {
pixbuf = this.pixbuf;
}
- window.sidebar.screenshot.set_from_pixbuf (pixbuf);
+ window.sidebar.props_sidebar.screenshot.set_from_pixbuf (pixbuf);
break;
}
diff --git a/src/properties-sidebar.vala b/src/properties-sidebar.vala
new file mode 100644
index 0000000..b98da6f
--- /dev/null
+++ b/src/properties-sidebar.vala
@@ -0,0 +1,48 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+using Gdk;
+
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/properties-sidebar.ui")]
+private class Boxes.PropertiesSidebar: Gtk.Box {
+ [GtkChild]
+ public Gtk.Image screenshot;
+ [GtkChild]
+ public Gtk.ListStore listmodel;
+ [GtkChild]
+ private Gtk.TreeModelFilter model_filter;
+ [GtkChild]
+ public Gtk.TreeSelection selection;
+ [GtkChild]
+ public Gtk.Button shutdown_button;
+ [GtkChild]
+ public MiniGraph cpu_graph;
+ [GtkChild]
+ public MiniGraph io_graph;
+ [GtkChild]
+ public MiniGraph net_graph;
+
+ private AppWindow window;
+
+ construct {
+ model_filter.set_visible_column (1);
+ }
+
+ public void setup_ui (AppWindow window) {
+ this.window = window;
+ }
+
+ [GtkCallback]
+ private void on_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn column) {
+ Gtk.TreeIter filter_iter, iter;
+ model_filter.get_iter (out filter_iter, path);
+ model_filter.convert_iter_to_child_iter (out iter, filter_iter);
+ window.properties.page = (PropertiesPage) listmodel.get_path (iter).get_indices ()[0];
+ }
+
+ [GtkCallback]
+ private void on_shutdown_button_clicked () {
+ var machine = window.current_item as LibvirtMachine;
+ if (machine != null)
+ machine.force_shutdown ();
+ }
+}
diff --git a/src/properties.vala b/src/properties.vala
index 08bef40..d281ab9 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -134,14 +134,15 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
}
private void populate () {
- window.sidebar.props_listmodel.clear ();
+ window.sidebar.props_sidebar.listmodel.clear ();
foreach (var page in get_children ())
remove (page);
var machine = window.current_item as Machine;
var libvirt_machine = window.current_item as LibvirtMachine;
- window.sidebar.shutdown_button.sensitive = libvirt_machine != null && libvirt_machine.is_running ();
+ window.sidebar.props_sidebar.shutdown_button.sensitive = libvirt_machine != null &&
+ libvirt_machine.is_running ();
if (machine == null)
return;
@@ -155,11 +156,11 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
var current_page = page;
this.populate ();
var path = new Gtk.TreePath.from_indices (current_page);
- window.sidebar.props_selection.select_path (path);
+ window.sidebar.props_sidebar.selection.select_path (path);
page = current_page;
});
- list_append (window.sidebar.props_listmodel, page.name, !page.empty);
+ list_append (window.sidebar.props_sidebar.listmodel, page.name, !page.empty);
}
PropertiesPage current_page;
@@ -170,7 +171,7 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
current_page = PropertiesPage.LOGIN;
var path = new Gtk.TreePath.from_indices (current_page);
- window.sidebar.props_selection.select_path (path);
+ window.sidebar.props_sidebar.selection.select_path (path);
visible_child_name = page_names[current_page];
}
@@ -196,9 +197,9 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
if (window.current_item is LibvirtMachine) {
var libvirt_machine = window.current_item as LibvirtMachine;
stats_id = libvirt_machine.stats_updated.connect (() => {
- window.sidebar.cpu_graph.points = libvirt_machine.cpu_stats;
- window.sidebar.net_graph.points = libvirt_machine.net_stats;
- window.sidebar.io_graph.points = libvirt_machine.io_stats;
+ window.sidebar.props_sidebar.cpu_graph.points = libvirt_machine.cpu_stats;
+ window.sidebar.props_sidebar.net_graph.points = libvirt_machine.net_stats;
+ window.sidebar.props_sidebar.io_graph.points = libvirt_machine.io_stats;
});
}
diff --git a/src/sidebar.vala b/src/sidebar.vala
index ccfbcd1..d9084b9 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -15,32 +15,19 @@ private class Boxes.Sidebar: Gtk.Revealer, Boxes.UI {
[GtkChild]
public WizardSidebar wizard_sidebar;
[GtkChild]
- public Gtk.Image screenshot;
+ public PropertiesSidebar props_sidebar;
[GtkChild]
private Gtk.Notebook notebook;
- public Gtk.ListStore props_listmodel;
- [GtkChild]
- private Gtk.TreeModelFilter props_model_filter;
- [GtkChild]
- public Gtk.TreeSelection props_selection;
- [GtkChild]
- public Gtk.Button shutdown_button;
- [GtkChild]
- public MiniGraph cpu_graph;
- [GtkChild]
- public MiniGraph io_graph;
- [GtkChild]
- public MiniGraph net_graph;
private AppWindow window;
construct {
notify["ui-state"].connect (ui_state_changed);
- setup_sidebar ();
}
public void setup_ui (AppWindow window) {
this.window = window;
+ props_sidebar.setup_ui (window);
}
private void ui_state_changed () {
@@ -56,23 +43,4 @@ private class Boxes.Sidebar: Gtk.Revealer, Boxes.UI {
break;
}
}
-
- private void setup_sidebar () {
- props_model_filter.set_visible_column (1);
- }
-
- [GtkCallback]
- private void on_props_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn
column) {
- Gtk.TreeIter filter_iter, iter;
- props_model_filter.get_iter (out filter_iter, path);
- props_model_filter.convert_iter_to_child_iter (out iter, filter_iter);
- window.properties.page = (PropertiesPage) props_listmodel.get_path (iter).get_indices ()[0];
- }
-
- [GtkCallback]
- private void on_shutdown_button_clicked () {
- var machine = window.current_item as LibvirtMachine;
- if (machine != null)
- machine.force_shutdown ();
- }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]