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

« back to all changes in this revision

Viewing changes to src/ui/gtk/downloads_common.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: downloads_common.c,v 1.5 2005/07/01 09:35:51 daichik Exp $
 
3
 *
 
4
 * Copyright (c) 2001-2003, Raphael Manfredi, Richard Eckart
 
5
 *
 
6
 *----------------------------------------------------------------------
 
7
 * This file is part of gtk-gnutella.
 
8
 *
 
9
 *  gtk-gnutella is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  gtk-gnutella is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with gtk-gnutella; if not, write to the Free Software
 
21
 *  Foundation, Inc.:
 
22
 *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 *----------------------------------------------------------------------
 
24
 */
 
25
 
 
26
#include "gui.h"
 
27
 
 
28
RCSID("$Id: downloads_common.c,v 1.5 2005/07/01 09:35:51 daichik Exp $");
 
29
#include "downloads_common.h"
 
30
#include "downloads.h"
 
31
#include "statusbar.h"
 
32
 
 
33
#ifdef USE_GTK2
 
34
#include "gtk2/downloads_cb.h"
 
35
#endif
 
36
#ifdef USE_GTK1
 
37
#include "gtk1/downloads_cb.h"
 
38
#endif
 
39
 
 
40
#include "if/bridge/ui2c.h"
 
41
#include "if/gui_property_priv.h"
 
42
 
 
43
#include "lib/override.h"               /* Must be the last header included */
 
44
 
 
45
#define IO_STALLED              60              /**< If nothing exchanged after that many secs */
 
46
#define IO_AVG_RATE             5               /**< Compute global recv rate every 5 secs */
 
47
 
 
48
static gboolean update_download_clear_needed = FALSE;
 
49
 
 
50
/**
 
51
 * Remember that we need to check for cleared downloads at the next
 
52
 * invocation of gui_update_download_clear_now(), which happens once
 
53
 * every second only to avoid too frequent costly list traversals.
 
54
 */
 
55
void
 
56
gui_update_download_clear(void)
 
57
{
 
58
        update_download_clear_needed = TRUE;
 
59
}
 
60
 
 
61
/**
 
62
 *      Checks if there are any active downloads that are clearable
 
63
 *  If so, this activates the "Clear Stopped" button
 
64
 */
 
65
void
 
66
gui_update_download_clear_now(void)
 
67
{
 
68
        if (!update_download_clear_needed)
 
69
                return;
 
70
 
 
71
        gtk_widget_set_sensitive(
 
72
        lookup_widget(main_window, "button_downloads_clear_stopped"),
 
73
        guc_download_something_to_clear());
 
74
}
 
75
 
 
76
/**
 
77
 *      Checks if the download queue is frozen, if so update the freeze queue
 
78
 *  widgets and display a message on the statusbar
 
79
 */
 
80
void
 
81
gui_update_queue_frozen(void)
 
82
{
 
83
    static gboolean msg_displayed = FALSE;
 
84
    static statusbar_msgid_t id = {0, 0};
 
85
 
 
86
    GtkWidget *togglebutton_queue_freeze;
 
87
 
 
88
    togglebutton_queue_freeze =
 
89
        lookup_widget(main_window, "togglebutton_queue_freeze");
 
90
 
 
91
    if (gui_debug >= 3)
 
92
                g_message("frozen %i, msg %i\n",
 
93
                        guc_download_queue_is_frozen(),
 
94
                (gint) msg_displayed);
 
95
 
 
96
    if (guc_download_queue_is_frozen() > 0) {
 
97
#ifdef USE_GTK1
 
98
        gtk_widget_hide(lookup_widget(main_window, "vbox_queue_freeze"));
 
99
        gtk_widget_show(lookup_widget(main_window, "vbox_queue_thaw"));
 
100
#endif
 
101
        /*
 
102
                gtk_label_set_text(
 
103
            GTK_LABEL(GTK_BIN(togglebutton_queue_freeze)->child),
 
104
                        "Thaw queue");
 
105
                */
 
106
        if (!msg_displayed) {
 
107
            msg_displayed = TRUE;
 
108
                id = statusbar_gui_message(0, "QUEUE FROZEN");
 
109
        }
 
110
    } else {
 
111
#ifdef USE_GTK1
 
112
        gtk_widget_show(lookup_widget(main_window, "vbox_queue_freeze"));
 
113
        gtk_widget_hide(lookup_widget(main_window, "vbox_queue_thaw"));
 
114
#endif
 
115
        /*
 
116
                gtk_label_set_text(
 
117
            GTK_LABEL(GTK_BIN(togglebutton_queue_freeze)->child),
 
118
                        "Freeze queue");
 
119
                */
 
120
        if (msg_displayed) {
 
121
            msg_displayed = FALSE;
 
122
            statusbar_gui_remove(id);
 
123
        }
 
124
        }
 
125
 
 
126
    gtk_signal_handler_block_by_func(
 
127
        GTK_OBJECT(togglebutton_queue_freeze),
 
128
        GTK_SIGNAL_FUNC(on_togglebutton_queue_freeze_toggled),
 
129
        NULL);
 
130
 
 
131
    gtk_toggle_button_set_active(
 
132
        GTK_TOGGLE_BUTTON(togglebutton_queue_freeze),
 
133
        guc_download_queue_is_frozen() > 0);
 
134
 
 
135
    gtk_signal_handler_unblock_by_func(
 
136
        GTK_OBJECT(togglebutton_queue_freeze),
 
137
        GTK_SIGNAL_FUNC(on_togglebutton_queue_freeze_toggled),
 
138
        NULL);
 
139
}
 
140
 
 
141
/**
 
142
 * Enable the "start now" menu entry for queued items.
 
143
 */
 
144
void
 
145
gui_download_enable_start_now(guint32 running_downloads, guint32 max_downloads)
 
146
{
 
147
        GtkWidget *w = lookup_widget(popup_queue, "popup_queue_start_now");
 
148
        gboolean selected = TRUE;
 
149
 
 
150
#ifdef USE_GTK1
 
151
        selected = GTK_CLIST(
 
152
                lookup_widget(main_window, "ctree_downloads_queue"))->selection != NULL;
 
153
#endif
 
154
        gtk_widget_set_sensitive(w, selected && running_downloads < max_downloads);
 
155
}
 
156
 
 
157
 
 
158
/**
 
159
 *      Clear all stopped, complete, and unavailable downloads.
 
160
 */
 
161
void
 
162
on_button_downloads_clear_stopped_clicked(GtkButton *unused_button,
 
163
        gpointer unused_udata)
 
164
{
 
165
        (void) unused_button;
 
166
        (void) unused_udata;
 
167
        guc_download_clear_stopped(TRUE, TRUE, TRUE, TRUE);
 
168
}
 
169
 
 
170
 
 
171
/**
 
172
 *      Freeze the downloads queue.
 
173
 */
 
174
void on_togglebutton_queue_freeze_toggled(GtkToggleButton *togglebutton,
 
175
        gpointer unused_udata)
 
176
{
 
177
        (void) unused_udata;
 
178
 
 
179
    if (gtk_toggle_button_get_active(togglebutton)) {
 
180
        guc_download_freeze_queue();
 
181
    } else {
 
182
        guc_download_thaw_queue();
 
183
    }
 
184
}
 
185
 
 
186
/* vi: set ts=4 sw=4 cindent: */