Added time span detection

This commit is contained in:
Markus Koch 2017-02-04 19:55:08 +01:00
parent 57623e464e
commit c628684c5b
5 changed files with 66 additions and 6 deletions

View File

@ -14,6 +14,7 @@ int main(int argc, char *argv[])
gtk_widget_show(mainWindow->mainWindow); gtk_widget_show(mainWindow->mainWindow);
mdiary_scan_to_store(argv[1], mainWindow->entryListStore); mdiary_scan_to_store(argv[1], mainWindow->entryListStore);
mainWindow_set_meta_information(mainWindow, mdiary_get_time_earliest(), mdiary_get_time_latest());
gtk_main(); gtk_main();

View File

@ -280,6 +280,8 @@ struct mainWindow *mainWindow_new()
mainWindow->filterSettings.time_start = 0; mainWindow->filterSettings.time_start = 0;
mainWindow->filterSettings.time_end = -1; mainWindow->filterSettings.time_end = -1;
mainWindow->time_earliest = 0;
mainWindow->time_latest = 0;
gtk_builder_connect_signals(builder, NULL); gtk_builder_connect_signals(builder, NULL);
@ -295,6 +297,20 @@ struct mainWindow *mainWindow_new()
return mainWindow; return mainWindow;
} }
/**
* @brief mainWindow_set_meta_information sets some meta info for a nice GUI. It also resets the search.
* @param mainWindow
* @param time_earliest is the reset value for the filter start date
* @param time_latest is the reset value for the filter end date
*/
void mainWindow_set_meta_information(struct mainWindow *mainWindow, guint time_earliest, guint time_latest)
{
mainWindow->time_earliest = time_earliest;
mainWindow->time_latest = time_latest;
mainWindow_clearSearch(NULL, mainWindow);
}
/** /**
* @brief mainWindow_chooseWorkspaceClicked is called when the user clicks the Choose Workspace button. * @brief mainWindow_chooseWorkspaceClicked is called when the user clicks the Choose Workspace button.
* @param widget N/A * @param widget N/A
@ -464,12 +480,20 @@ void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data)
void mainWindow_clearSearch(GtkWidget *widget, gpointer user_data) void mainWindow_clearSearch(GtkWidget *widget, gpointer user_data)
{ {
struct mainWindow *mainWindow = (struct mainWindow *)user_data; struct mainWindow *mainWindow = (struct mainWindow *)user_data;
GDateTime *datetime;
gchar *temp;
gtk_entry_set_text(GTK_ENTRY(mainWindow->searchEntry), ""); gtk_entry_set_text(GTK_ENTRY(mainWindow->searchEntry), "");
/** datetime = g_date_time_new_from_unix_local(mainWindow->time_earliest);
* These need to be set to oldest and newest after indexing date temp = g_date_time_format(datetime, "%Y-%m-%d");
*/ gtk_entry_set_text(GTK_ENTRY(mainWindow->dateStart), temp);
gtk_entry_set_text(GTK_ENTRY(mainWindow->dateStart), "2016-01-01"); g_date_time_unref(datetime);
gtk_entry_set_text(GTK_ENTRY(mainWindow->dateEnd), "2018-01-01"); g_free(temp);
datetime = g_date_time_new_from_unix_local(mainWindow->time_latest);
temp = g_date_time_format(datetime, "%Y-%m-%d");
gtk_entry_set_text(GTK_ENTRY(mainWindow->dateEnd), temp);
g_date_time_unref(datetime);
g_free(temp);
} }

View File

@ -28,6 +28,9 @@ struct mainWindow {
GtkWidget *selectedDateEntry; GtkWidget *selectedDateEntry;
GtkTreeModelFilter *entryListFiltered; GtkTreeModelFilter *entryListFiltered;
guint time_earliest;
guint time_latest;
struct filterSettings { struct filterSettings {
guint time_start; guint time_start;
guint time_end; guint time_end;
@ -39,6 +42,7 @@ struct mainWindow {
}; };
struct mainWindow *mainWindow_new(); struct mainWindow *mainWindow_new();
void mainWindow_set_meta_information(struct mainWindow *mainWindow, guint time_earliest, guint time_latest);
/* Slots */ /* Slots */
void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data); void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data);

View File

@ -1,5 +1,8 @@
#include "mdiary.h" #include "mdiary.h"
static gint64 time_earliest;
static gint64 time_latest;
/** /**
* @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.
*/ */
@ -154,7 +157,7 @@ static gboolean mdiary_is_empty_line(gchar *string)
{ {
GRegex *regex; GRegex *regex;
GMatchInfo *match_info; GMatchInfo *match_info;
gchar *ret = 0; gboolean ret = 0;
regex = g_regex_new("^\\s*$", G_REGEX_RAW, 0, NULL); regex = g_regex_new("^\\s*$", G_REGEX_RAW, 0, NULL);
if (g_regex_match(regex, string, 0, &match_info) && if (g_regex_match(regex, string, 0, &match_info) &&
@ -302,6 +305,11 @@ static void mdiary_add_file_to_store(gchar *filename, GtkListStore *entryListSto
summary, summary,
text->str); text->str);
if (g_date_time_to_unix(datetime) > time_latest)
time_latest = g_date_time_to_unix(datetime);
if (g_date_time_to_unix(datetime) < time_earliest)
time_earliest = g_date_time_to_unix(datetime);
g_input_stream_close(G_INPUT_STREAM(dstream), NULL, NULL); g_input_stream_close(G_INPUT_STREAM(dstream), NULL, NULL);
g_input_stream_close(G_INPUT_STREAM(stream), NULL, NULL); g_input_stream_close(G_INPUT_STREAM(stream), NULL, NULL);
g_string_free(text, 0); g_string_free(text, 0);
@ -347,9 +355,30 @@ static void mdiary_recurse_and_collect(gchar *base_dir, GtkListStore *entryListS
*/ */
void mdiary_scan_to_store(gchar *base_dir, GtkListStore *entryListStore) void mdiary_scan_to_store(gchar *base_dir, GtkListStore *entryListStore)
{ {
time_earliest = G_MAXINT64;
time_latest = 0;
mdiary_recurse_and_collect(base_dir, entryListStore, 5); mdiary_recurse_and_collect(base_dir, entryListStore, 5);
} }
/**
* @brief mdiary_get_time_earliest getter function for time_earliest. Call mdiary_scan_to_store before using.
* @return time_earliest
*/
guint mdiary_get_time_earliest(void)
{
return time_earliest;
}
/**
* @brief mdiary_get_time_earliest getter function for time_latest. Call mdiary_scan_to_store before using.
* @return time_latest
*/
guint mdiary_get_time_latest(void)
{
return time_latest;
}
/** /**
* @brief mainWindow_taglist_to_string concatenates a list with commas * @brief mainWindow_taglist_to_string concatenates a list with commas
* @param list is a GList of strings to concatenate * @param list is a GList of strings to concatenate

View File

@ -26,5 +26,7 @@ void mdiary_add_entry_to_store(GtkListStore *entryListStore,
gchar *text); gchar *text);
GDateTime *mdiary_get_date_from_string_ext(gchar *string, gchar *prefix, gchar *suffix); GDateTime *mdiary_get_date_from_string_ext(gchar *string, gchar *prefix, gchar *suffix);
GDateTime *mdiary_get_date_from_string(gchar *string); GDateTime *mdiary_get_date_from_string(gchar *string);
guint mdiary_get_time_earliest(void);
guint mdiary_get_time_latest(void);
#endif /* MDIARY_H */ #endif /* MDIARY_H */