summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2012-09-01 17:48:24 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2013-01-30 16:49:52 +0100
commiteff7835e5928f1a9c6051ba17ac75d100ed20aab (patch)
treeab09d64df2dfa3dbada74789c5dc23c7079dbba9
parente2aab7e53aabbe5793aa14bcc66de2e689172b2a (diff)
libvirt: Move App::add_domain to LibvirtBroker
https://bugzilla.gnome.org/show_bug.cgi?id=681747
-rw-r--r--src/app.vala14
-rw-r--r--src/libvirt-broker.vala20
-rw-r--r--src/vm-creator.vala2
3 files changed, 19 insertions, 17 deletions
diff --git a/src/app.vala b/src/app.vala
index 6c9f9e5..8c35249 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -325,20 +325,6 @@ private class Boxes.App: Boxes.UI {
return false;
}
- public LibvirtMachine add_domain (CollectionSource source, GVir.Connection connection, GVir.Domain domain)
- throws GLib.Error {
- var machine = domain.get_data<LibvirtMachine> ("machine");
- if (machine != null)
- return machine; // Already added
-
- machine = new LibvirtMachine (source, connection, domain);
- machine.suspend_at_exit = (connection == default_connection);
- collection.add_item (machine);
- domain.set_data<LibvirtMachine> ("machine", machine);
-
- return machine;
- }
-
public void delete_machine (Machine machine, bool by_user = true) {
machine.delete (by_user); // Will also delete associated storage volume if by_user is 'true'
collection.remove_item (machine);
diff --git a/src/libvirt-broker.vala b/src/libvirt-broker.vala
index 3c41d69..4e0185f 100644
--- a/src/libvirt-broker.vala
+++ b/src/libvirt-broker.vala
@@ -22,10 +22,26 @@ private class Boxes.LibvirtBroker : Boxes.Broker {
return broker.connections.get (name);
}
+ public LibvirtMachine add_domain (CollectionSource source, GVir.Connection connection, GVir.Domain domain)
+ throws GLib.Error {
+ return_if_fail (broker != null);
+
+ var machine = domain.get_data<LibvirtMachine> ("machine");
+ if (machine != null)
+ return machine; // Already added
+
+ machine = new LibvirtMachine (source, connection, domain);
+ machine.suspend_at_exit = (connection == App.app.default_connection);
+ App.app.collection.add_item (machine);
+ domain.set_data<LibvirtMachine> ("machine", machine);
+
+ return machine;
+ }
+
// New == Added after Boxes launch
private void try_add_new_domain (CollectionSource source, GVir.Connection connection, GVir.Domain domain) {
try {
- App.app.add_domain (source, connection, domain);
+ add_domain (source, connection, domain);
} catch (GLib.Error error) {
warning ("Failed to create source '%s': %s", source.name, error.message);
}
@@ -34,7 +50,7 @@ private class Boxes.LibvirtBroker : Boxes.Broker {
// Existing == Existed before Boxes was launched
private void try_add_existing_domain (CollectionSource source, GVir.Connection connection, GVir.Domain domain) {
try {
- var machine = App.app.add_domain (source, connection, domain);
+ var machine = add_domain (source, connection, domain);
var config = machine.domain_config;
if (VMConfigurator.is_install_config (config) || VMConfigurator.is_live_config (config)) {
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index 4805109..18e4cd1 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -52,7 +52,7 @@ private class Boxes.VMCreator {
var domain = connection.create_domain (config);
- return App.app.add_domain (App.app.default_source, App.app.default_connection, domain);
+ return LibvirtBroker.get_default ().add_domain (App.app.default_source, App.app.default_connection, domain);
}
public void launch_vm (LibvirtMachine machine) throws GLib.Error {