Compare commits

...

2 Commits

Author SHA1 Message Date
0a5ba481bc Some cleanups 2017-02-03 19:40:05 +01:00
ecf84fcd67 Added code to automatically fix date entries 2017-02-03 19:37:31 +01:00
2 changed files with 30 additions and 6 deletions

View File

@ -99,7 +99,6 @@ static GDateTime *mainWindow_get_date_from_string(gchar *string)
hour >= 0 && hour <= 23 &&
minute >= 0 && minute <= 59) {
datetime = g_date_time_new_local(year, month, day, hour, minute, 0);
g_regex_unref(regex);
break;
}
@ -311,11 +310,19 @@ static void mainWindow_connect_signals(struct mainWindow *mainWindow)
"changed",
(GCallback) mainWindow_dateChanged,
mainWindow);
g_signal_connect(mainWindow->dateEnd,
"changed",
(GCallback) mainWindow_dateChanged,
mainWindow);
g_signal_connect(mainWindow->dateStart,
"focus-out-event",
(GCallback) mainWindow_checkDate,
mainWindow);
g_signal_connect(mainWindow->dateEnd,
"focus-out-event",
(GCallback) mainWindow_checkDate,
mainWindow);
}
struct mainWindow *mainWindow_new()
@ -350,8 +357,8 @@ struct mainWindow *mainWindow_new()
/**
* These need to be set to oldest and newest after indexing date
*/
gtk_entry_set_text(mainWindow->dateStart, "2016-01-01");
gtk_entry_set_text(mainWindow->dateEnd, "2017-01-01");
gtk_entry_set_text(GTK_ENTRY(mainWindow->dateStart), "2016-01-01");
gtk_entry_set_text(GTK_ENTRY(mainWindow->dateEnd), "2017-01-01");
return mainWindow;
}
@ -426,12 +433,12 @@ void mainWindow_dateChanged(GtkWidget *widget, gpointer user_data)
GDateTime *datetime;
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
datetime = mainWindow_get_date_from_string(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);
}
datetime = mainWindow_get_date_from_string(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);
@ -439,3 +446,19 @@ void mainWindow_dateChanged(GtkWidget *widget, gpointer user_data)
gtk_tree_model_filter_refilter(mainWindow->entryListFiltered);
}
void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data)
{
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
GDateTime *datetime;
datetime = mainWindow_get_date_from_string((char *)gtk_entry_get_text(GTK_ENTRY(widget)));
if (!datetime) {
datetime = g_date_time_new_from_unix_local(widget == mainWindow->dateStart
? mainWindow->filterSettings.time_start
: mainWindow->filterSettings.time_end);
gtk_entry_set_text(GTK_ENTRY(widget),
g_date_time_format(datetime, "%Y-%m-%d"));
}
g_date_time_unref(datetime);
}

View File

@ -34,5 +34,6 @@ void mainWindow_chooseWorkspaceClicked(GtkWidget *widget, gint event, gpointer u
void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data);
void mainWindow_entrySelected(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 */