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

« back to all changes in this revision

Viewing changes to src/ui/gtk/gtk1/monitor.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: monitor.c,v 1.6 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
/**
 
27
 * @ingroup gtk
 
28
 * @file
 
29
 *
 
30
 * GUI stuff used by 'share.c'.
 
31
 *
 
32
 * @author Raphael Manfredi
 
33
 * @author Richard Eckart
 
34
 * @date 2001-2003
 
35
 */
 
36
 
 
37
#include "gtk/gui.h"
 
38
 
 
39
RCSID("$Id: monitor.c,v 1.6 2005/07/01 09:35:51 daichik Exp $");
 
40
 
 
41
#include "gtk/monitor.h"
 
42
 
 
43
#include "if/core/share.h"
 
44
#include "if/gui_property_priv.h"
 
45
#include "if/bridge/ui2c.h"
 
46
 
 
47
#include "lib/misc.h"
 
48
#include "lib/glib-missing.h"
 
49
#include "lib/override.h"               /* Must be the last header included */
 
50
 
 
51
/***
 
52
 *** Private variables
 
53
 ***/
 
54
 
 
55
static guint32 monitor_items = 0;
 
56
 
 
57
/***
 
58
 *** Callbacks
 
59
 ***/
 
60
 
 
61
static void
 
62
monitor_gui_append_to_monitor(query_type_t type, const gchar *item,
 
63
        guint32 unused_ip, guint16 unused_port)
 
64
{
 
65
    static GtkWidget *clist_monitor = NULL;
 
66
 
 
67
        (void) unused_ip;
 
68
        (void) unused_port;
 
69
 
 
70
    if (clist_monitor == NULL) {
 
71
        clist_monitor = lookup_widget(main_window, "clist_monitor");
 
72
        g_assert(clist_monitor != NULL);
 
73
    }
 
74
 
 
75
        gtk_clist_freeze(GTK_CLIST(clist_monitor));
 
76
 
 
77
        for (/* empty */; monitor_items >= monitor_max_items; monitor_items--) {
 
78
                gint row = GTK_CLIST(clist_monitor)->rows - 1;
 
79
 
 
80
                if (row < 0)
 
81
                        break;
 
82
 
 
83
        gtk_clist_remove(GTK_CLIST(clist_monitor), row);
 
84
        }
 
85
 
 
86
        if (monitor_max_items > 0) {
 
87
        gchar *titles[1];
 
88
        gchar tmpstr[100];
 
89
 
 
90
        if (type == QUERY_SHA1) {
 
91
                /* If the query is empty and we have a SHA1 extension,
 
92
                 * we print a urn:sha1-query instead. */
 
93
                gm_snprintf(tmpstr, sizeof(tmpstr), "urn:sha1:%s", item);
 
94
        } else {
 
95
                g_strlcpy(tmpstr, item, sizeof(tmpstr));
 
96
        }
 
97
 
 
98
        titles[0] = tmpstr;
 
99
                gtk_clist_prepend(GTK_CLIST(clist_monitor), titles);
 
100
        monitor_items++;
 
101
        }
 
102
 
 
103
        gtk_clist_thaw(GTK_CLIST(clist_monitor));
 
104
}
 
105
 
 
106
 
 
107
 
 
108
 
 
109
/***
 
110
 *** Public functions
 
111
 ***/
 
112
 
 
113
void
 
114
monitor_gui_init(void)
 
115
{
 
116
    gtk_clist_column_titles_passive
 
117
        (GTK_CLIST(lookup_widget(main_window, "clist_monitor")));
 
118
}
 
119
 
 
120
void
 
121
monitor_gui_shutdown(void)
 
122
{
 
123
    monitor_gui_enable_monitor(FALSE);
 
124
}
 
125
 
 
126
/**
 
127
 * Remove all but the first n items from the monitor.
 
128
 */
 
129
void
 
130
monitor_gui_clear_monitor(void)
 
131
{
 
132
    GtkWidget *clist_monitor;
 
133
 
 
134
    clist_monitor = lookup_widget(main_window, "clist_monitor");
 
135
 
 
136
    gtk_clist_clear(GTK_CLIST(clist_monitor));
 
137
        monitor_items = 0;
 
138
}
 
139
 
 
140
/**
 
141
 * Enable/disable monitor.
 
142
 */
 
143
void
 
144
monitor_gui_enable_monitor(const gboolean val)
 
145
{
 
146
    static gboolean registered = FALSE;
 
147
    gtk_widget_set_sensitive
 
148
        (lookup_widget(main_window, "clist_monitor"), !val);
 
149
 
 
150
    if (val != registered) {
 
151
        if (val) {
 
152
            guc_share_add_search_request_listener
 
153
                (monitor_gui_append_to_monitor);
 
154
        } else {
 
155
            guc_share_remove_search_request_listener
 
156
                (monitor_gui_append_to_monitor);
 
157
        }
 
158
        registered = val;
 
159
    }
 
160
}
 
161
 
 
162
/* vi: set ts=4 sw=4 cindent: */