Anna Schumaker
3383f9e32a
And add in various cleanups while we're at it. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
32 lines
677 B
C
32 lines
677 B
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <gui/idle.h>
|
|
|
|
static guint idle_id = 0;
|
|
|
|
static gboolean __on_idle(gpointer data)
|
|
{
|
|
bool more = idle_run_task();
|
|
gchar *text = g_strdup_printf("%f%%", idle_progress() * 100);
|
|
|
|
gtk_widget_set_visible(GTK_WIDGET(gui_progress_bar()), more);
|
|
gtk_progress_bar_set_fraction(gui_progress_bar(), idle_progress());
|
|
gtk_widget_set_tooltip_text(GTK_WIDGET(gui_progress_bar()), text);
|
|
g_free(text);
|
|
|
|
idle_id = more ? idle_id : 0;
|
|
return more ? G_SOURCE_CONTINUE : G_SOURCE_REMOVE;
|
|
}
|
|
|
|
void gui_idle_enable()
|
|
{
|
|
idle_id = g_idle_add(__on_idle, NULL);
|
|
}
|
|
|
|
void gui_idle_disable()
|
|
{
|
|
if (idle_id)
|
|
g_source_remove(idle_id);
|
|
}
|