[gnome-boxes/wip/ui-files] Move DisplayPage UI setup to UI file



commit 0dcf6cbb3efa07426bc9a4d7014cbbfcc456e838
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Jan 8 17:01:45 2014 +0000

    Move DisplayPage UI setup to UI file

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/display-page.ui        |   94 ++++++++++++++++++++++++++++++
 src/app.vala                   |    2 +-
 src/display-page.vala          |  122 +++++++++++++++-------------------------
 src/machine.vala               |    2 +-
 5 files changed, 143 insertions(+), 78 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index f2fc8d6..f2d59d1 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -6,6 +6,7 @@
     <file>icons/boxes-create.png</file>
     <file>icons/boxes-dark.png</file>
     <file>icons/boxes-gray.png</file>
+    <file preprocess="xml-stripblanks">ui/display-page.ui</file>
     <file preprocess="xml-stripblanks">ui/display-toolbar.ui</file>
     <file preprocess="xml-stripblanks">ui/topbar.ui</file>
     <file preprocess="xml-stripblanks">ui/unattended-setup-box.ui</file>
diff --git a/data/ui/display-page.ui b/data/ui/display-page.ui
new file mode 100644
index 0000000..aaf2fe2
--- /dev/null
+++ b/data/ui/display-page.ui
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+  <template class="BoxesDisplayPage" parent="GtkBox">
+    <property name="orientation">vertical</property>
+    <property name="spacing">0</property>
+
+    <child>
+      <object class="BoxesDisplayToolbar" id="toolbar">
+        <property name="visible">True</property>
+        <property name="overlay">False</property>
+        <property name="handle-drag">True</property>
+      </object>
+
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">False</property>
+        <property name="padding">0</property>
+      </packing>
+    </child>
+
+    <child>
+      <object class="GtkGrid" id="grid">
+        <property name="visible">True</property>
+
+        <child>
+          <object class="GtkEventBox" id="event_box">
+            <property name="visible">True</property>
+            <property name="above-child">True</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <signal name="event" handler="on_event_box_event"/>
+            <style>
+              <class name="boxes-toplevel"/>
+            </style>
+          </object>
+
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">2</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkEventBox" id="overlay_toolbar_box">
+            <property name="visible">True</property>
+            <property name="valign">start</property>
+            <property name="vexpand">False</property>
+
+            <child>
+              <object class="BoxesDisplayToolbar" id="overlay_toolbar">
+                <property name="visible">True</property>
+                <property name="overlay">True</property>
+                <property name="handle-drag">True</property>
+              </object>
+            </child>
+          </object>
+
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkGrid" id="notification_grid">
+            <property name="visible">True</property>
+            <property name="valign">start</property>
+            <property name="halign">center</property>
+            <property name="vexpand">True</property>
+          </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>
+      </object>
+
+      <packing>
+        <property name="expand">True</property>
+        <property name="fill">True</property>
+        <property name="padding">0</property>
+      </packing>
+    </child>
+
+  </template>
+</interface>
diff --git a/src/app.vala b/src/app.vala
index 93960a2..c6b6ccc 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -531,7 +531,7 @@ private class Boxes.App: GLib.Object, Boxes.UI {
         notebook.append_page (embed, null);
 
         display_page = new DisplayPage ();
-        notebook.append_page (display_page.widget, null);
+        notebook.append_page (display_page, null);
 
         selectionbar = new Selectionbar ();
         main_vbox.add (selectionbar);
diff --git a/src/display-page.vala b/src/display-page.vala
index 3fef46c..ce6cd06 100644
--- a/src/display-page.vala
+++ b/src/display-page.vala
@@ -2,15 +2,18 @@
 using Gtk;
 using Gdk;
 
-private class Boxes.DisplayPage: GLib.Object {
-    public Widget widget { get { return box; } }
-
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/display-page.ui")]
+private class Boxes.DisplayPage: Gtk.Box {
+    [GtkChild]
     public DisplayToolbar toolbar;
 
+    [GtkChild]
     private EventBox event_box;
-    private Box box;
+    [GtkChild]
     private DisplayToolbar overlay_toolbar;
+    [GtkChild]
     private EventBox overlay_toolbar_box;
+    [GtkChild]
     private Grid notification_grid;
     private uint toolbar_hide_id;
     private uint toolbar_show_id;
@@ -34,80 +37,13 @@ private class Boxes.DisplayPage: GLib.Object {
 
     public DisplayPage () {
         overlay_toolbar_invisible_timeout = App.app.duration;
-        event_box = new EventBox ();
-        event_box.get_style_context ().add_class ("boxes-toplevel");
         event_box.set_events (EventMask.POINTER_MOTION_MASK | EventMask.SCROLL_MASK);
-        event_box.above_child = true;
-        event_box.event.connect ((event) => {
-            if (App.app.fullscreen && event.type == EventType.MOTION_NOTIFY) {
-                var y = event.motion.y;
-                if (y <= 0 && toolbar_show_id == 0) {
-                    toolbar_event_stop ();
-                    if ((event.motion.state &
-                         (ModifierType.SHIFT_MASK | ModifierType.CONTROL_MASK |
-                          ModifierType.MOD1_MASK | ModifierType.SUPER_MASK |
-                          ModifierType.HYPER_MASK | ModifierType.META_MASK |
-                          ModifierType.BUTTON1_MASK | ModifierType.BUTTON2_MASK |
-                          ModifierType.BUTTON3_MASK | ModifierType.BUTTON4_MASK |
-                          ModifierType.BUTTON5_MASK)) == 0) {
-                        toolbar_show_id = Timeout.add (App.app.duration, () => {
-                            set_overlay_toolbar_visible (true);
-                            toolbar_show_id = 0;
-                            return false;
-                        });
-                    }
-                } else if (y > 5 && toolbar_hide_id == 0) {
-                    toolbar_event_stop ();
-                    toolbar_hide_id = Timeout.add (overlay_toolbar_invisible_timeout, () => {
-                        set_overlay_toolbar_visible (false);
-                        toolbar_hide_id = 0;
-                        overlay_toolbar_invisible_timeout = App.app.duration;
-                        return false;
-                    });
-                }
-            }
-
-            if (event.type == EventType.GRAB_BROKEN)
-                return false;
-
-            if (event_box.get_child () != null)
-                event_box.get_child ().event (event);
 
-            return false;
-        });
-
-        toolbar = new DisplayToolbar (false, true);
-
-        box = new Box (Orientation.VERTICAL, 0);
-        box.pack_start (toolbar, false, false, 0);
-
-        var grid = new Gtk.Grid ();
         App.app.window.window_state_event.connect ((event) => {
             update_toolbar_visible ();
 
             return false;
         });
-        event_box.hexpand = true;
-        event_box.vexpand = true;
-
-        box.pack_start (grid, true, true, 0);
-
-        overlay_toolbar = new DisplayToolbar (true, true);
-        overlay_toolbar_box = new EventBox ();
-        overlay_toolbar_box.add (overlay_toolbar);
-        overlay_toolbar_box.valign = Gtk.Align.START;
-        overlay_toolbar_box.vexpand = false;
-
-        notification_grid = new Grid ();
-        notification_grid.valign = Gtk.Align.START;
-        notification_grid.halign = Gtk.Align.CENTER;
-        notification_grid.vexpand = true;
-
-        grid.attach (event_box, 0, 0, 1, 2);
-        grid.attach (overlay_toolbar_box, 0, 0, 1, 1);
-        grid.attach (notification_grid, 0, 1, 1, 1);
-
-        box.show_all ();
 
         toolbar.bind_property ("title", overlay_toolbar, "title", BindingFlags.SYNC_CREATE);
         toolbar.bind_property ("subtitle", overlay_toolbar, "subtitle", BindingFlags.SYNC_CREATE);
@@ -159,10 +95,6 @@ private class Boxes.DisplayPage: GLib.Object {
         toolbar_show_id = 0;
     }
 
-    public void show () {
-        App.app.notebook.page = Boxes.AppPage.DISPLAY;
-    }
-
     public void update_title () {
         var machine = App.app.current_item as Boxes.Machine;
         return_if_fail (machine != null);
@@ -221,7 +153,7 @@ private class Boxes.DisplayPage: GLib.Object {
             return false;
         });
 
-        show ();
+        App.app.notebook.page = Boxes.AppPage.DISPLAY;
         widget.grab_focus ();
     }
 
@@ -249,4 +181,42 @@ private class Boxes.DisplayPage: GLib.Object {
         return widget;
     }
 
+    [GtkCallback]
+    private bool on_event_box_event (Gdk.Event event) {
+        if (App.app.fullscreen && event.type == EventType.MOTION_NOTIFY) {
+            var y = event.motion.y;
+            if (y <= 0 && toolbar_show_id == 0) {
+                toolbar_event_stop ();
+                if ((event.motion.state &
+                     (ModifierType.SHIFT_MASK | ModifierType.CONTROL_MASK |
+                      ModifierType.MOD1_MASK | ModifierType.SUPER_MASK |
+                      ModifierType.HYPER_MASK | ModifierType.META_MASK |
+                      ModifierType.BUTTON1_MASK | ModifierType.BUTTON2_MASK |
+                      ModifierType.BUTTON3_MASK | ModifierType.BUTTON4_MASK |
+                      ModifierType.BUTTON5_MASK)) == 0) {
+                    toolbar_show_id = Timeout.add (App.app.duration, () => {
+                        set_overlay_toolbar_visible (true);
+                        toolbar_show_id = 0;
+                        return false;
+                    });
+                }
+            } else if (y > 5 && toolbar_hide_id == 0) {
+                toolbar_event_stop ();
+                toolbar_hide_id = Timeout.add (overlay_toolbar_invisible_timeout, () => {
+                    set_overlay_toolbar_visible (false);
+                    toolbar_hide_id = 0;
+                    overlay_toolbar_invisible_timeout = App.app.duration;
+                    return false;
+                });
+            }
+        }
+
+        if (event.type == EventType.GRAB_BROKEN)
+            return false;
+
+        if (event_box.get_child () != null)
+            event_box.get_child ().event (event);
+
+        return false;
+    }
 }
diff --git a/src/machine.vala b/src/machine.vala
index 59b49ee..128f9b8 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -799,7 +799,7 @@ private class Boxes.MachineActor: GLib.Object, Boxes.UI {
 
                     thumbnail.add_transition ("back-from-properties", transition);
                 } else
-                    App.app.display_page.show ();
+                    App.app.notebook.page = Boxes.AppPage.DISPLAY;
             }
             break;
 


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