[gnome-software/wip/hughsie/fwupd_client_modify_remote: 7/7] fwupd: Add a secret search term to show devices from the daemon



commit 4feb54968dc2d024f3ac4c5bc9c47d4841e916e8
Author: Richard Hughes <richard hughsie com>
Date:   Sun Sep 10 13:24:36 2017 +0100

    fwupd: Add a secret search term to show devices from the daemon

 plugins/fwupd/gs-plugin-fwupd.c |  112 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index 4a12bea..17f1a20 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -1064,3 +1064,115 @@ gs_plugin_add_sources (GsPlugin *plugin,
        }
        return TRUE;
 }
+
+static gchar *
+gs_plugin_fwupd_build_device_id (FwupdDevice *dev)
+{
+       g_autofree gchar *tmp = g_strdup (fwupd_device_get_id (dev));
+       g_strdelimit (tmp, "/", '_');
+       return g_strdup_printf ("org.fwupd.%s.device", tmp);
+}
+
+static gboolean
+gs_plugin_fwupd_add_releases (GsPlugin *plugin, GsApp *app,
+                             GCancellable *cancellable, GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       g_autoptr(GError) error_local = NULL;
+       g_autoptr(GPtrArray) releases = NULL;
+
+       releases = fwupd_client_get_releases (priv->client,
+                                             gs_fwupd_app_get_device_id (app),
+                                             cancellable,
+                                             &error_local);
+       if (releases == NULL) {
+               /* just ignore empty array */
+               if (g_error_matches (error_local,
+                                    FWUPD_ERROR,
+                                    FWUPD_ERROR_NOTHING_TO_DO)) {
+                       return TRUE;
+               }
+               g_propagate_error (error, g_steal_pointer (&error_local));
+               return FALSE;
+       }
+       for (guint j = 0; j < releases->len; j++) {
+               FwupdRelease *rel = g_ptr_array_index (releases, j);
+               g_autoptr(GsApp) app2 = gs_plugin_app_new (plugin, NULL);
+               if (fwupd_release_get_appstream_id (rel) == NULL) {
+                       g_warning ("no AppStream ID for release");
+                       continue;
+               }
+               gs_app_set_id (app2, fwupd_release_get_appstream_id (rel));
+               gs_fwupd_app_set_from_release (app2, rel);
+               gs_app_add_history (app, app2);
+       }
+       return TRUE;
+}
+
+static gboolean
+gs_plugin_fwupd_add_devices (GsPlugin *plugin, GsAppList *list,
+                            GCancellable *cancellable, GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       g_autoptr(GPtrArray) devices = NULL;
+
+       /* get devices */
+       devices = fwupd_client_get_devices_simple (priv->client, cancellable, error);
+       if (devices == NULL)
+               return FALSE;
+       for (guint i = 0; i < devices->len; i++) {
+               FwupdDevice *device = g_ptr_array_index (devices, i);
+               GPtrArray *icons;
+               g_autofree gchar *id = NULL;
+               g_autoptr(GsApp) app = NULL;
+
+               /* ignore these, we can't do anything */
+               if (!fwupd_device_has_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE))
+                       continue;
+
+               /* create something that we can use to enable/disable */
+               id = gs_plugin_fwupd_build_device_id (device);
+               app = gs_plugin_app_new (plugin, 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);
+               gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
+               gs_app_set_version (app, fwupd_device_get_version (device));
+               gs_app_set_name (app, GS_APP_QUALITY_LOWEST, fwupd_device_get_name (device));
+               gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, fwupd_device_get_summary (device));
+               gs_app_set_description (app, GS_APP_QUALITY_LOWEST, fwupd_device_get_description (device));
+               gs_app_set_origin (app, fwupd_device_get_vendor (device));
+               gs_app_set_management_plugin (app, "fwupd");
+               gs_fwupd_app_set_device_id (app, fwupd_device_get_id (device));
+               gs_app_list_add (list, app);
+
+               /* create icon */
+               icons = fwupd_device_get_icons (device);
+               for (guint j = 0; j < icons->len; j++) {
+                       const gchar *icon = g_ptr_array_index (icons, j);
+                       g_autoptr(AsIcon) icon_tmp = as_icon_new ();
+                       if (g_str_has_prefix (icon, "/")) {
+                               as_icon_set_kind (icon_tmp, AS_ICON_KIND_LOCAL);
+                               as_icon_set_filename (icon_tmp, icon);
+                       } else {
+                               as_icon_set_kind (icon_tmp, AS_ICON_KIND_STOCK);
+                               as_icon_set_name (icon_tmp, icon);
+                       }
+                       gs_app_add_icon (app, icon_tmp);
+               }
+
+               /* add releases */
+               if (!gs_plugin_fwupd_add_releases (plugin, app, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_add_search (GsPlugin *plugin, gchar **values, GsAppList *list,
+                     GCancellable *cancellable, GError **error)
+{
+       if (g_strv_contains ((const gchar * const *) values, "fwupd"))
+               return gs_plugin_fwupd_add_devices (plugin, list, cancellable, error);
+       return TRUE;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]