[gnome-boxes] unattended-setup-box: Cache setup data
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] unattended-setup-box: Cache setup data
- Date: Mon, 2 Mar 2015 14:01:03 +0000 (UTC)
commit ae21e562515ab60d3279f182313e9a6c7be53abd
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Feb 26 23:33:59 2015 +0000
unattended-setup-box: Cache setup data
Cache express install toggle, username, password and product key for
every media. No need to keep product keys in a separate file and having
to paste them each time you create a windows VM anymore. \o/
https://bugzilla.gnome.org/show_bug.cgi?id=693391
src/unattended-installer.vala | 2 +
src/unattended-setup-box.vala | 62 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 61 insertions(+), 3 deletions(-)
---
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index 59c9c0d..5a22a7b 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -143,6 +143,8 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
}
public override async void prepare_for_installation (string vm_name, Cancellable? cancellable) {
+ setup_box.save_settings ();
+
if (!setup_box.express_install) {
debug ("Unattended installation disabled.");
diff --git a/src/unattended-setup-box.vala b/src/unattended-setup-box.vala
index 8b9c62d..5ff6da9 100644
--- a/src/unattended-setup-box.vala
+++ b/src/unattended-setup-box.vala
@@ -2,6 +2,12 @@
[GtkTemplate (ui = "/org/gnome/Boxes/ui/unattended-setup-box.ui")]
private class Boxes.UnattendedSetupBox : Gtk.Box {
+ private const string KEY_FILE = "setup-data.conf";
+ private const string EXPRESS_KEY = "express-install";
+ private const string USERNAME_KEY = "username";
+ private const string PASSWORD_KEY = "password";
+ private const string PRODUCTKEY_KEY = "product-key";
+
public bool ready_for_express {
get {
return username != "" &&
@@ -90,15 +96,32 @@ private class Boxes.UnattendedSetupBox : Gtk.Box {
private Gtk.Entry product_key_entry;
private string? product_key_format;
+ private string media_path;
+ private GLib.KeyFile keyfile;
public UnattendedSetupBox (InstallerMedia media, string? product_key_format, bool needs_internet) {
this.product_key_format = product_key_format;
- username_entry.text = Environment.get_user_name ();
- setup_express_toggle (media.os_media.live, needs_internet);
var msg = _("Express installation of %s requires an internet connection.").printf (media.label);
needs_internet_label.label = msg;
needs_internet_bar.visible = needs_internet;
+ media_path = media.device_file;
+ keyfile = new GLib.KeyFile ();
+
+ try {
+ var filename = get_user_unattended (KEY_FILE);
+ keyfile.load_from_file (filename, KeyFileFlags.KEEP_COMMENTS);
+
+ set_entry_text_from_key (username_entry, USERNAME_KEY, Environment.get_user_name ());
+ set_entry_text_from_key (password_entry, PASSWORD_KEY);
+ set_entry_text_from_key (password_entry, PASSWORD_KEY);
+ if (password != "")
+ password_notebook.next_page ();
+ set_entry_text_from_key (product_key_entry, PRODUCTKEY_KEY);
+ } catch (GLib.Error error) {
+ debug ("%s either doesn't already exist or we failed to load it: %s", media_path, error.message);
+ }
+ setup_express_toggle (media.os_media.live, needs_internet);
if (product_key_format != null) {
product_key_label.visible = true;
@@ -117,8 +140,27 @@ private class Boxes.UnattendedSetupBox : Gtk.Box {
NetworkMonitor.get_default ().network_changed.disconnect (update_express_toggle);
}
+ public void save_settings () {
+ keyfile.set_boolean (media_path, EXPRESS_KEY, express_install);
+ keyfile.set_string (media_path, USERNAME_KEY, username);
+ keyfile.set_string (media_path, PASSWORD_KEY, password);
+ keyfile.set_string (media_path, PRODUCTKEY_KEY, product_key);
+
+ var filename = get_user_unattended (KEY_FILE);
+ try {
+ keyfile.save_to_file (filename);
+ } catch (GLib.Error error) {
+ debug ("Error saving settings for '%s': %s", media_path, error.message);
+ }
+ }
+
private void setup_express_toggle (bool live, bool needs_internet) {
- express_toggle.active = !live;
+ try {
+ express_toggle.active = keyfile.get_boolean (media_path, EXPRESS_KEY);
+ } catch (GLib.Error error) {
+ debug ("Failed to read key '%s' under '%s': %s\n", EXPRESS_KEY, media_path, error.message);
+ express_toggle.active = !live;
+ }
if (!needs_internet)
return;
@@ -137,6 +179,20 @@ private class Boxes.UnattendedSetupBox : Gtk.Box {
}
}
+ private void set_entry_text_from_key (Gtk.Entry entry, string key, string? default_value = null) {
+ string? str = null;
+ try {
+ str = keyfile.get_string (media_path, key);
+ } catch (GLib.Error error) {
+ debug ("Failed to read key '%s' under '%s': %s\n", key, media_path, error.message);
+ }
+
+ if (str != null && str != "")
+ entry.text = str;
+ else if (default_value != null)
+ entry.text = default_value;
+ }
+
[GtkCallback]
private void on_mandatory_input_changed () {
notify_property ("ready-to-create");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]