[grilo] grl-inspect: Print list of available keys



commit 88bb9eb3a01242d4e41cc705d1311371f5ee7fb8
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Mon Mar 25 00:30:01 2013 +0000

    grl-inspect: Print list of available keys

 configure.ac                      |  1 +
 src/grl-metadata-key.h            |  2 +-
 tools/grilo-inspect/Makefile.am   |  9 ++++-
 tools/grilo-inspect/grl-inspect.c | 77 +++++++++++++++++++++++++++++++++++----
 4 files changed, 79 insertions(+), 10 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d19d041..0918b54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,7 @@ AC_CONFIG_SRCDIR([src])
 
 AC_CONFIG_HEADERS([src/config.h])
 
+AC_PROG_AWK
 AC_PROG_CC
 AC_PROG_INSTALL
 
diff --git a/src/grl-metadata-key.h b/src/grl-metadata-key.h
index 1880be1..f525054 100644
--- a/src/grl-metadata-key.h
+++ b/src/grl-metadata-key.h
@@ -36,7 +36,6 @@
 #define GRL_METADATA_KEY_GET_TYPE(key) (grl_metadata_key_get_type (key))
 
 #define GRL_KEYID_FORMAT "u"
-#define GRL_METADATA_KEY_INVALID 0
 
 #define GRLPOINTER_TO_KEYID(p) (GPOINTER_TO_UINT(p))
 #define GRLKEYID_TO_POINTER(k) (GUINT_TO_POINTER(k))
@@ -46,6 +45,7 @@ typedef guint32 GrlKeyID;
 #define g_value_get_grl_key_id(value) ((GrlKeyID) g_value_get_uint(value))
 #define g_value_set_grl_key_id(value,key) g_value_set_uint(value,(guint)key)
 
+#define GRL_METADATA_KEY_INVALID              0
 
 #define GRL_METADATA_KEY_ALBUM                1
 #define GRL_METADATA_KEY_ARTIST               2
diff --git a/tools/grilo-inspect/Makefile.am b/tools/grilo-inspect/Makefile.am
index 142da96..169fe8e 100644
--- a/tools/grilo-inspect/Makefile.am
+++ b/tools/grilo-inspect/Makefile.am
@@ -5,9 +5,14 @@
 #
 # Copyright (C) 2010 Igalia S.L.
 
+grl-core-keys.h: $(top_builddir)/src/grl-metadata-key.h
+       $(AWK) 'BEGIN { printf "gchar *grl_core_keys[] = {\n" } { if ( $$2 ~ /^GRL_METADATA_KEY_/ && $$2 !~ 
/_GET_/ ) printf "\""$$2"\",\n" } END { printf "};\n" }' $< > $@
+
 INCLUDES = $(DEPS_CFLAGS)
 
-bin_PROGRAMS = grl-inspect- GRL_MAJORMINOR@
+bin_PROGRAMS =                 \
+       grl-core-keys.h \
+       grl-inspect- GRL_MAJORMINOR@
 
 grl_inspect_ GRL_MAJORMINOR@_SOURCES = \
        grl-inspect.c
@@ -22,6 +27,8 @@ grl_inspect_ GRL_MAJORMINOR@_LDADD =  \
        $(GTK_LIBS)                                                                     \
        $(top_builddir)/src/lib GRL_NAME@.la
 
+noinst_HEADERS = grl-core-keys.h
+
 MAINTAINERCLEANFILES = \
        *.in                                            \
        *~
diff --git a/tools/grilo-inspect/grl-inspect.c b/tools/grilo-inspect/grl-inspect.c
index c38003f..c0e7905 100644
--- a/tools/grilo-inspect/grl-inspect.c
+++ b/tools/grilo-inspect/grl-inspect.c
@@ -24,16 +24,18 @@
 #include <glib.h>
 
 #include "config.h"
+#include "grl-core-keys.h"
 
 #define GRL_LOG_DOMAIN_DEFAULT grl_inspect_log_domain
 GRL_LOG_DOMAIN_STATIC(grl_inspect_log_domain);
 
 static gint delay = 1;
 static GMainLoop *mainloop = NULL;
