From 05f6fab9e750ab9adc5561a12f97906d68d85606 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Thu, 9 Jan 2025 12:40:32 +0600 Subject: [PATCH] Source file were splitted, added function for tree view's colums automatic fixed width --- source/CMakeLists.txt | 12 +- source/libublsettings-gtk3-calendar.c | 67 + source/libublsettings-gtk3-menu.c | 94 ++ source/libublsettings-gtk3-misc.c | 302 ++++ source/libublsettings-gtk3-socket.c | 63 + source/libublsettings-gtk3-status.c | 257 ++++ source/libublsettings-gtk3-tree-view.c | 221 +++ source/libublsettings-gtk3-vte.c | 139 ++ source/libublsettings-gtk3-webkit.c | 29 + source/libublsettings-gtk3-window-config.c | 359 +++++ source/libublsettings-gtk3.c | 1442 -------------------- source/libublsettings-gtk3.h | 6 + 12 files changed, 1547 insertions(+), 1444 deletions(-) create mode 100644 source/libublsettings-gtk3-calendar.c create mode 100644 source/libublsettings-gtk3-menu.c create mode 100644 source/libublsettings-gtk3-misc.c create mode 100644 source/libublsettings-gtk3-socket.c create mode 100644 source/libublsettings-gtk3-status.c create mode 100644 source/libublsettings-gtk3-tree-view.c create mode 100644 source/libublsettings-gtk3-vte.c create mode 100644 source/libublsettings-gtk3-webkit.c create mode 100644 source/libublsettings-gtk3-window-config.c diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 4fe2d98..fbad207 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.9) -project(libublsettings-gtk3 VERSION 0) +project(libublsettings-gtk3 VERSION 1.2) include(GNUInstallDirs) find_package(PkgConfig REQUIRED) @@ -30,8 +30,16 @@ 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}-calendar.c + ${PROJECT_NAME}-menu.c + ${PROJECT_NAME}-misc.c + ${PROJECT_NAME}-socket.c + ${PROJECT_NAME}-status.c + ${PROJECT_NAME}-tree-view.c + ${PROJECT_NAME}-vte.c + ${PROJECT_NAME}-webkit.c + ${PROJECT_NAME}-window-config.c ${PROJECT_NAME}.c ${PROJECT_NAME}.h) diff --git a/source/libublsettings-gtk3-calendar.c b/source/libublsettings-gtk3-calendar.c new file mode 100644 index 0000000..81f542a --- /dev/null +++ b/source/libublsettings-gtk3-calendar.c @@ -0,0 +1,67 @@ +#include "libublsettings-gtk3.h" + +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); + +} \ No newline at end of file diff --git a/source/libublsettings-gtk3-menu.c b/source/libublsettings-gtk3-menu.c new file mode 100644 index 0000000..03e9ed4 --- /dev/null +++ b/source/libublsettings-gtk3-menu.c @@ -0,0 +1,94 @@ +#include "libublsettings-gtk3.h" + +// rmb menu section +typedef int (*RmbCheck)(void*); + +gboolean on_rmb_menu_open(GtkWidget *self,GdkEventButton *event, rmb_menu_window *window){ + int (*func)(void*) = (RmbCheck)(window->show_function); + if (!func||func(window->show_data)){ + if (self){}; + if (event->button==3){ + + gtk_widget_show_all(window->menu); + gtk_menu_popup_at_pointer(GTK_MENU(window->menu),NULL); + return 0; + } + return 0; + } +} + +rmb_menu_window *yon_rmb_menu_new(){ + rmb_menu_window *window = malloc(sizeof(rmb_menu_window)); + window->menu=gtk_menu_new(); + gtk_menu_set_reserve_toggle_size(GTK_MENU(window->menu),0); + window->buttons=NULL; + + return window; +} + +rmb_menu_window *yon_rmb_menu_setup(GtkWidget *target_widget, int (show_function)(void*), void *show_data, const char *button_label, const char *icon_name, GCallback function, gpointer data,...){ + if (target_widget){ + rmb_menu_window *window = yon_rmb_menu_new(); + window->show_function=(GCallback)show_function; + window->show_data=show_data; + { + GtkWidget *menu_item = gtk_menu_item_new(); + GtkWidget *content_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); + gtk_container_add(GTK_CONTAINER(menu_item),content_box); + + GtkWidget *image=NULL; + if (!yon_char_is_empty(icon_name)){ + image=gtk_image_new_from_icon_name(icon_name,GTK_ICON_SIZE_BUTTON); + gtk_box_pack_start(GTK_BOX(content_box),image,0,0,0); + gtk_widget_show(image); + } + + GtkWidget *label = gtk_label_new(button_label); + gtk_box_pack_start(GTK_BOX(content_box),label,0,0,0); + + if (function){ + g_signal_connect(G_OBJECT(menu_item),"activate",function,data); + } else { + gtk_widget_set_sensitive(menu_item,0); + } + yon_dictionary_add_or_create_if_exists_with_data(window->buttons,(char*)button_label,menu_item); + gtk_menu_shell_append(GTK_MENU_SHELL(window->menu),menu_item); + } + va_list list; + va_start(list,data); + const char *current_label, *current_icon; + GCallback current_function; + gpointer *current_data; + while ((current_label=va_arg(list,const char*))){ + if (current_label){ + current_icon=va_arg(list,const char*); + current_function=va_arg(list,GCallback); + current_data=va_arg(list,gpointer); + GtkWidget *menu_item = gtk_menu_item_new(); + GtkWidget *content_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); + gtk_container_add(GTK_CONTAINER(menu_item),content_box); + + GtkWidget *image=NULL; + if (!yon_char_is_empty(current_icon)){ + image=gtk_image_new_from_icon_name(current_icon,GTK_ICON_SIZE_BUTTON); + gtk_box_pack_start(GTK_BOX(content_box),image,0,0,0); + gtk_widget_show(image); + } + + GtkWidget *label = gtk_label_new(current_label); + gtk_box_pack_start(GTK_BOX(content_box),label,0,0,0); + + if (current_function){ + g_signal_connect(G_OBJECT(menu_item),"activate",current_function,current_data); + } else { + gtk_widget_set_sensitive(menu_item,0); + } + yon_dictionary_add_or_create_if_exists_with_data(window->buttons,(char*)current_label,menu_item); + gtk_menu_shell_append(GTK_MENU_SHELL(window->menu),menu_item); + gtk_widget_show(menu_item); + } + } + g_signal_connect(G_OBJECT(target_widget),"button-press-event",G_CALLBACK(on_rmb_menu_open),window); + return window; + } +} \ No newline at end of file diff --git a/source/libublsettings-gtk3-misc.c b/source/libublsettings-gtk3-misc.c new file mode 100644 index 0000000..c21c4a7 --- /dev/null +++ b/source/libublsettings-gtk3-misc.c @@ -0,0 +1,302 @@ +#include "libublsettings-gtk3.h" + + +void on_subwindow_close(GtkWidget *self){ + gtk_widget_destroy(gtk_widget_get_toplevel(self)); +} + +int yon_gtk_window_setup(GtkWindow *window, GtkWindow *transistent_window, char *title, char *icon_name, char *window_id){ + if (GTK_IS_WINDOW(window)){ + int success=0; + if (transistent_window){ + gtk_window_set_transient_for(window,transistent_window); + success++; + } + if (!yon_char_is_empty(title)){ + gtk_window_set_title(window,title); + success++; + } + if (!yon_char_is_empty(icon_name)){ + gtk_window_set_icon_name(window,icon_name); + success++; + } + if (!yon_char_is_empty(window_id)){ + yon_window_config_custom_window_setup(window,window_id); + success++; + } + return success; + } else { + return 0; + } +} + +GtkWidget *yon_ubl_menu_item_about_new(char *buttonname){ + GtkWidget *menu_item = gtk_menu_item_new(); + gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitembottom"); + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); + GtkWidget *label = gtk_label_new(buttonname); + GtkWidget *image = gtk_image_new_from_icon_name("dialog-information-symbolic",GTK_ICON_SIZE_BUTTON); + gtk_label_set_xalign(GTK_LABEL(label),0.0); + gtk_box_pack_start(GTK_BOX(box),image,0,0,5); + gtk_box_pack_start(GTK_BOX(box),label,0,0,5); + gtk_container_add(GTK_CONTAINER(menu_item),box); + gtk_widget_show_all(menu_item); + return menu_item; +} + +GtkWidget *yon_ubl_menu_item_documentation_new(char *buttonname){ + GtkWidget *menu_item = gtk_menu_item_new(); + gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitemtop"); + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); + GtkWidget *label = gtk_label_new(buttonname); + GtkWidget *image = gtk_image_new_from_icon_name("dialog-question-symbolic",GTK_ICON_SIZE_BUTTON); + gtk_label_set_xalign(GTK_LABEL(label),0.0); + gtk_box_pack_start(GTK_BOX(box),image,0,0,5); + gtk_box_pack_start(GTK_BOX(box),label,0,0,5); + gtk_container_add(GTK_CONTAINER(menu_item),box); + gtk_widget_show_all(menu_item); + return menu_item; +} + +int yon_gtk_combo_box_fill(GtkWidget *combo, config_str parameters,int size){ + if (combo&¶meters){ + for (int i=0;icolumn&&resizing_columns>connect_to){ + char *name="1"; + name[0]=connect_to+1; + dictionary *cur = NULL; + if (!(cur =yon_dictionary_get(&dict,name))){ + int *width = malloc(sizeof(int)); + (*width)=gtk_tree_view_column_get_width(gtk_tree_view_get_column(top,column)); + yon_dictionary_append_with_data(dict,name,width); + } else { + *(int*)cur->data+=gtk_tree_view_column_get_width(gtk_tree_view_get_column(top,column)); + } + } + } + dictionary *cur; + for_dictionaries(cur,dict){ + int cur_column = cur->key[0]-1; + gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column(resizing,cur_column),*(int*)dict->data); + free(dict->data); + } + va_end(arglist); +} + +int yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...){ + va_list args; + va_start(args,padding); + GtkWidget *widget = va_arg(args,GtkWidget*); + while (widget){ + gtk_box_pack_start(GTK_BOX(destination), widget, expand, fill, padding); + } + va_end(args); + return 1; +} + +int yon_dictionary_gtk_pack_end_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...){ + va_list args; + va_start(args,padding); + GtkWidget *widget = va_arg(args,GtkWidget*); + while (widget){ + gtk_box_pack_end(GTK_BOX(destination), widget, expand, fill, padding); + } + va_end(args); + return 1; +} + +int yon_gtk_list_store_find_text(GtkListStore *list, GtkTreeIter *iter, int seek_column, char *value){ + int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list),iter); + for (;valid;valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(list),iter)){ + char *seek_value; + gtk_tree_model_get(GTK_TREE_MODEL(list),iter,seek_column,&seek_value,-1); + if (!strcmp(value,seek_value)){ + free(seek_value); + return 1; + } + free(seek_value); + } + return 0; +} +void yon_on_cell_renderer_toggle_toggled_for_list_store(GtkWidget *self, gchar *path,GtkWidget *tree){ + GtkTreePath *path_converted = gtk_tree_path_new_from_string(path); + GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree)); + GtkTreeIter iter; + gtk_tree_model_get_iter(model,&iter,path_converted); + int last = yon_char_find_last(path,':'); + char *col = path+last+1; + int status; + gtk_tree_model_get(model,&iter,atoi(col),&status,-1); + gtk_list_store_set(GTK_LIST_STORE(model),&iter,atoi(col),!status,-1); +} + +void yon_cell_renderer_toggle_set_toggle(GtkCellRendererToggle *target,GtkWidget *tree){ + g_return_if_fail(GTK_IS_CELL_RENDERER_TOGGLE(target)); + g_signal_connect(G_OBJECT(target),"toggled",G_CALLBACK(yon_on_cell_renderer_toggle_toggled_for_list_store),tree); +} + +void yon_gtk_toggle_button_set_inactive_from_toggle(GtkToggleButton *self, GtkToggleButton *target){ + if (gtk_toggle_button_get_active(self)){ + gtk_toggle_button_set_active(target,1); + } else { + gtk_toggle_button_set_active(target,0); + } +} + +void yon_gtk_toggle_button_set_inactive_from_entry(GtkEntry *self, GtkToggleButton *target){ + if (strlen(gtk_entry_get_text(self))>0){ + gtk_toggle_button_set_active(target,1); + } else { + gtk_toggle_button_set_active(target,0); + } +} + +void yon_gtk_toggle_button_set_inactive_from_combo_box(GtkComboBox *self, GtkToggleButton *target){ + if (gtk_combo_box_get_active(self)>0){ + gtk_toggle_button_set_active(target,1); + } else { + gtk_toggle_button_set_active(target,0); + } +} + +void yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target){ + gtk_widget_set_sensitive(target,gtk_toggle_button_get_active(toggle)); +} + +void yon_gtk_widget_set_sensitive_from_toggle_button_inversed(GtkToggleButton *toggle, GtkWidget *target){ + gtk_widget_set_sensitive(target,!gtk_toggle_button_get_active(toggle)); + +} + +void yon_gtk_widget_set_sensitive_from_combo_box(GtkComboBox *toggle, GtkWidget *target){ + gtk_widget_set_sensitive(target,gtk_combo_box_get_active(toggle)>0 ? 1 : 0); +} + +void yon_gtk_widget_set_sensitive_from_combo_box_inversed(GtkComboBox *toggle, GtkWidget *target){ + gtk_widget_set_sensitive(target,!gtk_combo_box_get_active(toggle)>0 ? 0 : 1); +} + +void yon_gtk_toggle_button_set_inactive_from_toggle_button_inversed(GtkToggleButton *self, GtkToggleButton *target){ + if (gtk_toggle_button_get_active(self)){ + gtk_toggle_button_set_active(target,0); + } +} + +void yon_gtk_toggle_button_set_inactive_from_toggle_button(GtkToggleButton *self, GtkToggleButton *target){ + if (!gtk_toggle_button_get_active(self)){ + gtk_toggle_button_set_active(target,0); + } +} + +void yon_on_text_insert_only_digits(GtkEditable *editable, const gchar *text, gint length, gint *position, gpointer user_data){ + gchar *new_text = g_new(gchar, length + 1); + gint i, j = 0; + + for (i = 0; i < length; i++) { + if (g_ascii_isdigit(text[i])) { + new_text[j] = text[i]; + j++; + } + } + + if (j < length) { + g_signal_handlers_block_by_func(editable, G_CALLBACK(yon_on_text_insert_only_digits), user_data); + gtk_editable_insert_text(editable, new_text, j, position); + g_signal_handlers_unblock_by_func(editable, G_CALLBACK(yon_on_text_insert_only_digits), user_data); + g_signal_stop_emission_by_name(editable, "insert-text"); + } + + g_free(new_text); +} + +void yon_on_insert_restricted_check(GtkEditable *editable, const gchar *text, gint length, gint *position, gpointer){ + gchar *new_text = g_new(gchar, length + 1); + gint i, j = 0; + + for (i = 0; i < length; i++) { + if (text[i]!='!'&&text[i]!='@'&&text[i]!='#'&&text[i]!='%'&&text[i]!='^'&&text[i]!='&'&&text[i]!='*'&&text[i]!='\"'&&text[i]!='\'') { + new_text[j] = text[i]; + j++; + } + } + + if (j < length) { + g_signal_handlers_block_by_func(editable, G_CALLBACK(yon_on_insert_restricted_check), NULL); + gtk_editable_insert_text(editable, new_text, j, position); + g_signal_handlers_unblock_by_func(editable, G_CALLBACK(yon_on_insert_restricted_check), NULL); + g_signal_stop_emission_by_name(editable, "insert-text"); + } + + g_free(new_text); +} + +void yon_gtk_entry_block_restricted_symbols(GtkEntry *target){ + g_return_if_fail(GTK_IS_ENTRY(target)); + g_signal_connect(G_OBJECT(target),"insert-text",G_CALLBACK(yon_on_insert_restricted_check),NULL); +} \ No newline at end of file diff --git a/source/libublsettings-gtk3-socket.c b/source/libublsettings-gtk3-socket.c new file mode 100644 index 0000000..dfcb665 --- /dev/null +++ b/source/libublsettings-gtk3-socket.c @@ -0,0 +1,63 @@ +#include "libublsettings-gtk3.h" + + +void yon_ubl_setup_sockets(GtkWidget *main_window, GtkWidget *left_window, GtkWidget *right_window, int socket_main_id, int socket_left_id, int socket_right_id){ + if (main_window&&socket_main_id>-1){ + gtk_widget_hide(gtk_widget_get_toplevel(main_window)); + GtkWidget *plug_main=gtk_plug_new(socket_main_id); + GtkWidget *plug_left=NULL; + GtkWidget *plug_right=NULL; + GtkWidget *box=NULL; + g_signal_connect(G_OBJECT(plug_main), "destroy", G_CALLBACK(gtk_main_quit),NULL); + if (socket_left_id>-1&&left_window){ + plug_left=gtk_plug_new(socket_left_id); + g_object_ref(left_window); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(left_window)),left_window); + gtk_container_add(GTK_CONTAINER(plug_left),left_window); + gtk_style_context_add_class(gtk_widget_get_style_context(plug_left),"primary-toolbar"); + gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"button"); + gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"opacited"); + gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"color"); + gtk_style_context_add_class(gtk_widget_get_style_context(plug_left),"noborder"); + gtk_widget_show(plug_left); + } + else if (left_window){ + if (box==NULL){ + box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); + gtk_box_pack_start(GTK_BOX(main_window),box,0,0,5); + gtk_box_reorder_child(GTK_BOX(main_window),box,0); + gtk_widget_show(box); + } + gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"inherited"); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(left_window)),left_window); + gtk_box_pack_start(GTK_BOX(box),left_window,0,0,5); + } + if (socket_right_id>-1&&right_window){ + plug_right=gtk_plug_new(socket_right_id); + g_object_ref(right_window); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(right_window)),right_window); + gtk_container_add(GTK_CONTAINER(plug_right),right_window); + gtk_style_context_add_class(gtk_widget_get_style_context(plug_right),"primary-toolbar"); + gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"button"); + gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"opacited"); + gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"color"); + gtk_style_context_add_class(gtk_widget_get_style_context(plug_right),"noborder"); + gtk_widget_show(plug_right); + } + else if (right_window){ + if (box==NULL){ + box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); + gtk_box_pack_start(GTK_BOX(main_window),box,0,0,5); + gtk_box_reorder_child(GTK_BOX(main_window),box,0); + gtk_widget_show(box); + } + gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"inherited"); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(right_window)),right_window); + gtk_box_pack_end(GTK_BOX(box),right_window,0,0,5); + } + g_object_ref(main_window); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(main_window)),main_window); + gtk_container_add(GTK_CONTAINER(plug_main),main_window); + gtk_widget_show(plug_main); + } +} \ No newline at end of file diff --git a/source/libublsettings-gtk3-status.c b/source/libublsettings-gtk3-status.c new file mode 100644 index 0000000..7bb6d0a --- /dev/null +++ b/source/libublsettings-gtk3-status.c @@ -0,0 +1,257 @@ +#include "libublsettings-gtk3.h" + +static render_data render; + +void _yon_ubl_header_setup(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path) +{ + gtk_overlay_add_overlay(GTK_OVERLAY(Overlay), Head); + gtk_image_set_from_file(GTK_IMAGE(Image), image_path); +} + +void _yon_ubl_header_setup_resource(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path) +{ + gtk_overlay_add_overlay(GTK_OVERLAY(Overlay), Head); + gtk_image_set_from_resource(GTK_IMAGE(Image), image_path); +} + +int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label) +{ + if(icon&&box&&label){ + render.icon=icon; + render.box=box; + render.label=label; + return 1; + } else return 0; +} + +void yon_ubl_status_box_set(BACKGROUND_IMAGE_TYPE type, GtkWidget *box, GtkImage *icon){ + + GtkIconTheme *ictheme = gtk_icon_theme_get_default(); + switch (type){ + case BACKGROUND_IMAGE_SUCCESS_TYPE: + { + gtk_style_context_remove_class(gtk_widget_get_style_context(box), "boxInfoMessError"); + gtk_style_context_add_class(gtk_widget_get_style_context(box), "boxInfoMessOK"); + gtk_image_set_from_pixbuf(GTK_IMAGE(icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.libublsettingsui-gtk3.checked", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, NULL)); + } + break; + case BACKGROUND_IMAGE_FAIL_TYPE: + { + gtk_style_context_remove_class(gtk_widget_get_style_context(box), "boxInfoMessOK"); + gtk_style_context_add_class(gtk_widget_get_style_context(box), "boxInfoMessError"); + gtk_image_set_from_pixbuf(GTK_IMAGE(icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.libublsettingsui-gtk3.warning", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, NULL)); + } + break; + case BACKGROUND_IMAGE_INFO_TYPE: + { + gtk_style_context_remove_class(gtk_widget_get_style_context(box), "boxInfoMessError"); + gtk_style_context_add_class(gtk_widget_get_style_context(box), "boxInfoMessOK"); + gtk_image_set_from_pixbuf(GTK_IMAGE(icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.libublsettingsui-gtk3.important", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, NULL)); + } + break; + } +} + +void _yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type) +{ + render_data data = render; + yon_ubl_status_box_set(type,data.box,GTK_IMAGE(data.icon)); + if (text) + gtk_label_set_text(GTK_LABEL(data.label), text); +} + +void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type){ + _yon_ubl_status_box_render(text,type); +} + +void _yon_ubl_status_highlight_incorrect(GtkWidget *widget){ + gtk_style_context_add_class(gtk_widget_get_style_context(widget),"errorBox"); + sleep(5); + gtk_style_context_remove_class(gtk_widget_get_style_context(widget),"errorBox"); +} + +void yon_ubl_status_highlight_incorrect(GtkWidget *widget){ + GThread *thread = g_thread_new(NULL,(GThreadFunc)_yon_ubl_status_highlight_incorrect,widget); +} + +void _yon_ubl_status_list_store_highlight_incorrect(GtkWidget **widget_pack){ + GtkListStore *list = (GtkListStore*)widget_pack[0]; + GtkTreeIter *iter = (GtkTreeIter*)widget_pack[1]; + GdkRGBA rgba,rgba2; + rgba.alpha=1; + rgba.blue=153.0/255.0; + rgba.green=153.0/255.0; + rgba.red=234.0/255.0; + rgba2.alpha=1; + rgba2.blue=0; + rgba2.green=0; + rgba2.red=0; + gtk_list_store_set(list,iter,1,gdk_rgba_to_string(&rgba2),2,gdk_rgba_to_string(&rgba),-1); + sleep(5); + gtk_list_store_set(list,iter,1,NULL,2,NULL,-1); +} + +void yon_ubl_status_list_store_highlight_incorrect(GtkListStore *list, GtkTreeIter *iter){ + GtkWidget **pack = malloc(sizeof(GtkWidget *)*2); + pack[0]=(GtkWidget*)list; + pack[1]=(GtkWidget*)iter; + GThread *thread = g_thread_new(NULL,(GThreadFunc)_yon_ubl_status_list_store_highlight_incorrect,pack); +} + +struct temp_statusbox { + int times; + GtkWidget *revealer; + }; + +static char *yon_status_thread_id=NULL; + +void _yon_ubl_status_box_timed_remove(struct temp_statusbox *statusstruct){ + sleep(statusstruct->times); + if (statusstruct->revealer){ + gtk_revealer_set_reveal_child(GTK_REVEALER(statusstruct->revealer),0); + sleep(1); + gtk_widget_destroy(statusstruct->revealer); + + } +} + +void __yon_ubl_status_box_destroyed(GtkWidget *self,struct temp_statusbox *statusstruct){ + statusstruct->revealer=NULL; +} + +void yon_status_box_destroyed(){ + if (yon_status_thread_id){ + free(yon_status_thread_id); + yon_status_thread_id=NULL; + } +} + +int yon_ubl_status_box_spawn_infinite(GtkContainer *container, char *status_id, char *display_text, BACKGROUND_IMAGE_TYPE type){ + if (!gtk_container_get_children(container)){ + if (yon_status_thread_id){ + if (!strcmp(yon_status_thread_id,status_id)){ + return 0; + } + free(yon_status_thread_id); + yon_status_thread_id=NULL; + GList *list = gtk_container_get_children(container); + for (int i=0;irevealer = revealer; + } +} + +int delete_busy=0; +int _yon_ubl_status_box_despawn_infinite(GtkContainer *container){ + if (!delete_busy){ + delete_busy=1; + if (yon_status_thread_id){ + free(yon_status_thread_id); + yon_status_thread_id=NULL; + } + GList *list = gtk_container_get_children(container); + for (int i=0; i0){ + if (GTK_IS_REVEALER(revealer)){ + gtk_widget_destroy(revealer); + } + } + } + } + delete_busy=0; + } +} + +int yon_ubl_status_box_despawn_infinite(GtkContainer *container){ + GThread *thread = g_thread_new("StatusThread",(GThreadFunc)_yon_ubl_status_box_despawn_infinite,container); +} + +void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int timeout,BACKGROUND_IMAGE_TYPE type){ + 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(""); + GtkWidget *icon = gtk_image_new(); + gtk_label_set_line_wrap(GTK_LABEL(label),1); + gtk_label_set_line_wrap_mode(GTK_LABEL(label),PANGO_WRAP_WORD); + gtk_container_add(GTK_CONTAINER(revealer),box); + gtk_box_pack_start(GTK_BOX(box),icon,0,0,5); + gtk_box_pack_start(GTK_BOX(box),label,0,0,5); + gtk_container_add(container,revealer); + + gtk_widget_show_all(revealer); + gtk_revealer_set_reveal_child(GTK_REVEALER(revealer),1); + + gtk_widget_set_margin_bottom(label,9); + gtk_widget_set_margin_top(label,9); + gtk_label_set_xalign(GTK_LABEL(label),0.0); + PangoAttrList *attributes = pango_attr_list_new(); + PangoAttribute *boldAttr = pango_attr_weight_new(PANGO_WEIGHT_BOLD); + pango_attr_list_insert(attributes, boldAttr); + gtk_label_set_attributes(GTK_LABEL(label),attributes); + + GdkRGBA textColor; + gdk_rgba_parse(&textColor, "#4d4d4d4d4d4d"); + PangoAttribute *colorAttr = pango_attr_foreground_new( + (int)(textColor.red * 65535), + (int)(textColor.green * 65535), + (int)(textColor.blue * 65535) + ); + pango_attr_list_insert(attributes, colorAttr); + + yon_ubl_status_box_set(type,box,GTK_IMAGE(icon)); + if (display_text) + gtk_label_set_text(GTK_LABEL(label),display_text); + 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); + } +} \ No newline at end of file diff --git a/source/libublsettings-gtk3-tree-view.c b/source/libublsettings-gtk3-tree-view.c new file mode 100644 index 0000000..d8bda33 --- /dev/null +++ b/source/libublsettings-gtk3-tree-view.c @@ -0,0 +1,221 @@ +#include "libublsettings-gtk3.h" + +dictionary *yon_gtk_tree_store_get_children(GtkTreeStore *tree, GtkTreeIter *parent,int column){ + g_return_val_if_fail(GTK_IS_TREE_STORE(tree),NULL); + dictionary *children = NULL; + GtkTreeIter iter; + if(gtk_tree_model_iter_has_child){ + gtk_tree_model_iter_children(GTK_TREE_MODEL(tree),&iter,parent); + int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tree),&iter); + for (;valid;valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(tree),&iter)){ + void *result = NULL; + gtk_tree_model_get(GTK_TREE_MODEL(tree),&iter,column,&result,-1); + dictionary *child_children = yon_gtk_tree_store_get_children(tree,&iter,column); + yon_dictionary_add_or_create_if_exists_with_data(children,result,child_children); + } + return children; + } + return NULL; +} + +void yon_gtk_tree_store_fill_children(GtkTreeStore *tree, GtkTreeIter *parent, dictionary *data, int column){ + GtkTreeIter iter; + dictionary *dict=NULL; + for_dictionaries(dict,data){ + gtk_tree_store_append(tree,&iter,parent); + gtk_tree_store_set(tree,&iter,column,data->key,-1); + if (data->data){ + yon_gtk_tree_store_fill_children(tree,&iter,data->data,column); + } + } +} + +void yon_on_password_visibility_changed(GtkEntry *self, GtkEntryIconPosition position){ + if (position==GTK_ENTRY_ICON_SECONDARY){ + int status = gtk_entry_get_visibility(self); + gtk_entry_set_visibility(self,!status); + } +} + +void yon_gtk_entry_set_password_visibility_icon(GtkEntry *target){ + g_return_if_fail(GTK_IS_ENTRY(target)); + gtk_entry_set_icon_from_icon_name(target,GTK_ENTRY_ICON_SECONDARY,"com.ublinux.libublsettingsui-gtk3.view-symbolic"); + g_signal_connect(G_OBJECT(target),"icon-release",G_CALLBACK(yon_on_password_visibility_changed),NULL); +} + +void yon_gtk_tree_store_copy_recursive(GtkTreeModel *sourceModel, GtkTreeIter *sourceIter, GtkTreeStore *destination, GtkTreeIter *parentIter) { + GtkTreeIter destIter; + + gtk_tree_store_append(destination, &destIter, parentIter); + + gint nColumns = gtk_tree_model_get_n_columns(sourceModel); + for (gint col = 0; col < nColumns; col++) { + GValue value = G_VALUE_INIT; + + gtk_tree_model_get_value(sourceModel, sourceIter, col, &value); + + gtk_tree_store_set_value(destination, &destIter, col, &value); + + g_value_unset(&value); + } + + if (gtk_tree_model_iter_has_child(sourceModel, sourceIter)) { + GtkTreeIter childIter; + gboolean validChild = gtk_tree_model_iter_children(sourceModel, &childIter, sourceIter); + while (validChild) { + yon_gtk_tree_store_copy_recursive(sourceModel, &childIter, destination, &destIter); + validChild = gtk_tree_model_iter_next(sourceModel, &childIter); + } + } +} + +void yon_gtk_tree_store_copy_full(GtkTreeStore *source, GtkTreeStore *destination) { + GtkTreeModel *sourceModel = GTK_TREE_MODEL(source); + GtkTreeIter iter; + gboolean valid; + + valid = gtk_tree_model_get_iter_first(sourceModel, &iter); + + while (valid) { + yon_gtk_tree_store_copy_recursive(sourceModel, &iter, destination, NULL); + + valid = gtk_tree_model_iter_next(sourceModel, &iter); + } +} + +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; +} + +gboolean yon_gtk_list_store_copy_full(GtkListStore *target, GtkListStore *source){ + gtk_list_store_clear(target); + GtkTreeIter iter, itar; + g_return_val_if_fail(GTK_IS_LIST_STORE(target),0); + g_return_val_if_fail(GTK_IS_LIST_STORE(source),0); + int columns = gtk_tree_model_get_n_columns(GTK_TREE_MODEL(source)); + int target_columns = gtk_tree_model_get_n_columns(GTK_TREE_MODEL(target)); + if (columns!=target_columns){ + g_log((gchar*)0,G_LOG_LEVEL_WARNING,"%s\n","Target and source models have different number of columns"); + return 0; + } + for_iter(source,&iter){ + gtk_list_store_append(target,&itar); + for(int i=0;isize;i++){ + yon_gtk_tree_view_column_set_fixed_size(GTK_TREE_VIEW(info->target),info->columns[i]); + } + +} + +void on_row_fixed_deleted(GtkTreeModel* self, GtkTreePath* path, struct fixed_info *info){ + + for (int i=0;isize;i++){ + yon_gtk_tree_view_column_set_fixed_size(GTK_TREE_VIEW(info->target),info->columns[i]); + } +} + +void yon_on_fixed_changed(GtkTreeViewColumn *self, GParamSpec*,struct fixed_info *info){ + for (int i=0;isize;i++){ + if (self == gtk_tree_view_get_column(GTK_TREE_VIEW(info->target),info->columns[i])){ + int *new_columns = malloc(sizeof(int)*(info->size-1)); + for (int j=0;jsize-1;j++){ + if (jcolumns[j]; + else new_columns[j]=info->columns[j+1]; + } + free(info->columns); + info->columns=new_columns; + info->size--; + if (!info->size){ + GObject *model = G_OBJECT(gtk_tree_view_get_model(GTK_TREE_VIEW(info->target))); + g_signal_handlers_disconnect_by_func(model,on_row_fixed_changed,info); + g_signal_handlers_disconnect_by_func(model,on_row_fixed_deleted,info); + free(info->columns); + free(info); + } + return; + } + } +} + +int yon_gtk_tree_view_set_fixed_size(GtkTreeView *target,...){ + va_list args; + va_start(args,target); + int current; + int target_columns = gtk_tree_view_get_n_columns(target); + GtkTreeModel *model = gtk_tree_view_get_model(target); + struct fixed_info *info = malloc(sizeof(struct fixed_info)); + info->target=GTK_WIDGET(target); + info->columns=NULL; + info->size=0; + g_signal_connect(G_OBJECT(model),"row-changed",G_CALLBACK(on_row_fixed_changed),info); + g_signal_connect(G_OBJECT(model),"row-deleted",G_CALLBACK(on_row_fixed_deleted),info); + + while ((current=va_arg(args,int))!=-1){ + if (current>target_columns) return 0; + if (!info->columns) info->columns = malloc(sizeof(int)); + else info->columns = realloc(info->columns,sizeof(int)*(info->size+1)); + info->columns[info->size]=current; + g_signal_connect(G_OBJECT(gtk_tree_view_get_column(target,current)),"notify::fixed-width",G_CALLBACK(yon_on_fixed_changed),info); + info->size++; + } + va_end(args); + return 1; +} \ No newline at end of file diff --git a/source/libublsettings-gtk3-vte.c b/source/libublsettings-gtk3-vte.c new file mode 100644 index 0000000..a0f800c --- /dev/null +++ b/source/libublsettings-gtk3-vte.c @@ -0,0 +1,139 @@ +#include "libublsettings-gtk3.h" + +static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data) +{ + if (!terminal) return; + if (pid == -1) printf("Error\n\n\n"); + else vte_terminal_feed_child(VTE_TERMINAL(terminal),(char*)user_data,strlen((char*)user_data)); +} + +void yon_terminal_integrated_launch(GtkWidget *place_to_show, char* command, void *endwork_function, void* endwork_function_argument){ + GtkWidget *terminal = vte_terminal_new(); + config_str parsed=NULL; + int size=0; + g_shell_parse_argv(command, &size,&parsed, NULL); + vte_terminal_spawn_async(VTE_TERMINAL(terminal),VTE_PTY_NO_HELPER,NULL,parsed,NULL,G_SPAWN_SEARCH_PATH,NULL,NULL,NULL,2000,NULL,NULL,NULL); + vte_terminal_set_size(VTE_TERMINAL(terminal),10,15); + if(endwork_function) + g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument); + vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), -1); + vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE); + vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE); + gtk_widget_show_all(terminal); + } + +void yon_terminal_integrated_start(GtkWidget *terminal, char* command){ + gchar *envv[] = { NULL }; + config_str parsed=NULL; + int size=0; + g_shell_parse_argv(command, &size,&parsed, NULL); + vte_terminal_spawn_async(VTE_TERMINAL(terminal),VTE_PTY_NO_HELPER,"/bin",parsed,envv,G_SPAWN_SEARCH_PATH,NULL,NULL,NULL,20,NULL,NULL,NULL); + vte_terminal_set_size(VTE_TERMINAL(terminal),10,15); + vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), -1); + vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE); + vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE); + gtk_widget_show_all(terminal); + } + +void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument){ + char **commands=new_arr(char*,2); + gchar **envp = g_get_environ(); + commands[0]=(gchar *)g_strdup(g_environ_getenv(envp, "SHELL")); + commands[1]=NULL; + char **env=new_arr(char*,2); + env[0]=""; + env[1]=NULL; + vte_terminal_set_size(VTE_TERMINAL(terminal),10,15); + VtePty *pty = vte_pty_new_sync(VTE_PTY_DEFAULT,NULL,NULL); + vte_terminal_set_pty(VTE_TERMINAL(terminal),pty); + char *install_command=yon_char_unite("clear;tput cup 0 0 && tput ed && ",command," ; stty -echo; unset PS1;exit 0","\n",NULL); + if(endwork_function) + g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument); + vte_terminal_spawn_async(VTE_TERMINAL(terminal), + VTE_PTY_DEFAULT, + NULL, + commands, + NULL, + 0, + NULL, NULL, + NULL, + -1, + NULL, + child_ready, + install_command); + vte_pty_spawn_async(pty, + NULL, + commands, + NULL, + 0, + NULL, NULL, + NULL, + -1, + NULL, + NULL, + NULL); + vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), -1); + vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE); + vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE); + gtk_widget_show_all(terminal); + } + + + void __on_yon_terminal_done(GtkWidget *, int state, GtkWidget *status_box){ + if (state) yon_ubl_status_box_spawn_infinite(GTK_CONTAINER(status_box),"terminal_done","",BACKGROUND_IMAGE_SUCCESS_TYPE); + else yon_ubl_status_box_spawn_infinite(GTK_CONTAINER(status_box),"terminal_done","",BACKGROUND_IMAGE_FAIL_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); + gdouble lower = gtk_adjustment_get_lower(adjustment); + gdouble upper = gtk_adjustment_get_upper(adjustment); + switch (event->direction){ + case GDK_SCROLL_DOWN: + val+=2; + if (val>upper) val=upper; + break; + case GDK_SCROLL_UP: + val-=2; + if (valsection,param->parameter_name,NULL); + } + if (__yon_main_window_config.custom_listeners) + for_dictionaries(dict,__yon_main_window_config.custom_listeners){ + __yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*); + GValue *val = g_malloc0(sizeof(GValue)); + g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val); + switch(param->containing_type){ + case YON_TYPE_STRING: + g_key_file_set_string(__yon_window_config_file,"window",param->parameter_name, g_value_get_string(val)); + break; + case YON_TYPE_INT: + g_key_file_set_integer(__yon_window_config_file,"window",param->parameter_name, g_value_get_int(val)); + break; + case YON_TYPE_BOOLEAN: + g_key_file_set_boolean(__yon_window_config_file,"window",param->parameter_name, g_value_get_boolean(val)); + break; + case YON_TYPE_OTHER:printf("\033[0;31mCannot save %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break; + } + } + if (__yon_main_window_config.custom_parameters) + for_dictionaries(dict,__yon_main_window_config.custom_parameters){ + __yon_custom_parameter *param = yon_dictionary_get_data(dict,__yon_custom_parameter*); + switch (param->containing_type){ + case YON_TYPE_STRING: + g_key_file_set_string(__yon_window_config_file,param->section,param->parameter_name, (char*)param->property); + break; + case YON_TYPE_INT: + g_key_file_set_integer(__yon_window_config_file,param->section,param->parameter_name, *(int*)param->property); + break; + case YON_TYPE_BOOLEAN: + g_key_file_set_boolean(__yon_window_config_file,param->section,param->parameter_name, *(gboolean*)param->property); + break; + default: + break; + } + } + + g_key_file_save_to_file(__yon_window_config_file,__yon_window_config_path,NULL); + } else { + // g_warning("config file were not loaded properly"); + } + } + + void yon_get_is_fullscreen(){ + gtk_window_is_maximized(__yon_window_config_target_window); + __yon_main_window_config.fullscreen = gtk_window_is_maximized(__yon_window_config_target_window); + 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] + * + * [RU] + * Сохраняет настройки основного окна. Вызывается когда основное окно уничтожается. + */ + void yon_on_configured_window_destroy(GtkWidget* self,GdkEvent* event){ + check_window_config_setup{ + if (__yon_window_config_path){ + yon_get_is_fullscreen(); + yon_window_config_save(); + } + } else { + g_warning("config file were not loaded properly"); + } + gtk_main_quit(); + } + + void __yon_window_config_on_resize(){ + if (__yon_window_config_path){ + int max=0; + max=gtk_window_is_maximized(__yon_window_config_target_window); + if(max==0){ + gtk_window_get_size(__yon_window_config_target_window,&__yon_main_window_config.width,&__yon_main_window_config.height); + gtk_window_get_position(__yon_window_config_target_window,&__yon_main_window_config.x,&__yon_main_window_config.y); + } + } + } + + void yon_window_config_setup(GtkWindow *window){ + __yon_window_config_target_window = window; + g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(yon_on_configured_window_destroy),NULL); + g_signal_connect(G_OBJECT(window),"check-resize"/*"configure-event"*/,G_CALLBACK(__yon_window_config_on_resize),NULL); + } + + void _yon_maximize(void *data){ + g_usleep(G_USEC_PER_SEC/10); + if(__yon_main_window_config.fullscreen ==1) gtk_window_maximize(__yon_window_config_target_window); + } + + int yon_window_config_load(char *path){ + if(__yon_window_config_target_window){ + if (access(path,0)){ + yon_file_create_full_path(path,0644); + } + __yon_window_config_file = g_key_file_new(); + __yon_window_config_path=yon_char_new(path); + if (!g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL)){ + struct stat st; + int size; + g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL); + } + __yon_main_window_config.x = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosX",NULL); + __yon_main_window_config.y = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosY",NULL); + __yon_main_window_config.width = g_key_file_get_integer(__yon_window_config_file,"window","WindowWidth",NULL); + __yon_main_window_config.height = g_key_file_get_integer(__yon_window_config_file,"window","WindowHeight",NULL); + __yon_main_window_config.fullscreen = g_key_file_get_integer(__yon_window_config_file,"window","fullscreen",NULL); + dictionary *dict=NULL; + if (__yon_main_window_config.custom_listeners) + for_dictionaries(dict,__yon_main_window_config.custom_listeners){ + __yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*); + GValue *val = g_malloc0(sizeof(GValue)); + g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val); + switch(param->containing_type){ + case YON_TYPE_STRING: + g_value_set_string(val,g_key_file_get_string(__yon_window_config_file,"window",param->parameter_name, NULL)); + break; + case YON_TYPE_INT: + int output = g_key_file_get_integer(__yon_window_config_file,"window",param->parameter_name, NULL); + if (!output) output=-1; + g_value_set_int(val,output); + break; + case YON_TYPE_BOOLEAN: + gboolean res = g_key_file_get_boolean(__yon_window_config_file,"window",param->parameter_name, NULL); + g_value_set_boolean(val,res); + break; + default:printf("\033[0;31mCannot load %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break; + } + g_object_set_property(G_OBJECT(param->track_widget),param->property_name,val); + } + if (__yon_main_window_config.width==0) __yon_main_window_config.width=800; + if (__yon_main_window_config.height==0) __yon_main_window_config.height=600; + gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height); + gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y); + pthread_t tid; + pthread_create(&tid,NULL,(void *)_yon_maximize,NULL); + return 1; + } + return 0; + } + + void yon_window_config_apply(){ + dictionary *dict=NULL; + gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y); + gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height); + } + + config_str yon_window_config_get_section(char *section, gsize *size){ + config_str key = g_key_file_get_keys(__yon_window_config_file,section,size,NULL); + return key; + } + + void yon_window_config_add_listener(GtkWidget *widget, char *param_name, char *widget_property, enum YON_TYPE val_type){ + __yon_listener_parameter *param = NULL; + param = yon_remalloc(param,sizeof(__yon_listener_parameter)); + param->parameter_name = yon_char_new(param_name); + param->track_widget = widget; + param->property_name = yon_char_new(widget_property); + param->containing_type = val_type; + yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.custom_listeners,param->parameter_name,param); + } + + void yon_window_config_add_custom_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type){ + __yon_custom_parameter *param = NULL; + param = yon_remalloc(param,sizeof(__yon_custom_parameter)); + param->parameter_name = yon_char_new(param_name); + param->section=section; + param->property = tracked_value; + param->containing_type = val_type; + yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.custom_parameters,param->parameter_name,param); + dictionary *dict=NULL; + if (__yon_main_window_config.deleted_parameters) + for_dictionaries(dict,__yon_main_window_config.deleted_parameters){ + if (strcmp(dict->key,param->parameter_name)) + yon_dictionary_rip(dict); + } + } + + void yon_window_config_add_instant_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type){ + check_window_config_setup { + switch (val_type){ + case YON_TYPE_BOOLEAN: g_key_file_set_boolean(__yon_window_config_file,section,param_name,*((gboolean*)tracked_value)); + break; + case YON_TYPE_INT: g_key_file_set_integer(__yon_window_config_file,section,param_name,*((int*)tracked_value)); + break; + case YON_TYPE_STRING: g_key_file_set_string(__yon_window_config_file,section,param_name,(char*)tracked_value); + break; + } + } + } + + void yon_window_config_erase_custom_parameter(char *param_name, char *section){ + __yon_custom_parameter *param = NULL; + param = yon_remalloc(param,sizeof(__yon_custom_parameter)); + param->parameter_name=param_name; + 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){ + check_window_config_setup{ + GError *err=NULL; + switch (type){ + case YON_TYPE_BOOLEAN: + *((int*)return_value) = g_key_file_get_boolean(__yon_window_config_file,section,config_parameter,&err); + if (err) return 0; else return 1; + break; + case YON_TYPE_INT: + *((int*)return_value) = g_key_file_get_integer(__yon_window_config_file,section,config_parameter,&err); + if (err) return 0; else return 1; + break; + case YON_TYPE_STRING: + *((char**)return_value) = g_key_file_get_string(__yon_window_config_file,section,config_parameter,&err); + if (err) return 0; else return 1; + break; + case YON_TYPE_STRING_LIST: + gsize size=0; + *((char***)return_value) = g_key_file_get_string_list(__yon_window_config_file,section,config_parameter,&size,&err); + *((char***)return_value)=yon_remalloc(return_value,size+1); + *((char***)return_value)[size]=NULL; + if (err) return 0; else return 1; + break; + } + } + return 0; + } + + void yon_on_window_config_custom_window_destroy(GtkWindow *window, GdkEvent* event, char *window_name){ + if (!gtk_window_is_maximized(window)){ + int height=0; + int width=0; + int X=0; + int Y=0; + gtk_window_get_position(window,&X,&Y); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosX"),"window",&X,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosY"),"window",&Y,YON_TYPE_INT); + + } + } + + void yon_on_window_config_custom_window_resize(GtkWindow *window, char *window_name){ + if (!gtk_window_is_maximized(window)){ + int height=0; + int width=0; + int X=0; + int Y=0; + gtk_window_get_size(window,&width,&height); + gtk_window_get_position(window,&X,&Y); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"Width"),"window",&width,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"Height"),"window",&height,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosX"),"window",&X,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosY"),"window",&Y,YON_TYPE_INT); + } + + } + + void yon_window_config_custom_window_setup(GtkWindow *window, char *window_name){ + int height=0; + int width=0; + int X=0; + int Y=0; + yon_window_config_get_parameter("window",yon_char_append(window_name,"Width"),&width,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"Height"),&height,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"PosX"),&X,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"PosY"),&Y,YON_TYPE_INT); + if (width&&height) + gtk_window_resize(window,width,height); + if (X&&Y) + gtk_window_move(window,X,Y); + char *signals_window_name = yon_char_new(window_name); + g_signal_connect(G_OBJECT(window),"check-resize",G_CALLBACK(yon_on_window_config_custom_window_resize),signals_window_name); + g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(yon_on_window_config_custom_window_destroy),signals_window_name); + } + + void yon_window_config_custom_window_get(GtkWindow *window, char *window_name){ + int height=0; + int width=0; + int X=0; + int Y=0; + yon_window_config_get_parameter("window",yon_char_append(window_name,"Width"),&width,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"Height"),&height,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"PosX"),&X,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"PosY"),&Y,YON_TYPE_INT); + if (width&&height) + gtk_window_resize(window,width,height); + if (X&&Y) + gtk_window_move(window,X,Y); + } + + void yon_window_config_custom_window_set(GtkWindow *window, char *window_name){ + int height=0; + int width=0; + int X=0; + int Y=0; + gtk_window_get_size(window,&width,&height); + gtk_window_get_position(window,&X,&Y); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"Width"),"window",&width,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"Height"),"window",&height,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosX"),"window",&X,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosY"),"window",&Y,YON_TYPE_INT); + } \ No newline at end of file diff --git a/source/libublsettings-gtk3.c b/source/libublsettings-gtk3.c index 45c1551..64cc185 100644 --- a/source/libublsettings-gtk3.c +++ b/source/libublsettings-gtk3.c @@ -2,1250 +2,6 @@ #ifdef __GTK_H__ - -static render_data render; - -// vte section - -static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data) -{ - if (!terminal) return; - if (pid == -1) printf("Error\n\n\n"); - else vte_terminal_feed_child(VTE_TERMINAL(terminal),(char*)user_data,strlen((char*)user_data)); -} - -void yon_terminal_integrated_launch(GtkWidget *place_to_show, char* command, void *endwork_function, void* endwork_function_argument){ - GtkWidget *terminal = vte_terminal_new(); - config_str parsed=NULL; - int size=0; - g_shell_parse_argv(command, &size,&parsed, NULL); - vte_terminal_spawn_async(VTE_TERMINAL(terminal),VTE_PTY_NO_HELPER,NULL,parsed,NULL,G_SPAWN_SEARCH_PATH,NULL,NULL,NULL,2000,NULL,NULL,NULL); - vte_terminal_set_size(VTE_TERMINAL(terminal),10,15); - if(endwork_function) - g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument); - vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), -1); - vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE); - vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE); - gtk_widget_show_all(terminal); - } - -void yon_terminal_integrated_start(GtkWidget *terminal, char* command){ - gchar *envv[] = { NULL }; - config_str parsed=NULL; - int size=0; - g_shell_parse_argv(command, &size,&parsed, NULL); - vte_terminal_spawn_async(VTE_TERMINAL(terminal),VTE_PTY_NO_HELPER,"/bin",parsed,envv,G_SPAWN_SEARCH_PATH,NULL,NULL,NULL,20,NULL,NULL,NULL); - vte_terminal_set_size(VTE_TERMINAL(terminal),10,15); - vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), -1); - vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE); - vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE); - gtk_widget_show_all(terminal); - } - -void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument){ - char **commands=new_arr(char*,2); - gchar **envp = g_get_environ(); - commands[0]=(gchar *)g_strdup(g_environ_getenv(envp, "SHELL")); - commands[1]=NULL; - char **env=new_arr(char*,2); - env[0]=""; - env[1]=NULL; - vte_terminal_set_size(VTE_TERMINAL(terminal),10,15); - VtePty *pty = vte_pty_new_sync(VTE_PTY_DEFAULT,NULL,NULL); - vte_terminal_set_pty(VTE_TERMINAL(terminal),pty); - char *install_command=yon_char_unite("clear;tput cup 0 0 && tput ed && ",command," ; stty -echo; unset PS1;exit 0","\n",NULL); - if(endwork_function) - g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument); - vte_terminal_spawn_async(VTE_TERMINAL(terminal), - VTE_PTY_DEFAULT, - NULL, - commands, - NULL, - 0, - NULL, NULL, - NULL, - -1, - NULL, - child_ready, - install_command); - vte_pty_spawn_async(pty, - NULL, - commands, - NULL, - 0, - NULL, NULL, - NULL, - -1, - NULL, - NULL, - NULL); - vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), -1); - vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE); - vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE); - gtk_widget_show_all(terminal); - } - - - void __on_yon_terminal_done(GtkWidget *, int state, GtkWidget *status_box){ - if (state) yon_ubl_status_box_spawn_infinite(GTK_CONTAINER(status_box),"terminal_done","",BACKGROUND_IMAGE_SUCCESS_TYPE); - else yon_ubl_status_box_spawn_infinite(GTK_CONTAINER(status_box),"terminal_done","",BACKGROUND_IMAGE_FAIL_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); - gdouble lower = gtk_adjustment_get_lower(adjustment); - gdouble upper = gtk_adjustment_get_upper(adjustment); - switch (event->direction){ - case GDK_SCROLL_DOWN: - val+=2; - if (val>upper) val=upper; - break; - case GDK_SCROLL_UP: - val-=2; - if (valsection,param->parameter_name,NULL); - } - if (__yon_main_window_config.custom_listeners) - for_dictionaries(dict,__yon_main_window_config.custom_listeners){ - __yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*); - GValue *val = g_malloc0(sizeof(GValue)); - g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val); - switch(param->containing_type){ - case YON_TYPE_STRING: - g_key_file_set_string(__yon_window_config_file,"window",param->parameter_name, g_value_get_string(val)); - break; - case YON_TYPE_INT: - g_key_file_set_integer(__yon_window_config_file,"window",param->parameter_name, g_value_get_int(val)); - break; - case YON_TYPE_BOOLEAN: - g_key_file_set_boolean(__yon_window_config_file,"window",param->parameter_name, g_value_get_boolean(val)); - break; - case YON_TYPE_OTHER:printf("\033[0;31mCannot save %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break; - } - } - if (__yon_main_window_config.custom_parameters) - for_dictionaries(dict,__yon_main_window_config.custom_parameters){ - __yon_custom_parameter *param = yon_dictionary_get_data(dict,__yon_custom_parameter*); - switch (param->containing_type){ - case YON_TYPE_STRING: - g_key_file_set_string(__yon_window_config_file,param->section,param->parameter_name, (char*)param->property); - break; - case YON_TYPE_INT: - g_key_file_set_integer(__yon_window_config_file,param->section,param->parameter_name, *(int*)param->property); - break; - case YON_TYPE_BOOLEAN: - g_key_file_set_boolean(__yon_window_config_file,param->section,param->parameter_name, *(gboolean*)param->property); - break; - default: - break; - } - } - - g_key_file_save_to_file(__yon_window_config_file,__yon_window_config_path,NULL); - } else { - // g_warning("config file were not loaded properly"); - } - } - - void yon_get_is_fullscreen(){ - gtk_window_is_maximized(__yon_window_config_target_window); - __yon_main_window_config.fullscreen = gtk_window_is_maximized(__yon_window_config_target_window); - 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] - * - * [RU] - * Сохраняет настройки основного окна. Вызывается когда основное окно уничтожается. - */ - void yon_on_configured_window_destroy(GtkWidget* self,GdkEvent* event){ - check_window_config_setup{ - if (__yon_window_config_path){ - yon_get_is_fullscreen(); - yon_window_config_save(); - } - } else { - g_warning("config file were not loaded properly"); - } - gtk_main_quit(); - } - - void __yon_window_config_on_resize(){ - if (__yon_window_config_path){ - int max=0; - max=gtk_window_is_maximized(__yon_window_config_target_window); - if(max==0){ - gtk_window_get_size(__yon_window_config_target_window,&__yon_main_window_config.width,&__yon_main_window_config.height); - gtk_window_get_position(__yon_window_config_target_window,&__yon_main_window_config.x,&__yon_main_window_config.y); - } - } - } - - void yon_window_config_setup(GtkWindow *window){ - __yon_window_config_target_window = window; - g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(yon_on_configured_window_destroy),NULL); - g_signal_connect(G_OBJECT(window),"check-resize"/*"configure-event"*/,G_CALLBACK(__yon_window_config_on_resize),NULL); - } - - void _yon_maximize(void *data){ - g_usleep(G_USEC_PER_SEC/10); - if(__yon_main_window_config.fullscreen ==1) gtk_window_maximize(__yon_window_config_target_window); - } - - int yon_window_config_load(char *path){ - if(__yon_window_config_target_window){ - if (access(path,0)){ - yon_file_create_full_path(path,0644); - } - __yon_window_config_file = g_key_file_new(); - __yon_window_config_path=yon_char_new(path); - if (!g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL)){ - struct stat st; - int size; - g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL); - } - __yon_main_window_config.x = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosX",NULL); - __yon_main_window_config.y = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosY",NULL); - __yon_main_window_config.width = g_key_file_get_integer(__yon_window_config_file,"window","WindowWidth",NULL); - __yon_main_window_config.height = g_key_file_get_integer(__yon_window_config_file,"window","WindowHeight",NULL); - __yon_main_window_config.fullscreen = g_key_file_get_integer(__yon_window_config_file,"window","fullscreen",NULL); - dictionary *dict=NULL; - if (__yon_main_window_config.custom_listeners) - for_dictionaries(dict,__yon_main_window_config.custom_listeners){ - __yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*); - GValue *val = g_malloc0(sizeof(GValue)); - g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val); - switch(param->containing_type){ - case YON_TYPE_STRING: - g_value_set_string(val,g_key_file_get_string(__yon_window_config_file,"window",param->parameter_name, NULL)); - break; - case YON_TYPE_INT: - int output = g_key_file_get_integer(__yon_window_config_file,"window",param->parameter_name, NULL); - if (!output) output=-1; - g_value_set_int(val,output); - break; - case YON_TYPE_BOOLEAN: - gboolean res = g_key_file_get_boolean(__yon_window_config_file,"window",param->parameter_name, NULL); - g_value_set_boolean(val,res); - break; - default:printf("\033[0;31mCannot load %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break; - } - g_object_set_property(G_OBJECT(param->track_widget),param->property_name,val); - } - if (__yon_main_window_config.width==0) __yon_main_window_config.width=800; - if (__yon_main_window_config.height==0) __yon_main_window_config.height=600; - gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height); - gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y); - pthread_t tid; - pthread_create(&tid,NULL,(void *)_yon_maximize,NULL); - return 1; - } - return 0; - } - - void yon_window_config_apply(){ - dictionary *dict=NULL; - gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y); - gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height); - } - - config_str yon_window_config_get_section(char *section, gsize *size){ - config_str key = g_key_file_get_keys(__yon_window_config_file,section,size,NULL); - return key; - } - - void yon_window_config_add_listener(GtkWidget *widget, char *param_name, char *widget_property, enum YON_TYPE val_type){ - __yon_listener_parameter *param = NULL; - param = yon_remalloc(param,sizeof(__yon_listener_parameter)); - param->parameter_name = yon_char_new(param_name); - param->track_widget = widget; - param->property_name = yon_char_new(widget_property); - param->containing_type = val_type; - yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.custom_listeners,param->parameter_name,param); - } - - void yon_window_config_add_custom_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type){ - __yon_custom_parameter *param = NULL; - param = yon_remalloc(param,sizeof(__yon_custom_parameter)); - param->parameter_name = yon_char_new(param_name); - param->section=section; - param->property = tracked_value; - param->containing_type = val_type; - yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.custom_parameters,param->parameter_name,param); - dictionary *dict=NULL; - if (__yon_main_window_config.deleted_parameters) - for_dictionaries(dict,__yon_main_window_config.deleted_parameters){ - if (strcmp(dict->key,param->parameter_name)) - yon_dictionary_rip(dict); - } - } - - void yon_window_config_add_instant_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type){ - check_window_config_setup { - switch (val_type){ - case YON_TYPE_BOOLEAN: g_key_file_set_boolean(__yon_window_config_file,section,param_name,*((gboolean*)tracked_value)); - break; - case YON_TYPE_INT: g_key_file_set_integer(__yon_window_config_file,section,param_name,*((int*)tracked_value)); - break; - case YON_TYPE_STRING: g_key_file_set_string(__yon_window_config_file,section,param_name,(char*)tracked_value); - break; - } - } - } - - void yon_window_config_erase_custom_parameter(char *param_name, char *section){ - __yon_custom_parameter *param = NULL; - param = yon_remalloc(param,sizeof(__yon_custom_parameter)); - param->parameter_name=param_name; - 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){ - check_window_config_setup{ - GError *err=NULL; - switch (type){ - case YON_TYPE_BOOLEAN: - *((int*)return_value) = g_key_file_get_boolean(__yon_window_config_file,section,config_parameter,&err); - if (err) return 0; else return 1; - break; - case YON_TYPE_INT: - *((int*)return_value) = g_key_file_get_integer(__yon_window_config_file,section,config_parameter,&err); - if (err) return 0; else return 1; - break; - case YON_TYPE_STRING: - *((char**)return_value) = g_key_file_get_string(__yon_window_config_file,section,config_parameter,&err); - if (err) return 0; else return 1; - break; - case YON_TYPE_STRING_LIST: - gsize size=0; - *((char***)return_value) = g_key_file_get_string_list(__yon_window_config_file,section,config_parameter,&size,&err); - *((char***)return_value)=yon_remalloc(return_value,size+1); - *((char***)return_value)[size]=NULL; - if (err) return 0; else return 1; - break; - } - } - return 0; - } - - void yon_on_window_config_custom_window_destroy(GtkWindow *window, GdkEvent* event, char *window_name){ - if (!gtk_window_is_maximized(window)){ - int height=0; - int width=0; - int X=0; - int Y=0; - gtk_window_get_position(window,&X,&Y); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosX"),"window",&X,YON_TYPE_INT); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosY"),"window",&Y,YON_TYPE_INT); - - } - } - - void yon_on_window_config_custom_window_resize(GtkWindow *window, char *window_name){ - if (!gtk_window_is_maximized(window)){ - int height=0; - int width=0; - int X=0; - int Y=0; - gtk_window_get_size(window,&width,&height); - gtk_window_get_position(window,&X,&Y); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"Width"),"window",&width,YON_TYPE_INT); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"Height"),"window",&height,YON_TYPE_INT); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosX"),"window",&X,YON_TYPE_INT); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosY"),"window",&Y,YON_TYPE_INT); - } - - } - - void yon_window_config_custom_window_setup(GtkWindow *window, char *window_name){ - int height=0; - int width=0; - int X=0; - int Y=0; - yon_window_config_get_parameter("window",yon_char_append(window_name,"Width"),&width,YON_TYPE_INT); - yon_window_config_get_parameter("window",yon_char_append(window_name,"Height"),&height,YON_TYPE_INT); - yon_window_config_get_parameter("window",yon_char_append(window_name,"PosX"),&X,YON_TYPE_INT); - yon_window_config_get_parameter("window",yon_char_append(window_name,"PosY"),&Y,YON_TYPE_INT); - if (width&&height) - gtk_window_resize(window,width,height); - if (X&&Y) - gtk_window_move(window,X,Y); - char *signals_window_name = yon_char_new(window_name); - g_signal_connect(G_OBJECT(window),"check-resize",G_CALLBACK(yon_on_window_config_custom_window_resize),signals_window_name); - g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(yon_on_window_config_custom_window_destroy),signals_window_name); - } - - void yon_window_config_custom_window_get(GtkWindow *window, char *window_name){ - int height=0; - int width=0; - int X=0; - int Y=0; - yon_window_config_get_parameter("window",yon_char_append(window_name,"Width"),&width,YON_TYPE_INT); - yon_window_config_get_parameter("window",yon_char_append(window_name,"Height"),&height,YON_TYPE_INT); - yon_window_config_get_parameter("window",yon_char_append(window_name,"PosX"),&X,YON_TYPE_INT); - yon_window_config_get_parameter("window",yon_char_append(window_name,"PosY"),&Y,YON_TYPE_INT); - if (width&&height) - gtk_window_resize(window,width,height); - if (X&&Y) - gtk_window_move(window,X,Y); - } - - void yon_window_config_custom_window_set(GtkWindow *window, char *window_name){ - int height=0; - int width=0; - int X=0; - int Y=0; - gtk_window_get_size(window,&width,&height); - gtk_window_get_position(window,&X,&Y); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"Width"),"window",&width,YON_TYPE_INT); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"Height"),"window",&height,YON_TYPE_INT); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosX"),"window",&X,YON_TYPE_INT); - yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosY"),"window",&Y,YON_TYPE_INT); - } - -// gtk misc section - -void on_subwindow_close(GtkWidget *self){ - gtk_widget_destroy(gtk_widget_get_toplevel(self)); -} - -int yon_gtk_window_setup(GtkWindow *window, GtkWindow *transistent_window, char *title, char *icon_name, char *window_id){ - if (GTK_IS_WINDOW(window)){ - int success=0; - if (transistent_window){ - gtk_window_set_transient_for(window,transistent_window); - success++; - } - if (!yon_char_is_empty(title)){ - gtk_window_set_title(window,title); - success++; - } - if (!yon_char_is_empty(icon_name)){ - gtk_window_set_icon_name(window,icon_name); - success++; - } - if (!yon_char_is_empty(window_id)){ - yon_window_config_custom_window_setup(window,window_id); - success++; - } - return success; - } else { - return 0; - } -} - -GtkWidget *yon_ubl_menu_item_about_new(char *buttonname){ - GtkWidget *menu_item = gtk_menu_item_new(); - gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitembottom"); - GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); - GtkWidget *label = gtk_label_new(buttonname); - GtkWidget *image = gtk_image_new_from_icon_name("dialog-information-symbolic",GTK_ICON_SIZE_BUTTON); - gtk_label_set_xalign(GTK_LABEL(label),0.0); - gtk_box_pack_start(GTK_BOX(box),image,0,0,5); - gtk_box_pack_start(GTK_BOX(box),label,0,0,5); - gtk_container_add(GTK_CONTAINER(menu_item),box); - gtk_widget_show_all(menu_item); - return menu_item; -} - -GtkWidget *yon_ubl_menu_item_documentation_new(char *buttonname){ - GtkWidget *menu_item = gtk_menu_item_new(); - gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitemtop"); - GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); - GtkWidget *label = gtk_label_new(buttonname); - GtkWidget *image = gtk_image_new_from_icon_name("dialog-question-symbolic",GTK_ICON_SIZE_BUTTON); - gtk_label_set_xalign(GTK_LABEL(label),0.0); - gtk_box_pack_start(GTK_BOX(box),image,0,0,5); - gtk_box_pack_start(GTK_BOX(box),label,0,0,5); - gtk_container_add(GTK_CONTAINER(menu_item),box); - gtk_widget_show_all(menu_item); - return menu_item; -} - -int yon_gtk_combo_box_fill(GtkWidget *combo, config_str parameters,int size){ - if (combo&¶meters){ - for (int i=0;icolumn&&resizing_columns>connect_to){ - char *name="1"; - name[0]=connect_to+1; - dictionary *cur = NULL; - if (!(cur =yon_dictionary_get(&dict,name))){ - int *width = malloc(sizeof(int)); - (*width)=gtk_tree_view_column_get_width(gtk_tree_view_get_column(top,column)); - yon_dictionary_append_with_data(dict,name,width); - } else { - *(int*)cur->data+=gtk_tree_view_column_get_width(gtk_tree_view_get_column(top,column)); - } - } - } - dictionary *cur; - for_dictionaries(cur,dict){ - int cur_column = cur->key[0]-1; - gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column(resizing,cur_column),*(int*)dict->data); - free(dict->data); - } - va_end(arglist); -} - -int yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...){ - va_list args; - va_start(args,padding); - GtkWidget *widget = va_arg(args,GtkWidget*); - while (widget){ - gtk_box_pack_start(GTK_BOX(destination), widget, expand, fill, padding); - } - va_end(args); - return 1; -} - -int yon_dictionary_gtk_pack_end_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...){ - va_list args; - va_start(args,padding); - GtkWidget *widget = va_arg(args,GtkWidget*); - while (widget){ - gtk_box_pack_end(GTK_BOX(destination), widget, expand, fill, padding); - } - va_end(args); - return 1; -} - -int yon_gtk_list_store_find_text(GtkListStore *list, GtkTreeIter *iter, int seek_column, char *value){ - int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list),iter); - for (;valid;valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(list),iter)){ - char *seek_value; - gtk_tree_model_get(GTK_TREE_MODEL(list),iter,seek_column,&seek_value,-1); - if (!strcmp(value,seek_value)){ - free(seek_value); - return 1; - } - free(seek_value); - } - return 0; -} -void yon_on_cell_renderer_toggle_toggled_for_list_store(GtkWidget *self, gchar *path,GtkWidget *tree){ - GtkTreePath *path_converted = gtk_tree_path_new_from_string(path); - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree)); - GtkTreeIter iter; - gtk_tree_model_get_iter(model,&iter,path_converted); - int last = yon_char_find_last(path,':'); - char *col = path+last+1; - int status; - gtk_tree_model_get(model,&iter,atoi(col),&status,-1); - gtk_list_store_set(GTK_LIST_STORE(model),&iter,atoi(col),!status,-1); -} - -void yon_cell_renderer_toggle_set_toggle(GtkCellRendererToggle *target,GtkWidget *tree){ - g_return_if_fail(GTK_IS_CELL_RENDERER_TOGGLE(target)); - g_signal_connect(G_OBJECT(target),"toggled",G_CALLBACK(yon_on_cell_renderer_toggle_toggled_for_list_store),tree); -} - -void yon_gtk_toggle_button_set_inactive_from_toggle(GtkToggleButton *self, GtkToggleButton *target){ - if (gtk_toggle_button_get_active(self)){ - gtk_toggle_button_set_active(target,1); - } else { - gtk_toggle_button_set_active(target,0); - } -} - -void yon_gtk_toggle_button_set_inactive_from_entry(GtkEntry *self, GtkToggleButton *target){ - if (strlen(gtk_entry_get_text(self))>0){ - gtk_toggle_button_set_active(target,1); - } else { - gtk_toggle_button_set_active(target,0); - } -} - -void yon_gtk_toggle_button_set_inactive_from_combo_box(GtkComboBox *self, GtkToggleButton *target){ - if (gtk_combo_box_get_active(self)>0){ - gtk_toggle_button_set_active(target,1); - } else { - gtk_toggle_button_set_active(target,0); - } -} - -void yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target){ - gtk_widget_set_sensitive(target,gtk_toggle_button_get_active(toggle)); -} - -void yon_gtk_widget_set_sensitive_from_toggle_button_inversed(GtkToggleButton *toggle, GtkWidget *target){ - gtk_widget_set_sensitive(target,!gtk_toggle_button_get_active(toggle)); - -} - -void yon_gtk_widget_set_sensitive_from_combo_box(GtkComboBox *toggle, GtkWidget *target){ - gtk_widget_set_sensitive(target,gtk_combo_box_get_active(toggle)>0 ? 1 : 0); -} - -void yon_gtk_widget_set_sensitive_from_combo_box_inversed(GtkComboBox *toggle, GtkWidget *target){ - gtk_widget_set_sensitive(target,!gtk_combo_box_get_active(toggle)>0 ? 0 : 1); -} - -void yon_gtk_toggle_button_set_inactive_from_toggle_button_inversed(GtkToggleButton *self, GtkToggleButton *target){ - if (gtk_toggle_button_get_active(self)){ - gtk_toggle_button_set_active(target,0); - } -} - -void yon_gtk_toggle_button_set_inactive_from_toggle_button(GtkToggleButton *self, GtkToggleButton *target){ - if (!gtk_toggle_button_get_active(self)){ - gtk_toggle_button_set_active(target,0); - } -} - -// status section -void _yon_ubl_header_setup(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path) -{ - gtk_overlay_add_overlay(GTK_OVERLAY(Overlay), Head); - gtk_image_set_from_file(GTK_IMAGE(Image), image_path); -} - -void _yon_ubl_header_setup_resource(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path) -{ - gtk_overlay_add_overlay(GTK_OVERLAY(Overlay), Head); - gtk_image_set_from_resource(GTK_IMAGE(Image), image_path); -} - -int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label) -{ - if(icon&&box&&label){ - render.icon=icon; - render.box=box; - render.label=label; - return 1; - } else return 0; -} - -void yon_ubl_status_box_set(BACKGROUND_IMAGE_TYPE type, GtkWidget *box, GtkImage *icon){ - - GtkIconTheme *ictheme = gtk_icon_theme_get_default(); - switch (type){ - case BACKGROUND_IMAGE_SUCCESS_TYPE: - { - gtk_style_context_remove_class(gtk_widget_get_style_context(box), "boxInfoMessError"); - gtk_style_context_add_class(gtk_widget_get_style_context(box), "boxInfoMessOK"); - gtk_image_set_from_pixbuf(GTK_IMAGE(icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.libublsettingsui-gtk3.checked", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, NULL)); - } - break; - case BACKGROUND_IMAGE_FAIL_TYPE: - { - gtk_style_context_remove_class(gtk_widget_get_style_context(box), "boxInfoMessOK"); - gtk_style_context_add_class(gtk_widget_get_style_context(box), "boxInfoMessError"); - gtk_image_set_from_pixbuf(GTK_IMAGE(icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.libublsettingsui-gtk3.warning", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, NULL)); - } - break; - case BACKGROUND_IMAGE_INFO_TYPE: - { - gtk_style_context_remove_class(gtk_widget_get_style_context(box), "boxInfoMessError"); - gtk_style_context_add_class(gtk_widget_get_style_context(box), "boxInfoMessOK"); - gtk_image_set_from_pixbuf(GTK_IMAGE(icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.libublsettingsui-gtk3.important", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, NULL)); - } - break; - } -} - -void _yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type) -{ - render_data data = render; - yon_ubl_status_box_set(type,data.box,GTK_IMAGE(data.icon)); - if (text) - gtk_label_set_text(GTK_LABEL(data.label), text); -} - -void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type){ - _yon_ubl_status_box_render(text,type); -} - -void _yon_ubl_status_highlight_incorrect(GtkWidget *widget){ - gtk_style_context_add_class(gtk_widget_get_style_context(widget),"errorBox"); - sleep(5); - gtk_style_context_remove_class(gtk_widget_get_style_context(widget),"errorBox"); -} - -void yon_ubl_status_highlight_incorrect(GtkWidget *widget){ - GThread *thread = g_thread_new(NULL,(GThreadFunc)_yon_ubl_status_highlight_incorrect,widget); -} - -void _yon_ubl_status_list_store_highlight_incorrect(GtkWidget **widget_pack){ - GtkListStore *list = (GtkListStore*)widget_pack[0]; - GtkTreeIter *iter = (GtkTreeIter*)widget_pack[1]; - GdkRGBA rgba,rgba2; - rgba.alpha=1; - rgba.blue=153.0/255.0; - rgba.green=153.0/255.0; - rgba.red=234.0/255.0; - rgba2.alpha=1; - rgba2.blue=0; - rgba2.green=0; - rgba2.red=0; - gtk_list_store_set(list,iter,1,gdk_rgba_to_string(&rgba2),2,gdk_rgba_to_string(&rgba),-1); - sleep(5); - gtk_list_store_set(list,iter,1,NULL,2,NULL,-1); -} - -void yon_ubl_status_list_store_highlight_incorrect(GtkListStore *list, GtkTreeIter *iter){ - GtkWidget **pack = malloc(sizeof(GtkWidget *)*2); - pack[0]=(GtkWidget*)list; - pack[1]=(GtkWidget*)iter; - GThread *thread = g_thread_new(NULL,(GThreadFunc)_yon_ubl_status_list_store_highlight_incorrect,pack); -} - -struct temp_statusbox { - int times; - GtkWidget *revealer; - }; - -static char *yon_status_thread_id=NULL; - -void _yon_ubl_status_box_timed_remove(struct temp_statusbox *statusstruct){ - sleep(statusstruct->times); - if (statusstruct->revealer){ - gtk_revealer_set_reveal_child(GTK_REVEALER(statusstruct->revealer),0); - sleep(1); - gtk_widget_destroy(statusstruct->revealer); - - } -} - -void __yon_ubl_status_box_destroyed(GtkWidget *self,struct temp_statusbox *statusstruct){ - statusstruct->revealer=NULL; -} - -void yon_status_box_destroyed(){ - if (yon_status_thread_id){ - free(yon_status_thread_id); - yon_status_thread_id=NULL; - } -} - -int yon_ubl_status_box_spawn_infinite(GtkContainer *container, char *status_id, char *display_text, BACKGROUND_IMAGE_TYPE type){ - if (!gtk_container_get_children(container)){ - if (yon_status_thread_id){ - if (!strcmp(yon_status_thread_id,status_id)){ - return 0; - } - free(yon_status_thread_id); - yon_status_thread_id=NULL; - GList *list = gtk_container_get_children(container); - for (int i=0;irevealer = revealer; - } -} - -int delete_busy=0; -int _yon_ubl_status_box_despawn_infinite(GtkContainer *container){ - if (!delete_busy){ - delete_busy=1; - if (yon_status_thread_id){ - free(yon_status_thread_id); - yon_status_thread_id=NULL; - } - GList *list = gtk_container_get_children(container); - for (int i=0; i0){ - if (GTK_IS_REVEALER(revealer)){ - gtk_widget_destroy(revealer); - } - } - } - } - delete_busy=0; - } -} - -int yon_ubl_status_box_despawn_infinite(GtkContainer *container){ - GThread *thread = g_thread_new("StatusThread",(GThreadFunc)_yon_ubl_status_box_despawn_infinite,container); -} - -void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int timeout,BACKGROUND_IMAGE_TYPE type){ - 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(""); - GtkWidget *icon = gtk_image_new(); - gtk_label_set_line_wrap(GTK_LABEL(label),1); - gtk_label_set_line_wrap_mode(GTK_LABEL(label),PANGO_WRAP_WORD); - gtk_container_add(GTK_CONTAINER(revealer),box); - gtk_box_pack_start(GTK_BOX(box),icon,0,0,5); - gtk_box_pack_start(GTK_BOX(box),label,0,0,5); - gtk_container_add(container,revealer); - - gtk_widget_show_all(revealer); - gtk_revealer_set_reveal_child(GTK_REVEALER(revealer),1); - - gtk_widget_set_margin_bottom(label,9); - gtk_widget_set_margin_top(label,9); - gtk_label_set_xalign(GTK_LABEL(label),0.0); - PangoAttrList *attributes = pango_attr_list_new(); - PangoAttribute *boldAttr = pango_attr_weight_new(PANGO_WEIGHT_BOLD); - pango_attr_list_insert(attributes, boldAttr); - gtk_label_set_attributes(GTK_LABEL(label),attributes); - - GdkRGBA textColor; - gdk_rgba_parse(&textColor, "#4d4d4d4d4d4d"); - PangoAttribute *colorAttr = pango_attr_foreground_new( - (int)(textColor.red * 65535), - (int)(textColor.green * 65535), - (int)(textColor.blue * 65535) - ); - pango_attr_list_insert(attributes, colorAttr); - - yon_ubl_status_box_set(type,box,GTK_IMAGE(icon)); - if (display_text) - gtk_label_set_text(GTK_LABEL(label),display_text); - 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); - } -} - -// socket section -void yon_ubl_setup_sockets(GtkWidget *main_window, GtkWidget *left_window, GtkWidget *right_window, int socket_main_id, int socket_left_id, int socket_right_id){ - if (main_window&&socket_main_id>-1){ - gtk_widget_hide(gtk_widget_get_toplevel(main_window)); - GtkWidget *plug_main=gtk_plug_new(socket_main_id); - GtkWidget *plug_left=NULL; - GtkWidget *plug_right=NULL; - GtkWidget *box=NULL; - g_signal_connect(G_OBJECT(plug_main), "destroy", G_CALLBACK(gtk_main_quit),NULL); - if (socket_left_id>-1&&left_window){ - plug_left=gtk_plug_new(socket_left_id); - g_object_ref(left_window); - gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(left_window)),left_window); - gtk_container_add(GTK_CONTAINER(plug_left),left_window); - gtk_style_context_add_class(gtk_widget_get_style_context(plug_left),"primary-toolbar"); - gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"button"); - gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"opacited"); - gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"color"); - gtk_style_context_add_class(gtk_widget_get_style_context(plug_left),"noborder"); - gtk_widget_show(plug_left); - } - else if (left_window){ - if (box==NULL){ - box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); - gtk_box_pack_start(GTK_BOX(main_window),box,0,0,5); - gtk_box_reorder_child(GTK_BOX(main_window),box,0); - gtk_widget_show(box); - } - gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"inherited"); - gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(left_window)),left_window); - gtk_box_pack_start(GTK_BOX(box),left_window,0,0,5); - } - if (socket_right_id>-1&&right_window){ - plug_right=gtk_plug_new(socket_right_id); - g_object_ref(right_window); - gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(right_window)),right_window); - gtk_container_add(GTK_CONTAINER(plug_right),right_window); - gtk_style_context_add_class(gtk_widget_get_style_context(plug_right),"primary-toolbar"); - gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"button"); - gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"opacited"); - gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"color"); - gtk_style_context_add_class(gtk_widget_get_style_context(plug_right),"noborder"); - gtk_widget_show(plug_right); - } - else if (right_window){ - if (box==NULL){ - box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); - gtk_box_pack_start(GTK_BOX(main_window),box,0,0,5); - gtk_box_reorder_child(GTK_BOX(main_window),box,0); - gtk_widget_show(box); - } - gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"inherited"); - gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(right_window)),right_window); - gtk_box_pack_end(GTK_BOX(box),right_window,0,0,5); - } - g_object_ref(main_window); - gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(main_window)),main_window); - gtk_container_add(GTK_CONTAINER(plug_main),main_window); - gtk_widget_show(plug_main); - } -} - -// webkit section -#ifdef WEBKIT_INCLUDE - -GtkWidget *yon_ubl_browser_window_open(char *link, char *browser_window_name){ - GtkWidget *browser=gtk_window_new(GTK_WINDOW_TOPLEVEL); - GtkWidget *web_place=gtk_box_new(GTK_ORIENTATION_VERTICAL,0); - GtkWidget *header=gtk_header_bar_new(); - GtkWidget *header_label=gtk_label_new(browser_window_name); - GtkWidget *WebView=webkit_web_view_new(); - gtk_container_add(GTK_CONTAINER(browser),web_place); - gtk_window_set_titlebar(GTK_WINDOW(browser),header); - gtk_window_set_title(GTK_WINDOW(browser),browser_window_name); - gtk_widget_set_size_request(browser,800,600); - gtk_header_bar_set_custom_title(GTK_HEADER_BAR(header),header_label); - gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header),1); - webkit_web_view_load_uri(WEBKIT_WEB_VIEW(WebView),link); - gtk_box_pack_start(GTK_BOX(web_place),WebView,1,1,0); - gtk_widget_show_all(browser); - return browser; -} -#else - -GtkWidget *yon_ubl_browser_window_open(char *link, char *browser_window_name){ - char *user=yon_ubl_root_user_get(); - char *command=yon_char_unite("sudo -u ",user," xdg-open ", link,NULL); - yon_launch(command); - return NULL; -} -#endif - -// rmb menu section -typedef int (*RmbCheck)(void*); - -gboolean on_rmb_menu_open(GtkWidget *self,GdkEventButton *event, rmb_menu_window *window){ - int (*func)(void*) = (RmbCheck)(window->show_function); - if (!func||func(window->show_data)){ - if (self){}; - if (event->button==3){ - - gtk_widget_show_all(window->menu); - gtk_menu_popup_at_pointer(GTK_MENU(window->menu),NULL); - return 0; - } - return 0; - } -} - -rmb_menu_window *yon_rmb_menu_new(){ - rmb_menu_window *window = malloc(sizeof(rmb_menu_window)); - window->menu=gtk_menu_new(); - gtk_menu_set_reserve_toggle_size(GTK_MENU(window->menu),0); - window->buttons=NULL; - - return window; -} - -rmb_menu_window *yon_rmb_menu_setup(GtkWidget *target_widget, int (show_function)(void*), void *show_data, const char *button_label, const char *icon_name, GCallback function, gpointer data,...){ - if (target_widget){ - rmb_menu_window *window = yon_rmb_menu_new(); - window->show_function=(GCallback)show_function; - window->show_data=show_data; - { - GtkWidget *menu_item = gtk_menu_item_new(); - GtkWidget *content_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); - gtk_container_add(GTK_CONTAINER(menu_item),content_box); - - GtkWidget *image=NULL; - if (!yon_char_is_empty(icon_name)){ - image=gtk_image_new_from_icon_name(icon_name,GTK_ICON_SIZE_BUTTON); - gtk_box_pack_start(GTK_BOX(content_box),image,0,0,0); - gtk_widget_show(image); - } - - GtkWidget *label = gtk_label_new(button_label); - gtk_box_pack_start(GTK_BOX(content_box),label,0,0,0); - - if (function){ - g_signal_connect(G_OBJECT(menu_item),"activate",function,data); - } else { - gtk_widget_set_sensitive(menu_item,0); - } - yon_dictionary_add_or_create_if_exists_with_data(window->buttons,(char*)button_label,menu_item); - gtk_menu_shell_append(GTK_MENU_SHELL(window->menu),menu_item); - } - va_list list; - va_start(list,data); - const char *current_label, *current_icon; - GCallback current_function; - gpointer *current_data; - while ((current_label=va_arg(list,const char*))){ - if (current_label){ - current_icon=va_arg(list,const char*); - current_function=va_arg(list,GCallback); - current_data=va_arg(list,gpointer); - GtkWidget *menu_item = gtk_menu_item_new(); - GtkWidget *content_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); - gtk_container_add(GTK_CONTAINER(menu_item),content_box); - - GtkWidget *image=NULL; - if (!yon_char_is_empty(current_icon)){ - image=gtk_image_new_from_icon_name(current_icon,GTK_ICON_SIZE_BUTTON); - gtk_box_pack_start(GTK_BOX(content_box),image,0,0,0); - gtk_widget_show(image); - } - - GtkWidget *label = gtk_label_new(current_label); - gtk_box_pack_start(GTK_BOX(content_box),label,0,0,0); - - if (current_function){ - g_signal_connect(G_OBJECT(menu_item),"activate",current_function,current_data); - } else { - gtk_widget_set_sensitive(menu_item,0); - } - yon_dictionary_add_or_create_if_exists_with_data(window->buttons,(char*)current_label,menu_item); - gtk_menu_shell_append(GTK_MENU_SHELL(window->menu),menu_item); - gtk_widget_show(menu_item); - } - } - g_signal_connect(G_OBJECT(target_widget),"button-press-event",G_CALLBACK(on_rmb_menu_open),window); - return window; - } -} - -void yon_on_text_insert_only_digits(GtkEditable *editable, const gchar *text, gint length, gint *position, gpointer user_data){ - gchar *new_text = g_new(gchar, length + 1); - gint i, j = 0; - - for (i = 0; i < length; i++) { - if (g_ascii_isdigit(text[i])) { - new_text[j] = text[i]; - j++; - } - } - - if (j < length) { - g_signal_handlers_block_by_func(editable, G_CALLBACK(yon_on_text_insert_only_digits), user_data); - gtk_editable_insert_text(editable, new_text, j, position); - g_signal_handlers_unblock_by_func(editable, G_CALLBACK(yon_on_text_insert_only_digits), user_data); - g_signal_stop_emission_by_name(editable, "insert-text"); - } - - g_free(new_text); -} - -void yon_on_insert_restricted_check(GtkEditable *editable, const gchar *text, gint length, gint *position, gpointer){ - gchar *new_text = g_new(gchar, length + 1); - gint i, j = 0; - - for (i = 0; i < length; i++) { - if (text[i]!='!'&&text[i]!='@'&&text[i]!='#'&&text[i]!='%'&&text[i]!='^'&&text[i]!='&'&&text[i]!='*'&&text[i]!='\"'&&text[i]!='\'') { - new_text[j] = text[i]; - j++; - } - } - - if (j < length) { - g_signal_handlers_block_by_func(editable, G_CALLBACK(yon_on_insert_restricted_check), NULL); - gtk_editable_insert_text(editable, new_text, j, position); - g_signal_handlers_unblock_by_func(editable, G_CALLBACK(yon_on_insert_restricted_check), NULL); - g_signal_stop_emission_by_name(editable, "insert-text"); - } - - g_free(new_text); -} - -void yon_gtk_entry_block_restricted_symbols(GtkEntry *target){ - g_return_if_fail(GTK_IS_ENTRY(target)); - g_signal_connect(G_OBJECT(target),"insert-text",G_CALLBACK(yon_on_insert_restricted_check),NULL); -} - // GtkEntry section // struct entry_pattern_data { // GtkEntry *entry; @@ -1284,204 +40,6 @@ void yon_gtk_entry_block_restricted_symbols(GtkEntry *target){ // } -// GtkTreeStore section - -dictionary *yon_gtk_tree_store_get_children(GtkTreeStore *tree, GtkTreeIter *parent,int column){ - g_return_val_if_fail(GTK_IS_TREE_STORE(tree),NULL); - dictionary *children = NULL; - GtkTreeIter iter; - if(gtk_tree_model_iter_has_child){ - gtk_tree_model_iter_children(GTK_TREE_MODEL(tree),&iter,parent); - int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tree),&iter); - for (;valid;valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(tree),&iter)){ - void *result = NULL; - gtk_tree_model_get(GTK_TREE_MODEL(tree),&iter,column,&result,-1); - dictionary *child_children = yon_gtk_tree_store_get_children(tree,&iter,column); - yon_dictionary_add_or_create_if_exists_with_data(children,result,child_children); - } - return children; - } - return NULL; -} - -void yon_gtk_tree_store_fill_children(GtkTreeStore *tree, GtkTreeIter *parent, dictionary *data, int column){ - GtkTreeIter iter; - dictionary *dict=NULL; - for_dictionaries(dict,data){ - gtk_tree_store_append(tree,&iter,parent); - gtk_tree_store_set(tree,&iter,column,data->key,-1); - if (data->data){ - yon_gtk_tree_store_fill_children(tree,&iter,data->data,column); - } - } -} - -#include - -void yon_on_password_visibility_changed(GtkEntry *self, GtkEntryIconPosition position){ - if (position==GTK_ENTRY_ICON_SECONDARY){ - int status = gtk_entry_get_visibility(self); - gtk_entry_set_visibility(self,!status); - } -} - -void yon_gtk_entry_set_password_visibility_icon(GtkEntry *target){ - g_return_if_fail(GTK_IS_ENTRY(target)); - gtk_entry_set_icon_from_icon_name(target,GTK_ENTRY_ICON_SECONDARY,"com.ublinux.libublsettingsui-gtk3.view-symbolic"); - g_signal_connect(G_OBJECT(target),"icon-release",G_CALLBACK(yon_on_password_visibility_changed),NULL); -} - -void yon_gtk_tree_store_copy_recursive(GtkTreeModel *sourceModel, GtkTreeIter *sourceIter, GtkTreeStore *destination, GtkTreeIter *parentIter) { - GtkTreeIter destIter; - - gtk_tree_store_append(destination, &destIter, parentIter); - - gint nColumns = gtk_tree_model_get_n_columns(sourceModel); - for (gint col = 0; col < nColumns; col++) { - GValue value = G_VALUE_INIT; - - gtk_tree_model_get_value(sourceModel, sourceIter, col, &value); - - gtk_tree_store_set_value(destination, &destIter, col, &value); - - g_value_unset(&value); - } - - if (gtk_tree_model_iter_has_child(sourceModel, sourceIter)) { - GtkTreeIter childIter; - gboolean validChild = gtk_tree_model_iter_children(sourceModel, &childIter, sourceIter); - while (validChild) { - yon_gtk_tree_store_copy_recursive(sourceModel, &childIter, destination, &destIter); - validChild = gtk_tree_model_iter_next(sourceModel, &childIter); - } - } -} - -void yon_gtk_tree_store_copy_full(GtkTreeStore *source, GtkTreeStore *destination) { - GtkTreeModel *sourceModel = GTK_TREE_MODEL(source); - GtkTreeIter iter; - gboolean valid; - - valid = gtk_tree_model_get_iter_first(sourceModel, &iter); - - while (valid) { - yon_gtk_tree_store_copy_recursive(sourceModel, &iter, destination, NULL); - - valid = gtk_tree_model_iter_next(sourceModel, &iter); - } -} - -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; -} - -gboolean yon_gtk_list_store_copy_full(GtkListStore *target, GtkListStore *source){ - gtk_list_store_clear(target); - GtkTreeIter iter, itar; - g_return_val_if_fail(GTK_IS_LIST_STORE(target),0); - g_return_val_if_fail(GTK_IS_LIST_STORE(source),0); - int columns = gtk_tree_model_get_n_columns(GTK_TREE_MODEL(source)); - int target_columns = gtk_tree_model_get_n_columns(GTK_TREE_MODEL(target)); - if (columns!=target_columns){ - g_log((gchar*)0,G_LOG_LEVEL_WARNING,"%s\n","Target and source models have different number of columns"); - return 0; - } - for_iter(source,&iter){ - gtk_list_store_append(target,&itar); - for(int i=0;i0)||(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); - -} config_str yon_resource_open_file(const char *path, int *size){ config_str parsed = NULL; diff --git a/source/libublsettings-gtk3.h b/source/libublsettings-gtk3.h index bce6787..18ea3b4 100644 --- a/source/libublsettings-gtk3.h +++ b/source/libublsettings-gtk3.h @@ -312,6 +312,10 @@ void yon_gtk_toggle_button_set_inactive_from_toggle_button_inversed(GtkToggleBut */ void yon_gtk_toggle_button_set_inactive_from_toggle_button(GtkToggleButton *self, GtkToggleButton *target); + +int yon_gtk_tree_view_set_fixed_size(GtkTreeView *target, ...); + +//status section typedef enum { BACKGROUND_IMAGE_INFO_TYPE, @@ -429,6 +433,7 @@ void _yon_ubl_header_setup(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image void _yon_ubl_header_setup_resource(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path); +//socket section /**yon_ubl_setup_sockets(GtkWidget *main_window, GtkWidget *left_window, GtkWidget *right_window, int socket_main_id, int socket_left_id, int socket_right_id) * [EN] * Set up plugs for using with GtkSockets insine ubl-settings-manager. @@ -449,6 +454,7 @@ void _yon_ubl_header_setup_resource(GtkWidget *Overlay, GtkWidget *Head, GtkWidg */ void yon_ubl_setup_sockets(GtkWidget *main_window, GtkWidget *left_window, GtkWidget *right_window, int socket_main_id, int socket_left_id, int socket_right_id); +//webkit section #ifdef WEBKIT_INCLUDE #include