Merge pull request 'Fixes' (#150) from YanTheKaller/ubl-settings-datetime:master into master

Reviewed-on: #150
pull/189/head v2.13
Dmitry Razumov 2 years ago
commit 5ffd8042b4

@ -53,7 +53,7 @@ void yon_save_parameters(main_window *widgets){
const char *zone = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widgets->ZoneCombo)); const char *zone = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widgets->ZoneCombo));
if (!yon_char_is_empty(region)&&!yon_char_is_empty(zone)){ if (!yon_char_is_empty(region)&&!yon_char_is_empty(zone)){
char *zone_parameter = yon_char_unite(region,"/",zone,NULL); char *zone_parameter = yon_char_unite((char*)region,"/",(char*)zone,NULL);
yon_config_register(ZONE_parameter,ZONE_parameter_command,zone_parameter); yon_config_register(ZONE_parameter,ZONE_parameter_command,zone_parameter);
free(zone_parameter); free(zone_parameter);
} }
@ -67,40 +67,52 @@ void yon_save_parameters(main_window *widgets){
} }
void on_config_save(GtkWidget *, main_window *widgets){ void on_config_save(GtkWidget *, main_window *widgets){
main_config.load_mode=3; main_config.save_config=2;
yon_save_parameters(widgets); yon_save_parameters(widgets);
yon_save_proceed(NULL,YON_CONFIG_BOTH,config_get_global_command,NULL); yon_save_proceed(NULL,YON_CONFIG_BOTH,config_get_global_command,NULL);
} }
void on_config_save_global(GtkWidget *, main_window *widgets){ void on_config_save_global(GtkWidget *, main_window *widgets){
main_config.load_mode=0; main_config.save_config=0;
yon_save_parameters(widgets); yon_save_parameters(widgets);
yon_save_proceed(NULL,YON_CONFIG_BOTH,config_get_global_command,NULL); yon_save_proceed(NULL,YON_CONFIG_GLOBAL,config_get_global_command,NULL);
} }
void on_config_save_local(GtkWidget *, main_window *widgets){ void on_config_save_local(GtkWidget *, main_window *widgets){
main_config.load_mode=1; main_config.save_config=1;
yon_save_parameters(widgets); yon_save_parameters(widgets);
yon_save_proceed(NULL,YON_CONFIG_BOTH,config_get_global_command,NULL); yon_save_proceed(NULL,YON_CONFIG_LOCAL,config_get_global_command,NULL);
} }
void on_config_save_custom(GtkWidget *, main_window *widgets){ void on_config_save_custom(GtkWidget *, main_window *widgets){
main_config.load_mode=3; main_config.save_config=3;
yon_save_parameters(widgets); yon_save_parameters(widgets);
yon_save_proceed(NULL,YON_CONFIG_BOTH,config_get_global_command,NULL); yon_save_proceed(NULL,YON_CONFIG_CUSTOM,config_get_global_command,NULL);
} }
void on_config_load_global(){ void on_config_load_global(){
main_config.load_mode=1;
textdomain(template_ui_LocaleName);
yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
textdomain(LocaleName);
yon_load_proceed(YON_CONFIG_GLOBAL); yon_load_proceed(YON_CONFIG_GLOBAL);
} }
void on_config_load_local(){ void on_config_load_local(){
main_config.load_mode=0;
textdomain(template_ui_LocaleName);
yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
textdomain(LocaleName);
yon_load_proceed(YON_CONFIG_LOCAL); yon_load_proceed(YON_CONFIG_LOCAL);
} }
void on_config_load_custom(){ void on_config_load_custom(){
main_config.load_mode=2;
textdomain(template_ui_LocaleName);
yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
textdomain(LocaleName);
yon_load_proceed(YON_CONFIG_CUSTOM); yon_load_proceed(YON_CONFIG_CUSTOM);
} }
@ -139,6 +151,31 @@ void yon_load_proceed(YON_CONFIG_TYPE type){
} }
} }
void on_save_done(main_window *widgets, config_str output, int size){
char *final_output = yon_char_parsed_to_string(output,size,"");
if (final_output){
printf("%s\n",final_output);
free(final_output);
}
yon_char_parsed_free(output,size);
yon_interface_update(widgets);
textdomain(template_ui_LocaleName);
switch (main_config.save_config){
case 0:
yon_ubl_status_box_render(GLOBAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
break;
case 1:
yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
break;
case 2:
case 3:
yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
break;
}
textdomain(LocaleName);
}
void yon_interface_update(main_window *widgets){ void yon_interface_update(main_window *widgets){
char *ntp = config(NTPSERVERS_parameter); char *ntp = config(NTPSERVERS_parameter);
char *zone = config(ZONE_parameter); char *zone = config(ZONE_parameter);
@ -180,7 +217,7 @@ void yon_interface_update(main_window *widgets){
GDateTime *datetime = g_date_time_new_now_local(); GDateTime *datetime = g_date_time_new_now_local();
char *time = g_date_time_format(datetime,"%H %M"); char *time = g_date_time_format(datetime,"%H %M");
char *date = g_date_time_format(datetime,"%Y:%m:%d"); char *date = g_date_time_format(datetime,"%Y.%m.%d");
gtk_calendar_select_month(GTK_CALENDAR(widgets->DateCalendar),g_date_time_get_month(datetime),g_date_time_get_year(datetime)); gtk_calendar_select_month(GTK_CALENDAR(widgets->DateCalendar),g_date_time_get_month(datetime),g_date_time_get_year(datetime));
gtk_calendar_select_day(GTK_CALENDAR(widgets->DateCalendar),g_date_time_get_day_of_month(datetime)); gtk_calendar_select_day(GTK_CALENDAR(widgets->DateCalendar),g_date_time_get_day_of_month(datetime));
@ -241,7 +278,7 @@ void *yon_sync_thread_start(void *arg){
struct datetime_arg *data = (struct datetime_arg*)arg; struct datetime_arg *data = (struct datetime_arg*)arg;
char *command_time = time_sync_command(data->time); char *command_time = time_sync_command(data->time);
char *command_date = date_sync_command(data->date); char *command_date = date_sync_command(data->date);
char *command = yon_char_unite(command_time,"; ",command_date,NULL); char *command = yon_char_unite(command_date,"; ",command_time,NULL);
free(command_time); free(command_time);
free(command_date); free(command_date);
if (system(yon_debug_output("%s\n",command))){ if (system(yon_debug_output("%s\n",command))){
@ -264,7 +301,7 @@ void on_sync_clicked(GtkWidget *, main_window *widgets){
data->time=time; data->time=time;
if (!yon_char_is_empty(date)){ if (!yon_char_is_empty(date)){
int size; int size;
config_str parsed = yon_char_parse((char*)date,&size,":"); config_str parsed = yon_char_parse((char*)date,&size,".");
data->date=yon_char_parsed_to_string(parsed,size,""); data->date=yon_char_parsed_to_string(parsed,size,"");
yon_char_parsed_free(parsed,size); yon_char_parsed_free(parsed,size);
} }
@ -325,7 +362,7 @@ void on_date_accept(GtkWidget *,main_window *widgets){
char *ye_str = yon_char_from_int(year); char *ye_str = yon_char_from_int(year);
char *mo_str = yon_char_from_int(++month); char *mo_str = yon_char_from_int(++month);
char *da_str = yon_char_from_int(day); char *da_str = yon_char_from_int(day);
char *date = yon_char_unite(ye_str,":",month<10?"0":"",mo_str,":",day<10?"0":"",da_str,NULL); char *date = yon_char_unite(ye_str,".",month<10?"0":"",mo_str,".",day<10?"0":"",da_str,NULL);
gtk_entry_set_text(GTK_ENTRY(widgets->DateEntry),date); gtk_entry_set_text(GTK_ENTRY(widgets->DateEntry),date);
gtk_popover_popdown(GTK_POPOVER(widgets->DatePopover)); gtk_popover_popdown(GTK_POPOVER(widgets->DatePopover));
free(date); free(date);
@ -436,6 +473,7 @@ void yon_main_window_complete(main_window *widgets){
yon_load_proceed(YON_CONFIG_LOCAL); yon_load_proceed(YON_CONFIG_LOCAL);
yon_interface_update(widgets); yon_interface_update(widgets);
yon_save_window_set_postsave_function(on_save_done,widgets);
} }
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){

@ -44,8 +44,8 @@
#define ZONE_parameter "ZONE" #define ZONE_parameter "ZONE"
#define ZONE_parameter_command "ubconfig --source global get clock ZONE" #define ZONE_parameter_command "ubconfig --source global get clock ZONE"
#define time_sync_command(time) yon_char_unite("date +%T -s \"",time,"\"",NULL) #define time_sync_command(time) yon_char_unite("pkexec date +%H:%M:%S -s \"",time,"\"",NULL)
#define date_sync_command(date) yon_char_unite("date +%Y%m%d -s \"",date,"\"",NULL) #define date_sync_command(date) yon_char_unite("pkexec date +%Y%m%d -s \"",date,"\"",NULL)
#define hardware_datetime_sync_command "hwclock --systohc" #define hardware_datetime_sync_command "hwclock --systohc"
@ -59,6 +59,7 @@ char *local;
typedef struct { typedef struct {
template_config_fields template_config_fields
int save_config;
char *ntp_default; char *ntp_default;
} config; } config;
@ -141,4 +142,5 @@ void on_date_cancel(GtkWidget *, main_window *widgets);
config_str yon_char_parsed_sort(config_str parsed, int size); config_str yon_char_parsed_sort(config_str parsed, int size);
int yon_char_parsed_compare(const void *a, const void *b); int yon_char_parsed_compare(const void *a, const void *b);
void on_save_done(main_window *widgets, config_str output, int size);

@ -20,58 +20,84 @@
border-color:alpha(@theme_text_color, 0.01); border-color:alpha(@theme_text_color, 0.01);
} }
.menuitemtop{ .menuitembottom{
margin-bottom:0px; margin-top:0px;
} margin-bottom:4px;
.menuitemtop *{ border-color:inherit;
margin:2px 2px 0 2px; border-left-width:inherit;
padding: 5px 10px 3px 5px; border-right-width:inherit;
} }
.menuitemmiddle *{ .menuitemmiddle{
margin:0 2px 0 2px; margin-top:0px;
padding: 3px 10px 3px 5px; margin-bottom:0px;
} border-color:inherit;
.menuitembottom *{ border-left-width:inherit;
margin:0 2px 2px 2px; border-right-width:inherit;
padding: 3px 10px 5px 5px; }
}
.menuitemtop:hover { .menuitemtop{
background:@theme_bg_color; margin-bottom:0px;
border-color:inherit; border-color:inherit;
border-left-width:inherit; border-top-width:inherit;
border-right-width:inherit; border-left-width:inherit;
} border-right-width:inherit;
.menuitemmiddle:hover { }
background:@theme_bg_color; .menuitemtop>*{
border-color:inherit; margin:2px 2px 0 2px;
border-left-width:inherit; padding: 3px 10px 3px 5px;
border-right-width:inherit; border:transparent;
} }
.menuitembottom:hover { .menuitemmiddle>*{
background:@theme_bg_color; margin:0 2px 0 2px;
border-color:inherit; padding: 3px 10px 3px 5px;
border-left-width:inherit; border:transparent;
border-right-width:inherit; }
.menuitembottom>*{
} margin:0 2px 2px 2px;
.menuitemtop:hover* { padding: 3px 10px 3px 5px;
margin:2px 2px 0 2px; }
padding: 5px 10px 3px 5px; .menuitemtop:hover {
background:@theme_selected_bg_color; background:@theme_base_color;
border-radius:2px; border-color:inherit;
} border-top-width:inherit;
.menuitemmiddle:hover* { border-left-width:inherit;
margin:0 2px 0 2px; border-right-width:inherit;
padding: 3px 10px 3px 5px; }
background:@theme_selected_bg_color; .menuitemmiddle:hover {
border-radius:2px; background:@theme_base_color;
} border-color:inherit;
.menuitembottom:hover* { border-left-width:inherit;
margin:0 2px 2px 2px; border-right-width:inherit;
padding: 3px 10px 5px 5px; }
background:@theme_selected_bg_color; .menuitembottom:hover {
border-radius:2px; background:@theme_base_color;
} border-color:inherit;
border-bottom-width:0px;
border-left-width:inherit;
border-right-width:inherit;
}
.menuitemtop:hover>* {
margin:2px 2px 0 2px;
padding: 3px 10px 3px 5px;
/* padding: 5px 0 3px 5px; */
background:@theme_selected_bg_color;
border-radius:2px;
}
.menuitemmiddle:hover>* {
margin:0 2px 0px 2px;
padding: 3px 10px 3px 5px;
/* padding: 3px 0px 3px 5px; */
background:@theme_selected_bg_color;
border-radius:2px;
}
.menuitembottom:hover>* {
margin:0 2px 2px 2px;
padding: 3px 10px 3px 5px;
/* padding: 3px 0px 5px 5px; */
background:@theme_selected_bg_color;
border-radius:2px;
}
.noborder{ .noborder{
border:none; border:none;

@ -26,10 +26,6 @@
<object class="GtkBox" id="BoxMain"> <object class="GtkBox" id="BoxMain">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkBox" id="boxDateTime"> <object class="GtkBox" id="boxDateTime">
@ -384,7 +380,7 @@ Format: DD.MM.YYYY</property>
</items> </items>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack-type">end</property> <property name="pack-type">end</property>
<property name="position">2</property> <property name="position">2</property>
@ -410,7 +406,7 @@ Format: DD.MM.YYYY</property>
<property name="vexpand">False</property> <property name="vexpand">False</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
@ -434,7 +430,7 @@ Format: DD.MM.YYYY</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack-type">end</property> <property name="pack-type">end</property>
<property name="position">2</property> <property name="position">2</property>
@ -444,7 +440,7 @@ Format: DD.MM.YYYY</property>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="label" translatable="yes" context="Zone" comments="Zone">Zone:</property> <property name="label" translatable="yes">Zone:</property>
<property name="xalign">0</property> <property name="xalign">0</property>
</object> </object>
<packing> <packing>

Loading…
Cancel
Save