/** * gs_plugin_add_category_apps: */ gboolean gs_plugin_add_category_apps (GsPlugin *plugin, GsCategory *category, GList **list, GCancellable *cancellable, GError **error) { g_autoptr(GsApp) app = gs_app_new ("gnome-boxes"); gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "Boxes"); gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "View and use virtual machines"); gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, "http://www.box.org"); gs_app_set_kind (app, GS_APP_KIND_NORMAL); gs_app_set_state (app, AS_APP_STATE_AVAILABLE); gs_app_set_pixbuf (app, gdk_pixbuf_new_from_file ("/usr/share/icons/hicolor/48x48/apps/gnome-boxes.png", NULL)); gs_app_set_id_kind (app, AS_ID_KIND_DESKTOP); gs_plugin_add_app (list, app); return TRUE; }
gboolean gs_plugin_add_sources (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autoptr(GPtrArray) remotes = NULL; /* find all remotes */ remotes = fwupd_client_get_remotes (priv->client, cancellable, error); if (remotes == NULL) return FALSE; for (guint i = 0; i < remotes->len; i++) { FwupdRemote *remote = g_ptr_array_index (remotes, i); g_autofree gchar *id = NULL; g_autoptr(GsApp) app = NULL; /* ignore these, they're built in */ if (fwupd_remote_get_kind (remote) != FWUPD_REMOTE_KIND_DOWNLOAD) continue; /* create something that we can use to enable/disable */ id = g_strdup_printf ("org.fwupd.%s.remote", fwupd_remote_get_id (remote)); app = gs_app_new (id); gs_app_set_kind (app, AS_APP_KIND_SOURCE); gs_app_set_scope (app, AS_APP_SCOPE_SYSTEM); gs_app_set_state (app, fwupd_remote_get_enabled (remote) ? AS_APP_STATE_INSTALLED : AS_APP_STATE_AVAILABLE); gs_app_add_quirk (app, GS_APP_QUIRK_NOT_LAUNCHABLE); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, fwupd_remote_get_title (remote)); #if FWUPD_CHECK_VERSION(1,0,7) gs_app_set_agreement (app, fwupd_remote_get_agreement (remote)); #endif gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, fwupd_remote_get_metadata_uri (remote)); gs_app_set_metadata (app, "fwupd::remote-id", fwupd_remote_get_id (remote)); gs_app_set_management_plugin (app, "fwupd"); gs_app_list_add (list, app); } return TRUE; }
/** * gs_plugin_add_sources: */ gboolean gs_plugin_add_sources (GsPlugin *plugin, GList **list, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autoptr(GPtrArray) xremotes = NULL; guint i; xremotes = xdg_app_installation_list_remotes (priv->installation, cancellable, error); if (xremotes == NULL) return FALSE; for (i = 0; i < xremotes->len; i++) { XdgAppRemote *xremote = g_ptr_array_index (xremotes, i); g_autoptr(GsApp) app = NULL; /* apps installed from bundles add their own remote that only * can be used for updating that app only -- so hide them */ if (xdg_app_remote_get_noenumerate (xremote)) continue; app = gs_app_new (xdg_app_remote_get_name (xremote)); gs_app_set_management_plugin (app, gs_plugin_get_name (plugin)); gs_app_set_kind (app, AS_APP_KIND_SOURCE); gs_app_set_state (app, AS_APP_STATE_INSTALLED); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, xdg_app_remote_get_name (xremote)); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, xdg_app_remote_get_title (xremote)); gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, xdg_app_remote_get_url (xremote)); gs_app_list_add (list, app); } return TRUE; }
/** * gs_plugin_filename_to_app: */ gboolean gs_plugin_filename_to_app (GsPlugin *plugin, GList **list, const gchar *filename, GCancellable *cancellable, GError **error) { const gchar *package_id; gboolean supported; PkDetails *item; ProgressData data; g_autoptr (PkResults) results = NULL; g_autofree gchar *basename = NULL; g_autofree gchar *license_spdx = NULL; g_auto(GStrv) files = NULL; g_auto(GStrv) split = NULL; g_autoptr(GPtrArray) array = NULL; g_autoptr(GsApp) app = NULL; /* does this match any of the mimetypes we support */ if (!gs_plugin_packagekit_refresh_content_type_matches (filename, &supported, cancellable, error)) return FALSE; if (!supported) return TRUE; data.plugin = plugin; data.ptask = NULL; /* get details */ files = g_strsplit (filename, "\t", -1); pk_client_set_cache_age (PK_CLIENT (plugin->priv->task), G_MAXUINT); results = pk_client_get_details_local (PK_CLIENT (plugin->priv->task), files, cancellable, gs_plugin_packagekit_progress_cb, &data, error); if (results == NULL) return FALSE; /* get results */ array = pk_results_get_details_array (results); if (array->len == 0) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "no details for %s", filename); return FALSE; } if (array->len > 1) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "too many details [%i] for %s", array->len, filename); return FALSE; } /* create application */ item = g_ptr_array_index (array, 0); app = gs_app_new (NULL); package_id = pk_details_get_package_id (item); split = pk_package_id_split (package_id); basename = g_path_get_basename (filename); gs_app_set_management_plugin (app, "PackageKit"); gs_app_set_kind (app, GS_APP_KIND_PACKAGE); gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL); if (pk_details_get_summary (item)) gs_app_set_name (app, GS_APP_QUALITY_LOWEST, pk_details_get_summary (item)); else gs_app_set_name (app, GS_APP_QUALITY_LOWEST, split[PK_PACKAGE_ID_NAME]); gs_app_set_version (app, split[PK_PACKAGE_ID_VERSION]); gs_app_set_metadata (app, "PackageKit::local-filename", filename); gs_app_set_origin (app, basename); gs_app_add_source (app, split[PK_PACKAGE_ID_NAME]); gs_app_add_source_id (app, package_id); gs_plugin_packagekit_refresh_set_text (app, pk_details_get_description (item)); gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, pk_details_get_url (item)); gs_app_set_size (app, pk_details_get_size (item)); license_spdx = as_utils_license_to_spdx (pk_details_get_license (item)); gs_app_set_licence (app, license_spdx, GS_APP_QUALITY_LOWEST); /* look for a desktop file so we can use a valid application id */ if (!gs_plugin_packagekit_refresh_guess_app_id (plugin, app, filename, cancellable, error)) return FALSE; gs_plugin_add_app (list, app); return TRUE; }
/** * gs_appstream_refine_app: */ gboolean gs_appstream_refine_app (GsPlugin *plugin, GsApp *app, AsApp *item, GError **error) { AsRelease *rel; GHashTable *urls; GPtrArray *pkgnames; GPtrArray *kudos; const gchar *tmp; guint i; /* set the kind to be more precise */ if (gs_app_get_kind (app) == AS_APP_KIND_UNKNOWN || gs_app_get_kind (app) == AS_APP_KIND_GENERIC) { gs_app_set_kind (app, as_app_get_kind (item)); } /* is installed already */ if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN) { switch (as_app_get_source_kind (item)) { case AS_APP_SOURCE_KIND_APPDATA: case AS_APP_SOURCE_KIND_DESKTOP: gs_app_set_kind (app, AS_APP_KIND_DESKTOP); gs_app_set_state (app, AS_APP_STATE_INSTALLED); break; case AS_APP_SOURCE_KIND_METAINFO: gs_app_set_state (app, AS_APP_STATE_INSTALLED); break; case AS_APP_SOURCE_KIND_APPSTREAM: gs_app_set_state (app, as_app_get_state (item)); break; default: break; } } /* set management plugin automatically */ gs_refine_item_management_plugin (app, item); /* set id */ if (as_app_get_id (item) != NULL && gs_app_get_id (app) == NULL) gs_app_set_id (app, as_app_get_id (item)); /* set name */ tmp = as_app_get_name (item, NULL); if (tmp != NULL) { if (g_str_has_prefix (tmp, "(Nightly) ")) { tmp += 10; if (gs_app_get_metadata_item (app, "X-XdgApp-Tags") == NULL) gs_app_set_metadata (app, "X-XdgApp-Tags", "nightly"); } gs_app_set_name (app, GS_APP_QUALITY_HIGHEST, tmp); } /* set summary */ tmp = as_app_get_comment (item, NULL); if (tmp != NULL) { gs_app_set_summary (app, GS_APP_QUALITY_HIGHEST, tmp); } /* add urls */ urls = as_app_get_urls (item); if (g_hash_table_size (urls) > 0 && gs_app_get_url (app, AS_URL_KIND_HOMEPAGE) == NULL) { GList *l; g_autoptr(GList) keys = NULL; keys = g_hash_table_get_keys (urls); for (l = keys; l != NULL; l = l->next) { gs_app_set_url (app, as_url_kind_from_string (l->data), g_hash_table_lookup (urls, l->data)); } } /* set licence */ if (as_app_get_project_license (item) != NULL && gs_app_get_license (app) == NULL) gs_app_set_license (app, GS_APP_QUALITY_HIGHEST, as_app_get_project_license (item)); /* set keywords */ if (as_app_get_keywords (item, NULL) != NULL && gs_app_get_keywords (app) == NULL) { gs_app_set_keywords (app, as_app_get_keywords (item, NULL)); gs_app_add_kudo (app, GS_APP_KUDO_HAS_KEYWORDS); } /* set origin */ if (as_app_get_origin (item) != NULL && gs_app_get_origin (app) == NULL) { gs_app_set_origin (app, as_app_get_origin (item)); } /* set description */ tmp = as_app_get_description (item, NULL); if (tmp != NULL) { g_autofree gchar *from_xml = NULL; from_xml = as_markup_convert_simple (tmp, error); if (from_xml == NULL) { g_prefix_error (error, "trying to parse '%s': ", tmp); return FALSE; } gs_app_set_description (app, GS_APP_QUALITY_HIGHEST, from_xml); } /* set icon */ if (as_app_get_icon_default (item) != NULL && gs_app_get_pixbuf (app) == NULL) gs_refine_item_pixbuf (plugin, app, item); /* set categories */ if (as_app_get_categories (item) != NULL && gs_app_get_categories (app)->len == 0) gs_app_set_categories (app, as_app_get_categories (item)); /* set project group */ if (as_app_get_project_group (item) != NULL && gs_app_get_project_group (app) == NULL) gs_app_set_project_group (app, as_app_get_project_group (item)); /* this is a core application for the desktop and cannot be removed */ if (_as_app_has_compulsory_for_desktop (item, "GNOME") && gs_app_get_kind (app) == AS_APP_KIND_DESKTOP) gs_app_add_quirk (app, AS_APP_QUIRK_COMPULSORY); /* set id kind */ if (gs_app_get_kind (app) == AS_APP_KIND_UNKNOWN) gs_app_set_kind (app, as_app_get_kind (item)); /* copy all the metadata */ gs_appstream_copy_metadata (app, item); /* set package names */ pkgnames = as_app_get_pkgnames (item); if (pkgnames->len > 0 && gs_app_get_sources(app)->len == 0) gs_app_set_sources (app, pkgnames); /* set addons */ gs_appstream_refine_add_addons (plugin, app, item); /* set screenshots */ gs_appstream_refine_add_screenshots (app, item); /* are the screenshots perfect */ if (gs_appstream_are_screenshots_perfect (item)) gs_app_add_kudo (app, GS_APP_KUDO_PERFECT_SCREENSHOTS); /* was this application released recently */ if (gs_appstream_is_recent_release (item)) gs_app_add_kudo (app, GS_APP_KUDO_RECENT_RELEASE); /* add kudos */ if (as_app_get_language (item, plugin->locale) > 50) gs_app_add_kudo (app, GS_APP_KUDO_MY_LANGUAGE); /* add new-style kudos */ kudos = as_app_get_kudos (item); for (i = 0; i < kudos->len; i++) { tmp = g_ptr_array_index (kudos, i); switch (as_kudo_kind_from_string (tmp)) { case AS_KUDO_KIND_SEARCH_PROVIDER: gs_app_add_kudo (app, GS_APP_KUDO_SEARCH_PROVIDER); break; case AS_KUDO_KIND_USER_DOCS: gs_app_add_kudo (app, GS_APP_KUDO_INSTALLS_USER_DOCS); break; case AS_KUDO_KIND_APP_MENU: gs_app_add_kudo (app, GS_APP_KUDO_USES_APP_MENU); break; case AS_KUDO_KIND_MODERN_TOOLKIT: gs_app_add_kudo (app, GS_APP_KUDO_MODERN_TOOLKIT); break; case AS_KUDO_KIND_NOTIFICATIONS: gs_app_add_kudo (app, GS_APP_KUDO_USES_NOTIFICATIONS); break; case AS_KUDO_KIND_HIGH_CONTRAST: gs_app_add_kudo (app, GS_APP_KUDO_HIGH_CONTRAST); break; case AS_KUDO_KIND_HI_DPI_ICON: gs_app_add_kudo (app, GS_APP_KUDO_HI_DPI_ICON); break; default: g_debug ("no idea how to handle kudo '%s'", tmp); break; } } /* is there any update information */ rel = as_app_get_release_default (item); if (rel != NULL) { tmp = as_release_get_description (rel, NULL); if (tmp != NULL) { g_autofree gchar *desc = NULL; desc = as_markup_convert (tmp, AS_MARKUP_CONVERT_FORMAT_MARKDOWN, error); if (desc == NULL) return FALSE; gs_app_set_update_details (app, desc); } gs_app_set_update_urgency (app, as_release_get_urgency (rel)); gs_app_set_update_version (app, as_release_get_version (rel)); } return TRUE; }
gboolean gs_plugin_file_to_app (GsPlugin *plugin, GsAppList *list, GFile *file, GCancellable *cancellable, GError **error) { GsApp *app; guint i; g_autofree gchar *content_type = NULL; g_autofree gchar *output = NULL; g_auto(GStrv) argv = NULL; g_auto(GStrv) tokens = NULL; g_autoptr(GString) str = NULL; const gchar *mimetypes[] = { "application/vnd.debian.binary-package", NULL }; /* does this match any of the mimetypes we support */ content_type = gs_utils_get_content_type (file, cancellable, error); if (content_type == NULL) return FALSE; if (!g_strv_contains (mimetypes, content_type)) return TRUE; /* exec sync */ argv = g_new0 (gchar *, 5); argv[0] = g_strdup (DPKG_DEB_BINARY); argv[1] = g_strdup ("--showformat=${Package}\\n" "${Version}\\n" "${Installed-Size}\\n" "${Homepage}\\n" "${Description}"); argv[2] = g_strdup ("-W"); argv[3] = g_file_get_path (file); if (!g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, &output, NULL, NULL, error)) { gs_utils_error_convert_gio (error); return FALSE; } /* parse output */ tokens = g_strsplit (output, "\n", 0); if (g_strv_length (tokens) < 5) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED, "dpkg-deb output format incorrect:\n\"%s\"\n", output); return FALSE; } /* create app */ app = gs_app_new (NULL); gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL); gs_app_add_source (app, tokens[0]); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, tokens[0]); gs_app_set_version (app, tokens[1]); gs_app_set_size_installed (app, 1024 * g_ascii_strtoull (tokens[2], NULL, 10)); gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, tokens[3]); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, tokens[4]); gs_app_set_kind (app, AS_APP_KIND_GENERIC); gs_app_set_metadata (app, "GnomeSoftware::Creator", gs_plugin_get_name (plugin)); /* multiline text */ str = g_string_new (""); for (i = 5; tokens[i] != NULL; i++) { if (g_strcmp0 (tokens[i], " .") == 0) { if (str->len > 0) g_string_truncate (str, str->len - 1); g_string_append (str, "\n"); continue; } g_strstrip (tokens[i]); g_string_append_printf (str, "%s ", tokens[i]); } if (str->len > 0) g_string_truncate (str, str->len - 1); gs_app_set_description (app, GS_APP_QUALITY_LOWEST, str->str); /* success */ gs_app_list_add (list, app); 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; }