[gnome-todo] project: Use GTK models
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] project: Use GTK models
- Date: Mon, 17 Sep 2018 01:38:55 +0000 (UTC)
commit f0a466722ea4fe1010c6f60ae99e524553ab5883
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Sep 16 22:37:45 2018 -0300
project: Use GTK models
This is mostly for testing purposes, but in the very
near future we'll remove our custom models entirely.
plugins/all-tasks-panel/gtd-all-tasks-panel.c | 27 ++++----
plugins/next-week-panel/gtd-next-week-panel.c | 25 ++++---
plugins/scheduled-panel/gtd-panel-scheduled.c | 23 +++----
plugins/today-panel/gtd-panel-today.c | 93 +++++++++++++--------------
src/task-list-view/gtd-task-list-popover.c | 17 +++--
5 files changed, 88 insertions(+), 97 deletions(-)
---
diff --git a/plugins/all-tasks-panel/gtd-all-tasks-panel.c b/plugins/all-tasks-panel/gtd-all-tasks-panel.c
index 9ecd426..2fc100b 100644
--- a/plugins/all-tasks-panel/gtd-all-tasks-panel.c
+++ b/plugins/all-tasks-panel/gtd-all-tasks-panel.c
@@ -25,6 +25,8 @@
#include "gnome-todo.h"
+#include "gtd-debug.h"
+
#include <glib/gi18n.h>
#include <math.h>
@@ -41,8 +43,8 @@ struct _GtdAllTasksPanel
guint number_of_tasks;
GtdTaskListView *view;
- GtdListModelFilter *filter_model;
- GtdListModelSort *sort_model;
+ GtkFilterListModel *filter_model;
+ GtkSortListModel *sort_model;
};
static void gtd_panel_iface_init (GtdPanelInterface *iface);
@@ -233,9 +235,9 @@ header_func (GtdTask *task,
}
static gint
-sort_func (GObject *a,
- GObject *b,
- gpointer user_data)
+sort_func (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data)
{
GtdTask *task_a = (GtdTask*) a;
GtdTask *task_b = (GtdTask*) b;
@@ -244,10 +246,10 @@ sort_func (GObject *a,
}
static gboolean
-filter_func (GObject *object,
+filter_func (gpointer item,
gpointer user_data)
{
- GtdTask *task = (GtdTask*) object;
+ GtdTask *task = (GtdTask*) item;
return !gtd_task_get_complete (task);
}
@@ -261,6 +263,8 @@ on_model_items_changed_cb (GListModel *model,
if (self->number_of_tasks == g_list_model_get_n_items (model))
return;
+ GTD_TRACE_MSG ("Received items-changed(%u, %u, %u)", position, n_removed, n_added);
+
self->number_of_tasks = g_list_model_get_n_items (model);
g_object_notify (G_OBJECT (self), "subtitle");
}
@@ -274,7 +278,7 @@ on_timer_updated_cb (GtdTimer *timer,
now = g_date_time_new_now_local ();
gtd_task_list_view_set_default_date (self->view, now);
- gtd_list_model_filter_invalidate (self->filter_model);
+ gtk_filter_list_model_refilter (self->filter_model);
}
/*
@@ -426,11 +430,8 @@ gtd_all_tasks_panel_init (GtdAllTasksPanel *self)
self->icon = g_themed_icon_new ("view-tasks-all-symbolic");
- self->filter_model = gtd_list_model_filter_new (gtd_manager_get_tasks_model (manager));
- gtd_list_model_filter_set_filter_func (self->filter_model, filter_func, self, NULL);
-
- self->sort_model = gtd_list_model_sort_new (G_LIST_MODEL (self->filter_model));
- gtd_list_model_sort_set_sort_func (self->sort_model, sort_func, self, NULL);
+ self->filter_model = gtk_filter_list_model_new (gtd_manager_get_tasks_model (manager), filter_func, self,
NULL);
+ self->sort_model = gtk_sort_list_model_new (G_LIST_MODEL (self->filter_model), sort_func, self, NULL);
/* The main view */
self->view = GTD_TASK_LIST_VIEW (gtd_task_list_view_new ());
diff --git a/plugins/next-week-panel/gtd-next-week-panel.c b/plugins/next-week-panel/gtd-next-week-panel.c
index aa560c1..2d0dd35 100644
--- a/plugins/next-week-panel/gtd-next-week-panel.c
+++ b/plugins/next-week-panel/gtd-next-week-panel.c
@@ -41,8 +41,8 @@ struct _GtdNextWeekPanel
guint number_of_tasks;
GtdTaskListView *view;
- GtdListModelFilter *filter_model;
- GtdListModelSort *sort_model;
+ GtkFilterListModel *filter_model;
+ GtkSortListModel *sort_model;
};
static void gtd_panel_iface_init (GtdPanelInterface *iface);
@@ -219,9 +219,9 @@ header_func (GtdTask *task,
}
static gint
-sort_func (GObject *a,
- GObject *b,
- gpointer user_data)
+sort_func (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data)
{
GDateTime *dt1;
GDateTime *dt2;
@@ -287,14 +287,14 @@ sort_func (GObject *a,
}
static gboolean
-filter_func (GObject *object,
- gpointer user_data)
+filter_func (gpointer item,
+ gpointer user_data)
{
g_autoptr (GDateTime) task_dt = NULL;
GtdTask *task;
gint days_offset;
- task = (GtdTask*) object;
+ task = (GtdTask*) item;
task_dt = gtd_task_get_due_date (task);
return !gtd_task_get_complete (task) &&
@@ -326,7 +326,7 @@ on_timer_updated_cb (GtdTimer *timer,
now = g_date_time_new_now_local ();
gtd_task_list_view_set_default_date (self->view, now);
- gtd_list_model_filter_invalidate (self->filter_model);
+ gtk_filter_list_model_refilter (self->filter_model);
}
/*
@@ -478,11 +478,8 @@ gtd_next_week_panel_init (GtdNextWeekPanel *self)
self->icon = g_themed_icon_new ("view-tasks-week-symbolic");
- self->filter_model = gtd_list_model_filter_new (gtd_manager_get_tasks_model (manager));
- gtd_list_model_filter_set_filter_func (self->filter_model, filter_func, self, NULL);
-
- self->sort_model = gtd_list_model_sort_new (G_LIST_MODEL (self->filter_model));
- gtd_list_model_sort_set_sort_func (self->sort_model, sort_func, self, NULL);
+ self->filter_model = gtk_filter_list_model_new (gtd_manager_get_tasks_model (manager), filter_func, self,
NULL);
+ self->sort_model = gtk_sort_list_model_new (G_LIST_MODEL (self->filter_model), sort_func, self, NULL);
/* The main view */
self->view = GTD_TASK_LIST_VIEW (gtd_task_list_view_new ());
diff --git a/plugins/scheduled-panel/gtd-panel-scheduled.c b/plugins/scheduled-panel/gtd-panel-scheduled.c
index 73e7b4e..86ee852 100644
--- a/plugins/scheduled-panel/gtd-panel-scheduled.c
+++ b/plugins/scheduled-panel/gtd-panel-scheduled.c
@@ -34,8 +34,8 @@ struct _GtdPanelScheduled
guint number_of_tasks;
GtdTaskListView *view;
- GtdListModelFilter *filter_model;
- GtdListModelSort *sort_model;
+ GtkFilterListModel *filter_model;
+ GtkSortListModel *sort_model;
};
static void gtd_panel_iface_init (GtdPanelInterface *iface);
@@ -215,9 +215,9 @@ header_func (GtdTask *task,
}
static gint
-sort_func (GObject *a,
- GObject *b,
- gpointer user_data)
+sort_func (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data)
{
GDateTime *dt1;
GDateTime *dt2;
@@ -289,13 +289,13 @@ sort_func (GObject *a,
}
static gboolean
-filter_func (GObject *object,
+filter_func (gpointer item,
gpointer user_data)
{
g_autoptr (GDateTime) task_dt = NULL;
GtdTask *task;
- task = (GtdTask*) object;
+ task = (GtdTask*) item;
task_dt = gtd_task_get_due_date (task);
return !gtd_task_get_complete (task) && task_dt != NULL;
@@ -324,7 +324,7 @@ on_timer_updated_cb (GtdTimer *timer,
now = g_date_time_new_now_local ();
gtd_task_list_view_set_default_date (self->view, now);
- gtd_list_model_filter_invalidate (self->filter_model);
+ gtk_filter_list_model_refilter (self->filter_model);
}
@@ -471,11 +471,8 @@ gtd_panel_scheduled_init (GtdPanelScheduled *self)
self->icon = g_themed_icon_new ("alarm-symbolic");
- self->filter_model = gtd_list_model_filter_new (gtd_manager_get_tasks_model (manager));
- gtd_list_model_filter_set_filter_func (self->filter_model, filter_func, self, NULL);
-
- self->sort_model = gtd_list_model_sort_new (G_LIST_MODEL (self->filter_model));
- gtd_list_model_sort_set_sort_func (self->sort_model, sort_func, self, NULL);
+ self->filter_model = gtk_filter_list_model_new (gtd_manager_get_tasks_model (manager), filter_func, self,
NULL);
+ self->sort_model = gtk_sort_list_model_new (G_LIST_MODEL (self->filter_model), sort_func, self, NULL);
/* The main view */
self->view = GTD_TASK_LIST_VIEW (gtd_task_list_view_new ());
diff --git a/plugins/today-panel/gtd-panel-today.c b/plugins/today-panel/gtd-panel-today.c
index 444d8f3..ef1c68e 100644
--- a/plugins/today-panel/gtd-panel-today.c
+++ b/plugins/today-panel/gtd-panel-today.c
@@ -34,8 +34,8 @@ struct _GtdPanelToday
guint number_of_tasks;
GtdTaskListView *view;
- GtdListModelFilter *filter_model;
- GtdListModelSort *sort_model;
+ GtkFilterListModel *filter_model;
+ GtkSortListModel *sort_model;
};
static void gtd_panel_iface_init (GtdPanelInterface *iface);
@@ -105,44 +105,6 @@ should_be_added (GDateTime *today,
return is_today (today, dt) || is_overdue (today, dt);
}
-static gint
-sort_func (GObject *a,
- GObject *b,
- gpointer user_data)
-{
- g_autoptr (GDateTime) dt1 = NULL;
- g_autoptr (GDateTime) dt2 = NULL;
- GtdTask *task1;
- GtdTask *task2;
- GDate dates[2];
- gint result;
-
- task1 = (GtdTask*) a;
- task2 = (GtdTask*) b;
-
- dt1 = gtd_task_get_due_date (task1);
- dt2 = gtd_task_get_due_date (task2);
-
- g_date_clear (dates, 2);
-
- g_date_set_dmy (&dates[0],
- g_date_time_get_day_of_month (dt1),
- g_date_time_get_month (dt1),
- g_date_time_get_year (dt1));
-
- g_date_set_dmy (&dates[1],
- g_date_time_get_day_of_month (dt2),
- g_date_time_get_month (dt2),
- g_date_time_get_year (dt2));
-
- result = g_date_days_between (&dates[1], &dates[0]);
-
- if (result != 0)
- return result;
-
- return gtd_task_compare (task1, task2);
-}
-
static GtkWidget*
create_label (const gchar *text,
gboolean overdue)
@@ -201,20 +163,58 @@ header_func (GtdTask *task,
*/
static gboolean
-filter_func (GObject *object,
+filter_func (gpointer item,
gpointer user_data)
{
g_autoptr (GDateTime) task_dt = NULL;
g_autoptr (GDateTime) now = NULL;
GtdTask *task;
- task = (GtdTask*) object;
+ task = (GtdTask*) item;
now = g_date_time_new_now_local ();
task_dt = gtd_task_get_due_date (task);
return !gtd_task_get_complete (task) && should_be_added (now, task_dt);
}
+static gint
+sort_func (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data)
+{
+ g_autoptr (GDateTime) dt1 = NULL;
+ g_autoptr (GDateTime) dt2 = NULL;
+ GtdTask *task1;
+ GtdTask *task2;
+ GDate dates[2];
+ gint result;
+
+ task1 = (GtdTask*) a;
+ task2 = (GtdTask*) b;
+
+ dt1 = gtd_task_get_due_date (task1);
+ dt2 = gtd_task_get_due_date (task2);
+
+ g_date_clear (dates, 2);
+
+ g_date_set_dmy (&dates[0],
+ g_date_time_get_day_of_month (dt1),
+ g_date_time_get_month (dt1),
+ g_date_time_get_year (dt1));
+
+ g_date_set_dmy (&dates[1],
+ g_date_time_get_day_of_month (dt2),
+ g_date_time_get_month (dt2),
+ g_date_time_get_year (dt2));
+
+ result = g_date_days_between (&dates[1], &dates[0]);
+
+ if (result != 0)
+ return result;
+
+ return gtd_task_compare (task1, task2);
+}
+
static void
on_model_items_changed_cb (GListModel *model,
guint position,
@@ -238,7 +238,7 @@ on_timer_updated_cb (GtdTimer *timer,
now = g_date_time_new_now_local ();
gtd_task_list_view_set_default_date (self->view, now);
- gtd_list_model_filter_invalidate (self->filter_model);
+ gtk_filter_list_model_refilter (self->filter_model);
}
@@ -389,11 +389,8 @@ gtd_panel_today_init (GtdPanelToday *self)
self->icon = g_themed_icon_new ("view-tasks-today-symbolic");
- self->filter_model = gtd_list_model_filter_new (gtd_manager_get_tasks_model (manager));
- gtd_list_model_filter_set_filter_func (self->filter_model, filter_func, self, NULL);
-
- self->sort_model = gtd_list_model_sort_new (G_LIST_MODEL (self->filter_model));
- gtd_list_model_sort_set_sort_func (self->sort_model, sort_func, self, NULL);
+ self->filter_model = gtk_filter_list_model_new (gtd_manager_get_tasks_model (manager), filter_func, self,
NULL);
+ self->sort_model = gtk_sort_list_model_new (G_LIST_MODEL (self->filter_model), sort_func, self, NULL);
/* Connect to GtdManager::list-* signals to update the title */
manager = gtd_manager_get_default ();
diff --git a/src/task-list-view/gtd-task-list-popover.c b/src/task-list-view/gtd-task-list-popover.c
index d61e597..f084c64 100644
--- a/src/task-list-view/gtd-task-list-popover.c
+++ b/src/task-list-view/gtd-task-list-popover.c
@@ -32,7 +32,7 @@ struct _GtdTaskListPopover
{
GtkPopover parent;
- GtdListModelFilter *filter_model;
+ GtkFilterListModel *filter_model;
GtkSizeGroup *sizegroup;
GtkListBox *listbox;
@@ -79,7 +79,7 @@ set_selected_tasklist (GtdTaskListPopover *self,
*/
static gboolean
-filter_listbox_cb (GObject *object,
+filter_listbox_cb (gpointer item,
gpointer user_data)
{
GtdTaskListPopover *self;
@@ -88,7 +88,7 @@ filter_listbox_cb (GObject *object,
GtdTaskList *list;
self = (GtdTaskListPopover*) user_data;
- list = (GtdTaskList*) object;
+ list = (GtdTaskList*) item;
normalized_search_query = gtd_normalize_casefold_and_unaccent (gtk_entry_get_text (self->search_entry));
normalized_list_name = gtd_normalize_casefold_and_unaccent (gtd_task_list_get_name (list));
@@ -193,7 +193,7 @@ static void
on_search_entry_search_changed_cb (GtkEntry *search_entry,
GtdTaskListPopover *self)
{
- gtd_list_model_filter_invalidate (self->filter_model);
+ gtk_filter_list_model_refilter (self->filter_model);
}
@@ -242,11 +242,10 @@ gtd_task_list_popover_init (GtdTaskListPopover *self)
{
GtdManager *manager = gtd_manager_get_default ();
- self->filter_model = gtd_list_model_filter_new (gtd_manager_get_task_lists_model (manager));
- gtd_list_model_filter_set_filter_func (self->filter_model,
- filter_listbox_cb,
- self,
- NULL);
+ self->filter_model = gtk_filter_list_model_new (gtd_manager_get_task_lists_model (manager),
+ filter_listbox_cb,
+ self,
+ NULL);
gtk_widget_init_template (GTK_WIDGET (self));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]