static gchar * gs_plugin_snap_get_description_safe (SnapdSnap *snap) { GString *str = g_string_new (snapd_snap_get_description (snap)); as_utils_string_replace (str, "\r", ""); as_utils_string_replace (str, " ", " "); return g_string_free (str, FALSE); }
static gchar * as_markup_import_html (const gchar *text, GError **error) { AsMarkupImportHelper helper; GMarkupParser parser = { as_markup_import_html_start_cb, as_markup_import_html_end_cb, as_markup_import_html_text_cb, NULL, NULL }; g_autoptr(GMarkupParseContext) ctx = NULL; g_autoptr(GString) str = NULL; g_autoptr(GString) helper_output = NULL; g_autoptr(GString) helper_temp = NULL; /* clean these up on failure */ helper_output = g_string_new (""); helper_temp = g_string_new (""); /* set up XML parser */ helper.action = AS_MARKUP_TAG_UNKNOWN; helper.output = helper_output; helper.temp = helper_temp; ctx = g_markup_parse_context_new (&parser, G_MARKUP_TREAT_CDATA_AS_TEXT, &helper, NULL); /* ensure this has at least one set of quotes */ str = g_string_new (""); g_string_append_printf (str, "<document>%s</document>", text); /* convert win32 line endings */ g_strdelimit (str->str, "\r", '\n'); /* treat as paragraph breaks */ as_utils_string_replace (str, "<br>", "\n"); /* tidy up non-compliant HTML5 */ as_markup_import_html_erase (str, "<img", ">"); as_markup_import_html_erase (str, "<link", ">"); as_markup_import_html_erase (str, "<meta", ">"); /* use UTF-8 */ as_utils_string_replace (str, "™", "™"); as_utils_string_replace (str, "®", "®"); as_utils_string_replace (str, " ", " "); /* parse */ if (!g_markup_parse_context_parse (ctx, str->str, -1, error)) return NULL; /* return only valid AppStream markup */ return as_markup_convert_full (helper.output->str, AS_MARKUP_CONVERT_FORMAT_APPSTREAM, AS_MARKUP_CONVERT_FLAG_IGNORE_ERRORS, error); }
static void as_node_cdata_to_escaped (AsNodeData *data) { GString *str; if (data->cdata_escaped) return; str = g_string_new (data->cdata); g_free (data->cdata); as_utils_string_replace (str, "&", "&"); as_utils_string_replace (str, "<", "<"); as_utils_string_replace (str, ">", ">"); data->cdata = g_string_free (str, FALSE); data->cdata_escaped = TRUE; }
static GsApp * gs_plugin_create_app_dummy (const gchar *id) { GsApp *app = gs_app_new (id); g_autoptr(GString) str = NULL; str = g_string_new (id); as_utils_string_replace (str, ".desktop", ""); g_string_prepend (str, "No description is available for "); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, "Unknown Application"); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, "Application not found"); gs_app_set_description (app, GS_APP_QUALITY_LOWEST, str->str); return app; }
static gboolean gs_plugin_steam_update_description (AsApp *app, const gchar *html, GError **error) { guint i = 0; g_autofree gchar *desc = NULL; g_autofree gchar *subsect = NULL; g_autoptr(GError) error_local = NULL; g_autoptr(GString) subsect_str = NULL; /* get the game description div section */ subsect = gs_plugin_steam_capture (html, "<div id=\"game_area_description\" class=\"game_area_description\">", "</div>", &i); /* fall back gracefully */ if (subsect == NULL) { subsect = gs_plugin_steam_capture (html, "<meta name=\"Description\" content=\"", "\">", &i); } if (subsect == NULL) { g_warning ("Failed to get description for %s [%s]", as_app_get_name (app, NULL), as_app_get_id (app)); return TRUE; } subsect_str = g_string_new (subsect); as_utils_string_replace (subsect_str, "About This Game", ""); desc = as_markup_import (subsect_str->str, AS_MARKUP_CONVERT_FORMAT_HTML, &error_local); if (desc == NULL) { g_warning ("Failed to parse description for %s [%s]: %s", as_app_get_name (app, NULL), as_app_get_id (app), error_local->message); return TRUE; } as_app_set_description (app, NULL, desc); return TRUE; }
void gs_app_row_refresh (GsAppRow *app_row) { GsAppRowPrivate *priv = gs_app_row_get_instance_private (app_row); GtkStyleContext *context; GString *str = NULL; const gchar *tmp; gboolean missing_search_result; guint64 installed_size; if (priv->app == NULL) return; /* is this a missing search result from the extras page? */ missing_search_result = (gs_app_get_state (priv->app) == AS_APP_STATE_UNAVAILABLE && gs_app_get_url (priv->app, AS_URL_KIND_MISSING) != NULL); /* do a fill bar for the current progress */ switch (gs_app_get_state (priv->app)) { case AS_APP_STATE_INSTALLING: gs_progress_button_set_progress (GS_PROGRESS_BUTTON (priv->button), gs_app_get_progress (priv->app)); gs_progress_button_set_show_progress (GS_PROGRESS_BUTTON (priv->button), TRUE); break; default: gs_progress_button_set_show_progress (GS_PROGRESS_BUTTON (priv->button), FALSE); break; } /* join the description lines */ str = gs_app_row_get_description (app_row); if (str != NULL) { as_utils_string_replace (str, "\n", " "); gtk_label_set_label (GTK_LABEL (priv->description_label), str->str); g_string_free (str, TRUE); } else { gtk_label_set_text (GTK_LABEL (priv->description_label), NULL); } /* add warning */ if (gs_app_has_quirk (priv->app, AS_APP_QUIRK_REMOVABLE_HARDWARE)) { gtk_label_set_text (GTK_LABEL (priv->label_warning), /* TRANSLATORS: during the update the device * will restart into a special update-only mode */ _("Device cannot be used during update.")); gtk_widget_show (priv->label_warning); } /* where did this app come from */ if (priv->show_source) { tmp = gs_app_get_origin_hostname (priv->app); if (tmp != NULL) { g_autofree gchar *origin_tmp = NULL; /* TRANSLATORS: this refers to where the app came from */ origin_tmp = g_strdup_printf ("%s: %s", _("Source"), tmp); gtk_label_set_label (GTK_LABEL (priv->label_origin), origin_tmp); } gtk_widget_set_visible (priv->label_origin, tmp != NULL); } else { gtk_widget_set_visible (priv->label_origin, FALSE); } /* installed tag */ if (!priv->show_buttons) { switch (gs_app_get_state (priv->app)) { case AS_APP_STATE_UPDATABLE: case AS_APP_STATE_UPDATABLE_LIVE: case AS_APP_STATE_INSTALLED: gtk_widget_set_visible (priv->label_installed, TRUE); break; default: gtk_widget_set_visible (priv->label_installed, FALSE); break; } } else { gtk_widget_set_visible (priv->label_installed, FALSE); } /* name */ if (g_strcmp0 (gs_app_get_branch (priv->app), "master") == 0) { g_autofree gchar *name = NULL; /* TRANSLATORS: not translated to match what flatpak does */ name = g_strdup_printf ("%s (Nightly)", gs_app_get_name (priv->app)); gtk_label_set_label (GTK_LABEL (priv->name_label), name); } else { gtk_label_set_label (GTK_LABEL (priv->name_label), gs_app_get_name (priv->app)); } if (priv->show_update && (gs_app_get_state (priv->app) == AS_APP_STATE_UPDATABLE || gs_app_get_state (priv->app) == AS_APP_STATE_UPDATABLE_LIVE)) { g_autofree gchar *verstr = NULL; verstr = gs_app_row_format_version_update (priv->app); gtk_label_set_label (GTK_LABEL (priv->version_label), verstr); gtk_widget_set_visible (priv->version_label, verstr != NULL); gtk_widget_hide (priv->star); } else { gtk_widget_hide (priv->version_label); if (missing_search_result || gs_app_get_rating (priv->app) <= 0) { gtk_widget_hide (priv->star); } else { gtk_widget_show (priv->star); gtk_widget_set_sensitive (priv->star, FALSE); gs_star_widget_set_rating (GS_STAR_WIDGET (priv->star), gs_app_get_rating (priv->app)); } gtk_label_set_label (GTK_LABEL (priv->version_label), gs_app_get_version_ui (priv->app)); } /* folders */ if (priv->show_folders && gs_utils_is_current_desktop ("GNOME") && g_settings_get_boolean (priv->settings, "show-folder-management")) { g_autoptr(GsFolders) folders = NULL; const gchar *folder; folders = gs_folders_get (); folder = gs_folders_get_app_folder (folders, gs_app_get_id (priv->app), gs_app_get_categories (priv->app)); if (folder != NULL) folder = gs_folders_get_folder_name (folders, folder); gtk_label_set_label (GTK_LABEL (priv->folder_label), folder); gtk_widget_set_visible (priv->folder_label, folder != NULL); } else { gtk_widget_hide (priv->folder_label); } /* pixbuf */ if (gs_app_get_pixbuf (priv->app) != NULL) gs_image_set_from_pixbuf (GTK_IMAGE (priv->image), gs_app_get_pixbuf (priv->app)); context = gtk_widget_get_style_context (priv->image); if (missing_search_result) gtk_style_context_add_class (context, "dimmer-label"); else gtk_style_context_remove_class (context, "dimmer-label"); /* pending label */ switch (gs_app_get_state (priv->app)) { case AS_APP_STATE_QUEUED_FOR_INSTALL: gtk_widget_set_visible (priv->label, TRUE); gtk_label_set_label (GTK_LABEL (priv->label), _("Pending")); break; default: gtk_widget_set_visible (priv->label, FALSE); break; } /* spinner */ switch (gs_app_get_state (priv->app)) { case AS_APP_STATE_REMOVING: gtk_spinner_start (GTK_SPINNER (priv->spinner)); gtk_widget_set_visible (priv->spinner, TRUE); break; default: gtk_widget_set_visible (priv->spinner, FALSE); break; } /* button */ gs_app_row_refresh_button (app_row, missing_search_result); /* hide buttons in the update list, unless the app is live updatable */ switch (gs_app_get_state (priv->app)) { case AS_APP_STATE_UPDATABLE_LIVE: case AS_APP_STATE_INSTALLING: gtk_widget_set_visible (priv->button_box, TRUE); break; default: gtk_widget_set_visible (priv->button_box, !priv->show_update); break; } /* checkbox */ if (priv->selectable) { if (gs_app_get_kind (priv->app) == AS_APP_KIND_DESKTOP || gs_app_get_kind (priv->app) == AS_APP_KIND_RUNTIME || gs_app_get_kind (priv->app) == AS_APP_KIND_WEB_APP) gtk_widget_set_visible (priv->checkbox, TRUE); } else { gtk_widget_set_visible (priv->checkbox, FALSE); } installed_size = gs_app_get_size_installed (priv->app); if (priv->show_installed_size && installed_size != GS_APP_SIZE_UNKNOWABLE && installed_size != 0) { g_autofree gchar *size = NULL; size = g_format_size (installed_size); gtk_label_set_label (GTK_LABEL (priv->label_app_size), size); gtk_widget_show (priv->label_app_size); } else { gtk_widget_hide (priv->label_app_size); } }