Mercurial > pidgin
annotate src/ticker.c @ 2517:9cee43e4903d
[gaim-migrate @ 2530]
hm
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 16 Oct 2001 19:37:47 +0000 |
parents | bd9d403fb15b |
children | 2bc6ee172103 |
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 |
430 | 59 void |
60 BuddyTickerDestroyWindow( GtkWidget *window ) | |
61 { | |
432 | 62 BuddyTickerClearList(); |
430 | 63 gtk_ticker_stop_scroll( GTK_TICKER( ticker ) ); |
64 gtk_widget_destroy( window ); | |
65 ticker = tickerwindow = (GtkWidget *) NULL; | |
432 | 66 userclose = TRUE; |
430 | 67 } |
68 | |
955
889e5026fd98
[gaim-migrate @ 965]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
905
diff
changeset
|
69 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 | 70 |
430 | 71 void |
72 BuddyTickerCreateWindow() | |
73 { | |
74 if ( tickerwindow != (GtkWidget *) NULL ) | |
75 return; | |
76 tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
77 gtk_signal_connect (GTK_OBJECT(tickerwindow), "destroy", | |
78 GTK_SIGNAL_FUNC (BuddyTickerDestroyWindow), "WM destroy"); | |
433 | 79 gtk_window_set_title (GTK_WINDOW(tickerwindow), "GAIM - Buddy Ticker"); |
905 | 80 gtk_window_set_wmclass (GTK_WINDOW(tickerwindow), |
81 "ticker", "Gaim"); | |
430 | 82 |
83 ticker = gtk_ticker_new(); | |
433 | 84 gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 ); |
85 gtk_widget_set_usize( ticker, 500, -1 ); | |
430 | 86 gtk_container_add( GTK_CONTAINER( tickerwindow ), ticker ); |
87 gtk_ticker_set_interval( GTK_TICKER( ticker ), 500 ); | |
88 gtk_ticker_set_scootch( GTK_TICKER( ticker ), 10 ); | |
433 | 89 msgw = gtk_label_new( msg ); |
90 gtk_ticker_add( GTK_TICKER( ticker ), msgw ); | |
430 | 91 gtk_ticker_start_scroll( GTK_TICKER( ticker ) ); |
433 | 92 |
93 gtk_timeout_add( 60000, BuddyTickerMessageRemove, (gpointer) NULL ); | |
94 | |
95 gtk_widget_show_all (ticker); | |
96 | |
430 | 97 } |
98 | |
438 | 99 gint |
100 ButtonPressCallback( GtkWidget *widget, GdkEvent *event, gpointer callback_data ) | |
101 { | |
102 TickerData *p = (TickerData *) callback_data; | |
103 | |
104 pressed_ticker( p->buddy ); | |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
105 |
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
106 return TRUE; |
438 | 107 } |
108 | |
430 | 109 void |
110 BuddyTickerAddUser( char *name, GdkPixmap *pm, GdkBitmap *bm ) | |
111 { | |
112 TickerData *p; | |
432 | 113 GList *q; |
114 | |
115 if ( userclose == TRUE ) | |
116 return; | |
436 | 117 |
118 BuddyTickerCreateWindow(); | |
119 | |
432 | 120 q = (GList *) BuddyTickerFindUser( name ); |
121 if ( q != (GList *) NULL ) | |
122 return; | |
430 | 123 |
124 p = (TickerData *) malloc( sizeof( TickerData ) ); | |
125 p->hbox = (GtkWidget *) NULL; | |
126 p->label = (GtkWidget *) NULL; | |
127 p->pix = (GtkWidget *) NULL; | |
128 strcpy( p->buddy, name ); | |
129 tickerbuds = g_list_append( tickerbuds, p ); | |
130 | |
131 p->hbox = gtk_hbox_new( FALSE, 0 ); | |
132 gtk_ticker_add( GTK_TICKER( ticker ), p->hbox ); | |
133 gtk_widget_show_all( p->hbox ); | |
134 | |
135 BuddyTickerSetPixmap( name, pm, bm ); | |
136 | |
438 | 137 p->ebox = gtk_event_box_new(); |
138 | |
1976 | 139 /* click detection */ |
438 | 140 |
141 gtk_widget_set_events (p->ebox, GDK_BUTTON_PRESS_MASK); | |
142 gtk_signal_connect (GTK_OBJECT (p->ebox), "button_press_event", | |
143 GTK_SIGNAL_FUNC(ButtonPressCallback), (gpointer) p); | |
144 | |
145 gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->ebox ); | |
146 gtk_widget_show( p->ebox ); | |
147 | |
430 | 148 p->label = gtk_label_new( name ); |
438 | 149 gtk_container_add( GTK_CONTAINER(p->ebox), p->label ); |
150 | |
430 | 151 gtk_widget_show( p->label ); |
152 | |
153 gtk_widget_show( tickerwindow ); | |
154 } | |
155 | |
156 void | |
157 BuddyTickerRemoveUser( char *name ) | |
158 { | |
159 GList *p = (GList *) BuddyTickerFindUser( name ); | |
460 | 160 TickerData *data; |
161 | |
162 if ( !p ) | |
163 return; | |
164 | |
165 data = (TickerData *) p->data; | |
430 | 166 |
432 | 167 if ( userclose == TRUE ) |
168 return; | |
430 | 169 if ( data ) { |
170 gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox ); | |
171 tickerbuds = g_list_remove( tickerbuds, data ); | |
172 free( data ); | |
173 } | |
174 } | |
175 | |
176 void | |
177 BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm ) | |
178 { | |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
179 GList *p; |
432 | 180 TickerData *data; |
430 | 181 |
432 | 182 if ( userclose == TRUE ) |
183 return; | |
184 p = (GList *) BuddyTickerFindUser( name ); | |
436 | 185 if ( p ) |
186 data = (TickerData *) p->data; | |
187 else | |
188 return; | |
430 | 189 if ( data->pix == (GtkWidget *) NULL ) { |
190 data->pix = gtk_pixmap_new( pm, bm ); | |
191 gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix ); | |
192 } else { | |
193 gtk_widget_hide( data->pix ); | |
194 gtk_pixmap_set(GTK_PIXMAP(data->pix), pm, bm); | |
195 } | |
196 gtk_widget_show( data->pix ); | |
197 } | |
198 | |
199 GList * | |
200 BuddyTickerFindUser( char *name ) | |
201 { | |
202 GList *p = tickerbuds; | |
203 | |
204 while ( p ) { | |
205 TickerData *q = (TickerData *) p->data; | |
206 if ( !strcmp( name, q->buddy ) ) | |
207 return( p ); | |
208 p = p->next; | |
209 } | |
210 return (GList *) NULL; | |
211 } | |
212 | |
213 int | |
433 | 214 BuddyTickerMessageRemove( gpointer data ) |
215 { | |
216 if ( userclose == TRUE ) | |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
469
diff
changeset
|
217 return FALSE; |
1425
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
218 if ( tickerwindow == NULL ) |
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
219 return FALSE; |
433 | 220 gtk_ticker_remove( GTK_TICKER( ticker ), msgw ); |
221 return FALSE; | |
222 } | |
223 | |
224 int | |
430 | 225 BuddyTickerLogonTimeout( gpointer data ) |
226 { | |
227 return FALSE; | |
228 } | |
229 | |
230 int | |
231 BuddyTickerLogoutTimeout( gpointer data ) | |
232 { | |
233 char *name = (char *) data; | |
234 | |
432 | 235 if ( userclose == TRUE ) |
236 return FALSE; | |
430 | 237 BuddyTickerRemoveUser( name ); |
238 | |
239 return FALSE; | |
240 } | |
432 | 241 |
242 void | |
243 BuddyTickerSignoff( void ) | |
244 { | |
245 GList *p = tickerbuds; | |
246 TickerData *q; | |
247 | |
248 while ( p ) { | |
249 q = (TickerData *) p->data; | |
436 | 250 if ( q ) |
251 BuddyTickerRemoveUser( q->buddy ); | |
432 | 252 p = tickerbuds; |
253 } | |
254 userclose = FALSE; | |
1425
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
255 if ( tickerwindow ) |
3e6a17ae51e8
[gaim-migrate @ 1435]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
955
diff
changeset
|
256 gtk_widget_hide( tickerwindow ); |
432 | 257 } |
258 | |
259 void | |
260 BuddyTickerClearList( void ) | |
261 { | |
262 GList *p = tickerbuds; | |
263 | |
436 | 264 while ( p ) |
432 | 265 p = g_list_remove( p, p->data ); |
266 tickerbuds = (GList *) NULL; | |
267 } | |
268 | |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
269 void BuddyTickerShow() |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
270 { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
271 GdkPixmap *pm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
272 GdkBitmap *bm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
273 struct gaim_connection *gc; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
274 struct group *g; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
275 struct buddy *b; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
276 GSList *gcons, *grps, *buds; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
277 char **xpm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
278 |
2313
bd9d403fb15b
[gaim-migrate @ 2323]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1976
diff
changeset
|
279 if( !(misc_options & OPT_MISC_BUDDY_TICKER) ) { |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
280 BuddyTickerSignoff(); |
2313
bd9d403fb15b
[gaim-migrate @ 2323]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1976
diff
changeset
|
281 misc_options &= ~OPT_MISC_BUDDY_TICKER; |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
282 return; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
283 } |
432 | 284 |
1750
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
285 for( gcons = connections; gcons; gcons = gcons->next ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
286 gc = (struct gaim_connection *)gcons->data; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
287 for( grps = gc->groups; grps; grps = grps->next ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
288 g = (struct group *)grps->data; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
289 for( buds = g->members; buds; buds = buds->next ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
290 b = (struct buddy *)buds->data; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
291 if( b->present ) { |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
292 xpm = NULL; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
293 if (gc->prpl->list_icon) |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
294 xpm = (*gc->prpl->list_icon)(b->uc); |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
295 if (xpm == NULL) |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
296 xpm = (char **)no_icon_xpm; |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
297 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
|
298 BuddyTickerAddUser( b->name, pm, bm ); |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
299 } |
d2eca7a46cfd
[gaim-migrate @ 1760]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1425
diff
changeset
|
300 } |
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 } |