Moved some functions to mdiary.h, started backend
This commit is contained in:
parent
9bac55c4ce
commit
6a47f95675
@ -2,6 +2,7 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "mdiary.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -12,6 +13,8 @@ int main(int argc, char *argv[])
|
|||||||
mainWindow = mainWindow_new();
|
mainWindow = mainWindow_new();
|
||||||
gtk_widget_show(mainWindow->mainWindow);
|
gtk_widget_show(mainWindow->mainWindow);
|
||||||
|
|
||||||
|
mdiary_scan_to_store("/", mainWindow->entryListStore);
|
||||||
|
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "mdiary.h"
|
#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_COUNT
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The dateFormats struct contains regex/date-info pairs to parse different date formats.
|
* @brief The dateFormats struct contains regex/date-info pairs to parse different date formats.
|
||||||
*/
|
*/
|
||||||
@ -114,65 +104,6 @@ static GDateTime *mainWindow_get_date_from_string(gchar *string)
|
|||||||
return datetime;
|
return datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 *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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief mainWindow_list_add_entry adds a diary entry to the main store. All parameters are duplicated.
|
|
||||||
* @param mainWindow struct mainWindow *
|
|
||||||
* @param title entry title
|
|
||||||
* @param datetime entry date time
|
|
||||||
* @param tags string list of tags
|
|
||||||
* @param text MD source of the entry
|
|
||||||
*/
|
|
||||||
static void mainWindow_list_add_entry(struct mainWindow *mainWindow,
|
|
||||||
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 = mainWindow_taglist_to_string(tags);
|
|
||||||
|
|
||||||
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),
|
|
||||||
-1);
|
|
||||||
g_free(date_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief mainWindow_list_entry_visible checks whether the entry should be displayed.
|
* @brief mainWindow_list_entry_visible checks whether the entry should be displayed.
|
||||||
* @param model N/A
|
* @param model N/A
|
||||||
@ -336,15 +267,15 @@ static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
|||||||
list = g_list_append(list, "Tag2");
|
list = g_list_append(list, "Tag2");
|
||||||
|
|
||||||
dt = g_date_time_new_local(2017, 11, 21, 02, 03, 0);
|
dt = g_date_time_new_local(2017, 11, 21, 02, 03, 0);
|
||||||
mainWindow_list_add_entry(mainWindow, "Title", dt, list, "Text text text");
|
mdiary_add_entry_to_store(mainWindow->entryListStore, "Title", dt, list, "Text text text");
|
||||||
g_date_time_unref(dt);
|
g_date_time_unref(dt);
|
||||||
|
|
||||||
dt = g_date_time_new_local(2017, 2, 3, 6, 7, 1);
|
dt = g_date_time_new_local(2017, 2, 3, 6, 7, 1);
|
||||||
mainWindow_list_add_entry(mainWindow, "AAA 2", dt, list, "fdfd Text text text");
|
mdiary_add_entry_to_store(mainWindow->entryListStore, "AAA 2", dt, list, "fdfd Text text text");
|
||||||
g_date_time_unref(dt);
|
g_date_time_unref(dt);
|
||||||
|
|
||||||
dt = g_date_time_new_local(2016, 4, 18, 13, 44, 2);
|
dt = g_date_time_new_local(2016, 4, 18, 13, 44, 2);
|
||||||
mainWindow_list_add_entry(mainWindow, "Yey entries 3", dt, list, "The content is content.");
|
mdiary_add_entry_to_store(mainWindow->entryListStore, "Yey entries 3", dt, list, "The content is content.");
|
||||||
g_date_time_unref(dt);
|
g_date_time_unref(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include "mdiary.h"
|
||||||
|
|
||||||
struct mainWindow {
|
struct mainWindow {
|
||||||
GtkWidget *mainWindow;
|
GtkWidget *mainWindow;
|
||||||
|
76
src/mdiary.c
76
src/mdiary.c
@ -1 +1,77 @@
|
|||||||
#include "mdiary.h"
|
#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);
|
||||||
|
}
|
||||||
|
20
src/mdiary.h
20
src/mdiary.h
@ -1,4 +1,24 @@
|
|||||||
#ifndef MDIARY_H
|
#ifndef MDIARY_H
|
||||||
#define MDIARY_H
|
#define MDIARY_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <gtk/gtk.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_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
void mdiary_scan_to_store(gchar *base_dir,
|
||||||
|
GtkListStore *entryListStore);
|
||||||
|
void mdiary_add_entry_to_store(GtkListStore *entryListStore,
|
||||||
|
gchar *title,
|
||||||
|
GDateTime *datetime,
|
||||||
|
GList *tags,
|
||||||
|
gchar *text);
|
||||||
#endif /* MDIARY_H */
|
#endif /* MDIARY_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user