Mercurial > pidgin
comparison plugins/ticker/ticker.c @ 3391:412d1035d666
[gaim-migrate @ 3410]
Pluginzed the ticker. the ticker will load itself if the old ticker option
was set.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sun, 11 Aug 2002 06:42:17 +0000 |
parents | |
children | 7a3f16a375a5 |
comparison
equal
deleted
inserted
replaced
3390:a5d356cba156 | 3391:412d1035d666 |
---|---|
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 * pluginized- Sean Egan, Summer 2002 | |
23 */ | |
24 | |
25 #define GAIM_PLUGINS | |
26 | |
27 #include <gtk/gtk.h> | |
28 #include "gtkticker.h" | |
29 #include <string.h> | |
30 #include <stdlib.h> | |
31 #include "gaim.h" | |
32 #include "prpl.h" | |
33 #include "pixmaps/no_icon.xpm" | |
34 | |
35 static GtkWidget *tickerwindow = NULL; | |
36 static GtkWidget *ticker; | |
37 static GModule *handle; | |
38 | |
39 typedef struct { | |
40 char buddy[ 128 ]; | |
41 char alias[ 388 ]; | |
42 GtkWidget *hbox; | |
43 GtkWidget *ebox; | |
44 GtkWidget *label; | |
45 GtkWidget *pix; | |
46 } TickerData; | |
47 | |
48 GList *tickerbuds = (GList *) NULL; | |
49 gboolean userclose = FALSE; | |
50 GtkWidget *msgw; | |
51 | |
52 void BuddyTickerDestroyWindow( GtkWidget *window ); | |
53 void BuddyTickerCreateWindow( void ); | |
54 void BuddyTickerAddUser( char *name, char *alias, GdkPixmap *pm, GdkBitmap *bm ); | |
55 void BuddyTickerRemoveUser( char *name ); | |
56 void BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm ); | |
57 void BuddyTickerClearList( void ); | |
58 void BuddyTickerSignOff( void ); | |
59 GList * BuddyTickerFindUser( char *name ); | |
60 int BuddyTickerMessageRemove( gpointer data ); | |
61 void BuddyTickerShow(); | |
62 | |
63 void | |
64 BuddyTickerDestroyWindow( GtkWidget *window ) | |
65 { | |
66 BuddyTickerClearList(); | |
67 gtk_ticker_stop_scroll( GTK_TICKER( ticker ) ); | |
68 gtk_widget_destroy( window ); | |
69 ticker = tickerwindow = (GtkWidget *) NULL; | |
70 userclose = TRUE; | |
71 } | |
72 | |
73 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"; | |
74 | |
75 void | |
76 BuddyTickerCreateWindow() | |
77 { | |
78 | |
79 if ( tickerwindow != (GtkWidget *) NULL ) | |
80 return; | |
81 debug_printf("Making ticker\n"); | |
82 tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
83 gtk_signal_connect (GTK_OBJECT(tickerwindow), "destroy", | |
84 GTK_SIGNAL_FUNC (BuddyTickerDestroyWindow), "WM destroy"); | |
85 gtk_window_set_title (GTK_WINDOW(tickerwindow), "Gaim - Buddy Ticker"); | |
86 gtk_window_set_wmclass (GTK_WINDOW(tickerwindow), | |
87 "ticker", "Gaim"); | |
88 gtk_widget_realize(tickerwindow); | |
89 aol_icon(tickerwindow->window); | |
90 | |
91 ticker = gtk_ticker_new(); | |
92 if (!ticker) | |
93 return; | |
94 gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 ); | |
95 gtk_widget_set_usize( ticker, 500, -1 ); | |
96 gtk_container_add( GTK_CONTAINER( tickerwindow ), ticker ); | |
97 gtk_ticker_set_interval( GTK_TICKER( ticker ), 500 ); | |
98 gtk_ticker_set_scootch( GTK_TICKER( ticker ), 10 ); | |
99 /* Damned egotists | |
100 msgw = gtk_label_new( msg ); | |
101 gtk_ticker_add( GTK_TICKER( ticker ), msgw ); | |
102 */ | |
103 gtk_ticker_start_scroll( GTK_TICKER( ticker ) ); | |
104 | |
105 gtk_timeout_add( 60000, BuddyTickerMessageRemove, (gpointer) NULL ); | |
106 | |
107 gtk_widget_show_all (ticker); | |
108 | |
109 } | |
110 | |
111 gint | |
112 ButtonPressCallback( GtkWidget *widget, GdkEvent *event, gpointer callback_data ) | |
113 { | |
114 TickerData *p = (TickerData *) callback_data; | |
115 struct conversation *conv = new_conversation(p->buddy); | |
116 | |
117 return TRUE; | |
118 } | |
119 | |
120 void | |
121 BuddyTickerAddUser( char *name, char *alias, GdkPixmap *pm, GdkBitmap *bm ) | |
122 { | |
123 TickerData *p; | |
124 GList *q; | |
125 | |
126 if ( userclose == TRUE ) | |
127 return; | |
128 | |
129 debug_printf("Adding %s\n", name); | |
130 | |
131 BuddyTickerCreateWindow(); | |
132 if (!ticker) | |
133 return; | |
134 | |
135 q = (GList *) BuddyTickerFindUser( name ); | |
136 if ( q != (GList *) NULL ) | |
137 return; | |
138 | |
139 p = (TickerData *) malloc( sizeof( TickerData ) ); | |
140 p->hbox = (GtkWidget *) NULL; | |
141 p->label = (GtkWidget *) NULL; | |
142 p->pix = (GtkWidget *) NULL; | |
143 strcpy( p->buddy, name ); | |
144 strcpy( p->alias, alias); | |
145 tickerbuds = g_list_append( tickerbuds, p ); | |
146 | |
147 p->hbox = gtk_hbox_new( FALSE, 0 ); | |
148 gtk_ticker_add( GTK_TICKER( ticker ), p->hbox ); | |
149 gtk_widget_show_all( p->hbox ); | |
150 | |
151 BuddyTickerSetPixmap( name, pm, bm ); | |
152 | |
153 p->ebox = gtk_event_box_new(); | |
154 | |
155 /* click detection */ | |
156 | |
157 gtk_widget_set_events (p->ebox, GDK_BUTTON_PRESS_MASK); | |
158 gtk_signal_connect (GTK_OBJECT (p->ebox), "button_press_event", | |
159 GTK_SIGNAL_FUNC(ButtonPressCallback), (gpointer) p); | |
160 | |
161 gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->ebox ); | |
162 gtk_widget_show( p->ebox ); | |
163 | |
164 if (im_options & OPT_IM_ALIAS_TAB) | |
165 p->label = gtk_label_new( alias ); | |
166 else | |
167 p->label = gtk_label_new( name ); | |
168 gtk_container_add( GTK_CONTAINER(p->ebox), p->label ); | |
169 | |
170 gtk_widget_show( p->label ); | |
171 | |
172 gtk_widget_show( tickerwindow ); | |
173 } | |
174 | |
175 void | |
176 BuddyTickerRemoveUser( char *name ) | |
177 { | |
178 GList *p = (GList *) BuddyTickerFindUser( name ); | |
179 TickerData *data; | |
180 | |
181 if ( !p ) | |
182 return; | |
183 | |
184 data = (TickerData *) p->data; | |
185 | |
186 if ( userclose == TRUE ) | |
187 return; | |
188 if ( data ) { | |
189 gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox ); | |
190 tickerbuds = g_list_remove( tickerbuds, data ); | |
191 free( data ); | |
192 } | |
193 } | |
194 | |
195 void | |
196 BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm ) | |
197 { | |
198 GList *p; | |
199 TickerData *data; | |
200 | |
201 if ( userclose == TRUE ) | |
202 return; | |
203 p = (GList *) BuddyTickerFindUser( name ); | |
204 if ( p ) | |
205 data = (TickerData *) p->data; | |
206 else | |
207 return; | |
208 if ( data->pix == (GtkWidget *) NULL ) { | |
209 data->pix = gtk_pixmap_new( pm, bm ); | |
210 gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix ); | |
211 } else { | |
212 gtk_widget_hide( data->pix ); | |
213 gtk_pixmap_set(GTK_PIXMAP(data->pix), pm, bm); | |
214 } | |
215 gtk_widget_show( data->pix ); | |
216 } | |
217 | |
218 void | |
219 BuddyTickerSetAlias( char *name, char *alias) { | |
220 GList *p; | |
221 TickerData *data; | |
222 | |
223 if ( userclose == TRUE ) | |
224 return; | |
225 p = (GList *) BuddyTickerFindUser( name ); | |
226 if ( p ) | |
227 data = (TickerData *) p->data; | |
228 else | |
229 return; | |
230 if (alias) { | |
231 g_snprintf(data->alias, sizeof(data->alias), alias); | |
232 | |
233 if (im_options & OPT_IM_ALIAS_TAB) | |
234 gtk_label_set_text(GTK_LABEL(data->label), alias); | |
235 } | |
236 } | |
237 | |
238 GList * | |
239 BuddyTickerFindUser( char *name ) | |
240 { | |
241 GList *p = tickerbuds; | |
242 | |
243 while ( p ) { | |
244 TickerData *q = (TickerData *) p->data; | |
245 if ( !strcmp( name, q->buddy ) ) | |
246 return( p ); | |
247 p = p->next; | |
248 } | |
249 return (GList *) NULL; | |
250 } | |
251 | |
252 void | |
253 BuddyTickerSetNames() | |
254 { | |
255 GList *p = tickerbuds; | |
256 while ( p ) { | |
257 TickerData *q = (TickerData *) p->data; | |
258 if (im_options & OPT_IM_ALIAS_TAB) | |
259 gtk_label_set_text(GTK_LABEL(q->label), q->alias); | |
260 else | |
261 gtk_label_set_text(GTK_LABEL(q->label), q->buddy); | |
262 p = p->next; | |
263 } | |
264 } | |
265 | |
266 int | |
267 BuddyTickerMessageRemove( gpointer data ) | |
268 { | |
269 if ( userclose == TRUE ) | |
270 return FALSE; | |
271 if ( tickerwindow == NULL ) | |
272 return FALSE; | |
273 gtk_ticker_remove( GTK_TICKER( ticker ), msgw ); | |
274 return FALSE; | |
275 } | |
276 | |
277 int | |
278 BuddyTickerLogonTimeout( gpointer data ) | |
279 { | |
280 return FALSE; | |
281 } | |
282 | |
283 int | |
284 BuddyTickerLogoutTimeout( gpointer data ) | |
285 { | |
286 char *name = (char *) data; | |
287 | |
288 if ( userclose == TRUE ) | |
289 return FALSE; | |
290 BuddyTickerRemoveUser( name ); | |
291 | |
292 return FALSE; | |
293 } | |
294 | |
295 void | |
296 BuddyTickerSignoff( void ) | |
297 { | |
298 GList *p = tickerbuds; | |
299 TickerData *q; | |
300 | |
301 while ( p ) { | |
302 q = (TickerData *) p->data; | |
303 if ( q ) | |
304 BuddyTickerRemoveUser( q->buddy ); | |
305 p = tickerbuds; | |
306 } | |
307 userclose = FALSE; | |
308 if ( tickerwindow ) | |
309 gtk_widget_hide( tickerwindow ); | |
310 } | |
311 | |
312 void | |
313 BuddyTickerClearList( void ) | |
314 { | |
315 GList *p = tickerbuds; | |
316 | |
317 while ( p ) | |
318 p = g_list_remove( p, p->data ); | |
319 tickerbuds = (GList *) NULL; | |
320 } | |
321 | |
322 void BuddyTickerShow() | |
323 { | |
324 GdkPixmap *pm; | |
325 GdkBitmap *bm; | |
326 struct gaim_connection *gc; | |
327 struct group *g; | |
328 struct buddy *b; | |
329 GSList *gcons, *grps, *buds; | |
330 char **xpm; | |
331 | |
332 for( gcons = connections; gcons; gcons = gcons->next ) { | |
333 gc = (struct gaim_connection *)gcons->data; | |
334 for( grps = gc->groups; grps; grps = grps->next ) { | |
335 g = (struct group *)grps->data; | |
336 for( buds = g->members; buds; buds = buds->next ) { | |
337 b = (struct buddy *)buds->data; | |
338 if( b->present ) { | |
339 xpm = NULL; | |
340 if (gc->prpl->list_icon) | |
341 xpm = gc->prpl->list_icon(b->uc); | |
342 if (xpm == NULL) | |
343 xpm = (char **)no_icon_xpm; | |
344 pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, xpm); | |
345 BuddyTickerAddUser( b->name, b->show, pm, bm ); | |
346 gdk_pixmap_unref(pm); | |
347 if (bm) | |
348 gdk_bitmap_unref(bm); | |
349 } | |
350 } | |
351 } | |
352 } | |
353 } | |
354 | |
355 void signon_cb(struct gaim_connection *gc, char *who) { | |
356 struct buddy *b = find_buddy(gc, who); | |
357 char **xpm = NULL; | |
358 | |
359 GdkPixmap *pm; | |
360 GdkBitmap *bm; | |
361 | |
362 if (gc->prpl->list_icon) | |
363 xpm = gc->prpl->list_icon(b->uc); | |
364 if (xpm == NULL) | |
365 xpm = (char **)no_icon_xpm; | |
366 pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, xpm); | |
367 | |
368 BuddyTickerAddUser(who, b->show, pm, bm); | |
369 gdk_pixmap_unref(pm); | |
370 if (bm) | |
371 gdk_bitmap_unref(bm); | |
372 } | |
373 | |
374 void signoff_cb(struct gaim_connection *gc) { | |
375 if (!connections->next) { | |
376 gtk_widget_destroy(tickerwindow); | |
377 tickerwindow = NULL; | |
378 ticker = NULL; | |
379 } | |
380 } | |
381 | |
382 void buddy_signoff_cb(struct gaim_connection *gc, char *who) { | |
383 BuddyTickerRemoveUser(who); | |
384 } | |
385 | |
386 void away_cb(struct gaim_connection *gc, char *who) { | |
387 struct buddy *b = find_buddy(gc, who); | |
388 char **xpm = NULL; | |
389 | |
390 GdkPixmap *pm; | |
391 GdkBitmap *bm; | |
392 | |
393 if (gc->prpl->list_icon) | |
394 xpm = gc->prpl->list_icon(b->uc); | |
395 if (xpm == NULL) | |
396 xpm = (char **)no_icon_xpm; | |
397 pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, xpm); | |
398 BuddyTickerSetPixmap(who, pm, bm); | |
399 gdk_pixmap_unref(pm); | |
400 if (bm) | |
401 gdk_bitmap_unref(bm); | |
402 } | |
403 | |
404 char *gaim_plugin_init(GModule *h) { | |
405 handle = h; | |
406 | |
407 gaim_signal_connect(h, event_buddy_signon, signon_cb, NULL); | |
408 gaim_signal_connect(h, event_signoff, signoff_cb, NULL); | |
409 gaim_signal_connect(h, event_buddy_signoff, buddy_signoff_cb, NULL); | |
410 gaim_signal_connect(h, event_buddy_away, away_cb, NULL); | |
411 gaim_signal_connect(h, event_buddy_back, away_cb, NULL); | |
412 | |
413 if (connections) | |
414 BuddyTickerShow(); | |
415 return NULL; | |
416 } | |
417 | |
418 void gaim_plugin_remove() { | |
419 gtk_widget_destroy(tickerwindow); | |
420 } |