users: Fixup parental controls row visibility

Previously, the row would remain visible (and do nothing when clicked)
if g-c-c is compiled w/o support for libmalcontent. Now, we make sure to
only show the row if compiled w/ libmalcontent support.
This commit is contained in:
Adrian Vovk 2024-04-22 20:05:57 -04:00 committed by Felipe Borges
parent 2e2ba583a0
commit ec3823ac58
2 changed files with 13 additions and 10 deletions

View file

@ -679,12 +679,24 @@ cc_user_page_class_init (CcUserPageClass * klass)
static void static void
cc_user_page_init (CcUserPage *self) cc_user_page_init (CcUserPage *self)
{ {
g_autofree gchar *malcontent_control_path = NULL;
gtk_widget_init_template (GTK_WIDGET (self)); gtk_widget_init_template (GTK_WIDGET (self));
self->avatar_chooser = cc_avatar_chooser_new (); self->avatar_chooser = cc_avatar_chooser_new ();
gtk_menu_button_set_popover (self->avatar_edit_button, GTK_WIDGET (self->avatar_chooser)); gtk_menu_button_set_popover (self->avatar_edit_button, GTK_WIDGET (self->avatar_chooser));
#ifdef HAVE_MALCONTENT #ifdef HAVE_MALCONTENT
/* Parental Controls: Unavailable if user is admin or if
* malcontent-control is not available (which can happen if
* libmalcontent is installed but malcontent-control is not). */
malcontent_control_path = g_find_program_in_path ("malcontent-control");
if (malcontent_control_path)
g_object_bind_property (self,
"is-admin",
self->parental_controls_row,
"visible",
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
g_signal_connect_object (self->parental_controls_row, g_signal_connect_object (self->parental_controls_row,
"activated", "activated",
G_CALLBACK (spawn_malcontent_control), G_CALLBACK (spawn_malcontent_control),
@ -708,9 +720,6 @@ cc_user_page_set_user (CcUserPage *self,
{ {
gboolean is_admin = FALSE; gboolean is_admin = FALSE;
g_autofree gchar *user_language = NULL; g_autofree gchar *user_language = NULL;
#ifdef HAVE_MALCONTENT
g_autofree gchar *malcontent_control_path = NULL;
#endif
g_assert (CC_IS_USER_PAGE (self)); g_assert (CC_IS_USER_PAGE (self));
g_assert (ACT_IS_USER (user)); g_assert (ACT_IS_USER (user));
@ -737,12 +746,6 @@ cc_user_page_set_user (CcUserPage *self,
gtk_switch_set_active (self->account_type_switch, is_admin); gtk_switch_set_active (self->account_type_switch, is_admin);
#ifdef HAVE_MALCONTENT #ifdef HAVE_MALCONTENT
/* Parental Controls: Unavailable if user is admin or if
* malcontent-control is not available (which can happen if
* libmalcontent is installed but malcontent-control is not). */
malcontent_control_path = g_find_program_in_path ("malcontent-control");
gtk_widget_set_visible (GTK_WIDGET (self->parental_controls_row),
!(is_admin && malcontent_control_path));
cc_list_row_set_secondary_label (self->parental_controls_row, cc_list_row_set_secondary_label (self->parental_controls_row,
is_parental_controls_enabled_for_user (user) ? is_parental_controls_enabled_for_user (user) ?
/* TRANSLATORS: Status of Parental Controls setup */ /* TRANSLATORS: Status of Parental Controls setup */

View file

@ -152,13 +152,13 @@
<child> <child>
<object class="CcListRow" id="parental_controls_row"> <object class="CcListRow" id="parental_controls_row">
<property name="visible" bind-source="CcUserPage" bind-property="is-admin" bind-flags="invert-boolean|sync-create"/>
<property name="title" translatable="yes">_Parental Controls</property> <property name="title" translatable="yes">_Parental Controls</property>
<property name="subtitle" translatable="yes">Open the Parental Controls app</property> <property name="subtitle" translatable="yes">Open the Parental Controls app</property>
<property name="subtitle-lines">0</property> <property name="subtitle-lines">0</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="activatable">True</property> <property name="activatable">True</property>
<property name="show-arrow">True</property> <property name="show-arrow">True</property>
<property name="visible">False</property>
</object> </object>
</child> </child>