[gnome-boxes] Add password support
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Add password support
- Date: Tue, 11 Oct 2011 17:39:08 +0000 (UTC)
commit 0833948f9d6d453854ca384b5d7c30a832998013
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Tue Oct 11 17:03:59 2011 +0200
Add password support
src/display.vala | 4 ++-
src/machine.vala | 54 +++++++++++++++++++++++++++++++++++------------
src/spice-display.vala | 34 ++++++++++++++++++++---------
3 files changed, 66 insertions(+), 26 deletions(-)
---
diff --git a/src/display.vala b/src/display.vala
index 713aa35..c8007d8 100644
--- a/src/display.vala
+++ b/src/display.vala
@@ -1,7 +1,8 @@
// This file is part of GNOME Boxes. License: LGPLv2
private abstract class Boxes.Display: GLib.Object {
- protected HashTable<int, Gtk.Widget?> displays;
+ public bool need_password { get; set; }
+ public string? password { get; set; }
public signal void show (int display_id);
public signal void hide (int display_id);
@@ -11,6 +12,7 @@ private abstract class Boxes.Display: GLib.Object {
public abstract void connect_it ();
public abstract void disconnect_it ();
+ protected HashTable<int, Gtk.Widget?> displays;
construct {
displays = new HashTable<int, Gtk.Widget> (direct_hash, direct_equal);
}
diff --git a/src/machine.vala b/src/machine.vala
index bf8acdd..3728c7c 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -21,6 +21,7 @@ private class Boxes.Machine: Boxes.CollectionItem {
private ulong show_id;
private ulong disconnected_id;
+ private ulong need_password_id;
private uint screenshot_id;
private Display? _display;
@@ -30,6 +31,7 @@ private class Boxes.Machine: Boxes.CollectionItem {
if (_display != null) {
_display.disconnect (show_id);
_display.disconnect (disconnected_id);
+ _display.disconnect (need_password_id);
}
_display = value;
@@ -46,6 +48,12 @@ private class Boxes.Machine: Boxes.CollectionItem {
disconnected_id = _display.disconnected.connect (() => {
app.ui_state = Boxes.UIState.COLLECTION;
});
+
+ need_password_id = display.notify["need-password"].connect (() => {
+ machine_actor.set_password_needed (display.need_password);
+ });
+
+ display.password = machine_actor.get_password ();
}
}
@@ -211,7 +219,7 @@ private class Boxes.MachineActor: Boxes.UI {
public GtkClutter.Actor gtk_display;
private Gtk.Label label;
private Gtk.VBox vbox; // and the vbox under it
- private Gtk.Entry entry;
+ private Gtk.Entry password_entry;
private Gtk.Widget? display;
private Machine machine;
@@ -236,13 +244,24 @@ private class Boxes.MachineActor: Boxes.UI {
label = new Gtk.Label (machine.name);
vbox.add (label);
- entry = new Gtk.Entry ();
- entry.set_visibility (false);
- entry.set_placeholder_text (_("Password"));
- vbox.add (entry);
+ 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 ();
+ return true;
+ }
+
+ return false;
+ });
+ vbox.add (password_entry);
vbox.show_all ();
- entry.hide ();
+ password_entry.hide ();
actor_add (gtk_vbox, box);
}
@@ -286,21 +305,28 @@ private class Boxes.MachineActor: Boxes.UI {
gtk_display = null;
}
+ public void set_password_needed (bool needed) {
+ password_entry.set_sensitive (needed);
+ password_entry.set_can_focus (needed);
+ if (needed)
+ password_entry.grab_focus ();
+ }
+
+ public string get_password () {
+ return password_entry.text;
+ }
+
public override void ui_state_changed () {
switch (ui_state) {
case UIState.CREDS:
scale_screenshot (2.0f);
- entry.show ();
- // actor.entry.set_sensitive (false); FIXME: depending on spice-gtk conn. results
- entry.set_can_focus (true);
- entry.grab_focus ();
-
+ password_entry.show ();
break;
case UIState.DISPLAY: {
int width, height;
- entry.hide ();
+ password_entry.hide ();
label.hide ();
machine.app.window.get_size (out width, out height);
screenshot.animate (Clutter.AnimationMode.LINEAR, Boxes.App.duration,
@@ -315,8 +341,8 @@ private class Boxes.MachineActor: Boxes.UI {
case UIState.COLLECTION:
hide_display ();
scale_screenshot ();
- entry.set_can_focus (false);
- entry.hide ();
+ password_entry.set_can_focus (false);
+ password_entry.hide ();
label.show ();
break;
diff --git a/src/spice-display.vala b/src/spice-display.vala
index a4dd1c2..1f9f04b 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -4,11 +4,13 @@ using Spice;
private class Boxes.SpiceDisplay: Boxes.Display {
private Session session;
+ private ulong channel_new_id;
public SpiceDisplay (string host, int port) {
session = new Session ();
session.port = port.to_string ();
session.host = host;
+ need_password = false;
}
public override Gtk.Widget get_display (int n) throws Boxes.Error {
@@ -28,18 +30,21 @@ private class Boxes.SpiceDisplay: Boxes.Display {
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_new_id == 0) {
+ channel_new_id = session.channel_new.connect ((channel) => {
+ if (channel is Spice.MainChannel)
+ channel.channel_event.connect (main_event);
- if (channel is Spice.DisplayChannel) {
- var display = channel as DisplayChannel;
+ if (channel is Spice.DisplayChannel) {
+ var display = channel as DisplayChannel;
- show (display.channel_id);
- display.display_mark.connect ((mark) => { show (display.channel_id); });
- }
- });
+ show (display.channel_id);
+ display.display_mark.connect ((mark) => { show (display.channel_id); });
+ }
+ });
+ }
+ session.password = password;
session.connect ();
}
@@ -48,8 +53,15 @@ private class Boxes.SpiceDisplay: Boxes.Display {
}
private void main_event (ChannelEvent event) {
- if (ChannelEvent.CLOSED in event)
+ switch (event) {
+ case ChannelEvent.CLOSED:
disconnected ();
+ break;
+ case ChannelEvent.ERROR_AUTH:
+ need_password = true;
+ break;
+ default:
+ break;
+ }
}
}
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]