#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; } int yon_status_box_is_set(){ if (render.box){ return 1; } return 0; } GMutex _render_block_mutex; gboolean _render_blocked=0; void *_yon_ubl_status_box_block_input(int*seconds){ g_mutex_lock(&_render_block_mutex); _render_blocked = 1; g_mutex_unlock(&_render_block_mutex); sleep(*seconds); g_mutex_lock(&_render_block_mutex); _render_blocked = 0; g_mutex_unlock(&_render_block_mutex); } void yon_ubl_status_box_block_input(int seconds){ g_thread_new("block_thread",(GThreadFunc)_yon_ubl_status_box_block_input,&seconds); } 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-symbolic", 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){ g_mutex_lock(&_render_block_mutex); int blocked = _render_blocked; g_mutex_unlock(&_render_block_mutex); if (blocked) return; _yon_ubl_status_box_render(text,type); } 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){ g_mutex_lock(&_render_block_mutex); int blocked = _render_blocked; g_mutex_unlock(&_render_block_mutex); if (blocked) return; 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_start(GtkWidget *widget){ gtk_style_context_add_class(gtk_widget_get_style_context(widget),"errorBox"); return G_SOURCE_REMOVE; } gboolean _yon_ubl_status_highlight_incorrect_stop(GtkWidget *widget){ gtk_style_context_remove_class(gtk_widget_get_style_context(widget),"errorBox"); return G_SOURCE_REMOVE; } gboolean _yon_ubl_status_highlight_incorrect(GtkWidget *widget){ g_idle_add((GSourceFunc)_yon_ubl_status_highlight_incorrect_start,widget); sleep(5); g_idle_add((GSourceFunc)_yon_ubl_status_highlight_incorrect_stop,widget); } void yon_ubl_status_highlight_incorrect(GtkWidget *widget){ g_thread_new("error_highlight",(GThreadFunc)_yon_ubl_status_highlight_incorrect,widget); } gboolean _yon_ubl_status_list_store_highlight_incorrect_start(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); return G_SOURCE_REMOVE; } gboolean _yon_ubl_status_list_store_highlight_incorrect_stop(GtkWidget **widget_pack){ GtkListStore *list = (GtkListStore*)widget_pack[0]; GtkTreeIter *iter = (GtkTreeIter*)widget_pack[1]; gtk_list_store_set(list,iter,1,NULL,2,NULL,-1); return G_SOURCE_REMOVE; } void _yon_ubl_status_list_store_highlight_incorrect(GtkWidget **widget_pack){ g_idle_add((GSourceFunc)_yon_ubl_status_highlight_incorrect_stop,widget_pack); sleep(5); g_idle_add((GSourceFunc)_yon_ubl_status_highlight_incorrect_stop,widget_pack); } 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; g_thread_new("error_highlight",(GThreadFunc)_yon_ubl_status_list_store_highlight_incorrect,pack); } struct temp_statusbox { int times; GtkWidget *revealer; int window_height; }; static char *yon_status_thread_id=NULL; gboolean yon_ubl_status_hide_revealer(struct temp_statusbox *statusstruct){ gtk_revealer_set_reveal_child(GTK_REVEALER(statusstruct->revealer),0); } gboolean yon_status_shrink_window(struct temp_statusbox *statusstruct){ if (statusstruct->revealer){ GtkWidget *window = gtk_widget_get_toplevel(statusstruct->revealer); int width, height; gtk_window_get_size(GTK_WINDOW(window),&width,NULL); gtk_window_resize(GTK_WINDOW(window),width,statusstruct->window_height); return G_SOURCE_CONTINUE; } else return G_SOURCE_REMOVE; } gboolean yon_ubl_status_destroy_status(struct temp_statusbox *statusstruct){ GtkWidget *window = gtk_widget_get_toplevel(statusstruct->revealer); GtkWidget *revealer = statusstruct->revealer; gtk_widget_destroy(statusstruct->revealer); statusstruct->revealer = NULL; int width, height; gtk_window_get_size(GTK_WINDOW(window),&width,NULL); gtk_window_resize(GTK_WINDOW(window),width,statusstruct->window_height); return G_SOURCE_REMOVE; } void _yon_ubl_status_box_timed_remove(struct temp_statusbox *statusstruct){ sleep(statusstruct->times); if (statusstruct->revealer){ g_idle_add((GSourceFunc)yon_ubl_status_hide_revealer,statusstruct); g_idle_add((GSourceFunc)yon_status_shrink_window,statusstruct); sleep(1); g_idle_add((GSourceFunc)yon_ubl_status_destroy_status,statusstruct); } } 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){ g_mutex_lock(&_render_block_mutex); int blocked = _render_blocked; g_mutex_unlock(&_render_block_mutex); if (blocked) return 0; // 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; gtk_window_get_size(GTK_WINDOW(gtk_widget_get_toplevel(revealer)),NULL,&statusstruct->window_height); // } } 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_despawn(GtkContainer *status_container){ GList *list = gtk_container_get_children(status_container); GtkWidget *revealer = g_list_nth_data(list,0); struct temp_statusbox *statusstruct = malloc(sizeof(struct temp_statusbox)); statusstruct->revealer = revealer; statusstruct->times = 0; g_idle_add((GSourceFunc)yon_ubl_status_hide_revealer,statusstruct); sleep(1); gtk_widget_destroy(statusstruct->revealer); g_list_free(list); return NULL; } void yon_ubl_status_box_despawn(GtkContainer *status_container){ GList *list = gtk_container_get_children(status_container); if (!list) return; g_list_free(list); g_thread_new("status_despawn",(GThreadFunc)__yon_ubl_status_box_despawn,status_container); } void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int timeout,BACKGROUND_IMAGE_TYPE type){ g_mutex_lock(&_render_block_mutex); int blocked = _render_blocked; g_mutex_unlock(&_render_block_mutex); if (blocked) return; 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; gtk_window_get_size(GTK_WINDOW(gtk_widget_get_toplevel(revealer)),NULL,&statusstruct->window_height); 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); } int yon_ubl_status_set_text(GtkContainer *status_placeholder,char *text){ GList *placeholder_children = gtk_container_get_children(status_placeholder); if (placeholder_children){ GList *status_children = gtk_container_get_children(GTK_CONTAINER(placeholder_children->data)); if (status_children){ gtk_label_set_text(GTK_LABEL(g_list_nth_data(status_children,1)),text); g_list_free(status_children); } g_list_free(placeholder_children); } return 0; }