summaryrefslogtreecommitdiff
path: root/src/trg-torrent-graph.c
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-12-11 15:08:03 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-12-11 15:08:03 +0000
commit763abd8c8fc32b29c5f989cd0d4cab1b6e472997 (patch)
tree4ff54223e8526dbb20e9fe87e9c21d9a3b80975c /src/trg-torrent-graph.c
parent0d08a471f9ebfdfadded6c92abc700c706475644 (diff)
oops, no tabs. (indent -kr -nut)
Diffstat (limited to 'src/trg-torrent-graph.c')
-rw-r--r--src/trg-torrent-graph.c294
1 files changed, 147 insertions, 147 deletions
diff --git a/src/trg-torrent-graph.c b/src/trg-torrent-graph.c
index 26e5fd4..99c5dad 100644
--- a/src/trg-torrent-graph.c
+++ b/src/trg-torrent-graph.c
@@ -90,23 +90,23 @@ static int trg_torrent_graph_update(gpointer user_data);
static void
trg_torrent_graph_get_property(GObject * object, guint property_id,
- GValue * value, GParamSpec * pspec)
+ GValue * value, GParamSpec * pspec)
{
switch (property_id) {
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
}
}
static void
trg_torrent_graph_set_property(GObject * object, guint property_id,
- const GValue * value, GParamSpec * pspec)
+ const GValue * value, GParamSpec * pspec)
{
switch (property_id) {
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
}
}
@@ -127,18 +127,18 @@ void trg_torrent_graph_draw_background(TrgTorrentGraph * g)
priv = TRG_TORRENT_GRAPH_GET_PRIVATE(g);
num_bars = trg_torrent_graph_get_num_bars(g);
- priv->graph_dely = (priv->draw_height - 15) / num_bars; /* round to int to avoid AA blur */
+ priv->graph_dely = (priv->draw_height - 15) / num_bars; /* round to int to avoid AA blur */
priv->real_draw_height = priv->graph_dely * num_bars;
priv->graph_delx =
- (priv->draw_width - 2.0 - priv->rmargin -
- priv->indent) / (GRAPH_NUM_POINTS - 3);
+ (priv->draw_width - 2.0 - priv->rmargin -
+ priv->indent) / (GRAPH_NUM_POINTS - 3);
priv->graph_buffer_offset =
- (int) (1.5 * priv->graph_delx) + GRAPH_FRAME_WIDTH;
+ (int) (1.5 * priv->graph_delx) + GRAPH_FRAME_WIDTH;
gtk_widget_get_allocation(priv->disp, &allocation);
priv->background =
- gdk_pixmap_new(GDK_DRAWABLE(gtk_widget_get_window(priv->disp)),
- allocation.width, allocation.height, -1);
+ gdk_pixmap_new(GDK_DRAWABLE(gtk_widget_get_window(priv->disp)),
+ allocation.width, allocation.height, -1);
cr = gdk_cairo_create(priv->background);
gdk_cairo_set_source_color(cr, &priv->style->bg[GTK_STATE_NORMAL]);
@@ -146,8 +146,8 @@ void trg_torrent_graph_draw_background(TrgTorrentGraph * g)
cairo_translate(cr, GRAPH_FRAME_WIDTH, GRAPH_FRAME_WIDTH);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_rectangle(cr, priv->rmargin + priv->indent, 0,
- priv->draw_width - priv->rmargin - priv->indent,
- priv->real_draw_height);
+ priv->draw_width - priv->rmargin - priv->indent,
+ priv->real_draw_height);
cairo_fill(cr);
@@ -156,22 +156,22 @@ void trg_torrent_graph_draw_background(TrgTorrentGraph * g)
cairo_set_font_size(cr, priv->fontsize);
for (i = 0; i <= num_bars; ++i) {
- double y;
- gchar caption[32];
-
- if (i == 0)
- y = 0.5 + priv->fontsize / 2.0;
- else if (i == num_bars)
- y = i * priv->graph_dely + 0.5;
- else
- y = i * priv->graph_dely + priv->fontsize / 2.0;
-
- gdk_cairo_set_source_color(cr, &priv->style->fg[GTK_STATE_NORMAL]);
- rate = priv->max - (i * priv->max / num_bars);
- trg_strlspeed(caption, (gint64) (rate / 1024));
- cairo_text_extents(cr, caption, &extents);
- cairo_move_to(cr, priv->indent - extents.width + 20, y);
- cairo_show_text(cr, caption);
+ double y;
+ gchar caption[32];
+
+ if (i == 0)
+ y = 0.5 + priv->fontsize / 2.0;
+ else if (i == num_bars)
+ y = i * priv->graph_dely + 0.5;
+ else
+ y = i * priv->graph_dely + priv->fontsize / 2.0;
+
+ gdk_cairo_set_source_color(cr, &priv->style->fg[GTK_STATE_NORMAL]);
+ rate = priv->max - (i * priv->max / num_bars);
+ trg_strlspeed(caption, (gint64) (rate / 1024));
+ cairo_text_extents(cr, caption, &extents);
+ cairo_move_to(cr, priv->indent - extents.width + 20, y);
+ cairo_show_text(cr, caption);
}
cairo_stroke(cr);
@@ -181,29 +181,29 @@ void trg_torrent_graph_draw_background(TrgTorrentGraph * g)
total_seconds = priv->speed * (GRAPH_NUM_POINTS - 2) / 1000;
for (i = 0; i < 7; i++) {
- unsigned seconds;
- const char *format;
- double x =
- (i) * (priv->draw_width - priv->rmargin - priv->indent) / 6;
- cairo_set_source_rgba(cr, 0, 0, 0, 0.75);
- cairo_move_to(cr, (ceil(x) + 0.5) + priv->rmargin + priv->indent,
- 0.5);
- cairo_line_to(cr, (ceil(x) + 0.5) + priv->rmargin + priv->indent,
- priv->real_draw_height + 4.5);
- cairo_stroke(cr);
- seconds = total_seconds - i * total_seconds / 6;
- if (i == 0)
- format = "%u seconds";
- else
- format = "%u";
- caption = g_strdup_printf(format, seconds);
- cairo_text_extents(cr, caption, &extents);
- cairo_move_to(cr,
- ((ceil(x) + 0.5) + priv->rmargin + priv->indent) -
- (extents.width / 2), priv->draw_height);
- gdk_cairo_set_source_color(cr, &priv->style->fg[GTK_STATE_NORMAL]);
- cairo_show_text(cr, caption);
- g_free(caption);
+ unsigned seconds;
+ const char *format;
+ double x =
+ (i) * (priv->draw_width - priv->rmargin - priv->indent) / 6;
+ cairo_set_source_rgba(cr, 0, 0, 0, 0.75);
+ cairo_move_to(cr, (ceil(x) + 0.5) + priv->rmargin + priv->indent,
+ 0.5);
+ cairo_line_to(cr, (ceil(x) + 0.5) + priv->rmargin + priv->indent,
+ priv->real_draw_height + 4.5);
+ cairo_stroke(cr);
+ seconds = total_seconds - i * total_seconds / 6;
+ if (i == 0)
+ format = "%u seconds";
+ else
+ format = "%u";
+ caption = g_strdup_printf(format, seconds);
+ cairo_text_extents(cr, caption, &extents);
+ cairo_move_to(cr,
+ ((ceil(x) + 0.5) + priv->rmargin + priv->indent) -
+ (extents.width / 2), priv->draw_height);
+ gdk_cairo_set_source_color(cr, &priv->style->fg[GTK_STATE_NORMAL]);
+ cairo_show_text(cr, caption);
+ g_free(caption);
}
cairo_stroke(cr);
@@ -218,7 +218,7 @@ void trg_torrent_graph_set_nothing(TrgTorrentGraph * g)
}
void trg_torrent_graph_set_speed(TrgTorrentGraph * g,
- trg_torrent_model_update_stats * stats)
+ trg_torrent_model_update_stats * stats)
{
TrgTorrentGraphPrivate *priv = TRG_TORRENT_GRAPH_GET_PRIVATE(g);
@@ -228,7 +228,7 @@ void trg_torrent_graph_set_speed(TrgTorrentGraph * g,
static gboolean
trg_torrent_graph_configure(GtkWidget * widget,
- GdkEventConfigure * event, gpointer data_ptr)
+ GdkEventConfigure * event, gpointer data_ptr)
{
GtkAllocation allocation;
TrgTorrentGraph *g = TRG_TORRENT_GRAPH(data_ptr);
@@ -241,7 +241,7 @@ trg_torrent_graph_configure(GtkWidget * widget,
trg_torrent_graph_clear_background(g);
if (priv->gc == NULL)
- priv->gc = gdk_gc_new(GDK_DRAWABLE(gtk_widget_get_window(widget)));
+ priv->gc = gdk_gc_new(GDK_DRAWABLE(gtk_widget_get_window(widget)));
trg_torrent_graph_draw(g);
@@ -250,7 +250,7 @@ trg_torrent_graph_configure(GtkWidget * widget,
static gboolean
trg_torrent_graph_expose(GtkWidget * widget,
- GdkEventExpose * event, gpointer data_ptr)
+ GdkEventExpose * event, gpointer data_ptr)
{
TrgTorrentGraph *g = TRG_TORRENT_GRAPH(data_ptr);
TrgTorrentGraphPrivate *priv = TRG_TORRENT_GRAPH_GET_PRIVATE(data_ptr);
@@ -264,22 +264,22 @@ trg_torrent_graph_expose(GtkWidget * widget,
gdouble sample_width, x_offset;
if (priv->background == NULL)
- trg_torrent_graph_draw_background(g);
+ trg_torrent_graph_draw_background(g);
window = gtk_widget_get_window(priv->disp);
gtk_widget_get_allocation(priv->disp, &allocation);
gdk_draw_drawable(window,
- priv->gc,
- priv->background,
- 0, 0, 0, 0, allocation.width, allocation.height);
+ priv->gc,
+ priv->background,
+ 0, 0, 0, 0, allocation.width, allocation.height);
sample_width =
- (float) (priv->draw_width - priv->rmargin -
- priv->indent) / (float) GRAPH_NUM_POINTS;
+ (float) (priv->draw_width - priv->rmargin -
+ priv->indent) / (float) GRAPH_NUM_POINTS;
x_offset = priv->draw_width - priv->rmargin + (sample_width * 2);
x_offset +=
- priv->rmargin -
- ((sample_width / priv->frames_per_unit) * priv->render_counter);
+ priv->rmargin -
+ ((sample_width / priv->frames_per_unit) * priv->render_counter);
cr = gdk_cairo_create(window);
@@ -287,39 +287,39 @@ trg_torrent_graph_expose(GtkWidget * widget,
cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
cairo_rectangle(cr,
- priv->rmargin + priv->indent + GRAPH_FRAME_WIDTH + 1,
- GRAPH_FRAME_WIDTH - 1,
- priv->draw_width - priv->rmargin - priv->indent - 1,
- priv->real_draw_height + GRAPH_FRAME_WIDTH - 1);
+ priv->rmargin + priv->indent + GRAPH_FRAME_WIDTH + 1,
+ GRAPH_FRAME_WIDTH - 1,
+ priv->draw_width - priv->rmargin - priv->indent - 1,
+ priv->real_draw_height + GRAPH_FRAME_WIDTH - 1);
cairo_clip(cr);
for (j = 0; j < GRAPH_NUM_LINES; ++j) {
- GList *li = priv->points;
- fp = (float *) li->data;
- cairo_move_to(cr, x_offset,
- (1.0f - fp[j]) * priv->real_draw_height);
- gdk_cairo_set_source_color(cr, &(priv->colors[j]));
-
- i = 0;
- for (li = g_list_next(li); li != NULL; li = g_list_next(li)) {
- GList *lli = g_list_previous(li);
- float *lfp = (float *) lli->data;
- fp = (float *) li->data;
-
- i++;
-
- if (fp[j] == -1.0f)
- continue;
-
- cairo_curve_to(cr,
- x_offset - ((i - 0.5f) * priv->graph_delx),
- (1.0f - lfp[j]) * priv->real_draw_height + 3.5f,
- x_offset - ((i - 0.5f) * priv->graph_delx),
- (1.0f - fp[j]) * priv->real_draw_height + 3.5f,
- x_offset - (i * priv->graph_delx),
- (1.0f - fp[j]) * priv->real_draw_height + 3.5f);
- }
- cairo_stroke(cr);
+ GList *li = priv->points;
+ fp = (float *) li->data;
+ cairo_move_to(cr, x_offset,
+ (1.0f - fp[j]) * priv->real_draw_height);
+ gdk_cairo_set_source_color(cr, &(priv->colors[j]));
+
+ i = 0;
+ for (li = g_list_next(li); li != NULL; li = g_list_next(li)) {
+ GList *lli = g_list_previous(li);
+ float *lfp = (float *) lli->data;
+ fp = (float *) li->data;
+
+ i++;
+
+ if (fp[j] == -1.0f)
+ continue;
+
+ cairo_curve_to(cr,
+ x_offset - ((i - 0.5f) * priv->graph_delx),
+ (1.0f - lfp[j]) * priv->real_draw_height + 3.5f,
+ x_offset - ((i - 0.5f) * priv->graph_delx),
+ (1.0f - fp[j]) * priv->real_draw_height + 3.5f,
+ x_offset - (i * priv->graph_delx),
+ (1.0f - fp[j]) * priv->real_draw_height + 3.5f);
+ }
+ cairo_stroke(cr);
}
cairo_destroy(cr);
@@ -342,7 +342,7 @@ static void trg_torrent_graph_dispose(GObject * object)
trg_torrent_graph_stop(g);
if (priv->timer_index)
- g_source_remove(priv->timer_index);
+ g_source_remove(priv->timer_index);
trg_torrent_graph_clear_background(g);
@@ -354,11 +354,11 @@ void trg_torrent_graph_start(TrgTorrentGraph * g)
TrgTorrentGraphPrivate *priv = TRG_TORRENT_GRAPH_GET_PRIVATE(g);
if (!priv->timer_index) {
- trg_torrent_graph_update(g);
+ trg_torrent_graph_update(g);
- priv->timer_index =
- g_timeout_add(priv->speed / priv->frames_per_unit,
- trg_torrent_graph_update, g);
+ priv->timer_index =
+ g_timeout_add(priv->speed / priv->frames_per_unit,
+ trg_torrent_graph_update, g);
}
priv->draw = TRUE;
@@ -371,8 +371,8 @@ static unsigned get_max_value_element(TrgTorrentGraph * g)
int i;
for (i = 0; i < GRAPH_NUM_POINTS; i++)
- if (priv->values[i] > r)
- r = priv->values[i];
+ if (priv->values[i] > r)
+ r = priv->values[i];
return r;
}
@@ -382,7 +382,7 @@ static void trg_torrent_graph_update_net(TrgTorrentGraph * g)
TrgTorrentGraphPrivate *priv = TRG_TORRENT_GRAPH_GET_PRIVATE(g);
unsigned max, new_max, bak_max, pow2, base10, coef10, factor10,
- num_bars;
+ num_bars;
float scale;
char speed[32];
@@ -402,17 +402,17 @@ static void trg_torrent_graph_update_net(TrgTorrentGraph * g)
trg_strlspeed(speed, (gint64) (priv->out / KILOBYTE_FACTOR));
labelMarkup =
- g_markup_printf_escaped("<span font_size=\"small\" color=\""
- GRAPH_OUT_COLOR "\">%s: %s</span>",
- _("Total Uploading"), speed);
+ g_markup_printf_escaped("<span font_size=\"small\" color=\""
+ GRAPH_OUT_COLOR "\">%s: %s</span>",
+ _("Total Uploading"), speed);
gtk_label_set_markup(GTK_LABEL(priv->label_out), labelMarkup);
g_free(labelMarkup);
trg_strlspeed(speed, (gint64) (priv->in / 1024));
labelMarkup =
- g_markup_printf_escaped("<span font_size=\"small\" color=\""
- GRAPH_IN_COLOR "\">%s: %s</span>",
- _("Total Downloading"), speed);
+ g_markup_printf_escaped("<span font_size=\"small\" color=\""
+ GRAPH_IN_COLOR "\">%s: %s</span>",
+ _("Total Downloading"), speed);
gtk_label_set_markup(GTK_LABEL(priv->label_in), labelMarkup);
g_free(labelMarkup);
@@ -421,9 +421,9 @@ static void trg_torrent_graph_update_net(TrgTorrentGraph * g)
priv->cur = (priv->cur + 1) % GRAPH_NUM_POINTS;
if (max >= priv->max)
- new_max = max;
+ new_max = max;
else
- new_max = get_max_value_element(g);
+ new_max = get_max_value_element(g);
bak_max = new_max;
new_max = 1.1 * new_max;
@@ -437,25 +437,25 @@ static void trg_torrent_graph_update_net(TrgTorrentGraph * g)
num_bars = trg_torrent_graph_get_num_bars(g);
if (coef10 % num_bars != 0)
- coef10 = coef10 + (num_bars - coef10 % num_bars);
+ coef10 = coef10 + (num_bars - coef10 % num_bars);
new_max = coef10 * (1UL << (base10 * 10));
if (bak_max > new_max) {
- new_max = bak_max;
+ new_max = bak_max;
}
if ((0.8 * priv->max) < new_max && new_max <= priv->max)
- return;
+ return;
scale = 1.0f * priv->max / new_max;
for (li = priv->points; li != NULL; li = g_list_next(li)) {
- float *fp = (float *) li->data;
- if (fp[0] >= 0.0f) {
- fp[0] *= scale;
- fp[1] *= scale;
- }
+ float *fp = (float *) li->data;
+ if (fp[0] >= 0.0f) {
+ fp[0] *= scale;
+ fp[1] *= scale;
+ }
}
priv->max = new_max;
@@ -464,10 +464,10 @@ static void trg_torrent_graph_update_net(TrgTorrentGraph * g)
}
static GObject *trg_torrent_graph_constructor(GType type,
- guint
- n_construct_properties,
- GObjectConstructParam *
- construct_params)
+ guint
+ n_construct_properties,
+ GObjectConstructParam *
+ construct_params)
{
GObject *object;
TrgTorrentGraphPrivate *priv;
@@ -475,10 +475,10 @@ static GObject *trg_torrent_graph_constructor(GType type,
int i;
object =
- G_OBJECT_CLASS
- (trg_torrent_graph_parent_class)->constructor(type,
- n_construct_properties,
- construct_params);
+ G_OBJECT_CLASS
+ (trg_torrent_graph_parent_class)->constructor(type,
+ n_construct_properties,
+ construct_params);
priv = TRG_TORRENT_GRAPH_GET_PRIVATE(object);
priv->draw_width = 0;
@@ -526,9 +526,9 @@ static GObject *trg_torrent_graph_constructor(GType type,
priv->disp = gtk_drawing_area_new();
g_signal_connect(G_OBJECT(priv->disp), "expose_event",
- G_CALLBACK(trg_torrent_graph_expose), object);
+ G_CALLBACK(trg_torrent_graph_expose), object);
g_signal_connect(G_OBJECT(priv->disp), "configure_event",
- G_CALLBACK(trg_torrent_graph_configure), object);
+ G_CALLBACK(trg_torrent_graph_configure), object);
gtk_widget_set_events(priv->disp, GDK_EXPOSURE_MASK);
@@ -536,10 +536,10 @@ static GObject *trg_torrent_graph_constructor(GType type,
priv->points = NULL;
for (i = 0; i < GRAPH_NUM_DATA_BLOCK_ELEMENTS; i++) {
- priv->data_block[i] = -1.0f;
- if (i % GRAPH_NUM_LINES == 0)
- priv->points =
- g_list_append(priv->points, &priv->data_block[i]);
+ priv->data_block[i] = -1.0f;
+ if (i % GRAPH_NUM_LINES == 0)
+ priv->points =
+ g_list_append(priv->points, &priv->data_block[i]);
}
return object;
@@ -583,8 +583,8 @@ void trg_torrent_graph_clear_background(TrgTorrentGraph * g)
TrgTorrentGraphPrivate *priv = TRG_TORRENT_GRAPH_GET_PRIVATE(g);
if (priv->background) {
- g_object_unref(priv->background);
- priv->background = NULL;
+ g_object_unref(priv->background);
+ priv->background = NULL;
}
}
@@ -593,18 +593,18 @@ static gboolean trg_torrent_graph_update(gpointer user_data)
{
TrgTorrentGraph *g = TRG_TORRENT_GRAPH(user_data);
TrgTorrentGraphPrivate *priv =
- TRG_TORRENT_GRAPH_GET_PRIVATE(user_data);
+ TRG_TORRENT_GRAPH_GET_PRIVATE(user_data);
if (priv->render_counter == priv->frames_per_unit - 1)
- trg_torrent_graph_update_net(g);
+ trg_torrent_graph_update_net(g);
if (priv->draw)
- trg_torrent_graph_draw(g);
+ trg_torrent_graph_draw(g);
priv->render_counter++;
if (priv->render_counter >= priv->frames_per_unit)
- priv->render_counter = 0;
+ priv->render_counter = 0;
return TRUE;
}
@@ -617,18 +617,18 @@ unsigned trg_torrent_graph_get_num_bars(TrgTorrentGraph * g)
switch ((int) (priv->draw_height / (priv->fontsize + 14))) {
case 0:
case 1:
- n = 1;
- break;
+ n = 1;
+ break;
case 2:
case 3:
- n = 2;
- break;
+ n = 2;
+ break;
case 4:
- n = 4;
- break;
+ n = 4;
+ break;
default:
- n = 5;
- break;
+ n = 5;
+ break;
}
return n;