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