Mercurial > pidgin.yaz
annotate src/ticker.c @ 3346:2b9ea67bdc38
[gaim-migrate @ 3365]
lalala
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Wed, 03 Jul 2002 05:52:58 +0000 |
parents | 30ca1b76ad0c |
children |
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 ]; | |
3278 | 37 char alias[ 388 ]; |
430 | 38 GtkWidget *hbox; |
438 | 39 GtkWidget *ebox; |
430 | 40 GtkWidget *label; |
41 GtkWidget *pix; | |
42 } TickerData; | |
43 | |
44 static GList *tickerbuds = (GList *) NULL; | |
432 | 45 static gboolean userclose = FALSE; |
433 | 46 static GtkWidget *msgw; |
430 | 47 |
48 void BuddyTickerDestroyWindow( GtkWidget *window ); | |
49 void BuddyTickerCreateWindow( void ); | |
3278 | 50 void BuddyTickerAddUser( char *name, char *alias, GdkPixmap *pm, GdkBitmap *bm ); |
430 | 51 void BuddyTickerRemoveUser( char *name ); |
52 void BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm ); | |
432 | 53 void BuddyTickerClearList( void ); |
54 void BuddyTickerSignOff( void ); | |
430 | 55 GList * BuddyTickerFindUser( char *name ); |
433 | 56 int BuddyTickerMessageRemove( gpointer data ); |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
57 extern void pressed_ticker(char *); |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
58 void BuddyTickerShow(); |
436 | 59 |
430 | 60 void |
61 BuddyTickerDestroyWindow( GtkWidget *window ) | |
62 { | |
432 | 63 BuddyTickerClearList(); |
430 | 64 gtk_ticker_stop_scroll( GTK_TICKER( ticker ) ); |
65 gtk_widget_destroy( window ); | |
66 ticker = tickerwindow = (GtkWidget *) NULL; | |
432 | 67 userclose = TRUE; |
430 | 68 } |
69 | |
3278 | 70 static char *msg = "Welcome to Gaim " VERSION ", brought to you by Rob Flynn (maintainer), Eric Warmenhoven, Mark Spencer, Jeramey Crawford, Jim Duchek, Syd Logan, and Sean Egan"; |
433 | 71 |
430 | 72 void |
73 BuddyTickerCreateWindow() | |
74 { | |
75 if ( tickerwindow != (GtkWidget *) NULL ) | |
76 return; | |
77 tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
78 gtk_signal_connect (GTK_OBJECT(tickerwindow), "destroy", | |
79 GTK_SIGNAL_FUNC (BuddyTickerDestroyWindow), "WM destroy"); | |
2534 | 80 gtk_window_set_title (GTK_WINDOW(tickerwindow), "Gaim - Buddy Ticker"); |
905 | 81 gtk_window_set_wmclass (GTK_WINDOW(tickerwindow), |
82 "ticker", "Gaim"); | |
2547
ab55ac6234b8
[gaim-migrate @ 2560]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2534
diff
changeset
|
83 gtk_widget_realize(tickerwindow); |
ab55ac6234b8
[gaim-migrate @ 2560]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2534
diff
changeset
|
84 aol_icon(tickerwindow->window); |
430 | 85 |
86 ticker = gtk_ticker_new(); | |
433 | 87 gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 ); |
88 gtk_widget_set_usize( ticker, 500, -1 ); | |
430 | 89 gtk_container_add( GTK_CONTAINER( tickerwindow ), ticker ); |
90 gtk_ticker_set_interval( GTK_TICKER( ticker ), 500 ); | |
91 gtk_ticker_set_scootch( GTK_TICKER( ticker ), 10 ); | |
433 | 92 msgw = gtk_label_new( msg ); |
93 gtk_ticker_add( GTK_TICKER( ticker ), msgw ); | |
430 | 94 gtk_ticker_start_scroll( GTK_TICKER( ticker ) ); |
433 | 95 |
96 gtk_timeout_add( 60000, BuddyTickerMessageRemove, (gpointer) NULL ); | |
97 | |
98 gtk_widget_show_all (ticker); | |
99 | |
430 | 100 } |
101 | |
438 | 102 gint |
103 ButtonPressCallback( GtkWidget *widget, GdkEvent *event, gpointer callback_data ) | |
104 { | |
105 TickerData *p = (TickerData *) callback_data; | |
106 | |
107 pressed_ticker( p->buddy ); | |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
108 |
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
109 return TRUE; |
438 | 110 } |
111 | |
430 | 112 void |
3278 | 113 BuddyTickerAddUser( char *name, char *alias, GdkPixmap *pm, GdkBitmap *bm ) |
430 | 114 { |
115 TickerData *p; | |
432 | 116 GList *q; |
117 | |
118 if ( userclose == TRUE ) | |
119 return; | |
436 | 120 |
121 BuddyTickerCreateWindow(); | |
122 | |
432 | 123 q = (GList *) BuddyTickerFindUser( name ); |
124 if ( q != (GList *) NULL ) | |
125 return; | |
430 | 126 |
127 p = (TickerData *) malloc( sizeof( TickerData ) ); | |
128 p->hbox = (GtkWidget *) NULL; | |
129 p->label = (GtkWidget *) NULL; | |
130 p->pix = (GtkWidget *) NULL; | |
131 strcpy( p->buddy, name ); | |
3278 | 132 strcpy( p->alias, alias); |
430 | 133 tickerbuds = g_list_append( tickerbuds, p ); |
134 | |
135 p->hbox = gtk_hbox_new( FALSE, 0 ); | |
136 gtk_ticker_add( GTK_TICKER( ticker ), p->hbox ); | |
137 gtk_widget_show_all( p->hbox ); | |
138 | |
139 BuddyTickerSetPixmap( name, pm, bm ); | |
140 | |
438 | 141 p->ebox = gtk_event_box_new(); |
142 | |
1976 | 143 /* click detection */ |
438 | 144 |
145 gtk_widget_set_events (p->ebox, GDK_BUTTON_PRESS_MASK); | |
146 gtk_signal_connect (GTK_OBJECT (p->ebox), "button_press_event", | |
147 GTK_SIGNAL_FUNC(ButtonPressCallback), (gpointer) p); | |
148 | |
149 gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->ebox ); | |
150 gtk_widget_show( p->ebox ); | |
151 | |
3278 | 152 if (im_options & OPT_IM_ALIAS_TAB) |
153 p->label = gtk_label_new( alias ); | |
154 else | |
155 p->label = gtk_label_new( name ); | |
438 | 156 gtk_container_add( GTK_CONTAINER(p->ebox), p->label ); |
157 | |
430 | 158 gtk_widget_show( p->label ); |
159 | |
160 gtk_widget_show( tickerwindow ); | |
161 } | |
162 | |
163 void | |
164 BuddyTickerRemoveUser( char *name ) | |
165 { | |
166 GList *p = (GList *) BuddyTickerFindUser( name ); | |
460 | 167 TickerData *data; |
168 | |
169 if ( !p ) | |
170 return; | |
171 | |
172 data = (TickerData *) p->data; | |
430 | 173 |
432 | 174 if ( userclose == TRUE ) |
175 return; | |
430 | 176 if ( data ) { |
177 gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox ); | |
178 tickerbuds = g_list_remove( tickerbuds, data ); | |
179 free( data ); | |
180 } | |
181 } | |
182 | |
183 void | |
184 BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm ) | |
185 { | |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
186 GList *p; |
432 | 187 TickerData *data; |
430 | 188 |
432 | 189 if ( userclose == TRUE ) |
190 return; | |
191 p = (GList *) BuddyTickerFindUser( name ); | |
436 | 192 if ( p ) |
193 data = (TickerData *) p->data; | |
194 else | |
195 return; | |
430 | 196 if ( data->pix == (GtkWidget *) NULL ) { |
197 data->pix = gtk_pixmap_new( pm, bm ); | |
198 gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix ); | |
199 } else { | |
200 gtk_widget_hide( data->pix ); | |
201 gtk_pixmap_set(GTK_PIXMAP(data->pix), pm, bm); | |
202 } | |
203 gtk_widget_show( data->pix ); | |
204 } | |
205 | |
3278 | 206 void |
207 BuddyTickerSetAlias( char *name, char *alias) { | |
208 GList *p; | |
209 TickerData *data; | |
210 | |
211 if ( userclose == TRUE ) | |
212 return; | |
213 p = (GList *) BuddyTickerFindUser( name ); | |
214 if ( p ) | |
215 data = (TickerData *) p->data; | |
216 else | |
217 return; | |
218 if (alias) { | |
219 g_snprintf(data->alias, sizeof(data->alias), alias); | |
220 | |
221 if (im_options & OPT_IM_ALIAS_TAB) | |
222 gtk_label_set_text(GTK_LABEL(data->label), alias); | |
223 } | |
224 } | |
225 | |
430 | 226 GList * |
227 BuddyTickerFindUser( char *name ) | |
228 { | |
229 GList *p = tickerbuds; | |
230 | |
231 while ( p ) { | |
232 TickerData *q = (TickerData *) p->data; | |
233 if ( !strcmp( name, q->buddy ) ) | |
234 return( p ); | |
235 p = p->next; | |
236 } | |
237 return (GList *) NULL; | |
238 } | |
239 | |
3278 | 240 void |
241 BuddyTickerSetNames() | |
242 { | |
243 GList *p = tickerbuds; | |
244 while ( p ) { | |
245 TickerData *q = (TickerData *) p->data; | |
246 if (im_options & OPT_IM_ALIAS_TAB) | |
247 gtk_label_set_text(GTK_LABEL(q->label), q->alias); | |
248 else | |
249 gtk_label_set_text(GTK_LABEL(q->label), q->buddy); | |
250 p = p->next; | |
251 } | |
252 } | |
253 | |
430 | 254 int |
433 | 255 BuddyTickerMessageRemove( gpointer data ) |
256 { | |
257 if ( userclose == TRUE ) | |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
258 return FALSE; |
1425
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
259 if ( tickerwindow == NULL ) |
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
260 return FALSE; |
433 | 261 gtk_ticker_remove( GTK_TICKER( ticker ), msgw ); |
262 return FALSE; | |
263 } | |
264 | |
265 int | |
430 | 266 BuddyTickerLogonTimeout( gpointer data ) |
267 { | |
268 return FALSE; | |
269 } | |
270 | |
271 int | |
272 BuddyTickerLogoutTimeout( gpointer data ) | |
273 { | |
274 char *name = (char *) data; | |
275 | |
432 | 276 if ( userclose == TRUE ) |
277 return FALSE; | |
430 | 278 BuddyTickerRemoveUser( name ); |
279 | |
280 return FALSE; | |
281 } | |
432 | 282 |
283 void | |
284 BuddyTickerSignoff( void ) | |
285 { | |
286 GList *p = tickerbuds; | |
287 TickerData *q; | |
288 | |
289 while ( p ) { | |
290 q = (TickerData *) p->data; | |
436 | 291 if ( q ) |
292 BuddyTickerRemoveUser( q->buddy ); | |
432 | 293 p = tickerbuds; |
294 } | |
295 userclose = FALSE; | |
1425
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
296 if ( tickerwindow ) |
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
297 gtk_widget_hide( tickerwindow ); |
432 | 298 } |
299 | |
300 void | |
301 BuddyTickerClearList( void ) | |
302 { | |
303 GList *p = tickerbuds; | |
304 | |
436 | 305 while ( p ) |
432 | 306 p = g_list_remove( p, p->data ); |
307 tickerbuds = (GList *) NULL; | |
308 } | |
309 | |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
310 void BuddyTickerShow() |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
311 { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
312 GdkPixmap *pm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
313 GdkBitmap *bm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
314 struct gaim_connection *gc; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
315 struct group *g; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
316 struct buddy *b; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
317 GSList *gcons, *grps, *buds; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
318 char **xpm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
319 |
2313
bd9d403fb15b
[gaim-migrate @ 2323]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1976
diff
changeset
|
320 if( !(misc_options & OPT_MISC_BUDDY_TICKER) ) { |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
321 BuddyTickerSignoff(); |
2313
bd9d403fb15b
[gaim-migrate @ 2323]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1976
diff
changeset
|
322 misc_options &= ~OPT_MISC_BUDDY_TICKER; |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
323 return; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
324 } |
432 | 325 |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
326 for( gcons = connections; gcons; gcons = gcons->next ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
327 gc = (struct gaim_connection *)gcons->data; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
328 for( grps = gc->groups; grps; grps = grps->next ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
329 g = (struct group *)grps->data; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
330 for( buds = g->members; buds; buds = buds->next ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
331 b = (struct buddy *)buds->data; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
332 if( b->present ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
333 xpm = NULL; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
334 if (gc->prpl->list_icon) |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2547
diff
changeset
|
335 xpm = gc->prpl->list_icon(b->uc); |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
336 if (xpm == NULL) |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
337 xpm = (char **)no_icon_xpm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
338 pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, xpm); |
3278 | 339 BuddyTickerAddUser( b->name, b->show, pm, bm ); |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
340 } |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
341 } |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
342 } |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
343 } |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
344 } |