[gnome-boxes] Break out machine connection into App.connect_to
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Break out machine connection into App.connect_to
- Date: Fri, 2 Nov 2012 13:11:52 +0000 (UTC)
commit ec26d545e2ab2339abed2c92a098b03b6a6654c2
Author: Alexander Larsson <alexl redhat com>
Date: Wed Oct 31 13:37:37 2012 +0100
Break out machine connection into App.connect_to
This merges all the code that handles connection and going into
the CREDS state into a single function instead of being distributed
into App.select_item() and CollectionView UIState.CREDS handling.
This allows connecting to a machine without the collection view being
involved (such as when starting a box from the properties page).
It also moves the place where we collect the actor animation start
position to App.select_item() so that we can use a different start
in other cases.
https://bugzilla.gnome.org/show_bug.cgi?id=677714
src/app.vala | 58 +++++++++++++++++++++++++++++++++++----------
src/collection-view.vala | 19 +--------------
2 files changed, 46 insertions(+), 31 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 9991284..648ecec 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -712,6 +712,47 @@ private class Boxes.App: Boxes.UI {
return false;
}
+ public void connect_to (Machine machine, float x, float y) {
+ 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);
+ actor.set_easing_duration (0);
+
+ Clutter.ActorBox box = { x, y, x + Machine.SCREENSHOT_WIDTH, y + Machine.SCREENSHOT_HEIGHT * 2};
+ actor.allocate (box, 0);
+ }
+ 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.x_align = Clutter.ActorAlign.CENTER;
+ actor.y_align = Clutter.ActorAlign.CENTER;
+ actor.set_easing_duration (App.app.duration);
+
+ // Track machine status in toobar
+ topbar.set_status (machine.status);
+ status_id = machine.notify["status"].connect ( () => {
+ topbar.set_status (machine.status);
+ });
+
+ // Connect to the display
+ machine.connect_display.begin ( (obj, res) => {
+ try {
+ machine.connect_display.end (res);
+ } catch (GLib.Error e) {
+ ui_state = UIState.COLLECTION;
+ App.app.notificationbar.display_error (_("Connection to '%s' failed").printf (machine.name));
+ debug ("connect display failed: %s", e.message);
+ }
+ });
+
+ // Start the CREDS state
+ ui_state = UIState.CREDS;
+ }
+
public void select_item (CollectionItem item) {
if (ui_state == UIState.COLLECTION && !selection_mode) {
current_item = item;
@@ -719,19 +760,10 @@ private class Boxes.App: Boxes.UI {
if (current_item is Machine) {
var machine = current_item as Machine;
- status_id = machine.notify["status"].connect ( () => {
- topbar.set_status (machine.status);
- });
- machine.connect_display.begin ( (obj, res) => {
- try {
- machine.connect_display.end (res);
- } catch (GLib.Error e) {
- ui_state = UIState.COLLECTION;
- App.app.notificationbar.display_error (_("Connection to '%s' failed").printf (machine.name));
- debug ("connect display failed: %s", e.message);
- }
- });
- ui_state = UIState.CREDS;
+ float item_x, item_y;
+ view.get_item_pos (item, out item_x, out item_y);
+
+ connect_to (machine, item_x, item_y);
} else
warning ("unknown item, fix your code");
diff --git a/src/collection-view.vala b/src/collection-view.vala
index 70ba7f3..0cd8645 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -51,7 +51,7 @@ private class Boxes.CollectionView: Boxes.UI {
});
}
- private void get_item_pos (CollectionItem item, out float x, out float y) {
+ 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) {
@@ -104,23 +104,6 @@ private class Boxes.CollectionView: Boxes.UI {
break;
case UIState.CREDS:
- var actor = current_item.actor;
- if (actor.get_parent () == null) {
- App.app.overlay_bin_actor.add_child (actor);
- actor.set_easing_mode (Clutter.AnimationMode.LINEAR);
- actor.set_easing_duration (0);
-
- float item_x, item_y;
- get_item_pos (current_item, out item_x, out item_y);
- Clutter.ActorBox box = { item_x, item_y, item_x + Machine.SCREENSHOT_WIDTH, item_y + Machine.SCREENSHOT_HEIGHT * 2};
- actor.allocate (box, 0);
-
- }
- actor.min_width = actor.natural_width = Machine.SCREENSHOT_WIDTH * 2;
- actor.fixed_position_set = false;
- actor.x_align = Clutter.ActorAlign.CENTER;
- actor.y_align = Clutter.ActorAlign.CENTER;
- actor.set_easing_duration (App.app.duration);
break;
case UIState.WIZARD:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]