[gnome-boxes/wip/less-actors: 2/2] tmp



commit ec66f8e88c32830f555fe040700584a45c2936c8
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sat Feb 8 09:29:32 2014 +0100

    tmp

 data/ui/sidebar.ui       |    6 +-
 src/app.vala             |   95 +----------
 src/collection-view.vala |   48 ------
 src/display-page.vala    |   11 --
 src/machine.vala         |  395 ++++++++--------------------------------------
 src/sidebar.vala         |    2 +-
 src/util-app.vala        |    9 +
 7 files changed, 83 insertions(+), 483 deletions(-)
---
diff --git a/data/ui/sidebar.ui b/data/ui/sidebar.ui
index 8b66283..64ee6ef 100644
--- a/data/ui/sidebar.ui
+++ b/data/ui/sidebar.ui
@@ -175,12 +175,8 @@
             <property name="margin-bottom">30</property>
 
             <child>
-              <object class="GtkAlignment" id="screenshot_placeholder">
+              <object class="GtkBox" id="screenshot_placeholder">
                 <property name="visible">True</property>
-                <property name="xalign">0.0</property>
-                <property name="yalign">0.0</property>
-                <property name="xscale">0.0</property>
-                <property name="yscale">0.0</property>
                 <property name="width-request">180</property>
                 <property name="height-request">130</property>
               </object>
diff --git a/src/app.vala b/src/app.vala
index ea3305c..03ba32a 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -63,7 +63,7 @@ private class Boxes.App: GLib.Object, Boxes.UI {
         }
     }
 
-    private bool maximized { get { return WindowState.MAXIMIZED in window.get_window ().get_state (); } }
+    public bool maximized { get { return WindowState.MAXIMIZED in window.get_window ().get_state (); } }
     public Gtk.Notebook notebook;
     public ClutterWidget embed;
     public Clutter.Stage stage;
@@ -651,36 +651,6 @@ private class Boxes.App: GLib.Object, Boxes.UI {
         notebook.page = Boxes.AppPage.MAIN;
     }
 
