[gnome-games] grilo: Add GriloMedia



commit e47ceb1b454d0abba8c883b7742a79d2cea3b3cc
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri May 13 09:18:51 2016 +0200

    grilo: Add GriloMedia
    
    This will be used in a next commit to create GriloCover to get covers
    from the web using Grilo.

 src/Makefile.am            |    2 +
 src/grilo/grilo-media.vala |   72 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 9e26918..a826f60 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,6 +53,8 @@ gnome_games_SOURCES = \
        dummy/dummy-icon.vala \
        dummy/dummy-runner.vala \
        \
+       grilo/grilo-media.vala \
+       \
        retro/retro-error.vala \
        retro/retro-log.vala \
        retro/retro-runner.vala \
diff --git a/src/grilo/grilo-media.vala b/src/grilo/grilo-media.vala
new file mode 100644
index 0000000..77c0a92
--- /dev/null
+++ b/src/grilo/grilo-media.vala
@@ -0,0 +1,72 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.GriloMedia : Object {
+       private static Grl.Registry registry;
+
+       public signal void resolved ();
+
+       private Title title;
+       private string mime_type;
+       private bool resolving;
+
+       private Grl.Media? media;
+
+       public GriloMedia (Title title, string mime_type) {
+               this.title = title;
+               this.mime_type = mime_type;
+               resolving = false;
+       }
+
+       private static Grl.Registry get_registry () throws Error {
+               if (registry != null)
+                       return registry;
+
+               registry = Grl.Registry.get_default ();
+               registry.load_all_plugins(true);
+
+               return registry;
+       }
+
+       public void try_resolve_media () {
+               try {
+                       resolve_media ();
+               }
+               catch (Error e) {
+                       warning (e.message);
+               }
+       }
+
+       internal Grl.Media? get_media () {
+               return media;
+       }
+
+       private void resolve_media () throws Error {
+               if (resolving)
+                       return;
+
+               resolving = true;
+
+               var registry = get_registry ();
+               var source = registry.lookup_source ("grl-thegamesdb");
+
+               return_val_if_fail (source != null, null);
+
+               var base_media = new Grl.Media ();
+               var title_string = title.get_title ();
+               base_media.set_title (title_string);
+               base_media.set_mime (mime_type);
+
+               var keys = Grl.MetadataKey.list_new (Grl.MetadataKey.THUMBNAIL,
+                                                    null);
+
+               var options = new Grl.OperationOptions (null);
+               options.set_resolution_flags (Grl.ResolutionFlags.FULL);
+
+               source.do_resolve (base_media, keys, options, on_media_resolved);
+       }
+
+       private void on_media_resolved (Grl.Source source, uint operation_id, owned Grl.Media media, 
GLib.Error? error) {
+               this.media = media;
+               resolved ();
+       }
+}


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