[gnome-software: 2/3] gs-storage-context-dialog: Add link to control center
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 2/3] gs-storage-context-dialog: Add link to control center
- Date: Fri, 20 Aug 2021 16:17:25 +0000 (UTC)
commit 8a69ae597179fda9e0654eb0c2d5d2efbb6d6024
Author: Philip Withnall <pwithnall endlessos org>
Date: Tue Aug 17 15:33:51 2021 +0100
gs-storage-context-dialog: Add link to control center
Add a hyperlink which opens the control center on the app’s page,
allowing the user to clear app cache data and other things.
This implements the design:
https://gitlab.gnome.org/Teams/Design/software-mockups/-/blob/master/adaptive/context-tiles.png
The fix at https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/1041
is needed for the apps to be displayed properly when opened in g-c-c.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Fixes: #1394
src/gs-storage-context-dialog.c | 45 ++++++++++++++++++++++++++++++++++++++--
src/gs-storage-context-dialog.ui | 12 +++++++++++
2 files changed, 55 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-storage-context-dialog.c b/src/gs-storage-context-dialog.c
index 42e887f8a..2d24434e8 100644
--- a/src/gs-storage-context-dialog.c
+++ b/src/gs-storage-context-dialog.c
@@ -52,6 +52,7 @@ struct _GsStorageContextDialog
GtkWidget *lozenge;
GtkLabel *title;
GtkListBox *sizes_list;
+ GtkLabel *manage_storage_label;
};
G_DEFINE_TYPE (GsStorageContextDialog, gs_storage_context_dialog, HDY_TYPE_WINDOW)
@@ -105,6 +106,7 @@ update_sizes_list (GsStorageContextDialog *self)
guint64 title_size_bytes;
g_autofree gchar *title_size_bytes_str = NULL;
const gchar *title;
+ gboolean cache_row_added = FALSE;
gs_container_remove_all (GTK_CONTAINER (self->sizes_list));
@@ -142,9 +144,8 @@ update_sizes_list (GsStorageContextDialog *self)
_("Cache Data"),
_("Temporary cached data"));
title_size_bytes += size_cache_data;
+ cache_row_added = TRUE;
}
-
- /* FIXME: ‘Manage Storage’ button */
} else {
guint64 size_download;
guint64 size_download_dependencies;
@@ -172,6 +173,9 @@ update_sizes_list (GsStorageContextDialog *self)
title_size_bytes_str = g_format_size (title_size_bytes);
gtk_label_set_text (self->lozenge_content, title_size_bytes_str);
gtk_label_set_text (self->title, title);
+
+ /* Update the Manage Storage label. */
+ gtk_widget_set_visible (GTK_WIDGET (self->manage_storage_label), cache_row_added);
}
static void
@@ -221,6 +225,41 @@ key_press_event_cb (GtkWidget *sender,
return GDK_EVENT_PROPAGATE;
}
+static gboolean
+manage_storage_activate_link_cb (GtkLabel *label,
+ const gchar *uri,
+ gpointer user_data)
+{
+ GsStorageContextDialog *self = GS_STORAGE_CONTEXT_DIALOG (user_data);
+ g_autoptr(GError) local_error = NULL;
+ const gchar *desktop_id;
+ const gchar *argv[] = {
+ "gnome-control-center",
+ "applications",
+ "", /* application ID */
+ NULL
+ };
+
+ /* Button shouldn’t have been sensitive if the launchable ID isn’t available. */
+ desktop_id = gs_app_get_launchable (self->app, AS_LAUNCHABLE_KIND_DESKTOP_ID);
+ g_assert (desktop_id != NULL);
+
+ argv[2] = desktop_id;
+
+ if (!g_spawn_async (NULL, (gchar **) argv, NULL,
+ G_SPAWN_SEARCH_PATH |
+ G_SPAWN_STDOUT_TO_DEV_NULL |
+ G_SPAWN_STDERR_TO_DEV_NULL |
+ G_SPAWN_CLOEXEC_PIPES,
+ NULL, NULL, NULL, &local_error)) {
+ g_warning ("Error opening GNOME Control Center: %s",
+ local_error->message);
+ return TRUE;
+ }
+
+ return TRUE;
+}
+
static void
gs_storage_context_dialog_init (GsStorageContextDialog *self)
{
@@ -307,8 +346,10 @@ gs_storage_context_dialog_class_init (GsStorageContextDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, GsStorageContextDialog, lozenge);
gtk_widget_class_bind_template_child (widget_class, GsStorageContextDialog, title);
gtk_widget_class_bind_template_child (widget_class, GsStorageContextDialog, sizes_list);
+ gtk_widget_class_bind_template_child (widget_class, GsStorageContextDialog, manage_storage_label);
gtk_widget_class_bind_template_callback (widget_class, key_press_event_cb);
+ gtk_widget_class_bind_template_callback (widget_class, manage_storage_activate_link_cb);
}
/**
diff --git a/src/gs-storage-context-dialog.ui b/src/gs-storage-context-dialog.ui
index c1de3053f..d0c949639 100644
--- a/src/gs-storage-context-dialog.ui
+++ b/src/gs-storage-context-dialog.ui
@@ -110,6 +110,18 @@
<placeholder/>
</object>
</child>
+
+ <child>
+ <object class="GtkLabel" id="manage_storage_label">
+ <!-- The ‘dummy’ URI is ignored in the activate-link handler, but needs to be
specified as otherwise GTK complains that no href is set -->
+ <property name="label" translatable="yes" comments="Translators: Please do not
translate the markup or link href">Cached data can be cleared from the <a href="dummy">_application
settings</a>.</property>
+ <property name="margin-top">16</property>
+ <property name="use-markup">True</property>
+ <property name="use-underline">True</property>
+ <property name="visible">True</property>
+ <signal name="activate-link" handler="manage_storage_activate_link_cb"/>
+ </object>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]