[gnome-games/wip/aplazas/781334-refactor-game-sources: 2/4] Allow a media to have any number of URIs
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/781334-refactor-game-sources: 2/4] Allow a media to have any number of URIs
- Date: Thu, 4 May 2017 19:39:32 +0000 (UTC)
commit 748073188a30fcb44535b2f43689f3b05c8251d6
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 413aa83..f29ea92 100644
--- a/plugins/playstation/src/playstation-game-factory.vala
+++ b/plugins/playstation/src/playstation-game-factory.vala
@@ -120,7 +120,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);
@@ -132,7 +134,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]