-static gchar **introspect_sources = NULL;
+static gchar **introspect_elements = NULL;
 static gchar *conffile = NULL;
 static GrlRegistry *registry = NULL;
 static gboolean version;
+static gboolean keys;
 
 static GOptionEntry entries[] = {
   { "delay", 'd', 0,
@@ -44,13 +46,17 @@ static GOptionEntry entries[] = {
     G_OPTION_ARG_STRING, &conffile,
     "Configuration file to send to sources",
     NULL },
+  { "keys", 'k', 0,
+    G_OPTION_ARG_NONE, &keys,
+    "List available metadata keys in the system",
+    NULL },
   { "version", 'V', 0,
     G_OPTION_ARG_NONE, &version,
     "Print version",
     NULL },
   { G_OPTION_REMAINING, '\0', 0,
-    G_OPTION_ARG_STRING_ARRAY, &introspect_sources,
-    "Sources to introspect",
+    G_OPTION_ARG_STRING_ARRAY, &introspect_elements,
+    "Elements to introspect",
     NULL },
   { NULL }
 };
@@ -78,6 +84,37 @@ list_all_sources (void)
   g_list_free (sources);
 }
 
+static gint
+compare_keys (gpointer key1, gpointer key2)
+{
+  const gchar *key1_name =
+    grl_metadata_key_get_name (GRLPOINTER_TO_KEYID (key1));
+  const gchar *key2_name =
+    grl_metadata_key_get_name (GRLPOINTER_TO_KEYID (key2));
+
+  return g_strcmp0 (key1_name, key2_name);
+}
+
+static void
+list_all_keys (void)
+{
+  GList *keys;
+  GList *keys_iter;
+
+  keys = grl_registry_get_metadata_keys (registry);
+
+  keys = g_list_sort (keys, (GCompareFunc) compare_keys);
+
+  for (keys_iter = keys; keys_iter;
+       keys_iter = g_list_next (keys_iter)) {
+    GrlKeyID key = GRLPOINTER_TO_KEYID (keys_iter->data);
+    g_print ("%s:  %s\n",
+             grl_metadata_key_get_name (key),
+             grl_metadata_key_get_desc (key));
+  }
+  g_list_free (keys);
+}
+
 static void
 print_keys (const GList *keys)
 {
@@ -194,17 +231,41 @@ introspect_source (const gchar *source_id)
   g_print ("\n");
 }
 
+static void
+introspect_key (const gchar *key_name)
+{
+  GrlKeyID key;
+
+  key = grl_registry_lookup_metadata_key (registry, key_name);
+
+  if (key) {
+  } else {
+    g_printerr ("Metadata Key Not Found: %s\n\n", key_name);
+  }
+  g_print ("\n");
+}
+
 static gboolean
 run (gpointer data)
 {
   gchar **s;
 
-  if (introspect_sources) {
-    for (s = introspect_sources; *s; s++) {
-      introspect_source (*s);
+  if (keys) {
+    if (introspect_elements) {
+      for (s = introspect_elements; *s; s++) {
+        introspect_key (*s);
+      }
+    } else {
+        list_all_keys ();
     }
   } else {
-    list_all_sources ();
+    if (introspect_elements) {
+      for (s = introspect_elements; *s; s++) {
+        introspect_source (*s);
+      }
+    } else {
+      list_all_sources ();
+    }
   }
 
   g_main_loop_quit (mainloop);
@@ -218,7 +279,7 @@ main (int argc, char *argv[])
   GError *error = NULL;
   GOptionContext *context;
 
-  context = g_option_context_new ("- introspect Grilo sources");
+  context = g_option_context_new ("- introspect Grilo elements");
   g_option_context_add_main_entries (context, entries, NULL);
   g_option_context_add_group (context, grl_init_get_option_group ());
   g_option_context_parse (context, &argc, &argv, &error);


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