#include <config.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pwd.h>
#include <unistd.h>
#include <glib.h>
#include <gtk/gtk.h>
#include "types.h"
#include "distcc.h"
#include "rpc.h"
#include "trace.h"
#include "exitcode.h"
#include "mon.h"
#include "netutil.h"
#include "renderer.h"
struct _DccCellRendererChart
{
GtkCellRenderer parent;
struct dcc_history *history;
};
struct _DccCellRendererChartClass
{
GtkCellRendererClass parent_class;
};
enum {
PROP_ZERO,
PROP_HISTORY
};
GtkCellRenderer *
dcc_cell_renderer_chart_new (void)
{
return g_object_new (DCC_TYPE_CELL_RENDERER_CHART, NULL);
}
static void
dcc_cell_renderer_chart_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
DccCellRendererChart *renderer;
renderer = DCC_CELL_RENDERER_CHART (object);
switch (prop_id)
{
case PROP_HISTORY:
renderer->history = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
dcc_cell_renderer_chart_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
DccCellRendererChart *renderer;
renderer = DCC_CELL_RENDERER_CHART (object);
switch (prop_id)
{
case PROP_HISTORY:
g_value_set_pointer (value, renderer->history);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
dcc_cell_renderer_chart_render (GtkCellRenderer *cell,
GdkWindow *window,
GtkWidget *UNUSED(widget),
GdkRectangle *UNUSED(background_area),
GdkRectangle *cell_area,
GdkRectangle *UNUSED(expose_area),
GtkCellRendererState UNUSED(flags))
{
const struct dcc_history *history;
enum dcc_phase state;
int x1, y1;
int bar_height;
int bar_width;
int i;
const enum dcc_phase *phases;
DccCellRendererChart *cellchart = (DccCellRendererChart *) cell;
history = cellchart->history;
g_return_if_fail (history);
x1 = cell_area->x + cell->xpad;
y1 = cell_area->y + cell->ypad;
bar_height = cell_area->height - (2 * cell->ypad);
bar_width = (cell_area->width + history->len - 1) / history->len;
if (bar_width < 1)
bar_width = 1;
phases = history->past_phases;
for (i = 0; i < history->len; i++)
{
state = phases[(history->len + history->now - i) % history->len];
g_return_if_fail (state <= DCC_PHASE_DONE);
if (state != DCC_PHASE_DONE)
{
gdk_draw_rectangle (window,
dcc_phase_gc[state],
TRUE,
x1, y1, bar_width, bar_height);
}
x1 += bar_width;
}
}
static void
dcc_cell_renderer_chart_get_size (GtkCellRenderer *UNUSED(cell),
GtkWidget *UNUSED (widget),
GdkRectangle *UNUSED (cell_area),
gint *UNUSED (x_offset),
gint *UNUSED (y_offset),
gint *UNUSED (width),
gint *UNUSED (height))
{
}
static void
dcc_cell_renderer_chart_class_init (DccCellRendererChartClass *class)
{
GParamSpec *spec;
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
object_class->get_property = dcc_cell_renderer_chart_get_property;
object_class->set_property = dcc_cell_renderer_chart_set_property;
cell_class->render = dcc_cell_renderer_chart_render;
cell_class->get_size = dcc_cell_renderer_chart_get_size;
spec = g_param_spec_pointer ("history",
"Slot history",
"",
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property (object_class,
PROP_HISTORY,
spec);
}
static void
dcc_cell_renderer_chart_init (DccCellRendererChart *cell)
{
cell->history = NULL;
}
GType
dcc_cell_renderer_chart_get_type (void)
{
static GType cell_chart_type = 0;
if (!cell_chart_type)
{
static const GTypeInfo cell_chart_info =
{
sizeof (DccCellRendererChartClass),
NULL,
NULL,
(GClassInitFunc) dcc_cell_renderer_chart_class_init,
NULL,
NULL,
sizeof (DccCellRendererChart),
0,
(GInstanceInitFunc) dcc_cell_renderer_chart_init,
NULL
};
cell_chart_type =
g_type_register_static (GTK_TYPE_CELL_RENDERER,
"DccCellRendererChart",
&cell_chart_info, 0);
}
return cell_chart_type;
}