[gnome-games] grilo: Add GriloDeveloper & GriloPublisher



commit a9f5dc4e6e5190507f813618add271194d3583bd
Author: 1PunMan <saurabhsingh412 gmail com>
Date:   Thu May 10 15:47:52 2018 +0530

    grilo: Add GriloDeveloper & GriloPublisher
    
    These will be used to make several games get developer& publisher from the
    web using Grilo.

 src/grilo/grilo-developer.vala | 49 ++++++++++++++++++++++++++++++++++++++++++
 src/grilo/grilo-publisher.vala | 49 ++++++++++++++++++++++++++++++++++++++++++
 src/meson.build                |  2 ++
 3 files changed, 100 insertions(+)
---
diff --git a/src/grilo/grilo-developer.vala b/src/grilo/grilo-developer.vala
new file mode 100644
index 0000000..819f99a
--- /dev/null
+++ b/src/grilo/grilo-developer.vala
@@ -0,0 +1,49 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.GriloDeveloper : Object, Developer {
+       private GriloMedia media;
+       private string developer;
+       private bool resolving;
+
+       public GriloDeveloper (GriloMedia media) {
+               this.media = media;
+               media.resolved.connect (on_media_resolved);
+               resolving = false;
+       }
+
+       public string get_developer () {
+               if (resolving)
+                       return developer;
+
+               if (developer != null)
+                       return developer;
+
+               resolving = true;
+               media.try_resolve_media ();
+
+               return developer;
+       }
+
+       private void on_media_resolved () {
+               var grl_media = media.get_media ();
+
+               if (grl_media == null)
+                       return;
+
+               var registry = Grl.Registry.get_default ();
+               var grl_metadata_key_developer = registry.lookup_metadata_key ("developer");
+
+               if (grl_media.length (grl_metadata_key_developer) == 0)
+                       return;
+
+               var developer_string = grl_media.get_string (grl_metadata_key_developer);
+               load_media_developer (developer_string);
+       }
+
+       private void load_media_developer (string developer_string) {
+               developer = developer_string;
+               resolving = true;
+
+               changed();
+       }
+}
diff --git a/src/grilo/grilo-publisher.vala b/src/grilo/grilo-publisher.vala
new file mode 100644
index 0000000..0311ba2
--- /dev/null
+++ b/src/grilo/grilo-publisher.vala
@@ -0,0 +1,49 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.GriloPublisher : Object, Publisher {
+       private GriloMedia media;
+       private string publisher;
+       private bool resolving;
+
+       public GriloPublisher (GriloMedia media) {
+               this.media = media;
+               media.resolved.connect (on_media_resolved);
+               resolving = false;
+       }
+
+       public string get_publisher () {
+               if (resolving)
+                       return publisher;
+
+               if (publisher != null)
+                       return publisher;
+
+               resolving = true;
+               media.try_resolve_media ();
+
+               return publisher;
+       }
+
+       private void on_media_resolved () {
+               var grl_media = media.get_media ();
+
+               if (grl_media == null)
+                       return;
+
+               var registry = Grl.Registry.get_default();
+               var grl_metadata_key_publisher = registry.lookup_metadata_key ("publisher");
+
+               if (grl_media.length (grl_metadata_key_publisher) == 0)
+                       return;
+
+               var publisher_string = grl_media.get_string (grl_metadata_key_publisher);
+               load_media_publisher (publisher_string);
+       }
+
+       private void load_media_publisher (string publisher_string) {
+               publisher = publisher_string;
+               resolving = true;
+
+               changed();
+       }
+}
diff --git a/src/meson.build b/src/meson.build
index 71cd94f..f0ac6c3 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -83,9 +83,11 @@ vala_sources = [
 
   'grilo/grilo-cooperative.vala',
   'grilo/grilo-cover.vala',
+  'grilo/grilo-developer.vala',
   'grilo/grilo-genre.vala',
   'grilo/grilo-media.vala',
   'grilo/grilo-players.vala',
+  'grilo/grilo-publisher.vala',
   'grilo/grilo-release-date.vala',
 
   'keyboard/keyboard-mapping-builder.vala',


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