[gnome-boxes] Save/load display properties
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Save/load display properties
- Date: Wed, 2 Nov 2011 20:06:44 +0000 (UTC)
commit 8df8985097cb15d14bb99a4dc31b3dde46c59807
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Wed Nov 2 21:06:28 2011 +0100
Save/load display properties
src/collection-source.vala | 33 +++++++++++++++++++++++++++++++++
src/display.vala | 23 +++++++++++++++++++++++
src/remote-machine.vala | 4 ++--
src/spice-display.vala | 27 ++++++++++++++++++++++-----
src/vnc-display.vala | 9 ++++++++-
5 files changed, 88 insertions(+), 8 deletions(-)
---
diff --git a/src/collection-source.vala b/src/collection-source.vala
index f65ec0d..e8996a3 100644
--- a/src/collection-source.vala
+++ b/src/collection-source.vala
@@ -66,4 +66,37 @@ private class Boxes.CollectionSource: GLib.Object {
return null;
}
}
+
+ public void save_display_property (Object display, string property_name) {
+ var group = "display";
+ var value = Value (display.get_class ().find_property (property_name).value_type);
+
+ display.get_property (property_name, ref value);
+
+ if (value.type () == typeof (string))
+ keyfile.set_string (group, property_name, value.get_string ());
+ else if (value.type () == typeof (bool))
+ keyfile.set_boolean (group, property_name, value.get_boolean ());
+ else
+ warning ("unhandled property %s type, value: %s".printf (
+ property_name, value.strdup_contents ()));
+
+ save ();
+ }
+
+ public void load_display_property (Object display, string property_name, Value default_value) {
+ var group = "display";
+ var value = Value (display.get_class ().find_property (property_name).value_type);
+
+ try {
+ if (value.type () == typeof (string))
+ value = keyfile.get_string (group, property_name);
+ if (value.type () == typeof (bool))
+ value = keyfile.get_boolean (group, property_name);
+ } catch (GLib.Error err) {
+ value = default_value;
+ }
+
+ display.set_property (property_name, value);
+ }
}
diff --git a/src/display.vala b/src/display.vala
index fbcf3f7..f57c873 100644
--- a/src/display.vala
+++ b/src/display.vala
@@ -2,6 +2,11 @@
using Gtk;
private abstract class Boxes.Display: GLib.Object, Boxes.IProperties {
+ protected struct SavedProperty {
+ string name;
+ Value default_value;
+ }
+
public abstract string protocol { get; }
public abstract string uri { owned get; }
@@ -26,4 +31,22 @@ private abstract class Boxes.Display: GLib.Object, Boxes.IProperties {
construct {
displays = new HashTable<int, Gtk.Widget> (direct_hash, direct_equal);
}
+
+ public CollectionSource? source { get; set; }
+
+ public void sync_source_with_display (Object display, SavedProperty[] saved_properties) {
+ if (source == null)
+ return;
+
+ foreach (var prop in saved_properties)
+ source.load_display_property (display, prop.name, prop.default_value);
+
+ display.notify.connect ((pspec) => {
+ foreach (var prop in saved_properties)
+ if (pspec.name == prop.name) {
+ source.save_display_property (display, pspec.name);
+ break;
+ }
+ });
+ }
}
diff --git a/src/remote-machine.vala b/src/remote-machine.vala
index 434c384..c6fea6b 100644
--- a/src/remote-machine.vala
+++ b/src/remote-machine.vala
@@ -16,9 +16,9 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IProperties {
try {
if (source.source_type == "spice")
- display = new SpiceDisplay.with_uri (source.uri);
+ display = new SpiceDisplay.with_uri (source, source.uri);
else if (source.source_type == "vnc")
- display = new VncDisplay.with_uri (source.uri);
+ display = new VncDisplay.with_uri (source, source.uri);
display.connect_it ();
} catch (GLib.Error error) {
diff --git a/src/spice-display.vala b/src/spice-display.vala
index c96f9d0..9362669 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -10,20 +10,36 @@ private class Boxes.SpiceDisplay: Boxes.Display, Boxes.IProperties {
private unowned GtkSession gtk_session;
private ulong channel_new_id;
private ulong channel_destroy_id;
+ private Display.SavedProperty[] display_saved_properties;
+ private Display.SavedProperty[] gtk_session_saved_properties;
construct {
+ display_saved_properties = {
+ SavedProperty () { name = "resize-guest", default_value = true }
+ };
+
+ gtk_session_saved_properties = {
+ SavedProperty () { name = "auto-clipboard", default_value = true },
+ SavedProperty () { name = "auto-usbredir", default_value = false }
+ };
+
need_password = false;
+ session = new Session ();
+ gtk_session = GtkSession.get (session);
+
+ this.notify["source"].connect (() => {
+ sync_source_with_display (gtk_session, gtk_session_saved_properties);
+ });
}
public SpiceDisplay (string host, int port) {
- session = new Session ();
session.port = port.to_string ();
session.host = host;
- gtk_session = GtkSession.get (session);
}
- public SpiceDisplay.with_uri (string uri) {
- session = new Session ();
+ public SpiceDisplay.with_uri (CollectionSource source, string uri) {
+ this.source = source;
+
session.uri = uri;
}
@@ -36,7 +52,8 @@ private class Boxes.SpiceDisplay: Boxes.Display, Boxes.IProperties {
if (display == null)
throw new Boxes.Error.INVALID ("invalid display");
- display.resize_guest = true;
+ sync_source_with_display (display, display_saved_properties);
+
display.scaling = true;
displays.replace (n, display);
diff --git a/src/vnc-display.vala b/src/vnc-display.vala
index 2611376..e8092b3 100644
--- a/src/vnc-display.vala
+++ b/src/vnc-display.vala
@@ -10,8 +10,12 @@ private class Boxes.VncDisplay: Boxes.Display {
private string host;
private int port;
private Gtk.Window window;
+ private Display.SavedProperty[] saved_properties;
construct {
+ saved_properties = {
+ SavedProperty () { name = "read-only", default_value = false }
+ };
need_password = false;
display = new Vnc.Display ();
@@ -71,7 +75,10 @@ private class Boxes.VncDisplay: Boxes.Display {
this.port = port;
}
- public VncDisplay.with_uri (string _uri) throws Boxes.Error {
+ public VncDisplay.with_uri (CollectionSource source, string _uri) throws Boxes.Error {
+ this.source = source;
+ sync_source_with_display (display, saved_properties);
+
var uri = Xml.URI.parse (_uri);
if (uri.scheme != "vnc")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]