[gnome-software/wip/hughsie/lets-break-the-world] fwupd: Port to the version 1.0 API
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/lets-break-the-world] fwupd: Port to the version 1.0 API
- Date: Sun, 17 Sep 2017 19:27:29 +0000 (UTC)
commit 574787a4ae74ac10b4d53a8c94fd99086bbf53fa
Author: Richard Hughes <richard hughsie com>
Date: Sun Sep 17 12:58:47 2017 +0100
fwupd: Port to the version 1.0 API
plugins/fwupd/gs-plugin-fwupd.c | 104 +++++++++++++++++++++++++++++++++++++++
1 files changed, 104 insertions(+), 0 deletions(-)
---
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index 112efbd..f0a2fd6 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -150,10 +150,16 @@ gs_plugin_fwupd_changed_cb (FwupdClient *client, GsPlugin *plugin)
static void
gs_plugin_fwupd_device_changed_cb (FwupdClient *client,
+#if FWUPD_CHECK_VERSION(1,0,0)
+ FwupdDevice *dev,
+#else
FwupdResult *res,
+#endif
GsPlugin *plugin)
{
+#if !FWUPD_CHECK_VERSION(1,0,0)
FwupdDevice *dev = fwupd_result_get_device (res);
+#endif
/* fwupd >= 0.7.1 supports per-device signals, and also the
* SUPPORTED flag -- so we can limit number of UI refreshes */
@@ -345,11 +351,18 @@ gs_plugin_fwupd_add_required_location (GsPlugin *plugin, const gchar *location)
g_ptr_array_add (priv->to_download, g_strdup (location));
}
+#if FWUPD_CHECK_VERSION(1,0,0)
+static GsApp *
+gs_plugin_fwupd_new_app_from_device (GsPlugin *plugin, FwupdDevice *dev)
+{
+ FwupdRelease *rel = fwupd_device_get_release_default (dev);
+#else
static GsApp *
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);
+#endif
GsApp *app;
g_autofree gchar *id = NULL;
g_autoptr(AsIcon) icon = NULL;
@@ -397,11 +410,19 @@ gs_plugin_fwupd_new_app_from_results (GsPlugin *plugin, FwupdResult *res)
static gboolean
gs_plugin_add_update_app (GsPlugin *plugin,
GsAppList *list,
+#if FWUPD_CHECK_VERSION(1,0,0)
+ FwupdDevice *dev,
+#else
FwupdResult *res,
+#endif
gboolean is_downloaded,
GError **error)
{
+#if FWUPD_CHECK_VERSION(1,0,0)
+ FwupdRelease *rel = fwupd_device_get_release_default (dev);
+#else
FwupdRelease *rel = fwupd_result_get_release (res);
+#endif
GPtrArray *checksums;
const gchar *update_uri;
g_autofree gchar *basename = NULL;
@@ -410,7 +431,11 @@ gs_plugin_add_update_app (GsPlugin *plugin,
g_autoptr(GsApp) app = NULL;
/* update unsupported */
+#if FWUPD_CHECK_VERSION(1,0,0)
+ app = gs_plugin_fwupd_new_app_from_device (plugin, dev);
+#else
app = gs_plugin_fwupd_new_app_from_results (plugin, res);
+#endif
if (gs_app_get_state (app) != AS_APP_STATE_UPDATABLE_LIVE) {
g_set_error (error,
GS_PLUGIN_ERROR,
@@ -529,14 +554,26 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GError) error_local = NULL;
g_autoptr(GsApp) app = NULL;
+#if FWUPD_CHECK_VERSION(1,0,0)
+ g_autoptr(FwupdDevice) dev = NULL;
+#else
g_autoptr(FwupdResult) res = NULL;
+#endif
/* get historical updates */
+#if FWUPD_CHECK_VERSION(1,0,0)
+ dev = fwupd_client_get_results (priv->client,
+ FWUPD_DEVICE_ID_ANY,
+ cancellable,
+ &error_local);
+ if (dev == NULL) {
+#else
res = fwupd_client_get_results (priv->client,
FWUPD_DEVICE_ID_ANY,
cancellable,
&error_local);
if (res == NULL) {
+#endif
if (g_error_matches (error_local,
FWUPD_ERROR,
FWUPD_ERROR_NOTHING_TO_DO))
@@ -552,7 +589,11 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
}
/* parse */
+#if FWUPD_CHECK_VERSION(1,0,0)
+ app = gs_plugin_fwupd_new_app_from_device (plugin, dev);
+#else
app = gs_plugin_fwupd_new_app_from_results (plugin, res);
+#endif
gs_app_list_add (list, app);
return TRUE;
}
@@ -566,12 +607,23 @@ gs_plugin_fwupd_add_updates (GsPlugin *plugin,
{
GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GError) error_local = NULL;
+#if FWUPD_CHECK_VERSION(1,0,0)
+ g_autoptr(GPtrArray) devices = NULL;
+#else
g_autoptr(GPtrArray) results = NULL;
+#endif
/* get current list of updates */
+#if FWUPD_CHECK_VERSION(1,0,0)
+ devices = fwupd_client_get_upgrades_all (priv->client,
+ cancellable,
+ &error_local);
+ if (devices == NULL) {
+#else
results = fwupd_client_get_updates (priv->client,
cancellable, &error_local);
if (results == NULL) {
+#endif
if (g_error_matches (error_local,
FWUPD_ERROR,
FWUPD_ERROR_NOTHING_TO_DO))
@@ -583,9 +635,14 @@ gs_plugin_fwupd_add_updates (GsPlugin *plugin,
}
/* parse */
+#if FWUPD_CHECK_VERSION(1,0,0)
+ for (guint i = 0; i < devices->len; i++) {
+ FwupdDevice *dev = g_ptr_array_index (devices, i);
+#else
for (guint i = 0; i < results->len; i++) {
FwupdResult *res = g_ptr_array_index (results, i);
FwupdDevice *dev = fwupd_result_get_device (res);
+#endif
g_autoptr(GError) error_local2 = NULL;
/* locked device that needs unlocking */
@@ -593,16 +650,26 @@ gs_plugin_fwupd_add_updates (GsPlugin *plugin,
g_autoptr(GsApp) app = NULL;
if (!is_downloaded)
continue;
+#if FWUPD_CHECK_VERSION(1,0,0)
+ app = gs_plugin_fwupd_new_app_from_device (plugin, dev);
+#else
app = gs_plugin_fwupd_new_app_from_results (plugin, res);
+#endif
gs_fwupd_app_set_is_locked (app, TRUE);
gs_app_list_add (list, app);
continue;
}
/* normal device update */
+#if FWUPD_CHECK_VERSION(1,0,0)
+ if (!gs_plugin_add_update_app (plugin, list, dev,
+ is_downloaded, &error_local2))
+ g_debug ("%s", error_local2->message);
+#else
if (!gs_plugin_add_update_app (plugin, list, res,
is_downloaded, &error_local2))
g_debug ("%s", error_local2->message);
+#endif
}
return TRUE;
@@ -728,12 +795,21 @@ gs_plugin_fwupd_refresh_remote (GsPlugin *plugin,
}
/* phew, lets send all this to fwupd */
+#if FWUPD_CHECK_VERSION(1,0,0)
+ if (!fwupd_client_update_metadata (priv->client,
+ fwupd_remote_get_id (remote),
+ filename,
+ filename_asc,
+ cancellable,
+ error)) {
+#else
if (!fwupd_client_update_metadata_with_id (priv->client,
fwupd_remote_get_id (remote),
filename,
filename_asc,
cancellable,
error)) {
+#endif
gs_plugin_fwupd_error_convert (error);
return FALSE;
}
@@ -988,7 +1064,11 @@ gs_plugin_file_to_app (GsPlugin *plugin,
GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *content_type = NULL;
g_autofree gchar *filename = NULL;
+#if FWUPD_CHECK_VERSION(1,0,0)
+ g_autoptr(GPtrArray) devices = NULL;
+#else
g_autoptr(GPtrArray) results = NULL;
+#endif
const gchar *mimetypes[] = {
"application/vnd.ms-cab-compressed",
NULL };
@@ -1002,6 +1082,29 @@ gs_plugin_file_to_app (GsPlugin *plugin,
/* get results */
filename = g_file_get_path (file);
+#if FWUPD_CHECK_VERSION(1,0,0)
+ devices = fwupd_client_get_details (priv->client,
+ filename,
+ cancellable,
+ error);
+ if (devices == NULL) {
+ gs_plugin_fwupd_error_convert (error);
+ return FALSE;
+ }
+ for (guint i = 0; i < devices->len; i++) {
+ FwupdDevice *dev = g_ptr_array_index (devices, i);
+ g_autoptr(GsApp) app = NULL;
+
+ /* create each app */
+ app = gs_plugin_fwupd_new_app_from_device (plugin, dev);
+
+ /* we have no update view for local files */
+ gs_app_set_version (app, gs_app_get_update_version (app));
+ gs_app_set_description (app, GS_APP_QUALITY_NORMAL,
+ gs_app_get_update_details (app));
+ gs_app_list_add (list, app);
+ }
+#else
results = fwupd_client_get_details_local (priv->client,
filename,
cancellable,
@@ -1023,6 +1126,7 @@ gs_plugin_file_to_app (GsPlugin *plugin,
gs_app_get_update_details (app));
gs_app_list_add (list, app);
}
+#endif
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]