[gnome-software] trivial: Factor out some fwupd code for future use



commit 6f17aab146d4496e3ce58bcfe316cc33d74e8368
Author: Richard Hughes <richard hughsie com>
Date:   Sat Sep 9 20:09:18 2017 +0100

    trivial: Factor out some fwupd code for future use

 plugins/fwupd/gs-fwupd-app.c    |   90 +++++++++++++++++++++++++++++++++++++++
 plugins/fwupd/gs-fwupd-app.h    |    4 ++
 plugins/fwupd/gs-plugin-fwupd.c |   83 +-----------------------------------
 3 files changed, 96 insertions(+), 81 deletions(-)
---
diff --git a/plugins/fwupd/gs-fwupd-app.c b/plugins/fwupd/gs-fwupd-app.c
index 3ed2697..c9e84e4 100644
--- a/plugins/fwupd/gs-fwupd-app.c
+++ b/plugins/fwupd/gs-fwupd-app.c
@@ -99,6 +99,96 @@ gs_fwupd_app_set_is_locked (GsApp *app, gboolean is_locked)
        fwupd_app->is_locked = is_locked;
 }
 
+void
+gs_fwupd_app_set_from_device (GsApp *app, FwupdDevice *dev)
+{
+       GPtrArray *guids;
+
+       /* something can be done */
+       if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE))
+               gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE);
+
+       /* only can be applied in systemd-offline */
+       if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_ONLY_OFFLINE))
+               gs_app_set_metadata (app, "fwupd::OnlyOffline", "");
+
+
+       /* reboot required to apply update */
+       if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_REBOOT))
+               gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_REBOOT);
+
+       /* is removable */
+       if (!fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_INTERNAL))
+               gs_app_add_quirk (app, AS_APP_QUIRK_REMOVABLE_HARDWARE);
+
+       guids = fwupd_device_get_guids (dev);
+       if (guids->len > 0) {
+               g_autofree gchar *guid_str = NULL;
+               g_auto(GStrv) tmp = g_new0 (gchar *, guids->len + 1);
+               for (guint i = 0; i < guids->len; i++)
+                       tmp[i] = g_strdup (g_ptr_array_index (guids, i));
+               guid_str = g_strjoinv (",", tmp);
+               gs_app_set_metadata (app, "fwupd::Guid", guid_str);
+       }
+       if (fwupd_device_get_version (dev) != NULL) {
+               gs_app_set_version (app, fwupd_device_get_version (dev));
+       }
+       if (fwupd_device_get_created (dev) != 0)
+               gs_app_set_install_date (app, fwupd_device_get_created (dev));
+       if (fwupd_device_get_description (dev) != NULL) {
+               g_autofree gchar *tmp = NULL;
+               tmp = as_markup_convert (fwupd_device_get_description (dev),
+                                        AS_MARKUP_CONVERT_FORMAT_SIMPLE, NULL);
+               if (tmp != NULL)
+                       gs_app_set_description (app, GS_APP_QUALITY_NORMAL, tmp);
+       }
+
+       /* needs action */
+       if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_BOOTLOADER))
+               gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_USER_ACTION);
+       else
+               gs_app_remove_quirk (app, AS_APP_QUIRK_NEEDS_USER_ACTION);
+}
+
+void
+gs_fwupd_app_set_from_release (GsApp *app, FwupdRelease *rel)
+{
+       if (fwupd_release_get_name (rel) != NULL) {
+               gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
+                                fwupd_release_get_name (rel));
+       }
+       if (fwupd_release_get_summary (rel) != NULL) {
+               gs_app_set_summary (app, GS_APP_QUALITY_NORMAL,
+                                   fwupd_release_get_summary (rel));
+       }
+       if (fwupd_release_get_homepage (rel) != NULL) {
+               gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
+                               fwupd_release_get_homepage (rel));
+       }
+       if (fwupd_release_get_size (rel) != 0) {
+               gs_app_set_size_installed (app, 0);
+               gs_app_set_size_download (app, fwupd_release_get_size (rel));
+       }
+       if (fwupd_release_get_version (rel) != NULL)
+               gs_app_set_update_version (app, fwupd_release_get_version (rel));
+       if (fwupd_release_get_license (rel) != NULL) {
+               gs_app_set_license (app, GS_APP_QUALITY_NORMAL,
+                                   fwupd_release_get_license (rel));
+       }
+       if (fwupd_release_get_uri (rel) != NULL) {
+               gs_app_set_origin_hostname (app,
+                                           fwupd_release_get_uri (rel));
+               gs_fwupd_app_set_update_uri (app, fwupd_release_get_uri (rel));
+       }
+       if (fwupd_release_get_description (rel) != NULL) {
+               g_autofree gchar *tmp = NULL;
+               tmp = as_markup_convert (fwupd_release_get_description (rel),
+                                        AS_MARKUP_CONVERT_FORMAT_SIMPLE, NULL);
+               if (tmp != NULL)
+                       gs_app_set_update_details (app, tmp);
+       }
+}
+
 static void
 gs_fwupd_app_finalize (GObject *object)
 {
diff --git a/plugins/fwupd/gs-fwupd-app.h b/plugins/fwupd/gs-fwupd-app.h
index dc93f77..d79cefd 100644
--- a/plugins/fwupd/gs-fwupd-app.h
+++ b/plugins/fwupd/gs-fwupd-app.h
@@ -41,6 +41,10 @@ void                  gs_fwupd_app_set_update_uri            (GsApp          *app,
                                                                 const gchar    *update_uri);
 void                    gs_fwupd_app_set_is_locked             (GsApp          *app,
                                                                 gboolean        is_locked);
+void                    gs_fwupd_app_set_from_device           (GsApp          *app,
+                                                                FwupdDevice    *dev);
+void                    gs_fwupd_app_set_from_release          (GsApp          *app,
+                                                                FwupdRelease   *rel);
 
 G_END_DECLS
 
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index 6d6fe1f..3d71015 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -351,7 +351,6 @@ gs_plugin_fwupd_new_app_from_results (GsPlugin *plugin, FwupdResult *res)
        FwupdDevice *dev = fwupd_result_get_device (res);
        FwupdRelease *rel = fwupd_result_get_release (res);
        GsApp *app;
-       GPtrArray *guids;
        const gchar *id;
        g_autoptr(AsIcon) icon = NULL;
 
@@ -370,95 +369,17 @@ gs_plugin_fwupd_new_app_from_results (GsPlugin *plugin, FwupdResult *res)
        gs_app_add_category (app, "System");
        gs_fwupd_app_set_device_id (app, fwupd_device_get_id (dev));
 
-       /* something can be done */
-       if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE))
-               gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE);
-
-       /* only can be applied in systemd-offline */
-       if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_ONLY_OFFLINE))
-               gs_app_set_metadata (app, "fwupd::OnlyOffline", "");
-
-
-       /* reboot required to apply update */
-       if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_REBOOT))
-               gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_REBOOT);
-
-       /* is removable */
-       if (!fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_INTERNAL))
-               gs_app_add_quirk (app, AS_APP_QUIRK_REMOVABLE_HARDWARE);
-
        /* create icon */
        icon = as_icon_new ();
        as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
        as_icon_set_name (icon, "application-x-firmware");
        gs_app_add_icon (app, icon);
