Compare commits
3 Commits
7f296855d5
...
1101026d19
Author | SHA1 | Date | |
---|---|---|---|
1101026d19 | |||
ec7a072920 | |||
6a8cbccbfe |
145
src/mainwindow.c
145
src/mainwindow.c
@ -11,7 +11,9 @@ enum {
|
|||||||
COL_COUNT
|
COL_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The dateFormats struct contains regex/date-info pairs to parse different date formats.
|
||||||
|
*/
|
||||||
struct dateFormats {
|
struct dateFormats {
|
||||||
gchar *regex;
|
gchar *regex;
|
||||||
guint index_count;
|
guint index_count;
|
||||||
@ -59,7 +61,7 @@ struct dateFormats {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Tries to guess the date format used and converts it to GDateTime.
|
* @brief mainWindow_get_date_from_string tries to guess the date format used and converts it to GDateTime.
|
||||||
* @param Input string.
|
* @param Input string.
|
||||||
* @return A GDateTime object or NULL on error. You need to free it after use.
|
* @return A GDateTime object or NULL on error. You need to free it after use.
|
||||||
*/
|
*/
|
||||||
@ -113,7 +115,9 @@ static GDateTime *mainWindow_get_date_from_string(gchar *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns: The string, needs to be freed using g_free().
|
* @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)
|
static gchar *mainWindow_taglist_to_string(GList *list)
|
||||||
{
|
{
|
||||||
@ -136,7 +140,12 @@ static gchar *mainWindow_taglist_to_string(GList *list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: This function creates a copyof each argument.
|
* @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,
|
static void mainWindow_list_add_entry(struct mainWindow *mainWindow,
|
||||||
gchar *title,
|
gchar *title,
|
||||||
@ -164,11 +173,50 @@ static void mainWindow_list_add_entry(struct mainWindow *mainWindow,
|
|||||||
g_free(date_text);
|
g_free(date_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_list_entry_visible checks whether the entry should be displayed.
|
||||||
|
* @param model N/A
|
||||||
|
* @param iter N/A
|
||||||
|
* @param mainWindow struct mainWindow *
|
||||||
|
* @return True when it should displayed, else false.
|
||||||
|
*/
|
||||||
static gboolean mainWindow_list_entry_visible(GtkTreeModel *model, GtkTreeIter *iter, struct mainWindow *mainWindow)
|
static gboolean mainWindow_list_entry_visible(GtkTreeModel *model, GtkTreeIter *iter, struct mainWindow *mainWindow)
|
||||||
{
|
{
|
||||||
|
GRegex *regex;
|
||||||
|
GMatchInfo *match_info;
|
||||||
|
gchar *searchString;
|
||||||
|
gchar *temp;
|
||||||
|
|
||||||
|
gboolean search_matched = 0;
|
||||||
|
|
||||||
GDateTime *datetime;
|
GDateTime *datetime;
|
||||||
guint time;
|
guint time;
|
||||||
|
|
||||||
|
/* Check text search */
|
||||||
|
searchString = (gchar *)gtk_entry_get_text(GTK_ENTRY(mainWindow->searchEntry));
|
||||||
|
if (searchString[0] != 0) {
|
||||||
|
regex = g_regex_new(searchString, G_REGEX_CASELESS, 0, NULL);
|
||||||
|
|
||||||
|
gtk_tree_model_get(model, iter, COL_TEXT, &temp, -1);
|
||||||
|
if (g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
|
||||||
|
search_matched = 1;
|
||||||
|
g_free(temp);
|
||||||
|
|
||||||
|
gtk_tree_model_get(model, iter, COL_TAGS_TEXT, &temp, -1);
|
||||||
|
if (g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
|
||||||
|
search_matched = 1;
|
||||||
|
g_free(temp);
|
||||||
|
|
||||||
|
gtk_tree_model_get(model, iter, COL_TITLE, &temp, -1);
|
||||||
|
if (g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
|
||||||
|
search_matched = 1;
|
||||||
|
g_free(temp);
|
||||||
|
|
||||||
|
if (!search_matched)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check time span */
|
||||||
gtk_tree_model_get(model, iter, COL_TIMESTAMP, &datetime, -1);
|
gtk_tree_model_get(model, iter, COL_TIMESTAMP, &datetime, -1);
|
||||||
if (datetime) {
|
if (datetime) {
|
||||||
time = g_date_time_to_unix(datetime);
|
time = g_date_time_to_unix(datetime);
|
||||||
@ -178,6 +226,14 @@ static gboolean mainWindow_list_entry_visible(GtkTreeModel *model, GtkTreeIter *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_sort_date_compare_func Compares the two GDateTimes from the main store.
|
||||||
|
* @param model N/A
|
||||||
|
* @param a N/A
|
||||||
|
* @param b N/A
|
||||||
|
* @param userdata N/A
|
||||||
|
* @return N/A
|
||||||
|
*/
|
||||||
static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
|
static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
|
||||||
GtkTreeIter *a,
|
GtkTreeIter *a,
|
||||||
GtkTreeIter *b,
|
GtkTreeIter *b,
|
||||||
@ -201,7 +257,10 @@ static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_configure_treeView configures GtkTreeView
|
||||||
|
* @param mainWindow struct mainWindow *
|
||||||
|
*/
|
||||||
static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
||||||
{
|
{
|
||||||
GtkCellRenderer *renderer;
|
GtkCellRenderer *renderer;
|
||||||
@ -261,7 +320,6 @@ static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
|||||||
/*
|
/*
|
||||||
* Test entries for debugging only
|
* Test entries for debugging only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GDateTime *dt;
|
GDateTime *dt;
|
||||||
GList *list = NULL;
|
GList *list = NULL;
|
||||||
|
|
||||||
@ -282,6 +340,10 @@ static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
|||||||
g_date_time_unref(dt);
|
g_date_time_unref(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_connect_signals connects are g signals
|
||||||
|
* @param mainWindow struct mainWindow *
|
||||||
|
*/
|
||||||
static void mainWindow_connect_signals(struct mainWindow *mainWindow)
|
static void mainWindow_connect_signals(struct mainWindow *mainWindow)
|
||||||
{
|
{
|
||||||
g_signal_connect(mainWindow->dateStart,
|
g_signal_connect(mainWindow->dateStart,
|
||||||
@ -308,11 +370,11 @@ static void mainWindow_connect_signals(struct mainWindow *mainWindow)
|
|||||||
|
|
||||||
g_signal_connect(mainWindow->dateStart,
|
g_signal_connect(mainWindow->dateStart,
|
||||||
"changed",
|
"changed",
|
||||||
(GCallback) mainWindow_dateChanged,
|
(GCallback) mainWindow_filterChanged,
|
||||||
mainWindow);
|
mainWindow);
|
||||||
g_signal_connect(mainWindow->dateEnd,
|
g_signal_connect(mainWindow->dateEnd,
|
||||||
"changed",
|
"changed",
|
||||||
(GCallback) mainWindow_dateChanged,
|
(GCallback) mainWindow_filterChanged,
|
||||||
mainWindow);
|
mainWindow);
|
||||||
|
|
||||||
g_signal_connect(mainWindow->dateStart,
|
g_signal_connect(mainWindow->dateStart,
|
||||||
@ -323,8 +385,17 @@ static void mainWindow_connect_signals(struct mainWindow *mainWindow)
|
|||||||
"focus-out-event",
|
"focus-out-event",
|
||||||
(GCallback) mainWindow_checkDate,
|
(GCallback) mainWindow_checkDate,
|
||||||
mainWindow);
|
mainWindow);
|
||||||
|
|
||||||
|
g_signal_connect(mainWindow->searchEntry,
|
||||||
|
"changed",
|
||||||
|
(GCallback) mainWindow_filterChanged,
|
||||||
|
mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_new creates a new mainWindow.
|
||||||
|
* @return Returns struct mainWindow *
|
||||||
|
*/
|
||||||
struct mainWindow *mainWindow_new()
|
struct mainWindow *mainWindow_new()
|
||||||
{
|
{
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
@ -364,18 +435,29 @@ struct mainWindow *mainWindow_new()
|
|||||||
return mainWindow;
|
return mainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_chooseWorkspaceClicked is called when the user clicks the Choose Workspace button.
|
||||||
|
* @param widget N/A
|
||||||
|
* @param event N/A
|
||||||
|
* @param user_data struct mainWindow *
|
||||||
|
*/
|
||||||
void mainWindow_chooseWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data)
|
void mainWindow_chooseWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data)
|
||||||
{
|
{
|
||||||
printf("Choose workspace.\n");
|
printf("Choose workspace.\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_showPopover is called from a dateEntry when it is focused.
|
||||||
|
* @param widget is the text entry.
|
||||||
|
* @param event N/A
|
||||||
|
* @param user_data struct mainWindow *
|
||||||
|
*/
|
||||||
void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data)
|
void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
||||||
GDateTime *datetime;
|
GDateTime *datetime;
|
||||||
|
|
||||||
|
|
||||||
mainWindow->selectedDateEntry = NULL;
|
mainWindow->selectedDateEntry = NULL;
|
||||||
|
|
||||||
datetime = g_date_time_new_from_unix_local((widget == mainWindow->dateStart
|
datetime = g_date_time_new_from_unix_local((widget == mainWindow->dateStart
|
||||||
@ -398,6 +480,11 @@ void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_da
|
|||||||
gtk_popover_set_relative_to(GTK_POPOVER(mainWindow->popoverDate), widget);
|
gtk_popover_set_relative_to(GTK_POPOVER(mainWindow->popoverDate), widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_calendarSelected is the callback when the user selects a date in the calendar.
|
||||||
|
* @param widget is the calendar.
|
||||||
|
* @param user_data struct mainWindow *
|
||||||
|
*/
|
||||||
void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data)
|
void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
||||||
@ -412,6 +499,11 @@ void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_entrySelected is the callback when the user selects a diary entry.
|
||||||
|
* @param widget N/A
|
||||||
|
* @param user_data struct mainWindow *
|
||||||
|
*/
|
||||||
void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data)
|
void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
||||||
@ -429,25 +521,42 @@ void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainWindow_dateChanged(GtkWidget *widget, gpointer user_data)
|
/**
|
||||||
|
* @brief mainWindow_filterChanged updates the filter backend values
|
||||||
|
* @param widget The widget that caused the update request. Can be NULL to update all.
|
||||||
|
* @param user_data struct mainWindow *
|
||||||
|
*/
|
||||||
|
void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data)
|
||||||
{
|
{
|
||||||
GDateTime *datetime;
|
GDateTime *datetime;
|
||||||
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
||||||
|
|
||||||
datetime = mainWindow_get_date_from_string((gchar *)gtk_entry_get_text(GTK_ENTRY(mainWindow->dateStart)));
|
if (!widget || widget == mainWindow->dateStart) {
|
||||||
if (datetime) {
|
datetime = mainWindow_get_date_from_string((gchar *)gtk_entry_get_text(
|
||||||
mainWindow->filterSettings.time_start = g_date_time_to_unix(datetime);
|
GTK_ENTRY(mainWindow->dateStart)));
|
||||||
g_date_time_unref(datetime);
|
if (datetime) {
|
||||||
|
mainWindow->filterSettings.time_start = g_date_time_to_unix(datetime);
|
||||||
|
g_date_time_unref(datetime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
datetime = mainWindow_get_date_from_string((gchar *)gtk_entry_get_text(GTK_ENTRY(mainWindow->dateEnd)));
|
if (!widget || widget == mainWindow->dateEnd) {
|
||||||
if (datetime) {
|
datetime = mainWindow_get_date_from_string((gchar *)gtk_entry_get_text(
|
||||||
mainWindow->filterSettings.time_end = g_date_time_to_unix(datetime);
|
GTK_ENTRY(mainWindow->dateEnd)));
|
||||||
g_date_time_unref(datetime);
|
if (datetime) {
|
||||||
|
mainWindow->filterSettings.time_end = g_date_time_to_unix(datetime);
|
||||||
|
g_date_time_unref(datetime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_tree_model_filter_refilter(mainWindow->entryListFiltered);
|
gtk_tree_model_filter_refilter(mainWindow->entryListFiltered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mainWindow_checkDate checks the date in a text box and resets it if necessary.
|
||||||
|
* @param widget is the GtkEntry to be checked.
|
||||||
|
* @param event N/A
|
||||||
|
* @param user_data struct mainWindow *
|
||||||
|
*/
|
||||||
void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data)
|
void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
||||||
|
@ -34,7 +34,7 @@ void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_da
|
|||||||
void mainWindow_chooseWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data);
|
void mainWindow_chooseWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data);
|
||||||
void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data);
|
void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data);
|
||||||
void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data);
|
void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data);
|
||||||
void mainWindow_dateChanged(GtkWidget *widget, gpointer user_data);
|
void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data);
|
||||||
void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data);
|
void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data);
|
||||||
|
|
||||||
#endif /* MAINWINDOW_H */
|
#endif /* MAINWINDOW_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user