[grilo] [doc] Added a searching example. Added instructions for compiling programs that use Grilo.



commit 2f530d881f7b304a79a975b0cc5f8d5cb14c9df8
Author: Iago Toral Quiroga <itoral igalia com>
Date:   Tue Apr 6 09:08:35 2010 +0200

    [doc] Added a searching example.
          Added instructions for compiling programs that use Grilo.

 doc/reference/quick-start-using-grilo.xml |  114 ++++++++++++++++++++++++++++-
 1 files changed, 113 insertions(+), 1 deletions(-)
---
diff --git a/doc/reference/quick-start-using-grilo.xml b/doc/reference/quick-start-using-grilo.xml
index ce30759..b7fc867 100644
--- a/doc/reference/quick-start-using-grilo.xml
+++ b/doc/reference/quick-start-using-grilo.xml
@@ -38,6 +38,13 @@ $ tools/grilo-test-ui/grilo-test-ui
     </programlisting>    
   </section>
 
+  <section id="compiling-grilo-programs">
+    <title>Compiling Grilo based programs</title>
+    <programlisting>
+libtool --mode=link gcc -o example `pkg-config --cflags --libs grilo-0.1` example.c
+    </programlisting>    
+  </section>
+
   <section id="programming-with-grilo-loading-plugins">
     <title>Programming with Grilo: Loading plugins</title>
     <para>Here is a small program illustrating how you can load plugins:</para>
@@ -111,7 +118,7 @@ main (int argc, gchar *argv[])
     </programlisting>    
   </section>
 
-  <section id="programming-with-grilo-browsinf">
+  <section id="programming-with-grilo-browsing">
     <title>Programming with Grilo: Browsing content</title>
     <para>Here is a small program illustrating how you can browse
       content from a particular media source (a similar approach
@@ -242,4 +249,109 @@ main (int argc, gchar *argv[])
     </programlisting>    
   </section>
 
+  <section id="programming-with-grilo-searching">
+    <title>Programming with Grilo: Searching content</title>
+    <para>Here is a small program illustrating how you can search
+      content by text from a particular media source (Jamendo
+      in this example):</para>
+    <programlisting role="C">
+<![CDATA[
+#include <grilo.h>
+#include <string.h>
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "example"
+
+static void
+search_cb (GrlMediaSource *source,
+	   guint browse_id,
+	   GrlMedia *media,
+	   guint remaining,
+	   gpointer user_data,
+	   const GError *error)
+{
+  if (error) {
+    g_error ("Search operation failed. Reason: %s", error->message);
+  }
+
+  if (media) {
+    const gchar *title = grl_media_get_title (media);
+    if (GRL_IS_MEDIA_BOX (media)) {
+      guint childcount = grl_media_box_get_childcount (GRL_MEDIA_BOX (media));
+      g_debug ("\t Got '%s' (container with %d elements)", title, childcount);
+    } else {
+      guint seconds = grl_media_get_duration (media);
+      const gchar *url = grl_media_get_url (media);
+      g_debug ("\t Got '%s' (media - length: %d seconds)", title, seconds);
+      g_debug ("\t\t URL: %s", url);
+    }
+  }
+
+  if (remaining == 0) {
+    g_debug ("Search operation finished!");
+  } else {
+    g_debug ("\t%d results remaining!", remaining);
+  }
+}
+
+static void
+source_added_cb (GrlPluginRegistry *registry, gpointer user_data)
+{
+  const gchar *id;
+  GrlMetadataSource *source = GRL_METADATA_SOURCE (user_data);
+  GList * keys = grl_metadata_key_list_new (GRL_METADATA_KEY_TITLE,
+					    GRL_METADATA_KEY_DURATION,
+					    GRL_METADATA_KEY_CHILDCOUNT,
+					    NULL);
+
+  /* Not interested if not searchable */
+  if (!(grl_metadata_source_supported_operations (source) & GRL_OP_SEARCH))
+    return;
+
+  g_debug ("Detected new searchable source available: '%s'",
+	   grl_metadata_source_get_name (source));
+
+  /* Only interested in Jamendo */
+  id = grl_metadata_source_get_id (source);
+  if (strcmp (id, "grl-jamendo"))
+    return;
+
+  g_debug ("Searching \"rock\" in Jamendo");
+  grl_media_source_search (GRL_MEDIA_SOURCE (source),
+			   "rock",
+			   keys,
+			   0, 5,
+			   GRL_RESOLVE_IDLE_RELAY,
+			   search_cb, 
+			   NULL);
+}
+
+static void
+load_plugins (void)
+{
+  GrlPluginRegistry *registry;
+
+  registry = grl_plugin_registry_get_instance ();
+  g_signal_connect (registry, "source-added",
+		    G_CALLBACK (source_added_cb), NULL);
+  if (!grl_plugin_registry_load_all (registry)) {
+    g_error ("Failed to load plugins.");
+  }
+}
+
+gint
+main (int argc, gchar *argv[])
+{
+  GMainLoop *loop;
+  g_type_init ();
+  grl_log_init ("example:*");
+  load_plugins ();
+  loop = g_main_loop_new (NULL, FALSE);
+  g_main_loop_run (loop);
+  return 0;
+}
+]]>
+    </programlisting>    
+  </section>
+
 </section>



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