[gnome-software: 5/6] Add a message in the UI when an app is renamed
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 5/6] Add a message in the UI when an app is renamed
- Date: Thu, 3 Dec 2020 14:35:51 +0000 (UTC)
commit 282e3efb481279cc85a5918aaa5b17cded758d99
Author: Phaedrus Leeds <mwleeds endlessos org>
Date: Wed Nov 4 13:48:02 2020 -0800
Add a message in the UI when an app is renamed
Without a message the user may be confused why they can't find the app
by looking for the name they remember.
lib/gs-app.c | 40 ++++++++++++++++++++++++++++++++
lib/gs-app.h | 3 +++
plugins/flatpak/gs-flatpak-transaction.c | 6 ++++-
plugins/flatpak/gs-flatpak.c | 22 +++++++++++++++++-
src/gs-app-row.c | 24 +++++++++++++++----
5 files changed, 88 insertions(+), 7 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 4a9e6d27..3f57985e 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -54,6 +54,7 @@ typedef struct
gboolean unique_id_valid;
gchar *branch;
gchar *name;
+ gchar *renamed_from;
GsAppQuality name_quality;
GPtrArray *icons;
GPtrArray *sources;
@@ -1330,6 +1331,44 @@ gs_app_set_name (GsApp *app, GsAppQuality quality, const gchar *name)
g_object_notify_by_pspec (G_OBJECT (app), obj_props[PROP_NAME]);
}
+/**
+ * gs_app_get_renamed_from:
+ * @app: a #GsApp
+ *
+ * Gets the old human-readable name of an application that's being renamed, the
+ * same name that was returned by gs_app_get_name() before the rename.
+ *
+ * Returns: (nullable): a string, or %NULL for unset
+ *
+ * Since: 40
+ **/
+const gchar *
+gs_app_get_renamed_from (GsApp *app)
+{
+ GsAppPrivate *priv = gs_app_get_instance_private (app);
+ g_return_val_if_fail (GS_IS_APP (app), NULL);
+ return priv->renamed_from;
+}
+
+/**
+ * gs_app_set_renamed_from:
+ * @app: a #GsApp
+ * @renamed_from: (nullable): The old name, e.g. "Iagno"
+ *
+ * Sets the old name of an application that's being renamed
+ *
+ * Since: 40
+ **/
+void
+gs_app_set_renamed_from (GsApp *app, const gchar *renamed_from)
+{
+ GsAppPrivate *priv = gs_app_get_instance_private (app);
+ g_autoptr(GMutexLocker) locker = NULL;
+ g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+ _g_set_str (&priv->renamed_from, renamed_from);
+}
+
/**
* gs_app_get_branch:
* @app: a #GsApp
@@ -4245,6 +4284,7 @@ gs_app_finalize (GObject *object)
g_free (priv->unique_id);
g_free (priv->branch);
g_free (priv->name);
+ g_free (priv->renamed_from);
g_hash_table_unref (priv->urls);
g_hash_table_unref (priv->launchables);
g_free (priv->license);
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 4c199dc1..7b1608d3 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -213,6 +213,9 @@ const gchar *gs_app_get_name (GsApp *app);
void gs_app_set_name (GsApp *app,
GsAppQuality quality,
const gchar *name);
+const gchar *gs_app_get_renamed_from (GsApp *app);
+void gs_app_set_renamed_from (GsApp *app,
+ const gchar *renamed_from);
const gchar *gs_app_get_source_default (GsApp *app);
void gs_app_add_source (GsApp *app,
const gchar *source);
diff --git a/plugins/flatpak/gs-flatpak-transaction.c b/plugins/flatpak/gs-flatpak-transaction.c
index 4a74a0d7..eb89b8db 100644
--- a/plugins/flatpak/gs-flatpak-transaction.c
+++ b/plugins/flatpak/gs-flatpak-transaction.c
@@ -728,7 +728,6 @@ _transaction_end_of_lifed_with_rebase (FlatpakTransaction *transaction,
if (rebased_to_ref && remote) {
g_autoptr(GError) local_error = NULL;
- //FIXME: show something in the UI
if (!flatpak_transaction_add_rebase (transaction, remote, rebased_to_ref,
NULL, previous_ids, &local_error) ||
!flatpak_transaction_add_uninstall (transaction, ref, &local_error)) {
@@ -740,6 +739,11 @@ _transaction_end_of_lifed_with_rebase (FlatpakTransaction *transaction,
g_warning ("Failed to rebase %s to %s: %s", ref, rebased_to_ref,
local_error->message);
return FALSE;
}
+
+ /* Note: A message about the rename will be shown in the UI
+ * thanks to code in gs_flatpak_refine_appstream() which
+ * sets gs_app_set_renamed_from().
+ */
return TRUE;
}
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 10d5bcd2..507ad305 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2400,6 +2400,7 @@ get_renamed_component (GsFlatpak *self,
g_autofree gchar *xpath = NULL;
g_autofree gchar *source_safe = NULL;
g_autoptr(FlatpakRemoteRef) remote_ref = NULL;
+ g_autoptr(XbNode) component = NULL;
remote_ref = flatpak_installation_fetch_remote_ref_sync (self->installation,
origin,
@@ -2421,7 +2422,26 @@ get_renamed_component (GsFlatpak *self,
source_safe = xb_string_escape (renamed_to);
xpath = g_strdup_printf ("components[@origin='%s']/component/bundle[@type='flatpak'][text()='%s']/..",
origin, source_safe);
- return xb_silo_query_first (silo, xpath, NULL);
+ component = xb_silo_query_first (silo, xpath, NULL);
+
+ /* Get the previous name so it can be displayed in the UI */
+ if (component != NULL) {
+ g_autoptr(FlatpakInstalledRef) installed_ref = NULL;
+ const gchar *installed_name = NULL;
+
+ installed_ref = flatpak_installation_get_installed_ref (self->installation,
+ gs_flatpak_app_get_ref_kind (app),
+ gs_flatpak_app_get_ref_name (app),
+ gs_flatpak_app_get_ref_arch (app),
+ gs_app_get_branch (app),
+ NULL, NULL);
+ if (installed_ref != NULL)
+ installed_name = flatpak_installed_ref_get_appdata_name (installed_ref);
+ if (installed_name != NULL)
+ gs_app_set_renamed_from (app, installed_name);
+ }
+
+ return g_steal_pointer (&component);
}
static gboolean
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 4425f551..15cfe0bc 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -467,11 +467,25 @@ gs_app_row_actually_refresh (GsAppRow *app_row)
}
/* add warning */
- if (priv->show_update &&
- gs_app_has_quirk (priv->app, GS_APP_QUIRK_NEW_PERMISSIONS)) {
- gtk_label_set_text (GTK_LABEL (priv->label_warning),
- _("Requires additional permissions"));
- gtk_widget_show (priv->label_warning);
+ if (priv->show_update) {
+ g_autoptr(GString) warning = g_string_new (NULL);
+ const gchar *renamed_from;
+
+ if (gs_app_has_quirk (priv->app, GS_APP_QUIRK_NEW_PERMISSIONS))
+ g_string_append (warning, _("Requires additional permissions"));
+
+ renamed_from = gs_app_get_renamed_from (priv->app);
+ if (renamed_from && g_strcmp0 (renamed_from, gs_app_get_name (priv->app)) != 0) {
+ if (warning->len > 0)
+ g_string_append (warning, "\n");
+ /* Translators: A message to indicate that an app has been renamed. The placeholder
is the old human-readable name. */
+ g_string_append_printf (warning, _("Renamed from %s"), renamed_from);
+ }
+
+ if (warning->len > 0) {
+ gtk_label_set_text (GTK_LABEL (priv->label_warning), warning->str);
+ gtk_widget_show (priv->label_warning);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]