[gnome-games] utils: Add CompositeTitle



commit 103eb05aaec1045707f6a0a9fa55b40c0c61cfbc
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu May 26 17:31:11 2016 +0200

    utils: Add CompositeTitle
    
    This will be used in subsequent commits to allow games to have several
    titles sources ordered by priority.

 src/Makefile.am                |    1 +
 src/utils/composite-title.vala |   24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2064097..59f7bf7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -123,6 +123,7 @@ gnome_games_SOURCES = \
        ui/ui-state.vala \
        \
        utils/composite-cover.vala \
+       utils/composite-title.vala \
        utils/cue-sheet/cue-sheet.vala \
        utils/cue-sheet/cue-sheet-error.vala \
        utils/cue-sheet/cue-sheet-file-format.vala \
diff --git a/src/utils/composite-title.vala b/src/utils/composite-title.vala
new file mode 100644
index 0000000..e2a0b18
--- /dev/null
+++ b/src/utils/composite-title.vala
@@ -0,0 +1,24 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.CompositeTitle : Object, Title {
+       private Title[] titles;
+
+       public CompositeTitle (Title[] titles) ensures (titles.length > 0) {
+               this.titles = titles;
+       }
+
+       public string get_title () throws Error {
+               Error last_error = null;
+
+               foreach (var title in titles) {
+                       try {
+                               return title.get_title ();
+                       }
+                       catch (Error e) {
+                               last_error = e;
+                       }
+               }
+
+               throw last_error;
+       }
+}


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