-    private void position_item_actor_at_icon (CollectionItem item) {
-        float item_x, item_y;
-        view.get_item_pos (item, out item_x, out item_y);
-        var actor = item.actor;
-
-        var transition = actor.get_transition ("animate-position");
-        if (transition != null)
-            actor.remove_transition ("animate-position");
-
-        transition = animate_actor_geometry (item_x, item_y, Machine.SCREENSHOT_WIDTH, 
Machine.SCREENSHOT_HEIGHT);
-
-        // Also track size changes in the icon_view during the animation
-        var id = view.main_view.size_allocate.connect ((allocation) => {
-            // We do this in an idle to avoid causing a layout inside a size_allocate cycle
-            Idle.add_full (Priority.HIGH, () => {
-                position_item_actor_at_icon (current_item);
-                return false;
-            });
-        });
-
-        transition.completed.connect (() => {
-            actor.remove_transition ("animate-position");
-            view.main_view.disconnect (id);
-            if (App.app.ui_state == UIState.COLLECTION ||
-                App.app.current_item.actor != actor)
-            actor_remove (actor);
-        });
-        actor.add_transition ("animate-position", transition);
-    }
-
     private void ui_state_changed () {
         // The order is important for some widgets here (e.g properties must change its state before wizard 
so it can
         // flush any deferred changes for wizard to pick-up when going back from properties to wizard 
(review).
@@ -710,26 +680,15 @@ private class Boxes.App: GLib.Object, Boxes.UI {
             fullscreen = false;
             view.visible = true;
 
-            // Animate current_item actor to collection position
-            if (current_item != null) {
-                var actor = current_item.actor;
-
-                actor.show ();
-                position_item_actor_at_icon (current_item);
-            }
-
             break;
 
         case UIState.CREDS:
             break;
 
         case UIState.WIZARD:
-            if (current_item != null)
-                actor_remove (current_item.actor);
             break;
 
         case UIState.PROPERTIES:
-            current_item.actor.hide ();
             break;
 
         case UIState.DISPLAY:
@@ -873,23 +832,9 @@ private class Boxes.App: GLib.Object, Boxes.UI {
         return false;
     }
 
-    public void connect_to (Machine machine, float x, float y, Machine.ConnectFlags flags = 
Machine.ConnectFlags.NONE) {
+    public void connect_to (Machine machine) {
         current_item = machine;
 
-        // Set up actor for CREDS animation
-        var actor = machine.actor;
-        if (actor.get_parent () == null) {
-            App.app.overlay_bin_actor.add_child (actor);
-            allocate_actor_no_animation (actor, x, y,
-                                         Machine.SCREENSHOT_WIDTH,
-                                         Machine.SCREENSHOT_HEIGHT * 2);
-        }
-        actor.show ();
-        actor.set_easing_mode (Clutter.AnimationMode.LINEAR);
-        actor.min_width = actor.natural_width = Machine.SCREENSHOT_WIDTH * 2;
-        actor.fixed_position_set = false;
-        actor.set_easing_duration (App.app.duration);
-
         // Track machine status in toobar
         status_bind = machine.bind_property ("status", topbar, "status", BindingFlags.SYNC_CREATE);
 
@@ -897,33 +842,12 @@ private class Boxes.App: GLib.Object, Boxes.UI {
             App.app.notificationbar.display_error (message);
         });
 
-        // Start the CREDS state
-        set_state (UIState.CREDS);
+        if (ui_state != UIState.CREDS) {
+            // Start the CREDS state
+            set_state (UIState.CREDS);
 
-        // Connect to the display
-        machine.connect_display.begin (flags, (obj, res) => {
-            try {
-                machine.connect_display.end (res);
-
-                if (maximized)
-                    fullscreen = true;
-            } catch (GLib.Error e) {
-                set_state (UIState.COLLECTION);
-                debug ("connect display failed: %s", e.message);
-                var bar = App.app.notificationbar;
-
-                if (e is Boxes.Error.RESTORE_FAILED &&
-                    !(Machine.ConnectFlags.IGNORE_SAVED_STATE in flags)) {
-                    var message =
-                        _("'%s' could not be restored from disk\nTry without saved state?").printf 
(machine.name);
-                    bar.display_for_action (message, _("Restart"), () => {
-                        connect_to (machine, x, y,
-                                    flags | Machine.ConnectFlags.IGNORE_SAVED_STATE);
-                    });
-                } else
-                    bar.display_error (_("Connection to '%s' failed").printf (machine.name));
-            }
-        });
+            return;
+        }
     }
 
     public void select_item (CollectionItem item) {
@@ -933,10 +857,7 @@ private class Boxes.App: GLib.Object, Boxes.UI {
             if (current_item is Machine) {
                 var machine = current_item as Machine;
 
-                float item_x, item_y;
-                view.get_item_pos (item, out item_x, out item_y);
-
-                connect_to (machine, item_x, item_y);
+                connect_to (machine);
             } else
                 warning ("unknown item, fix your code");
 
diff --git a/src/collection-view.vala b/src/collection-view.vala
index 03f809f..89a489f 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -53,45 +53,12 @@ private class Boxes.CollectionView: GLib.Object, Boxes.UI {
         });
     }
 
-    public void get_item_pos (CollectionItem item, out float x, out float y) {
-        Gdk.Rectangle rect;
-        var path = get_path_for_item (item);
-        if (path != null) {
-            (main_view.get_generic_view () as Gtk.IconView).get_cell_rect (path, null, out rect);
-            x = rect.x;
-            y = rect.y;
-        } else {
-            x = 0.0f;
-            y = 0.0f;
-        }
-    }
-
     private void ui_state_changed () {
         if (ui_state == UIState.COLLECTION)
             main_view.unselect_all ();
         fade_actor (actor, ui_state == UIState.COLLECTION ? 255 : 0);
     }
 
-    private void update_item_visible (CollectionItem item) {
-        var visible = false;
-
-        // FIXME
-        if (item is Machine) {
-            var machine = item as Machine;
-
-            switch (category.kind) {
-            case Category.Kind.USER:
-                visible = category.name in machine.config.categories;
-                break;
-            case Category.Kind.NEW:
-                visible = true;
-                break;
-            }
-        }
-
-        item.actor.visible = visible;
-    }
-
     private void update_screenshot (Gtk.TreeIter iter) {
         CollectionItem item;
         GLib.Icon[] emblem_icons = {};
@@ -188,9 +155,6 @@ private class Boxes.CollectionView: GLib.Object, Boxes.UI {
         item.set_data<ulong> ("under_construct_id", under_construct_id);
 
         item.set_state (App.app.ui_state);
-        actor_remove (item.actor);
-
-        update_item_visible (item);
     }
 
     public List<CollectionItem> get_selected_items () {
@@ -238,18 +202,6 @@ private class Boxes.CollectionView: GLib.Object, Boxes.UI {
         }
     }
 
-    private Gtk.TreePath? get_path_for_item (CollectionItem item) {
-        var iter = item.get_data<Gtk.TreeIter?> ("iter");
-        if (iter == null)
-            return null;
-
-        Gtk.TreeIter filter_iter;
-        if (!model_filter.convert_child_iter_to_iter (out filter_iter, iter))
-            return null;
-
-        return model_filter.get_path (filter_iter);
-    }
-
     private CollectionItem get_item_for_iter (Gtk.TreeIter iter) {
         GLib.Value value;
 
diff --git a/src/display-page.vala b/src/display-page.vala
index ce6cd06..6278386 100644
--- a/src/display-page.vala
+++ b/src/display-page.vala
@@ -53,17 +53,6 @@ private class Boxes.DisplayPage: Gtk.Box {
         notification_grid.attach (w, 0, 0, 1, 1);
     }
 
-    public void get_size (out int width, out int height) {
-        int tb_height;
-
-        App.app.window.get_size (out width, out height);
-
-        if (!App.app.fullscreen) {
-            toolbar.get_preferred_height (null, out tb_height);
-            height -= tb_height;
-        }
-    }
-
      private void update_toolbar_visible() {
          if (App.app.fullscreen && can_grab_mouse)
              toolbar.visible = true;
diff --git a/src/machine.vala b/src/machine.vala
index f5dd9e5..2558a9b 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -4,8 +4,16 @@ using Gdk;
 using Gtk;
 
 private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesProvider {
-    public override Clutter.Actor item_actor { get { return machine_actor.actor; } }
-    private MachineActor machine_actor;
+    // Check FIXME on Topbar.actor
+    public override Clutter.Actor item_actor {
+        get {
+            if (machine_actor == null)
+                machine_actor = new Clutter.Actor ();
+            return machine_actor;
+        }
+    }
+    private Clutter.Actor machine_actor;
+
     public Boxes.CollectionSource source;
     public Boxes.BoxConfig config;
     public Gdk.Pixbuf? pixbuf { get; set; }
@@ -24,8 +32,6 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
     private ulong hide_id;
     private uint show_timeout_id;
     private ulong disconnected_id;
-    private ulong need_password_id;
-    private ulong need_username_id;
     private ulong ui_state_id;
     private ulong got_error_id;
     private uint screenshot_id;
@@ -33,6 +39,8 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
     public static const int SCREENSHOT_HEIGHT = 134;
     private static Cairo.Surface grid_surface;
     private bool updating_screenshot;
+    private string username;
+    private string password;
 
     public Cancellable connecting_cancellable { get; protected set; }
 
@@ -84,6 +92,8 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
         Gtk.Widget widget;
 
         widget = display.get_display (0);
+        widget_remove (widget);
+        display.set_enable_inputs (widget, true);
 
         switch (App.app.ui_state) {
         case Boxes.UIState.CREDS:
@@ -101,7 +111,9 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
             break;
 
         case Boxes.UIState.PROPERTIES:
-            machine_actor.update_thumbnail (widget, false);
+            App.app.sidebar.screenshot_placeholder.add (widget);
+            display.set_enable_inputs (widget, false);
+
             break;
         }
     }
@@ -120,10 +132,6 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
                 hide_id = 0;
                 _display.disconnect (disconnected_id);
                 disconnected_id = 0;
-                _display.disconnect (need_password_id);
-                need_password_id = 0;
-                _display.disconnect (need_username_id);
-                need_username_id = 0;
                 _display.disconnect (got_error_id);
                 got_error_id = 0;
             }
@@ -153,17 +161,8 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
                     App.app.notificationbar.display_error (_("Connection to '%s' failed").printf (name));
             });
 
-            need_password_id = _display.notify["need-password"].connect (() => {
-                // Translators: The %s will be expanded with the name of the vm
-                status = _("Enter password for %s").printf (name);
-                machine_actor.set_password_needed (display.need_password);
-            });
-
-            need_username_id = _display.notify["need-username"].connect (() => {
-                machine_actor.set_username_needed (display.need_username);
-            });
-
-            _display.password = machine_actor.get_password ();
+            _display.username = username;
+            _display.password = password;
         }
     }
 
