/* * Copyright 2016 (c) Anna Schumaker. */ #include #include #include static guint idle_id = 0; static gboolean __on_idle(gpointer data) { GtkProgressBar *progress = GTK_PROGRESS_BAR(data); unsigned int percent = idle_progress() * 100; gchar *text; if (idle_run_task()) { gtk_progress_bar_set_fraction(progress, idle_progress()); text = g_strdup_printf("%u%%", percent); gtk_widget_set_tooltip_text(GTK_WIDGET(progress), text); g_free(text); return G_SOURCE_CONTINUE; } else { gtk_widget_hide(GTK_WIDGET(progress)); idle_id = 0; return G_SOURCE_REMOVE; } } void gui_idle_enable() { GtkWidget *progress = gui_builder_widget("o_idle_progress"); gtk_widget_show(progress); idle_id = g_idle_add(__on_idle, progress); } void gui_idle_disable() { if (idle_id) g_source_remove(idle_id); }