diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 457ab14..4fe2d98 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -30,7 +30,7 @@ endif() # -O2 -pipe -fno-plt -fexceptions \ # -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \ # -fstack-clash-protection -fcf-protection") - +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") add_library(${PROJECT_NAME} SHARED ${PROJECT_NAME}.c ${PROJECT_NAME}.h) diff --git a/source/libublsettings-gtk3.c b/source/libublsettings-gtk3.c index 74b7115..a84f1e0 100644 --- a/source/libublsettings-gtk3.c +++ b/source/libublsettings-gtk3.c @@ -87,6 +87,41 @@ void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, voi gtk_widget_show_all(terminal); } + + void __on_yon_terminal_done(GtkWidget *self, void *, GtkWidget *status_box){ + yon_ubl_status_box_spawn_infinite(GTK_CONTAINER(status_box),"terminal_done","",BACKGROUND_IMAGE_SUCCESS_TYPE); + } + + void yon_terminal_window_launch(GtkWindow *parent_window, char *command){ + GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + GtkWidget *header = gtk_header_bar_new(); + GtkWidget *terminal = vte_terminal_new(); + GtkWidget *status_box = gtk_box_new(GTK_ORIENTATION_VERTICAL,5); + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL,5); + GtkWidget *terminal_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); + GtkWidget *scroll = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL,gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(terminal))); + + gtk_window_set_titlebar(GTK_WINDOW(window),header); + gtk_container_add(GTK_CONTAINER(window),box); + gtk_box_pack_start(GTK_BOX(box),status_box,0,0,0); + gtk_box_pack_start(GTK_BOX(box),terminal_box,1,1,0); + gtk_box_pack_start(GTK_BOX(terminal_box),terminal,1,1,0); + gtk_box_pack_start(GTK_BOX(terminal_box),scroll,0,0,0); + gtk_widget_set_margin_bottom(terminal_box,5); + gtk_widget_set_margin_start(terminal_box,5); + gtk_widget_set_margin_end(terminal_box,5); + gtk_widget_show_all(window); + + vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal),-1); + + gtk_window_set_modal(GTK_WINDOW(window),1); + gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header),1); + gtk_window_set_title(GTK_WINDOW(window),gtk_window_get_title(parent_window)); + gtk_window_set_icon_name(GTK_WINDOW(window),gtk_window_get_icon_name(parent_window)); + g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(__on_yon_terminal_done), status_box); + yon_terminal_integrated_start(terminal,command); + } + void yon_gtk_set_scroll(GtkWidget* self,GdkEventScroll *event, GtkAdjustment *adjustment){ if (self){}; gdouble val = gtk_adjustment_get_value(adjustment); @@ -201,6 +236,13 @@ void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, voi if (!__yon_main_window_config.fullscreen) gtk_window_get_position(__yon_window_config_target_window,&__yon_main_window_config.x,&__yon_main_window_config.y); } + void yon_window_config_save_instant(){ + check_window_config_setup{ + yon_get_is_fullscreen(); + yon_window_config_save(); + } + } + /**yon_on_configured_window_destroy(GtkWidget* self,GdkEvent* event) * [EN] * @@ -344,6 +386,10 @@ void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, voi param->section=section; yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.deleted_parameters,param->parameter_name,param); } + + void yon_window_config_erase_instant_parameter(char *param_name, char *section){ + g_key_file_remove_key(__yon_window_config_file,section,param_name,NULL); + } int yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type){ @@ -723,17 +769,16 @@ static char *yon_status_thread_id=NULL; void _yon_ubl_status_box_timed_remove(struct temp_statusbox *statusstruct){ sleep(statusstruct->times); - if (status_thread_busy){ + if (statusstruct->revealer){ gtk_revealer_set_reveal_child(GTK_REVEALER(statusstruct->revealer),0); sleep(1); gtk_widget_destroy(statusstruct->revealer); } - status_thread_busy=0; } -void __yon_ubl_status_box_destroyed(){ - status_thread_busy=0; +void __yon_ubl_status_box_destroyed(GtkWidget *self,struct temp_statusbox *statusstruct){ + statusstruct->revealer=NULL; } void yon_status_box_destroyed(){ @@ -744,7 +789,7 @@ void yon_status_box_destroyed(){ } int yon_ubl_status_box_spawn_infinite(GtkContainer *container, char *status_id, char *display_text, BACKGROUND_IMAGE_TYPE type){ - if (!status_thread_busy){ + if (!gtk_container_get_children(container)){ if (yon_status_thread_id){ if (!strcmp(yon_status_thread_id,status_id)){ return 0; @@ -755,7 +800,6 @@ int yon_ubl_status_box_spawn_infinite(GtkContainer *container, char *status_id, for (int i=0;irevealer = revealer; } } @@ -822,7 +866,7 @@ int yon_ubl_status_box_despawn_infinite(GtkContainer *container){ } void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int timeout,BACKGROUND_IMAGE_TYPE type){ - if (!status_thread_busy){ + if (!gtk_container_get_children(container)){ GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); GtkWidget *revealer = gtk_revealer_new(); GtkWidget *label = gtk_label_new(""); @@ -836,7 +880,6 @@ void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int ti gtk_widget_show_all(revealer); gtk_revealer_set_reveal_child(GTK_REVEALER(revealer),1); - g_signal_connect(G_OBJECT(revealer),"destroy", G_CALLBACK(__yon_ubl_status_box_destroyed),NULL); gtk_widget_set_margin_bottom(label,9); gtk_widget_set_margin_top(label,9); @@ -861,8 +904,8 @@ void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int ti struct temp_statusbox *statusstruct = malloc(sizeof(struct temp_statusbox)); statusstruct->revealer = revealer; statusstruct->times = timeout; + g_signal_connect(G_OBJECT(revealer),"destroy", G_CALLBACK(__yon_ubl_status_box_destroyed),statusstruct); GThread *thread = g_thread_new("StatusThread",(GThreadFunc)_yon_ubl_status_box_timed_remove,statusstruct); - status_thread_busy=1; } } @@ -1165,7 +1208,91 @@ void yon_gtk_tree_store_copy_full(GtkTreeStore *source, GtkTreeStore *destinatio } } +gboolean yon_gtk_tree_iter_get_from_combo_box_id(GtkComboBox *combo, GtkTreeModel *model, GtkTreeIter *iter){ + g_return_val_if_fail(GTK_IS_COMBO_BOX(combo),0); + g_return_val_if_fail(GTK_IS_TREE_MODEL(model),0); + const char *id = gtk_combo_box_get_active_id(combo); + if (yon_char_is_empty(id)) return 0; + gtk_tree_model_get_iter_from_string(model,iter,id); + return 1; +} +gboolean yon_gtk_tree_model_check_exist(GtkTreeModel *model, GtkTreeIter *iter, char *id, int column){ + g_return_val_if_fail(model&>K_IS_TREE_MODEL(model),0); + g_return_val_if_fail(iter,0); + for_iter(model,iter){ + char *check_target; + gtk_tree_model_get(model,iter,column,&check_target,-1); + if (!yon_char_is_empty(check_target)&&!strcmp(id,check_target)){ + return 1; + } + } + return 0; +} + +int yon_calendar_set_orientation = 0; + +int yon_calendar_last_date = 0; + +int yon_calendar_get_last_date(){ + return yon_calendar_last_date; +} + +void yon_calendar_set_date_orientation(int orientation){ + yon_calendar_set_orientation = orientation; +} + +void yon_on_date_selected(GtkWidget *self,GtkWidget *target){ + { + if (self){}; + unsigned int year=0, month=0, day=0; + gtk_calendar_get_date(GTK_CALENDAR(self),&year,&month,&day); + char *dy = yon_char_from_int(day); + char *mn = yon_char_from_int(month+1); + char *yr = yon_char_from_int(year); + if (month+1<10) mn = yon_char_append("0",mn); + if (day<10) dy = yon_char_append("0",dy); + + GDateTime *datetime = g_date_time_new_now_local(); + GDateTime *current_datetime = g_date_time_new_local(year,month+1,day,0,0,0); + int comparison = g_date_time_compare(current_datetime,datetime); + if ((comparison <0&&yon_calendar_set_orientation>0)||(comparison>0&&yon_calendar_set_orientation<0)){ + gtk_entry_set_text(GTK_ENTRY(target),g_date_time_format(datetime,"%Y-%m-%d")); + yon_calendar_last_date = g_date_time_to_unix(datetime); + } else { + char *date_string = yon_char_unite(yr,"-",mn,"-",dy,NULL); + gtk_entry_set_text(GTK_ENTRY(target), date_string); + yon_calendar_last_date = g_date_time_to_unix(current_datetime); + } + free(dy); + free(mn); + free(yr); + } +} +void yon_on_popover_closed(GtkWidget *self){ + gtk_widget_destroy(self); +} +void yon_calendar_popover_open(GtkEntry *TargetEntry,GtkWidget *PopupTarget){ + g_return_if_fail(GTK_IS_ENTRY(TargetEntry)); + g_return_if_fail(GTK_IS_WIDGET(PopupTarget)); + GtkWidget *popover = gtk_popover_new(PopupTarget); + GtkWidget *calendar = gtk_calendar_new(); + gtk_container_add(GTK_CONTAINER(popover),calendar); + gtk_widget_show_all(popover); + gtk_popover_popup(GTK_POPOVER(popover)); + + const char *date_str = gtk_entry_get_text(TargetEntry); + if (date_str&&strcmp(date_str,"")){ + int date_size; + config_str date_parsed = yon_char_parse((char*)date_str,&date_size,"-"); + gtk_calendar_select_day(GTK_CALENDAR(calendar),atoi(date_parsed[2])); + gtk_calendar_select_month(GTK_CALENDAR(calendar),atoi(date_parsed[1])-1,atoi(date_parsed[0])); + } + + g_signal_connect(G_OBJECT(calendar),"day-selected",G_CALLBACK(yon_on_date_selected),TargetEntry); + g_signal_connect(G_OBJECT(popover),"closed",G_CALLBACK(yon_on_popover_closed),NULL); + +} #endif \ No newline at end of file diff --git a/source/libublsettings-gtk3.h b/source/libublsettings-gtk3.h index 448f428..012b911 100644 --- a/source/libublsettings-gtk3.h +++ b/source/libublsettings-gtk3.h @@ -42,6 +42,8 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command); */ void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument); +void yon_terminal_window_launch(GtkWindow *parent_window, char *command); + #endif #define for_iter(model,iter) for(int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model),iter);valid;valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model),iter)) @@ -77,6 +79,8 @@ enum YON_TYPE{ */ #define yon_gtk_builder_get_widget(builder, widget_name) GTK_WIDGET(gtk_builder_get_object(builder, widget_name)) +void yon_window_config_save_instant(); + /**yon_window_config_setup(GtkWindow *window) * [EN] * @@ -119,6 +123,8 @@ void yon_window_config_add_listener(GtkWidget *widget, char *param_name, char *w */ void yon_window_config_add_custom_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type); +void yon_window_config_add_instant_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type); + /**yon_window_config_erase_custom_parameter(char *param_name, char *section) * [EN] * @@ -128,6 +134,8 @@ void yon_window_config_add_custom_parameter(char *param_name, char *section, voi */ void yon_window_config_erase_custom_parameter(char *param_name, char *section); +void yon_window_config_erase_instant_parameter(char *param_name, char *section); + /**yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type) * [EN] * @@ -209,6 +217,8 @@ int yon_gtk_combo_box_text_find(GtkWidget *combo_box, char *text_to_find); */ void yon_gtk_tree_view_minimal_fixed_size_set_full(GtkTreeView *tree); +void yon_gtk_tree_view_set_(GtkTreeView *top,GtkTreeView *resizing, ...); + /**yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...) * [EN] * @@ -463,4 +473,16 @@ dictionary *yon_gtk_tree_store_get_children(GtkTreeStore *tree, GtkTreeIter *par void yon_gtk_tree_store_fill_children(GtkTreeStore *tree, GtkTreeIter *parent, dictionary *data, int column); -void yon_gtk_tree_store_copy_full(GtkTreeStore *source, GtkTreeStore *destination); \ No newline at end of file +void yon_gtk_tree_store_copy_full(GtkTreeStore *source, GtkTreeStore *destination); + +gboolean yon_gtk_tree_store_find_full(GtkTreeModel *model, GtkTreeIter *iter, gint column, const gchar *target); + +gboolean yon_gtk_tree_iter_get_from_combo_box_id(GtkComboBox *combo, GtkTreeModel *model, GtkTreeIter *iter); + +gboolean yon_gtk_tree_model_check_exist(GtkTreeModel *model, GtkTreeIter *iter, char *id, int column); + +void yon_calendar_set_date_orientation(int orientation); + +void yon_calendar_popover_open(GtkEntry *TargetEntry,GtkWidget *PopupTarget); + +int yon_calendar_get_last_date(); \ No newline at end of file