[rygel-grilo] Add configuration file
- From: Juan A. Suarez Romero <jasuarez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel-grilo] Add configuration file
- Date: Wed, 21 Apr 2010 17:51:42 +0000 (UTC)
commit fbc5bb705cf91d397284c4abc5d5ef02c6969145
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Wed Apr 21 19:16:32 2010 +0200
Add configuration file
As some plugins need configuration (for instance, Youtube plugin needs an API
key), create a configuration file to store this and future configurations.
User can copy this file to her home and modify or add new keys or new plugins.
configure.ac | 1 +
data/Makefile.am | 8 ++++-
data/rygel-grilo.conf | 3 ++
src/Makefile.am | 5 ++-
src/rygel-grilo.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 81 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d80a010..daad055 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,6 +74,7 @@ fi
AC_SUBST([abs_top_builddir])
AC_SUBST([builddir])
+AC_SUBST([sysconfdir])
# ----------------------------------------------------------
# OUTPUT
diff --git a/data/Makefile.am b/data/Makefile.am
index 14414e4..a2b8780 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -10,6 +10,10 @@ configdir = $(datadir)/rygel-grilo
config_DATA = \
media-server2.xml
-EXTRA_DIST = \
- $(config_DATA)
+sysconf_DATA = \
+ rygel-grilo.conf
+
+EXTRA_DIST = \
+ $(config_DATA) \
+ $(sysconf_DATA)
diff --git a/data/rygel-grilo.conf b/data/rygel-grilo.conf
new file mode 100644
index 0000000..3411139
--- /dev/null
+++ b/data/rygel-grilo.conf
@@ -0,0 +1,3 @@
+[grl-youtube]
+api-key = AI39si7vmzZRjlZVjsp3e048LGAkxGJ-8ksZtKuM-L5prIScRv7zhUWTHUwF64uof_J7hMktXrxtm5i9BLEalHXTMvdt7Fs83w
+
diff --git a/src/Makefile.am b/src/Makefile.am
index c3fb32c..3f1c872 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,8 +20,9 @@ rygel_grilo_SOURCES = \
rygel-grilo.c
-rygel_grilo_CFLAGS = \
- -DPREFIX=$(prefix) \
+rygel_grilo_CFLAGS = \
+ -DPREFIX=$(prefix) \
+ -DSYSCONFDIR=\"$(sysconfdir)\" \
-I$(top_srcdir)/lib
rygel_grilo_LDADD = \
diff --git a/src/rygel-grilo.c b/src/rygel-grilo.c
index 08f4b6d..d40e01d 100644
--- a/src/rygel-grilo.c
+++ b/src/rygel-grilo.c
@@ -27,6 +27,8 @@
#include <media-server2-server.h>
+#define RYGEL_GRILO_CONFIG_FILE "rygel-grilo.conf"
+
#define ID_PREFIX_AUDIO "gra://"
#define ID_PREFIX_CONTAINER "grc://"
#define ID_PREFIX_IMAGE "gri://"
@@ -34,6 +36,7 @@
#define ID_SEPARATOR "/"
static GList *providers_names = NULL;
+static GrlPluginRegistry *registry = NULL;
static gchar **args;
static gboolean dups;
@@ -548,13 +551,71 @@ source_removed_cb (GrlPluginRegistry *registry, gpointer user_data)
}
}
+/* Load plugins configuration */
+static void
+load_config ()
+{
+ GError *error = NULL;
+ GKeyFile *keyfile;
+ GrlConfig *config;
+ gchar **key;
+ gchar **keys;
+ gchar **plugin;
+ gchar **plugins;
+ gchar **search_paths;
+ gchar *value;
+
+ keyfile = g_key_file_new ();
+
+ search_paths = g_new0 (gchar *, 3);
+ search_paths[0] = g_build_filename (g_get_user_config_dir (),
+ "rygel-grilo",
+ NULL);
+ search_paths[1] = g_strdup (SYSCONFDIR);
+
+ if (!g_key_file_load_from_dirs (keyfile,
+ RYGEL_GRILO_CONFIG_FILE,
+ (const gchar **) search_paths,
+ NULL,
+ G_KEY_FILE_NONE,
+ &error)) {
+ g_warning ("Unable to load configuration. %s", error->message);
+ g_error_free (error);
+ g_key_file_free (keyfile);
+ g_strfreev (search_paths);
+ return;
+ }
+
+ g_strfreev (search_paths);
+
+ /* Look up for defined plugins */
+ plugins = g_key_file_get_groups (keyfile, NULL);
+ for (plugin = plugins; *plugin; plugin++) {
+ config = grl_config_new (*plugin, NULL);
+
+ /* Look up for keys in this plugin */
+ keys = g_key_file_get_keys (keyfile, *plugin, NULL, NULL);
+ for (key = keys; *key; key++) {
+ value = g_key_file_get_string (keyfile, *plugin, *key, NULL);
+ if (value) {
+ grl_config_set_string (config, *key, value);
+ g_free (value);
+ }
+ }
+ grl_plugin_registry_add_config (registry, config);
+ g_strfreev (keys);
+ }
+
+ g_strfreev (plugins);
+ g_key_file_free (keyfile);
+}
+
/* Main program */
gint
main (gint argc, gchar **argv)
{
GError *error = NULL;
GOptionContext *context = NULL;
- GrlPluginRegistry *registry;
gint i;
g_type_init ();
@@ -572,6 +633,12 @@ main (gint argc, gchar **argv)
/* Load grilo plugins */
registry = grl_plugin_registry_get_instance ();
+ if (!registry) {
+ g_printerr ("Unable to load Grilo registry\n");
+ return -1;
+ }
+
+ load_config ();
g_signal_connect (registry, "source-added",
G_CALLBACK (source_added_cb), NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]