78 lines
1.9 KiB
C
78 lines
1.9 KiB
C
#include "mdiary.h"
|
|
|
|
void mdiary_scan_to_store(gchar *base_dir, GtkListStore *entryListStore)
|
|
{
|
|
GError *error;
|
|
GDir *dir = g_dir_open("/", 0, &error);
|
|
gchar *dirname;
|
|
|
|
if (!dir) {
|
|
g_print("Error, could not open base directory.\n");
|
|
} else {
|
|
while (dirname = (gchar *)g_dir_read_name(dir)) {
|
|
g_print("EL=%s\n", dirname);
|
|
}
|
|
g_dir_close(dir);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief mainWindow_taglist_to_string concatenates a list with commas
|
|
* @param list is a GList of strings to concatenate
|
|
* @return The string, it needs to be freed using g_free().
|
|
*/
|
|
static gchar *mdiary_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;
|
|
}
|
|
|
|
/**
|
|
* @brief mdiary_add_entry_to_store adds the specified entry to the store. All params are copied.
|
|
* @param entryListStore target store
|
|
* @param title Entry title
|
|
* @param datetime Entry GDateTime
|
|
* @param tags Entry tags
|
|
* @param text Entry MD text (with header)
|
|
*/
|
|
void mdiary_add_entry_to_store(GtkListStore *entryListStore,
|
|
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 = mdiary_taglist_to_string(tags);
|
|
|
|
gtk_list_store_append(entryListStore, &iter);
|
|
gtk_list_store_set(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),
|
|
-1);
|
|
g_free(date_text);
|
|
}
|