summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarinus Schraal <mschraal@gnome.org>2018-07-31 10:31:39 +0200
committerMarinus Schraal <mschraal@gnome.org>2018-08-02 16:20:34 +0200
commitf2826aedbfb77ad900f40c09b1ef5685b06f38c3 (patch)
tree97d71ff2c9b2a0ddea2bc255861aa5606298153f
parent991ce3cd76d6bc961586d5af51b09d7c20022ef8 (diff)
downloadgrilo-wip/mschraal/plugin-ranks-glob.tar.gz
registry: Glob pattern matching for plugin rankswip/mschraal/plugin-ranks-glob
Source names can be constructed partially with unique identifiers, making it difficult to match directly to the static identifiers in GRL_PLUGIN_RANKS. Introduce glob pattern matching for GRL_PLUGIN_RANKS, which allows for example GRL_PLUGIN_RANKS="grl-lastfm-cover*:3". Add a short explanation and example to the documentation as well. https://bugzilla.gnome.org/show_bug.cgi?id=761695
-rw-r--r--doc/grilo/environment-setup.xml16
-rw-r--r--src/grl-registry.c17
2 files changed, 33 insertions, 0 deletions
diff --git a/doc/grilo/environment-setup.xml b/doc/grilo/environment-setup.xml
index b2a90ae..96267af 100644
--- a/doc/grilo/environment-setup.xml
+++ b/doc/grilo/environment-setup.xml
@@ -150,5 +150,21 @@ $ export GRL_DEBUG=registry:*,youtube:warning
$ export GRL_PLUGIN_RANKS=youtube:5,bookmarks:-4
</programlisting>
+ <para>
+ Some plugins extend their plugin name with login specific identifiers.
+ To match these plugins the ranks environment variable allows for simple
+ glob pattern matching with the '?' and '*' wildcards. This can of course
+ also be used in other situations.
+ Here is one example:
+ </para>
+
+ <programlisting>
+# Set the rank of all coverart plugins to 2, but the Last.FM
+# coverart plugin whether logged in or not to 5.
+# Note that order is important here: the ranks are interpreted from
+# right to left.
+$ export GRL_PLUGIN_RANKS=grl-lastfm-cover*:5,*cover*:2
+ </programlisting>
+
</section>
</section>
diff --git a/src/grl-registry.c b/src/grl-registry.c
index a6189b7..afb9772 100644
--- a/src/grl-registry.c
+++ b/src/grl-registry.c
@@ -380,9 +380,26 @@ set_source_rank (GrlRegistry *registry, GrlSource *source)
rank =
GPOINTER_TO_INT (g_hash_table_lookup (registry->priv->ranks,
grl_source_get_id (source)));
+
+ if (!rank) {
+ GHashTableIter iter;
+ const gchar *key = NULL;
+ gpointer value;
+
+ g_hash_table_iter_init(&iter, registry->priv->ranks);
+
+ while (g_hash_table_iter_next (&iter, (gpointer *) &key, &value)) {
+ if (g_pattern_match_simple ((const gchar*) key, grl_source_get_id (source))) {
+ rank = GPOINTER_TO_INT (value);
+ break;
+ }
+ }
+ }
+
if (!rank) {
rank = GRL_RANK_DEFAULT;
}
+
g_object_set (source, "rank", rank, NULL);
GRL_DEBUG ("Source rank '%s' : %d", grl_source_get_id (source), rank);
}