Added timestamp sorting for date field

This commit is contained in:
Markus Koch 2017-01-31 21:56:37 +01:00
parent 02ac6dc595
commit 40c2b77d39
3 changed files with 48 additions and 23 deletions

View File

@ -10,6 +10,8 @@
<column type="gchararray"/>
<!-- column-name Tags -->
<column type="gchararray"/>
<!-- column-name Timestamp -->
<column type="guint"/>
</columns>
</object>
<object class="GtkTextBuffer" id="entryTextBuffer">

View File

@ -4,10 +4,31 @@ enum {
COL_TITLE = 0,
COL_DATE,
COL_TAGS,
COL_TIMESTAMP,
COL_COUNT
};
static void mainWindow_test_treeView(struct mainWindow *mainWindow)
static gint
mainWindow_sort_date_compare_func(GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer userdata)
{
guint time1, time2;
gtk_tree_model_get(model, a, COL_TIMESTAMP, &time1, -1);
gtk_tree_model_get(model, b, COL_TIMESTAMP, &time2, -1);
if (time1 == time2)
return 0;
else if (time1 > time2)
return 1;
else
return -1;
}
static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
{
GtkCellRenderer *renderer;
GtkTreeIter iter;
@ -35,33 +56,35 @@ static void mainWindow_test_treeView(struct mainWindow *mainWindow)
gtk_tree_view_column_set_resizable(col, 1);
gtk_tree_view_column_set_sort_column_id(col, COL_TAGS);
/*gtk_tree_sortable_set_sort_func(sortable, COL_DATE, mainWindow_sort_date_compare_func,
GINT_TO_POINTER(COL_DATE), NULL);*/
sortable = GTK_TREE_SORTABLE(mainWindow->entryListStore);
gtk_tree_sortable_set_sort_func(sortable, COL_DATE, mainWindow_sort_date_compare_func,
GINT_TO_POINTER(COL_DATE), NULL);
gtk_tree_sortable_set_sort_column_id(sortable, COL_DATE, GTK_SORT_DESCENDING);
/*
* Code just for debugging - some test values
*/
gtk_list_store_append(mainWindow->entryListStore, &iter);
gtk_list_store_set (mainWindow->entryListStore, &iter,
COL_TITLE, "ZA Test entry longer title",
COL_DATE, "2016-05-12",
COL_TAGS, "X",
-1);
gtk_list_store_set(mainWindow->entryListStore, &iter,
COL_TITLE, "ZA Test entry longer title",
COL_DATE, "Weekday, Month nth Year hh:mm",
COL_TAGS, "X",
COL_TIMESTAMP, 123,
-1);
gtk_list_store_append(mainWindow->entryListStore, &iter);
gtk_list_store_set (mainWindow->entryListStore, &iter,
COL_TITLE, "baz",
COL_DATE, "2016-11-22",
COL_TAGS, "A",
-1);
gtk_list_store_set(mainWindow->entryListStore, &iter,
COL_TITLE, "baz",
COL_DATE, "Mayday, July 8th 1234",
COL_TAGS, "A",
COL_TIMESTAMP, 555,
-1);
gtk_list_store_append(mainWindow->entryListStore, &iter);
gtk_list_store_set (mainWindow->entryListStore, &iter,
COL_TITLE, "Foo",
COL_DATE, "1998-12-03",
COL_TAGS, "F",
-1);
sortable = GTK_TREE_SORTABLE(mainWindow->entryListStore);
gtk_tree_sortable_set_sort_column_id(sortable, COL_DATE, GTK_SORT_DESCENDING);
gtk_list_store_set(mainWindow->entryListStore, &iter,
COL_TITLE, "Foo",
COL_DATE, "Sunday, Movember 1337",
COL_TAGS, "F",
COL_TIMESTAMP, 11,
-1);
}
struct mainWindow *mainWindow_new()
@ -85,7 +108,7 @@ struct mainWindow *mainWindow_new()
g_object_unref(G_OBJECT(builder));
mainWindow_test_treeView(mainWindow);
mainWindow_configure_treeView(mainWindow);
return mainWindow;
}

View File

@ -17,4 +17,4 @@ struct mainWindow {
struct mainWindow *mainWindow_new();
#endif // MAINWINDOW_H
#endif /* MAINWINDOW_H */