[gnome-boxes] First round of big clean-ups of the whole source tree
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] First round of big clean-ups of the whole source tree
- Date: Tue, 4 Oct 2011 19:53:30 +0000 (UTC)
commit e8cfd77600793e1634b69bd967674cdb6000255b
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Oct 4 22:52:44 2011 +0300
First round of big clean-ups of the whole source tree
src/box.vala | 370 ++++++++++++++++++++++++----------------------
src/boxes.vala | 252 ++++++++++++++++----------------
src/collection-view.vala | 175 ++++++++++++----------
src/collection.vala | 16 +-
src/sidebar.vala | 165 +++++++++++---------
src/spice-display.vala | 52 ++++----
src/topbar.vala | 122 +++++++++-------
src/util.vala | 76 +++++-----
8 files changed, 648 insertions(+), 580 deletions(-)
---
diff --git a/src/box.vala b/src/box.vala
index 77ca7b5..90e86b5 100644
--- a/src/box.vala
+++ b/src/box.vala
@@ -5,17 +5,20 @@ using Gtk;
using GVir;
abstract class Boxes.Display: GLib.Object {
-// public bool need_password = false;
- protected HashTable<int, Gtk.Widget?> displays = new HashTable<int, Gtk.Widget> (direct_hash, direct_equal);
+ protected HashTable<int, Gtk.Widget?> displays;
- public signal void show (int displayid);
- public signal void hide (int displayid);
+ public signal void show (int display_id);
+ public signal void hide (int display_id);
public signal void disconnected ();
public abstract Gtk.Widget get_display (int n) throws Boxes.Error;
public abstract void connect_it ();
public abstract void disconnect_it ();
+ public override void constructed () {
+ this.displays = new HashTable<int, Gtk.Widget> (direct_hash, direct_equal);
+ }
+
~Boxes() {
disconnect_it ();
}
@@ -24,189 +27,197 @@ abstract class Boxes.Display: GLib.Object {
class Boxes.Box: Boxes.CollectionItem {
public Boxes.App app;
public BoxActor actor;
- public DomainState state { get {
+ public DomainState state {
+ get {
try {
- return domain.get_info ().state;
- } catch (GLib.Error e) {
+ return this.domain.get_info ().state;
+ } catch (GLib.Error error) {
return DomainState.NONE;
}
}
}
- Display? display;
-
- GVir.Domain _domain;
+ private GVir.Domain _domain;
public GVir.Domain domain {
- get { return _domain; }
+ get { return this._domain; }
construct set {
this._domain = value;
}
}
+ private Display? display;
+
public Box (Boxes.App app, GVir.Domain domain) {
Object (domain: domain);
this.app = app;
- name = domain.get_name ();
- actor = new BoxActor (this);
+ this.name = domain.get_name ();
+ this.actor = new BoxActor (this);
- update_screenshot.begin ();
+ this.update_screenshot.begin ();
Timeout.add_seconds (5, () => {
- update_screenshot.begin ();
- return true;
- });
-
- app.cstate.completed.connect ( () => {
- if (app.cstate.state == "display") {
- if (app.box != this)
- return;
-
- try {
- actor.show_display (display.get_display (0));
- } catch (Boxes.Error e) {
- warning (e.message);
- }
+ this.update_screenshot.begin ();
+
+ return true;
+ });
+
+ app.state.completed.connect ( () => {
+ if (app.state.state == "display") {
+ if (app.selected_box != this)
+ return;
+
+ try {
+ this.actor.show_display (this.display.get_display (0));
+ } catch (Boxes.Error error) {
+ warning (error.message);
}
- });
+ }
+ });
}
public Clutter.Actor get_clutter_actor () {
- return actor.actor;
+ return this.actor.actor;
+ }
+
+ public async bool take_screenshot () throws GLib.Error {
+ if (this.state != DomainState.RUNNING &&
+ this.state != DomainState.PAUSED)
+ return false;
+
+ var stream = this.app.connection.get_stream (0);
+ var file_name = this.get_screenshot_filename ();
+ var file = File.new_for_path (file_name);
+ var output_stream = yield file.replace_async (null, false, FileCreateFlags.REPLACE_DESTINATION);
+ var input_stream = stream.get_input_stream ();
+ this.domain.screenshot (stream, 0, 0);
+
+ var buffer = new uint8[65535];
+ ssize_t length = 0;
+ do {
+ length = yield input_stream.read_async (buffer);
+ yield output_stream_write (output_stream, buffer[0:length]);
+ } while (length > 0);
+
+ return true;
+ }
+
+ public bool connect_display () {
+ this.update_display ();
+
+ if (this.display == null)
+ return false;
+
+ this.display.connect_it ();
+
+ return true;
}
private string get_screenshot_filename (string ext = "ppm") {
- var uuid = domain.get_uuid ();
+ var uuid = this.domain.get_uuid ();
+
return get_pkgcache (uuid + "-screenshot." + ext);
}
private async void update_screenshot () {
- Gdk.Pixbuf? pix = null;
+ Gdk.Pixbuf? pixbuf = null;
try {
- yield take_screenshot ();
- pix = new Gdk.Pixbuf.from_file (get_screenshot_filename ());
- } catch (GLib.Error e) {
- if (!(e is FileError.NOENT))
- warning (e.message);
+ yield this.take_screenshot ();
+ pixbuf = new Gdk.Pixbuf.from_file (this.get_screenshot_filename ());
+ } catch (GLib.Error error) {
+ if (!(error is FileError.NOENT))
+ warning (error.message);
}
- if (pix == null)
- pix = draw_fallback_vm (128, 96);
+ if (pixbuf == null)
+ pixbuf = draw_fallback_vm (128, 96);
try {
- actor.set_screenshot (pix);
+ this.actor.set_screenshot (pixbuf);
} catch (GLib.Error err) {
warning (err.message);
}
}
- public async bool take_screenshot () throws GLib.Error {
-
- if (state != DomainState.RUNNING &&
- state != DomainState.PAUSED)
- return false;
-
- var st = app.conn.get_stream (0);
- var fname = get_screenshot_filename ();
- var file = File.new_for_path (fname);
- var o = yield file.replace_async (null, false, FileCreateFlags.REPLACE_DESTINATION);
- var i = st.get_input_stream ();
- domain.screenshot (st, 0, 0);
-
- var b = new uint8[65535];
- ssize_t l = 0;
- do {
- l = yield i.read_async (b);
- yield output_stream_write (o, b[0:l]);
- } while (l > 0);
-
- return true;
- }
-
- private static Gdk.Pixbuf draw_fallback_vm (int w, int h) {
+ private static Gdk.Pixbuf draw_fallback_vm (int width, int height) {
Gdk.Pixbuf pixbuf = null;
try {
- var cst = new Cairo.ImageSurface (Cairo.Format.ARGB32, w, h);
- var cr = new Cairo.Context (cst);
+ var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height);
+ var context = new Cairo.Context (surface);
- var pat = new Cairo.Pattern.linear (0, 0, 0, h);
- pat.add_color_stop_rgb (0, 0.260, 0.260, 0.260);
- pat.add_color_stop_rgb (1, 0.220, 0.220, 0.220);
+ var pattern = new Cairo.Pattern.linear (0, 0, 0, height);
+ pattern.add_color_stop_rgb (0, 0.260, 0.260, 0.260);
+ pattern.add_color_stop_rgb (1, 0.220, 0.220, 0.220);
- cr.set_source (pat);
- cr.paint ();
+ context.set_source (pattern);
+ context.paint ();
- int size = (int)(h * 0.5);
+ int size = (int) (height * 0.5);
var icon_info = IconTheme.get_default ().lookup_icon ("computer-symbolic", size,
IconLookupFlags.GENERIC_FALLBACK);
- Gdk.cairo_set_source_pixbuf (cr, icon_info.load_icon (),
- (w - size) / 2, (h - size) / 2);
- cr.rectangle ((w - size) / 2, (h - size) / 2, size, size);
- cr.fill ();
- pixbuf = Gdk.pixbuf_get_from_surface (cst, 0, 0, w, h);
+ Gdk.cairo_set_source_pixbuf (context, icon_info.load_icon (),
+ (width - size) / 2, (height - size) / 2);
+ context.rectangle ((width - size) / 2, (height - size) / 2, size, size);
+ context.fill ();
+ pixbuf = Gdk.pixbuf_get_from_surface (surface, 0, 0, width, height);
} catch {
}
if (pixbuf != null)
return pixbuf;
- var cst = new Cairo.ImageSurface (Cairo.Format.ARGB32, w, h);
- return Gdk.pixbuf_get_from_surface (cst, 0, 0, w, h);
- }
-
- public bool connect_display () {
- update_display ();
-
- if (display == null)
- return false;
-
- display.connect_it ();
- return true;
+ var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height);
+ return Gdk.pixbuf_get_from_surface (surface, 0, 0, width, height);
}
private void update_display () {
- string? type, gport, socket, ghost;
+ string type, gport, socket, ghost;
try {
- var xmldoc = domain.get_config (0).doc;
+ var xmldoc = this.domain.get_config (0).doc;
type = extract_xpath (xmldoc, "string(/domain/devices/graphics/@type)", true);
gport = extract_xpath (xmldoc, @"string(/domain/devices/graphics[ type='$type']/@port)");
socket = extract_xpath (xmldoc, @"string(/domain/devices/graphics[ type='$type']/@socket)");
ghost = extract_xpath (xmldoc, @"string(/domain/devices/graphics[ type='$type']/@listen)");
- } catch (GLib.Error e) {
- warning (e.message);
+ } catch (GLib.Error error) {
+ warning (error.message);
+
return;
}
if (type == "spice") {
- display = new SpiceDisplay (ghost, gport.to_int ());
+ this.display = new SpiceDisplay (ghost, gport.to_int ());
} else {
warning ("unsupported display of type " + type);
+
return;
}
- display.show.connect ( (id) => {
- app.ui_state = Boxes.UIState.DISPLAY;
- });
- display.disconnected.connect ( () => {
- app.ui_state = Boxes.UIState.COLLECTION;
- });
+ this.display.show.connect ((id) => {
+ this.app.ui_state = Boxes.UIState.DISPLAY;
+ });
+
+ this.display.disconnected.connect (() => {
+ this.app.ui_state = Boxes.UIState.COLLECTION;
+ });
}
}
class Boxes.BoxActor: Boxes.UI {
public Clutter.Box actor;
- GtkClutter.Texture screenshot;
- GtkClutter.Actor gtkactor;
- Gtk.Label label;
- Gtk.VBox vbox; // and the vbox under it
- Gtk.Entry entry;
- Gtk.Widget? display;
- Box box;
+ private GtkClutter.Texture screenshot;
+ private GtkClutter.Actor gtkactor;
+ private Gtk.Label label;
+ private Gtk.VBox vbox; // and the vbox under it
+ private Gtk.Entry entry;
+ private Gtk.Widget? display;
+ private Box box;
- ulong wrsid; ulong hrsid; // signal handlers
+ // signal handler IDs
+ private ulong width_req_id;
+ private ulong height_req_id;
public BoxActor (Box box) {
this.box = box;
@@ -215,46 +226,36 @@ class Boxes.BoxActor: Boxes.UI {
layout.vertical = true;
var cbox = new Clutter.Box (layout);
- screenshot = new GtkClutter.Texture ();
- screenshot.name = "screenshot";
+ this.screenshot = new GtkClutter.Texture ();
+ this.screenshot.name = "screenshot";
- scale_screenshot ();
- actor_add (screenshot, cbox);
- screenshot.keep_aspect_ratio = true;
+ this.scale_screenshot ();
+ actor_add (this.screenshot, cbox);
+ this.screenshot.keep_aspect_ratio = true;
- vbox = new Gtk.VBox (false, 0);
- gtkactor = new GtkClutter.Actor.with_contents (vbox);
- label = new Gtk.Label (box.name);
- vbox.add (label);
- entry = new Gtk.Entry ();
- entry.set_visibility (false);
- entry.set_placeholder_text ("Password"); // TODO: i18n stupid vala...
- vbox.add (entry);
+ this.vbox = new Gtk.VBox (false, 0);
+ this.gtkactor = new GtkClutter.Actor.with_contents (this.vbox);
+ this.label = new Gtk.Label (box.name);
+ this.vbox.add (this.label);
+ this.entry = new Gtk.Entry ();
+ this.entry.set_visibility (false);
+ this.entry.set_placeholder_text ("Password"); // TODO: i18n stupid vala...
+ this.vbox.add (this.entry);
- vbox.show_all ();
- entry.hide ();
+ this.vbox.show_all ();
+ this.entry.hide ();
- actor_add (gtkactor, cbox);
+ actor_add (this.gtkactor, cbox);
- actor = cbox;
+ this.actor = cbox;
}
public void scale_screenshot (float scale = 1.5f) {
- screenshot.set_size (128 * scale, 96 * scale);
- }
-
- public void set_screenshot (Gdk.Pixbuf pix) throws GLib.Error {
- screenshot.set_from_pixbuf (pix);
+ this.screenshot.set_size (128 * scale, 96 * scale);
}
- void update_display_size () {
- if (display.width_request < 320 || display.height_request < 200) {
- // filter invalid size request
- // TODO: where does it come from
- return;
- }
-
- box.app.set_window_size (display.width_request, display.height_request);
+ public void set_screenshot (Gdk.Pixbuf pixbuf) throws GLib.Error {
+ this.screenshot.set_from_pixbuf (pixbuf);
}
public void show_display (Gtk.Widget display) {
@@ -263,70 +264,85 @@ class Boxes.BoxActor: Boxes.UI {
return;
}
- actor_remove (screenshot);
+ actor_remove (this.screenshot);
this.display = display;
- wrsid = display.notify["width-request"].connect ( (pspec) => {
- update_display_size ();
- });
- hrsid = display.notify["height-request"].connect ( (pspec) => {
- update_display_size ();
- });
- vbox.add (display);
- update_display_size ();
+ this.width_req_id = display.notify["width-request"].connect ( (pspec) => {
+ this.update_display_size ();
+ });
+ this.height_req_id = display.notify["height-request"].connect ( (pspec) => {
+ this.update_display_size ();
+ });
+ this.vbox.add (display);
+ this.update_display_size ();
display.show ();
display.grab_focus ();
}
public void hide_display () {
- if (display == null)
+ if (this.display == null)
return;
- vbox.remove (display);
- display.disconnect (wrsid);
- display.disconnect (hrsid);
- display = null;
+ this.vbox.remove (this.display);
+ this.display.disconnect (this.width_req_id);
+ this.display.disconnect (this.height_req_id);
+ this.display = null;
- actor.pack_at (screenshot, 0);
+ this.actor.pack_at (this.screenshot, 0);
}
public override void ui_state_changed () {
switch (ui_state) {
- case UIState.CREDS: {
- scale_screenshot (2.0f);
- entry.show ();
+ case UIState.CREDS:
+ this.scale_screenshot (2.0f);
+ this.entry.show ();
// actor.entry.set_sensitive (false); FIXME: depending on spice-gtk conn. results
- entry.set_can_focus (true);
- entry.grab_focus ();
+ this.entry.set_can_focus (true);
+ this.entry.grab_focus ();
+
break;
- }
+
case UIState.DISPLAY: {
- int w, h;
-
- entry.hide ();
- label.hide ();
- box.app.window.get_size (out w, out h);
- screenshot.animate (Clutter.AnimationMode.LINEAR, Boxes.App.duration,
- "width", (float)w,
- "height", (float)h);
- actor.animate (Clutter.AnimationMode.LINEAR, Boxes.App.duration,
- "x", 0.0f,
- "y", 0.0f);
+ int width, height;
+
+ this.entry.hide ();
+ this.label.hide ();
+ this.box.app.window.get_size (out width, out height);
+ this.screenshot.animate (Clutter.AnimationMode.LINEAR, Boxes.App.duration,
+ "width", (float) width,
+ "height", (float) height);
+ this.actor.animate (Clutter.AnimationMode.LINEAR, Boxes.App.duration,
+ "x", 0.0f,
+ "y", 0.0f);
+
break;
}
- case UIState.COLLECTION: {
- hide_display ();
- scale_screenshot ();
- entry.set_can_focus (false);
- entry.hide ();
- label.show ();
+
+ case UIState.COLLECTION:
+ this.hide_display ();
+ this.scale_screenshot ();
+ this.entry.set_can_focus (false);
+ this.entry.hide ();
+ this.label.show ();
+
break;
- }
+
default:
message ("Unhandled UI state " + ui_state.to_string ());
+
break;
}
}
+
+ private void update_display_size () {
+ if (this.display.width_request < 320 || this.display.height_request < 200) {
+ // filter invalid size request
+ // TODO: where does it come from
+ return;
+ }
+
+ this.box.app.set_window_size (this.display.width_request, this.display.height_request);
+ }
}
diff --git a/src/boxes.vala b/src/boxes.vala
index 8ec1482..f63607d 100644
--- a/src/boxes.vala
+++ b/src/boxes.vala
@@ -28,147 +28,148 @@ class Boxes.App: Boxes.UI {
public Gtk.Window window;
public GtkClutter.Embed embed;
- public Clutter.Stage cstage;
- public Clutter.State cstate;
- public Clutter.Box cbox; // the whole app box
- public Box? box; // currently selected box
- public GVir.Connection conn;
+ public Stage stage;
+ public Clutter.State state;
+ public Clutter.Box box; // the whole app box
+ public Box? selected_box; // currently selected box
+ public GVir.Connection connection;
public static const uint duration = 555; // default to 1/2 for all transitions
- Clutter.TableLayout cbox_table;
- Collection collection;
- Sidebar sidebar;
- Topbar topbar;
- CollectionView view;
+ private Clutter.TableLayout box_table;
+ private Collection collection;
+ private Sidebar sidebar;
+ private Topbar topbar;
+ private CollectionView view;
+
+ public static void main (string[] args) {
+ Intl.bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+ Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ Intl.textdomain (GETTEXT_PACKAGE);
+ GLib.Environment.set_application_name (_("GNOME Boxes"));
+
+ GtkClutter.init (ref args);
+ Gtk.Window.set_default_icon_name ("gnome-boxes");
+ Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
+ var provider = new Gtk.CssProvider ();
+ try {
+ var sheet = get_style ("gtk-style.css");
+ provider.load_from_path (sheet);
+ Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
+ provider,
+ 600);
+ } catch (GLib.Error e) {
+ warning (e.message);
+ }
+
+ new App ();
+ Gtk.main ();
+ }
public App() {
- setup_ui ();
- collection = new Collection ();
+ this.setup_ui ();
+ this.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); });
- }
+ this.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 this.box_clicked (box, event); });
+ }
- view.add_item (item);
- });
+ this.view.add_item (item);
+ });
- setup_libvirt.begin ();
+ this.setup_libvirt.begin ();
+ }
+
+ public void set_category (Category category) {
+ this.topbar.label.set_text (category.name);
}
private async void setup_libvirt () {
- conn = new GVir.Connection ("qemu:///system");
+ this.connection = new GVir.Connection ("qemu:///system");
try {
- yield conn.open_async (null);
- conn.fetch_domains (null);
+ yield this.connection.open_async (null);
+ this.connection.fetch_domains (null);
} catch (GLib.Error e) {
warning (e.message);
}
- foreach (var d in conn.get_domains ()) {
- var box = new Box (this, d);
- collection.add_item (box);
+ foreach (var domain in this.connection.get_domains ()) {
+ var box = new Box (this, domain);
+ this.collection.add_item (box);
}
}
private void setup_ui () {
- window = new Gtk.Window ();
- window.set_default_size (640, 480);
- embed = new GtkClutter.Embed ();
- embed.show ();
- window.add (embed);
- cstage = embed.get_stage () as Clutter.Stage;
-
- var a = new GtkClutter.Actor (); // just to have background
- a.add_constraint (new Clutter.BindConstraint ((Clutter.Actor) cstage, BindCoordinate.SIZE, 0));
- ((Clutter.Container) cstage).add_actor (a);
-
- cstate = new Clutter.State ();
- cstate.set_duration (null, null, duration);
-
- window.destroy.connect (quit);
- window.key_press_event.connect (key_pressed);
- window.configure_event.connect ( (event) => {
- if (event.type == Gdk.EventType.CONFIGURE)
- save_window_size ();
- return false;
- });
-
- cbox_table = new Clutter.TableLayout ();
- cbox = new Clutter.Box (cbox_table);
- cbox.add_constraint (new Clutter.BindConstraint ((Clutter.Actor) cstage, BindCoordinate.SIZE, 0));
- ((Clutter.Container) cstage).add_actor (cbox);
-
- topbar = new Topbar (this);
- sidebar = new Sidebar (this);
- view = new CollectionView (this);
-
- var sg = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
- sg.add_widget (topbar.corner);
- sg.add_widget (sidebar.notebook);
-
- window.show ();
+ this.window = new Gtk.Window ();
+ this.window.set_default_size (640, 480);
+ this.embed = new GtkClutter.Embed ();
+ this.embed.show ();
+ this.window.add (this.embed);
+ this.stage = this.embed.get_stage () as Clutter.Stage;
- ui_state = UIState.COLLECTION;
- }
+ var actor = new GtkClutter.Actor (); // just to have background
+ actor.add_constraint (new Clutter.BindConstraint ((Clutter.Actor) this.stage, BindCoordinate.SIZE, 0));
+ ((Clutter.Container) this.stage).add_actor (actor);
- public void set_category (Category category) {
- topbar.label.set_text (category.name);
- }
+ this.state = new Clutter.State ();
+ this.state.set_duration (null, null, this.duration);
- bool key_pressed (Gtk.Widget widget, Gdk.EventKey event) {
- if (event.keyval == F11_KEY) {
- if (WindowState.FULLSCREEN in window.get_window ().get_state ())
- window.unfullscreen ();
- else
- window.fullscreen ();
- return true;
- }
- if (event.keyval == F12_KEY) {
- ui_state = UIState.COLLECTION;
- }
- return false;
- }
+ this.window.destroy.connect (quit);
+ this.window.key_press_event.connect (this.on_key_pressed);
+ this.window.configure_event.connect ( (event) => {
+ if (event.type == Gdk.EventType.CONFIGURE)
+ save_window_size ();
- bool box_clicked (Box box, Clutter.ButtonEvent event) {
- if (ui_state == UIState.COLLECTION) {
- this.box = box;
- if (this.box.connect_display ())
- ui_state = UIState.CREDS;
- }
+ return false;
+ });
- return false;
+ this.box_table = new Clutter.TableLayout ();
+ this.box = new Clutter.Box (this.box_table);
+ this.box.add_constraint (new Clutter.BindConstraint ((Clutter.Actor) this.stage, BindCoordinate.SIZE, 0));
+ ((Clutter.Container) this.stage).add_actor (this.box);
+
+ this.topbar = new Topbar (this);
+ this.sidebar = new Sidebar (this);
+ this.view = new CollectionView (this);
+
+ var size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
+ size_group.add_widget (this.topbar.corner);
+ size_group.add_widget (this.sidebar.notebook);
+
+ this.window.show ();
+
+ ui_state = UIState.COLLECTION;
}
public void go_back () {
ui_state = UIState.COLLECTION;
- box = null;
+ this.selected_box = null;
}
public override void ui_state_changed () {
message ("Switching layout to %s".printf (ui_state.to_string ()));
- foreach (var o in new Boxes.UI[] { sidebar, topbar, view }) {
+ foreach (var o in new Boxes.UI[] { this.sidebar, this.topbar, this.view }) {
o.ui_state = ui_state;
}
- cbox.set_layout_manager (cbox_table);
+ this.box.set_layout_manager (this.box_table);
switch (ui_state) {
case UIState.DISPLAY:
- cbox.set_layout_manager (new Clutter.FixedLayout ());
- cstate.set_state ("display");
+ this.box.set_layout_manager (new Clutter.FixedLayout ());
+ this.state.set_state ("display");
break;
case UIState.CREDS:
- cstate.set_state ("creds");
+ this.state.set_state ("creds");
break;
case UIState.COLLECTION:
restore_window_size ();
- cstate.set_state ("collection");
+ this.state.set_state ("collection");
break;
default:
warning ("Unhandled UI state %s".printf (ui_state.to_string ()));
@@ -182,47 +183,50 @@ class Boxes.App: Boxes.UI {
if (ui_state == UIState.DISPLAY)
return;
- window.get_size (out w, out h);
- window.default_width = (int)w;
- window.default_height = (int)h;
+ this.window.get_size (out w, out h);
+ this.window.default_width = (int)w;
+ this.window.default_height = (int)h;
}
public void restore_window_size () {
- window.resize (window.default_width, window.default_height);
+ this.window.resize (this.window.default_width, this.window.default_height);
}
public void set_window_size (int width, int height, bool save=false) {
if (save)
save_window_size ();
- window.resize (width, height);
+ this.window.resize (width, height);
}
public void quit () {
Gtk.main_quit ();
}
- public static void main (string[] args) {
- Intl.bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
- Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- Intl.textdomain (GETTEXT_PACKAGE);
- GLib.Environment.set_application_name (_("GNOME Boxes"));
+ private bool on_key_pressed (Widget widget, Gdk.EventKey event) {
+ if (event.keyval == F11_KEY) {
+ if (WindowState.FULLSCREEN in this.window.get_window ().get_state ())
+ this.window.unfullscreen ();
+ else
+ this.window.fullscreen ();
- GtkClutter.init (ref args);
- Gtk.Window.set_default_icon_name ("gnome-boxes");
- Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
- var provider = new Gtk.CssProvider ();
- try {
- var sheet = get_style ("gtk-style.css");
- provider.load_from_path (sheet);
- Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
- provider,
- 600);
- } catch (GLib.Error e) {
- warning (e.message);
+ return true;
}
- new App ();
- Gtk.main ();
+ if (event.keyval == F12_KEY) {
+ ui_state = UIState.COLLECTION;
+ }
+
+ return false;
+ }
+
+ private bool box_clicked (Box box, Clutter.ButtonEvent event) {
+ if (ui_state == UIState.COLLECTION) {
+ this.selected_box = box;
+ if (this.selected_box.connect_display ())
+ ui_state = UIState.CREDS;
+ }
+
+ return false;
}
}
@@ -231,12 +235,12 @@ public abstract class Boxes.UI: GLib.Object {
public UI () {
this.notify["ui-state"].connect ( (s, p) => {
- ui_state_changed ();
- });
+ ui_state_changed ();
+ });
}
- public void pin_actor (Clutter.Actor a) {
- a.set_geometry (a.get_geometry ());
+ 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 53db3a4..a6b6afa 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -2,111 +2,130 @@ using GLib;
using Clutter;
class Boxes.CollectionView: Boxes.UI {
- App app;
+ private App app;
- Clutter.Group actor; // the surrounding actor, for the margin
- Clutter.Box boxes; // the boxes list box
- Clutter.FlowLayout flow;
- Clutter.Box actor_onebox; // a box on top of boxes list
+ private Clutter.Group actor; // 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
public CollectionView (App app) {
this.app = app;
- setup_view ();
- }
-
- private void setup_view () {
- flow = new Clutter.FlowLayout (Clutter.FlowOrientation.HORIZONTAL);
- actor = new Clutter.Group ();
- boxes = new Clutter.Box (flow);
- flow.set_column_spacing (35);
- flow.set_row_spacing (25);
- actor.add (boxes);
- app.cbox.pack (actor, "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));
- boxes.add_constraint_with_name ("boxes-height", new Clutter.BindConstraint (actor, BindCoordinate.HEIGHT, -25f));
- // FIXME! report bug to clutter about flow inside table
- actor.add_constraint_with_name ("boxes-left", new Clutter.SnapConstraint (app.cstage, SnapEdge.RIGHT, SnapEdge.RIGHT, 0));
- actor.add_constraint_with_name ("boxes-bottom", new Clutter.SnapConstraint (app.cstage, SnapEdge.BOTTOM, SnapEdge.RIGHT.BOTTOM, 0));
-
- actor_onebox = new Clutter.Box (new Clutter.BinLayout (Clutter.BinAlignment.FILL, Clutter.BinAlignment.FILL));
- actor_onebox.add_constraint_with_name ("onebox-size", new Clutter.BindConstraint (actor, BindCoordinate.SIZE, 0));
- actor_onebox.add_constraint_with_name ("onebox-position", new Clutter.BindConstraint (actor, BindCoordinate.POSITION, 0));
- app.cstage.add_actor (actor_onebox);
-
- app.cstate.set_key (null, "creds", boxes, "opacity", AnimationMode.EASE_OUT_QUAD, (uint)0, 0, 0);
- app.cstate.set_key (null, "display", boxes, "opacity", AnimationMode.EASE_OUT_QUAD, (uint)0, 0, 0);
- app.cstate.set_key (null, "collection", boxes, "opacity", AnimationMode.EASE_OUT_QUAD, (uint)255, 0, 0);
- app.cstate.set_key (null, "display", actor_onebox, "x", AnimationMode.EASE_OUT_QUAD, (float)0, 0, 0);
- app.cstate.set_key (null, "display", actor_onebox, "y", AnimationMode.EASE_OUT_QUAD, (float)0, 0, 0);
- }
-
- public void add_item (CollectionItem item) {
- if (item is Box) {
- var box = (Box)item;
-
- box.actor.ui_state = UIState.COLLECTION;
- actor_add (box.get_clutter_actor (), boxes);
- } else {
- warning ("Cannot add item %p".printf (&item));
- }
- }
-
- public void remove_item (CollectionItem item) {
- if (item is Box) {
- var box = (Box)item;
- var actor = box.get_clutter_actor ();
- if (actor.get_parent () == this.boxes)
- this.boxes.remove_actor (actor); // FIXME: why Clutter warn here??!
- } else {
- warning ("Cannot remove item %p".printf (&item));
- }
+ this.setup_view ();
}
public override void ui_state_changed () {
switch (ui_state) {
- case UIState.CREDS: {
- remove_item (app.box);
- app.box.actor.ui_state = UIState.CREDS;
+ case UIState.CREDS:
+ this.remove_item (this.app.selected_box);
+ this.app.selected_box.actor.ui_state = UIState.CREDS;
- actor_onebox.pack (app.box.get_clutter_actor (),
+ this.top_box.pack (this.app.selected_box.get_clutter_actor (),
"x-align", Clutter.BinAlignment.CENTER,
"y-align", Clutter.BinAlignment.CENTER);
this.boxes.set_layout_manager (new Clutter.FixedLayout ());
+
break;
- }
+
case UIState.DISPLAY: {
float x, y;
- var a = app.box.get_clutter_actor ();
+ var actor = this.app.selected_box.get_clutter_actor ();
/* move box actor to stage */
- a.get_transformed_position (out x, out y);
- if (a.get_parent () == actor_onebox)
- actor_onebox.remove_actor (a);
- if (a.get_parent () != app.cstage)
- app.cstage.add_actor (a);
- a.set_position (x, y);
-
- app.box.actor.ui_state = UIState.DISPLAY;
+ actor.get_transformed_position (out x, out y);
+ if (actor.get_parent () == this.top_box)
+ this.top_box.remove_actor (actor);
+ if (actor.get_parent () != this.app.stage)
+ this.app.stage.add_actor (actor);
+ actor.set_position (x, y);
+
+ this.app.selected_box.actor.ui_state = UIState.DISPLAY;
+
break;
}
- case UIState.COLLECTION: {
- boxes.set_layout_manager (flow);
- if (app.box == null)
+ case UIState.COLLECTION:
+ this.boxes.set_layout_manager (this.layout);
+
+ if (this.app.selected_box == null)
break;
- var a = app.box.get_clutter_actor ();
- if (a.get_parent () == actor_onebox)
- actor_onebox.remove_actor (a);
- add_item (app.box);
+ var actor = this.app.selected_box.get_clutter_actor ();
+ if (actor.get_parent () == this.top_box)
+ this.top_box.remove_actor (actor);
+ this.add_item (this.app.selected_box);
break;
- }
+
default:
+
break;
}
}
+
+ public void add_item (CollectionItem item) {
+ if (item is Box) {
+ var box = (Box)item;
+
+ box.actor.ui_state = UIState.COLLECTION;
+ actor_add (box.get_clutter_actor (), this.boxes);
+ } else
+ warning ("Cannot add item %p".printf (&item));
+ }
+
+ public void remove_item (CollectionItem item) {
+ if (item is Box) {
+ var box = (Box)item;
+ var actor = box.get_clutter_actor ();
+ if (actor.get_parent () == this.boxes)
+ this.boxes.remove_actor (actor); // FIXME: why Clutter warn here??!
+ } else
+ warning ("Cannot remove item %p".printf (&item));
+ }
+
+ private void setup_view () {
+ this.layout = new Clutter.FlowLayout (Clutter.FlowOrientation.HORIZONTAL);
+ this.actor = new Clutter.Group ();
+ this.boxes = new Clutter.Box (this.layout);
+ this.layout.set_column_spacing (35);
+ this.layout.set_row_spacing (25);
+ this.actor.add (this.boxes);
+ this.app.box.pack (this.actor, "column", 1, "row", 1, "x-expand", true, "y-expand", true);
+
+ this.boxes.set_position (15f, 15f);
+ this.boxes.add_constraint_with_name ("boxes-width",
+ new Clutter.BindConstraint (this.actor, BindCoordinate.WIDTH, -25f));
+ this.boxes.add_constraint_with_name ("boxes-height",
+ new Clutter.BindConstraint (this.actor, BindCoordinate.HEIGHT, -25f));
+ // FIXME! report bug to clutter about flow inside table
+ this.actor.add_constraint_with_name ("boxes-left", new Clutter.SnapConstraint (this.app.stage,
+ SnapEdge.RIGHT,
+ SnapEdge.RIGHT,
+ 0));
+ this.actor.add_constraint_with_name ("boxes-bottom", new Clutter.SnapConstraint (this.app.stage,
+ SnapEdge.BOTTOM,
+ SnapEdge.RIGHT.BOTTOM,
+ 0));
+
+ this.top_box = new Clutter.Box (new Clutter.BinLayout (Clutter.BinAlignment.FILL, Clutter.BinAlignment.FILL));
+ this.top_box.add_constraint_with_name ("top-box-size",
+ new Clutter.BindConstraint (this.actor, BindCoordinate.SIZE, 0));
+ this.top_box.add_constraint_with_name ("top-box-position",
+ new Clutter.BindConstraint (this.actor, BindCoordinate.POSITION, 0));
+ this.app.stage.add_actor (this.top_box);
+
+ this.app.state.set_key (null, "creds", this.boxes, "opacity", AnimationMode.EASE_OUT_QUAD, (uint) 0, 0, 0);
+ this.app.state.set_key (null, "display", this.boxes, "opacity", AnimationMode.EASE_OUT_QUAD, (uint) 0, 0, 0);
+ this.app.state.set_key (null,
+ "collection",
+ this.boxes,
+ "opacity",
+ AnimationMode.EASE_OUT_QUAD,
+ (uint) 255,
+ 0,
+ 0);
+ this.app.state.set_key (null, "display", this.top_box, "x", AnimationMode.EASE_OUT_QUAD, (float) 0, 0, 0);
+ this.app.state.set_key (null, "display", this.top_box, "y", AnimationMode.EASE_OUT_QUAD, (float) 0, 0, 0);
+ }
}
diff --git a/src/collection.vala b/src/collection.vala
index 76edbe9..4869e3f 100644
--- a/src/collection.vala
+++ b/src/collection.vala
@@ -1,19 +1,21 @@
using GLib;
class Boxes.CollectionItem: GLib.Object {
- GenericArray<Category> categories = new GenericArray<Category> ();
-
public string name;
}
class Boxes.Collection: GLib.Object {
public signal void item_added (CollectionItem item);
- GenericArray<CollectionItem> array = new GenericArray<CollectionItem> ();
+ GenericArray<CollectionItem> items;
+
+ public Collection () {
+ this.items = new GenericArray<CollectionItem> ();
+ }
public void add_item (CollectionItem item) {
- array.add (item);
- item_added (item);
+ this.items.add (item);
+ this.item_added (item);
}
}
@@ -23,8 +25,4 @@ class Boxes.Category: GLib.Object {
public Category (string name) {
this.name = name;
}
-
- // public bool item_filter (CollectionItem item) {
- // return true;
- // }
}
diff --git a/src/sidebar.vala b/src/sidebar.vala
index 92b3f9e..5ee2594 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -4,23 +4,44 @@ using Clutter;
using GLib;
class Boxes.Sidebar: Boxes.UI {
- App app;
- uint width = 180;
+ public Notebook notebook;
+ public TreeView tree_view;
- Clutter.Actor actor; // the sidebar box
- public Gtk.Notebook notebook;
- public Gtk.TreeView tree_view;
+ private App app;
+ private uint width;
- public Sidebar(App app) {
+ private Clutter.Actor actor; // the sidebar box
+
+ private bool selection_func (Gtk.TreeSelection selection,
+ Gtk.TreeModel model,
+ Gtk.TreePath path,
+ bool path_currently_selected) {
+ Gtk.TreeIter iter;
+ bool selectable;
+
+ model.get_iter (out iter, path);
+ model.get (iter, 2, out selectable);
+
+ return selectable;
+ }
+
+ public Sidebar (App app) {
this.app = app;
- setup_sidebar ();
+ this.width = 180;
+
+ this.setup_sidebar ();
+ }
+
+ public override void ui_state_changed () {
+ if (ui_state == UIState.DISPLAY)
+ pin_actor(this.actor);
}
private void list_append (ListStore listmodel,
- Category category,
- string? icon = null,
- uint height = 0,
- bool sensitive = true) {
+ Category category,
+ string? icon = null,
+ uint height = 0,
+ bool sensitive = true) {
Gtk.TreeIter iter;
listmodel.append (out iter);
@@ -31,81 +52,77 @@ class Boxes.Sidebar: Boxes.UI {
listmodel.set (iter, 4, category);
}
- private static bool selection_func (Gtk.TreeSelection selection, Gtk.TreeModel model,
- Gtk.TreePath path, bool path_currently_selected) {
- Gtk.TreeIter iter;
- bool selectable;
-
- model.get_iter (out iter, path);
- model.get (iter, 2, out selectable);
- return selectable;
- }
-
private void setup_sidebar () {
- notebook = new Gtk.Notebook ();
- notebook.set_size_request ((int)width, 100);
+ this.notebook = new Gtk.Notebook ();
+ this.notebook.set_size_request ((int)this.width, 100);
var vbox = new Gtk.VBox (false, 0);
- notebook.append_page (vbox, new Gtk.Label (""));
+ this.notebook.append_page (vbox, new Gtk.Label (""));
- tree_view = new Gtk.TreeView ();
- var selection = tree_view.get_selection ();
+ this.tree_view = new Gtk.TreeView ();
+ var selection = this.tree_view.get_selection ();
selection.set_select_function (selection_func);
- tree_view_activate_on_single_click (tree_view, true);
- tree_view.row_activated.connect ( (tv, path, column) => {
- Gtk.TreeIter iter;
- Category category;
- var model = tv.get_model ();
- bool selectable;
-
- model.get_iter (out iter, path);
- model.get (iter, 4, out category);
- model.get (iter, 2, out selectable);
-
- if (selectable)
- app.set_category (category);
- });
-
- vbox.pack_start (tree_view, true, true, 0);
- notebook.page = 0;
- notebook.show_tabs = false;
- notebook.show_all ();
-
- actor = new GtkClutter.Actor.with_contents (notebook);
- app.cbox.pack (actor, "column", 0, "row", 1, "x-expand", false, "y-expand", true);
-
- var listmodel = new ListStore (5, typeof (string), typeof (uint), typeof (bool), typeof (string), typeof (Category));
- tree_view.set_model (listmodel);
- tree_view.headers_visible = false;
- var cellpix = new CellRendererPixbuf ();
- // cellpix.width = 20;
- // cellpix.mode = CellRendererMode.INERT;
- // cellpix.xalign = 1f;
- cellpix.xpad = 5;
- tree_view.insert_column_with_attributes (-1, "", cellpix, "icon-name", 3);
- tree_view.insert_column_with_attributes (-1, "", new CellRendererText (), "text", 0, "height", 1, "sensitive", 2);
-
- list_append (listmodel, new Category ("New and Recent"));
+ tree_view_activate_on_single_click (this.tree_view, true);
+ this.tree_view.row_activated.connect ( (treeview, path, column) => {
+ Gtk.TreeIter iter;
+ Category category;
+ var model = treeview.get_model ();
+ bool selectable;
+
+ model.get_iter (out iter, path);
+ model.get (iter, 4, out category);
+ model.get (iter, 2, out selectable);
+
+ if (selectable)
+ this.app.set_category (category);
+ });
+
+ vbox.pack_start (this.tree_view, true, true, 0);
+ this.notebook.page = 0;
+ this.notebook.show_tabs = false;
+ this.notebook.show_all ();
+
+ this.actor = new GtkClutter.Actor.with_contents (this.notebook);
+ app.box.pack (this.actor, "column", 0, "row", 1, "x-expand", false, "y-expand", true);
+
+ var listmodel = new ListStore (5,
+ typeof (string),
+ typeof (uint),
+ typeof (bool),
+ typeof (string),
+ typeof (Category));
+ this.tree_view.set_model (listmodel);
+ this.tree_view.headers_visible = false;
+ var pixbuf_renderer = new CellRendererPixbuf ();
+ // pixbuf_renderer.width = 20;
+ // pixbuf_renderer.mode = CellRendererMode.INERT;
+ // pixbuf_renderer.xalign = 1f;
+ pixbuf_renderer.xpad = 5;
+ this.tree_view.insert_column_with_attributes (-1, "", pixbuf_renderer, "icon-name", 3);
+ var renderer = new CellRendererText ();
+ this.tree_view.insert_column_with_attributes (-1, "", renderer, "text", 0, "height", 1, "sensitive", 2);
+
+ this.list_append (listmodel, new Category ("New and Recent"));
selection.select_path (new Gtk.TreePath.from_string ("0"));
- list_append (listmodel, new Category ("Favorites"), "emblem-favorite-symbolic");
- list_append (listmodel, new Category ("Private"), "channel-secure-symbolic");
- list_append (listmodel, new Category ("Shared with you"), "emblem-shared-symbolic");
- list_append (listmodel, new Category ("Collections"), null, 40, false);
+ this.list_append (listmodel, new Category ("Favorites"), "emblem-favorite-symbolic");
+ this.list_append (listmodel, new Category ("Private"), "channel-secure-symbolic");
+ this.list_append (listmodel, new Category ("Shared with you"), "emblem-shared-symbolic");
+ this.list_append (listmodel, new Category ("Collections"), null, 40, false);
// TODO: make it dynamic
- list_append (listmodel, new Category ("Work"));
- list_append (listmodel, new Category ("Game"));
+ this.list_append (listmodel, new Category ("Work"));
+ this.list_append (listmodel, new Category ("Game"));
var create = new Gtk.Button.with_label ("Create");
create.margin = 5;
vbox.pack_end (create, false, false, 0);
create.show ();
- app.cstate.set_key (null, "display", actor, "x", AnimationMode.EASE_OUT_QUAD, -(float)width, 0, 0); // FIXME: make it dynamic depending on sidebar size..
- }
-
- public override void ui_state_changed () {
- if (ui_state == UIState.DISPLAY) {
- pin_actor(actor);
- }
+ this.app.state.set_key (null,
+ "display",
+ this.actor,
+ "x", AnimationMode.EASE_OUT_QUAD,
+ -(float) this.width,
+ 0,
+ 0); // FIXME: make it dynamic depending on sidebar size..
}
}
diff --git a/src/spice-display.vala b/src/spice-display.vala
index 658cc82..ccb04c9 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -2,20 +2,21 @@ using Gtk;
using Spice;
class Boxes.SpiceDisplay: Boxes.Display {
- Spice.Session session;
+ private Session session;
public SpiceDisplay (string host, int port) {
- session = new Spice.Session ();
- session.port = port.to_string ();
- session.host = host;
+ this.session = new Session ();
+ this.session.port = port.to_string ();
+ this.session.host = host;
}
- public override Gtk.Widget get_display (int n) throws Boxes.Error {
+ public override Gtk.Widget get_display (int n) throws Boxes.Error {
var display = displays.lookup (n);
if (display == null) {
- display = new Spice.Display (session, n);
+ display = new Spice.Display (this.session, n);
}
+
if (display == null) {
throw new Boxes.Error.INVALID ("invalid display");
}
@@ -23,31 +24,30 @@ class Boxes.SpiceDisplay: Boxes.Display {
return display;
}
- private void main_event (ChannelEvent event) {
- if (ChannelEvent.CLOSED in event)
- disconnected ();
- }
-
public override void connect_it () {
// FIXME: vala does't want to put this in ctor..
- session.channel_new.connect ( (channel) => {
- if (channel is Spice.MainChannel) {
- channel.channel_event.connect (main_event);
- }
- if (channel is Spice.DisplayChannel) {
- var d = channel as DisplayChannel;
- show (d.channel_id);
- d.display_mark.connect ( (mark) => {
- show (d.channel_id);
- });
- }
- });
-
- session.connect ();
+ this.session.channel_new.connect ((channel) => {
+ if (channel is Spice.MainChannel)
+ channel.channel_event.connect (this.main_event);
+
+ if (channel is Spice.DisplayChannel) {
+ var display = channel as DisplayChannel;
+
+ show (display.channel_id);
+ display.display_mark.connect ((mark) => { show (display.channel_id); });
+ }
+ });
+
+ this.session.connect ();
}
public override void disconnect_it () {
- session.disconnect ();
+ this.session.disconnect ();
+ }
+
+ private void main_event (ChannelEvent event) {
+ if (ChannelEvent.CLOSED in event)
+ disconnected ();
}
}
diff --git a/src/topbar.vala b/src/topbar.vala
index 42436fa..8f981c7 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -2,89 +2,105 @@ using Clutter;
using Gtk;
class Boxes.Topbar: Boxes.UI {
- App app;
- uint height = 50;
-
- Clutter.Actor actor; // the topbar box
- Gtk.Notebook notebook;
- public Gtk.Widget corner;
+ public Widget corner;
public Gtk.Label label;
- Gtk.HBox hbox;
- Gtk.Toolbar toolbar_start;
- Gtk.ToolButton spinner;
+
+ private App app;
+ private uint height;
+
+ private Actor actor; // the topbar box
+ private Notebook notebook;
+
+ private HBox hbox;
+ private Toolbar toolbar_start;
+ private ToolButton spinner;
public Topbar (App app) {
this.app = app;
- setup_topbar ();
+ this.height = 50;
+
+ this.setup_topbar ();
}
private void setup_topbar () {
- notebook = new Gtk.Notebook ();
- notebook.set_size_request (50, (int)height);
- actor = new GtkClutter.Actor.with_contents (notebook);
- app.cbox.pack (actor,
- "column", 0, "row", 0,
- "column-span", 2,
- "x-expand", true, "y-expand", false);
+ this.notebook = new Gtk.Notebook ();
+ this.notebook.set_size_request (50, (int)this.height);
+ this.actor = new GtkClutter.Actor.with_contents (this.notebook);
+ this.app.box.pack (this.actor,
+ "column", 0,
+ "row", 0,
+ "column-span", 2,
+ "x-expand", true,
+ "y-expand", false);
- hbox = new Gtk.HBox (false, 0);
- hbox.get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR);
+ this.hbox = new Gtk.HBox (false, 0);
+ this.hbox.get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR);
- corner = new Gtk.EventBox ();
- // FIXME.. corner.get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR);
- hbox.pack_start (corner, false, false, 0);
+ this.corner = new Gtk.EventBox ();
+ // FIXME.. this.corner.get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR);
+ this.hbox.pack_start (this.corner, false, false, 0);
- toolbar_start = new Gtk.Toolbar ();
- toolbar_start.icon_size = Gtk.IconSize.MENU;
- toolbar_start.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
+ this.toolbar_start = new Gtk.Toolbar ();
+ this.toolbar_start.icon_size = Gtk.IconSize.MENU;
+ this.toolbar_start.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
var back = new Gtk.ToolButton (null, null);
back.icon_name = "go-previous-symbolic";
back.get_style_context ().add_class ("raised");
- back.clicked.connect ( (button) => { app.go_back (); });
- toolbar_start.insert (back, 0);
- toolbar_start.set_show_arrow (false);
- hbox.pack_start (toolbar_start, false, false, 0);
+ back.clicked.connect ( (button) => { this.app.go_back (); });
+ this.toolbar_start.insert (back, 0);
+ this.toolbar_start.set_show_arrow (false);
+ this.hbox.pack_start (this.toolbar_start, false, false, 0);
- label = new Gtk.Label ("New and Recent");
- label.name = "TopbarLabel";
- label.set_halign (Gtk.Align.START);
- hbox.pack_start (label, true, true, 0);
+ this.label = new Gtk.Label ("New and Recent");
+ this.label.name = "TopbarLabel";
+ this.label.set_halign (Gtk.Align.START);
+ this.hbox.pack_start (this.label, true, true, 0);
var toolbar_end = new Gtk.Toolbar ();
toolbar_end.icon_size = Gtk.IconSize.MENU;
toolbar_end.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
- spinner = new Gtk.ToolButton (new Gtk.Spinner (), null);
- spinner.get_style_context ().add_class ("raised");
- toolbar_end.insert (spinner, 0);
+ this.spinner = new Gtk.ToolButton (new Gtk.Spinner (), null);
+ this.spinner.get_style_context ().add_class ("raised");
+ toolbar_end.insert (this.spinner, 0);
toolbar_end.set_show_arrow (false);
- hbox.pack_start (toolbar_end, false, false, 0);
+ this.hbox.pack_start (toolbar_end, false, false, 0);
- notebook.append_page (hbox, null);
- notebook.page = 0;
- notebook.show_tabs = false;
- notebook.show_all ();
+ this.notebook.append_page (this.hbox, null);
+ this.notebook.page = 0;
+ this.notebook.show_tabs = false;
+ this.notebook.show_all ();
- app.cstate.set_key (null, "display", actor, "y", AnimationMode.EASE_OUT_QUAD, -(float)height, 0, 0); // FIXME: make it dynamic depending on topbar size..
+ this.app.state.set_key (null,
+ "display",
+ this.actor,
+ "y",
+ AnimationMode.EASE_OUT_QUAD,
+ -(float) this.height,
+ 0,
+ 0); // FIXME: make it dynamic depending on topbar size..
}
public override void ui_state_changed () {
switch (ui_state) {
- case UIState.COLLECTION: {
- toolbar_start.hide ();
- spinner.hide ();
+ case UIState.COLLECTION:
+ this.toolbar_start.hide ();
+ this.spinner.hide ();
+
break;
- }
- case UIState.CREDS: {
- toolbar_start.show ();
- spinner.show ();
+
+ case UIState.CREDS:
+ this.toolbar_start.show ();
+ this.spinner.show ();
+
break;
- }
- case UIState.DISPLAY: {
- pin_actor(actor);
+
+ case UIState.DISPLAY:
+ pin_actor(this.actor);
+
break;
- }
+
default:
break;
}
diff --git a/src/util.vala b/src/util.vala
index 6ade855..55b0cc0 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -3,59 +3,58 @@ using Gtk;
using Config;
using Xml;
-public string get_pkgdata (string? file = null) {
- return Path.build_filename (Config.DATADIR, Config.PACKAGE_TARNAME, file);
+public string get_pkgdata (string? file_name = null) {
+ return Path.build_filename (DATADIR, Config.PACKAGE_TARNAME, file_name);
}
-public string get_style (string? file = null) {
- return Path.build_filename (get_pkgdata (), "style", file);
+public string get_style (string? file_name = null) {
+ return Path.build_filename (get_pkgdata (), "style", file_name);
}
-public string get_pkgcache (string? file = null) {
+public string get_pkgcache (string? file_name = null) {
var dir = Path.build_filename (Environment.get_user_cache_dir (), Config.PACKAGE_TARNAME);
try {
- var f = GLib.File.new_for_path (dir);
- f.make_directory_with_parents (null);
+ var file = GLib.File.new_for_path (dir);
+ file.make_directory_with_parents (null);
} catch (GLib.Error e) {
if (!(e is IOError.EXISTS))
warning (e.message);
}
- return Path.build_filename (dir, file);
+ return Path.build_filename (dir, file_name);
}
-public void tree_view_activate_on_single_click (Gtk.TreeView tv, bool should_activate) {
- var id = tv.get_data<ulong> ("boxes-tree-view-activate");
+public void tree_view_activate_on_single_click (Gtk.TreeView tree_view, bool should_activate) {
+ var id = tree_view.get_data<ulong> ("boxes-tree-view-activate");
if (id != 0 && should_activate == false) {
- tv.disconnect (id);
- tv.set_data<ulong> ("boxes-tree-view-activate", 0);
+ tree_view.disconnect (id);
+ tree_view.set_data<ulong> ("boxes-tree-view-activate", 0);
} else {
- id = tv.button_press_event.connect (
- (w, event) => {
- Gtk.TreePath? path;
- unowned Gtk.TreeViewColumn? column;
- int x, y;
-
- if (event.button == 1 && event.type == Gdk.EventType.BUTTON_PRESS) {
- tv.get_path_at_pos ((int)event.x, (int)event.y, out path, out column, out x, out y);
+ id = tree_view.button_press_event.connect ((w, event) => {
+ Gtk.TreePath? path;
+ unowned Gtk.TreeViewColumn? column;
+ int x, y;
+
+ if (event.button == 1 && event.type == Gdk.EventType.BUTTON_PRESS) {
+ tree_view.get_path_at_pos ((int)event.x, (int)event.y, out path, out column, out x, out y);
if (path != null)
- tv.row_activated (path, column);
- }
- return false;
- });
- tv.set_data<ulong> ("boxes-tree-view-activate", id);
+ tree_view.row_activated (path, column);
+ }
+
+ return false;
+ });
+ tree_view.set_data<ulong> ("boxes-tree-view-activate", id);
}
}
-public async void output_stream_write (OutputStream o, uint8[] buffer) throws GLib.IOError {
- var l = buffer.length;
+public async void output_stream_write (OutputStream stream, uint8[] buffer) throws GLib.IOError {
+ var length = buffer.length;
ssize_t i = 0;
- while (i < l) {
- i += yield o.write_async (buffer[i:l]);
- }
+ while (i < length)
+ i += yield stream.write_async (buffer[i:length]);
}
public string? extract_xpath (string xmldoc, string xpath, bool required = false) throws Boxes.Error {
@@ -80,20 +79,19 @@ public string? extract_xpath (string xmldoc, string xpath, bool required = false
return obj->stringval;
}
-public void actor_add (Clutter.Actor a, Clutter.Container c) {
- if (a.get_parent () == (Clutter.Actor)c)
+public void actor_add (Clutter.Actor actor, Clutter.Container container) {
+ if (actor.get_parent () == (Clutter.Actor) container)
return;
- actor_remove (a);
- c.add (a);
+ actor_remove (actor);
+ container.add (actor);
}
-public void actor_remove (Clutter.Actor a) {
- var c = a.get_parent () as Clutter.Container;
+public void actor_remove (Clutter.Actor actor) {
+ var container = actor.get_parent () as Clutter.Container;
- if (c == null) {
+ if (container == null)
return;
- }
- c.remove (a);
+ container.remove (actor);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]