Compare commits

..

No commits in common. "1101026d193991dd83e9121e94124841e895a75c" and "7f296855d513169cfa4ccf2dd7803a9f9c1ab285" have entirely different histories.

2 changed files with 19 additions and 128 deletions

View File

@ -11,9 +11,7 @@ enum {
COL_COUNT
};
/**
* @brief The dateFormats struct contains regex/date-info pairs to parse different date formats.
*/
struct dateFormats {
gchar *regex;
guint index_count;
@ -61,7 +59,7 @@ struct dateFormats {
};
/**
* @brief mainWindow_get_date_from_string tries to guess the date format used and converts it to GDateTime.
* @brief Tries to guess the date format used and converts it to GDateTime.
* @param Input string.
* @return A GDateTime object or NULL on error. You need to free it after use.
*/
@ -115,9 +113,7 @@ static GDateTime *mainWindow_get_date_from_string(gchar *string)
}
/**
* @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().
* Returns: The string, needs to be freed using g_free().
*/
static gchar *mainWindow_taglist_to_string(GList *list)
{
@ -140,12 +136,7 @@ static gchar *mainWindow_taglist_to_string(GList *list)
}
/**
* @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
* Note: This function creates a copyof each argument.
*/
static void mainWindow_list_add_entry(struct mainWindow *mainWindow,
gchar *title,
@ -173,50 +164,11 @@ static void mainWindow_list_add_entry(struct mainWindow *mainWindow,
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)
{
GRegex *regex;
GMatchInfo *match_info;
gchar *searchString;
gchar *temp;
gboolean search_matched = 0;
GDateTime *datetime;
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);
if (datetime) {
time = g_date_time_to_unix(datetime);
@ -226,14 +178,6 @@ 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,
GtkTreeIter *a,
GtkTreeIter *b,
@ -257,10 +201,7 @@ static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
return -1;
}
/**
* @brief mainWindow_configure_treeView configures GtkTreeView
* @param mainWindow struct mainWindow *
*/
static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
{
GtkCellRenderer *renderer;
@ -320,6 +261,7 @@ static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
/*
* Test entries for debugging only
*/
GDateTime *dt;
GList *list = NULL;
@ -340,10 +282,6 @@ static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
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)
{
g_signal_connect(mainWindow->dateStart,
@ -370,11 +308,11 @@ static void mainWindow_connect_signals(struct mainWindow *mainWindow)
g_signal_connect(mainWindow->dateStart,
"changed",
(GCallback) mainWindow_filterChanged,
(GCallback) mainWindow_dateChanged,
mainWindow);
g_signal_connect(mainWindow->dateEnd,
"changed",
(GCallback) mainWindow_filterChanged,
(GCallback) mainWindow_dateChanged,
mainWindow);
g_signal_connect(mainWindow->dateStart,
@ -385,17 +323,8 @@ static void mainWindow_connect_signals(struct mainWindow *mainWindow)
"focus-out-event",
(GCallback) mainWindow_checkDate,
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()
{
GtkBuilder *builder;
@ -435,29 +364,18 @@ struct mainWindow *mainWindow_new()
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)
{
printf("Choose workspace.\n");
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)
{
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
GDateTime *datetime;
mainWindow->selectedDateEntry = NULL;
datetime = g_date_time_new_from_unix_local((widget == mainWindow->dateStart
@ -480,11 +398,6 @@ void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_da
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)
{
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
@ -499,11 +412,6 @@ 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)
{
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
@ -521,42 +429,25 @@ void mainWindow_entrySelected(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)
void mainWindow_dateChanged(GtkWidget *widget, gpointer user_data)
{
GDateTime *datetime;
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
if (!widget || widget == mainWindow->dateStart) {
datetime = mainWindow_get_date_from_string((gchar *)gtk_entry_get_text(
GTK_ENTRY(mainWindow->dateStart)));
datetime = mainWindow_get_date_from_string((gchar *)gtk_entry_get_text(GTK_ENTRY(mainWindow->dateStart)));
if (datetime) {
mainWindow->filterSettings.time_start = g_date_time_to_unix(datetime);
g_date_time_unref(datetime);
}
}
if (!widget || widget == mainWindow->dateEnd) {
datetime = mainWindow_get_date_from_string((gchar *)gtk_entry_get_text(
GTK_ENTRY(mainWindow->dateEnd)));
datetime = mainWindow_get_date_from_string((gchar *)gtk_entry_get_text(GTK_ENTRY(mainWindow->dateEnd)));
if (datetime) {
mainWindow->filterSettings.time_end = g_date_time_to_unix(datetime);
g_date_time_unref(datetime);
}
}
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)
{
struct mainWindow *mainWindow = (struct mainWindow *)user_data;

View File

@ -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_calendarSelected(GtkWidget *widget, gpointer user_data);
void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data);
void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data);
void mainWindow_dateChanged(GtkWidget *widget, gpointer user_data);
void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data);
#endif /* MAINWINDOW_H */