[gnome-boxes] installer-media: Refactor label setup code



commit db96a87e69d1f5323e1008c5dae5036cf724009e
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Jul 10 01:28:52 2012 +0300

    installer-media: Refactor label setup code
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679657

 src/installer-media.vala |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)
---
diff --git a/src/installer-media.vala b/src/installer-media.vala
index a726161..a0823c9 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -20,14 +20,12 @@ private class Boxes.InstallerMedia : Object {
                                          Media?            media,
                                          Osinfo.Resources? resources) {
         this.device_file = path;
-        this.label = label;
         this.os = os;
         this.os_media = media;
         this.resources = resources;
         from_image = true;
 
-        if (media != null && media.live)
-            this.label = _("%s (Live)").printf (label);
+        setup_label (label);
     }
 
     public static async InstallerMedia create_for_path (string       path,
@@ -52,15 +50,7 @@ private class Boxes.InstallerMedia : Object {
             os = yield media_manager.os_db.guess_os_from_install_media (device_file, out os_media, cancellable);
         }
 
-        if (os != null)
-            label = os.get_name ();
-            if (os_media != null && os_media.live)
-                // Translators: We are appending " (Live)" suffix to name of OS media to indication that it's live.
-                //              http://en.wikipedia.org/wiki/Live_CD
-                label = _("%s (Live)").printf (label);
-
-        if (label == null)
-            label = Path.get_basename (device_file);
+        setup_label ();
 
         // FIXME: these values could be made editable somehow
         var architecture = (os_media != null) ? os_media.architecture : "i686";
@@ -111,4 +101,22 @@ private class Boxes.InstallerMedia : Object {
                 os_media = os_db.get_media_by_id (os, media_id);
         }
     }
+
+    private void setup_label (string? label = null) {
+        if (label != null)
+            this.label = label;
+        else if (os != null)
+            this.label = os.get_name ();
+        else {
+            // No appropriate label? :( Lets just use filename then
+            this.label = Path.get_basename (device_file);
+
+            return;
+        }
+
+        if (os_media != null && os_media.live)
+            // Translators: We are appending " (Live)" suffix to name of OS media to indication that it's live.
+            //              http://en.wikipedia.org/wiki/Live_CD
+            this.label = _("%s (Live)").printf (this.label);
+    }
 }



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