[libhandy/more_colors_avatar: 7/7] demo: Create fake contacts
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/more_colors_avatar: 7/7] demo: Create fake contacts
- Date: Fri, 7 Aug 2020 05:49:41 +0000 (UTC)
commit 6d0e3fe60f0545e6398b349aa5fdd14d27994def
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Aug 6 17:25:23 2020 +0200
demo: Create fake contacts
Create fake contact names randomly to demo the avatar widget. List 30 of
them.
examples/hdy-demo-window.c | 87 +++++++++++++++++++++++++++++++++
examples/hdy-demo-window.ui | 115 +-------------------------------------------
2 files changed, 88 insertions(+), 114 deletions(-)
---
diff --git a/examples/hdy-demo-window.c b/examples/hdy-demo-window.c
index 15aa0eeb..188c332c 100644
--- a/examples/hdy-demo-window.c
+++ b/examples/hdy-demo-window.c
@@ -32,7 +32,9 @@ struct _HdyDemoWindow
HdyComboRow *carousel_indicators_row;
GListStore *carousel_indicators_model;
HdyAvatar *avatar;
+ GtkEntry *avatar_text;
GtkFileChooserButton *avatar_filechooser;
+ GtkListBox *avatar_contacts;
};
G_DEFINE_TYPE (HdyDemoWindow, hdy_demo_window, HDY_TYPE_APPLICATION_WINDOW)
@@ -339,6 +341,78 @@ avatar_file_set_cb (HdyDemoWindow *self)
hdy_avatar_set_image_load_func (self->avatar, (HdyAvatarImageLoadFunc) avatar_load_file, self, NULL);
}
+static gchar *
+avatar_new_random_name (void)
+{
+ static const char *first_names[] = {
+ "Adam",
+ "Adrian",
+ "Anna",
+ "Charlotte",
+ "Frédérique",
+ "Ilaria",
+ "Jakub",
+ "Jennyfer",
+ "Julia",
+ "Justin",
+ "Mario",
+ "Miriam",
+ "Mohamed",
+ "Nourimane",
+ "Owen",
+ "Peter",
+ "Petra",
+ "Rachid",
+ "Rebecca",
+ "Sarah",
+ "Thibault",
+ "Wolfgang",
+ };
+ static const char *last_names[] = {
+ "Bailey",
+ "Berat",
+ "Chen",
+ "Farquharson",
+ "Ferber",
+ "Franco",
+ "Galinier",
+ "Han",
+ "Lawrence",
+ "Lepied",
+ "Lopez",
+ "Mariotti",
+ "Rossi",
+ "Urasawa",
+ "Zwickelman",
+ };
+
+ return g_strdup_printf ("%s %s",
+ first_names[g_random_int_range (0, G_N_ELEMENTS (first_names))],
+ last_names[g_random_int_range (0, G_N_ELEMENTS (last_names))]);
+}
+
+static void
+avatar_update_contacts (HdyDemoWindow *self)
+{
+ g_autoptr (GList) children = gtk_container_get_children (GTK_CONTAINER (self->avatar_contacts));
+
+ for (GList *child = children; child; child = child->next)
+ gtk_container_remove (GTK_CONTAINER (self->avatar_contacts), child->data);
+
+ for (int i = 0; i < 30; i++) {
+ g_autofree gchar *name = avatar_new_random_name ();
+ GtkWidget *contact = hdy_action_row_new ();
+ GtkWidget *avatar = hdy_avatar_new (48, name, TRUE);
+
+ gtk_widget_show (contact);
+ gtk_widget_show (avatar);
+
+ hdy_preferences_row_set_title (HDY_PREFERENCES_ROW (contact), name);
+ hdy_action_row_add_prefix (HDY_ACTION_ROW (contact), avatar);
+ gtk_container_add (GTK_CONTAINER (self->avatar_contacts), contact);
+ }
+}
+
static void
hdy_demo_window_constructed (GObject *object)
{
@@ -383,7 +457,9 @@ hdy_demo_window_class_init (HdyDemoWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, carousel_orientation_row);
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, carousel_indicators_row);
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, avatar);
+ gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, avatar_text);
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, avatar_filechooser);
+ gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, avatar_contacts);
gtk_widget_class_bind_template_callback_full (widget_class, "key_pressed_cb",
G_CALLBACK(hdy_demo_window_key_pressed_cb));
gtk_widget_class_bind_template_callback_full (widget_class, "notify_visible_child_cb",
G_CALLBACK(hdy_demo_window_notify_visible_child_cb));
gtk_widget_class_bind_template_callback_full (widget_class, "notify_deck_visible_child_cb",
G_CALLBACK(hdy_demo_window_notify_deck_visible_child_cb));
@@ -455,6 +531,16 @@ carousel_page_init (HdyDemoWindow *self)
NULL);
}
+static void
+avatar_page_init (HdyDemoWindow *self)
+{
+ g_autofree gchar *name = avatar_new_random_name ();
+
+ gtk_entry_set_text (self->avatar_text, name);
+
+ avatar_update_contacts (self);
+}
+
static void
hdy_demo_window_init (HdyDemoWindow *self)
{
@@ -478,6 +564,7 @@ hdy_demo_window_init (HdyDemoWindow *self)
lists_page_init (self);
carousel_page_init (self);
+ avatar_page_init (self);
hdy_leaflet_set_visible_child_name (self->content_box, "content");
}
diff --git a/examples/hdy-demo-window.ui b/examples/hdy-demo-window.ui
index 6f295207..36fe1d52 100644
--- a/examples/hdy-demo-window.ui
+++ b/examples/hdy-demo-window.ui
@@ -2001,7 +2001,6 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
- <property name="text">Mario Rossi</property>
</object>
</child>
</object>
@@ -2074,7 +2073,7 @@
</object>
</child>
<child>
- <object class="GtkListBox">
+ <object class="GtkListBox" id="avatar_contacts">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="expand">True</property>
@@ -2082,118 +2081,6 @@
<style>
<class name="content"/>
</style>
- <child>
- <object class="HdyActionRow" id="avatar1">
- <property name="title">Miriam Lepied</property>
- <property name="visible">True</property>
- <child type="prefix">
- <object class="HdyAvatar">
- <property name="show-initials">True</property>
- <property name="size">48</property>
- <property name="text" bind-source="avatar1"
bind-property="title" bind-flags="sync-create"/>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="HdyActionRow" id="avatar2">
- <property name="title">Ilaria Franco</property>
- <property name="visible">True</property>
- <child type="prefix">
- <object class="HdyAvatar">
- <property name="show-initials">True</property>
- <property name="size">48</property>
- <property name="text" bind-source="avatar2"
bind-property="title" bind-flags="sync-create"/>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="HdyActionRow" id="avatar3">
- <property name="title">Adrian Lopez</property>
- <property name="visible">True</property>
- <child type="prefix">
- <object class="HdyAvatar">
- <property name="show-initials">True</property>
- <property name="size">48</property>
- <property name="text" bind-source="avatar3"
bind-property="title" bind-flags="sync-create"/>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="HdyActionRow" id="avatar4">
- <property name="title">Thibault Galinier</property>
- <property name="visible">True</property>
- <child type="prefix">
- <object class="HdyAvatar">
- <property name="show-initials">True</property>
- <property name="size">48</property>
- <property name="text" bind-source="avatar4"
bind-property="title" bind-flags="sync-create"/>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="HdyActionRow" id="avatar5">
- <property name="title">Adam Mariotti</property>
- <property name="visible">True</property>
- <child type="prefix">
- <object class="HdyAvatar">
- <property name="show-initials">True</property>
- <property name="size">48</property>
- <property name="text" bind-source="avatar5"
bind-property="title" bind-flags="sync-create"/>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="HdyActionRow" id="avatar6">
- <property name="title">Frédérique Zwickelman</property>
- <property name="visible">True</property>
- <child type="prefix">
- <object class="HdyAvatar">
- <property name="show-initials">True</property>
- <property name="size">48</property>
- <property name="text" bind-source="avatar6"
bind-property="title" bind-flags="sync-create"/>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="HdyActionRow" id="avatar7">
- <property name="title">Peter Berat</property>
- <property name="visible">True</property>
- <child type="prefix">
- <object class="HdyAvatar">
- <property name="show-initials">True</property>
- <property name="size">48</property>
- <property name="text" bind-source="avatar7"
bind-property="title" bind-flags="sync-create"/>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="HdyActionRow" id="avatar8">
- <property name="title">Sarah Ferber</property>
- <property name="visible">True</property>
- <child type="prefix">
- <object class="HdyAvatar">
- <property name="show-initials">True</property>
- <property name="size">48</property>
- <property name="text" bind-source="avatar8"
bind-property="title" bind-flags="sync-create"/>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]