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