summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libappstream-glib/as-app-private.h3
-rw-r--r--libappstream-glib/as-app.c91
-rw-r--r--libappstream-glib/as-app.h19
-rw-r--r--libappstream-glib/as-self-test.c6
-rw-r--r--libappstream-glib/as-store.c1
5 files changed, 103 insertions, 17 deletions
diff --git a/libappstream-glib/as-app-private.h b/libappstream-glib/as-app-private.h
index 48f8de3..20369a0 100644
--- a/libappstream-glib/as-app-private.h
+++ b/libappstream-glib/as-app-private.h
@@ -32,6 +32,9 @@
G_BEGIN_DECLS
+void as_app_set_source_kind (AsApp *app,
+ AsAppSourceKind source_kind);
+
GNode *as_app_node_insert (AsApp *app,
GNode *parent,
gdouble api_version);
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index b732c39..031f417 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -63,6 +63,7 @@ struct _AsAppPrivate
GPtrArray *architectures; /* of string */
GPtrArray *releases; /* of AsRelease */
GPtrArray *screenshots; /* of AsScreenshot */
+ AsAppSourceKind source_kind;
gchar *icon;
gchar *icon_path;
gchar *id;
@@ -375,6 +376,23 @@ as_app_get_id_kind (AsApp *app)
}
/**
+ * as_app_get_source_kind:
+ * @app: a #AsApp instance.
+ *
+ * Gets the source kind, i.e. where the AsApp came from.
+ *
+ * Returns: enumerated value
+ *
+ * Since: 0.1.4
+ **/
+AsAppSourceKind
+as_app_get_source_kind (AsApp *app)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ return priv->source_kind;
+}
+
+/**
* as_app_get_icon_kind:
* @app: a #AsApp instance.
*
@@ -669,6 +687,22 @@ as_app_set_id_full (AsApp *app, const gchar *id_full, gssize id_full_len)
}
/**
+ * as_app_set_source_kind:
+ * @app: a #AsApp instance.
+ * @source_kind: the #AsAppSourceKind.
+ *
+ * Sets the source kind.
+ *
+ * Since: 0.1.4
+ **/
+void
+as_app_set_source_kind (AsApp *app, AsAppSourceKind source_kind)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ priv->source_kind = source_kind;
+}
+
+/**
* as_app_set_id_kind:
* @app: a #AsApp instance.
* @id_kind: the #AsIdKind.
@@ -2160,23 +2194,13 @@ out:
}
/**
- * as_app_parse_file:
- * @app: a #AsApp instance.
- * @desktop_file: desktop file to load.
- * @flags: #AsAppParseFlags, e.g. %AS_APP_PARSE_FLAG_USE_HEURISTICS
- * @error: A #GError or %NULL.
- *
- * Parses a desktop file and populates the application state.
- *
- * Returns: %TRUE for success
- *
- * Since: 0.1.2
+ * as_app_parse_desktop_file:
**/
-gboolean
-as_app_parse_file (AsApp *app,
- const gchar *desktop_file,
- AsAppParseFlags flags,
- GError **error)
+static gboolean
+as_app_parse_desktop_file (AsApp *app,
+ const gchar *desktop_file,
+ AsAppParseFlags flags,
+ GError **error)
{
GKeyFile *kf;
gboolean ret;
@@ -2239,6 +2263,41 @@ out:
}
/**
+ * as_app_parse_file:
+ * @app: a #AsApp instance.
+ * @filename: file to load.
+ * @flags: #AsAppParseFlags, e.g. %AS_APP_PARSE_FLAG_USE_HEURISTICS
+ * @error: A #GError or %NULL.
+ *
+ * Parses a desktop or AppData file and populates the application state.
+ *
+ * Returns: %TRUE for success
+ *
+ * Since: 0.1.2
+ **/
+gboolean
+as_app_parse_file (AsApp *app,
+ const gchar *filename,
+ AsAppParseFlags flags,
+ GError **error)
+{
+ gboolean ret = FALSE;
+
+ if (g_str_has_suffix (filename, ".desktop")) {
+ as_app_set_source_kind (app, AS_APP_SOURCE_KIND_DESKTOP);
+ ret = as_app_parse_desktop_file (app, filename, flags, error);
+ goto out;
+ }
+ g_set_error (error,
+ AS_APP_ERROR,
+ AS_APP_ERROR_INVALID_TYPE,
+ "%s has an unrecognised type",
+ filename);
+out:
+ return ret;
+}
+
+/**
* as_app_new:
*
* Creates a new #AsApp.
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index d27cb0e..f403357 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -91,6 +91,22 @@ typedef enum {
AS_APP_ERROR_LAST
} AsAppError;
+/**
+ * AsAppSourceKind:
+ * @AS_APP_SOURCE_KIND_UNKNOWN: Not sourced from a file
+ * @AS_APP_SOURCE_KIND_APPSTREAM: Sourced from a AppStream file
+ * @AS_APP_SOURCE_KIND_DESKTOP: Sourced from a desktop file
+ *
+ * The source kind.
+ **/
+typedef enum {
+ AS_APP_SOURCE_KIND_UNKNOWN, /* Since: 0.1.4 */
+ AS_APP_SOURCE_KIND_APPSTREAM, /* Since: 0.1.4 */
+ AS_APP_SOURCE_KIND_DESKTOP, /* Since: 0.1.4 */
+ /*< private >*/
+ AS_APP_SOURCE_KIND_LAST
+} AsAppSourceKind;
+
#define AS_APP_ERROR as_app_error_quark ()
GType as_app_get_type (void);
@@ -100,6 +116,7 @@ GQuark as_app_error_quark (void);
/* getters */
AsIconKind as_app_get_icon_kind (AsApp *app);
AsIdKind as_app_get_id_kind (AsApp *app);
+AsAppSourceKind as_app_get_source_kind (AsApp *app);
GList *as_app_get_languages (AsApp *app);
GPtrArray *as_app_get_categories (AsApp *app);
GPtrArray *as_app_get_compulsory_for_desktops (AsApp *app);
@@ -216,7 +233,7 @@ guint as_app_search_matches_all (AsApp *app,
guint as_app_search_matches (AsApp *app,
const gchar *search);
gboolean as_app_parse_file (AsApp *app,
- const gchar *desktop_file,
+ const gchar *filename,
AsAppParseFlags flags,
GError **error);
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 63aceca..fd41389 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -322,6 +322,7 @@ ch_test_app_func (void)
g_assert_cmpstr (as_app_get_comment (app, NULL), ==, "Application manager");
g_assert_cmpstr (as_app_get_icon (app), ==, "org.gnome.Software.png");
g_assert_cmpint (as_app_get_icon_kind (app), ==, AS_ICON_KIND_CACHED);
+ g_assert_cmpint (as_app_get_source_kind (app), ==, AS_APP_SOURCE_KIND_UNKNOWN);
g_assert_cmpstr (as_app_get_project_group (app), ==, "GNOME");
g_assert_cmpstr (as_app_get_project_license (app), ==, "GPLv2+");
g_assert_cmpint (as_app_get_categories(app)->len, ==, 1);
@@ -820,6 +821,7 @@ ch_test_store_func (void)
static void
ch_test_store_versions_func (void)
{
+ AsApp *app;
AsStore *store;
GError *error = NULL;
gboolean ret;
@@ -845,6 +847,10 @@ ch_test_store_versions_func (void)
g_assert_cmpfloat (as_store_get_api_version (store), <, 0.4 + 0.01);
g_assert_cmpfloat (as_store_get_api_version (store), >, 0.4 - 0.01);
+ /* verify source kind */
+ app = as_store_get_app_by_id (store, "test.desktop");
+ g_assert_cmpint (as_app_get_source_kind (app), ==, AS_APP_SOURCE_KIND_APPSTREAM);
+
/* test with latest features */
as_store_set_api_version (store, 0.6);
g_assert_cmpfloat (as_store_get_api_version (store), <, 0.6 + 0.01);
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index 5b3be13..7415c9e 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -383,6 +383,7 @@ as_store_from_root (AsStore *store,
app = as_app_new ();
if (icon_path != NULL)
as_app_set_icon_path (app, icon_path, -1);
+ as_app_set_source_kind (app, AS_APP_SOURCE_KIND_APPSTREAM);
ret = as_app_node_parse (app, n, &error_local);
if (!ret) {
g_set_error (error,