@@ -187,7 +186,6 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
         this.connecting_cancellable = new Cancellable ();
 
         pixbuf = draw_fallback_vm ();
-        machine_actor = new MachineActor (this);
 
         notify["ui-state"].connect (ui_state_changed);
         ui_state_id = App.app.notify["ui-state"].connect (() => {
@@ -386,14 +384,12 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
 
             orig_pixbuf = small_screenshot;
             pixbuf = draw_vm (small_screenshot, SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT);
-            machine_actor.set_screenshot (large_screenshot); // high resolution
             if (save)
                 save_pixbuf_as_screenshot (small_screenshot);
 
         } else {
             orig_pixbuf = null;
             pixbuf = draw_stopped_vm ();
-            machine_actor.set_screenshot (pixbuf);
         }
     }
 
@@ -512,330 +508,67 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
     }
 
     private void ui_state_changed () {
-        machine_actor.set_state (ui_state);
-
-        if (ui_state != Boxes.UIState.DISPLAY &&
-            ui_state != Boxes.UIState.PROPERTIES &&
-            ui_state != Boxes.UIState.CREDS) {
-            /* Disconnect if we go to any other state */
-            machine_actor.update_thumbnail (null, false);
-            disconnect_display ();
-        }
-    }
-
-    public override int compare (CollectionItem other) {
-        if (other is Machine)
-            return config.compare ((other as Machine).config);
-        else
-            return -1; // Machines are listed before non-machines
-    }
-}
-
-private class Boxes.MachineActor: GLib.Object, Boxes.UI {
-    public Clutter.Actor actor { get { return _actor; } }
-    public Clutter.Actor _actor;
-    public UIState previous_ui_state { get; protected set; }
-    public UIState ui_state { get; protected set; }
-
-    private GtkClutter.Texture screenshot;
-    private GtkClutter.Actor gtk_vbox;
-    private Clutter.Actor? thumbnail;
-    private GtkClutter.Texture? thumbnail_screenshot;
-    private Gtk.Label label;
-    private Gtk.Box vbox; // and the vbox under it
-    private Gtk.Entry password_entry;
-    private Machine machine;
-    ulong track_screenshot_id = 0;
-
-    ~MachineActor() {
-        if (track_screenshot_id != 0)
-            App.app.sidebar.screenshot_placeholder.disconnect (track_screenshot_id);
-    }
-
-    public MachineActor (Machine machine) {
-        this.machine = machine;
-
-        var layout = new Clutter.BoxLayout ();
-        layout.orientation = Clutter.Orientation.VERTICAL;
-        layout.spacing = 10;
-        _actor = new Clutter.Actor ();
-        _actor.set_layout_manager (layout);
-
-        screenshot = new GtkClutter.Texture ();
-        screenshot.name = "screenshot";
-        set_screenshot (machine.pixbuf);
-        _actor.min_width = _actor.natural_width = Machine.SCREENSHOT_WIDTH;
-
-        screenshot.keep_aspect_ratio = true;
-        _actor.add (screenshot);
-
-        vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
-        gtk_vbox = new GtkClutter.Actor.with_contents (vbox);
-        // Ensure we have enough space to fit everything without changing
-        // size, as that causes weird re-animations
-        gtk_vbox.height = 80;
-
-        gtk_vbox.get_widget ().get_style_context ().add_class ("boxes-bg");
-
-        label = new Gtk.Label (machine.name);
-        label.get_style_context ().add_class ("boxes-machine-name-label");
-        machine.bind_property ("name", label, "label", BindingFlags.DEFAULT);
-        vbox.add (label);
-        vbox.set_valign (Gtk.Align.START);
-        password_entry = new Gtk.Entry ();
-        password_entry.set_visibility (false);
-        password_entry.set_placeholder_text (_("Password"));
-        set_password_needed (false);
-        password_entry.key_press_event.connect ((event) => {
-            if (event.keyval == Gdk.Key.KP_Enter ||
-                event.keyval == Gdk.Key.ISO_Enter ||
-                event.keyval == Gdk.Key.Return) {
-                machine.connect_display.begin (Machine.ConnectFlags.NONE);
+        switch (ui_state) {
+        case UIState.CREDS:
+            if (!(display.need_username || display.need_password)) {
+                App.app.set_state (UIState.DISPLAY);
 
-                return true;
+                break;
             }
 
-            return false;
-        });
-        vbox.add (password_entry);
-
-        vbox.show_all ();
-        password_entry.hide ();
-
-        _actor.add (gtk_vbox);
-        _actor.set_reactive (true);
-
-        notify["ui-state"].connect (ui_state_changed);
-    }
-
-    public void set_screenshot (Gdk.Pixbuf pixbuf) {
-        try {
-            screenshot.set_from_pixbuf (pixbuf);
-            if (thumbnail_screenshot != null)
-                thumbnail_screenshot.set_from_pixbuf (pixbuf);
-        } catch (GLib.Error err) {
-            warning (err.message);
-        }
-    }
-
-    public void set_password_needed (bool needed) {
-        _actor.queue_relayout ();
-        password_entry.visible = needed;
-        password_entry.set_can_focus (needed);
-        if (needed) {
-            password_entry.grab_focus ();
-            machine.display = null;
-        }
-    }
-
-    public void set_username_needed (bool needed) {
-        debug ("FIXME: Do something about fetching username when required?");
-        if (needed)
-            machine.display = null;
-    }
-
-    public string get_password () {
-        return password_entry.text;
-    }
-
-    private Widget? steal_display_widget_from_thumbnail () {
-        Widget? widget = null;
-        if (thumbnail is GtkClutter.Actor) {
-            widget = (thumbnail as GtkClutter.Actor).contents;
-            (thumbnail as GtkClutter.Actor).contents = null;
-        }
-        thumbnail.destroy ();
-        thumbnail = null;
-        thumbnail_screenshot = null;
-        if (widget != null) {
-            // FIXME: enable grabs
-            machine.display.set_enable_inputs (widget, true);
-        }
-        return widget;
-    }
-
-    public void update_thumbnail (Gtk.Widget? display_widget, bool zoom = true) {
-        if (track_screenshot_id != 0)
-            App.app.sidebar.screenshot_placeholder.disconnect (track_screenshot_id);
-        track_screenshot_id = 0;
+            AuthNotification.AuthFunc auth_func = (username, password) => {
+                this.username = username;
+                this.password = password;
 
-        if (thumbnail != null) {
-            actor_remove (thumbnail);
-            thumbnail.destroy ();
-            thumbnail = null;
-            thumbnail_screenshot = null;
-        }
-
-        if (ui_state == UIState.PROPERTIES) {
-            if (display_widget != null) {
-                thumbnail = new GtkClutter.Actor.with_contents (display_widget);
-            } else {
-                thumbnail_screenshot = new GtkClutter.Texture ();
-                thumbnail_screenshot.set_reactive (true);
-
-                Gdk.Pixbuf pixbuf = null;
-                if (previous_ui_state == UIState.WIZARD) {
-                    var theme = Gtk.IconTheme.get_for_screen (App.app.window.get_screen ());
-                    pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.RGB, true, 8,
-                                             Machine.SCREENSHOT_WIDTH, Machine.SCREENSHOT_HEIGHT);
-                    pixbuf.fill (0x00000000); // Transparent
-                    try {
-                        var icon = theme.load_icon ("media-optical", Machine.SCREENSHOT_HEIGHT, 0);
-                        // Center icon in pixbuf
-                        icon.copy_area (0, 0, Machine.SCREENSHOT_HEIGHT, Machine.SCREENSHOT_HEIGHT, pixbuf,
-                                        (Machine.SCREENSHOT_WIDTH - Machine.SCREENSHOT_HEIGHT) / 2, 0);
-                    } catch (GLib.Error err) {
-                        warning (err.message);
-                    }
-                } else {
-                    pixbuf = machine.pixbuf;
-                }
-                try {
-                    thumbnail_screenshot.set_from_pixbuf (pixbuf);
-                } catch (GLib.Error err) {
-                    warning (err.message);
-                }
-                thumbnail = thumbnail_screenshot;
-            }
-            thumbnail.name = "properties-thumbnail";
-            thumbnail.x_align = Clutter.ActorAlign.FILL;
-            thumbnail.y_align = Clutter.ActorAlign.FILL;
-            App.app.overlay_bin_actor.add_child (thumbnail);
-
-            var click = new Clutter.ClickAction ();
-            thumbnail.add_action (click);
-
-            if (display_widget != null) {
-                click.clicked.connect (() => {
-                    App.app.set_state (Boxes.UIState.DISPLAY);
-                });
-
-                machine.display.set_enable_inputs (display_widget, false);
-            } else if (previous_ui_state != UIState.WIZARD) {
-                click.clicked.connect (() => {
-                    App.app.connect_to (machine, thumbnail.allocation.x1, thumbnail.allocation.y1);
-                    update_thumbnail (null, false);
-                });
-            }
-
-            Boxes.ActorFunc update_screenshot_alloc = (thumbnail) => {
-                Gtk.Allocation alloc;
-
-                App.app.sidebar.screenshot_placeholder.get_allocation (out alloc);
-
-                // We disable implicit animations while setting the
-                // properties because we don't want to animate these individually
-                // we just want them to change instantly, causing a relayout
-                // and recalculation of the allocation rect, which will then
-                // be animated. Animating a rectangle between two states and
-                // animating position and size individually looks completely
-                // different.
-                var d = thumbnail.get_easing_duration ();
-                thumbnail.set_easing_duration (0);
-                thumbnail.fixed_x = alloc.x;
-                thumbnail.fixed_y = alloc.y;
-                thumbnail.min_width = thumbnail.natural_width = alloc.width;
-                thumbnail.min_height = thumbnail.natural_height = alloc.height;
-                thumbnail.set_easing_duration (d);
+                App.app.set_state (UIState.DISPLAY);
+            };
+            Notification.CancelFunc cancel_func = () => {
+                App.app.set_state (UIState.COLLECTION);
             };
 
-            track_screenshot_id = App.app.sidebar.screenshot_placeholder.size_allocate.connect (() => {
-                // We need to update in an idle to avoid changing layout stuff in a layout cycle
-                // (i.e. inside the size_allocate)
-                Idle.add_full (Priority.HIGH, () => {
-                    update_screenshot_alloc (thumbnail);
-                    return false;
-                });
-            });
-
-            if (!zoom)
-                thumbnail.set_easing_duration (0);
-            update_screenshot_alloc (thumbnail);
-        }
-    }
-
-    private void ui_state_changed () {
-        int window_width, window_height;
-        int width, height;
-        int x, y;
-
-        App.app.display_page.get_size (out width, out height);
-        App.app.window.get_size (out window_width, out window_height);
-        x = window_width - width;
-        y = window_height - height;
+            // Translators: %s => name of launched box
+            var auth_string = _("'%s' requires authentication").printf (name);
+            App.app.notificationbar.display_for_auth (auth_string, (owned) auth_func, (owned) cancel_func);
 
-        switch (ui_state) {
-        case UIState.CREDS:
-            actor.x_align = Clutter.ActorAlign.CENTER;
-            actor.y_align = Clutter.ActorAlign.CENTER;
-            actor.x_expand = true;
-            actor.y_expand = true;
-            gtk_vbox.show ();
             break;
 
         case UIState.DISPLAY:
-            gtk_vbox.hide ();
-            if (previous_ui_state == UIState.CREDS) {
-                actor.x_align = Clutter.ActorAlign.FILL;
-                actor.y_align = Clutter.ActorAlign.FILL;
-                actor.x_expand = true;
-                actor.y_expand = true;
-                actor.natural_width_set = false;
-                actor.natural_height_set = false;
-            } else {
-                if (thumbnail != null) {
-                    // zoom in, back from properties
-
-                    App.app.sidebar.screenshot_placeholder.disconnect (track_screenshot_id);
-                    track_screenshot_id = 0;
-
-                    var transition = animate_actor_geometry (x, y, width, height);
-                    transition.completed.connect (() => {
-                        thumbnail.remove_transition ("back-from-properties");
-                        var widget = steal_display_widget_from_thumbnail ();
-                        if (widget != null)
-                            App.app.display_page.show_display (machine.display, widget);
-                    });
-
-                    thumbnail.add_transition ("back-from-properties", transition);
-                } else
-                    App.app.notebook.page = Boxes.AppPage.DISPLAY;
-            }
-            break;
+            try_connect_display.begin ();
 
-        case UIState.COLLECTION:
-            actor.x_expand = false;
-            actor.y_expand = false;
-            password_entry.set_can_focus (false);
-            password_entry.hide ();
-            label.show ();
             break;
 
-        case UIState.PROPERTIES:
-            var display_widget = App.app.display_page.remove_display ();
-            var zoom = display_widget != null;
-
-            update_thumbnail (display_widget, zoom);
-
-
-            if (zoom) {
-                allocate_actor_no_animation (thumbnail, 0, 0, width, height);
-
-                thumbnail.set_easing_mode (Clutter.AnimationMode.LINEAR);
-                thumbnail.set_easing_duration (App.app.duration);
-                ulong completed_id = 0;
-                completed_id = thumbnail.transitions_completed.connect (() => {
-                    thumbnail.disconnect (completed_id);
-                    thumbnail.set_easing_duration (0);
-                });
-            }
-
-            thumbnail.show ();
+        case UIState.COLLECTION:
+            disconnect_display ();
 
             break;
+        }
+    }
 
-        default:
-            break;
+    private async void try_connect_display (ConnectFlags flags = ConnectFlags.NONE) {
+        try {
+            yield connect_display (flags);
+
+            if (App.app.maximized)
+                App.app.fullscreen = true;
+        } catch (Boxes.Error.RESTORE_FAILED e) {
+            var message = _("'%s' could not be restored from disk\nTry without saved state?").printf (name);
+            var notification = App.app.notificationbar.display_for_action (message, _("Restart"), () => {
+                try_connect_display.begin (flags | Machine.ConnectFlags.IGNORE_SAVED_STATE);
+            });
+            notification.dismissed.connect (() => {
+                App.app.set_state (UIState.COLLECTION);
+            });
+        } catch (GLib.Error e) {
+            debug ("connect display failed: %s", e.message);
+            App.app.set_state (UIState.COLLECTION);
+            App.app.notificationbar.display_error (_("Connection to '%s' failed").printf (name));
         }
     }
+
+    public override int compare (CollectionItem other) {
+        if (other is Machine)
+            return config.compare ((other as Machine).config);
+        else
+            return -1; // Machines are listed before non-machines
+    }
 }
diff --git a/src/sidebar.vala b/src/sidebar.vala
index c916ae2..681621b 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -31,7 +31,7 @@ private class Boxes.Sidebar: Gtk.Notebook, Boxes.UI {
     private Gtk.Label wizard_review_label;
 
     [GtkChild]
-    public Gtk.Widget screenshot_placeholder;
+    public Gtk.Box screenshot_placeholder;
     [GtkChild]
     public Gtk.ListStore props_listmodel;
     [GtkChild]
diff --git a/src/util-app.vala b/src/util-app.vala
index 80139cf..731004a 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -169,6 +169,15 @@ namespace Boxes {
         container.remove_child (actor);
     }
 
+    public void widget_remove (Gtk.Widget widget) {
+        var container = widget.get_parent () as Gtk.Container;
+
+        if (container == null)
+            return;
+
+        container.remove (widget);
+    }
+
     public Osinfo.Device? find_device_by_prop (Osinfo.DeviceList devices, string prop_name, string 
prop_value) {
         var filter = new Osinfo.Filter ();
         filter.add_constraint (prop_name, prop_value);


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