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