diff options
author | Richard Hughes <richard@hughsie.com> | 2015-03-11 13:24:23 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-03-11 13:24:23 +0000 |
commit | 9660f6f137f6c49ce4ce35516fd4a1c1d6e3aa66 (patch) | |
tree | 3383671432713930be09a412fa84a5af086fd371 | |
parent | 2bf28c4157d7a0ae61f30b6864f9f07a2f1ca160 (diff) | |
download | appstream-glib-9660f6f137f6c49ce4ce35516fd4a1c1d6e3aa66.tar.gz |
Add as_store_add_filter()
-rw-r--r-- | libappstream-glib/as-store.c | 54 | ||||
-rw-r--r-- | libappstream-glib/as-store.h | 4 |
2 files changed, 58 insertions, 0 deletions
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c index 5b0df08..8fdc0a4 100644 --- a/libappstream-glib/as-store.c +++ b/libappstream-glib/as-store.c @@ -66,6 +66,7 @@ struct _AsStorePrivate GHashTable *metadata_indexes; /* GHashTable{key} */ AsStoreAddFlags add_flags; AsStoreProblems problems; + guint32 filter; }; G_DEFINE_TYPE_WITH_PRIVATE (AsStore, as_store, G_TYPE_OBJECT) @@ -168,6 +169,47 @@ as_store_class_init (AsStoreClass *klass) } /** + * as_store_add_filter: + * @store: a #AsStore instance. + * @kind: a #AsIdKind, e.g. %AS_ID_KIND_FIRMWARE + * + * Adds a filter to the store so that only components of this type are + * loaded into the store. This may be useful if the client is only interested + * in certain types of component, or not interested in loading components + * it cannot process. + * + * If no filter is set then all types of components are loaded. + * + * Since: 0.3.5 + **/ +void +as_store_add_filter (AsStore *store, AsIdKind kind) +{ + AsStorePrivate *priv = GET_PRIVATE (store); + priv->filter |= 1 << kind; +} + +/** + * as_store_remove_filter: + * @store: a #AsStore instance. + * @kind: a #AsIdKind, e.g. %AS_ID_KIND_FIRMWARE + * + * Removed a filter from the store so that components of this type are no longer + * loaded into the store. This may be useful if the client is only interested + * in certain types of component. + * + * If all filters are removed then all types of components are loaded. + * + * Since: 0.3.5 + **/ +void +as_store_remove_filter (AsStore *store, AsIdKind kind) +{ + AsStorePrivate *priv = GET_PRIVATE (store); + priv->filter &= ~(1 << kind); +} + +/** * as_store_get_size: * @store: a #AsStore instance. * @@ -630,6 +672,18 @@ as_store_from_root (AsStore *store, _cleanup_object_unref_ AsApp *app = NULL; if (as_node_get_tag (n) != AS_TAG_APPLICATION) continue; + + /* do the filtering here */ + if (priv->filter != 0) { + if (g_strcmp0 (as_node_get_name (n), "component") == 0) { + AsIdKind kind_tmp; + tmp = as_node_get_attribute (n, "type"); + kind_tmp = as_id_kind_from_string (tmp); + if ((priv->filter & (1 << kind_tmp)) == 0) + continue; + } + } + app = as_app_new (); if (icon_path != NULL) as_app_set_icon_path (app, icon_path, -1); diff --git a/libappstream-glib/as-store.h b/libappstream-glib/as-store.h index f39c048..ba19fc3 100644 --- a/libappstream-glib/as-store.h +++ b/libappstream-glib/as-store.h @@ -186,6 +186,10 @@ GPtrArray *as_store_validate (AsStore *store, GError **error); void as_store_add_metadata_index (AsStore *store, const gchar *key); +void as_store_add_filter (AsStore *store, + AsIdKind kind); +void as_store_remove_filter (AsStore *store, + AsIdKind kind); G_END_DECLS |