[gnome-todo/wip/gbsneto/plugins: 15/18] scheduled-panel: show headers on tasks
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo/wip/gbsneto/plugins: 15/18] scheduled-panel: show headers on tasks
- Date: Mon, 18 Jan 2016 19:05:58 +0000 (UTC)
commit 3c76ee1a281b4098281167c086a80ce4ab75d460
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Jan 17 01:31:49 2016 -0200
scheduled-panel: show headers on tasks
Simply because I fell in love on Todoist's
organization. Now, I just have to make it in
the reverse order and it'll be perfect.
plugins/eds/eds.gresource.xml | 3 +-
plugins/eds/gtd-panel-scheduled.c | 139 +++++++++++++++++++++++++++++++++++++
plugins/eds/gtd-plugin-eds.c | 27 +++++++
plugins/eds/theme/Adwaita.css | 11 +++
4 files changed, 179 insertions(+), 1 deletions(-)
---
diff --git a/plugins/eds/eds.gresource.xml b/plugins/eds/eds.gresource.xml
index 5cc98dd..763d96e 100644
--- a/plugins/eds/eds.gresource.xml
+++ b/plugins/eds/eds.gresource.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/todo">
- <file compressed="true" alias="ui/eds/edit-pane.ui">edit-pane.ui</file>
+ <file compressed="true" alias="ui/eds/edit-pane.ui">edit-pane.ui</file>
+ <file compressed="true" alias="theme/eds/Adwaita.css" >theme/Adwaita.css</file>
</gresource>
</gresources>
diff --git a/plugins/eds/gtd-panel-scheduled.c b/plugins/eds/gtd-panel-scheduled.c
index 5965049..76787f8 100644
--- a/plugins/eds/gtd-panel-scheduled.c
+++ b/plugins/eds/gtd-panel-scheduled.c
@@ -51,6 +51,141 @@ enum {
N_PROPS
};
+static gchar*
+get_string_for_date (GDateTime *dt,
+ gint *span)
+{
+ GDateTime *now;
+ gchar *str;
+ gint days_diff;
+
+ /* This case should never happen */
+ if (!dt)
+ return g_strdup (_("No date set"));
+
+ now = g_date_time_new_now_local ();
+ days_diff = g_date_time_difference (dt, now) / G_TIME_SPAN_DAY;
+
+ if (days_diff < -1)
+ {
+ str = g_strdup_printf (_("%d days ago"), -days_diff);
+ }
+ else if (days_diff == -1)
+ {
+ str = g_strdup (_("Yesterday"));
+ }
+ else if (days_diff == 0)
+ {
+ str = g_strdup (_("Today"));
+ }
+ else if (days_diff == 1)
+ {
+ str = g_strdup (_("Tomorrow"));
+ }
+ else if (days_diff > 1 && days_diff < 7)
+ {
+ str = g_date_time_format (dt, "%A"); // Weekday name
+ }
+ else if (days_diff >= 7 && days_diff < (365 + g_date_time_get_year (dt) % 4 == 0))
+ {
+ str = g_date_time_format (dt, "%B"); // Full month name
+ }
+ else
+ {
+ str = g_strdup_printf ("%d", g_date_time_get_year (dt));
+ }
+
+ if (span)
+ *span = days_diff;
+
+ g_clear_pointer (&now, g_date_time_unref);
+
+ return str;
+}
+
+static GtkWidget*
+create_label (const gchar *text,
+ gint span,
+ gboolean first_header)
+{
+ GtkStyleContext *context;
+ GtkWidget *label;
+ GtkWidget *box;
+
+ label = g_object_new (GTK_TYPE_LABEL,
+ "label", text,
+ "margin-left", 12,
+ "margin-bottom", 6,
+ "margin-top", first_header ? 6 : 18,
+ "xalign", 0,
+ "hexpand", TRUE,
+ NULL);
+
+ context = gtk_widget_get_style_context (label);
+ gtk_style_context_add_class (context, span < 0 ? "date-overdue" : "date-scheduled");
+
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+
+ gtk_container_add (GTK_CONTAINER (box), label);
+ gtk_container_add (GTK_CONTAINER (box), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
+
+ gtk_widget_show_all (box);
+
+ return box;
+}
+
+static void
+gtd_panel_scheduled_header_func (GtkListBoxRow *row,
+ GtdTask *row_task,
+ GtkListBoxRow *before,
+ GtdTask *before_task,
+ GtdPanelScheduled *panel)
+{
+ GDateTime *dt;
+ gchar *text;
+ gint span;
+
+ dt = gtd_task_get_due_date (row_task);
+
+ if (!before)
+ {
+ text = get_string_for_date (dt, &span);
+
+ gtk_list_box_row_set_header (row, create_label (text,
+ span,
+ TRUE));
+
+ g_free (text);
+ }
+ else
+ {
+ GDateTime *before_dt;
+ gint diff;
+
+ before_dt = gtd_task_get_due_date (before_task);
+ diff = g_date_time_difference (dt, before_dt) / G_TIME_SPAN_DAY;
+
+ if (diff != 0)
+ {
+ text = get_string_for_date (dt, &span);
+
+ gtk_list_box_row_set_header (row, create_label (text,
+ span,
+ FALSE));
+
+ g_free (text);
+ }
+ else
+ {
+ gtk_list_box_row_set_header (row, NULL);
+ }
+
+ g_clear_pointer (&before_dt, g_date_time_unref);
+ }
+
+ g_clear_pointer (&dt, g_date_time_unref);
+}
+
static void
gtd_panel_scheduled_clear (GtdPanelScheduled *panel)
{
@@ -280,6 +415,10 @@ gtd_panel_scheduled_init (GtdPanelScheduled *self)
gtk_widget_set_vexpand (self->view, TRUE);
gtk_container_add (GTK_CONTAINER (self), self->view);
+ gtd_task_list_view_set_header_func (GTD_TASK_LIST_VIEW (self->view),
+ (GtdTaskListViewHeaderFunc) gtd_panel_scheduled_header_func,
+ self);
+
gtk_widget_show_all (GTK_WIDGET (self));
}
diff --git a/plugins/eds/gtd-plugin-eds.c b/plugins/eds/gtd-plugin-eds.c
index 6ca83a3..1ab6619 100644
--- a/plugins/eds/gtd-plugin-eds.c
+++ b/plugins/eds/gtd-plugin-eds.c
@@ -43,6 +43,7 @@ struct _GtdPluginEds
{
PeasExtensionBaseClass parent;
+ GtkCssProvider *provider;
ESourceRegistry *registry;
/* Panels */
@@ -420,6 +421,9 @@ gtd_plugin_eds_class_init (GtdPluginEdsClass *klass)
static void
gtd_plugin_eds_init (GtdPluginEds *self)
{
+ GError *error = NULL;
+ GFile* css_file;
+
self->panels = g_list_append (NULL, gtd_panel_today_new ());
self->panels = g_list_append (self->panels, gtd_panel_scheduled_new ());
@@ -427,6 +431,29 @@ gtd_plugin_eds_init (GtdPluginEds *self)
e_source_registry_new (NULL,
(GAsyncReadyCallback) gtd_plugin_eds_source_registry_finish_cb,
self);
+
+ /* load CSS */
+ self->provider = gtk_css_provider_new ();
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER (self->provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
+
+ css_file = g_file_new_for_uri ("resource:///org/gnome/todo/theme/eds/Adwaita.css");
+
+ gtk_css_provider_load_from_file (self->provider,
+ css_file,
+ &error);
+ if (error != NULL)
+ {
+ g_warning ("%s: %s: %s",
+ G_STRFUNC,
+ _("Error loading CSS from resource"),
+ error->message);
+
+ g_error_free (error);
+ }
+
+ g_object_unref (css_file);
}
/* Empty class_finalize method */
diff --git a/plugins/eds/theme/Adwaita.css b/plugins/eds/theme/Adwaita.css
new file mode 100644
index 0000000..38f4ce8
--- /dev/null
+++ b/plugins/eds/theme/Adwaita.css
@@ -0,0 +1,11 @@
+label.date-scheduled {
+ color: #4a90d9;
+ font-size: 16px;
+ font-weight: bold;
+}
+
+label.date-overdue {
+ color: #cc0000;
+ font-size: 16px;
+ font-weight: bold;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]