+       gs_fwupd_app_set_from_release (app, rel);
+       gs_fwupd_app_set_from_device (app, dev);
 
        if (fwupd_release_get_appstream_id (rel) != NULL)
                gs_app_set_id (app, fwupd_release_get_appstream_id (rel));
 
-       guids = fwupd_device_get_guids (dev);
-       if (guids->len > 0) {
-               guint i;
-               g_autofree gchar *guid_str = NULL;
-               g_auto(GStrv) tmp = g_new0 (gchar *, guids->len + 1);
-               for (i = 0; i < guids->len; i++)
-                       tmp[i] = g_strdup (g_ptr_array_index (guids, i));
-               guid_str = g_strjoinv (",", tmp);
-               gs_app_set_metadata (app, "fwupd::Guid", guid_str);
-       }
-       if (fwupd_release_get_name (rel) != NULL) {
-               gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
-                                fwupd_release_get_name (rel));
-       }
-       if (fwupd_release_get_summary (rel) != NULL) {
-               gs_app_set_summary (app, GS_APP_QUALITY_NORMAL,
-                                   fwupd_release_get_summary (rel));
-       }
-       if (fwupd_release_get_homepage (rel) != NULL) {
-               gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
-                               fwupd_release_get_homepage (rel));
-       }
-       if (fwupd_device_get_version (dev) != NULL) {
-               gs_app_set_version (app, fwupd_device_get_version (dev));
-       }
-       if (fwupd_release_get_size (rel) != 0) {
-               gs_app_set_size_installed (app, 0);
-               gs_app_set_size_download (app, fwupd_release_get_size (rel));
-       }
-       if (fwupd_device_get_created (dev) != 0)
-               gs_app_set_install_date (app, fwupd_device_get_created (dev));
-       if (fwupd_release_get_version (rel) != NULL)
-               gs_app_set_update_version (app, fwupd_release_get_version (rel));
-       if (fwupd_release_get_license (rel) != NULL) {
-               gs_app_set_license (app, GS_APP_QUALITY_NORMAL,
-                                   fwupd_release_get_license (rel));
-       }
-       if (fwupd_release_get_uri (rel) != NULL) {
-               gs_app_set_origin_hostname (app,
-                                           fwupd_release_get_uri (rel));
-               gs_fwupd_app_set_update_uri (app, fwupd_release_get_uri (rel));
-       }
-       if (fwupd_device_get_description (dev) != NULL) {
-               g_autofree gchar *tmp = NULL;
-               tmp = as_markup_convert (fwupd_device_get_description (dev),
-                                        AS_MARKUP_CONVERT_FORMAT_SIMPLE, NULL);
-               if (tmp != NULL)
-                       gs_app_set_description (app, GS_APP_QUALITY_NORMAL, tmp);
-       }
-       if (fwupd_release_get_description (rel) != NULL) {
-               g_autofree gchar *tmp = NULL;
-               tmp = as_markup_convert (fwupd_release_get_description (rel),
-                                        AS_MARKUP_CONVERT_FORMAT_SIMPLE, NULL);
-               if (tmp != NULL)
-                       gs_app_set_update_details (app, tmp);
-       }
-
-       /* needs action */
-       if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_BOOTLOADER))
-               gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_USER_ACTION);
-       else
-               gs_app_remove_quirk (app, AS_APP_QUIRK_NEEDS_USER_ACTION);
-
        /* the same as we have already */
        if (g_strcmp0 (fwupd_device_get_version (dev),
                       fwupd_release_get_version (rel)) == 0) {


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