Calendar now checks invalid date; Calendar initialy show current date

pull/133/head
parent a745d15d24
commit 657276e0ec

@ -1775,10 +1775,23 @@ void on_toggle_button_set_active_from_toggle_button_inversed(GtkToggleButton *se
void on_date_selected(GtkWidget *self, ubl_settings_usergroups_user_window *window){
int year=0, month=0, day=0;
gtk_calendar_get_date(GTK_CALENDAR(window->ExpirationCalendar),&year,&month,&day);
GDateTime *date = g_date_time_new_local(year,month,day,23,59,59);
char *date_string = g_date_time_format(date,"%Y-%m-%d");
time_t t = time(NULL);
struct tm tm = *localtime(&t);
if ((1900+tm.tm_year)>year||((1900+tm.tm_year)==year&&tm.tm_mon>month)||((1900+tm.tm_year)==year&&tm.tm_mon==month&&tm.tm_mday>day)) {
gtk_entry_set_text(GTK_ENTRY(window->userPasswordExpirationEntry), "");
return;
}
char *dy = yon_char_from_int(day);
char *mn = yon_char_from_int(month);
char *yr = yon_char_from_int(year);
if (tm.tm_mon<10) yon_char_append("0",mn);
if (tm.tm_mday<10) yon_char_append("0",dy);
char *date_string = yon_char_unite(yr,"-",mn,"-",dy);
gtk_entry_set_text(GTK_ENTRY(window->userPasswordExpirationEntry), date_string);
window->expiration_unix=date_string;
free(dy);
free(mn);
free(yr);
}
void on_parameter_changed(GtkWidget *self,ubl_settings_usergroups_user_window *window){
@ -1905,6 +1918,12 @@ ubl_settings_usergroups_user_window *yon_ubl_settings_usergroups_user_new(){
window->userTitleNameLabel=yon_gtk_builder_get_widget(builder,"userTitleNameLabel");
window->expiration_unix=NULL;
time_t t = time(NULL);
struct tm tm = *localtime(&t);
gtk_calendar_select_day(GTK_CALENDAR(window->ExpirationCalendar),tm.tm_mday);
gtk_calendar_select_month(GTK_CALENDAR(window->ExpirationCalendar),tm.tm_mon,1900+tm.tm_year);
on_UID_update(NULL,window);
int shell_size=0;
config_str shells = yon_file_open(shell_list_path,&shell_size);

Loading…
Cancel
Save