[gnome-control-center] applications: Use new snapd-glib API for labelling Snap interfaces
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] applications: Use new snapd-glib API for labelling Snap interfaces
- Date: Thu, 16 Apr 2020 04:03:26 +0000 (UTC)
commit ead0ae41788785911e429853f1b4616914ec0bb9
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Apr 3 14:02:38 2020 +1300
applications: Use new snapd-glib API for labelling Snap interfaces
This removes the need to put translated strings in g-c-c, and allows them to be
shared between multiple applications that use Snaps.
meson.build | 2 +-
panels/applications/cc-applications-panel.c | 25 +++++-
panels/applications/cc-snap-row.c | 130 ++--------------------------
panels/applications/cc-snap-row.h | 7 +-
po/POTFILES.in | 1 -
5 files changed, 35 insertions(+), 130 deletions(-)
---
diff --git a/meson.build b/meson.build
index b563d214e..7f6e8ee4b 100644
--- a/meson.build
+++ b/meson.build
@@ -201,7 +201,7 @@ config_h.set10('HAVE_FN_EXPLICIT_BZERO',
enable_snap = get_option('snap')
if enable_snap
snapd_glib_deps = [
- dependency('snapd-glib', version: '>= 1.49')
+ dependency('snapd-glib', version: '>= 1.57')
]
endif
config_h.set('HAVE_SNAP', enable_snap,
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index bc947e34a..457667a36 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -620,10 +620,13 @@ add_snap_permissions (CcApplicationsPanel *self,
g_autoptr(GList) rows = NULL;
gint index;
g_autoptr(SnapdClient) client = NULL;
+ g_autoptr(GPtrArray) interfaces = NULL;
g_autoptr(GPtrArray) plugs = NULL;
g_autoptr(GPtrArray) slots = NULL;
+ SnapdInterface *interface = NULL;
gint added = 0;
g_autoptr(GError) error = NULL;
+ g_autoptr(GError) interfaces_error = NULL;
if (!g_str_has_prefix (app_id, PORTAL_SNAP_PREFIX))
return FALSE;
@@ -634,6 +637,14 @@ add_snap_permissions (CcApplicationsPanel *self,
g_assert (index >= 0);
client = snapd_client_new ();
+
+ interfaces = snapd_client_get_interfaces2_sync (client,
+ SNAPD_GET_INTERFACES_FLAGS_NONE,
+ NULL,
+ NULL, &interfaces_error);
+ if (interfaces == NULL)
+ g_warning ("Failed to get snap interfaces: %s", interfaces_error->message);
+
if (!snapd_client_get_connections2_sync (client,
SNAPD_GET_CONNECTIONS_FLAGS_SELECT_ALL,
NULL, NULL,
@@ -641,7 +652,7 @@ add_snap_permissions (CcApplicationsPanel *self,
&plugs, &slots,
NULL, &error))
{
- g_warning ("Failed to get snap interfaces: %s", error->message);
+ g_warning ("Failed to get snap connections: %s", error->message);
return FALSE;
}
@@ -676,7 +687,17 @@ add_snap_permissions (CcApplicationsPanel *self,
g_ptr_array_add (available_slots, g_object_ref (slot));
}
- row = cc_snap_row_new (cc_panel_get_cancellable (CC_PANEL (self)), plug, available_slots);
+ if (interfaces != NULL)
+ {
+ for (int j = 0; j < interfaces->len; j++)
+ {
+ SnapdInterface *i = g_ptr_array_index (interfaces, j);
+ if (g_strcmp0 (snapd_interface_get_name (i), snapd_plug_get_interface (plug)) == 0)
+ interface = i;
+ }
+ }
+
+ row = cc_snap_row_new (cc_panel_get_cancellable (CC_PANEL (self)), interface, plug, available_slots);
gtk_widget_show (GTK_WIDGET (row));
gtk_list_box_insert (GTK_LIST_BOX (self->permission_list), GTK_WIDGET (row), index);
index++;
diff --git a/panels/applications/cc-snap-row.c b/panels/applications/cc-snap-row.c
index d20faf6e4..40a7fc407 100644
--- a/panels/applications/cc-snap-row.c
+++ b/panels/applications/cc-snap-row.c
@@ -48,127 +48,6 @@ typedef struct
SnapdSlot *slot;
} ConnectData;
-static const gchar *
-get_label (const gchar *interface_name)
-{
- if (strcmp (interface_name, "account-control") == 0)
- return _("Add user accounts and change passwords");
- else if (strcmp (interface_name, "alsa") == 0)
- return _("Play and record sound");
- else if (strcmp (interface_name, "avahi-observe") == 0)
- return _("Detect network devices using mDNS/DNS-SD (Bonjour/zeroconf)");
- else if (strcmp (interface_name, "bluetooth-control") == 0)
- return _("Access bluetooth hardware directly");
- else if (strcmp (interface_name, "bluez") == 0)
- return _("Use bluetooth devices");
- else if (strcmp (interface_name, "camera") == 0)
- return _("Use your camera");
- else if (strcmp (interface_name, "cups-control") == 0)
- return _("Print documents");
- else if (strcmp (interface_name, "joystick") == 0)
- return _("Use any connected joystick");
- else if (strcmp (interface_name, "docker") == 0)
- return _("Allow connecting to the Docker service");
- else if (strcmp (interface_name, "gsettings") == 0)
- return _("Can change settings");
- else if (strcmp (interface_name, "firewall-control") == 0)
- return _("Configure network firewall");
- else if (strcmp (interface_name, "fuse-support") == 0)
- return _("Setup and use privileged FUSE filesystems");
- else if (strcmp (interface_name, "fwupd") == 0)
- return _("Update firmware on this device");
- else if (strcmp (interface_name, "hardware-observe") == 0)
- return _("Access hardware information");
- else if (strcmp (interface_name, "hardware-random-control") == 0)
- return _("Provide entropy to hardware random number generator");
- else if (strcmp (interface_name, "hardware-random-observe") == 0)
- return _("Use hardware-generated random numbers");
- else if (strcmp (interface_name, "home") == 0)
- return _("Access files in your home folder");
- else if (strcmp (interface_name, "libvirt") == 0)
- return _("Access libvirt service");
- else if (strcmp (interface_name, "locale-control") == 0)
- return _("Change system language and region settings");
- else if (strcmp (interface_name, "location-control") == 0)
- return _("Change location settings and providers");
- else if (strcmp (interface_name, "location-observe") == 0)
- return _("Access your location");
- else if (strcmp (interface_name, "log-observe") == 0)
- return _("Read system and application logs");
- else if (strcmp (interface_name, "lxd") == 0)
- return _("Access LXD service");
- else if (strcmp (interface_name, "media-hub") == 0)
- return _("access the media-hub service");
- else if (strcmp (interface_name, "modem-manager") == 0)
- return _("Use and configure modems");
- else if (strcmp (interface_name, "mount-observe") == 0)
- return _("Read system mount information and disk quotas");
- else if (strcmp (interface_name, "mpris") == 0)
- return _("Control music and video players");
- else if (strcmp (interface_name, "network") == 0)
- return _("Has network access");
- else if (strcmp (interface_name, "network-control") == 0)
- return _("Change low-level network settings");
- else if (strcmp (interface_name, "network-manager") == 0)
- return _("Access the NetworkManager service to read and change network settings");
- else if (strcmp (interface_name, "network-observe") == 0)
- return _("Read access to network settings");
- else if (strcmp (interface_name, "network-setup-control") == 0)
- return _("Change network settings");
- else if (strcmp (interface_name, "network-setup-observe") == 0)
- return _("Read network settings");
- else if (strcmp (interface_name, "ofono") == 0)
- return _("Access the ofono service to read and change network settings for mobile telephony");
- else if (strcmp (interface_name, "openvtswitch") == 0)
- return _("Control Open vSwitch hardware");
- else if (strcmp (interface_name, "optical-drive") == 0)
- return _("Read from CD/DVD");
- else if (strcmp (interface_name, "password-manager-service") == 0)
- return _("Read, add, change, or remove saved passwords");
- else if (strcmp (interface_name, "ppp") == 0)
- return _("Access pppd and ppp devices for configuring Point-to-Point Protocol connections");
- else if (strcmp (interface_name, "process-control") == 0)
- return _("Pause or end any process on the system");
- else if (strcmp (interface_name, "pulseaudio") == 0)
- return _("Play and record sound");
- else if (strcmp (interface_name, "raw-usb") == 0)
- return _("Access USB hardware directly");
- else if (strcmp (interface_name, "removable-media") == 0)
- return _("Read/write files on removable storage devices");
- else if (strcmp (interface_name, "screen-inhibit-control") == 0)
- return _("Prevent screen sleep/lock");
- else if (strcmp (interface_name, "serial-port") == 0)
- return _("Access serial port hardware");
- else if (strcmp (interface_name, "shutdown") == 0)
- return _("Restart or power off the device");
- else if (strcmp (interface_name, "snapd-control") == 0)
- return _("Install, remove and configure software");
- else if (strcmp (interface_name, "storage-framework-service") == 0)
- return _("Access Storage Framework service");
- else if (strcmp (interface_name, "system-observe") == 0)
- return _("Read process and system information");
- else if (strcmp (interface_name, "system-trace") == 0)
- return _("Monitor and control any running program");
- else if (strcmp (interface_name, "time-control") == 0)
- return _("Change the date and time");
- else if (strcmp (interface_name, "timeserver-control") == 0)
- return _("Change time server settings");
- else if (strcmp (interface_name, "timezone-control") == 0)
- return _("Change the time zone");
- else if (strcmp (interface_name, "udisks2") == 0)
- return _("Access the UDisks2 service for configuring disks and removable media");
- else if (strcmp (interface_name, "unity8-calendar") == 0)
- return _("Read/change shared calendar events in Ubuntu Unity 8");
- else if (strcmp (interface_name, "unity8-contacts") == 0)
- return _("Read/change shared contacts in Ubuntu Unity 8");
- else if (strcmp (interface_name, "upower-observe") == 0)
- return _("Access energy usage data");
- else if (strcmp (interface_name, "u2f-devices") == 0)
- return _("Read/write access to U2F devices exposed");
- else
- return interface_name;
-}
-
static void
update_state (CcSnapRow *self)
{
@@ -382,10 +261,11 @@ cc_snap_row_init (CcSnapRow *self)
}
CcSnapRow *
-cc_snap_row_new (GCancellable *cancellable, SnapdPlug *plug, GPtrArray *slots)
+cc_snap_row_new (GCancellable *cancellable, SnapdInterface *interface, SnapdPlug *plug, GPtrArray *slots)
{
CcSnapRow *self;
GPtrArray *connected_slots;
+ g_autofree gchar *label = NULL;
GtkTreeIter iter;
g_return_val_if_fail (SNAPD_IS_PLUG (plug), NULL);
@@ -411,7 +291,11 @@ cc_snap_row_new (GCancellable *cancellable, SnapdPlug *plug, GPtrArray *slots)
}
}
- gtk_label_set_label (self->title_label, get_label (snapd_plug_get_interface (plug)));
+ if (interface != NULL)
+ label = snapd_interface_make_label (interface);
+ else
+ label = g_strdup (snapd_plug_get_interface (plug));
+ gtk_label_set_label (self->title_label, label);
/* Add option into combo box */
gtk_list_store_append (self->slots_combo_model, &iter);
diff --git a/panels/applications/cc-snap-row.h b/panels/applications/cc-snap-row.h
index 26563bd8d..d37bb804f 100644
--- a/panels/applications/cc-snap-row.h
+++ b/panels/applications/cc-snap-row.h
@@ -28,8 +28,9 @@ G_BEGIN_DECLS
#define CC_TYPE_SNAP_ROW (cc_snap_row_get_type())
G_DECLARE_FINAL_TYPE (CcSnapRow, cc_snap_row, CC, SNAP_ROW, GtkListBoxRow)
-CcSnapRow* cc_snap_row_new (GCancellable *cancellable,
- SnapdPlug *plug,
- GPtrArray *slots);
+CcSnapRow* cc_snap_row_new (GCancellable *cancellable,
+ SnapdInterface *interface,
+ SnapdPlug *plug,
+ GPtrArray *slots);
G_END_DECLS
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e58a1bef5..92fb7393e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,7 +2,6 @@
# Please keep this file sorted alphabetically.
panels/applications/cc-applications-panel.c
panels/applications/cc-applications-panel.ui
-panels/applications/cc-snap-row.c
panels/applications/gnome-applications-panel.desktop.in.in
panels/background/bg-colors-source.c
panels/background/cc-background-chooser.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]