~ubuntu-branches/ubuntu/karmic/gtk-gnutella/karmic

« back to all changes in this revision

Viewing changes to src/ui/gtk/gtk1/upload_stats.c

  • Committer: Bazaar Package Importer
  • Author(s): Anand Kumria
  • Date: 2005-08-04 11:32:05 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050804113205-q746i4lgo3rtlegn
Tags: 0.95.4-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: upload_stats.c,v 1.5 2005/06/29 14:24:28 daichik Exp $
 
3
 *
 
4
 * Copyright (c) 2001-2003, Richard Eckart
 
5
 * Copyright (c) 2002, Michael Tesch
 
6
 *
 
7
 *----------------------------------------------------------------------
 
8
 * This file is part of gtk-gnutella.
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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
 
22
 *  Foundation, Inc.:
 
23
 *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 *----------------------------------------------------------------------
 
25
 */
 
26
 
 
27
/**
 
28
 * @ingroup gtk
 
29
 * @file
 
30
 *
 
31
 * Keep track of which files we send away, and how often.
 
32
 *
 
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.
 
37
 *
 
38
 * This could be extended to keep the entire path to each file and
 
39
 * optionally show the entire path, but..
 
40
 *
 
41
 * The 'upload_history' file has the following format:
 
42
 *
 
43
 *              - "<url-escaped filename> <file size> <attempts> <completions>"
 
44
 *
 
45
 * @todo
 
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).
 
49
 *
 
50
 * @author Raphael Manfredi
 
51
 * @date 2001-2004
 
52
 * @author Michael Tesch
 
53
 * @date 2002
 
54
 *
 
55
 * Released with gtk-gnutella & its license
 
56
 */
 
57
 
 
58
#include "gtk/gui.h"
 
59
 
 
60
RCSID("$Id: upload_stats.c,v 1.5 2005/06/29 14:24:28 daichik Exp $");
 
61
 
 
62
#include "gtk/upload_stats.h"
 
63
#include "gtk/columns.h"
 
64
 
 
65
#include "lib/misc.h"
 
66
#include "lib/glib-missing.h"
 
67
#include "lib/override.h"               /* Must be the last header included */
 
68
 
 
69
/* Private variables */
 
70
static gint ul_rows = 0;
 
71
 
 
72
/* Private functions */
 
73
 
 
74
/**
 
75
 * This is me, dreaming of gtk 2.0...
 
76
 */
 
77
static gint
 
78
ul_find_row_by_upload(const gchar *name, guint64 size, struct ul_stats **s)
 
79
{
 
80
        gint i;
 
81
    GtkCList *clist =
 
82
        GTK_CLIST(lookup_widget(main_window, "clist_ul_stats"));
 
83
 
 
84
        /* go through the clist_ul_stats, looking for the file...
 
85
         * blame gtk/glib, not me...
 
86
         */
 
87
        for (i = 0; i < ul_rows; i++) {
 
88
                gchar *filename;
 
89
                struct ul_stats *us;
 
90
 
 
91
                us = gtk_clist_get_row_data(clist, i);
 
92
 
 
93
                if (us->size != size)
 
94
                        continue;
 
95
 
 
96
                gtk_clist_get_text(clist, i,
 
97
                        c_us_filename, &filename);
 
98
 
 
99
                if (0 == strcmp(filename, name)) {
 
100
                        *s = us;
 
101
                        return i;
 
102
                }
 
103
        }
 
104
        return -1;
 
105
}
 
106
 
 
107
/* Public functions */
 
108
void
 
109
upload_stats_gui_init(void)
 
110
{
 
111
}
 
112
 
 
113
void
 
114
upload_stats_gui_shutdown(void)
 
115
{
 
116
}
 
117
 
 
118
void
 
119
upload_stats_gui_add(struct ul_stats *s)
 
120
{
 
121
        gchar *rowdata[5];
 
122
        gint row;
 
123
        gchar size_tmp[16];
 
124
        gchar attempts_tmp[16];
 
125
        gchar complete_tmp[16];
 
126
        gchar norm_tmp[16];
 
127
    GtkCList *clist = GTK_CLIST(lookup_widget(main_window, "clist_ul_stats"));
 
128
 
 
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);
 
133
 
 
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;
 
139
 
 
140
    row = gtk_clist_insert(clist, 0, rowdata);
 
141
        ul_rows++;
 
142
 
 
143
        gtk_clist_set_row_data_full(clist, row, s, NULL);
 
144
 
 
145
    /* FIXME: should use auto_sort? */
 
146
        gtk_clist_sort(clist);
 
147
}
 
148
 
 
149
 
 
150
/**
 
151
 * Called when a row of the upload stats should be updated
 
152
 */
 
153
void
 
154
upload_stats_gui_update(const gchar *name, guint64 size)
 
155
{
 
156
        GtkCList *clist;
 
157
        gint row;
 
158
        struct ul_stats *s;
 
159
        static gchar tmpstr[16];
 
160
 
 
161
        /* find this file in the clist_ul_stats */
 
162
        row = ul_find_row_by_upload(name, size, &s);
 
163
        if (-1 == row) {
 
164
                g_assert_not_reached();
 
165
                return;
 
166
        }
 
167
 
 
168
        clist = GTK_CLIST(lookup_widget(main_window, "clist_ul_stats"));
 
169
 
 
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);
 
178
 
 
179
        /* FIXME: use auto-sort? */
 
180
        gtk_clist_sort(clist);
 
181
}
 
182
 
 
183
void
 
184
upload_stats_gui_clear_all(void)
 
185
{
 
186
    GtkCList *clist =
 
187
        GTK_CLIST(lookup_widget(main_window, "clist_ul_stats"));
 
188
 
 
189
        gtk_clist_clear(clist);
 
190
        ul_rows = 0;
 
191
}
 
192
 
 
193
/* vi: set ts=4 sw=4 cindent: */