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

« back to all changes in this revision

Viewing changes to src/ui/gtk/upload_stats_cb.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_cb.c,v 1.5 2005/06/25 01:37:44 daichik Exp $
 
3
 *
 
4
 * Copyright (c) 2003, Raphael Manfredi
 
5
 * Copyright (c) 2001-2003, Richard Eckart
 
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
 * Handles common GUI operations for upload stats.
 
32
 *
 
33
 * @author Raphael Manfredi
 
34
 * @date 2003
 
35
 * @author Richard Eckart
 
36
 * @date 2001-2003
 
37
 */
 
38
 
 
39
#include "gui.h"
 
40
 
 
41
RCSID("$Id: upload_stats_cb.c,v 1.5 2005/06/25 01:37:44 daichik Exp $");
 
42
 
 
43
#include "upload_stats_cb.h"
 
44
#include "upload_stats.h"
 
45
#include "gtkcolumnchooser.h"
 
46
#include "columns.h"
 
47
 
 
48
#include "if/bridge/ui2c.h"
 
49
#include "if/gui_property_priv.h"
 
50
 
 
51
#include "lib/override.h"               /* Must be the last header included */
 
52
 
 
53
 
 
54
/***
 
55
 *** Upload Stats pane
 
56
 ***/
 
57
 
 
58
void
 
59
on_button_ul_stats_clear_all_clicked(GtkButton *unused_button,
 
60
        gpointer unused_data)
 
61
{
 
62
        (void) unused_button;
 
63
        (void) unused_data;
 
64
        guc_upload_stats_clear_all();
 
65
}
 
66
 
 
67
void
 
68
on_button_ul_stats_clear_deleted_clicked(GtkButton *unused_button,
 
69
        gpointer unused_data)
 
70
{
 
71
        (void) unused_button;
 
72
        (void) unused_data;
 
73
        guc_upload_stats_prune_nonexistent();
 
74
}
 
75
 
 
76
 
 
77
#ifdef USE_GTK1
 
78
static gint
 
79
compare_ul_size(GtkCList *unused_clist, gconstpointer ptr1, gconstpointer ptr2)
 
80
{
 
81
        guint32 s1;
 
82
        guint32 s2;
 
83
 
 
84
        (void) unused_clist;
 
85
        s1 = ((const struct ul_stats *) ((const GtkCListRow *) ptr1)->data)->size;
 
86
        s2 = ((const struct ul_stats *) ((const GtkCListRow *) ptr2)->data)->size;
 
87
 
 
88
        return (s1 == s2) ? 0 : (s1 > s2) ? 1 : -1;
 
89
}
 
90
 
 
91
/**
 
92
 * first by complete, then by attempts
 
93
 */
 
94
static gint
 
95
compare_ul_complete(GtkCList *unused_clist,
 
96
        gconstpointer ptr1, gconstpointer ptr2)
 
97
{
 
98
        guint32 a1 = ((const struct ul_stats *)
 
99
                ((const GtkCListRow *) ptr1)->data)->attempts;
 
100
        guint32 a2 = ((const struct ul_stats *)
 
101
                ((const GtkCListRow *) ptr2)->data)->attempts;
 
102
        guint32 c1 = ((const struct ul_stats *)
 
103
                ((const GtkCListRow *) ptr1)->data)->complete;
 
104
        guint32 c2 = ((const struct ul_stats *)
 
105
                ((const GtkCListRow *) ptr2)->data)->complete;
 
106
 
 
107
        (void) unused_clist;
 
108
        return (c1 != c2) ? ((c1 > c2) ? 1 : -1) :
 
109
                (a1 == a2) ? 0 : (a1 > a2) ? 1 : -1;
 
110
}
 
111
 
 
112
/**
 
113
 * first by normalized, then by complete
 
114
 */
 
115
gint
 
