Commit d5d78df1 authored by Richard Hughes's avatar Richard Hughes

fwupd: Use custom GsApp GType

parent d81b8f1e
Pipeline #132158 passed with stage
in 3 minutes and 8 seconds
......@@ -12,44 +12,82 @@
#include "gs-fwupd-app.h"
struct _GsFwupdApp
{
GsApp parent_instance;
gchar *device_id;
gchar *update_uri;
gboolean is_locked;
};
G_DEFINE_TYPE (GsFwupdApp, gs_fwupd_app, GS_TYPE_APP)
static gboolean
_g_set_str (gchar **str_ptr, const gchar *new_str)
{
if (*str_ptr == new_str || g_strcmp0 (*str_ptr, new_str) == 0)
return FALSE;
g_free (*str_ptr);
*str_ptr = g_strdup (new_str);
return TRUE;
}
static void
gs_fwupd_app_to_string (GsApp *app, GString *str)
{
GsFwupdApp *self = GS_FWUPD_APP (app);
if (self->device_id != NULL) {
gs_utils_append_key_value (str, 20, "fwupd::device-id",
self->device_id);
}
if (self->update_uri != NULL) {
gs_utils_append_key_value (str, 20, "fwupd::update-uri",
self->update_uri);
}
gs_utils_append_key_value (str, 20, "fwupd::is-locked",
self->is_locked ? "yes" : "no");
}
const gchar *
gs_fwupd_app_get_device_id (GsApp *app)
{
return gs_app_get_metadata_item (app, "fwupd::DeviceID");
GsFwupdApp *self = GS_FWUPD_APP (app);
return self->device_id;
}
const gchar *
gs_fwupd_app_get_update_uri (GsApp *app)
{
return gs_app_get_metadata_item (app, "fwupd::UpdateID");
GsFwupdApp *self = GS_FWUPD_APP (app);
return self->update_uri;
}
gboolean
gs_fwupd_app_get_is_locked (GsApp *app)
{
GVariant *tmp = gs_app_get_metadata_variant (app, "fwupd::IsLocked");
if (tmp == NULL)
return FALSE;
return g_variant_get_boolean (tmp);
GsFwupdApp *self = GS_FWUPD_APP (app);
return self->is_locked;
}
void
gs_fwupd_app_set_device_id (GsApp *app, const gchar *device_id)
{
gs_app_set_metadata (app, "fwupd::DeviceID", device_id);
GsFwupdApp *self = GS_FWUPD_APP (app);
_g_set_str (&self->device_id, device_id);
}
void
gs_fwupd_app_set_update_uri (GsApp *app, const gchar *update_uri)
{
gs_app_set_metadata (app, "fwupd::UpdateID", update_uri);
GsFwupdApp *self = GS_FWUPD_APP (app);
_g_set_str (&self->update_uri, update_uri);
}
void
gs_fwupd_app_set_is_locked (GsApp *app, gboolean is_locked)
{
g_autoptr(GVariant) tmp = g_variant_new_boolean (is_locked);
gs_app_set_metadata_variant (app, "fwupd::IsLocked", tmp);
GsFwupdApp *self = GS_FWUPD_APP (app);
self->is_locked = is_locked;
}
void
......@@ -229,3 +267,32 @@ gs_fwupd_app_set_from_release (GsApp *app, FwupdRelease *rel)
}
#endif
}
static void
gs_fwupd_app_finalize (GObject *object)
{
GsFwupdApp *self = GS_FWUPD_APP (object);
g_free (self->device_id);
g_free (self->update_uri);
G_OBJECT_CLASS (gs_fwupd_app_parent_class)->finalize (object);
}
static void
gs_fwupd_app_class_init (GsFwupdAppClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GsAppClass *klass_app = GS_APP_CLASS (klass);
klass_app->to_string = gs_fwupd_app_to_string;
object_class->finalize = gs_fwupd_app_finalize;
}
static void
gs_fwupd_app_init (GsFwupdApp *self)
{
}
GsApp *
gs_fwupd_app_new (const gchar *id)
{
return GS_APP (g_object_new (GS_TYPE_FWUPD_APP, "id", id, NULL));
}
......@@ -12,6 +12,11 @@
G_BEGIN_DECLS
#define GS_TYPE_FWUPD_APP (gs_fwupd_app_get_type ())
G_DECLARE_FINAL_TYPE (GsFwupdApp, gs_fwupd_app, GS, FWUPD_APP, GsApp)
GsApp *gs_fwupd_app_new (const gchar *id);
const gchar *gs_fwupd_app_get_device_id (GsApp *app);
const gchar *gs_fwupd_app_get_update_uri (GsApp *app);
gboolean gs_fwupd_app_get_is_locked (GsApp *app);
......
......@@ -120,6 +120,12 @@ gs_plugin_destroy (GsPlugin *plugin)
g_object_unref (priv->client);
}
GsApp *
gs_plugin_create_app (GsPlugin *plugin, const gchar *id)
{
return gs_fwupd_app_new (id);
}
void
gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
{
......@@ -225,7 +231,6 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
/* add source */
priv->cached_origin = gs_app_new (gs_plugin_get_name (plugin));
gs_app_set_kind (priv->cached_origin, AS_APP_KIND_SOURCE);
gs_app_set_bundle_kind (priv->cached_origin, AS_BUNDLE_KIND_CABINET);
/* add the source to the plugin cache which allows us to match the
......@@ -272,7 +277,7 @@ gs_plugin_fwupd_new_app_from_device (GsPlugin *plugin, FwupdDevice *dev)
NULL);
app = gs_plugin_cache_lookup (plugin, id);
if (app == NULL) {
app = gs_app_new (id);
app = gs_fwupd_app_new (id);
gs_plugin_cache_add (plugin, id, app);
}
......@@ -321,7 +326,7 @@ gs_plugin_fwupd_new_app_from_device_raw (GsPlugin *plugin, FwupdDevice *device)
/* create a GsApp based on the device, not the release */
id = gs_plugin_fwupd_build_device_id (device);
app = gs_app_new (id);
app = gs_fwupd_app_new (id);
gs_app_set_kind (app, AS_APP_KIND_FIRMWARE);
gs_app_set_scope (app, AS_APP_SCOPE_SYSTEM);
gs_app_set_state (app, AS_APP_STATE_INSTALLED);
......@@ -1036,7 +1041,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
/* create something that we can use to enable/disable */
id = g_strdup_printf ("org.fwupd.%s.remote", fwupd_remote_get_id (remote));
app = gs_app_new (id);
app = gs_fwupd_app_new (id);
gs_app_set_kind (app, AS_APP_KIND_SOURCE);
gs_app_set_scope (app, AS_APP_SCOPE_SYSTEM);
gs_app_set_state (app, fwupd_remote_get_enabled (remote) ?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment