[gnome-todo] empty-list: show a nice, warm message when the tasklist is completed



commit ada903ce60f03fd0fcecd0d1944956435c640d0a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Oct 23 02:30:40 2016 -0200

    empty-list: show a nice, warm message when the tasklist is completed

 data/todo.gresource.xml     |    1 +
 data/ui/empty-list.ui       |   41 ++++++++++++
 data/ui/list-view.ui        |   39 +-----------
 doc/reference/Makefile.am   |    1 +
 po/POTFILES.in              |    2 +
 src/Makefile.am             |    4 +
 src/gtd-empty-list-widget.c |  144 +++++++++++++++++++++++++++++++++++++++++++
 src/gtd-empty-list-widget.h |   36 +++++++++++
 src/gtd-task-list-view.c    |    3 +
 9 files changed, 233 insertions(+), 38 deletions(-)
---
diff --git a/data/todo.gresource.xml b/data/todo.gresource.xml
index e4a4c04..c180086 100644
--- a/data/todo.gresource.xml
+++ b/data/todo.gresource.xml
@@ -4,6 +4,7 @@
     <file alias="gtk/menus.ui">gtk/menus.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/dnd-row.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/edit-pane.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/empty-list.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/initial-setup.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/list-selector-grid-item.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/list-selector-list-item.ui</file>
diff --git a/data/ui/empty-list.ui b/data/ui/empty-list.ui
new file mode 100644
index 0000000..165fa81
--- /dev/null
+++ b/data/ui/empty-list.ui
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <template class="GtdEmptyListWidget" parent="GtkBox">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <property name="spacing">12</property>
+    <child>
+      <object class="GtkImage" id="icon">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_bottom">18</property>
+        <property name="vexpand">True</property>
+        <property name="pixel_size">128</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+    </child>
+    <child>
+      <object class="GtkLabel" id="title_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <attributes>
+          <attribute name="weight" value="bold"/>
+          <attribute name="scale" value="1.44"/>
+        </attributes>
+      </object>
+    </child>
+    <child>
+      <object class="GtkLabel" id="subtitle_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/data/ui/list-view.ui b/data/ui/list-view.ui
index bf1185d..936a196 100644
--- a/data/ui/list-view.ui
+++ b/data/ui/list-view.ui
@@ -65,49 +65,12 @@
               </object>
             </child>
             <child type="overlay">
-              <object class="GtkBox" id="empty_box">
+              <object class="GtdEmptyListWidget" id="empty_box">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="vexpand">True</property>
                 <property name="valign">center</property>
                 <property name="halign">center</property>
-                <property name="orientation">vertical</property>
-                <property name="spacing">12</property>
-                <child>
-                  <object class="GtkImage" id="empty_view__list_image">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="valign">center</property>
-                    <property name="pixel_size">128</property>
-                    <property name="icon_name">checkbox-checked-symbolic</property>
-                    <property name="margin-bottom">18</property>
-                    <style>
-                      <class name="dim-label" />
-                    </style>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="empty_view_title_label">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="label" translatable="yes">No tasks found</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                      <attribute name="scale" value="1.44"/>
-                    </attributes>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="empty_view_subtitle_label">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="label" translatable="yes">You can add tasks using the 
&lt;b&gt;+&lt;/b&gt; above</property>
-                    <property name="use_markup">True</property>
-                    <style>
-                      <class name="dim-label" />
-                    </style>
-                  </object>
-                </child>
               </object>
             </child>
           </object>
diff --git a/doc/reference/Makefile.am b/doc/reference/Makefile.am
index 41159c5..97c00d3 100644
--- a/doc/reference/Makefile.am
+++ b/doc/reference/Makefile.am
@@ -58,6 +58,7 @@ IGNORE_HFILES = \
        gtd-arrow-frame.h \
        gtd-dnd-row.h \
        gtd-edit-pane.h \
+       gtd-empty-list-widget.h \
        gtd-enum-types.h \
        gtd-initial-setup-window.h \
        gtd-list-selector.h \
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 17a56a0..9c34f74 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@ data/appdata/org.gnome.Todo.appdata.xml.in
 data/org.gnome.Todo.desktop.in.in
 data/org.gnome.todo.gschema.xml
 [type: gettext/glade]data/ui/edit-pane.ui
+[type: gettext/glade]data/ui/empty-list.ui
 [type: gettext/glade]data/ui/initial-setup.ui
 [type: gettext/glade]data/ui/list-selector-panel.ui
 [type: gettext/glade]data/ui/list-view.ui
@@ -24,6 +25,7 @@ plugins/today-panel/gtd-panel-today.c
 plugins/unscheduled-panel/unscheduled-panel/__init__.py
 src/gtd-application.c
 src/gtd-edit-pane.c
+src/gtd-empty-list-widget.c
 src/gtd-plugin-dialog-row.c
 src/gtd-task-list-view.c
 src/gtd-task-row.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 749435d..4f08856 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -66,6 +66,8 @@ gnome_todo_SOURCES = \
        gtd-dnd-row.h \
        gtd-edit-pane.c \
        gtd-edit-pane.h \
+       gtd-empty-list-widget.c \
+       gtd-empty-list-widget.h \
        gtd-enums.h \
        gtd-initial-setup-window.c \
        gtd-initial-setup-window.h \
@@ -213,6 +215,8 @@ libgtd_la_SOURCES = \
        gtd-dnd-row.h \
        gtd-edit-pane.c \
        gtd-edit-pane.h \
+       gtd-empty-list-widget.c \
+       gtd-empty-list-widget.h \
        gtd-enum-types.c \
        gtd-enum-types.h \
        gtd-enums.h \
