summaryrefslogtreecommitdiff
path: root/src/trg-torrent-graph.c.glg
blob: 9479717412ef0f6eb32993c2cb430f4c6015daeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * transmission-remote-gtk - Transmission RPC client for GTK
 * Copyright (C) 2011  Alan Fitton

 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <stdint.h>
#include <gtk/gtk.h>

#include "util.h"
#include "glg.h"
#include "trg-torrent-model.h"
#include "trg-torrent-graph.h"

/*enum {
    PROP_0,
    PROP_SIZE_VALUE
};*/

G_DEFINE_TYPE(TrgTorrentGraph, trg_torrent_graph,
        GLG_TYPE_LINE_GRAPH)
#define TRG_TORRENT_GRAPH_GET_PRIVATE(o) \
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRG_TYPE_TORRENT_GRAPH, TrgTorrentGraphPrivate))
typedef struct _TrgTorrentGraphPrivate TrgTorrentGraphPrivate;

struct _TrgTorrentGraphPrivate {
    gint global_down_id;
    gint global_up_id;
};

static void
trg_torrent_graph_class_init(TrgTorrentGraphClass * klass)
{
    /*GObjectClass *object_class = G_OBJECT_CLASS(klass);*/
    g_type_class_add_private(klass, sizeof(TrgTorrentGraphPrivate));
}

static void trg_torrent_graph_init(TrgTorrentGraph * self)
{

}

void trg_torrent_graph_update(TrgTorrentGraph *g, trg_torrent_model_update_stats *global)
{
    TrgTorrentGraphPrivate *priv = TRG_TORRENT_GRAPH_GET_PRIVATE(g);


    glg_line_graph_data_series_add_value (GLG_LINE_GRAPH(g), priv->global_down_id, (gdouble)global->downRateTotal/1024);
    glg_line_graph_data_series_add_value (GLG_LINE_GRAPH(g), priv->global_up_id, (gdouble)global->upRateTotal/1024);

    glg_line_graph_redraw (GLG_LINE_GRAPH(g));
}

TrgTorrentGraph *trg_torrent_graph_new(void)
{
    TrgTorrentGraphPrivate *priv;

    GObject *glg = g_object_new(TRG_TYPE_TORRENT_GRAPH,
            "range-tick-minor-x", 1,
            "range-tick-major-x", 120,
            "range-scale-minor-x", 0,
            "range-scale-major-x", 120,
            "range-tick-minor-y", 1,
            "range-tick-major-y", 10,
            "range-scale-minor-y", 0,
            "range-scale-major-y", 10,
            NULL);

    priv = TRG_TORRENT_GRAPH_GET_PRIVATE(glg);

    g_object_set (glg, "chart-set-elements",
            GLG_GRID_LABELS_Y | GLG_GRID_LINES, NULL);

     g_object_set (glg, "series-line-width", 3, NULL);

     g_object_set (glg,
             "graph-title-foreground",  "blue",
             "graph-scale-foreground",  "blue",
                        "graph-chart-background",  "white",
                        "graph-window-background", "white",
                        NULL);

     g_object_set (glg, "text-title-yaxis", "Speed",
                        "text-title-xaxis", "Time",
                        NULL);

     priv->global_down_id = glg_line_graph_data_series_add (GLG_LINE_GRAPH(glg), "Global Down KB/s", "green");
     priv->global_up_id = glg_line_graph_data_series_add (GLG_LINE_GRAPH(glg), "Global Up KB/s", "red");

     glg_line_graph_redraw (GLG_LINE_GRAPH(glg));

    return TRG_TORRENT_GRAPH(glg);
}