gboolean gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); /* 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 * unique ID to a GsApp when creating an event */ gs_plugin_cache_add (plugin, gs_app_get_unique_id (priv->cached_origin), priv->cached_origin); /* register D-Bus errors */ fwupd_error_quark (); g_signal_connect (priv->client, "changed", G_CALLBACK (gs_plugin_fwupd_changed_cb), plugin); g_signal_connect (priv->client, "device-added", G_CALLBACK (gs_plugin_fwupd_device_changed_cb), plugin); g_signal_connect (priv->client, "device-removed", G_CALLBACK (gs_plugin_fwupd_device_changed_cb), plugin); g_signal_connect (priv->client, "device-changed", G_CALLBACK (gs_plugin_fwupd_device_changed_cb), plugin); g_signal_connect (priv->client, "notify::percentage", G_CALLBACK (gs_plugin_fwupd_notify_percentage_cb), plugin); g_signal_connect (priv->client, "notify::status", G_CALLBACK (gs_plugin_fwupd_notify_status_cb), plugin); return TRUE; }
static GsApp * snap_to_app (GsPlugin *plugin, SnapdSnap *snap) { GsPluginData *priv = gs_plugin_get_data (plugin); GStrv common_ids; g_autofree gchar *appstream_id = NULL; g_autofree gchar *unique_id = NULL; g_autoptr(GsApp) app = NULL; SnapdConfinement confinement; /* Get the AppStream ID from the snap, or generate a fallback one */ common_ids = snapd_snap_get_common_ids (snap); if (g_strv_length (common_ids) == 1) appstream_id = g_strdup (common_ids[0]); else appstream_id = g_strdup_printf ("io.snapcraft.%s-%s", snapd_snap_get_name (snap), snapd_snap_get_id (snap)); switch (snapd_snap_get_snap_type (snap)) { case SNAPD_SNAP_TYPE_APP: unique_id = g_strdup_printf ("system/snap/*/desktop/%s/*", appstream_id); break; case SNAPD_SNAP_TYPE_KERNEL: case SNAPD_SNAP_TYPE_GADGET: case SNAPD_SNAP_TYPE_OS: unique_id = g_strdup_printf ("system/snap/*/runtime/%s/*", appstream_id); break; default: case SNAPD_SNAP_TYPE_UNKNOWN: unique_id = g_strdup_printf ("system/snap/*/*/%s/*", appstream_id); break; } app = gs_plugin_cache_lookup (plugin, unique_id); if (app == NULL) { app = gs_app_new (NULL); gs_app_set_from_unique_id (app, unique_id); gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_SNAP); gs_app_set_metadata (app, "snap::name", snapd_snap_get_name (snap)); gs_plugin_cache_add (plugin, unique_id, app); } gs_app_set_management_plugin (app, "snap"); if (gs_app_get_kind (app) != AS_APP_KIND_DESKTOP) gs_app_add_quirk (app, GS_APP_QUIRK_NOT_LAUNCHABLE); if (gs_plugin_check_distro_id (plugin, "ubuntu")) gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE); confinement = snapd_snap_get_confinement (snap); if (confinement != SNAPD_CONFINEMENT_UNKNOWN) { GEnumClass *enum_class = g_type_class_ref (SNAPD_TYPE_CONFINEMENT); gs_app_set_metadata (app, "snap::confinement", g_enum_get_value (enum_class, confinement)->value_nick); g_type_class_unref (enum_class); } if (priv->system_confinement == SNAPD_SYSTEM_CONFINEMENT_STRICT && confinement == SNAPD_CONFINEMENT_STRICT) gs_app_add_kudo (app, GS_APP_KUDO_SANDBOXED); return g_steal_pointer (&app); }
gboolean gs_plugin_add_updates (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { guint i; g_autoptr(GError) error_local = NULL; g_auto(GStrv) package_ids = NULL; /* get the id's if the file exists */ package_ids = pk_offline_get_prepared_ids (&error_local); if (package_ids == NULL) { if (g_error_matches (error_local, PK_OFFLINE_ERROR, PK_OFFLINE_ERROR_NO_DATA)) { return TRUE; } g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_INVALID_FORMAT, "Failed to get prepared IDs: %s", error_local->message); return FALSE; } /* add them to the new array */ for (i = 0; package_ids[i] != NULL; i++) { g_autoptr(GsApp) app = NULL; g_auto(GStrv) split = NULL; /* search in the cache */ app = gs_plugin_cache_lookup (plugin, package_ids[i]); if (app != NULL) { gs_app_list_add (list, app); continue; } /* create new app */ app = gs_app_new (NULL); gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_REBOOT); gs_app_set_management_plugin (app, "packagekit"); gs_app_add_source_id (app, package_ids[i]); split = pk_package_id_split (package_ids[i]); gs_app_add_source (app, split[PK_PACKAGE_ID_NAME]); gs_app_set_update_version (app, split[PK_PACKAGE_ID_VERSION]); gs_app_set_state (app, AS_APP_STATE_UPDATABLE); gs_app_set_kind (app, AS_APP_KIND_GENERIC); gs_app_set_size_download (app, 0); gs_app_list_add (list, app); /* save in the cache */ gs_plugin_cache_add (plugin, package_ids[i], app); } return TRUE; }
void gs_plugin_initialize (GsPlugin *plugin) { GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData)); g_autoptr(GError) error = NULL; g_autoptr(GsOsRelease) os_release = NULL; priv->settings = g_settings_new ("org.gnome.software"); priv->review_server = g_settings_get_string (priv->settings, "review-server"); priv->ratings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_array_unref); /* get the machine+user ID hash value */ priv->user_hash = gs_utils_get_user_hash (&error); if (priv->user_hash == NULL) { g_warning ("Failed to get machine+user hash: %s", error->message); return; } /* get the distro name (e.g. 'Fedora') but allow a fallback */ os_release = gs_os_release_new (&error); if (os_release != NULL) { priv->distro = g_strdup (gs_os_release_get_name (os_release)); if (priv->distro == NULL) { g_warning ("no distro name specified"); priv->distro = g_strdup ("Unknown"); } } else { g_warning ("failed to get distro name: %s", error->message); priv->distro = g_strdup ("Unknown"); } /* 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_origin_hostname (priv->cached_origin, priv->review_server); gs_app_set_origin_ui (priv->cached_origin, "Open Desktop Review Server"); /* add the source to the plugin cache which allows us to match the * unique ID to a GsApp when creating an event */ gs_plugin_cache_add (plugin, gs_app_get_unique_id (priv->cached_origin), priv->cached_origin); /* need application IDs and version */ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream"); gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "flatpak-system"); gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "flatpak-user"); /* set name of MetaInfo file */ gs_plugin_set_appstream_id (plugin, "org.gnome.Software.Plugin.Odrs"); }
static GsApp * gs_plugin_fwupd_new_app_from_device (GsPlugin *plugin, FwupdDevice *dev) { FwupdRelease *rel = fwupd_device_get_release_default (dev); GsApp *app; g_autofree gchar *id = NULL; g_autoptr(AsIcon) icon = NULL; /* older versions of fwups didn't record this for historical devices */ if (fwupd_release_get_appstream_id (rel) == NULL) return NULL; /* get from cache */ id = as_utils_unique_id_build (AS_APP_SCOPE_SYSTEM, AS_BUNDLE_KIND_UNKNOWN, NULL, /* origin */ AS_APP_KIND_FIRMWARE, fwupd_release_get_appstream_id (rel), NULL); app = gs_plugin_cache_lookup (plugin, id); if (app == NULL) { app = gs_app_new (id); gs_plugin_cache_add (plugin, id, app); } /* default stuff */ gs_app_set_kind (app, AS_APP_KIND_FIRMWARE); gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_CABINET); gs_app_add_quirk (app, GS_APP_QUIRK_NOT_LAUNCHABLE); gs_app_set_management_plugin (app, "fwupd"); gs_app_add_category (app, "System"); gs_fwupd_app_set_device_id (app, fwupd_device_get_id (dev)); /* 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)); /* the same as we have already */ if (g_strcmp0 (fwupd_device_get_version (dev), fwupd_release_get_version (rel)) == 0) { g_warning ("same firmware version as installed"); } return app; }
gboolean gs_plugin_add_popular (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { guint i; const gchar *apps[] = { "org.gnome.Builder.desktop", "org.gnome.Calculator.desktop", "org.gnome.clocks.desktop", "org.gnome.Dictionary.desktop", "org.gnome.Documents.desktop", "org.gnome.Evince.desktop", "org.gnome.gedit.desktop", "org.gnome.Maps.desktop", "org.gnome.Weather.desktop", NULL }; /* we've already got enough popular apps */ if (gs_app_list_length (list) >= 5) return TRUE; /* just add all */ g_debug ("using hardcoded as only %u apps", gs_app_list_length (list)); for (i = 0; apps[i] != NULL; i++) { g_autoptr(GsApp) app = NULL; /* look in the cache */ app = gs_plugin_cache_lookup (plugin, apps[i]); if (app != NULL) { gs_app_list_add (list, app); continue; } /* create new */ app = gs_app_new (apps[i]); gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX); gs_app_set_metadata (app, "GnomeSoftware::Creator", gs_plugin_get_name (plugin)); gs_app_list_add (list, app); /* save in the cache */ gs_plugin_cache_add (plugin, apps[i], app); } return TRUE; }
gboolean gs_plugin_add_featured (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { guint i; /* we've already got enough featured apps */ if (gs_app_list_length (list) >= 5) return TRUE; /* just add all */ g_debug ("using hardcoded as only %u apps", gs_app_list_length (list)); for (i = 0; myapps[i].id != NULL; i++) { g_autoptr(GsApp) app = NULL; /* look in the cache */ app = gs_plugin_cache_lookup (plugin, myapps[i].id); if (app != NULL) { gs_app_list_add (list, app); continue; } /* create new */ app = gs_app_new (myapps[i].id); gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX); gs_app_set_metadata (app, "GnomeSoftware::Creator", gs_plugin_get_name (plugin)); gs_app_set_metadata (app, "GnomeSoftware::FeatureTile-css", myapps[i].css); gs_app_list_add (list, app); /* save in the cache */ gs_plugin_cache_add (plugin, myapps[i].id, app); } return TRUE; }
static GsApp * gs_plugin_generic_updates_get_os_update (GsPlugin *plugin) { GsApp *app; const gchar *id = "org.gnome.Software.OsUpdate"; g_autoptr(AsIcon) ic = NULL; /* look in cache */ app = gs_plugin_cache_lookup (plugin, id); if (app != NULL) return app; /* create new */ app = gs_app_new (id); gs_app_add_quirk (app, AS_APP_QUIRK_IS_PROXY); gs_app_set_management_plugin (app, ""); gs_app_set_kind (app, AS_APP_KIND_OS_UPDATE); gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE); gs_app_set_name (app, GS_APP_QUALITY_NORMAL, /* TRANSLATORS: this is a group of updates that are not * packages and are not shown in the main list */ _("OS Updates")); gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, /* TRANSLATORS: this is a longer description of the * "OS Updates" string */ _("Includes performance, stability and security improvements.")); gs_app_set_description (app, GS_APP_QUALITY_NORMAL, gs_app_get_summary (app)); ic = as_icon_new (); as_icon_set_kind (ic, AS_ICON_KIND_STOCK); as_icon_set_name (ic, "software-update-available-symbolic"); gs_app_add_icon (app, ic); gs_plugin_cache_add (plugin, id, app); return app; }
gboolean gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); const gchar *verstr = NULL; gchar *endptr = NULL; g_autoptr(GFile) file = NULL; g_autoptr(GsOsRelease) os_release = NULL; /* get the file to cache */ priv->cachefn = gs_utils_get_cache_filename ("upgrades", "fedora.json", GS_UTILS_CACHE_FLAG_WRITEABLE, error); if (priv->cachefn == NULL) return FALSE; /* watch this in case it is changed by the user */ file = g_file_new_for_path (priv->cachefn); priv->cachefn_monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, cancellable, error); if (priv->cachefn_monitor == NULL) return FALSE; g_signal_connect (priv->cachefn_monitor, "changed", G_CALLBACK (gs_plugin_fedora_distro_upgrades_changed_cb), plugin); /* read os-release for the current versions */ os_release = gs_os_release_new (error); if (os_release == NULL) return FALSE; priv->os_name = g_strdup (gs_os_release_get_name (os_release)); if (priv->os_name == NULL) return FALSE; verstr = gs_os_release_get_version_id (os_release); if (verstr == NULL) return FALSE; /* parse the version */ priv->os_version = g_ascii_strtoull (verstr, &endptr, 10); if (endptr == verstr || priv->os_version > G_MAXUINT) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_INVALID_FORMAT, "Failed parse VERSION_ID: %s", verstr); return FALSE; } /* 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_origin_ui (priv->cached_origin, "Fedora Project PkgDb"); gs_app_set_origin_hostname (priv->cached_origin, FEDORA_PKGDB_COLLECTIONS_API_URI); /* add the source to the plugin cache which allows us to match the * unique ID to a GsApp when creating an event */ gs_plugin_cache_add (plugin, gs_app_get_unique_id (priv->cached_origin), priv->cached_origin); /* success */ return TRUE; }
gboolean gs_plugin_add_distro_upgrades (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); gsize len; guint i; g_autofree gchar *data = NULL; g_autoptr(GPtrArray) distros = NULL; g_autoptr(GSettings) settings = NULL; /* just ensure there is any data, no matter how old */ if (!gs_plugin_fedora_distro_upgrades_refresh (plugin, G_MAXUINT, cancellable, error)) return FALSE; /* get cached file */ if (!g_file_get_contents (priv->cachefn, &data, &len, error)) { gs_utils_error_convert_gio (error); return FALSE; } /* parse data */ settings = g_settings_new ("org.gnome.software"); distros = parse_pkgdb_collections_data (data, (gssize) len, error); if (distros == NULL) return FALSE; g_ptr_array_sort (distros, sort_distros_cb); for (i = 0; i < distros->len; i++) { DistroInfo *distro_info = g_ptr_array_index (distros, i); g_autofree gchar *app_id = NULL; g_autofree gchar *app_version = NULL; g_autofree gchar *background = NULL; g_autofree gchar *cache_key = NULL; g_autofree gchar *url = NULL; g_autofree gchar *css = NULL; g_autoptr(GsApp) app = NULL; g_autoptr(AsIcon) ic = NULL; /* only interested in upgrades to the same distro */ if (g_strcmp0 (distro_info->name, priv->os_name) != 0) continue; /* only interested in newer versions, but not more than N+2 */ if (distro_info->version <= priv->os_version || distro_info->version > priv->os_version + 2) continue; /* only interested in non-devel distros */ if (!g_settings_get_boolean (settings, "show-upgrade-prerelease")) { if (distro_info->status == DISTRO_STATUS_DEVEL) continue; } /* search in the cache */ cache_key = g_strdup_printf ("release-%u", distro_info->version); app = gs_plugin_cache_lookup (plugin, cache_key); if (app != NULL) { gs_app_list_add (list, app); continue; } app_id = g_strdup_printf ("org.fedoraproject.release-%u.upgrade", distro_info->version); app_version = g_strdup_printf ("%u", distro_info->version); /* icon from disk */ ic = as_icon_new (); as_icon_set_kind (ic, AS_ICON_KIND_LOCAL); as_icon_set_filename (ic, "/usr/share/pixmaps/fedora-logo-sprite.png"); /* create */ app = gs_app_new (app_id); gs_app_set_kind (app, AS_APP_KIND_OS_UPGRADE); gs_app_set_state (app, AS_APP_STATE_AVAILABLE); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, distro_info->name); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, /* TRANSLATORS: this is a title for Fedora distro upgrades */ _("A major upgrade, with new features and added polish.")); gs_app_set_description (app, GS_APP_QUALITY_LOWEST, "Fedora Workstation is a polished, " "easy to use operating system for " "laptop and desktop computers, with a " "complete set of tools for developers " "and makers of all kinds."); gs_app_set_version (app, app_version); gs_app_set_size_installed (app, 1024 * 1024 * 1024); /* estimate */ gs_app_set_size_download (app, 256 * 1024 * 1024); /* estimate */ gs_app_set_license (app, GS_APP_QUALITY_LOWEST, "LicenseRef-free"); gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_REBOOT); gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE); gs_app_add_quirk (app, AS_APP_QUIRK_NOT_REVIEWABLE); gs_app_set_origin_ui (app, distro_info->name); gs_app_add_icon (app, ic); gs_app_set_management_plugin (app, "packagekit"); /* show a Fedora magazine article for the release */ url = g_strdup_printf ("https://fedoramagazine.org/whats-new-fedora-%u-workstation", distro_info->version); gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, url); /* use a fancy background */ background = get_upgrade_css_background (distro_info->version); css = g_strdup_printf ("background: %s;" "background-position: center;" "background-size: cover;", background); gs_app_set_metadata (app, "GnomeSoftware::UpgradeBanner-css", css); gs_app_list_add (list, app); /* save in the cache */ gs_plugin_cache_add (plugin, cache_key, app); } return TRUE; }