[gnome-games] game: Add last_played property



commit 1a7bcad2bba94867412dcbe413d65dbab98e8c70
Author: Neville <nevilleantony98 gmail com>
Date:   Sat Jul 18 14:31:18 2020 +0530

    game: Add last_played property
    
    last_played is a DateTime which is used to store when a game was last
    played. If this prop is null then it implies the game was never played
    after the introduction of this prop.
    
    Also adds a static compare_by_date_time which can be used to sort the
    games in decreasing order of last played.

 src/core/game.vala | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/src/core/game.vala b/src/core/game.vala
index 9422f2583..d77d6cb1b 100644
--- a/src/core/game.vala
+++ b/src/core/game.vala
@@ -28,6 +28,7 @@ public class Games.Game : Object {
        public Platform platform { get; private set; }
        public MediaSet? media_set { get; set; }
        public bool is_favorite { get; set; }
+       public DateTime? last_played { get; set; }
 
        private Title game_title;
        private Icon game_icon;
@@ -71,6 +72,10 @@ public class Games.Game : Object {
                return true;
        }
 
+       public void update_last_played () {
+               last_played = new DateTime.now ();
+       }
+
        public static uint hash (Game key) {
                return Uid.hash (key.uid);
        }
@@ -93,4 +98,17 @@ public class Games.Game : Object {
 
                return Uid.compare (a.uid, b.uid);
        }
+
+       public static int compare_by_date_time (Game a, Game b) {
+               if (a.last_played == null && b.last_played == null)
+                       return 0;
+
+               if (a.last_played == null)
+                       return 1;
+
+               if (b.last_played == null)
+                       return -1;
+
+               return b.last_played.compare (a.last_played);
+       }
 }


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