From 1708211d4212c015e0c6ebb8b7b2abf06c7442d6 Mon Sep 17 00:00:00 2001 From: Ivan Dmitrievich Yartsev Date: Thu, 27 Nov 2025 14:20:33 +0600 Subject: [PATCH] Configuration window update --- source/ubl-settings-datetime.c | 27 ++++++++++++++++++++++++--- source/ubl-settings-datetime.h | 16 +++++++++------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/source/ubl-settings-datetime.c b/source/ubl-settings-datetime.c index 1be8f8f..77c0e47 100644 --- a/source/ubl-settings-datetime.c +++ b/source/ubl-settings-datetime.c @@ -272,7 +272,8 @@ void yon_interface_update(main_window *widgets){ GDateTime *datetime = g_date_time_new_now_local(); char *time = g_date_time_format(datetime,"%H %M"); - char *date = g_date_time_format(datetime,yon_settings_configuration_get(date_format_parameter)); + char *format = yon_settings_configuration_get(date_format_parameter); + char *date = g_date_time_format(datetime,format?format:"%d.%m.%Y"); gtk_calendar_select_month(GTK_CALENDAR(widgets->DateCalendar),g_date_time_get_month(datetime)-1,g_date_time_get_year(datetime)); gtk_calendar_select_day(GTK_CALENDAR(widgets->DateCalendar),g_date_time_get_day_of_month(datetime)); @@ -352,6 +353,7 @@ gboolean on_sync_error(void*){ void yon_date_tooltip_update(main_window *widgets){ char *format = yon_settings_configuration_get(date_format_parameter); + format = format?format:"%d.%m.%Y"; char *temp = yon_char_replace(format,"%Y",YEAR_FORMAT_LABEL); char *month_temp = yon_char_replace(temp,"%m",MONTH_FORMAT_LABEL); char *day_temp = yon_char_replace(month_temp,"%d",DAY_FORMAT_LABEL); @@ -403,6 +405,7 @@ void on_sync_clicked(GtkWidget *, main_window *widgets){ if (!yon_char_is_empty(date)){ int size; char *format = yon_settings_configuration_get(date_format_parameter); + format = format?format:"%d.%m.%Y"; config_str parsed = yon_char_parse((char*)date,&size,!strcmp(format,"%d.%m.%Y")?".":!strcmp(format,"%d/%m/%Y")?"/":"-"); if (!strcmp(format,"%m-%d-%Y")){ char *year = parsed[2]; @@ -516,7 +519,8 @@ void on_date_accept(GtkWidget *,main_window *widgets){ guint year=0, month=0, day=0; gtk_calendar_get_date(GTK_CALENDAR(widgets->DateCalendar),&year,&month,&day); GDateTime *datetime = g_date_time_new_local(year,++month,day,0,0,0); - char *date = g_date_time_format(datetime,yon_settings_configuration_get(date_format_parameter)); + char *format = yon_settings_configuration_get(date_format_parameter); + char *date = g_date_time_format(datetime,format?format:"%d.%m.%Y"); gtk_entry_set_text(GTK_ENTRY(widgets->DateEntry),date); gtk_popover_popdown(GTK_POPOVER(widgets->DatePopover)); free(date); @@ -561,6 +565,17 @@ void config_init(){ } } +void yon_date_chooser_save_accept(GtkWidget *root){ + struct yon_date_chooser_option *parameter = g_object_get_data(G_OBJECT(root),"data_struct"); + char *path = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(parameter->DateCombo)); + if (!yon_char_is_empty(path)){ + yon_window_config_add_instant_parameter(date_format_parameter,yon_configuration_window_section,path,YON_TYPE_STRING); + } else { + yon_window_config_erase_instant_parameter(date_format_parameter,yon_configuration_window_section); + } + on_date_format_changed(NULL,main_config.widgets); +} + /**yon_main_window_complete(main_window *widgets) * [EN] * @@ -593,6 +608,7 @@ void yon_main_window_complete(main_window **window){ widgets->DateAcceptButton = yon_gtk_builder_get_widget(builder,"DateAcceptButton"); widgets->zone_list = GTK_LIST_STORE(gtk_builder_get_object(builder,"liststore1")); } + main_config.widgets=widgets; // Signal configuration { g_signal_connect(G_OBJECT(widgets->SaveMenuItem),"activate",G_CALLBACK(on_config_save),widgets); @@ -702,7 +718,12 @@ void yon_main_window_complete(main_window **window){ } } g_list_free(menu_items); - yon_configuration_window_add_combo_box_parameter(CONFIGURATION_PARAMETER_BOOL,date_format_parameter,DATE_FORMAT_SETTINGS_LABEL,G_CALLBACK(on_date_format_changed),widgets,"%d.%m.%Y",DMY_FORMAT_LABEL,"%d-%m-%Y",DMY_MINUS_FORMAT_LABEL,"%d/%m/%Y",DMY_SLASH_FORMAT_LABEL,"%m-%d-%Y",MDY_FORMAT_LABEL,NULL); + struct yon_configuration_window_custom_parameter *parameter = malloc(sizeof(struct yon_configuration_window_custom_parameter)); + parameter->custom_parameter_create_func = yon_date_chooser_new; + parameter->custom_parameter_save_value_func = yon_date_chooser_save_accept; + parameter->custom_parameter_update_func = yon_date_chooser_update; + yon_configuration_window_add_custom_parameter(date_format_parameter,parameter); + // yon_configuration_window_add_combo_box_parameter(CONFIGURATION_PARAMETER_BOOL,date_format_parameter,DATE_FORMAT_SETTINGS_LABEL,G_CALLBACK(on_date_format_changed),widgets,"%d.%m.%Y",DMY_FORMAT_LABEL,"%d-%m-%Y",DMY_MINUS_FORMAT_LABEL,"%d/%m/%Y",DMY_SLASH_FORMAT_LABEL,"%m-%d-%Y",MDY_FORMAT_LABEL,NULL); yon_load_proceed(YON_CONFIG_LOCAL); yon_interface_update(widgets); diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index 593e1ed..0a9e0a2 100644 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -62,12 +62,6 @@ string version_application; char *local; -typedef struct { - template_config_fields - - int save_config; - char *ntp_default; -} config; typedef struct { template_window_fields @@ -91,6 +85,13 @@ typedef struct { GtkWidget *DateCancelButton; } main_window; +typedef struct { + template_config_fields + + int save_config; + char *ntp_default; + main_window *widgets; +} config; typedef struct { GtkWidget *Window; @@ -157,4 +158,5 @@ void on_save_done(main_window *widgets, config_str output, int size); void on_date_format_changed(GtkWidget *, main_window *widgets); void yon_date_tooltip_update(main_window *widgets); -gboolean on_operation_success(void*); \ No newline at end of file +gboolean on_operation_success(void*); +void yon_date_chooser_save_accept(GtkWidget *root); \ No newline at end of file