user-accounts: Introduce an empty state page

There are eventually corner cases where there's no user other than
root in the system and control-center can be launched by the root
user (not recommended). In this cases, the panel crashes without
any user to show (since accountsservice would just list normal
users).

This patch introduces an empty state[0] "No Users Page".

[0] https://wiki.gnome.org/Design/OS/EmptyStates

https://bugzilla.gnome.org/show_bug.cgi?id=773673
This commit is contained in:
Felipe Borges 2017-02-22 12:18:24 +01:00
parent 09b94a9b53
commit a701b4646c
2 changed files with 64 additions and 1 deletions

View file

@ -42,6 +42,11 @@
<column type="gchararray"/>
</columns>
</object>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="visible-child">empty-state</property>
<child>
<object class="GtkOverlay" id="overlay">
<property name="visible">True</property>
<child type="overlay">
@ -435,6 +440,49 @@
</object>
</child>
</object>
<packing>
<property name="name">_users</property>
</packing>
</child>
<child>
<object class="GtkBox" id="empty-state">
<property name="visible">True</property>
<property name="orientation">GTK_ORIENTATION_VERTICAL</property>
<property name="valign">GTK_ALIGN_CENTER</property>
<property name="spacing">12</property>
<style>
<class name="dim-label"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon_name">avatar-default-symbolic</property>
<property name="pixel_size">192</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes" comments="Translators: This is the empty state page label which states that there are no users to show in the panel.">No Users Found</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.6"/>
</attributes>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Unlock to add a user account.</property>
</object>
</child>
</object>
<packing>
<property name="name">_empty_state</property>
</packing>
</child>
</object>
<object class="GtkSizeGroup" id="user-icon-sizegroup">
<property name="mode">both</property>
<widgets>

View file

@ -71,6 +71,7 @@ struct _CcUserPanelPrivate {
GSettings *login_screen_settings;
GtkWidget *headerbar_buttons;
GtkWidget *stack;
GtkWidget *main_box;
UmCarousel *carousel;
ActUser *selected_user;
@ -92,9 +93,14 @@ get_widget (CcUserPanelPrivate *d, const char *name)
return (GtkWidget *)gtk_builder_get_object (d->builder, name);
}
/* Headerbar button states. */
#define PAGE_LOCK "_lock"
#define PAGE_ADDUSER "_adduser"
/* Panel states */
#define PAGE_NO_USERS "_empty_state"
#define PAGE_USERS "_users"
static void show_restart_notification (CcUserPanelPrivate *d, const gchar *locale);
static gint user_compare (gconstpointer i, gconstpointer u);
@ -273,6 +279,7 @@ reload_users (CcUserPanelPrivate *d, ActUser *selected_user)
UmCarouselItem *item;
GtkSettings *settings;
gboolean animations;
gboolean can_reload;
settings = gtk_settings_get_default ();
@ -286,6 +293,13 @@ reload_users (CcUserPanelPrivate *d, ActUser *selected_user)
list = act_user_manager_list_users (d->um);
g_debug ("Got %d users\n", g_slist_length (list));
can_reload = (list != NULL);
gtk_stack_set_visible_child_name (GTK_STACK (d->stack),
can_reload ? PAGE_USERS : PAGE_NO_USERS);
if (!can_reload)
return;
list = g_slist_sort (list, (GCompareFunc) sort_users);
for (l = list; l; l = l->next) {
user = l->data;
@ -1478,13 +1492,14 @@ cc_user_panel_init (CcUserPanel *self)
g_object_unref (provider);
d->headerbar_buttons = get_widget (d, "headerbar-buttons");
d->stack = get_widget (d, "stack");
d->login_screen_settings = settings_or_null ("org.gnome.login-screen");
d->password_dialog = um_password_dialog_new ();
button = get_widget (d, "user-icon-button");
d->photo_dialog = um_photo_dialog_new (button);
d->main_box = get_widget (d, "accounts-vbox");
gtk_container_add (GTK_CONTAINER (self), get_widget (d, "overlay"));
gtk_container_add (GTK_CONTAINER (self), d->stack);
d->history_dialog = um_history_dialog_new ();
setup_main_window (self);
}