diff options
author | Marinus Schraal <mschraal@gnome.org> | 2018-07-31 10:31:39 +0200 |
---|---|---|
committer | Victor Toso <me@victortoso.com> | 2018-08-03 22:30:46 +0200 |
commit | d9c8b9f630f56893fd58a6cbda18695182b9f03c (patch) | |
tree | a65cb4578134b6f0a54d23db1776dd6300e9323e | |
parent | 991ce3cd76d6bc961586d5af51b09d7c20022ef8 (diff) | |
download | grilo-d9c8b9f630f56893fd58a6cbda18695182b9f03c.tar.gz |
registry: Glob pattern matching for plugin ranks
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
https://gitlab.gnome.org/GNOME/grilo/merge_requests/17
-rw-r--r-- | doc/grilo/environment-setup.xml | 16 | ||||
-rw-r--r-- | src/grl-registry.c | 16 |
2 files changed, 32 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..27fd41c 100644 --- a/src/grl-registry.c +++ b/src/grl-registry.c @@ -380,9 +380,25 @@ 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; + gpointer key, value; + + g_hash_table_iter_init(&iter, registry->priv->ranks); + + while (g_hash_table_iter_next (&iter, &key, &value)) { + if (g_pattern_match_simple (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); } |