[gnome-boxes] media-manager: Avoid listing duplicate media



commit 548f25b0e6a25bb6fbb2a51f1c30161b8bbc779c
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Dec 17 19:59:35 2013 +0000

    media-manager: Avoid listing duplicate media
    
    In case of duplicate media, prefer:
    
    * released OS over unreleased one
    * latest release
    * soft over hard media
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685243

 src/media-manager.vala |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/src/media-manager.vala b/src/media-manager.vala
index fb6259a..1dfbf53 100644
--- a/src/media-manager.vala
+++ b/src/media-manager.vala
@@ -124,6 +124,18 @@ private class Boxes.MediaManager : Object {
 
                 try {
                     var media = yield create_installer_media_from_iso_info (path, title, os_id, media_id);
+                    unowned GLib.List<InstallerMedia> dup_node = list.find_custom (media, 
compare_media_by_label);
+                    if (dup_node != null) {
+                        // In case of duplicate media, prefer:
+                        // * released OS over unreleased one
+                        // * latest release
+                        // * soft over hard media
+                        var dup_media = dup_node.data;
+                        if (compare_media_by_release_date (media, dup_media) <= 0)
+                            list.remove (dup_media);
+                        else
+                            continue;
+                    }
 
                     list.insert_sorted (media, compare_media_by_label);
                 } catch (GLib.Error error) {
@@ -170,6 +182,30 @@ private class Boxes.MediaManager : Object {
         return strcmp (media_a.label, media_b.label);
     }
 
+    private static int compare_media_by_release_date (InstallerMedia media_a, InstallerMedia media_b) {
+        if (media_a.os == null) {
+            if (media_b.os == null)
+                return 0;
+            else
+                return 1;
+        } else if (media_b.os == null)
+            return -1;
+        else {
+            var release_a = media_a.os.get_release_date ();
+            var release_b = media_b.os.get_release_date ();
+
+            if (release_a == null) {
+                if (release_b == null)
+                    return 0;
+                else
+                    return 1;
+            } else if (release_b == null)
+                return -1;
+            else
+                return release_a.compare (release_b);
+        }
+    }
+
     private async InstallerMedia create_installer_media_from_iso_info (string  path,
                                                                        string? label,
                                                                        string? os_id,


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