Skip to content
Permalink
Browse files
Add API for asking whether the pool is empty
On certain systems a refresh is necessary in such cases and, in any
case, it's useful to know whether queries are pointless.
  • Loading branch information
aleixpol committed Feb 24, 2023
1 parent 03e0231 commit a66c038
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 1 deletion.
@@ -249,6 +249,11 @@ bool Pool::addComponent(const AppStream::Component& cpt)
return addComponents(cpts);
}

bool AppStream::Pool::isEmpty() const
{
return as_pool_get_components_is_empty(d->pool);
}

uint Pool::cacheFlags() const
{
#pragma GCC diagnostic push
@@ -159,6 +159,8 @@ class APPSTREAMQT_EXPORT Pool : public QObject
void overrideCacheLocations(const QString &sysDir,
const QString &userDir);

bool isEmpty() const;

Q_DECL_DEPRECATED bool addComponent(const AppStream::Component& cpt);

Q_DECL_DEPRECATED uint cacheFlags() const;
@@ -1995,3 +1995,16 @@ as_cache_search (AsCache *cache, const gchar * const *terms, gboolean sort, GErr

return g_steal_pointer (&results);
}

gboolean
as_cache_get_is_empty(AsCache* cache)
{
g_autoptr(GError) error = NULL;
g_autoptr(GPtrArray) components = as_cache_query_components (cache,
"components/component",
NULL,
0,
FALSE,
&error);
return components->len > 0;
}
@@ -193,6 +193,8 @@ GPtrArray *as_cache_search (AsCache *cache,
gboolean sort,
GError **error);

gboolean as_cache_get_is_empty(AsCache *cache);

G_END_DECLS

#endif /* __AS_CACHE_H */
@@ -2888,6 +2888,13 @@ as_pool_set_load_std_data_locations (AsPool *pool, gboolean enabled)
}
}

gboolean
as_pool_get_components_is_empty(AsPool* pool)
{
AsPoolPrivate *priv = GET_PRIVATE (pool);
return as_cache_get_is_empty(priv->cache);
}

/**
* as_pool_get_os_metadata_cache_age:
* @pool: An instance of #AsPool.
@@ -181,6 +181,8 @@ void as_pool_remove_flags (AsPool *pool,
void as_pool_set_load_std_data_locations (AsPool *pool,
gboolean enabled);

gboolean as_pool_get_components_is_empty(AsPool *pool);

/* DEPRECATED */

gboolean as_pool_add_component (AsPool *pool,
@@ -266,7 +266,6 @@ test_cache (void)
NULL,
&error);
g_assert_no_error (error);
g_assert_true (ret);


/* new cache for loading */
@@ -486,6 +485,8 @@ test_pool_read (void)
cpt_s = AS_COMPONENT (g_ptr_array_index (result, 0));
g_assert_cmpstr (as_component_get_id (cpt_s), ==, "org.inkscape.Inkscape");
g_clear_pointer (&result, g_ptr_array_unref);

g_assert_false (as_pool_get_components_is_empty(dpool));
}

/**

0 comments on commit a66c038

Please sign in to comment.