static GsApp* gs_plugin_app_from_pki (LiPkgInfo *pki) { const gchar *cptkind_str; GsApp *app; cptkind_str = li_pkg_info_get_component_kind (pki); if ((cptkind_str != NULL) && (g_strcmp0 (cptkind_str, "desktop") == 0)) { g_autofree gchar *tmp = NULL; /* type=desktop AppStream components result in a Limba bundle name which has the .desktop stripped away. * We need to re-add it for GNOME Software. * In any other case, the Limba bundle name equals the AppStream ID of the component it contains */ tmp = g_strdup_printf ("%s.desktop", li_pkg_info_get_name (pki)); app = gs_app_new (tmp); gs_app_set_kind (app, AS_APP_KIND_DESKTOP); } else { app = gs_app_new (li_pkg_info_get_name (pki)); gs_app_set_kind (app, AS_APP_KIND_GENERIC); } /* TODO: scope?, branch? */ gs_app_set_management_plugin (app, "limba"); gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE); gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_LIMBA); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, li_pkg_info_get_name (pki)); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, li_pkg_info_get_name (pki)); gs_app_set_version (app, li_pkg_info_get_version (pki)); gs_app_add_source (app, li_pkg_info_get_id (pki)); return app; }
/** * gs_plugin_refine_app: */ static gboolean gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error) { LiPkgInfo *pki; g_autoptr(GError) error_local = NULL; /* sanity check */ if (gs_app_get_source_default (app) == NULL) return TRUE; pki = li_manager_get_software_by_pkid (plugin->priv->mgr, gs_app_get_source_default (app), &error_local); if (error_local != NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Unable to refine metadata: %s", error_local->message); return FALSE; } if (pki == NULL) return TRUE; if (li_pkg_info_has_flag (pki, LI_PACKAGE_FLAG_INSTALLED)) gs_app_set_state (app, AS_APP_STATE_INSTALLED); else gs_app_set_state (app, AS_APP_STATE_AVAILABLE); gs_app_set_version (app, li_pkg_info_get_version (pki)); return TRUE; }
gboolean gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); LiPkgInfo *pki; g_autoptr(GError) error_local = NULL; g_autoptr(AsProfileTask) ptask = NULL; /* not us */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* profile */ ptask = as_profile_start (gs_plugin_get_profile (plugin), "limba::refine{%s}", gs_app_get_id (app)); /* sanity check */ if (gs_app_get_source_default (app) == NULL) return TRUE; pki = li_manager_get_software_by_pkid (priv->mgr, gs_app_get_source_default (app), &error_local); if (error_local != NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Unable to refine metadata: %s", error_local->message); return FALSE; } if (pki == NULL) return TRUE; if (li_pkg_info_has_flag (pki, LI_PACKAGE_FLAG_INSTALLED)) gs_app_set_state (app, AS_APP_STATE_INSTALLED); else gs_app_set_state (app, AS_APP_STATE_AVAILABLE); gs_app_set_version (app, li_pkg_info_get_version (pki)); return TRUE; }
gboolean gs_plugin_add_updates (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autoptr(GList) updates = NULL; GList *l; g_autoptr(GError) error_local = NULL; updates = li_manager_get_update_list (priv->mgr, &error_local); if (error_local != NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Failed to list updates: %s", error_local->message); return FALSE; } for (l = updates; l != NULL; l = l->next) { LiPkgInfo *old_pki; LiPkgInfo *new_pki; g_autoptr(GsApp) app = NULL; LiUpdateItem *uitem = LI_UPDATE_ITEM (l->data); old_pki = li_update_item_get_installed_pkg (uitem); new_pki = li_update_item_get_available_pkg (uitem); app = gs_plugin_app_from_pki (old_pki); gs_app_set_update_version (app, li_pkg_info_get_version (new_pki)); gs_app_list_add (list, app); } return TRUE; }
/** * gs_plugin_add_updates: */ gboolean gs_plugin_add_updates (GsPlugin *plugin, GList **list, GCancellable *cancellable, GError **error) { g_autoptr(GList) updates = NULL; GList *l; g_autoptr(GError) error_local = NULL; updates = li_manager_get_update_list (plugin->priv->mgr, &error_local); if (error_local != NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Failed to list updates: %s", error_local->message); return FALSE; } for (l = updates; l != NULL; l = l->next) { LiPkgInfo *old_pki; LiPkgInfo *new_pki; const gchar *cptkind_str; g_autoptr(GsApp) app = NULL; LiUpdateItem *uitem = LI_UPDATE_ITEM (l->data); old_pki = li_update_item_get_installed_pkg (uitem); new_pki = li_update_item_get_available_pkg (uitem); cptkind_str = li_pkg_info_get_component_kind (old_pki); if ((cptkind_str != NULL) && (g_strcmp0 (cptkind_str, "desktop") == 0)) { g_autofree gchar *tmp = NULL; /* type=desktop AppStream components result in a Limba bundle name which has the .desktop stripped away. * We need to re-add it for GNOME Software. * In any other case, the Limba bundle name equals the AppStream ID of the component it contains */ tmp = g_strdup_printf ("%s.desktop", li_pkg_info_get_name (old_pki)); app = gs_app_new (tmp); gs_app_set_kind (app, AS_APP_KIND_DESKTOP); } else { app = gs_app_new (li_pkg_info_get_name (old_pki)); } gs_app_set_management_plugin (app, "Limba"); gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE); gs_app_set_kind (app, AS_APP_KIND_GENERIC); gs_plugin_add_app (list, app); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, li_pkg_info_get_name (old_pki)); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, li_pkg_info_get_name (old_pki)); gs_app_set_version (app, li_pkg_info_get_version (old_pki)); gs_app_set_update_version (app, li_pkg_info_get_version (new_pki)); gs_app_add_source (app, li_pkg_info_get_id (old_pki)); gs_plugin_add_app (list, app); } return TRUE; }