[gnome-boxes] s/box/machine to avoid clash with Gtk and Clutter
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] s/box/machine to avoid clash with Gtk and Clutter
- Date: Thu, 6 Oct 2011 02:43:06 +0000 (UTC)
commit ca7c98bf9f57226a1bd9f49c7370719ae011728c
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Thu Oct 6 04:42:38 2011 +0200
s/box/machine to avoid clash with Gtk and Clutter
src/Makefile.am | 2 +-
src/app.vala | 39 ++++++++++++++------------
src/collection-view.vala | 53 ++++++++++++++++++-----------------
src/collection.vala | 4 +-
src/display.vala | 2 +-
src/{box.vala => machine.vala} | 60 +++++++++++++++++----------------------
src/sidebar.vala | 9 +++--
src/topbar.vala | 11 ++++---
src/util.vala | 4 ++
9 files changed, 93 insertions(+), 91 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 60334b4..6c9a423 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,10 +24,10 @@ bin_PROGRAMS = gnome-boxes
gnome_boxes_SOURCES = \
app.vala \
- box.vala \
collection-view.vala \
collection.vala \
display.vala \
+ machine.vala \
main.vala \
sidebar.vala \
spice-display.vala \
diff --git a/src/app.vala b/src/app.vala
index 6271948..a234b89 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -19,12 +19,13 @@ private errordomain Boxes.Error {
}
private class Boxes.App: Boxes.UI {
+ public override Clutter.Actor actor { get { return stage; } }
public Gtk.Window window;
public GtkClutter.Embed embed;
- public Stage stage;
+ public Clutter.Stage stage;
public Clutter.State state;
public Clutter.Box box; // the whole app box
- public Box selected_box; // currently selected box
+ public CollectionItem current_item; // current object/vm manipulated
public GVir.Connection connection;
public static const uint duration = 555; // default to 1/2 for all transitions
@@ -39,12 +40,10 @@ private class Boxes.App: Boxes.UI {
collection = new Collection ();
collection.item_added.connect ((item) => {
- if (item is Box) {
- var box = item as Box;
- var actor = box.get_clutter_actor ();
- actor.set_reactive (true);
- actor.button_press_event.connect ((actor, event) => { return box_clicked (box, event); });
- }
+ item.actor.set_reactive (true);
+ item.actor.button_press_event.connect ((actor, event) => {
+ return item_clicked (item, event);
+ });
view.add_item (item);
});
@@ -67,8 +66,8 @@ private class Boxes.App: Boxes.UI {
}
foreach (var domain in connection.get_domains ()) {
- var box = new Box (this, domain);
- collection.add_item (box);
+ var machine = new Machine (this, domain);
+ collection.add_item (machine);
}
}
@@ -110,7 +109,7 @@ private class Boxes.App: Boxes.UI {
public void go_back () {
ui_state = UIState.COLLECTION;
- selected_box = null;
+ current_item = null;
}
public override void ui_state_changed () {
@@ -160,11 +159,18 @@ private class Boxes.App: Boxes.UI {
return false;
}
- private bool box_clicked (Box box, Clutter.ButtonEvent event) {
+ private bool item_clicked (CollectionItem item, Clutter.ButtonEvent event) {
if (ui_state == UIState.COLLECTION) {
- selected_box = box;
- if (selected_box.connect_display ())
+ current_item = item;
+
+ if (current_item is Machine) {
+ var machine = current_item as Machine;
+
+ machine.connect_display ();
ui_state = UIState.CREDS;
+
+ } else
+ warning ("unknown item, fix your code");
}
return false;
@@ -172,6 +178,7 @@ private class Boxes.App: Boxes.UI {
}
private abstract class Boxes.UI: GLib.Object {
+ public abstract Clutter.Actor actor { get; }
public UIState ui_state { get; set; }
public UI () {
@@ -180,9 +187,5 @@ private abstract class Boxes.UI: GLib.Object {
});
}
- public void pin_actor (Clutter.Actor actor) {
- actor.set_geometry (actor.get_geometry ());
- }
-
public abstract void ui_state_changed ();
}
diff --git a/src/collection-view.vala b/src/collection-view.vala
index db439ce..f2c3287 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -2,9 +2,10 @@
using Clutter;
private class Boxes.CollectionView: Boxes.UI {
- private App app;
+ public override Clutter.Actor actor { get { return group; } }
- private Clutter.Group actor; // the surrounding actor, for the margin
+ private App app;
+ private Clutter.Group group; // the surrounding actor, for the margin
private Clutter.Box boxes; // the boxes list box
private Clutter.FlowLayout layout;
private Clutter.Box top_box; // a box on top of boxes list
@@ -17,10 +18,10 @@ private class Boxes.CollectionView: Boxes.UI {
public override void ui_state_changed () {
switch (ui_state) {
case UIState.CREDS:
- remove_item (app.selected_box);
- app.selected_box.actor.ui_state = UIState.CREDS;
+ remove_item (app.current_item);
+ app.current_item.ui_state = UIState.CREDS;
- top_box.pack (app.selected_box.get_clutter_actor (),
+ top_box.pack (app.current_item.actor,
"x-align", Clutter.BinAlignment.CENTER,
"y-align", Clutter.BinAlignment.CENTER);
@@ -30,7 +31,7 @@ private class Boxes.CollectionView: Boxes.UI {
case UIState.DISPLAY: {
float x, y;
- var actor = app.selected_box.get_clutter_actor ();
+ var actor = app.current_item.actor;
/* move box actor to stage */
actor.get_transformed_position (out x, out y);
@@ -40,7 +41,7 @@ private class Boxes.CollectionView: Boxes.UI {
app.stage.add_actor (actor);
actor.set_position (x, y);
- app.selected_box.actor.ui_state = UIState.DISPLAY;
+ app.current_item.ui_state = UIState.DISPLAY;
break;
}
@@ -48,13 +49,13 @@ private class Boxes.CollectionView: Boxes.UI {
case UIState.COLLECTION:
boxes.set_layout_manager (layout);
- if (app.selected_box == null)
+ if (app.current_item == null)
break;
- var actor = app.selected_box.get_clutter_actor ();
+ var actor = app.current_item.actor;
if (actor.get_parent () == top_box)
top_box.remove_actor (actor);
- add_item (app.selected_box);
+ add_item (app.current_item);
break;
@@ -64,19 +65,19 @@ private class Boxes.CollectionView: Boxes.UI {
}
public void add_item (CollectionItem item) {
- if (item is Box) {
- var box = item as Box;
+ if (item is Machine) {
+ var machine = item as Machine;
- box.actor.ui_state = UIState.COLLECTION;
- actor_add (box.get_clutter_actor (), boxes);
+ machine.machine_actor.ui_state = UIState.COLLECTION;
+ actor_add (machine.actor, boxes);
} else
warning ("Cannot add item %p".printf (&item));
}
public void remove_item (CollectionItem item) {
- if (item is Box) {
- var box = item as Box;
- var actor = box.get_clutter_actor ();
+ if (item is Machine) {
+ var machine = item as Machine;
+ var actor = machine.actor;
if (actor.get_parent () == boxes)
boxes.remove_actor (actor); // FIXME: why Clutter warn here??!
} else
@@ -85,29 +86,29 @@ private class Boxes.CollectionView: Boxes.UI {
private void setup_view () {
layout = new Clutter.FlowLayout (Clutter.FlowOrientation.HORIZONTAL);
- actor = new Clutter.Group ();
+ group = new Clutter.Group ();
boxes = new Clutter.Box (layout);
layout.set_column_spacing (35);
layout.set_row_spacing (25);
- actor.add (boxes);
- app.box.pack (actor, "column", 1, "row", 1, "x-expand", true, "y-expand", true);
+ group.add (boxes);
+ app.box.pack (group, "column", 1, "row", 1, "x-expand", true, "y-expand", true);
boxes.set_position (15f, 15f);
boxes.add_constraint_with_name ("boxes-width",
- new Clutter.BindConstraint (actor, BindCoordinate.WIDTH, -25f));
+ new Clutter.BindConstraint (group, BindCoordinate.WIDTH, -25f));
boxes.add_constraint_with_name ("boxes-height",
- new Clutter.BindConstraint (actor, BindCoordinate.HEIGHT, -25f));
+ new Clutter.BindConstraint (group, BindCoordinate.HEIGHT, -25f));
// FIXME! report bug to clutter about flow inside table
- actor.add_constraint_with_name ("boxes-left",
+ group.add_constraint_with_name ("boxes-left",
new Clutter.SnapConstraint (app.stage, SnapEdge.RIGHT, SnapEdge.RIGHT, 0));
- actor.add_constraint_with_name ("boxes-bottom",
+ group.add_constraint_with_name ("boxes-bottom",
new Clutter.SnapConstraint (app.stage, SnapEdge.BOTTOM, SnapEdge.RIGHT.BOTTOM, 0));
top_box = new Clutter.Box (new Clutter.BinLayout (Clutter.BinAlignment.FILL, Clutter.BinAlignment.FILL));
top_box.add_constraint_with_name ("top-box-size",
- new Clutter.BindConstraint (actor, BindCoordinate.SIZE, 0));
+ new Clutter.BindConstraint (group, BindCoordinate.SIZE, 0));
top_box.add_constraint_with_name ("top-box-position",
- new Clutter.BindConstraint (actor, BindCoordinate.POSITION, 0));
+ new Clutter.BindConstraint (group, BindCoordinate.POSITION, 0));
app.stage.add_actor (top_box);
app.state.set_key (null, "creds", boxes, "opacity", AnimationMode.EASE_OUT_QUAD, (uint) 0, 0, 0);
diff --git a/src/collection.vala b/src/collection.vala
index c8a3a8b..3e177e0 100644
--- a/src/collection.vala
+++ b/src/collection.vala
@@ -1,6 +1,6 @@
// This file is part of GNOME Boxes. License: LGPLv2
-private class Boxes.CollectionItem: GLib.Object {
+private abstract class Boxes.CollectionItem: Boxes.UI {
public string name;
}
@@ -9,7 +9,7 @@ private class Boxes.Collection: GLib.Object {
GenericArray<CollectionItem> items;
- public Collection () {
+ construct {
items = new GenericArray<CollectionItem> ();
}
diff --git a/src/display.vala b/src/display.vala
index 3fbcc99..4a05fa1 100644
--- a/src/display.vala
+++ b/src/display.vala
@@ -11,7 +11,7 @@ private abstract class Boxes.Display: GLib.Object {
public abstract void connect_it ();
public abstract void disconnect_it ();
- public override void constructed () {
+ construct {
displays = new HashTable<int, Gtk.Widget> (direct_hash, direct_equal);
}
diff --git a/src/box.vala b/src/machine.vala
similarity index 87%
rename from src/box.vala
rename to src/machine.vala
index 6dcccbb..112da4a 100644
--- a/src/box.vala
+++ b/src/machine.vala
@@ -4,9 +4,11 @@ using Gdk;
using Gtk;
using GVir;
-private class Boxes.Box: Boxes.CollectionItem {
+private class Boxes.Machine: Boxes.CollectionItem {
+ public override Clutter.Actor actor { get { return machine_actor.actor; } }
public Boxes.App app;
- public BoxActor actor;
+ public MachineActor machine_actor;
+ public GVir.Domain domain;
public DomainState state {
get {
try {
@@ -17,22 +19,14 @@ private class Boxes.Box: Boxes.CollectionItem {
}
}
- private GVir.Domain _domain;
- public GVir.Domain domain {
- get { return _domain; }
- construct set {
- _domain = value;
- }
- }
-
private Display display;
- public Box (Boxes.App app, GVir.Domain domain) {
- Object (domain: domain);
+ public Machine (Boxes.App app, GVir.Domain domain) {
+ this.domain = domain;
this.app = app;
name = domain.get_name ();
- actor = new BoxActor (this);
+ machine_actor = new MachineActor (this);
update_screenshot.begin ();
Timeout.add_seconds (5, () => {
@@ -43,11 +37,11 @@ private class Boxes.Box: Boxes.CollectionItem {
app.state.completed.connect ( () => {
if (app.state.state == "display") {
- if (app.selected_box != this)
+ if (app.current_item != this)
return;
try {
- actor.show_display (display.get_display (0));
+ machine_actor.show_display (display.get_display (0));
} catch (Boxes.Error error) {
warning (error.message);
}
@@ -55,10 +49,6 @@ private class Boxes.Box: Boxes.CollectionItem {
});
}
- public Clutter.Actor get_clutter_actor () {
- return actor.actor;
- }
-
public async bool take_screenshot () throws GLib.Error {
if (state != DomainState.RUNNING &&
state != DomainState.PAUSED)
@@ -113,7 +103,7 @@ private class Boxes.Box: Boxes.CollectionItem {
pixbuf = draw_fallback_vm (128, 96);
try {
- actor.set_screenshot (pixbuf);
+ machine_actor.set_screenshot (pixbuf);
} catch (GLib.Error err) {
warning (err.message);
}
@@ -182,10 +172,15 @@ private class Boxes.Box: Boxes.CollectionItem {
app.ui_state = Boxes.UIState.COLLECTION;
});
}
+
+ public override void ui_state_changed () {
+ machine_actor.ui_state = ui_state;
+ }
}
-private class Boxes.BoxActor: Boxes.UI {
- public Clutter.Box actor;
+private class Boxes.MachineActor: Boxes.UI {
+ public override Clutter.Actor actor { get { return box; } }
+ public Clutter.Box box;
private GtkClutter.Texture screenshot;
private GtkClutter.Actor gtkactor;
@@ -193,25 +188,25 @@ private class Boxes.BoxActor: Boxes.UI {
private Gtk.VBox vbox; // and the vbox under it
private Gtk.Entry entry;
private Gtk.Widget? display;
- private Box box;
+ private Machine machine;
- public BoxActor (Box box) {
- this.box = box;
+ public MachineActor (Machine machine) {
+ this.machine = machine;
var layout = new Clutter.BoxLayout ();
layout.vertical = true;
- var cbox = new Clutter.Box (layout);
+ box = new Clutter.Box (layout);
screenshot = new GtkClutter.Texture ();
screenshot.name = "screenshot";
scale_screenshot ();
- actor_add (screenshot, cbox);
+ actor_add (screenshot, box);
screenshot.keep_aspect_ratio = true;
vbox = new Gtk.VBox (false, 0);
gtkactor = new GtkClutter.Actor.with_contents (vbox);
- label = new Gtk.Label (box.name);
+ label = new Gtk.Label (machine.name);
vbox.add (label);
entry = new Gtk.Entry ();
entry.set_visibility (false);
@@ -221,9 +216,7 @@ private class Boxes.BoxActor: Boxes.UI {
vbox.show_all ();
entry.hide ();
- actor_add (gtkactor, cbox);
-
- actor = cbox;
+ actor_add (gtkactor, box);
}
public void scale_screenshot (float scale = 1.5f) {
@@ -256,7 +249,7 @@ private class Boxes.BoxActor: Boxes.UI {
vbox.remove (display);
display = null;
- actor.pack_at (screenshot, 0);
+ box.pack_at (screenshot, 0);
}
public override void ui_state_changed () {
@@ -275,7 +268,7 @@ private class Boxes.BoxActor: Boxes.UI {
entry.hide ();
label.hide ();
- box.app.window.get_size (out width, out height);
+ machine.app.window.get_size (out width, out height);
screenshot.animate (Clutter.AnimationMode.LINEAR, Boxes.App.duration,
"width", (float) width,
"height", (float) height);
@@ -302,4 +295,3 @@ private class Boxes.BoxActor: Boxes.UI {
}
}
}
-
diff --git a/src/sidebar.vala b/src/sidebar.vala
index af71961..176d368 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -4,13 +4,14 @@ using Gdk;
using Clutter;
private class Boxes.Sidebar: Boxes.UI {
+ public override Clutter.Actor actor { get { return gtk_actor; } }
public Notebook notebook;
public TreeView tree_view;
private App app;
private uint width;
- private Clutter.Actor actor; // the sidebar box
+ private GtkClutter.Actor gtk_actor; // the sidebar box
private bool selection_func (Gtk.TreeSelection selection,
Gtk.TreeModel model,
@@ -82,8 +83,8 @@ private class Boxes.Sidebar: Boxes.UI {
notebook.show_tabs = false;
notebook.show_all ();
- actor = new GtkClutter.Actor.with_contents (notebook);
- app.box.pack (actor, "column", 0, "row", 1, "x-expand", false, "y-expand", true);
+ gtk_actor = new GtkClutter.Actor.with_contents (notebook);
+ app.box.pack (gtk_actor, "column", 0, "row", 1, "x-expand", false, "y-expand", true);
var listmodel = new ListStore (5,
typeof (string),
@@ -118,6 +119,6 @@ private class Boxes.Sidebar: Boxes.UI {
create.show ();
// FIXME: make it dynamic depending on sidebar size..:
- app.state.set_key (null, "display", actor, "x", AnimationMode.EASE_OUT_QUAD, -(float) width, 0, 0);
+ app.state.set_key (null, "display", gtk_actor, "x", AnimationMode.EASE_OUT_QUAD, -(float) width, 0, 0);
}
}
diff --git a/src/topbar.vala b/src/topbar.vala
index 32bbe8b..3fa5ed6 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -3,13 +3,14 @@ using Clutter;
using Gtk;
private class Boxes.Topbar: Boxes.UI {
+ public override Clutter.Actor actor { get { return gtk_actor; } }
public Widget corner;
public Gtk.Label label;
private App app;
private uint height;
- private Actor actor; // the topbar box
+ private GtkClutter.Actor gtk_actor; // the topbar box
private Notebook notebook;
private HBox hbox;
@@ -26,8 +27,8 @@ private class Boxes.Topbar: Boxes.UI {
private void setup_topbar () {
notebook = new Gtk.Notebook ();
notebook.set_size_request (50, (int) height);
- actor = new GtkClutter.Actor.with_contents (notebook);
- app.box.pack (actor,
+ gtk_actor = new GtkClutter.Actor.with_contents (notebook);
+ app.box.pack (gtk_actor,
"column", 0,
"row", 0,
"column-span", 2,
@@ -74,7 +75,7 @@ private class Boxes.Topbar: Boxes.UI {
notebook.show_all ();
// FIXME: make it dynamic depending on topbar size..:
- app.state.set_key (null, "display", actor, "y", AnimationMode.EASE_OUT_QUAD, -(float) height, 0, 0);
+ app.state.set_key (null, "display", gtk_actor, "y", AnimationMode.EASE_OUT_QUAD, -(float) height, 0, 0);
}
public override void ui_state_changed () {
@@ -90,7 +91,7 @@ private class Boxes.Topbar: Boxes.UI {
break;
case UIState.DISPLAY:
- pin_actor (actor);
+ pin_actor (gtk_actor);
break;
default:
diff --git a/src/util.vala b/src/util.vala
index cb7c9ee..2744d5e 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -100,4 +100,8 @@ namespace Boxes {
container.remove (actor);
}
+
+ private void pin_actor (Clutter.Actor actor) {
+ actor.set_geometry (actor.get_geometry ());
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]