116
compare_ul_norm(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
 
117
{
 
118
        gfloat n1;
 
119
        gfloat n2;
 
120
 
 
121
        n1 = ((const struct ul_stats *) ((const GtkCListRow *) ptr1)->data)->norm;
 
122
        n2 = ((const struct ul_stats *) ((const GtkCListRow *) ptr2)->data)->norm;
 
123
 
 
124
        return (n1 != n2) ? ((n1 > n2) ? 1 : -1) :
 
125
                compare_ul_complete(clist, ptr1, ptr2);
 
126
}
 
127
 
 
128
/**
 
129
 * first by attempts, then by complete
 
130
 */
 
131
static gint
 
132
compare_ul_attempts(GtkCList *unused_clist,
 
133
        gconstpointer ptr1, gconstpointer ptr2)
 
134
{
 
135
        guint32 a1 = ((const struct ul_stats *)
 
136
                ((const GtkCListRow *) ptr1)->data)->attempts;
 
137
        guint32 a2 = ((const struct ul_stats *)
 
138
                ((const GtkCListRow *) ptr2)->data)->attempts;
 
139
        guint32 c1 = ((const struct ul_stats *)
 
140
                ((const GtkCListRow *) ptr1)->data)->complete;
 
141
        guint32 c2 = ((const struct ul_stats *)
 
142
                ((const GtkCListRow *) ptr2)->data)->complete;
 
143
 
 
144
        (void) unused_clist;
 
145
        return (a1 != a2) ? ((a1 > a2) ? 1 : -1) :
 
146
                (c1 == c2) ? 0 : (c1 > c2) ? 1 : -1;
 
147
}
 
148
 
 
149
void
 
150
on_clist_ul_stats_click_column(GtkCList *clist, gint column,
 
151
        gpointer unused_udata)
 
152
{
 
153
        static gint ul_sort_column = 2;
 
154
        static gint ul_sort_order = GTK_SORT_DESCENDING;
 
155
 
 
156
        (void) unused_udata;
 
157
        switch (column) {
 
158
        case c_us_filename:
 
159
                gtk_clist_set_compare_func(clist, NULL);
 
160
                break;
 
161
        case c_us_size:
 
162
                gtk_clist_set_compare_func(clist, compare_ul_size);
 
163
                break;
 
164
        case c_us_attempts:
 
165
                gtk_clist_set_compare_func(clist, compare_ul_attempts);
 
166
                break;
 
167
        case c_us_complete:
 
168
                gtk_clist_set_compare_func(clist, compare_ul_complete);
 
169
                break;
 
170
        case c_us_norm:
 
171
                gtk_clist_set_compare_func(clist, compare_ul_norm);
 
172
                break;
 
173
        default:
 
174
                g_assert_not_reached();
 
175
        }
 
176
 
 
177
        if (column == ul_sort_column) {
 
178
                ul_sort_order = (ul_sort_order == GTK_SORT_DESCENDING) ?
 
179
                        GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
 
180
        } else {
 
181
                ul_sort_column = column;
 
182
        }
 
183
        gtk_clist_set_sort_type(clist, ul_sort_order);
 
184
        gtk_clist_set_sort_column(clist, column);
 
185
        gtk_clist_sort(clist);
 
186
}
 
187
 
 
188
void
 
189
on_clist_ul_stats_resize_column(GtkCList *unused_clist,
 
190
        gint column, gint width, gpointer unused_udata)
 
191
{
 
192
        (void) unused_clist;
 
193
        (void) unused_udata;
 
194
    /* FIXME: use properties */
 
195
        *(gint *) &ul_stats_col_widths[column] = width;
 
196
}
 
197
 
 
198
#endif /* USE_GTK1*/
 
199
 
 
200
#ifdef USE_GTK2
 
201
void
 
202
on_popup_upload_stats_config_cols_activate(GtkMenuItem *unused_menuitem,
 
203
        gpointer unused_udata)
 
204
{
 
205
    GtkWidget *cc;
 
206
 
 
207
        (void) unused_menuitem;
 
208
        (void) unused_udata;
 
209
    cc = gtk_column_chooser_new(
 
210
                        lookup_widget(main_window, "treeview_ul_stats"));
 
211
    gtk_menu_popup(GTK_MENU(cc), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME);
 
212
}
 
213
#endif /* USE_GTK2 */
 
214
 
 
215
/* vi: set ts=4 sw=4: */