2
* $Id: upload_stats.c,v 1.5 2005/06/29 14:24:28 daichik Exp $
4
* Copyright (c) 2001-2003, Richard Eckart
5
* Copyright (c) 2002, Michael Tesch
7
*----------------------------------------------------------------------
8
* This file is part of gtk-gnutella.
10
* gtk-gnutella is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* gtk-gnutella is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with gtk-gnutella; if not, write to the Free Software
23
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
*----------------------------------------------------------------------
31
* Keep track of which files we send away, and how often.
33
* Statistics are kept by _FILENAME_ and file size, not by actual path,
34
* so two files with the same name and size will be counted in the same
35
* bin. I dont see this as a limitation because the user wouldn't be able
36
* to differentiate the files anyway.
38
* This could be extended to keep the entire path to each file and
39
* optionally show the entire path, but..
41
* The 'upload_history' file has the following format:
43
* - "<url-escaped filename> <file size> <attempts> <completions>"
46
* TODO: Add a check to make sure that all of the files still exist(?)
47
* grey them out if they dont, optionally remove them from the stats
48
* list (when 'Clear Non-existant Files' is clicked).
50
* @author Raphael Manfredi
52
* @author Michael Tesch
55
* Released with gtk-gnutella & its license
60
RCSID("$Id: upload_stats.c,v 1.5 2005/06/29 14:24:28 daichik Exp $");
62
#include "gtk/upload_stats.h"
63
#include "gtk/columns.h"
66
#include "lib/glib-missing.h"
67
#include "lib/override.h" /* Must be the last header included */
69
/* Private variables */
70
static gint ul_rows = 0;
72
/* Private functions */
75
* This is me, dreaming of gtk 2.0...
78
ul_find_row_by_upload(const gchar *name, guint64 size, struct ul_stats **s)
82
GTK_CLIST(lookup_widget(main_window, "clist_ul_stats"));
84
/* go through the clist_ul_stats, looking for the file...
85
* blame gtk/glib, not me...
87
for (i = 0; i < ul_rows; i++) {
91
us = gtk_clist_get_row_data(clist, i);
96
gtk_clist_get_text(clist, i,
97
c_us_filename, &filename);
99
if (0 == strcmp(filename, name)) {
107
/* Public functions */
109
upload_stats_gui_init(void)
114
upload_stats_gui_shutdown(void)
119
upload_stats_gui_add(struct ul_stats *s)
124
gchar attempts_tmp[16];
125
gchar complete_tmp[16];
127
GtkCList *clist = GTK_CLIST(lookup_widget(main_window, "clist_ul_stats"));
129
g_strlcpy(size_tmp, short_size(s->size), sizeof(size_tmp));
130
gm_snprintf(attempts_tmp, sizeof(attempts_tmp), "%u", s->attempts);
131
gm_snprintf(complete_tmp, sizeof(complete_tmp), "%u", s->complete);
132
gm_snprintf(norm_tmp, sizeof(norm_tmp), "%.3f", s->norm);
134
rowdata[c_us_filename] = s->filename;
135
rowdata[c_us_size] = size_tmp;
136
rowdata[c_us_attempts] = attempts_tmp;
137
rowdata[c_us_complete] = complete_tmp;
138
rowdata[c_us_norm] = norm_tmp;
140
row = gtk_clist_insert(clist, 0, rowdata);
143
gtk_clist_set_row_data_full(clist, row, s, NULL);
145
/* FIXME: should use auto_sort? */
146
gtk_clist_sort(clist);
151
* Called when a row of the upload stats should be updated
154
upload_stats_gui_update(const gchar *name, guint64 size)
159
static gchar tmpstr[16];
161
/* find this file in the clist_ul_stats */
162
row = ul_find_row_by_upload(name, size, &s);
164
g_assert_not_reached();
168
clist = GTK_CLIST(lookup_widget(main_window, "clist_ul_stats"));
170
/* set attempt cell contents */
171
gm_snprintf(tmpstr, sizeof(tmpstr), "%d", s->attempts);
172
gtk_clist_set_text(clist, row, c_us_attempts, tmpstr);
173
gm_snprintf(tmpstr, sizeof(tmpstr), "%d", s->complete);
174
gtk_clist_set_text(clist, row, c_us_complete, tmpstr);
175
s->norm = (gfloat) s->bytes_sent / (gfloat) s->size;
176
gm_snprintf(tmpstr, sizeof(tmpstr), "%.3f", s->norm);
177
gtk_clist_set_text(clist, row, c_us_norm, tmpstr);
179
/* FIXME: use auto-sort? */
180
gtk_clist_sort(clist);
184
upload_stats_gui_clear_all(void)
187
GTK_CLIST(lookup_widget(main_window, "clist_ul_stats"));
189
gtk_clist_clear(clist);
193
/* vi: set ts=4 sw=4 cindent: */