[gnome-boxes/wip/ui-files] tmp



commit c34e2a3cdd2087d31c412396c2da9421ecb092f9
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Dec 24 20:24:51 2013 +0000

    tmp

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/wizard-source.ui       |  273 ++++++++++++++++++++++++++++++++++++++++
 src/wizard-source.vala         |  234 ++++++++++++----------------------
 src/wizard.vala                |    8 +-
 4 files changed, 358 insertions(+), 158 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index ce518e6..8d464dc 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -7,5 +7,6 @@
     <file>icons/boxes-gray.png</file>
     <file preprocess="xml-stripblanks">ui/unattended-setup-box.ui</file>
     <file preprocess="xml-stripblanks">ui/wizard-scrolled.ui</file>
+    <file preprocess="xml-stripblanks">ui/wizard-source.ui</file>
   </gresource>
 </gresources>
diff --git a/data/ui/wizard-source.ui b/data/ui/wizard-source.ui
new file mode 100644
index 0000000..a12a99e
--- /dev/null
+++ b/data/ui/wizard-source.ui
@@ -0,0 +1,273 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+  <template class="BoxesWizardSource" parent="GtkNotebook">
+    <property name="visible">True</property>
+    <property name="width-request">500</property>
+    <property name="show-tabs">False</property>
+    <signal name="switch-page" handler="on_switch_page"/>
+    <style>
+      <class name="boxes-source-nb"/>
+    </style>
+
+    <!-- main page -->
+    <child>
+      <object class="GtkBox" id="main_vbox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">0</property>
+        <property name="margin-top">15</property>
+        <property name="margin-bottom">15</property>
+        <style>
+          <class name="boxes-menu"/>
+        </style>
+        <child>
+          <object class="BoxesWizardScrolled" id="media_scrolled"/>
+        </child>
+
+        <child>
+          <object class="GtkButton" id="enter_url_button">
+            <signal name="clicked" handler="on_enter_url_button_clicked"/>
+            <style>
+              <class name="boxes-menu-row"/>
+            </style>
+            <child>
+              <object class="GtkBox" id="enter_url_box">
+                <property name="visible">True</property>
+                <property name="margin-top">10</property>
+                <property name="margin-bottom">10</property>
+                <property name="margin-left">20</property>
+                <property name="margin-right">20</property>
+                <property name="spacing">20</property>
+                <property name="orientation">horizontal</property>
+                <child>
+                  <object class="GtkLabel" id="enter_url_label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0.0</property>
+                    <property name="label" translatable="yes">Enter URL</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="enter_url_next_label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">▶</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkButton" id="select_file_button">
+            <signal name="clicked" handler="on_select_file_button_clicked"/>
+            <style>
+              <class name="boxes-menu-row"/>
+            </style>
+            <child>
+              <object class="GtkBox" id="select_file_box">
+                <property name="visible">True</property>
+                <property name="margin-top">10</property>
+                <property name="margin-bottom">10</property>
+                <property name="margin-left">20</property>
+                <property name="margin-right">20</property>
+                <property name="spacing">20</property>
+                <property name="orientation">horizontal</property>
+                <child>
+                  <object class="GtkLabel" id="select_file_label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0.0</property>
+                    <property name="label" translatable="yes">Select a file</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="select_file_next_label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">▶</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkButton" id="libvirt_sys_import_button">
+            <property name="visible">False</property>
+            <signal name="clicked" handler="on_libvirt_sys_import_button_clicked"/>
+            <style>
+              <class name="boxes-menu-row"/>
+            </style>
+            <child>
+              <object class="GtkBox" id="libvirt_sys_import_box">
+                <property name="visible">True</property>
+                <property name="margin-top">10</property>
+                <property name="margin-bottom">10</property>
+                <property name="margin-left">20</property>
+                <property name="margin-right">20</property>
+                <property name="spacing">20</property>
+                <property name="orientation">horizontal</property>
+                <child>
+                  <object class="GtkLabel" id="libvirt_sys_import_label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0.0</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="libvirt_sys_import_next_label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">▶</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+
+    <!-- URL page -->
+    <child>
+      <object class="GtkBox" id="url_menubox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">0</property>
+        <property name="margin-top">15</property>
+        <property name="margin-bottom">15</property>
+        <style>
+          <class name="boxes-menu"/>
+        </style>
+        <child>
+          <object class="GtkButton" id="url_back_button">
+            <signal name="clicked" handler="on_url_back_button_clicked"/>
+            <style>
+              <class name="boxes-menu-row"/>
+            </style>
+            <child>
+              <object class="GtkBox" id="url_back_box">
+                <property name="visible">True</property>
+                <property name="margin-top">10</property>
+                <property name="margin-bottom">10</property>
+                <property name="margin-left">20</property>
+                <property name="margin-right">20</property>
+                <property name="spacing">20</property>
+                <property name="orientation">horizontal</property>
+                <child>
+                  <object class="GtkLabel" id="enter_url_back_label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">◀</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="enter_url_label2">
+                    <property name="visible">True</property>
+                    <property name="xalign">0.0</property>
+                    <property name="label" translatable="yes">Enter URL</property>
+                    <style>
+                      <class name="boxes-source-label"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkAlignment" id="url_entry_bin">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="yalign">0</property>
+            <property name="xscale">1</property>
+            <property name="yscale">1</property>
+            <style>
+              <class name="boxes-menu-row"/>
+            </style>
+            <child>
+              <object class="GtkBox" id="url_entry_vbox">
+                <property name="visible">True</property>
+                <property name="margin-top">10</property>
+                <property name="margin-bottom">10</property>
+                <property name="margin-left">20</property>
+                <property name="margin-right">20</property>
+                <property name="spacing">20</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkEntry" id="url_entry"/>
+                </child>
+
+                <child>
+                  <object class="GtkBox" id="url_entry_hbox">
+                    <property name="visible">True</property>
+                    <property name="spacing">0</property>
+                    <property name="orientation">horizontal</property>
+                    <child>
+                      <object class="GtkImage" id="url_image">
+                        <property name="visible">True</property>
+                        <property name="icon-name">network-workgroup</property>
+                        <property name="icon-size">0</property>
+                        <property name="pixel-size">96</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                      </packing>
+                    </child>
+
+                    <child>
+                      <object class="GtkLabel" id="url_description_label">
+                        <property name="visible">True</property>
+                        <property name="use-markup">True</property>
+                        <property name="wrap">True</property>
+                        <property name="label" translatable="yes">&lt;b&gt;Desktop Access&lt;/b&gt;\n\nWill 
add boxes for all systems available from this account.</property>
+                        <property name="xalign">0</property>
+                        <!-- Work around clutter size allocation issue (bz#677260) -->
+                        <property name="width-chars">30</property>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index 5eecf34..7dc72c5 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -17,7 +17,10 @@ private class Boxes.WizardScrolled : Gtk.ScrolledWindow {
     public Gtk.Box vbox;
 
     private int num_visible;
-    public WizardScrolled (int num_visible) {
+
+    // Ideally, we shouldn't need this fuction but is there a way to connect
+    // vscrollbar signals from the UI template?
+    public void setup (int num_visible) {
         this.num_visible = num_visible;
 
         notify["num-visible"].connect (() => {
@@ -55,30 +58,9 @@ private class Boxes.WizardScrolled : Gtk.ScrolledWindow {
     }
 }
 
-private class Boxes.WizardSource: GLib.Object {
-    public Gtk.Widget widget { get { return notebook; } }
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/wizard-source.ui")]
+private class Boxes.WizardSource: Gtk.Notebook {
     public Gtk.Widget? selected { get; set; }
-    private SourcePage _page;
-    public SourcePage page {
-        get { return _page; }
-        set {
-            _page = value;
-            notebook.set_current_page (page);
-            if (selected != null)
-                selected.grab_focus ();
-            switch (page) {
-            case SourcePage.MAIN:
-                add_media_entries.begin ();
-                // FIXME: grab first element in the menu list
-                main_vbox.grab_focus ();
-                break;
-            case SourcePage.URL:
-                url_entry.changed ();
-                url_entry.grab_focus ();
-                break;
-            }
-        }
-    }
     public string uri {
         get { return url_entry.get_text (); }
         set { url_entry.set_text (value); }
@@ -87,103 +69,74 @@ private class Boxes.WizardSource: GLib.Object {
     public LibvirtSystemImporter libvirt_sys_importer { get; private set; }
     public bool libvirt_sys_import;
 
+    public signal void activated (); // Emitted on user activating a source
+
+    [GtkChild]
     private Gtk.Box main_vbox;
-    private Gtk.Box media_vbox;
+    [GtkChild]
     private Boxes.WizardScrolled media_scrolled;
-    private Gtk.Notebook notebook;
-    private Gtk.Label url_label;
+    [GtkChild]
+    private Gtk.Label url_description_label;
+    [GtkChild]
     private Gtk.Image url_image;
+    [GtkChild]
+    private Gtk.Alignment url_entry_bin;
+    [GtkChild]
     public Gtk.Entry url_entry;
+    [GtkChild]
+    private Gtk.Button select_file_button;
+    [GtkChild]
+    private Gtk.Button libvirt_sys_import_button;
+    [GtkChild]
+    private Gtk.Label libvirt_sys_import_label;
 
-    public signal void activate (); // Emitted on user activating a source
+    private Gtk.Box media_vbox;
 
     private MediaManager media_manager;
 
     public WizardSource (MediaManager media_manager) {
         this.media_manager = media_manager;
 
-        notebook = new Gtk.Notebook ();
-        notebook.width_request = 500;
-        notebook.get_style_context ().add_class ("boxes-source-nb");
-        notebook.show_tabs = false;
-
-        /* main page */
-        main_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
-        main_vbox.get_style_context ().add_class ("boxes-menu");
-        main_vbox.margin_top = main_vbox.margin_bottom = 15;
         main_vbox.grab_focus ();
-        notebook.append_page (main_vbox, null);
 
-        media_scrolled = new WizardScrolled (5);
+        media_scrolled.setup (5);
         media_vbox = media_scrolled.vbox;
-        main_vbox.add (media_scrolled);
-
-        var hbox = add_entry (main_vbox, () => {
-            page = SourcePage.URL;
-
-            return false;
-        });
-        var label = new Gtk.Label (_("Enter URL"));
-        label.xalign = 0.0f;
-        hbox.pack_start (label, true, true);
-        var next = new Gtk.Label ("▶");
-        hbox.pack_start (next, false, false);
-
-        hbox = add_entry (main_vbox, launch_file_selection_dialog);
-        label = new Gtk.Label (_("Select a file"));
-        label.xalign = 0.0f;
-        hbox.pack_start (label, true, true);
-        next = new Gtk.Label ("▶");
-        hbox.pack_start (next, false, false);
+        draw_as_css_box (url_entry_bin);
 
-        /* URL page */
-        var url_menubox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
-        url_menubox.get_style_context ().add_class ("boxes-menu");
-        url_menubox.margin_top = url_menubox.margin_bottom = 15;
-        notebook.append_page (url_menubox, null);
-
-        hbox = add_entry (url_menubox, () => {
-            selected = null;
-            page = SourcePage.MAIN;
-
-            return false;
-        });
-        var prev = new Gtk.Label ("◀");
-        hbox.pack_start (prev, false, false);
-        label = new Gtk.Label (_("Enter URL"));
-        label.get_style_context ().add_class ("boxes-source-label");
-        hbox.pack_start (label, true, true);
-
-        var vbox = add_entry (url_menubox);
-        vbox.set_orientation (Gtk.Orientation.VERTICAL);
-        url_entry = new Gtk.Entry ();
-        vbox.add (url_entry);
-
-        hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
-        url_image = new Gtk.Image.from_icon_name ("network-workgroup", 0);
-        // var image = new Gtk.Image.from_icon_name ("krfb", 0);
-        url_image.pixel_size = 96;
-        hbox.pack_start (url_image, false, false);
-
-        url_label = new Gtk.Label (null);
-        url_label.xalign = 0.0f;
-        url_label.set_markup (_("<b>Desktop Access</b>\n\nWill add boxes for all systems available from this 
account."));
-        url_label.set_use_markup (true);
-        url_label.wrap = true;
-        // Work around clutter size allocation issue (bz#677260)
-        url_label.width_chars = 30;
+        update_libvirt_sytem_entry_visibility.begin ();
+        add_media_entries.begin ();
+    }
 
-        hbox.pack_start (url_label, true, true);
-        vbox.add (hbox);
+    [GtkCallback]
+    private void on_enter_url_button_clicked () {
+        page = SourcePage.URL;
+    }
 
-        notebook.show_all ();
+    [GtkCallback]
+    private void on_url_back_button_clicked () {
+        selected = null;
+        page = SourcePage.MAIN;
+    }
 
-        add_libvirt_sytem_entry.begin ();
-        add_media_entries.begin ();
+    [GtkCallback]
+    private void on_switch_page (Gtk.Notebook self, Gtk.Widget page, uint page_num) {
+        if (selected != null)
+            selected.grab_focus ();
+        switch (page_num) {
+        case SourcePage.MAIN:
+            add_media_entries.begin ();
+            // FIXME: grab first element in the menu list
+            main_vbox.grab_focus ();
+            break;
+        case SourcePage.URL:
+            url_entry.changed ();
+            url_entry.grab_focus ();
+            break;
+        }
     }
 
     public void update_url_page(string title, string text, string icon_name) {
-        url_label.set_markup ("<b>"  + title + "</b>\n\n" + text);
+        url_description_label.set_markup ("<b>"  + title + "</b>\n\n" + text);
         url_image.icon_name = icon_name;
     }
 
@@ -228,11 +181,21 @@ private class Boxes.WizardSource: GLib.Object {
     }
 
     private void add_media_entry (InstallerMedia media) {
-        var hbox = add_entry (media_vbox, () => {
+        var button = new Gtk.Button ();
+        media_vbox.add (button);
+        button.get_style_context ().add_class ("boxes-menu-row");
+        button.clicked.connect (() => {
             on_media_selected (media);
 
-            return true;
-        }, 15, 5, media.device_file);
+            selected = button;
+        });
+
+        var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 20);
+        button.add (hbox);
+
+        hbox.margin_left = hbox.margin_right = 15;
+        hbox.margin_top = hbox.margin_bottom = 5;
+        button.set_data ("boxes-media", media.device_file);
 
         var image = new Gtk.Image.from_icon_name ("media-optical", 0);
         image.pixel_size = 64;
@@ -275,7 +238,7 @@ private class Boxes.WizardSource: GLib.Object {
         media_scrolled.show ();
     }
 
-    private async void add_libvirt_sytem_entry () {
+    private async void update_libvirt_sytem_entry_visibility () {
         try {
             libvirt_sys_importer = yield new LibvirtSystemImporter ();
         } catch (LibvirtSystemImporterError.NO_IMPORTS error) {
@@ -283,54 +246,12 @@ private class Boxes.WizardSource: GLib.Object {
 
             return;
         }
-
-        var hbox = add_entry (main_vbox, () => {
-            libvirt_sys_import = true;
-            activate ();
-
-            return true;
-        });
-        var label = new Gtk.Label (libvirt_sys_importer.wizard_menu_label);
-        label.xalign = 0.0f;
-        hbox.pack_start (label, true, true);
-        var next = new Gtk.Label ("▶");
-        hbox.pack_start (next, false, false);
+        libvirt_sys_import_label.label = libvirt_sys_importer.wizard_menu_label;
         main_vbox.show_all ();
     }
 
-    private Gtk.Box add_entry (Gtk.Box            box,
-                               owned ClickedFunc? clicked = null,
-                               int                h_margin = 20,
-                               int                v_margin = 10,
-                               string?            media = null) {
-        Gtk.Container row;
-        if (clicked != null) {
-            var button = new Gtk.Button ();
-            button.clicked.connect (() => {
-                if (clicked ())
-                    selected = button;
-            });
-            row = button;
-        } else {
-            var bin = new Gtk.Alignment (0,0,1,1);
-            draw_as_css_box (bin);
-            row = bin;
-        }
-        var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 20);
-        row.add (hbox);
-        row.get_style_context ().add_class ("boxes-menu-row");
-
-        box.add (row);
-        if (media != null)
-            row.set_data ("boxes-media", media);
-
-        hbox.margin_left = hbox.margin_right = h_margin;
-        hbox.margin_top = hbox.margin_bottom = v_margin;
-
-        return hbox;
-    }
-
-    private bool launch_file_selection_dialog () {
+    [GtkCallback]
+    private void on_select_file_button_clicked () {
         var dialog = new Gtk.FileChooserDialog (_("Select a device or ISO file"),
                                                 App.app.window,
                                                 Gtk.FileChooserAction.OPEN,
@@ -341,26 +262,31 @@ private class Boxes.WizardSource: GLib.Object {
         dialog.filter.add_mime_type ("application/x-cd-image");
         foreach (var extension in InstalledMedia.supported_extensions)
             dialog.filter.add_pattern ("*" + extension);
-        var ret = false;
         if (dialog.run () == Gtk.ResponseType.ACCEPT) {
             uri = dialog.get_uri ();
             // clean install_media as this may be set already when going back in the wizard
             install_media = null;
-            activate ();
+            activated ();
 
-            ret = true;
+            selected = select_file_button;
         }
 
         dialog.destroy ();
+    }
+
+    [GtkCallback]
+    private void on_libvirt_sys_import_button_clicked () {
+        libvirt_sys_import = true;
+        activated ();
 
-        return ret;
+        selected = libvirt_sys_import_button;
     }
 
     private void on_media_selected (InstallerMedia media) {
         try {
             install_media = media_manager.create_installer_media_from_media (media);
             uri = media.device_file;
-            activate ();
+            activated ();
         } catch (GLib.Error error) {
             // This is unlikely to happen since media we use as template should have already done most async 
work
             warning ("Failed to setup installation media '%s': %s", media.device_file, error.message);
diff --git a/src/wizard.vala b/src/wizard.vala
index 30d7fec..4f357e1 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -175,7 +175,7 @@ private class Boxes.Wizard: Boxes.UI {
         wizard_source.notify["selected"].connect(wizard_source_update_next);
         wizard_source.url_entry.changed.connect (wizard_source_update_next);
 
-        wizard_source.activate.connect(() => {
+        wizard_source.activated.connect(() => {
             page = WizardPage.PREPARATION;
         });
 
@@ -577,9 +577,9 @@ private class Boxes.Wizard: Boxes.UI {
         label.wrap = true;
         label.xalign = 0.0f;
         vbox.pack_start (label, false, false);
-        vbox.pack_start (wizard_source.widget, false, false);
-        wizard_source.widget.hexpand = true;
-        wizard_source.widget.halign = Gtk.Align.CENTER;
+        vbox.pack_start (wizard_source, false, false);
+        wizard_source.hexpand = true;
+        wizard_source.halign = Gtk.Align.CENTER;
         label = new Gtk.Label (_("Any trademarks shown above are used merely for identification of software 
products you have already obtained and are the property of their respective owners."));
         label.get_style_context ().add_class ("boxes-logo-notice-label");
         label.wrap = true;


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