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_xdg_app_create_installed: */ static GsApp * gs_plugin_xdg_app_create_installed (GsPlugin *plugin, XdgAppInstalledRef *xref, GError **error) { g_autofree gchar *id = NULL; g_autoptr(AsIcon) icon = NULL; g_autoptr(GsApp) app = NULL; g_return_val_if_fail (xref != NULL, NULL); /* * Only show the current application in GNOME Software * * You can have multiple versions/branches of a particular app-id * installed but only one of them is "current" where this means: * 1) the default to launch unless you specify a version * 2) The one that gets its exported files exported */ if (!xdg_app_installed_ref_get_is_current (xref) && xdg_app_ref_get_kind (XDG_APP_REF(xref)) == XDG_APP_REF_KIND_APP) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED, "%s not current, ignoring", xdg_app_ref_get_name (XDG_APP_REF (xref))); return NULL; } /* create new object */ id = gs_plugin_xdg_app_build_id (XDG_APP_REF (xref)); app = gs_app_new (id); gs_plugin_xdg_app_set_metadata_installed (app, xref); switch (xdg_app_ref_get_kind (XDG_APP_REF(xref))) { case XDG_APP_REF_KIND_APP: gs_app_set_kind (app, AS_APP_KIND_DESKTOP); break; case XDG_APP_REF_KIND_RUNTIME: gs_app_set_xdgapp_kind (app, XDG_APP_REF_KIND_RUNTIME); gs_app_set_kind (app, AS_APP_KIND_RUNTIME); gs_app_set_name (app, GS_APP_QUALITY_NORMAL, xdg_app_ref_get_name (XDG_APP_REF (xref))); gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "Framework for applications"); gs_app_set_version (app, xdg_app_ref_get_branch (XDG_APP_REF (xref))); icon = as_icon_new (); as_icon_set_kind (icon, AS_ICON_KIND_STOCK); as_icon_set_name (icon, "system-run-symbolic"); gs_app_set_icon (app, icon); break; default: g_set_error_literal (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED, "XdgAppRefKind not known"); return NULL; } return g_object_ref (app); }
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 * gs_plugin_generic_updates_get_os_update (GsPlugin *plugin) { GsApp *app; const gchar *id = "org.gnome.Software.OsUpdate"; g_autoptr(AsIcon) ic = NULL; /* create new */ app = gs_app_new (id); gs_app_add_quirk (app, GS_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); return app; }
gboolean gs_plugin_add_sources (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); PkBitfield filter; PkRepoDetail *rd; ProgressData data; const gchar *id; guint i; g_autoptr(GHashTable) hash = NULL; g_autoptr(PkResults) results = NULL; g_autoptr(GPtrArray) array = NULL; data.app = NULL; data.plugin = plugin; data.ptask = NULL; /* ask PK for the repo details */ filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NOT_SOURCE, PK_FILTER_ENUM_NOT_SUPPORTED, -1); results = pk_client_get_repo_list (PK_CLIENT(priv->task), filter, cancellable, gs_plugin_packagekit_progress_cb, &data, error); if (!gs_plugin_packagekit_results_valid (results, error)) return FALSE; hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); array = pk_results_get_repo_detail_array (results); for (i = 0; i < array->len; i++) { g_autoptr(GsApp) app = NULL; rd = g_ptr_array_index (array, i); id = pk_repo_detail_get_id (rd); app = gs_app_new (id); 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, pk_repo_detail_get_enabled (rd) ? AS_APP_STATE_INSTALLED : AS_APP_STATE_AVAILABLE); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, pk_repo_detail_get_description (rd)); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, pk_repo_detail_get_description (rd)); gs_app_list_add (list, app); g_hash_table_insert (hash, g_strdup (id), (gpointer) app); } /* get every application on the system and add it as a related package * if it matches */ return gs_plugin_add_sources_related (plugin, hash, cancellable, error); }
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; }
/** * gs_plugin_add_updates: */ gboolean gs_plugin_add_updates (GsPlugin *plugin, GList **list, GCancellable *cancellable, GError **error) { GsApp *app; /* update UI as this might take some time */ gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING); /* spin */ g_usleep (2 * G_USEC_PER_SEC); /* add a normal application */ 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, "Do not segfault when using newer versons of libvirt."); gs_app_set_kind (app, GS_APP_KIND_NORMAL); gs_app_set_id_kind (app, AS_ID_KIND_DESKTOP); gs_plugin_add_app (list, app); g_object_unref (app); /* add an OS update */ app = gs_app_new ("libvirt-glib-devel;0.0.1;noarch;fedora"); gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "libvirt-glib-devel"); gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "Fix several memory leaks."); gs_app_set_kind (app, GS_APP_KIND_PACKAGE); gs_app_set_id_kind (app, AS_ID_KIND_DESKTOP); gs_plugin_add_app (list, app); g_object_unref (app); /* add a second OS update */ app = gs_app_new ("gnome-boxes-libs;0.0.1;i386;updates-testing"); gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "gnome-boxes-libs"); gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "Do not segfault when using newer versons of libvirt."); gs_app_set_kind (app, GS_APP_KIND_PACKAGE); gs_app_set_id_kind (app, AS_ID_KIND_DESKTOP); gs_plugin_add_app (list, app); g_object_unref (app); return TRUE; }
/** * gs_plugin_packagekit_refresh_guess_app_id: */ static gboolean gs_plugin_packagekit_refresh_guess_app_id (GsPlugin *plugin, GsApp *app, const gchar *filename, GCancellable *cancellable, GError **error) { PkFiles *item; ProgressData data; guint i; guint j; gchar **fns; g_auto(GStrv) files = NULL; g_autoptr(PkResults) results = NULL; g_autoptr(GPtrArray) array = NULL; data.plugin = plugin; data.ptask = NULL; /* get file list so we can work out ID */ files = g_strsplit (filename, "\t", -1); results = pk_client_get_files_local (PK_CLIENT (plugin->priv->task), files, cancellable, gs_plugin_packagekit_progress_cb, &data, error); if (results == NULL) return FALSE; array = pk_results_get_files_array (results); if (array->len == 0) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "no files for %s", filename); return FALSE; } /* find the first desktop file */ for (i = 0; i < array->len; i++) { item = g_ptr_array_index (array, i); fns = pk_files_get_files (item); for (j = 0; fns[j] != NULL; j++) { if (g_str_has_prefix (fns[j], "/usr/share/applications/") && g_str_has_suffix (fns[j], ".desktop")) { g_autofree gchar *basename = g_path_get_basename (fns[j]); gs_app_set_id (app, basename); gs_app_set_kind (app, GS_APP_KIND_NORMAL); gs_app_set_id_kind (app, AS_ID_KIND_DESKTOP); break; } } } 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; }
/** * gs_plugin_add_popular: */ gboolean gs_plugin_add_popular (GsPlugin *plugin, GList **list, GCancellable *cancellable, GError **error) { g_autoptr(GsApp) app = gs_app_new ("gnome-power-manager"); gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "Power Manager"); gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "Power Management Program"); gs_app_set_state (app, AS_APP_STATE_AVAILABLE); gs_app_set_kind (app, GS_APP_KIND_NORMAL); gs_plugin_add_app (list, app); gs_app_set_id_kind (app, AS_ID_KIND_DESKTOP); return TRUE; }
/** * 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; }
gboolean gs_plugin_add_installed (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { g_autofree gchar *macaroon = NULL; g_auto(GStrv) discharges = NULL; g_autoptr(JsonArray) result = NULL; guint i; get_macaroon (plugin, &macaroon, &discharges); result = gs_snapd_list (macaroon, discharges, cancellable, error); if (result == NULL) return FALSE; for (i = 0; i < json_array_get_length (result); i++) { JsonObject *package = json_array_get_object_element (result, i); g_autoptr(GsApp) app = NULL; const gchar *status, *name; status = json_object_get_string_member (package, "status"); if (g_strcmp0 (status, "active") != 0) continue; /* create a unique ID for deduplication, TODO: branch? */ name = json_object_get_string_member (package, "name"); app = gs_app_new (name); gs_app_set_scope (app, AS_APP_SCOPE_SYSTEM); gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_SNAP); gs_app_set_management_plugin (app, "snap"); gs_app_set_kind (app, AS_APP_KIND_DESKTOP); gs_app_add_quirk (app, AS_APP_QUIRK_NOT_REVIEWABLE); refine_app (plugin, app, package, TRUE, cancellable); gs_app_list_add (list, app); } return TRUE; }
static GsApp * gs_plugin_fwupd_new_app_from_device_raw (GsPlugin *plugin, FwupdDevice *device) { GPtrArray *icons; g_autofree gchar *id = NULL; g_autoptr(GsApp) app = NULL; /* create a GsApp based on the device, not the release */ id = gs_plugin_fwupd_build_device_id (device); app = gs_app_new (id); gs_app_set_kind (app, AS_APP_KIND_FIRMWARE); gs_app_set_scope (app, AS_APP_SCOPE_SYSTEM); gs_app_set_state (app, AS_APP_STATE_INSTALLED); gs_app_add_quirk (app, GS_APP_QUIRK_NOT_LAUNCHABLE); gs_app_set_version (app, fwupd_device_get_version (device)); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, fwupd_device_get_name (device)); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, fwupd_device_get_summary (device)); gs_app_set_description (app, GS_APP_QUALITY_LOWEST, fwupd_device_get_description (device)); gs_app_set_origin (app, fwupd_device_get_vendor (device)); gs_fwupd_app_set_device_id (app, fwupd_device_get_id (device)); gs_app_set_management_plugin (app, "fwupd"); /* create icon */ icons = fwupd_device_get_icons (device); for (guint j = 0; j < icons->len; j++) { const gchar *icon = g_ptr_array_index (icons, j); g_autoptr(AsIcon) icon_tmp = as_icon_new (); if (g_str_has_prefix (icon, "/")) { as_icon_set_kind (icon_tmp, AS_ICON_KIND_LOCAL); as_icon_set_filename (icon_tmp, icon); } else { as_icon_set_kind (icon_tmp, AS_ICON_KIND_STOCK); as_icon_set_name (icon_tmp, icon); } gs_app_add_icon (app, icon_tmp); } return g_steal_pointer (&app); }
/** * gs_appstream_create_runtime: */ GsApp * gs_appstream_create_runtime (GsApp *parent, const gchar *runtime) { const gchar *id_parent; g_autofree gchar *id = NULL; g_autofree gchar *source = NULL; g_auto(GStrv) id_split = NULL; g_auto(GStrv) runtime_split = NULL; g_autoptr(GsApp) app = NULL; /* get the name/arch/branch */ runtime_split = g_strsplit (runtime, "/", -1); if (g_strv_length (runtime_split) != 3) return NULL; /* find the parent app ID prefix */ id_parent = gs_app_get_id (parent); if (id_parent == NULL) return NULL; id_split = g_strsplit (id_parent, ":", 2); if (g_strv_length (id_split) == 2) { id = g_strdup_printf ("%s:%s.runtime", id_split[0], runtime_split[0]); } else { id = g_strdup_printf ("%s.runtime", runtime_split[0]); } /* create the complete GsApp from the single string */ app = gs_app_new (id); source = g_strdup_printf ("runtime/%s", runtime); gs_app_add_source (app, source); gs_app_set_kind (app, AS_APP_KIND_RUNTIME); gs_app_set_version (app, id_split[2]); return g_steal_pointer (&app); }
/** * gs_plugin_file_to_app: */ gboolean gs_plugin_file_to_app (GsPlugin *plugin, GList **list, GFile *file, GCancellable *cancellable, GError **error) { g_autofree gchar *content_type = NULL; g_autofree gchar *id_prefixed = NULL; g_autoptr(GBytes) appstream_gz = NULL; g_autoptr(GBytes) icon_data = NULL; g_autoptr(GBytes) metadata = NULL; g_autoptr(GsApp) app = NULL; g_autoptr(XdgAppBundleRef) xref_bundle = NULL; const gchar *mimetypes[] = { "application/vnd.xdgapp", 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; /* load bundle */ xref_bundle = xdg_app_bundle_ref_new (file, error); if (xref_bundle == NULL) { g_prefix_error (error, "error loading bundle: "); return FALSE; } /* create a virtual ID */ id_prefixed = gs_plugin_xdg_app_build_id (XDG_APP_REF (xref_bundle)); /* load metadata */ app = gs_app_new (id_prefixed); gs_app_set_kind (app, AS_APP_KIND_DESKTOP); gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL); gs_app_set_size_installed (app, xdg_app_bundle_ref_get_installed_size (xref_bundle)); gs_plugin_xdg_app_set_metadata (app, XDG_APP_REF (xref_bundle)); metadata = xdg_app_bundle_ref_get_metadata (xref_bundle); if (!gs_plugin_xdg_app_set_app_metadata (app, g_bytes_get_data (metadata, NULL), g_bytes_get_size (metadata), error)) return FALSE; /* load AppStream */ appstream_gz = xdg_app_bundle_ref_get_appstream (xref_bundle); if (appstream_gz != NULL) { g_autoptr(GZlibDecompressor) decompressor = NULL; g_autoptr(GInputStream) stream_gz = NULL; g_autoptr(GInputStream) stream_data = NULL; g_autoptr(GBytes) appstream = NULL; g_autoptr(AsStore) store = NULL; g_autofree gchar *id = NULL; AsApp *item; /* decompress data */ decompressor = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP); stream_gz = g_memory_input_stream_new_from_bytes (appstream_gz); if (stream_gz == NULL) return FALSE; stream_data = g_converter_input_stream_new (stream_gz, G_CONVERTER (decompressor)); appstream = g_input_stream_read_bytes (stream_data, 0x100000, /* 1Mb */ cancellable, error); if (appstream == NULL) return FALSE; store = as_store_new (); if (!as_store_from_bytes (store, appstream, cancellable, error)) return FALSE; /* find app */ id = g_strdup_printf ("%s.desktop", gs_app_get_xdgapp_name (app)); item = as_store_get_app_by_id (store, id); if (item == NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "application %s not found", id); return FALSE; } /* copy details from AppStream to app */ if (!gs_appstream_refine_app (plugin, app, item, error)) return FALSE; } /* load icon */ icon_data = xdg_app_bundle_ref_get_icon (xref_bundle, 64 * gs_plugin_get_scale (plugin)); if (icon_data == NULL) icon_data = xdg_app_bundle_ref_get_icon (xref_bundle, 64); if (icon_data != NULL) { g_autoptr(GInputStream) stream_icon = NULL; g_autoptr(GdkPixbuf) pixbuf = NULL; stream_icon = g_memory_input_stream_new_from_bytes (icon_data); pixbuf = gdk_pixbuf_new_from_stream (stream_icon, cancellable, error); if (pixbuf == NULL) return FALSE; gs_app_set_pixbuf (app, pixbuf); } else { g_autoptr(AsIcon) icon = NULL; icon = as_icon_new (); as_icon_set_kind (icon, AS_ICON_KIND_STOCK); as_icon_set_name (icon, "application-x-executable"); gs_app_set_icon (app, icon); } /* not quite true: this just means we can update this specific app */ if (xdg_app_bundle_ref_get_origin (xref_bundle)) gs_app_add_quirk (app, AS_APP_QUIRK_HAS_SOURCE); g_debug ("created local app: %s", gs_app_to_string (app)); gs_app_list_add (list, app); return TRUE; }
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; }
/** * gs_plugin_add_updates_historical: */ gboolean gs_plugin_add_updates_historical (GsPlugin *plugin, GList **list, GCancellable *cancellable, GError **error) { gboolean ret; guint i; _cleanup_strv_free_ gchar **package_ids = NULL; _cleanup_free_ gchar *error_details = NULL; _cleanup_free_ gchar *packages = NULL; _cleanup_keyfile_unref_ GKeyFile *key_file = NULL; /* was any offline update attempted */ if (!g_file_test (PK_OFFLINE_UPDATE_RESULTS_FILENAME, G_FILE_TEST_EXISTS)) return TRUE; /* open the file */ key_file = g_key_file_new (); ret = g_key_file_load_from_file (key_file, PK_OFFLINE_UPDATE_RESULTS_FILENAME, G_KEY_FILE_NONE, error); if (!ret) return FALSE; /* only return results if successful */ ret = g_key_file_get_boolean (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Success", NULL); if (!ret) { error_details = g_key_file_get_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "ErrorDetails", error); if (error_details == NULL) return FALSE; g_set_error_literal (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, error_details); return FALSE; } /* get list of package-ids */ packages = g_key_file_get_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Packages", NULL); if (packages == NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED, "No 'Packages' in %s", PK_OFFLINE_UPDATE_RESULTS_FILENAME); return FALSE; } package_ids = g_strsplit (packages, ",", -1); for (i = 0; package_ids[i] != NULL; i++) { _cleanup_object_unref_ GsApp *app = NULL; _cleanup_strv_free_ gchar **split = NULL; app = gs_app_new (NULL); split = g_strsplit (package_ids[i], ";", 4); gs_app_add_source (app, split[0]); gs_app_set_update_version (app, split[1]); gs_app_set_management_plugin (app, "PackageKit"); gs_app_add_source_id (app, package_ids[i]); gs_app_set_state (app, AS_APP_STATE_UPDATABLE); gs_app_set_kind (app, GS_APP_KIND_PACKAGE); gs_plugin_add_app (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; }
gboolean gs_plugin_url_to_app (GsPlugin *plugin, GsAppList *list, const gchar *url, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autofree gchar *scheme = NULL; g_autofree gchar *path = NULL; const gchar *id = NULL; const gchar * const *id_like = NULL; g_auto(GStrv) package_ids = NULL; g_autoptr(PkResults) results = NULL; g_autoptr(GsApp) app = NULL; g_autoptr(GsOsRelease) os_release = NULL; g_autoptr(GPtrArray) packages = NULL; g_autoptr(GPtrArray) details = NULL; g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin); path = gs_utils_get_url_path (url); /* only do this for apt:// on debian or debian-like distros */ os_release = gs_os_release_new (error); if (os_release == NULL) { g_prefix_error (error, "failed to determine OS information:"); return FALSE; } else { id = gs_os_release_get_id (os_release); id_like = gs_os_release_get_id_like (os_release); scheme = gs_utils_get_url_scheme (url); if (!(g_strcmp0 (scheme, "apt") == 0 && (g_strcmp0 (id, "debian") == 0 || g_strv_contains (id_like, "debian")))) { return TRUE; } } app = gs_app_new (NULL); gs_plugin_packagekit_set_packaging_format (plugin, app); gs_app_add_source (app, path); gs_app_set_kind (app, AS_APP_KIND_GENERIC); gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_PACKAGE); package_ids = g_new0 (gchar *, 2); package_ids[0] = g_strdup (path); g_mutex_lock (&priv->client_mutex); results = pk_client_resolve (priv->client, pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST, PK_FILTER_ENUM_ARCH, -1), package_ids, cancellable, gs_packagekit_helper_cb, helper, error); g_mutex_unlock (&priv->client_mutex); if (!gs_plugin_packagekit_results_valid (results, error)) { g_prefix_error (error, "failed to resolve package_ids: "); return FALSE; } /* get results */ packages = pk_results_get_package_array (results); details = pk_results_get_details_array (results); if (packages->len >= 1) { if (gs_app_get_local_file (app) != NULL) return TRUE; gs_plugin_packagekit_resolve_packages_app (plugin, packages, app); gs_plugin_packagekit_refine_details_app (plugin, details, app); gs_app_list_add (list, app); } else { g_warning ("no results returned"); } 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_refine_app (GsPlugin *plugin, GsApp *app, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autoptr(SnapdClient) client = NULL; const gchar *name; g_autoptr(SnapdSnap) local_snap = NULL; g_autoptr(SnapdSnap) store_snap = NULL; SnapdSnap *snap; const gchar *developer_name; g_autofree gchar *description = NULL; /* not us */ if (g_strcmp0 (gs_app_get_management_plugin (app), "snap") != 0) return TRUE; client = get_client (plugin, error); if (client == NULL) return FALSE; /* get information from local snaps and store */ local_snap = snapd_client_get_snap_sync (client, gs_app_get_metadata_item (app, "snap::name"), cancellable, NULL); if (local_snap == NULL || (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SCREENSHOTS) != 0) store_snap = get_store_snap (plugin, gs_app_get_metadata_item (app, "snap::name"), cancellable, NULL); if (local_snap == NULL && store_snap == NULL) return TRUE; if (local_snap != NULL) gs_app_set_state (app, AS_APP_STATE_INSTALLED); else gs_app_set_state (app, AS_APP_STATE_AVAILABLE); /* use store information for basic metadata over local information */ snap = store_snap != NULL ? store_snap : local_snap; name = snapd_snap_get_title (snap); if (name == NULL || g_strcmp0 (name, "") == 0) name = snapd_snap_get_name (snap); gs_app_set_name (app, GS_APP_QUALITY_NORMAL, name); gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, snapd_snap_get_summary (snap)); description = gs_plugin_snap_get_description_safe (snap); if (description != NULL) gs_app_set_description (app, GS_APP_QUALITY_NORMAL, description); gs_app_set_license (app, GS_APP_QUALITY_NORMAL, snapd_snap_get_license (snap)); developer_name = snapd_snap_get_publisher_display_name (snap); if (developer_name == NULL) developer_name = snapd_snap_get_publisher_username (snap); gs_app_set_developer_name (app, developer_name); if (snapd_snap_get_publisher_validation (snap) == SNAPD_PUBLISHER_VALIDATION_VERIFIED) gs_app_add_quirk (app, GS_APP_QUIRK_DEVELOPER_VERIFIED); snap = local_snap != NULL ? local_snap : store_snap; gs_app_set_version (app, snapd_snap_get_version (snap)); switch (snapd_snap_get_snap_type (snap)) { case SNAPD_SNAP_TYPE_APP: gs_app_set_kind (app, AS_APP_KIND_DESKTOP); break; case SNAPD_SNAP_TYPE_KERNEL: case SNAPD_SNAP_TYPE_GADGET: case SNAPD_SNAP_TYPE_OS: gs_app_set_kind (app, AS_APP_KIND_RUNTIME); break; default: case SNAPD_SNAP_TYPE_UNKNOWN: gs_app_set_kind (app, AS_APP_KIND_UNKNOWN); break; } /* add information specific to installed snaps */ if (local_snap != NULL) { SnapdApp *snap_app; GDateTime *install_date; install_date = snapd_snap_get_install_date (local_snap); gs_app_set_size_installed (app, snapd_snap_get_installed_size (local_snap)); gs_app_set_install_date (app, install_date != NULL ? g_date_time_to_unix (install_date) : GS_APP_INSTALL_DATE_UNKNOWN); snap_app = get_primary_app (local_snap); if (snap_app != NULL) { gs_app_set_metadata (app, "snap::launch-name", snapd_app_get_name (snap_app)); gs_app_set_metadata (app, "snap::launch-desktop", snapd_app_get_desktop_file (snap_app)); } else { gs_app_add_quirk (app, GS_APP_QUIRK_NOT_LAUNCHABLE); } } /* add information specific to store snaps */ if (store_snap != NULL) { gs_app_set_origin (app, priv->store_name); gs_app_set_size_download (app, snapd_snap_get_download_size (store_snap)); if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SCREENSHOTS && gs_app_get_screenshots (app)->len == 0) refine_screenshots (app, store_snap); } /* load icon if requested */ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON && gs_app_get_pixbuf (app) == NULL) load_icon (plugin, client, app, gs_app_get_metadata_item (app, "snap::name"), local_snap, store_snap, cancellable); 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_refine_app (GsPlugin *plugin, GsApp *app, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { const gchar *gameid; const gchar *tmp; g_autofree gchar *manifest_basename = NULL; g_autofree gchar *fn = NULL; g_autoptr(GHashTable) manifest = NULL; /* check is us */ gameid = gs_app_get_metadata_item (app, "X-Steam-GameID"); if (gameid == NULL) return TRUE; /* is this true? */ gs_app_set_kind (app, AS_ID_KIND_DESKTOP); /* no way of knowing */ if (gs_app_get_size_download (app) == 0) gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE); /* hardcoded */ if (gs_app_get_origin_hostname (app) == NULL) gs_app_set_origin_hostname (app, "steampowered.com"); /* size */ tmp = gs_app_get_metadata_item (app, "X-Steam-Size"); if (tmp != NULL) { guint64 sz; sz = g_ascii_strtoull (tmp, NULL, 10); if (sz > 0) gs_app_set_size_installed (app, sz); } /* check manifest */ manifest_basename = g_strdup_printf ("appmanifest_%s.acf", gameid); fn = g_build_filename (g_get_user_data_dir (), "Steam", "steamapps", manifest_basename, NULL); if (!g_file_test (fn, G_FILE_TEST_EXISTS)) { /* can never have been installed */ gs_app_set_state (app, AS_APP_STATE_AVAILABLE); return TRUE; } manifest = gs_plugin_steam_load_app_manifest (fn, error); if (manifest == NULL) return FALSE; /* this is better than the download size */ tmp = g_hash_table_lookup (manifest, "SizeOnDisk"); if (tmp != NULL) { guint64 sz; sz = g_ascii_strtoull (tmp, NULL, 10); if (sz > 0) gs_app_set_size_installed (app, sz); } /* set state */ tmp = g_hash_table_lookup (manifest, "StateFlags"); if (tmp != NULL) { guint64 state_flags; /* set state */ state_flags = g_ascii_strtoull (tmp, NULL, 10); if (state_flags & GS_STEAM_STATE_FLAG_DOWNLOADING || state_flags & GS_STEAM_STATE_FLAG_PREALLOCATING || state_flags & GS_STEAM_STATE_FLAG_ADDING_FILES || state_flags & GS_STEAM_STATE_FLAG_COMMITTING || state_flags & GS_STEAM_STATE_FLAG_STAGING) gs_app_set_state (app, AS_APP_STATE_INSTALLING); else if (state_flags & GS_STEAM_STATE_FLAG_UNINSTALLING) gs_app_set_state (app, AS_APP_STATE_REMOVING); else if (state_flags & GS_STEAM_STATE_FLAG_FULLY_INSTALLED) gs_app_set_state (app, AS_APP_STATE_INSTALLED); else if (state_flags & GS_STEAM_STATE_FLAG_UNINSTALLED) gs_app_set_state (app, AS_APP_STATE_AVAILABLE); } /* set install date */ tmp = g_hash_table_lookup (manifest, "LastUpdated"); if (tmp != NULL) { guint64 ts; ts = g_ascii_strtoull (tmp, NULL, 10); if (ts > 0) gs_app_set_install_date (app, ts); } 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; }
/** * 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; }
int main (int argc, char **argv) { AsProfile *profile = NULL; GOptionContext *context; gboolean prefer_local = FALSE; gboolean ret; gboolean show_results = FALSE; gboolean verbose = FALSE; guint64 refine_flags = GS_PLUGIN_REFINE_FLAGS_DEFAULT; gint i; guint cache_age = 0; gint repeat = 1; int status = 0; g_auto(GStrv) plugin_blacklist = NULL; g_auto(GStrv) plugin_whitelist = NULL; g_autoptr(GError) error = NULL; g_autoptr(GsAppList) list = NULL; g_autoptr(GPtrArray) categories = NULL; g_autoptr(GsDebug) debug = gs_debug_new (); g_autofree gchar *plugin_blacklist_str = NULL; g_autofree gchar *plugin_whitelist_str = NULL; g_autofree gchar *refine_flags_str = NULL; g_autoptr(GsApp) app = NULL; g_autoptr(GFile) file = NULL; g_autoptr(GsPluginLoader) plugin_loader = NULL; g_autoptr(AsProfileTask) ptask = NULL; const GOptionEntry options[] = { { "show-results", '\0', 0, G_OPTION_ARG_NONE, &show_results, "Show the results for the action", NULL }, { "refine-flags", '\0', 0, G_OPTION_ARG_STRING, &refine_flags_str, "Set any refine flags required for the action", NULL }, { "repeat", '\0', 0, G_OPTION_ARG_INT, &repeat, "Repeat the action this number of times", NULL }, { "cache-age", '\0', 0, G_OPTION_ARG_INT, &cache_age, "Use this maximum cache age in seconds", NULL }, { "prefer-local", '\0', 0, G_OPTION_ARG_NONE, &prefer_local, "Prefer local file sources to AppStream", NULL }, { "plugin-blacklist", '\0', 0, G_OPTION_ARG_STRING, &plugin_blacklist_str, "Do not load specific plugins", NULL }, { "plugin-whitelist", '\0', 0, G_OPTION_ARG_STRING, &plugin_whitelist_str, "Only load specific plugins", NULL }, { "verbose", '\0', 0, G_OPTION_ARG_NONE, &verbose, "Show verbose debugging information", NULL }, { NULL} }; setlocale (LC_ALL, ""); g_setenv ("G_MESSAGES_DEBUG", "all", TRUE); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init (&argc, &argv); context = g_option_context_new (NULL); g_option_context_set_summary (context, "GNOME Software Test Program"); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); ret = g_option_context_parse (context, &argc, &argv, &error); if (!ret) { g_print ("Failed to parse options: %s\n", error->message); goto out; } if (verbose) g_setenv ("GS_DEBUG", "1", TRUE); /* prefer local sources */ if (prefer_local) g_setenv ("GNOME_SOFTWARE_PREFER_LOCAL", "true", TRUE); /* parse any refine flags */ refine_flags = gs_cmd_parse_refine_flags (refine_flags_str, &error); if (refine_flags == G_MAXUINT64) { g_print ("Flag unknown: %s\n", error->message); goto out; } /* load plugins */ plugin_loader = gs_plugin_loader_new (); profile = gs_plugin_loader_get_profile (plugin_loader); ptask = as_profile_start_literal (profile, "GsCmd"); g_assert (ptask != NULL); if (g_file_test (LOCALPLUGINDIR, G_FILE_TEST_EXISTS)) gs_plugin_loader_set_location (plugin_loader, LOCALPLUGINDIR); if (plugin_whitelist_str != NULL) plugin_whitelist = g_strsplit (plugin_whitelist_str, ",", -1); if (plugin_blacklist_str != NULL) plugin_blacklist = g_strsplit (plugin_blacklist_str, ",", -1); ret = gs_plugin_loader_setup (plugin_loader, plugin_whitelist, plugin_blacklist, GS_PLUGIN_FAILURE_FLAGS_NONE, NULL, &error); if (!ret) { g_print ("Failed to setup plugins: %s\n", error->message); goto out; } gs_plugin_loader_dump_state (plugin_loader); /* do action */ if (argc == 2 && g_strcmp0 (argv[1], "installed") == 0) { for (i = 0; i < repeat; i++) { if (list != NULL) g_object_unref (list); list = gs_plugin_loader_get_installed (plugin_loader, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (list == NULL) { ret = FALSE; break; } } } else if (argc == 3 && g_strcmp0 (argv[1], "search") == 0) { for (i = 0; i < repeat; i++) { if (list != NULL) g_object_unref (list); list = gs_plugin_loader_search (plugin_loader, argv[2], refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (list == NULL) { ret = FALSE; break; } } } else if (argc == 3 && g_strcmp0 (argv[1], "action-upgrade-download") == 0) { app = gs_app_new (argv[2]); gs_app_set_kind (app, AS_APP_KIND_OS_UPGRADE); ret = gs_plugin_loader_app_action (plugin_loader, app, GS_PLUGIN_ACTION_UPGRADE_DOWNLOAD, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (ret) gs_app_list_add (list, app); } else if (argc == 3 && g_strcmp0 (argv[1], "refine") == 0) { app = gs_app_new (argv[2]); for (i = 0; i < repeat; i++) { ret = gs_plugin_loader_app_refine (plugin_loader, app, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (!ret) break; } list = gs_app_list_new (); gs_app_list_add (list, app); } else if (argc == 3 && g_strcmp0 (argv[1], "launch") == 0) { app = gs_app_new (argv[2]); for (i = 0; i < repeat; i++) { ret = gs_plugin_loader_app_action (plugin_loader, app, GS_PLUGIN_ACTION_LAUNCH, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (!ret) break; } } else if (argc == 3 && g_strcmp0 (argv[1], "filename-to-app") == 0) { file = g_file_new_for_path (argv[2]); app = gs_plugin_loader_file_to_app (plugin_loader, file, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (app == NULL) { ret = FALSE; } else { list = gs_app_list_new (); gs_app_list_add (list, app); } } else if (argc == 2 && g_strcmp0 (argv[1], "updates") == 0) { for (i = 0; i < repeat; i++) { if (list != NULL) g_object_unref (list); list = gs_plugin_loader_get_updates (plugin_loader, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (list == NULL) { ret = FALSE; break; } } } else if (argc == 2 && g_strcmp0 (argv[1], "upgrades") == 0) { for (i = 0; i < repeat; i++) { if (list != NULL) g_object_unref (list); list = gs_plugin_loader_get_distro_upgrades (plugin_loader, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (list == NULL) { ret = FALSE; break; } } } else if (argc == 2 && g_strcmp0 (argv[1], "sources") == 0) { list = gs_plugin_loader_get_sources (plugin_loader, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (list == NULL) ret = FALSE; } else if (argc == 2 && g_strcmp0 (argv[1], "popular") == 0) { for (i = 0; i < repeat; i++) { if (list != NULL) g_object_unref (list); list = gs_plugin_loader_get_popular (plugin_loader, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (list == NULL) { ret = FALSE; break; } } } else if (argc == 2 && g_strcmp0 (argv[1], "featured") == 0) { for (i = 0; i < repeat; i++) { if (list != NULL) g_object_unref (list); list = gs_plugin_loader_get_featured (plugin_loader, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (list == NULL) { ret = FALSE; break; } } } else if (argc == 2 && g_strcmp0 (argv[1], "get-categories") == 0) { for (i = 0; i < repeat; i++) { if (categories != NULL) g_ptr_array_unref (categories); categories = gs_plugin_loader_get_categories (plugin_loader, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (categories == NULL) { ret = FALSE; break; } } } else if (argc == 3 && g_strcmp0 (argv[1], "get-category-apps") == 0) { g_autoptr(GsCategory) category = NULL; g_autoptr(GsCategory) parent = NULL; g_auto(GStrv) split = NULL; split = g_strsplit (argv[2], "/", 2); if (g_strv_length (split) == 1) { category = gs_category_new (split[0]); } else { parent = gs_category_new (split[0]); category = gs_category_new (split[1]); gs_category_add_child (parent, category); } for (i = 0; i < repeat; i++) { if (list != NULL) g_object_unref (list); list = gs_plugin_loader_get_category_apps (plugin_loader, category, refine_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); if (list == NULL) { ret = FALSE; break; } } } else if (argc >= 2 && g_strcmp0 (argv[1], "refresh") == 0) { GsPluginRefreshFlags refresh_flags; refresh_flags = gs_cmd_refresh_flag_from_string (argv[2]); ret = gs_plugin_loader_refresh (plugin_loader, cache_age, refresh_flags, GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY, NULL, &error); } else { ret = FALSE; g_set_error_literal (&error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Did not recognise option, use 'installed', " "'updates', 'popular', 'get-categories', " "'get-category-apps', 'filename-to-app', " "'sources', 'refresh', 'launch' or 'search'"); } if (!ret) { g_print ("Failed: %s\n", error->message); goto out; } if (show_results) { if (list != NULL) gs_cmd_show_results_apps (list); if (categories != NULL) gs_cmd_show_results_categories (categories); } out: if (profile != NULL) as_profile_dump (profile); g_option_context_free (context); return status; }
gboolean gs_plugin_add_updates_historical (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { gboolean ret; guint64 mtime; guint i; g_auto(GStrv) package_ids = NULL; g_autofree gchar *packages = NULL; g_autoptr(GFile) file = NULL; g_autoptr(GFileInfo) info = NULL; g_autoptr(GKeyFile) key_file = NULL; /* was any offline update attempted */ if (!g_file_test (PK_OFFLINE_UPDATE_RESULTS_FILENAME, G_FILE_TEST_EXISTS)) return TRUE; /* get the mtime of the results */ file = g_file_new_for_path (PK_OFFLINE_UPDATE_RESULTS_FILENAME); info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, cancellable, error); if (info == NULL) return FALSE; mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); /* open the file */ key_file = g_key_file_new (); ret = g_key_file_load_from_file (key_file, PK_OFFLINE_UPDATE_RESULTS_FILENAME, G_KEY_FILE_NONE, error); if (!ret) return FALSE; /* only return results if successful */ ret = g_key_file_get_boolean (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Success", NULL); if (!ret) { g_autofree gchar *code = NULL; g_autofree gchar *details = NULL; code = g_key_file_get_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "ErrorCode", error); if (code == NULL) return FALSE; details = g_key_file_get_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "ErrorDetails", error); if (details == NULL) return FALSE; return gs_plugin_packagekit_convert_error (error, pk_error_enum_from_string (code), details); } /* get list of package-ids */ packages = g_key_file_get_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Packages", NULL); if (packages == NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED, "No 'Packages' in %s", PK_OFFLINE_UPDATE_RESULTS_FILENAME); return FALSE; } package_ids = g_strsplit (packages, ",", -1); for (i = 0; package_ids[i] != NULL; i++) { g_autoptr(GsApp) app = NULL; g_auto(GStrv) split = NULL; app = gs_app_new (NULL); split = g_strsplit (package_ids[i], ";", 4); gs_app_add_source (app, split[0]); gs_app_set_update_version (app, split[1]); gs_app_set_management_plugin (app, "packagekit"); gs_app_add_source_id (app, package_ids[i]); gs_app_set_state (app, AS_APP_STATE_UPDATABLE); gs_app_set_kind (app, AS_APP_KIND_GENERIC); gs_app_set_install_date (app, mtime); gs_app_set_metadata (app, "GnomeSoftware::Creator", gs_plugin_get_name (plugin)); gs_app_list_add (list, app); } return TRUE; }