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 "mainwindow.h"
|
||||||
|
#include "mdiary.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
COL_TITLE = 0,
|
COL_TITLE = 0,
|
||||||
@ -8,10 +9,26 @@ enum {
|
|||||||
COL_COUNT
|
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)
|
static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
||||||
{
|
{
|
||||||
GtkCellRenderer *renderer;
|
GtkCellRenderer *renderer;
|
||||||
GtkTreeIter iter;
|
|
||||||
GtkTreeSortable *sortable;
|
GtkTreeSortable *sortable;
|
||||||
GtkTreeViewColumn *col;
|
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);
|
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,
|
struct mdiary_entry test;
|
||||||
COL_TITLE, "ZA Test entry longer title",
|
test.title = "Hello";
|
||||||
COL_DATE, "Weekday, Month nth Year hh:mm",
|
test.tags = "world";
|
||||||
COL_TAGS, "X",
|
test.date = g_date_time_new_local(2017, 11, 21, 02, 03, 0);
|
||||||
COL_TIMESTAMP, 123,
|
mainWindow_list_add_entry(mainWindow, &test);
|
||||||
-1);
|
g_date_time_unref(test.date);
|
||||||
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
|
||||||
gtk_list_store_set(mainWindow->entryListStore, &iter,
|
test.title = "Entry";
|
||||||
COL_TITLE, "baz",
|
test.tags = "Tag, B, C";
|
||||||
COL_DATE, "Mayday, July 8th 1234",
|
test.date = g_date_time_new_local(2016, 10, 4, 5, 34, 0);
|
||||||
COL_TAGS, "A",
|
mainWindow_list_add_entry(mainWindow, &test);
|
||||||
COL_TIMESTAMP, 555,
|
g_date_time_unref(test.date);
|
||||||
-1);
|
|
||||||
gtk_list_store_append(mainWindow->entryListStore, &iter);
|
test.title = "A Third One for Testing";
|
||||||
gtk_list_store_set(mainWindow->entryListStore, &iter,
|
test.tags = "Yey, stuff, works";
|
||||||
COL_TITLE, "Foo",
|
test.date = g_date_time_new_local(2016, 12, 22, 1, 55, 0);
|
||||||
COL_DATE, "Sunday, Movember 1337",
|
mainWindow_list_add_entry(mainWindow, &test);
|
||||||
COL_TAGS, "F",
|
g_date_time_unref(test.date);
|
||||||
COL_TIMESTAMP, 11,
|
|
||||||
-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mainWindow_connect_signals(struct mainWindow *mainWindow)
|
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