diff --git a/src/gtd-empty-list-widget.c b/src/gtd-empty-list-widget.c
new file mode 100644
index 0000000..92a1a4f
--- /dev/null
+++ b/src/gtd-empty-list-widget.c
@@ -0,0 +1,144 @@
+/* gtd-empty-list-widget.c
+ *
+ * Copyright (C) 2016 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gtd-empty-list-widget.h"
+
+#include <glib/gi18n.h>
+
+struct _GtdEmptyListWidget
+{
+  GtkBox              parent;
+
+  GtkWidget          *icon;
+  GtkWidget          *subtitle_label;
+  GtkWidget          *title_label;
+
+  gboolean            is_empty : 1;
+};
+
+G_DEFINE_TYPE (GtdEmptyListWidget, gtd_empty_list_widget, GTK_TYPE_BOX)
+
+/* Icons that will be randomly picked */
+const gchar *icons[] =
+{
+  "face-cool-symbolic",
+  "face-laugh-symbolic",
+  "face-smirk-symbolic",
+  "face-smile-symbolic",
+  "face-smile-big-symbolic",
+  "face-wink-symbolic"
+};
+
+const gchar *messages[] =
+{
+  N_("No more tasks left"),
+  N_("Nothing else to do here"),
+  N_("You made it!"),
+  N_("Looks like there's nothing else left here")
+};
+
+const gchar *subtitles[] =
+{
+  N_("Get some rest now"),
+  N_("Enjoy the rest of your day"),
+  N_("Good job!"),
+  N_("Meanwhile, spread the love"),
+  N_("Working hard is always rewarded")
+};
+
+static void
+update_message (GtdEmptyListWidget *self)
+{
+  const gchar *icon_name, *title_text, *subtitle_text;
+
+  if (self->is_empty)
+    {
+      icon_name = "checkbox-checked-symbolic";
+      title_text = _("No tasks found");
+      subtitle_text = _("You can add tasks using the <b>+</b> above");
+    }
+  else
+    {
+      gint icon_index, message_index, subtitle_index;
+
+      icon_index = g_random_int_range (0, G_N_ELEMENTS (icons));
+      message_index = g_random_int_range (0, G_N_ELEMENTS (messages));
+      subtitle_index = g_random_int_range (0, G_N_ELEMENTS (subtitles));
+
+      icon_name = icons[icon_index];
+      title_text = gettext (messages[message_index]);
+      subtitle_text = gettext (subtitles[subtitle_index]);
+    }
+
+  gtk_image_set_from_icon_name (GTK_IMAGE (self->icon),
+                                icon_name,
+                                -1);
+
+  gtk_label_set_markup (GTK_LABEL (self->title_label), title_text);
+  gtk_label_set_markup (GTK_LABEL (self->subtitle_label), subtitle_text);
+}
+
+static void
+gtd_empty_list_widget_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+}
+
+static void
+gtd_empty_list_widget_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+}
+
+static void
+gtd_empty_list_widget_class_init (GtdEmptyListWidgetClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->get_property = gtd_empty_list_widget_get_property;
+  object_class->set_property = gtd_empty_list_widget_set_property;
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/todo/ui/empty-list.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, GtdEmptyListWidget, icon);
+  gtk_widget_class_bind_template_child (widget_class, GtdEmptyListWidget, subtitle_label);
+  gtk_widget_class_bind_template_child (widget_class, GtdEmptyListWidget, title_label);
+}
+
+static void
+gtd_empty_list_widget_init (GtdEmptyListWidget *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+void
+gtd_empty_list_widget_set_is_empty (GtdEmptyListWidget *self,
+                                    gboolean            is_empty)
+{
+  g_return_if_fail (GTD_IS_EMPTY_LIST_WIDGET (self));
+
+  self->is_empty = is_empty;
+  update_message (self);
+}
diff --git a/src/gtd-empty-list-widget.h b/src/gtd-empty-list-widget.h
new file mode 100644
index 0000000..04aca94
--- /dev/null
+++ b/src/gtd-empty-list-widget.h
@@ -0,0 +1,36 @@
+/* gtd-empty-list-widget.h
+ *
+ * Copyright (C) 2016 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTD_EMPTY_LIST_WIDGET_H
+#define GTD_EMPTY_LIST_WIDGET_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTD_TYPE_EMPTY_LIST_WIDGET (gtd_empty_list_widget_get_type())
+
+G_DECLARE_FINAL_TYPE (GtdEmptyListWidget, gtd_empty_list_widget, GTD, EMPTY_LIST_WIDGET, GtkBox)
+
+void                 gtd_empty_list_widget_set_is_empty          (GtdEmptyListWidget *self,
+                                                                  gboolean            is_empty);
+
+G_END_DECLS
+
+#endif /* GTD_EMPTY_LIST_WIDGET_H */
+
diff --git a/src/gtd-task-list-view.c b/src/gtd-task-list-view.c
index b05f30d..a816051 100644
--- a/src/gtd-task-list-view.c
+++ b/src/gtd-task-list-view.c
@@ -19,6 +19,7 @@
 #include "gtd-arrow-frame.h"
 #include "gtd-dnd-row.h"
 #include "gtd-edit-pane.h"
+#include "gtd-empty-list-widget.h"
 #include "gtd-task-list-view.h"
 #include "gtd-manager.h"
 #include "gtd-notification.h"
@@ -543,6 +544,8 @@ gtd_task_list_view__update_empty_state (GtdTaskListView *view)
     }
 
   gtk_widget_set_visible (view->priv->empty_box, is_empty);
+  gtd_empty_list_widget_set_is_empty (GTD_EMPTY_LIST_WIDGET (view->priv->empty_box),
+                                      view->priv->complete_tasks == 0);
 
   g_list_free (tasks);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]