Code cleanup
This commit is contained in:
parent
dbaba810cf
commit
d4681b37f0
@ -51,6 +51,8 @@ typedef struct _Progress
|
|||||||
int fds[2]; /* for the pipe */
|
int fds[2]; /* for the pipe */
|
||||||
pid_t pid; /* child's pid */
|
pid_t pid; /* child's pid */
|
||||||
size_t cnt; /* bytes written */
|
size_t cnt; /* bytes written */
|
||||||
|
char buf[BUFSIZ];
|
||||||
|
size_t buf_cnt;
|
||||||
|
|
||||||
/* widgets */
|
/* widgets */
|
||||||
GtkWidget * speed;
|
GtkWidget * speed;
|
||||||
@ -200,24 +202,26 @@ static void _progress_cancel(GtkWidget * widget, gpointer data)
|
|||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* progress_out */
|
||||||
|
static void _out_rate(Progress * p);
|
||||||
|
|
||||||
static gboolean _progress_out(GIOChannel * source, GIOCondition condition,
|
static gboolean _progress_out(GIOChannel * source, GIOCondition condition,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
Progress * p = data;
|
Progress * p = data;
|
||||||
char buf[BUFSIZ];
|
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
gsize written;
|
gsize written;
|
||||||
gdouble fraction;
|
|
||||||
|
|
||||||
/* FIXME use g_io_channel_read too? */
|
/* FIXME use g_io_channel_read too? */
|
||||||
if(condition != G_IO_OUT
|
if(condition != G_IO_OUT
|
||||||
|| (len = read(p->fd, buf, sizeof(buf))) < 0)
|
|| (len = read(p->fd, p->buf, sizeof(p->buf))) < 0)
|
||||||
{
|
{
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
_progress_error(p->prefs->filename, 0);
|
_progress_error(p->prefs->filename, 0);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if(g_io_channel_write(source, buf, len, &written) != G_IO_ERROR_NONE
|
if(g_io_channel_write(source, p->buf, len, &written) != G_IO_ERROR_NONE
|
||||||
|| written != (gsize)len)
|
|| written != (gsize)len)
|
||||||
{
|
{
|
||||||
/* FIXME it may just be that everything was not written
|
/* FIXME it may just be that everything was not written
|
||||||
@ -227,17 +231,7 @@ static gboolean _progress_out(GIOChannel * source, GIOCondition condition,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
p->cnt += len;
|
p->cnt += len;
|
||||||
if(p->prefs->length == 0 || p->cnt == 0)
|
_out_rate(p);
|
||||||
p->pulse = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fraction = p->cnt;
|
|
||||||
fraction /= p->prefs->length;
|
|
||||||
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(p->progress),
|
|
||||||
fraction);
|
|
||||||
snprintf(buf, sizeof(buf), "%.1f%%", fraction * 100);
|
|
||||||
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(p->progress), buf);
|
|
||||||
}
|
|
||||||
if(len == 0)
|
if(len == 0)
|
||||||
{
|
{
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
@ -246,6 +240,26 @@ static gboolean _progress_out(GIOChannel * source, GIOCondition condition,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _out_rate(Progress * p)
|
||||||
|
{
|
||||||
|
gdouble fraction;
|
||||||
|
char buf[16];
|
||||||
|
|
||||||
|
if(p->prefs->length == 0 || p->cnt == 0)
|
||||||
|
{
|
||||||
|
p->pulse = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fraction = p->cnt;
|
||||||
|
fraction /= p->prefs->length;
|
||||||
|
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(p->progress),
|
||||||
|
fraction);
|
||||||
|
snprintf(buf, sizeof(buf), "%.1f%%", fraction * 100);
|
||||||
|
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(p->progress), buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* progress_timeout */
|
||||||
static gboolean _progress_timeout(gpointer data)
|
static gboolean _progress_timeout(gpointer data)
|
||||||
{
|
{
|
||||||
Progress * progress = data;
|
Progress * progress = data;
|
||||||
|
Loading…
Reference in New Issue
Block a user