2015-06-11 18:07:06 -05:00
|
|
|
// 11 june 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
struct uiProgressBar {
|
|
|
|
uiUnixControl c;
|
2015-06-11 18:07:06 -05:00
|
|
|
GtkWidget *widget;
|
2015-06-27 18:46:11 -05:00
|
|
|
GtkProgressBar *pbar;
|
2016-06-16 16:43:04 -05:00
|
|
|
gboolean indeterminate;
|
|
|
|
guint pulser;
|
2015-06-11 18:07:06 -05:00
|
|
|
};
|
|
|
|
|
2016-06-21 11:39:53 -05:00
|
|
|
uiUnixControlAllDefaultsExceptDestroy(uiProgressBar)
|
|
|
|
|
|
|
|
static void uiProgressBarDestroy(uiControl *c)
|
|
|
|
{
|
|
|
|
uiProgressBar *p = uiProgressBar(c);
|
|
|
|
|
|
|
|
// be sure to stop the timeout now
|
|
|
|
if (p->indeterminate)
|
|
|
|
g_source_remove(p->pulser);
|
|
|
|
g_object_unref(p->widget);
|
|
|
|
uiFreeControl(uiControl(p));
|
|
|
|
}
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2016-06-15 11:51:12 -05:00
|
|
|
int uiProgressBarValue(uiProgressBar *p)
|
|
|
|
{
|
2016-06-15 16:17:23 -05:00
|
|
|
if (p->indeterminate)
|
|
|
|
return -1;
|
2016-06-15 11:51:12 -05:00
|
|
|
return (int) (gtk_progress_bar_get_fraction(p->pbar) * 100);
|
|
|
|
}
|
|
|
|
|
2016-06-16 16:43:04 -05:00
|
|
|
static gboolean pulse(void* data)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2016-06-16 16:43:04 -05:00
|
|
|
uiProgressBar *p = uiProgressBar(data);
|
2016-06-15 14:51:08 -05:00
|
|
|
|
|
|
|
gtk_progress_bar_pulse(p->pbar);
|
2016-06-16 16:43:04 -05:00
|
|
|
return TRUE;
|
2016-06-15 14:51:08 -05:00
|
|
|
}
|
|
|
|
|
2016-06-15 16:17:23 -05:00
|
|
|
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
2016-06-15 14:51:08 -05:00
|
|
|
{
|
2016-06-15 16:17:23 -05:00
|
|
|
if (value == -1) {
|
|
|
|
if (!p->indeterminate) {
|
2016-06-16 16:43:04 -05:00
|
|
|
p->indeterminate = TRUE;
|
|
|
|
// TODO verify the timeout
|
|
|
|
p->pulser = g_timeout_add(100, pulse, p);
|
2016-06-15 16:17:23 -05:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2016-06-16 16:43:04 -05:00
|
|
|
if (p->indeterminate) {
|
|
|
|
p->indeterminate = FALSE;
|
|
|
|
g_source_remove(p->pulser);
|
|
|
|
}
|
2016-06-15 14:51:08 -05:00
|
|
|
|
2016-06-15 16:17:23 -05:00
|
|
|
if (value < 0 || value > 100)
|
|
|
|
userbug("Value %d is out of range for a uiProgressBar.", value);
|
|
|
|
|
|
|
|
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
|
2016-06-15 14:51:08 -05:00
|
|
|
}
|
|
|
|
|
2015-06-11 18:07:06 -05:00
|
|
|
uiProgressBar *uiNewProgressBar(void)
|
|
|
|
{
|
2015-08-27 22:00:34 -05:00
|
|
|
uiProgressBar *p;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2016-04-25 19:00:25 -05:00
|
|
|
uiUnixNewControl(uiProgressBar, p);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-06-27 18:46:11 -05:00
|
|
|
p->widget = gtk_progress_bar_new();
|
|
|
|
p->pbar = GTK_PROGRESS_BAR(p->widget);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
return p;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|