system: Load subpages on demand

Let's manually wire the row activation to the panel creation so that
we can create panels on demand.

This also makes calls to subpages directly avoid initializing the
other panels.

Fixes #2857
This commit is contained in:
Felipe Borges 2024-03-20 12:16:13 +01:00
parent c14215ea91
commit 808bb41348
2 changed files with 62 additions and 33 deletions

View file

@ -40,6 +40,12 @@ struct _CcSystemPanel
AdwNavigationView *navigation;
AdwActionRow *about_row;
AdwActionRow *datetime_row;
AdwActionRow *region_row;
AdwActionRow *remote_desktop_row;
AdwActionRow *users_row;
GtkWidget *remote_login_dialog;
AdwNavigationPage *software_updates_group;
};
@ -133,16 +139,55 @@ on_subpage_set (CcSystemPanel *self)
{
AdwNavigationPage *subpage;
g_autofree gchar *tag = NULL;
GType page_type = G_TYPE_INVALID;
g_object_get (self, "subpage", &tag, NULL);
if (!tag)
return;
subpage = adw_navigation_view_find_page (self->navigation, tag);
if (g_str_equal (tag, "about"))
page_type = CC_TYPE_ABOUT_PAGE;
else if (g_str_equal (tag, "datetime"))
page_type = CC_TYPE_DATE_TIME_PAGE;
else if (g_str_equal (tag, "region"))
page_type = CC_TYPE_REGION_PAGE;
else if (g_str_equal (tag, "remote-desktop"))
page_type = CC_TYPE_REMOTE_DESKTOP_PAGE;
else if (g_str_equal (tag, "users"))
page_type = CC_TYPE_USERS_PAGE;
if (page_type == G_TYPE_INVALID)
return;
subpage = ADW_NAVIGATION_PAGE (g_object_new (page_type, NULL));
if (subpage)
adw_navigation_view_push (self->navigation, subpage);
}
static void
on_page_activated (AdwActionRow *row,
gpointer user_data)
{
CcSystemPanel *self = CC_SYSTEM_PANEL (user_data);
GType page_type = G_TYPE_INVALID;
if (row == self->about_row)
page_type = CC_TYPE_ABOUT_PAGE;
else if (row == self->datetime_row)
page_type = CC_TYPE_DATE_TIME_PAGE;
else if (row == self->region_row)
page_type = CC_TYPE_REGION_PAGE;
else if (row == self->remote_desktop_row)
page_type = CC_TYPE_REMOTE_DESKTOP_PAGE;
else if (row == self->users_row)
page_type = CC_TYPE_USERS_PAGE;
if (!page_type)
return;
adw_navigation_view_push (self->navigation, g_object_new (page_type, NULL));
}
static void
cc_system_panel_class_init (CcSystemPanelClass *klass)
{
@ -150,11 +195,17 @@ cc_system_panel_class_init (CcSystemPanelClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/system/cc-system-panel.ui");
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, about_row);
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, datetime_row);
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, region_row);
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, remote_desktop_row);
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, users_row);
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, navigation);
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, software_updates_group);
gtk_widget_class_bind_template_callback (widget_class, cc_system_page_open_software_update);
gtk_widget_class_bind_template_callback (widget_class, on_secure_shell_row_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_page_activated);
g_type_ensure (CC_TYPE_ABOUT_PAGE);
g_type_ensure (CC_TYPE_DATE_TIME_PAGE);

View file

@ -19,48 +19,43 @@
<object class="AdwPreferencesGroup">
<child>
<object class="CcListRow">
<object class="CcListRow" id="region_row">
<property name="title" translatable="yes">_Region &amp;amp; Language</property>
<property name="subtitle" translatable="yes">System language and localization</property>
<property name="icon-name">org.gnome.Settings-region-symbolic</property>
<property name="show-arrow">True</property>
<property name="action-name">navigation.push</property>
<property name="action-target">'region'</property>
<signal name="activated" handler="on_page_activated"/>
</object>
</child>
<child>
<object class="CcListRow">
<object class="CcListRow" id="datetime_row">
<property name="title" translatable="yes">_Date &amp;amp; Time</property>
<property name="subtitle" translatable="yes">Time zone and clock settings</property>
<property name="icon-name">org.gnome.Settings-time-symbolic</property>
<property name="show-arrow">True</property>
<property name="action-name">navigation.push</property>
<property name="action-target">'datetime'</property>
<signal name="activated" handler="on_page_activated"/>
</object>
</child>
<child>
<object class="CcListRow">
<object class="CcListRow" id="users_row">
<property name="title" translatable="yes">_Users</property>
<property name="subtitle" translatable="yes">Add and remove accounts, change password</property>
<property name="icon-name">org.gnome.Settings-users-symbolic</property>
<property name="use-underline">True</property>
<property name="show-arrow">True</property>
<property name="action-name">navigation.push</property>
<property name="action-target">'users'</property>
<signal name="activated" handler="on_page_activated"/>
</object>
</child>
<child>
<object class="CcListRow">
<property name="visible" bind-source="remote_desktop_page" bind-property="visible" bind-flags="sync-create"/>
<object class="CcListRow" id="remote_desktop_row">
<property name="title" translatable="yes">R_emote Desktop</property>
<property name="subtitle" translatable="yes">Allow this device to be used remotely</property>
<property name="icon-name">org.gnome.Settings-remote-desktop-symbolic</property>
<property name="show-arrow">True</property>
<property name="action-name">navigation.push</property>
<property name="action-target">'remote-desktop'</property>
<signal name="activated" handler="on_page_activated"/>
</object>
</child>
@ -75,13 +70,12 @@
</child>
<child>
<object class="CcListRow">
<object class="CcListRow" id="about_row">
<property name="title" translatable="yes">_About</property>
<property name="subtitle" translatable="yes">Hardware details and software versions</property>
<property name="icon-name">org.gnome.Settings-about-symbolic</property>
<property name="show-arrow">True</property>
<property name="action-name">navigation.push</property>
<property name="action-target">'about'</property>
<signal name="activated" handler="on_page_activated"/>
</object>
</child>
@ -115,22 +109,6 @@
</property>
</object>
</child>
<child>
<object class="CcRegionPage" id="region_page"/>
</child>
<child>
<object class="CcDateTimePage" id="datetime_page"/>
</child>
<child>
<object class="CcUsersPage" id="users_page"/>
</child>
<child>
<object class="CcRemoteDesktopPage" id="remote_desktop_page"/>
</child>
<child>
<object class="CcAboutPage" id="about_page"/>
</child>
</object>
</child>
</template>