Added timestamp sorting for date field
This commit is contained in:
parent
02ac6dc595
commit
40c2b77d39
@ -10,6 +10,8 @@
|
|||||||
<column type="gchararray"/>
|
<column type="gchararray"/>
|
||||||
<!-- column-name Tags -->
|
<!-- column-name Tags -->
|
||||||
<column type="gchararray"/>
|
<column type="gchararray"/>
|
||||||
|
<!-- column-name Timestamp -->
|
||||||
|
<column type="guint"/>
|
||||||
</columns>
|
</columns>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkTextBuffer" id="entryTextBuffer">
|
<object class="GtkTextBuffer" id="entryTextBuffer">
|
||||||
|
@ -4,10 +4,31 @@ enum {
|
|||||||
COL_TITLE = 0,
|
COL_TITLE = 0,
|
||||||
COL_DATE,
|
COL_DATE,
|
||||||
COL_TAGS,
|
COL_TAGS,
|
||||||
|
COL_TIMESTAMP,
|
||||||
COL_COUNT
|
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;
|
GtkCellRenderer *renderer;
|
||||||
GtkTreeIter iter;
|
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_resizable(col, 1);
|
||||||
gtk_tree_view_column_set_sort_column_id(col, COL_TAGS);
|
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,
|
sortable = GTK_TREE_SORTABLE(mainWindow->entryListStore);
|
||||||
GINT_TO_POINTER(COL_DATE), NULL);*/
|
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
|
* Code just for debugging - some test values
|
||||||
*/
|
*/
|
||||||
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
||||||
gtk_list_store_set (mainWindow->entryListStore, &iter,
|
gtk_list_store_set(mainWindow->entryListStore, &iter,
|
||||||
COL_TITLE, "ZA Test entry longer title",
|
COL_TITLE, "ZA Test entry longer title",
|
||||||
COL_DATE, "2016-05-12",
|
COL_DATE, "Weekday, Month nth Year hh:mm",
|
||||||
COL_TAGS, "X",
|
COL_TAGS, "X",
|
||||||
|
COL_TIMESTAMP, 123,
|
||||||
-1);
|
-1);
|
||||||
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
||||||
gtk_list_store_set (mainWindow->entryListStore, &iter,
|
gtk_list_store_set(mainWindow->entryListStore, &iter,
|
||||||
COL_TITLE, "baz",
|
COL_TITLE, "baz",
|
||||||
COL_DATE, "2016-11-22",
|
COL_DATE, "Mayday, July 8th 1234",
|
||||||
COL_TAGS, "A",
|
COL_TAGS, "A",
|
||||||
|
COL_TIMESTAMP, 555,
|
||||||
-1);
|
-1);
|
||||||
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
||||||
gtk_list_store_set (mainWindow->entryListStore, &iter,
|
gtk_list_store_set(mainWindow->entryListStore, &iter,
|
||||||
COL_TITLE, "Foo",
|
COL_TITLE, "Foo",
|
||||||
COL_DATE, "1998-12-03",
|
COL_DATE, "Sunday, Movember 1337",
|
||||||
COL_TAGS, "F",
|
COL_TAGS, "F",
|
||||||
|
COL_TIMESTAMP, 11,
|
||||||
-1);
|
-1);
|
||||||
|
|
||||||
sortable = GTK_TREE_SORTABLE(mainWindow->entryListStore);
|
|
||||||
gtk_tree_sortable_set_sort_column_id(sortable, COL_DATE, GTK_SORT_DESCENDING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mainWindow *mainWindow_new()
|
struct mainWindow *mainWindow_new()
|
||||||
@ -85,7 +108,7 @@ struct mainWindow *mainWindow_new()
|
|||||||
|
|
||||||
g_object_unref(G_OBJECT(builder));
|
g_object_unref(G_OBJECT(builder));
|
||||||
|
|
||||||
mainWindow_test_treeView(mainWindow);
|
mainWindow_configure_treeView(mainWindow);
|
||||||
|
|
||||||
return mainWindow;
|
return mainWindow;
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,4 @@ struct mainWindow {
|
|||||||
|
|
||||||
struct mainWindow *mainWindow_new();
|
struct mainWindow *mainWindow_new();
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif /* MAINWINDOW_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user