[gnome-games/wip/exalm/db: 7/9] game-model: Ensure stable sorting



commit 041abed61f9e74eb605ae72066c86dbfdcbbb992
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sat Feb 8 19:49:11 2020 +0500

    game-model: Ensure stable sorting
    
    Multiple games can share the same name. In this case, try to sort by
    platform, and even if that fails, by uid.

 src/core/game-model.vala | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/src/core/game-model.vala b/src/core/game-model.vala
index 0f15910a..f98795c8 100644
--- a/src/core/game-model.vala
+++ b/src/core/game-model.vala
@@ -34,6 +34,20 @@ private class Games.GameModel : Object, ListModel {
        }
 
        private int compare_func (Game a, Game b) {
-               return a.name.collate (b.name);
+               var ret = a.name.collate (b.name);
+
+               if (ret != 0)
+                       return ret;
+
+               ret = a.get_platform ().get_name ().collate (b.get_platform ().get_name ());
+               if (ret != 0)
+                       return ret;
+
+               try {
+                       return a.get_uid ().get_uid ().collate (b.get_uid ().get_uid ());
+               }
+               catch (Error e) {
+                       assert_not_reached ();
+               }
        }
 }


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