lib/ref: Add collection ID support to FlatpakRef

This adds a new collection-id property which is only enabled if
FLATPAK_ENABLE_P2P is defined. The internal machinery for handling it is
always enabled, to reduce the amount of #ifdef spam.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
tingping/wmclass
Philip Withnall 2017-06-30 11:34:55 +01:00 committed by Alexander Larsson
parent 5b002edf06
commit 4c395cec13
3 changed files with 53 additions and 1 deletions

View File

@ -54,6 +54,7 @@ struct _FlatpakRefPrivate
char *branch;
char *commit;
FlatpakRefKind kind;
char *collection_id;
};
G_DEFINE_TYPE_WITH_PRIVATE (FlatpakRef, flatpak_ref, G_TYPE_OBJECT)
@ -65,7 +66,8 @@ enum {
PROP_ARCH,
PROP_BRANCH,
PROP_COMMIT,
PROP_KIND
PROP_KIND,
PROP_COLLECTION_ID,
};
static void
@ -117,6 +119,11 @@ flatpak_ref_set_property (GObject *object,
priv->kind = g_value_get_enum (value);
break;
case PROP_COLLECTION_ID:
g_clear_pointer (&priv->collection_id, g_free);
priv->collection_id = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -154,6 +161,10 @@ flatpak_ref_get_property (GObject *object,
g_value_set_enum (value, priv->kind);
break;
case PROP_COLLECTION_ID:
g_value_set_string (value, priv->collection_id);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -205,6 +216,16 @@ flatpak_ref_class_init (FlatpakRefClass *klass)
FLATPAK_TYPE_REF_KIND,
FLATPAK_REF_KIND_APP,
G_PARAM_READWRITE));
#ifdef FLATPAK_ENABLE_P2P
g_object_class_install_property (object_class,
PROP_COLLECTION_ID,
g_param_spec_string ("collection-id",
"Collection ID",
"The collection ID",
NULL,
G_PARAM_READWRITE));
#endif /* FLATPAK_ENABLE_P2P */
}
static void
@ -361,3 +382,21 @@ flatpak_ref_parse (const char *ref, GError **error)
"branch", parts[3],
NULL));
}
#ifdef FLATPAK_ENABLE_P2P
/**
* flatpak_ref_get_collection_id:
* @self: a #FlatpakRef
*
* Gets the collection ID of the ref.
*
* Returns: (transfer none): the collection ID
*/
const char *
flatpak_ref_get_collection_id (FlatpakRef *self)
{
FlatpakRefPrivate *priv = flatpak_ref_get_instance_private (self);
return priv->collection_id;
}
#endif /* FLATPAK_ENABLE_P2P */

View File

@ -71,4 +71,8 @@ FLATPAK_EXTERN char * flatpak_ref_format_ref (FlatpakRef *self);
FLATPAK_EXTERN FlatpakRef * flatpak_ref_parse (const char *ref,
GError **error);
#ifdef FLATPAK_ENABLE_P2P
FLATPAK_EXTERN const char * flatpak_ref_get_collection_id (FlatpakRef *self);
#endif /* FLATPAK_ENABLE_P2P */
#endif /* __FLATPAK_REF_H__ */

View File

@ -202,6 +202,9 @@ test_ref (void)
g_assert_cmpstr (flatpak_ref_get_name (ref), ==, "org.flatpak.Hello");
g_assert_cmpstr (flatpak_ref_get_arch (ref), ==, "x86_64");
g_assert_cmpstr (flatpak_ref_get_branch (ref), ==, "master");
#ifdef FLATPAK_ENABLE_P2P
g_assert_null (flatpak_ref_get_collection_id (ref));
#endif /* FLATPAK_ENABLE_P2P */
formatted = flatpak_ref_format_ref (ref);
g_assert_cmpstr (formatted, ==, valid);
@ -407,6 +410,9 @@ test_install_launch_uninstall (void)
g_assert_cmpstr (flatpak_ref_get_arch (FLATPAK_REF (ref)), ==, flatpak_get_default_arch ());
g_assert_cmpstr (flatpak_ref_get_branch (FLATPAK_REF (ref)), ==, "master");
g_assert_cmpint (flatpak_ref_get_kind (FLATPAK_REF (ref)), ==, FLATPAK_REF_KIND_RUNTIME);
#ifdef FLATPAK_ENABLE_P2P
g_assert_null (flatpak_ref_get_collection_id (FLATPAK_REF (ref)));
#endif /* FLATPAK_ENABLE_P2P */
g_assert_cmpuint (flatpak_installed_ref_get_installed_size (ref), >, 0);
@ -452,6 +458,9 @@ test_install_launch_uninstall (void)
g_assert_cmpstr (flatpak_ref_get_arch (FLATPAK_REF (ref)), ==, flatpak_get_default_arch ());
g_assert_cmpstr (flatpak_ref_get_branch (FLATPAK_REF (ref)), ==, "master");
g_assert_cmpint (flatpak_ref_get_kind (FLATPAK_REF (ref)), ==, FLATPAK_REF_KIND_APP);
#ifdef FLATPAK_ENABLE_P2P
g_assert_null (flatpak_ref_get_collection_id (FLATPAK_REF (ref)));
#endif /* FLATPAK_ENABLE_P2P */
g_assert_cmpuint (flatpak_installed_ref_get_installed_size (ref), >, 0);
g_assert_true (flatpak_installed_ref_get_is_current (ref));