Mercurial > pidgin.yaz
annotate src/ticker.c @ 2307:64dd9e99884c
[gaim-migrate @ 2317]
hi
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 19 Sep 2001 00:55:49 +0000 |
parents | 24aed1c31342 |
children | bd9d403fb15b |
rev | line source |
---|---|
430 | 1 /* GTK - The GIMP Toolkit |
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Library General Public | |
15 * License along with this library; if not, write to the | |
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 * Boston, MA 02111-1307, USA. | |
18 */ | |
19 | |
20 /* | |
21 * ticker.c -- Syd Logan, Summer 2000 | |
22 */ | |
23 | |
24 #include <gtk/gtk.h> | |
25 #include "gtkticker.h" | |
469 | 26 #include <string.h> |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
27 #include <stdlib.h> |
955
889e5026fd98
[gaim-migrate @ 965]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
905
diff
changeset
|
28 #include "gaim.h" |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
29 #include "prpl.h" |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
30 #include "pixmaps/no_icon.xpm" |
430 | 31 |
32 GtkWidget *tickerwindow = NULL; | |
33 GtkWidget *ticker; | |
34 | |
35 typedef struct { | |
36 char buddy[ 128 ]; | |
37 GtkWidget *hbox; | |
438 | 38 GtkWidget *ebox; |
430 | 39 GtkWidget *label; |
40 GtkWidget *pix; | |
41 } TickerData; | |
42 | |
43 static GList *tickerbuds = (GList *) NULL; | |
432 | 44 static gboolean userclose = FALSE; |
433 | 45 static GtkWidget *msgw; |
430 | 46 |
47 void BuddyTickerDestroyWindow( GtkWidget *window ); | |
48 void BuddyTickerCreateWindow( void ); | |
49 void BuddyTickerAddUser( char *name, GdkPixmap *pm, GdkBitmap *bm ); | |
50 void BuddyTickerRemoveUser( char *name ); | |
51 void BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm ); | |
432 | 52 void BuddyTickerClearList( void ); |
53 void BuddyTickerSignOff( void ); | |
430 | 54 GList * BuddyTickerFindUser( char *name ); |
433 | 55 int BuddyTickerMessageRemove( gpointer data ); |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
56 extern void pressed_ticker(char *); |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
57 void BuddyTickerShow(); |
436 | 58 |
59 extern int display_options; | |
60 | |
430 | 61 void |
62 BuddyTickerDestroyWindow( GtkWidget *window ) | |
63 { | |
432 | 64 BuddyTickerClearList(); |
430 | 65 gtk_ticker_stop_scroll( GTK_TICKER( ticker ) ); |
66 gtk_widget_destroy( window ); | |
67 ticker = tickerwindow = (GtkWidget *) NULL; | |
432 | 68 userclose = TRUE; |
430 | 69 } |
70 | |
955
889e5026fd98
[gaim-migrate @ 965]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
905
diff
changeset
|
71 static char *msg = "Welcome to GAIM " VERSION ", brought to you by Rob Flynn (maintainer), Eric Warmenhoven, Mark Spencer, Jeramey Crawford, Jim Duchek, and Syd Logan"; |
433 | 72 |
430 | 73 void |
74 BuddyTickerCreateWindow() | |
75 { | |
76 if ( tickerwindow != (GtkWidget *) NULL ) | |
77 return; | |
78 tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
79 gtk_signal_connect (GTK_OBJECT(tickerwindow), "destroy", | |
80 GTK_SIGNAL_FUNC (BuddyTickerDestroyWindow), "WM destroy"); | |
433 | 81 gtk_window_set_title (GTK_WINDOW(tickerwindow), "GAIM - Buddy Ticker"); |
905 | 82 gtk_window_set_wmclass (GTK_WINDOW(tickerwindow), |
83 "ticker", "Gaim"); | |
430 | 84 |
85 ticker = gtk_ticker_new(); | |
433 | 86 gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 ); |
87 gtk_widget_set_usize( ticker, 500, -1 ); | |
430 | 88 gtk_container_add( GTK_CONTAINER( tickerwindow ), ticker ); |
89 gtk_ticker_set_interval( GTK_TICKER( ticker ), 500 ); | |
90 gtk_ticker_set_scootch( GTK_TICKER( ticker ), 10 ); | |
433 | 91 msgw = gtk_label_new( msg ); |
92 gtk_ticker_add( GTK_TICKER( ticker ), msgw ); | |
430 | 93 gtk_ticker_start_scroll( GTK_TICKER( ticker ) ); |
433 | 94 |
95 gtk_timeout_add( 60000, BuddyTickerMessageRemove, (gpointer) NULL ); | |
96 | |
97 gtk_widget_show_all (ticker); | |
98 | |
430 | 99 } |
100 | |
438 | 101 gint |
102 ButtonPressCallback( GtkWidget *widget, GdkEvent *event, gpointer callback_data ) | |
103 { | |
104 TickerData *p = (TickerData *) callback_data; | |
105 | |
106 pressed_ticker( p->buddy ); | |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
107 |
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
108 return TRUE; |
438 | 109 } |
110 | |
430 | 111 void |
112 BuddyTickerAddUser( char *name, GdkPixmap *pm, GdkBitmap *bm ) | |
113 { | |
114 TickerData *p; | |
432 | 115 GList *q; |
116 | |
117 if ( userclose == TRUE ) | |
118 return; | |
436 | 119 |
120 BuddyTickerCreateWindow(); | |
121 | |
432 | 122 q = (GList *) BuddyTickerFindUser( name ); |
123 if ( q != (GList *) NULL ) | |
124 return; | |
430 | 125 |
126 p = (TickerData *) malloc( sizeof( TickerData ) ); | |
127 p->hbox = (GtkWidget *) NULL; | |
128 p->label = (GtkWidget *) NULL; | |
129 p->pix = (GtkWidget *) NULL; | |
130 strcpy( p->buddy, name ); | |
131 tickerbuds = g_list_append( tickerbuds, p ); | |
132 | |
133 p->hbox = gtk_hbox_new( FALSE, 0 ); | |
134 gtk_ticker_add( GTK_TICKER( ticker ), p->hbox ); | |
135 gtk_widget_show_all( p->hbox ); | |
136 | |
137 BuddyTickerSetPixmap( name, pm, bm ); | |
138 | |
438 | 139 p->ebox = gtk_event_box_new(); |
140 | |
1976 | 141 /* click detection */ |
438 | 142 |
143 gtk_widget_set_events (p->ebox, GDK_BUTTON_PRESS_MASK); | |
144 gtk_signal_connect (GTK_OBJECT (p->ebox), "button_press_event", | |
145 GTK_SIGNAL_FUNC(ButtonPressCallback), (gpointer) p); | |
146 | |
147 gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->ebox ); | |
148 gtk_widget_show( p->ebox ); | |
149 | |
430 | 150 p->label = gtk_label_new( name ); |
438 | 151 gtk_container_add( GTK_CONTAINER(p->ebox), p->label ); |
152 | |
430 | 153 gtk_widget_show( p->label ); |
154 | |
155 gtk_widget_show( tickerwindow ); | |
156 } | |
157 | |
158 void | |
159 BuddyTickerRemoveUser( char *name ) | |
160 { | |
161 GList *p = (GList *) BuddyTickerFindUser( name ); | |
460 | 162 TickerData *data; |
163 | |
164 if ( !p ) | |
165 return; | |
166 | |
167 data = (TickerData *) p->data; | |
430 | 168 |
432 | 169 if ( userclose == TRUE ) |
170 return; | |
430 | 171 if ( data ) { |
172 gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox ); | |
173 tickerbuds = g_list_remove( tickerbuds, data ); | |
174 free( data ); | |
175 } | |
176 } | |
177 | |
178 void | |
179 BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm ) | |
180 { | |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
181 GList *p; |
432 | 182 TickerData *data; |
430 | 183 |
432 | 184 if ( userclose == TRUE ) |
185 return; | |
186 p = (GList *) BuddyTickerFindUser( name ); | |
436 | 187 if ( p ) |
188 data = (TickerData *) p->data; | |
189 else | |
190 return; | |
430 | 191 if ( data->pix == (GtkWidget *) NULL ) { |
192 data->pix = gtk_pixmap_new( pm, bm ); | |
193 gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix ); | |
194 } else { | |
195 gtk_widget_hide( data->pix ); | |
196 gtk_pixmap_set(GTK_PIXMAP(data->pix), pm, bm); | |
197 } | |
198 gtk_widget_show( data->pix ); | |
199 } | |
200 | |
201 GList * | |
202 BuddyTickerFindUser( char *name ) | |
203 { | |
204 GList *p = tickerbuds; | |
205 | |
206 while ( p ) { | |
207 TickerData *q = (TickerData *) p->data; | |
208 if ( !strcmp( name, q->buddy ) ) | |
209 return( p ); | |
210 p = p->next; | |
211 } | |
212 return (GList *) NULL; | |
213 } | |
214 | |
215 int | |
433 | 216 BuddyTickerMessageRemove( gpointer data ) |
217 { | |
218 if ( userclose == TRUE ) | |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
219 return FALSE; |
1425
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
220 if ( tickerwindow == NULL ) |
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
221 return FALSE; |
433 | 222 gtk_ticker_remove( GTK_TICKER( ticker ), msgw ); |
223 return FALSE; | |
224 } | |
225 | |
226 int | |
430 | 227 BuddyTickerLogonTimeout( gpointer data ) |
228 { | |
229 return FALSE; | |
230 } | |
231 | |
232 int | |
233 BuddyTickerLogoutTimeout( gpointer data ) | |
234 { | |
235 char *name = (char *) data; | |
236 | |
432 | 237 if ( userclose == TRUE ) |
238 return FALSE; | |
430 | 239 BuddyTickerRemoveUser( name ); |
240 | |
241 return FALSE; | |
242 } | |
432 | 243 |
244 void | |
245 BuddyTickerSignoff( void ) | |
246 { | |
247 GList *p = tickerbuds; | |
248 TickerData *q; | |
249 | |
250 while ( p ) { | |
251 q = (TickerData *) p->data; | |
436 | 252 if ( q ) |
253 BuddyTickerRemoveUser( q->buddy ); | |
432 | 254 p = tickerbuds; |
255 } | |
256 userclose = FALSE; | |
1425
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
257 if ( tickerwindow ) |
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
258 gtk_widget_hide( tickerwindow ); |
432 | 259 } |
260 | |
261 void | |
262 BuddyTickerClearList( void ) | |
263 { | |
264 GList *p = tickerbuds; | |
265 | |
436 | 266 while ( p ) |
432 | 267 p = g_list_remove( p, p->data ); |
268 tickerbuds = (GList *) NULL; | |
269 } | |
270 | |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
271 void BuddyTickerShow() |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
272 { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
273 GdkPixmap *pm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
274 GdkBitmap *bm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
275 struct gaim_connection *gc; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
276 struct group *g; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
277 struct buddy *b; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
278 GSList *gcons, *grps, *buds; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
279 char **xpm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
280 |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
281 if( !(display_options & OPT_DISP_SHOW_BUDDYTICKER) ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
282 BuddyTickerSignoff(); |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
283 display_options &= ~OPT_DISP_SHOW_BUDDYTICKER; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
284 return; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
285 } |
432 | 286 |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
287 for( gcons = connections; gcons; gcons = gcons->next ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
288 gc = (struct gaim_connection *)gcons->data; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
289 for( grps = gc->groups; grps; grps = grps->next ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
290 g = (struct group *)grps->data; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
291 for( buds = g->members; buds; buds = buds->next ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
292 b = (struct buddy *)buds->data; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
293 if( b->present ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
294 xpm = NULL; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
295 if (gc->prpl->list_icon) |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
296 xpm = (*gc->prpl->list_icon)(b->uc); |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
297 if (xpm == NULL) |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
298 xpm = (char **)no_icon_xpm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
299 pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, xpm); |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
300 BuddyTickerAddUser( b->name, pm, bm ); |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
301 } |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
302 } |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
303 } |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
304 } |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
305 } |