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 -->
|
||||
<interface>
|
||||
<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">
|
||||
<property name="text" translatable="yes">Test text for debugging.</property>
|
||||
</object>
|
||||
@ -120,6 +132,7 @@
|
||||
<property name="height_request">300</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">entryListStore</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="entryListSelection"/>
|
||||
</child>
|
||||
|
168
src/mainwindow.c
168
src/mainwindow.c
@ -2,129 +2,35 @@
|
||||
#include "mdiary.h"
|
||||
|
||||
enum {
|
||||
COL_TITLE = 0, /* Title of the entry */
|
||||
COL_DATE_TEXT, /* Textual representation of the date (auto generated) */
|
||||
COL_TAGS_TEXT, /* Textual representation of the tags (auto generated) */
|
||||
COL_TIMESTAMP, /* GDateTime of the entry */
|
||||
COL_TAGLIST, /* GList<gchar *> of the tags */
|
||||
COL_TEXT, /* Raw text from the file */
|
||||
COL_TITLE = 0,
|
||||
COL_DATE,
|
||||
COL_TAGS,
|
||||
COL_TIMESTAMP,
|
||||
COL_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
static void mainWindow_list_add_entry(struct mainWindow *mainWindow, struct mdiary_entry *mdiary_entry) {
|
||||
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);
|
||||
date_text = g_date_time_format(mdiary_entry->date, "%A, %e %B %Y %R");
|
||||
|
||||
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
||||
gtk_list_store_set(mainWindow->entryListStore, &iter,
|
||||
COL_TITLE, title,
|
||||
COL_DATE_TEXT, date_text,
|
||||
COL_TAGS_TEXT, taglistString,
|
||||
COL_TIMESTAMP, datetime_copy,
|
||||
COL_TAGLIST, NULL,
|
||||
COL_TEXT, g_strdup(text),
|
||||
COL_TITLE, mdiary_entry->title,
|
||||
COL_DATE, date_text,
|
||||
COL_TAGS, mdiary_entry->tags,
|
||||
COL_TIMESTAMP, g_date_time_to_unix(mdiary_entry->date),
|
||||
-1);
|
||||
|
||||
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)
|
||||
{
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeSortable *sortable;
|
||||
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();
|
||||
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();
|
||||
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Date", renderer,
|
||||
"text", COL_DATE_TEXT, NULL);
|
||||
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_DATE_TEXT);
|
||||
"text", COL_DATE, NULL);
|
||||
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_DATE);
|
||||
gtk_tree_view_column_set_resizable(col, 1);
|
||||
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);
|
||||
gtk_tree_view_column_set_sort_column_id(col, COL_TIMESTAMP);
|
||||
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Tags", renderer,
|
||||
"text", COL_TAGS_TEXT, NULL);
|
||||
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_TAGS_TEXT);
|
||||
"text", COL_TAGS, NULL);
|
||||
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_TAGS);
|
||||
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
|
||||
*/
|
||||
|
||||
GDateTime *dt;
|
||||
GList *list = NULL;
|
||||
struct mdiary_entry test;
|
||||
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");
|
||||
list = g_list_append(list, "Tag1");
|
||||
list = g_list_append(list, "Tag2");
|
||||
test.title = "Entry";
|
||||
test.tags = "Tag, B, C";
|
||||
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);
|
||||
mainWindow_list_add_entry(mainWindow, "Title", dt, list, "Text text text");
|
||||
g_date_time_unref(dt);
|
||||
|
||||
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);
|
||||
test.title = "A Third One for Testing";
|
||||
test.tags = "Yey, stuff, works";
|
||||
test.date = g_date_time_new_local(2016, 12, 22, 1, 55, 0);
|
||||
mainWindow_list_add_entry(mainWindow, &test);
|
||||
g_date_time_unref(test.date);
|
||||
}
|
||||
|
||||
static void mainWindow_connect_signals(struct mainWindow *mainWindow)
|
||||
{
|
||||
g_signal_connect(mainWindow->dateStart,
|
||||
"focus-in-event",
|
||||
(GCallback) mainWindow_showPopover,
|
||||
mainWindow_showPopover,
|
||||
mainWindow);
|
||||
g_signal_connect(mainWindow->dateEnd,
|
||||
"focus-in-event",
|
||||
(GCallback) mainWindow_showPopover,
|
||||
mainWindow_showPopover,
|
||||
mainWindow);
|
||||
g_signal_connect(mainWindow->calendarRange,
|
||||
"day-selected",
|
||||
(GCallback) mainWindow_calendarSelected,
|
||||
mainWindow_calendarSelected,
|
||||
mainWindow);
|
||||
}
|
||||
|
||||
@ -204,6 +113,7 @@ struct mainWindow *mainWindow_new()
|
||||
mainWindow->popoverDate = GTK_WIDGET(gtk_builder_get_object(builder, "popoverDate"));
|
||||
mainWindow->calendarRange = GTK_WIDGET(gtk_builder_get_object(builder, "calendarRange"));
|
||||
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);
|
||||
|
||||
|
@ -14,8 +14,8 @@ struct mainWindow {
|
||||
GtkWidget *popoverDate;
|
||||
GtkWidget *calendarRange;
|
||||
GtkTreeView *entryListView;
|
||||
|
||||
GtkListStore *entryListStore;
|
||||
|
||||
GtkWidget *selectedDateEntry;
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,12 @@
|
||||
#ifndef MDIARY_H
|
||||
#define MDIARY_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
struct mdiary_entry {
|
||||
gchar *title;
|
||||
GDateTime *date;
|
||||
gchar *tags;
|
||||
};
|
||||
|
||||
#endif /* MDIARY_H */
|
||||
|
Loading…
Reference in New Issue
Block a user