diff --git a/source/libublsettings-gtk3-status.c b/source/libublsettings-gtk3-status.c index ae91cc7..4146cfd 100644 --- a/source/libublsettings-gtk3-status.c +++ b/source/libublsettings-gtk3-status.c @@ -64,17 +64,41 @@ 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){ +struct __yon_ubl_status_box_render_thread_struct{ + char *text; + BACKGROUND_IMAGE_TYPE type; +}; + +gboolean _yon_ubl_status_box_render_thread(struct __yon_ubl_status_box_render_thread_struct *data){ + render_data statusbox = render; + yon_ubl_status_box_set(data->type,statusbox.box,GTK_IMAGE(statusbox.icon)); + if (data->text){ + gtk_label_set_text(GTK_LABEL(statusbox.label), data->text); + free(data->text); + } + free(data); + return G_SOURCE_REMOVE; +} + +void yon_ubl_status_box_render_thread(char *text, BACKGROUND_IMAGE_TYPE type){ + struct __yon_ubl_status_box_render_thread_struct *data = malloc(sizeof(struct __yon_ubl_status_box_render_thread_struct)); + data->text=yon_char_new(text); + data->type=type; + g_idle_add((GSourceFunc)_yon_ubl_status_box_render_thread,data); +} + +gboolean _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"); + return G_SOURCE_REMOVE; } void yon_ubl_status_highlight_incorrect(GtkWidget *widget){ - GThread *thread = g_thread_new(NULL,(GThreadFunc)_yon_ubl_status_highlight_incorrect,widget); + g_idle_add((GSourceFunc)_yon_ubl_status_highlight_incorrect,widget); } -void _yon_ubl_status_list_store_highlight_incorrect(GtkWidget **widget_pack){ +gboolean _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; @@ -89,13 +113,14 @@ void _yon_ubl_status_list_store_highlight_incorrect(GtkWidget **widget_pack){ 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); + return G_SOURCE_REMOVE; } 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); + g_idle_add((GSourceFunc)_yon_ubl_status_list_store_highlight_incorrect,pack); } struct temp_statusbox { diff --git a/source/libublsettings-gtk3.h b/source/libublsettings-gtk3.h index 20a38df..0e3347e 100644 --- a/source/libublsettings-gtk3.h +++ b/source/libublsettings-gtk3.h @@ -367,6 +367,23 @@ int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label); */ void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type); +/**yon_ubl_status_box_render_thread(render,text,type) + * [EN] + * Renders message in status box. It is safe to use outside of interface thread. + * [render] is render_data structure of status box; + * [text] is text to be shown in status box; + * [type] if type of message. Can be BACKGROUND_IMAGE_FAIL_TYPE or BACKGROUND_IMAGE_SUCCESS_TYPE + * [RU] + * Отображает сообщение в статусном окне. Безопасна для вызова не из потока интерфейса. + * [render] - структура типа render_data для нужного статусного окна; + * [text] - текст, отображаемый в статусном окне; + * [type] - тип сообщения. Может быть: + * BACKGROUND_IMAGE_FAIL_TYPE (красный фон,иконка - восклицательный знак) + * или + * BACKGROUND_IMAGE_SUCCESS_TYPE (Жёлтный фон, иконка - галка) +*/ +void yon_ubl_status_box_render_thread(char *text, BACKGROUND_IMAGE_TYPE type); + /**yon_ubl_status_list_store_highlight_incorrect(GtkListStore *list, GtkTreeIter *iter) * [EN] *