[gnome-games/wip/aplazas/refactor-media-set: 1/3] Allow a media to have any number of URIs



commit 279120c94392fb299ed6b509d6d70183cbe3428d
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Apr 14 13:00:27 2017 +0200

    Allow a media to have any number of URIs
    
    This will be used to make MediaSet more flexible.

 .../playstation/src/playstation-game-factory.vala  |    9 +++++++--
 src/core/media.vala                                |   18 ++++++++++++++----
 src/retro/retro-runner.vala                        |   15 ++++++++++++---
 3 files changed, 33 insertions(+), 9 deletions(-)
---
diff --git a/plugins/playstation/src/playstation-game-factory.vala 
b/plugins/playstation/src/playstation-game-factory.vala
index 0979547..8896a1c 100644
--- a/plugins/playstation/src/playstation-game-factory.vala
+++ b/plugins/playstation/src/playstation-game-factory.vala
@@ -122,7 +122,9 @@ public class Games.PlayStationGameFactory : Object, UriGameFactory {
                disc_list.foreach ((disc_id) => {
                        var uri = discs[disc_id];
                        var title = new GameinfoDiscIdDiscTitle (gameinfo, disc_id);
-                       medias += new Media (uri, title);
+                       var media = new Media (title);
+                       media.add_uri (uri);
+                       medias += media;
                });
 
                var icon = GLib.Icon.new_for_string (ICON_NAME);
@@ -134,7 +136,10 @@ public class Games.PlayStationGameFactory : Object, UriGameFactory {
        }
 
        private Game game_for_uris (MediaSet media_set) throws Error {
-               var uri = media_set.get_selected_media (0).uri;
+               var selected_media = media_set.get_selected_media (0);
+               var uris = selected_media.get_uris ();
+               // FIXME Check that there is at least one URI.
+               var uri = uris[0];
                var cue_file = File.new_for_uri (uri);
                var cue_sheet = new CueSheet (cue_file);
                var cue_track_node = cue_sheet.get_track (0);
diff --git a/src/core/media.vala b/src/core/media.vala
index 56af130..d9d8f17 100644
--- a/src/core/media.vala
+++ b/src/core/media.vala
@@ -1,10 +1,20 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 public class Games.Media : Object {
-       public Title? title { get; construct; }
-       public string uri { get; construct; }
+       public Title? title { get; private set; }
 
-       public Media (string uri, Title? title = null) {
-               Object (title: title, uri: uri);
+       private string[] uris;
+
+       public Media (Title? title = null) {
+               this.title = title;
+               this.uris = {};
+       }
+
+       public string[] get_uris () {
+               return uris;
+       }
+
+       public void add_uri (string uri) {
+               uris += uri;
        }
 }
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 310e1e0..309dbde 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -76,7 +76,8 @@ public class Games.RetroRunner : Object, Runner {
                should_save = false;
 
                this.core_descriptor = null;
-               var game_media = new Media (uri);
+               var game_media = new Media ();
+               game_media.add_uri (uri);
                _media_set = new MediaSet ({ game_media });
 
                this.uid = uid;
@@ -212,8 +213,12 @@ public class Games.RetroRunner : Object, Runner {
                else {
                        var media_number = media_set.selected_media_number;
                        var media = media_set.get_selected_media (media_number);
-                       var uri = media.uri;
+                       // FIXME If there is no URI for thi media, it's an error.
+                       var uris = media.get_uris ();
+                       if (uris.length == 0)
+                               throw new RetroError.INVALID_GAME_FILE (_("No game file found for media 
ā€œ%sā€."), media.title.get_title ());
 
+                       var uri = uris[0];
                        if (!try_load_game (core, uri))
                                throw new RetroError.INVALID_GAME_FILE (_("Invalid game file: ā€œ%sā€."), uri);
                }
@@ -359,7 +364,11 @@ public class Games.RetroRunner : Object, Runner {
                        return;
                }
 
-               var uri = media.uri;
+               var uris = media.get_uris ();
+               if (uris.length == 0)
+                       return;
+
+               var uri = uris[0];
 
                try_load_game (core, uri);
 


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