[gnome-boxes/wip/wizard-n-props-in-dialog2: 15/20] libvirt-machine-props: Refactor system props code a little



commit 082c01316b9c0a46dcf69475592adad82b797b87
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sun Nov 23 15:23:42 2014 +0000

    libvirt-machine-props: Refactor system props code a little
    
    Put all the code to add troubleshoot log button and dialog into a
    separate method.

 src/libvirt-machine-properties.vala |  122 ++++++++++++++++++-----------------
 1 files changed, 63 insertions(+), 59 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 2507827..3d6065b 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -145,65 +145,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
             var storage_property = add_storage_property (ref list);
             mark_recommended_resources.begin (ram_property, storage_property);
 
-            var button = new Gtk.Button.with_label (_("Troubleshooting log"));
-            button.halign = Gtk.Align.START;
-            add_property (ref list, null, button);
-            button.clicked.connect (() => {
-                var log = collect_logs ();
-                var dialog = new Gtk.Dialog.with_buttons (_("Troubleshooting log"),
-                                                          machine.window,
-                                                          DialogFlags.DESTROY_WITH_PARENT,
-                                                          _("_Save"), 100,
-                                                          _("Copy to clipboard"), 101,
-                                                          _("_Close"), ResponseType.OK);
-                dialog.set_default_size (640, 480);
-                var text = new Gtk.TextView ();
-                text.editable = false;
-                var scroll = new Gtk.ScrolledWindow (null, null);
-                scroll.add (text);
-                scroll.vexpand = true;
-
-                dialog.get_content_area ().add (scroll);
-                text.buffer.set_text (log);
-                dialog.show_all ();
-
-                dialog.response.connect ( (response_id) => {
-                    if (response_id == 100) {
-                        var chooser = new Gtk.FileChooserDialog (_("Save log"), machine.window,
-                                                                 Gtk.FileChooserAction.SAVE,
-                                                                 _("_Save"), ResponseType.OK);
-                        chooser.local_only = false;
-                        chooser.do_overwrite_confirmation = true;
-                        chooser.response.connect ((response_id) => {
-                            if (response_id == ResponseType.OK) {
-                                var file = chooser.get_file ();
-                                try {
-                                    file.replace_contents (log.data, null, false,
-                                                           FileCreateFlags.REPLACE_DESTINATION, null);
-                                } catch (GLib.Error e) {
-                                    var m = new Gtk.MessageDialog (chooser,
-                                                                   Gtk.DialogFlags.DESTROY_WITH_PARENT,
-                                                                   Gtk.MessageType.ERROR,
-                                                                   Gtk.ButtonsType.CLOSE,
-                                                                   _("Error saving: %s").printf (e.message));
-                                    m.show_all ();
-                                    m.response.connect ( () => { m.destroy (); });
-                                    return;
-                                }
-                                chooser.destroy ();
-                            } else {
-                                chooser.destroy ();
-                            }
-                        });
-                        chooser.show_all ();
-                    } else if (response_id == 101){
-                        Gtk.Clipboard.get_for_display (dialog.get_display (),
-                                                       Gdk.SELECTION_CLIPBOARD).set_text (log, -1);
-                    } else {
-                        dialog.destroy ();
-                    }
-                });
-            });
+            add_troubleshoot_log_button (ref list);
             break;
 
         case PropertiesPage.DEVICES:
@@ -476,6 +418,68 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
         });
     }
 
+    private void add_troubleshoot_log_button (ref List<Boxes.Property> list) {
+        var button = new Gtk.Button.with_label (_("Troubleshooting log"));
+        button.halign = Gtk.Align.START;
+        add_property (ref list, null, button);
+        button.clicked.connect (() => {
+            var log = collect_logs ();
+            var dialog = new Gtk.Dialog.with_buttons (_("Troubleshooting log"),
+                                                      machine.window,
+                                                      DialogFlags.DESTROY_WITH_PARENT,
+                                                      _("_Save"), 100,
+                                                      _("Copy to clipboard"), 101,
+                                                      _("_Close"), ResponseType.OK);
+            dialog.set_default_size (640, 480);
+            var text = new Gtk.TextView ();
+            text.editable = false;
+            var scroll = new Gtk.ScrolledWindow (null, null);
+            scroll.add (text);
+            scroll.vexpand = true;
+
+            dialog.get_content_area ().add (scroll);
+            text.buffer.set_text (log);
+            dialog.show_all ();
+
+            dialog.response.connect ( (response_id) => {
+                if (response_id == 100) {
+                    var chooser = new Gtk.FileChooserDialog (_("Save log"), machine.window,
+                                                             Gtk.FileChooserAction.SAVE,
+                                                             _("_Save"), ResponseType.OK);
+                    chooser.local_only = false;
+                    chooser.do_overwrite_confirmation = true;
+                    chooser.response.connect ((response_id) => {
+                        if (response_id == ResponseType.OK) {
+                            var file = chooser.get_file ();
+                            try {
+                                file.replace_contents (log.data, null, false,
+                                                       FileCreateFlags.REPLACE_DESTINATION, null);
+                            } catch (GLib.Error e) {
+                                var m = new Gtk.MessageDialog (chooser,
+                                                               Gtk.DialogFlags.DESTROY_WITH_PARENT,
+                                                               Gtk.MessageType.ERROR,
+                                                               Gtk.ButtonsType.CLOSE,
+                                                               _("Error saving: %s").printf (e.message));
+                                m.show_all ();
+                                m.response.connect ( () => { m.destroy (); });
+                                return;
+                            }
+                            chooser.destroy ();
+                        } else {
+                            chooser.destroy ();
+                        }
+                    });
+                    chooser.show_all ();
+                } else if (response_id == 101){
+                    Gtk.Clipboard.get_for_display (dialog.get_display (),
+                                                   Gdk.SELECTION_CLIPBOARD).set_text (log, -1);
+                } else {
+                        dialog.destroy ();
+                }
+            });
+        });
+    }
+
     private SizeProperty? add_ram_property (ref List<Boxes.Property> list) {
         try {
             var max_ram = machine.connection.get_node_info ().memory;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]