Added helper function to add entries to the list
This commit is contained in:
parent
b5c1bd3613
commit
6ee8b284b6
@ -1,4 +1,5 @@
|
||||
#include "mainwindow.h"
|
||||
#include "mdiary.h"
|
||||
|
||||
enum {
|
||||
COL_TITLE = 0,
|
||||
@ -8,10 +9,26 @@ enum {
|
||||
COL_COUNT
|
||||
};
|
||||
|
||||
static void mainWindow_list_add_entry(struct mainWindow *mainWindow, struct mdiary_entry *mdiary_entry) {
|
||||
GtkTreeIter iter;
|
||||
gchar *date_text;
|
||||
|
||||
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, 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 void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
||||
{
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeSortable *sortable;
|
||||
GtkTreeViewColumn *col;
|
||||
|
||||
@ -40,29 +57,27 @@ static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
||||
gtk_tree_sortable_set_sort_column_id(sortable, COL_DATE, GTK_SORT_DESCENDING);
|
||||
|
||||
/*
|
||||
* Code just for debugging - some test values
|
||||
* Test entries for debugging only
|
||||
*/
|
||||
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
||||
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, "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, "Sunday, Movember 1337",
|
||||
COL_TAGS, "F",
|
||||
COL_TIMESTAMP, 11,
|
||||
-1);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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)
|
||||
|
1
src/mdiary.c
Normal file
1
src/mdiary.c
Normal file
@ -0,0 +1 @@
|
||||
#include "mdiary.h"
|
12
src/mdiary.h
Normal file
12
src/mdiary.h
Normal file
@ -0,0 +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