|
|
@ -2,35 +2,129 @@
|
|
|
|
#include "mdiary.h"
|
|
|
|
#include "mdiary.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
enum {
|
|
|
|
COL_TITLE = 0,
|
|
|
|
COL_TITLE = 0, /* Title of the entry */
|
|
|
|
COL_DATE,
|
|
|
|
COL_DATE_TEXT, /* Textual representation of the date (auto generated) */
|
|
|
|
COL_TAGS,
|
|
|
|
COL_TAGS_TEXT, /* Textual representation of the tags (auto generated) */
|
|
|
|
COL_TIMESTAMP,
|
|
|
|
COL_TIMESTAMP, /* GDateTime of the entry */
|
|
|
|
|
|
|
|
COL_TAGLIST, /* GList<gchar *> of the tags */
|
|
|
|
|
|
|
|
COL_TEXT, /* Raw text from the file */
|
|
|
|
COL_COUNT
|
|
|
|
COL_COUNT
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void mainWindow_list_add_entry(struct mainWindow *mainWindow, struct mdiary_entry *mdiary_entry) {
|
|
|
|
/**
|
|
|
|
GtkTreeIter iter;
|
|
|
|
* Returns: The string, needs to be freed using g_free().
|
|
|
|
gchar *date_text;
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gchar *mainWindow_taglist_to_string(GList *list)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GString *str = NULL;
|
|
|
|
|
|
|
|
gchar *ret = NULL;
|
|
|
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
|
|
date_text = g_date_time_format(mdiary_entry->date, "%A, %e %B %Y %R");
|
|
|
|
for (l = list; l != NULL; l = l->next)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (str == NULL)
|
|
|
|
|
|
|
|
str = g_string_new("");
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
str = g_string_append(str, ", ");
|
|
|
|
|
|
|
|
str = g_string_append(str, l->data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret = str->str;
|
|
|
|
|
|
|
|
g_string_free(str, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Note: This function creates a copyof each argument.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void mainWindow_list_add_entry(struct mainWindow *mainWindow,
|
|
|
|
|
|
|
|
gchar *title,
|
|
|
|
|
|
|
|
GDateTime *datetime,
|
|
|
|
|
|
|
|
GList *tags,
|
|
|
|
|
|
|
|
gchar *text) {
|
|
|
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
GDateTime *datetime_copy;
|
|
|
|
|
|
|
|
gchar *date_text;
|
|
|
|
|
|
|
|
gchar *taglistString;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
datetime_copy = g_date_time_add(datetime, 0);
|
|
|
|
|
|
|
|
date_text = g_date_time_format(datetime_copy, "%A, %e %B %Y %R");
|
|
|
|
|
|
|
|
taglistString = mainWindow_taglist_to_string(tags);
|
|
|
|
|
|
|
|
|
|
|
|
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, mdiary_entry->title,
|
|
|
|
COL_TITLE, title,
|
|
|
|
COL_DATE, date_text,
|
|
|
|
COL_DATE_TEXT, date_text,
|
|
|
|
COL_TAGS, mdiary_entry->tags,
|
|
|
|
COL_TAGS_TEXT, taglistString,
|
|
|
|
COL_TIMESTAMP, g_date_time_to_unix(mdiary_entry->date),
|
|
|
|
COL_TIMESTAMP, datetime_copy,
|
|
|
|
|
|
|
|
COL_TAGLIST, NULL,
|
|
|
|
|
|
|
|
COL_TEXT, g_strdup(text),
|
|
|
|
-1);
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
|
|
g_free(date_text);
|
|
|
|
g_free(date_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean mainWindow_list_entry_visible (GtkTreeModel *model, GtkTreeIter *iter, struct mainWindow *mainWindow)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* gtk_tree_model_get (model, iter, COLUMN_NAME, &target, -1); */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
|
|
|
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
|
|
|
gpointer userdata)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GDateTime *datetime1;
|
|
|
|
|
|
|
|
GDateTime *datetime2;
|
|
|
|
|
|
|
|
guint time1;
|
|
|
|
|
|
|
|
guint time2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, a, COL_TIMESTAMP, &datetime1, -1);
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, b, COL_TIMESTAMP, &datetime2, -1);
|
|
|
|
|
|
|
|
time1 = g_date_time_to_unix(datetime1);
|
|
|
|
|
|
|
|
time2 = g_date_time_to_unix(datetime2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (time1 == time2)
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
else if (time1 > time2)
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
|
|
|
static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkTreeSortable *sortable;
|
|
|
|
GtkTreeSortable *sortable;
|
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
GtkTreeModelFilter *filtered;
|
|
|
|
|
|
|
|
GtkTreeModelSort *sorted;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mainWindow->entryListStore = gtk_list_store_new(COL_COUNT,
|
|
|
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
|
|
|
G_TYPE_POINTER,
|
|
|
|
|
|
|
|
G_TYPE_POINTER,
|
|
|
|
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
|
|
filtered = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (
|
|
|
|
|
|
|
|
GTK_TREE_MODEL (mainWindow->entryListStore), NULL));
|
|
|
|
|
|
|
|
sorted = GTK_TREE_MODEL_SORT (gtk_tree_model_sort_new_with_model (
|
|
|
|
|
|
|
|
GTK_TREE_MODEL (filtered)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_set_visible_func (filtered,
|
|
|
|
|
|
|
|
(GtkTreeModelFilterVisibleFunc) mainWindow_list_entry_visible,
|
|
|
|
|
|
|
|
mainWindow, NULL);
|
|
|
|
|
|
|
|
model = GTK_TREE_MODEL (sorted);
|
|
|
|
|
|
|
|
gtk_tree_view_set_model(mainWindow->entryListView, model);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* TODO: Unref mainWindow->entryListStore and filtered, sorted and model? */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sortable = GTK_TREE_SORTABLE(sorted);
|
|
|
|
|
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Title", renderer,
|
|
|
|
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Title", renderer,
|
|
|
@ -41,58 +135,55 @@ static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
|
|
|
|
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Date", renderer,
|
|
|
|
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Date", renderer,
|
|
|
|
"text", COL_DATE, NULL);
|
|
|
|
"text", COL_DATE_TEXT, NULL);
|
|
|
|
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_DATE);
|
|
|
|
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_DATE_TEXT);
|
|
|
|
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_TIMESTAMP);
|
|
|
|
gtk_tree_sortable_set_sort_func(sortable, COL_TIMESTAMP, mainWindow_sort_date_compare_func,
|
|
|
|
|
|
|
|
GINT_TO_POINTER(COL_TIMESTAMP), NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id(col, COL_DATE_TEXT);
|
|
|
|
|
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Tags", renderer,
|
|
|
|
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Tags", renderer,
|
|
|
|
"text", COL_TAGS, NULL);
|
|
|
|
"text", COL_TAGS_TEXT, NULL);
|
|
|
|
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_TAGS);
|
|
|
|
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_TAGS_TEXT);
|
|
|
|
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_TEXT);
|
|
|
|
|
|
|
|
|
|
|
|
sortable = GTK_TREE_SORTABLE(mainWindow->entryListStore);
|
|
|
|
gtk_tree_sortable_set_sort_column_id(sortable, COL_DATE_TEXT, GTK_SORT_DESCENDING);
|
|
|
|
gtk_tree_sortable_set_sort_column_id(sortable, COL_DATE, GTK_SORT_DESCENDING);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Test entries for debugging only
|
|
|
|
* Test entries for debugging only
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
struct mdiary_entry test;
|
|
|
|
GDateTime *dt;
|
|
|
|
test.title = "Hello";
|
|
|
|
GList *list = NULL;
|
|
|
|
test.tags = "world";
|
|
|
|
|
|
|
|
test.date = g_date_time_new_local(2017, 11, 21, 02, 03, 0);
|
|
|
|
|
|
|
|
mainWindow_list_add_entry(mainWindow, &test);
|
|
|
|
|
|
|
|
g_date_time_unref(test.date);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test.title = "Entry";
|
|
|
|
list = g_list_append(list, "Tag0");
|
|
|
|
test.tags = "Tag, B, C";
|
|
|
|
list = g_list_append(list, "Tag1");
|
|
|
|
test.date = g_date_time_new_local(2016, 10, 4, 5, 34, 0);
|
|
|
|
list = g_list_append(list, "Tag2");
|
|
|
|
mainWindow_list_add_entry(mainWindow, &test);
|
|
|
|
|
|
|
|
g_date_time_unref(test.date);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test.title = "A Third One for Testing";
|
|
|
|
dt = g_date_time_new_local(2017, 11, 21, 02, 03, 0);
|
|
|
|
test.tags = "Yey, stuff, works";
|
|
|
|
mainWindow_list_add_entry(mainWindow, "Title", dt, list, "Text text text");
|
|
|
|
test.date = g_date_time_new_local(2016, 12, 22, 1, 55, 0);
|
|
|
|
g_date_time_unref(dt);
|
|
|
|
mainWindow_list_add_entry(mainWindow, &test);
|
|
|
|
|
|
|
|
g_date_time_unref(test.date);
|
|
|
|
dt = g_date_time_new_local(2017, 2, 3, 6, 7, 0);
|
|
|
|
|
|
|
|
mainWindow_list_add_entry(mainWindow, "AAA 2", dt, list, "fdfd Text text text");
|
|
|
|
|
|
|
|
g_date_time_unref(dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void mainWindow_connect_signals(struct mainWindow *mainWindow)
|
|
|
|
static void mainWindow_connect_signals(struct mainWindow *mainWindow)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
g_signal_connect(mainWindow->dateStart,
|
|
|
|
g_signal_connect(mainWindow->dateStart,
|
|
|
|
"focus-in-event",
|
|
|
|
"focus-in-event",
|
|
|
|
mainWindow_showPopover,
|
|
|
|
(GCallback) mainWindow_showPopover,
|
|
|
|
mainWindow);
|
|
|
|
mainWindow);
|
|
|
|
g_signal_connect(mainWindow->dateEnd,
|
|
|
|
g_signal_connect(mainWindow->dateEnd,
|
|
|
|
"focus-in-event",
|
|
|
|
"focus-in-event",
|
|
|
|
mainWindow_showPopover,
|
|
|
|
(GCallback) mainWindow_showPopover,
|
|
|
|
mainWindow);
|
|
|
|
mainWindow);
|
|
|
|
g_signal_connect(mainWindow->calendarRange,
|
|
|
|
g_signal_connect(mainWindow->calendarRange,
|
|
|
|
"day-selected",
|
|
|
|
"day-selected",
|
|
|
|
mainWindow_calendarSelected,
|
|
|
|
(GCallback) mainWindow_calendarSelected,
|
|
|
|
mainWindow);
|
|
|
|
mainWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -113,7 +204,6 @@ struct mainWindow *mainWindow_new()
|
|
|
|
mainWindow->popoverDate = GTK_WIDGET(gtk_builder_get_object(builder, "popoverDate"));
|
|
|
|
mainWindow->popoverDate = GTK_WIDGET(gtk_builder_get_object(builder, "popoverDate"));
|
|
|
|
mainWindow->calendarRange = GTK_WIDGET(gtk_builder_get_object(builder, "calendarRange"));
|
|
|
|
mainWindow->calendarRange = GTK_WIDGET(gtk_builder_get_object(builder, "calendarRange"));
|
|
|
|
mainWindow->entryListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "entryListView"));
|
|
|
|
mainWindow->entryListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "entryListView"));
|
|
|
|
mainWindow->entryListStore = GTK_LIST_STORE(gtk_builder_get_object(builder, "entryListStore"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gtk_builder_connect_signals(builder, NULL);
|
|
|
|
gtk_builder_connect_signals(builder, NULL);
|
|
|
|
|
|
|
|
|
|
|
|