[gnome-games] gameinfo: Add GameinfoDoc



commit d1d1fb15bf70deaf0fa28b0506ac64f6d167a6bc
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu May 26 16:06:44 2016 +0200

    gameinfo: Add GameinfoDoc
    
    This is needed to read Gameinfo documents which will be added in
    subsequent commits as a game information source.

 src/Makefile.am                |    1 +
 src/gameinfo/gameinfo-doc.vala |   59 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3a53f5e..202c079 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,6 +58,7 @@ gnome_games_SOURCES = \
        dummy/dummy-icon.vala \
        dummy/dummy-runner.vala \
        \
+       gameinfo/gameinfo-doc.vala \
        gameinfo/gameinfo-error.vala \
        \
        gamepad/gamepad.vala \
diff --git a/src/gameinfo/gameinfo-doc.vala b/src/gameinfo/gameinfo-doc.vala
new file mode 100644
index 0000000..e2cc625
--- /dev/null
+++ b/src/gameinfo/gameinfo-doc.vala
@@ -0,0 +1,59 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.GameinfoDoc : Object {
+       private XmlDoc xml_doc;
+
+       public GameinfoDoc.from_data (uint8[] data) throws Error {
+               xml_doc = new XmlDoc.from_data (data);
+       }
+
+       public string? get_game_title_for_disc_id (string disc_id) throws Error {
+               var expr = "/gameinfo/games/game[discs/disc[@id = \"" + disc_id + "\"]]/title";
+
+               var title = xml_doc.get_content (expr);
+               if (title == null)
+                       throw new GameinfoError.DISC_NOT_FOUND (_("No game title found for disc ID '%s'."), 
disc_id);
+
+               return title;
+       }
+
+       public string? get_disc_title_for_disc_id (string disc_id) throws Error {
+               var expr = "/gameinfo/games/game/discs/disc[@id = \"" + disc_id + "\"]/title";
+
+               var title = xml_doc.get_content (expr);
+               if (title == null)
+                       throw new GameinfoError.DISC_NOT_FOUND (_("No disc title found for disc ID '%s'."), 
disc_id);
+
+               return title;
+       }
+
+       public string? get_disc_set_id_for_disc_id (string disc_id) throws Error {
+               var expr = "/gameinfo/games/game/discs[disc[@id = \"" + disc_id + "\"]]/disc[1]/@id";
+
+               var title = xml_doc.get_content (expr);
+               if (title == null)
+                       throw new GameinfoError.DISC_NOT_FOUND (_("No disc set ID found for disc ID '%s'."), 
disc_id);
+
+               return title;
+       }
+
+       public int get_disc_set_index_for_disc_id (string disc_id) throws Error {
+               var test_expr = "/gameinfo/games/game/discs/disc[@id = \"" + disc_id + "\"]";
+               if (xml_doc.count_nodes (test_expr) == 0)
+                       throw new GameinfoError.DISC_NOT_FOUND (_("No disc found for disc ID '%s'."), 
disc_id);
+
+               var expr = "/gameinfo/games/game/discs/disc[@id = \"" + disc_id + 
"\"]/preceding-sibling::disc";
+
+               return xml_doc.count_nodes (expr);
+       }
+
+       public int get_disc_set_size_for_disc_id (string disc_id) throws Error {
+               var test_expr = "/gameinfo/games/game/discs/disc[@id = \"" + disc_id + "\"]";
+               if (xml_doc.count_nodes (test_expr) == 0)
+                       throw new GameinfoError.DISC_NOT_FOUND (_("No disc found for disc ID '%s'."), 
disc_id);
+
+               var expr = "/gameinfo/games/game/discs[disc[@id = \"" + disc_id + "\"]]/disc";
+
+               return xml_doc.count_nodes (expr);
+       }
+}


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