diff options
author | Felipe Borges <felipeborges@gnome.org> | 2022-12-05 17:20:01 +0100 |
---|---|---|
committer | Felipe Borges <felipeborges@gnome.org> | 2022-12-05 17:39:39 +0100 |
commit | fe44858b9f869c9ccfa23b3509e44f0874fa43e9 (patch) | |
tree | 21de23880631cee1a178ee1dae2abe5ffff2f3f3 | |
parent | b616d49602d42630d2f7902588c407e7d22372f3 (diff) | |
download | gnome-control-center-location-drop-empty-state-page.tar.gz |
location: Drop "Location Services Turned Off" stack pagelocation-drop-empty-state-page
Instead, we disable all apps when the user disables Location Services.
If Location Services are disabled and an user enables an app, that
will enable Location Services.
See https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/1508#note_1601000
-rw-r--r-- | panels/location/cc-location-panel.c | 59 | ||||
-rw-r--r-- | panels/location/cc-location-panel.ui | 75 |
2 files changed, 56 insertions, 78 deletions
diff --git a/panels/location/cc-location-panel.c b/panels/location/cc-location-panel.c index 4e1077ee3..bfd56f10e 100644 --- a/panels/location/cc-location-panel.c +++ b/panels/location/cc-location-panel.c @@ -34,7 +34,6 @@ struct _CcLocationPanel { CcPanel parent_instance; - GtkStack *stack; GtkListBox *location_apps_list_box; GtkSwitch *main_switch; @@ -89,6 +88,10 @@ on_perm_store_set_done (GObject *source_object, data = (LocationAppStateData *) user_data; data->changing_state = FALSE; gtk_switch_set_state (GTK_SWITCH (data->widget), data->pending_state); + + // Enable location services when enabling an app + if (data->pending_state) + gtk_switch_set_state (data->self->main_switch, TRUE); } static gboolean @@ -196,9 +199,7 @@ add_location_app (CcLocationPanel *self, gtk_switch_set_active (GTK_SWITCH (w), enabled); gtk_widget_set_valign (w, GTK_ALIGN_CENTER); adw_action_row_add_suffix (ADW_ACTION_ROW (row), w); - g_settings_bind (self->location_settings, LOCATION_ENABLED, - w, "sensitive", - G_SETTINGS_BIND_DEFAULT); + g_hash_table_insert (self->location_app_switches, g_strdup (app_id), g_object_ref (w)); @@ -216,17 +217,24 @@ add_location_app (CcLocationPanel *self, 0); } -static gboolean -to_child_name (GBinding *binding, - const GValue *from, - GValue *to, - gpointer user_data) +static void +foreach_location_app_switch (gpointer key, + gpointer value, + gpointer user_data) { - if (g_value_get_boolean (from)) - g_value_set_string (to, "content"); - else - g_value_set_string (to, "empty"); - return TRUE; + CcLocationPanel *self = CC_LOCATION_PANEL (user_data); + GtkSwitch *app_switch = GTK_SWITCH (value); + + if (!gtk_switch_get_active (self->main_switch)) + gtk_switch_set_active (app_switch, FALSE); +} + +static void +on_main_switch_toggled (CcLocationPanel *self) +{ + g_hash_table_foreach (self->location_app_switches, + (GHFunc) foreach_location_app_switch, + self); } /* Steals permissions and permissions_data references */ @@ -380,9 +388,10 @@ cc_location_panel_class_init (CcLocationPanelClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/location/cc-location-panel.ui"); - gtk_widget_class_bind_template_child (widget_class, CcLocationPanel, stack); gtk_widget_class_bind_template_child (widget_class, CcLocationPanel, location_apps_list_box); gtk_widget_class_bind_template_child (widget_class, CcLocationPanel, main_switch); + + gtk_widget_class_bind_template_callback (widget_class, on_main_switch_toggled); } static void @@ -395,25 +404,17 @@ cc_location_panel_init (CcLocationPanel *self) self->location_icon_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH); self->location_settings = g_settings_new ("org.gnome.system.location"); + self->location_app_switches = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_object_unref); + g_settings_bind (self->location_settings, LOCATION_ENABLED, self->main_switch, "active", G_SETTINGS_BIND_DEFAULT); - - g_object_bind_property_full (self->main_switch, - "active", - self->stack, - "visible-child-name", - G_BINDING_SYNC_CREATE, - to_child_name, - NULL, - NULL, NULL); - - self->location_app_switches = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - g_object_unref); + on_main_switch_toggled (self); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, diff --git a/panels/location/cc-location-panel.ui b/panels/location/cc-location-panel.ui index 3729618c5..78ee6c25a 100644 --- a/panels/location/cc-location-panel.ui +++ b/panels/location/cc-location-panel.ui @@ -5,6 +5,7 @@ <child type="titlebar-end"> <object class="GtkSwitch" id="main_switch"> <property name="valign">center</property> + <signal name="notify::active" handler="on_main_switch_toggled" swapped="yes" object="CcLocationPanel"/> <accessibility> <property name="label" translatable="yes">Enabled</property> </accessibility> @@ -12,64 +13,40 @@ </child> <child type="content"> - <object class="GtkStack" id="stack"> - - <child> - <object class="GtkStackPage"> - <property name="name">empty</property> - <property name="child"> - <object class="AdwStatusPage"> - <property name="icon-name">location-services-disabled-symbolic</property> - <property name="title" translatable="yes">Location Services Turned Off</property> - <property name="description" translatable="yes">No sandboxed applications can obtain location information.</property> - </object> - - </property> - </object> - </child> - + <object class="AdwPreferencesPage"> <child> - <object class="GtkStackPage"> - <property name="name">content</property> - <property name="child"> - <object class="AdwPreferencesPage"> - <child> - <object class="AdwPreferencesGroup"> - <property name="description" translatable="yes">Location services use GPS, Wi-Fi and cellular connections to determine the approximate location of this device. <a href='https://location.services.mozilla.com/privacy'>Learn about what data is collected, and how it is used.</a> + <object class="AdwPreferencesGroup"> + <property name="description" translatable="yes">Location services use GPS, Wi-Fi and cellular connections to determine the approximate location of this device. <a href='https://location.services.mozilla.com/privacy'>Learn about what data is collected, and how it is used.</a> The following sandboxed applications have been given access to location data. Applications that are not sandboxed can access location data without asking for permission.</property> - <child> - <object class="GtkListBox" id="location_apps_list_box"> - <property name="selection-mode">none</property> - <style> - <class name="boxed-list"/> - </style> - - <child type="placeholder"> - <object class="GtkLabel"> - <property name="margin_top">18</property> - <property name="margin_bottom">18</property> - <property name="margin_start">18</property> - <property name="margin_end">18</property> - <property name="label" translatable="yes">No sandboxed applications have asked for location access</property> - <property name="wrap">true</property> - <property name="max-width-chars">50</property> - <style> - <class name="dim-label" /> - </style> - </object> - </child> - - </object> - </child> + <child> + <object class="GtkListBox" id="location_apps_list_box"> + <property name="selection-mode">none</property> + <style> + <class name="boxed-list"/> + </style> + + <child type="placeholder"> + <object class="GtkLabel"> + <property name="margin_top">18</property> + <property name="margin_bottom">18</property> + <property name="margin_start">18</property> + <property name="margin_end">18</property> + <property name="label" translatable="yes">No sandboxed applications have asked for location access</property> + <property name="wrap">true</property> + <property name="max-width-chars">50</property> + <style> + <class name="dim-label" /> + </style> </object> </child> + </object> - </property> + </child> </object> </child> - </object> + </child> </template> </interface> |