summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-08-09 17:57:45 +0200
committerRichard Hughes <richard@hughsie.com>2014-08-09 18:02:52 +0200
commit36c4d159b7f0b3cc9f2b6b4bb413daeaa3270a3e (patch)
tree03d02a304c51a54bf1b128ef18ebfee14e21bfc7
parent6ed3e8502439779f6af48f6668d8ac0570d27b74 (diff)
downloadappstream-glib-36c4d159b7f0b3cc9f2b6b4bb413daeaa3270a3e.tar.gz
Add AS_STORE_LOAD_FLAG_ALLOW_VETO
This allows us to add applications to the AsStore that would normally not be added because they have been vetoed.
-rw-r--r--libappstream-glib/as-store.c24
-rw-r--r--libappstream-glib/as-store.h2
2 files changed, 18 insertions, 8 deletions
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index 27cf106..768db83 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -1153,9 +1153,13 @@ as_store_load_app_install (AsStore *store,
* as_store_load_installed:
**/
static gboolean
-as_store_load_installed (AsStore *store, const gchar *path,
- GCancellable *cancellable, GError **error)
+as_store_load_installed (AsStore *store,
+ AsStoreLoadFlags flags,
+ const gchar *path,
+ GCancellable *cancellable,
+ GError **error)
{
+ AsAppParseFlags parse_flags = AS_APP_PARSE_FLAG_USE_HEURISTICS;
AsStorePrivate *priv = GET_PRIVATE (store);
GError *error_local = NULL;
const gchar *tmp;
@@ -1165,6 +1169,10 @@ as_store_load_installed (AsStore *store, const gchar *path,
if (dir == NULL)
return FALSE;
+ /* relax the checks when parsing */
+ if (flags & AS_STORE_LOAD_FLAG_ALLOW_VETO)
+ parse_flags |= AS_APP_PARSE_FLAG_ALLOW_VETO;
+
while ((tmp = g_dir_read_name (dir)) != NULL) {
AsApp *app_tmp;
_cleanup_free_ gchar *filename = NULL;
@@ -1182,9 +1190,7 @@ as_store_load_installed (AsStore *store, const gchar *path,
}
}
app = as_app_new ();
- if (!as_app_parse_file (app, filename,
- AS_APP_PARSE_FLAG_USE_HEURISTICS,
- &error_local)) {
+ if (!as_app_parse_file (app, filename, parse_flags, &error_local)) {
if (g_error_matches (error_local,
AS_APP_ERROR,
AS_APP_ERROR_INVALID_TYPE)) {
@@ -1198,7 +1204,8 @@ as_store_load_installed (AsStore *store, const gchar *path,
}
/* do not load applications with NoDisplay=true */
- if (as_app_get_metadata_item (app, "NoDisplay") != NULL)
+ if ((flags & AS_STORE_LOAD_FLAG_ALLOW_VETO) == 0 &&
+ as_app_get_vetos(app)->len > 0)
continue;
/* set lower priority than AppStream entries */
@@ -1227,7 +1234,8 @@ gboolean
as_store_load_path (AsStore *store, const gchar *path,
GCancellable *cancellable, GError **error)
{
- return as_store_load_installed (store, path, cancellable, error);
+ return as_store_load_installed (store, AS_STORE_LOAD_FLAG_NONE,
+ path, cancellable, error);
}
/**
@@ -1312,7 +1320,7 @@ as_store_load (AsStore *store,
dest = g_build_filename (priv->destdir ? priv->destdir : "/", tmp, NULL);
if (!g_file_test (dest, G_FILE_TEST_EXISTS))
continue;
- if (!as_store_load_installed (store, dest, cancellable, error))
+ if (!as_store_load_installed (store, flags, dest, cancellable, error))
return FALSE;
}
diff --git a/libappstream-glib/as-store.h b/libappstream-glib/as-store.h
index c9f9c21..edc00bb 100644
--- a/libappstream-glib/as-store.h
+++ b/libappstream-glib/as-store.h
@@ -71,6 +71,7 @@ struct _AsStoreClass
* @AS_STORE_LOAD_FLAG_APP_INSTALL: The ubuntu-specific app-install data
* @AS_STORE_LOAD_FLAG_APPDATA: The installed AppData files
* @AS_STORE_LOAD_FLAG_DESKTOP: The installed desktop files
+ * @AS_STORE_LOAD_FLAG_ALLOW_VETO: Add vetoed applications
*
* The flags to use when loading the store.
**/
@@ -81,6 +82,7 @@ typedef enum {
AS_STORE_LOAD_FLAG_APP_INSTALL = 4, /* Since: 0.1.2 */
AS_STORE_LOAD_FLAG_APPDATA = 8, /* Since: 0.2.2 */
AS_STORE_LOAD_FLAG_DESKTOP = 16, /* Since: 0.2.2 */
+ AS_STORE_LOAD_FLAG_ALLOW_VETO = 32, /* Since: 0.2.5 */
/*< private >*/
AS_STORE_LOAD_FLAG_LAST
} AsStoreLoadFlags;