Compare commits
No commits in common. "826ee5b0e0ceb4344e3083e5ae996a838e3614e3" and "6ee8b284b677af280863a320afea521514f2ab65" have entirely different histories.
826ee5b0e0
...
6ee8b284b6
@ -2,6 +2,18 @@
|
|||||||
<!-- Generated with glade 3.20.0 -->
|
<!-- Generated with glade 3.20.0 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
|
<object class="GtkListStore" id="entryListStore">
|
||||||
|
<columns>
|
||||||
|
<!-- column-name Title -->
|
||||||
|
<column type="gchararray"/>
|
||||||
|
<!-- column-name Date -->
|
||||||
|
<column type="gchararray"/>
|
||||||
|
<!-- column-name Tags -->
|
||||||
|
<column type="gchararray"/>
|
||||||
|
<!-- column-name Timestamp -->
|
||||||
|
<column type="guint"/>
|
||||||
|
</columns>
|
||||||
|
</object>
|
||||||
<object class="GtkTextBuffer" id="entryTextBuffer">
|
<object class="GtkTextBuffer" id="entryTextBuffer">
|
||||||
<property name="text" translatable="yes">Test text for debugging.</property>
|
<property name="text" translatable="yes">Test text for debugging.</property>
|
||||||
</object>
|
</object>
|
||||||
@ -120,6 +132,7 @@
|
|||||||
<property name="height_request">300</property>
|
<property name="height_request">300</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
|
<property name="model">entryListStore</property>
|
||||||
<child internal-child="selection">
|
<child internal-child="selection">
|
||||||
<object class="GtkTreeSelection" id="entryListSelection"/>
|
<object class="GtkTreeSelection" id="entryListSelection"/>
|
||||||
</child>
|
</child>
|
||||||
|
168
src/mainwindow.c
168
src/mainwindow.c
@ -2,129 +2,35 @@
|
|||||||
#include "mdiary.h"
|
#include "mdiary.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
COL_TITLE = 0, /* Title of the entry */
|
COL_TITLE = 0,
|
||||||
COL_DATE_TEXT, /* Textual representation of the date (auto generated) */
|
COL_DATE,
|
||||||
COL_TAGS_TEXT, /* Textual representation of the tags (auto generated) */
|
COL_TAGS,
|
||||||
COL_TIMESTAMP, /* GDateTime of the entry */
|
COL_TIMESTAMP,
|
||||||
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) {
|
||||||
* Returns: The string, needs to be freed using g_free().
|
|
||||||
*/
|
|
||||||
static gchar *mainWindow_taglist_to_string(GList *list)
|
|
||||||
{
|
|
||||||
GString *str = NULL;
|
|
||||||
gchar *ret = NULL;
|
|
||||||
GList *l;
|
|
||||||
|
|
||||||
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;
|
GtkTreeIter iter;
|
||||||
GDateTime *datetime_copy;
|
|
||||||
gchar *date_text;
|
gchar *date_text;
|
||||||
gchar *taglistString;
|
|
||||||
|
|
||||||
datetime_copy = g_date_time_add(datetime, 0);
|
date_text = g_date_time_format(mdiary_entry->date, "%A, %e %B %Y %R");
|
||||||
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, title,
|
COL_TITLE, mdiary_entry->title,
|
||||||
COL_DATE_TEXT, date_text,
|
COL_DATE, date_text,
|
||||||
COL_TAGS_TEXT, taglistString,
|
COL_TAGS, mdiary_entry->tags,
|
||||||
COL_TIMESTAMP, datetime_copy,
|
COL_TIMESTAMP, g_date_time_to_unix(mdiary_entry->date),
|
||||||
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,
|
||||||
@ -135,55 +41,58 @@ 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_TEXT, NULL);
|
"text", COL_DATE, NULL);
|
||||||
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_DATE_TEXT);
|
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_DATE);
|
||||||
gtk_tree_view_column_set_resizable(col, 1);
|
gtk_tree_view_column_set_resizable(col, 1);
|
||||||
gtk_tree_sortable_set_sort_func(sortable, COL_TIMESTAMP, mainWindow_sort_date_compare_func,
|
gtk_tree_view_column_set_sort_column_id(col, COL_TIMESTAMP);
|
||||||
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_TEXT, NULL);
|
"text", COL_TAGS, NULL);
|
||||||
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_TAGS_TEXT);
|
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_TAGS);
|
||||||
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_TEXT);
|
gtk_tree_view_column_set_sort_column_id(col, COL_TAGS);
|
||||||
|
|
||||||
gtk_tree_sortable_set_sort_column_id(sortable, COL_DATE_TEXT, GTK_SORT_DESCENDING);
|
sortable = GTK_TREE_SORTABLE(mainWindow->entryListStore);
|
||||||
|
gtk_tree_sortable_set_sort_column_id(sortable, COL_DATE, GTK_SORT_DESCENDING);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test entries for debugging only
|
* Test entries for debugging only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GDateTime *dt;
|
struct mdiary_entry test;
|
||||||
GList *list = NULL;
|
test.title = "Hello";
|
||||||
|
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);
|
||||||
|
|
||||||
list = g_list_append(list, "Tag0");
|
test.title = "Entry";
|
||||||
list = g_list_append(list, "Tag1");
|
test.tags = "Tag, B, C";
|
||||||
list = g_list_append(list, "Tag2");
|
test.date = g_date_time_new_local(2016, 10, 4, 5, 34, 0);
|
||||||
|
mainWindow_list_add_entry(mainWindow, &test);
|
||||||
|
g_date_time_unref(test.date);
|
||||||
|
|
||||||
dt = g_date_time_new_local(2017, 11, 21, 02, 03, 0);
|
test.title = "A Third One for Testing";
|
||||||
mainWindow_list_add_entry(mainWindow, "Title", dt, list, "Text text text");
|
test.tags = "Yey, stuff, works";
|
||||||
g_date_time_unref(dt);
|
test.date = g_date_time_new_local(2016, 12, 22, 1, 55, 0);
|
||||||
|
mainWindow_list_add_entry(mainWindow, &test);
|
||||||
dt = g_date_time_new_local(2017, 2, 3, 6, 7, 0);
|
g_date_time_unref(test.date);
|
||||||
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",
|
||||||
(GCallback) mainWindow_showPopover,
|
mainWindow_showPopover,
|
||||||
mainWindow);
|
mainWindow);
|
||||||
g_signal_connect(mainWindow->dateEnd,
|
g_signal_connect(mainWindow->dateEnd,
|
||||||
"focus-in-event",
|
"focus-in-event",
|
||||||
(GCallback) mainWindow_showPopover,
|
mainWindow_showPopover,
|
||||||
mainWindow);
|
mainWindow);
|
||||||
g_signal_connect(mainWindow->calendarRange,
|
g_signal_connect(mainWindow->calendarRange,
|
||||||
"day-selected",
|
"day-selected",
|
||||||
(GCallback) mainWindow_calendarSelected,
|
mainWindow_calendarSelected,
|
||||||
mainWindow);
|
mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +113,7 @@ 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);
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ struct mainWindow {
|
|||||||
GtkWidget *popoverDate;
|
GtkWidget *popoverDate;
|
||||||
GtkWidget *calendarRange;
|
GtkWidget *calendarRange;
|
||||||
GtkTreeView *entryListView;
|
GtkTreeView *entryListView;
|
||||||
|
|
||||||
GtkListStore *entryListStore;
|
GtkListStore *entryListStore;
|
||||||
|
|
||||||
GtkWidget *selectedDateEntry;
|
GtkWidget *selectedDateEntry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
#ifndef MDIARY_H
|
#ifndef MDIARY_H
|
||||||
#define MDIARY_H
|
#define MDIARY_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
struct mdiary_entry {
|
||||||
|
gchar *title;
|
||||||
|
GDateTime *date;
|
||||||
|
gchar *tags;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* MDIARY_H */
|
#endif /* MDIARY_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user