Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for asking whether the pool is empty #466

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 Mar 15, 2023
commit c8de3707e8696411a7d24ec73de846d30b2bae47
@@ -249,6 +249,11 @@ bool Pool::addComponent(const AppStream::Component& cpt)
return addComponents(cpts);
}

bool AppStream::Pool::isEmpty() const
{
return as_pool_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);
}

guint
as_cache_get_component_count (AsCache* cache)
{
g_autoptr(GError) error = NULL;
g_autoptr(GPtrArray) components = as_cache_query_components (cache,
aleixpol marked this conversation as resolved.
Show resolved Hide resolved
"components/component",
NULL,
0,
FALSE,
&error);
return components->len;
}
@@ -193,6 +193,8 @@ GPtrArray *as_cache_search (AsCache *cache,
gboolean sort,
GError **error);

guint as_cache_get_component_count (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_is_empty (AsPool* pool)
{
AsPoolPrivate *priv = GET_PRIVATE (pool);
return as_cache_get_component_count (priv->cache) == 0;
}

/**
* 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_is_empty (AsPool *pool);

/* DEPRECATED */

gboolean as_pool_add_component (AsPool *pool,
@@ -486,6 +486,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_is_empty (dpool));
}

/**