[gnome-boxes] libvirt-machine-props: Some more refactoring
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] libvirt-machine-props: Some more refactoring
- Date: Tue, 2 Apr 2013 14:08:49 +0000 (UTC)
commit b00b02b2c0165d770e9389ca14316caaaed03c1b
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Mar 15 04:17:48 2013 +0200
libvirt-machine-props: Some more refactoring
Put 'reboot' into a separate method. lambdas inside lambdas weren't make
it easy to read this code.
https://bugzilla.gnome.org/show_bug.cgi?id=696242
src/libvirt-machine-properties.vala | 96 ++++++++++++++++++-----------------
1 files changed, 49 insertions(+), 47 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index cf35ad6..9d3d129 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -456,57 +456,59 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
if (!machine.is_on ())
return;
- Notificationbar.OKFunc reboot = () => {
- debug ("Rebooting '%s'..", machine.name);
- machine.stay_on_display = true;
- ulong state_id = 0;
- Gd.Notification notification = null;
-
- state_id = machine.notify["state"].connect (() => {
- if (machine.state == Machine.MachineState.STOPPED ||
- machine.state == Machine.MachineState.FORCE_STOPPED) {
- debug ("'%s' stopped.", machine.name);
- machine.start.begin (Machine.ConnectFlags.NONE, (obj, res) => {
- try {
- machine.start.end (res);
- } catch (GLib.Error error) {
- warning ("Failed to start '%s': %s", machine.domain.get_name (), error.message);
- }
- });
- machine.disconnect (state_id);
- if (shutdown_timeout != 0) {
- Source.remove (shutdown_timeout);
- shutdown_timeout = 0;
- }
- if (notification != null) {
- notification.dismiss ();
- notification = null;
+ var message = _("Changes require restart of '%s'. Attempt restart?").printf (machine.name);
+ App.app.notificationbar.display_for_action (message, Gtk.Stock.YES, reboot);
+ }
+
+ private void reboot () {
+ debug ("Rebooting '%s'..", machine.name);
+ machine.stay_on_display = true;
+ ulong state_id = 0;
+ Gd.Notification notification = null;
+
+ state_id = machine.notify["state"].connect (() => {
+ if (machine.state == Machine.MachineState.STOPPED ||
+ machine.state == Machine.MachineState.FORCE_STOPPED) {
+ debug ("'%s' stopped.", machine.name);
+ machine.start.begin (Machine.ConnectFlags.NONE, (obj, res) => {
+ try {
+ machine.start.end (res);
+ } catch (GLib.Error error) {
+ warning ("Failed to start '%s': %s", machine.domain.get_name (), error.message);
}
- }
- });
+ });
- shutdown_timeout = Timeout.add_seconds (5, () => {
- // Seems guest ignored ACPI shutdown, lets force shutdown with user's consent
- Notificationbar.OKFunc really_force_shutdown = () => {
+ machine.disconnect (state_id);
+ if (shutdown_timeout != 0) {
+ Source.remove (shutdown_timeout);
+ shutdown_timeout = 0;
+ }
+ if (notification != null) {
+ notification.dismiss ();
notification = null;
- machine.force_shutdown (false);
- };
+ }
+ }
+ });
- var message = _("Restart of '%s' is taking too long. Force it to shutdown?").printf
(machine.name);
- notification = App.app.notificationbar.display_for_action (message,
- Gtk.Stock.YES,
- (owned) really_force_shutdown,
- null,
- -1);
- shutdown_timeout = 0;
+ shutdown_timeout = Timeout.add_seconds (5, () => {
+ // Seems guest ignored ACPI shutdown, lets force shutdown with user's consent
+ Notificationbar.OKFunc really_force_shutdown = () => {
+ notification = null;
+ machine.force_shutdown (false);
+ };
+
+ var message = _("Restart of '%s' is taking too long. Force it to shutdown?").printf
(machine.name);
+ notification = App.app.notificationbar.display_for_action (message,
+ Gtk.Stock.YES,
+ (owned) really_force_shutdown,
+ null,
+ -1);
+ shutdown_timeout = 0;
- return false;
- });
+ return false;
+ });
- machine.try_shutdown ();
- };
- var message = _("Changes require restart of '%s'. Attempt restart?").printf (machine.name);
- App.app.notificationbar.display_for_action (message, Gtk.Stock.YES, (owned) reboot);
+ machine.try_shutdown ();
}
private SizeProperty? add_storage_property (ref List<Boxes.Property> list) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]