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"
|
3630
|
32 #ifdef _WIN32
|
|
33 #include "win32dep.h"
|
|
34 #endif
|
3391
|
35
|
3867
|
36 #ifndef GAIM_PLUGINS
|
|
37 #define GAIM_PLUGINS
|
|
38 #endif
|
|
39
|
3391
|
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 );
|
4687
|
63 void BuddyTickerAddUser( char *name, char *alias, const char *pb);
|
3391
|
64 void BuddyTickerRemoveUser( char *name );
|
4687
|
65 void BuddyTickerSetPixmap( char *name, const char *pb);
|
3391
|
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();
|
4850
|
76 gtk_ticker_stop_scroll( GTK_TICKER( ticker ) );
|
3391
|
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
|
4850
|
89 if ( tickerwindow != (GtkWidget *) NULL )
|
3391
|
90 return;
|
|
91 debug_printf("Making ticker\n");
|
4850
|
92 tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
93 g_signal_connect (GTK_OBJECT(tickerwindow), "destroy",
|
|
94 G_CALLBACK (BuddyTickerDestroyWindow), "WM destroy");
|
|
95 gtk_window_set_title (GTK_WINDOW(tickerwindow), _("Gaim - Buddy Ticker"));
|
|
96 gtk_window_set_role (GTK_WINDOW(tickerwindow), "ticker");
|
3391
|
97 gtk_widget_realize(tickerwindow);
|
|
98
|
4850
|
99 ticker = gtk_ticker_new();
|
3391
|
100 if (!ticker)
|
|
101 return;
|
4850
|
102 gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 );
|
|
103 gtk_widget_set_size_request( ticker, 500, -1 );
|
|
104 gtk_container_add( GTK_CONTAINER( tickerwindow ), ticker );
|
|
105 gtk_ticker_set_interval( GTK_TICKER( ticker ), 500 );
|
|
106 gtk_ticker_set_scootch( GTK_TICKER( ticker ), 10 );
|
3391
|
107 /* Damned egotists
|
4850
|
108 msgw = gtk_label_new( msg );
|
|
109 gtk_ticker_add( GTK_TICKER( ticker ), msgw );
|
|
110 */
|
3391
|
111 gtk_ticker_start_scroll( GTK_TICKER( ticker ) );
|
|
112
|
4168
|
113 g_timeout_add( 60000, BuddyTickerMessageRemove, NULL);
|
3391
|
114
|
4168
|
115 gtk_widget_show_all (ticker);
|
3391
|
116
|
|
117 }
|
|
118
|
|
119 gint
|
|
120 ButtonPressCallback( GtkWidget *widget, GdkEvent *event, gpointer callback_data )
|
|
121 {
|
|
122 TickerData *p = (TickerData *) callback_data;
|
4850
|
123 struct gaim_buddy_list *gaimbuddylist;
|
|
124 GaimBlistNode *group;
|
|
125 GaimBlistNode *buddy;
|
|
126 struct buddy *b = NULL;
|
|
127 char *norm_name = g_strdup(normalize(p->buddy));
|
|
128
|
|
129 if (!(gaimbuddylist = gaim_get_blist()))
|
|
130 return TRUE;
|
|
131
|
|
132 group = gaimbuddylist->root;
|
|
133 while (group) {
|
|
134 buddy = group->child;
|
|
135 while (buddy) {
|
|
136 if (!gaim_utf8_strcasecmp(normalize(((struct buddy*)buddy)->name), norm_name))
|
|
137 b = (struct buddy*)buddy;
|
|
138 buddy = buddy->next;
|
|
139 }
|
|
140 group = group->next;
|
|
141 }
|
|
142 g_free(norm_name);
|
|
143
|
|
144 if (b->account)
|
|
145 gaim_conversation_new(GAIM_CONV_IM, b->account, p->buddy);
|
3391
|
146
|
|
147 return TRUE;
|
|
148 }
|
|
149
|
|
150 void
|
4687
|
151 BuddyTickerAddUser( char *name, char *alias, const char *pb)
|
3391
|
152 {
|
|
153 TickerData *p;
|
|
154 GList *q;
|
|
155
|
|
156 if ( userclose == TRUE )
|
|
157 return;
|
|
158
|
|
159 debug_printf("Adding %s\n", name);
|
|
160
|
|
161 BuddyTickerCreateWindow();
|
|
162 if (!ticker)
|
|
163 return;
|
|
164
|
|
165 q = (GList *) BuddyTickerFindUser( name );
|
|
166 if ( q != (GList *) NULL )
|
|
167 return;
|
|
168
|
|
169 p = (TickerData *) malloc( sizeof( TickerData ) );
|
|
170 p->hbox = (GtkWidget *) NULL;
|
|
171 p->label = (GtkWidget *) NULL;
|
|
172 p->pix = (GtkWidget *) NULL;
|
|
173 strcpy( p->buddy, name );
|
|
174 strcpy( p->alias, alias);
|
|
175 tickerbuds = g_list_append( tickerbuds, p );
|
|
176
|
|
177 p->hbox = gtk_hbox_new( FALSE, 0 );
|
|
178 gtk_ticker_add( GTK_TICKER( ticker ), p->hbox );
|
|
179 gtk_widget_show_all( p->hbox );
|
|
180
|
4687
|
181 BuddyTickerSetPixmap(name, pb);
|
3391
|
182
|
|
183 p->ebox = gtk_event_box_new();
|
|
184
|
|
185 /* click detection */
|
|
186
|
4850
|
187 gtk_widget_set_events (p->ebox, GDK_BUTTON_PRESS_MASK);
|
|
188 g_signal_connect (GTK_OBJECT (p->ebox), "button_press_event",
|
|
189 G_CALLBACK(ButtonPressCallback), (gpointer) p);
|
3391
|
190
|
|
191 gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->ebox );
|
|
192 gtk_widget_show( p->ebox );
|
|
193
|
|
194 if (im_options & OPT_IM_ALIAS_TAB)
|
|
195 p->label = gtk_label_new( alias );
|
|
196 else
|
|
197 p->label = gtk_label_new( name );
|
|
198 gtk_container_add( GTK_CONTAINER(p->ebox), p->label );
|
|
199
|
|
200 gtk_widget_show( p->label );
|
|
201
|
4850
|
202 gtk_widget_show( tickerwindow );
|
3391
|
203 }
|
|
204
|
|
205 void
|
|
206 BuddyTickerRemoveUser( char *name )
|
|
207 {
|
|
208 GList *p = (GList *) BuddyTickerFindUser( name );
|
|
209 TickerData *data;
|
|
210
|
|
211 if ( !p )
|
|
212 return;
|
|
213
|
|
214 data = (TickerData *) p->data;
|
|
215
|
|
216 if ( userclose == TRUE )
|
|
217 return;
|
|
218 if ( data ) {
|
|
219 gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox );
|
|
220 tickerbuds = g_list_remove( tickerbuds, data );
|
|
221 free( data );
|
|
222 }
|
|
223 }
|
|
224
|
|
225 void
|
4687
|
226 BuddyTickerSetPixmap( char *name, const char *pb)
|
3391
|
227 {
|
|
228 GList *p;
|
|
229 TickerData *data;
|
4687
|
230 char *file = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", pb, NULL);
|
|
231
|
3391
|
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 ( data->pix == (GtkWidget *) NULL ) {
|
4687
|
240 data->pix = gtk_image_new_from_file(file);
|
3391
|
241 gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix );
|
|
242 } else {
|
|
243 gtk_widget_hide( data->pix );
|
4687
|
244 gtk_image_set_from_file(GTK_IMAGE(data->pix), file);
|
3391
|
245 }
|
|
246 gtk_widget_show( data->pix );
|
|
247 }
|
|
248
|
|
249 void
|
|
250 BuddyTickerSetAlias( char *name, char *alias) {
|
|
251 GList *p;
|
|
252 TickerData *data;
|
|
253
|
|
254 if ( userclose == TRUE )
|
|
255 return;
|
|
256 p = (GList *) BuddyTickerFindUser( name );
|
|
257 if ( p )
|
|
258 data = (TickerData *) p->data;
|
|
259 else
|
|
260 return;
|
|
261 if (alias) {
|
|
262 g_snprintf(data->alias, sizeof(data->alias), alias);
|
|
263
|
|
264 if (im_options & OPT_IM_ALIAS_TAB)
|
|
265 gtk_label_set_text(GTK_LABEL(data->label), alias);
|
|
266 }
|
|
267 }
|
|
268
|
|
269 GList *
|
|
270 BuddyTickerFindUser( char *name )
|
|
271 {
|
|
272 GList *p = tickerbuds;
|
|
273
|
|
274 while ( p ) {
|
|
275 TickerData *q = (TickerData *) p->data;
|
|
276 if ( !strcmp( name, q->buddy ) )
|
|
277 return( p );
|
|
278 p = p->next;
|
|
279 }
|
|
280 return (GList *) NULL;
|
|
281 }
|
|
282
|
|
283 void
|
|
284 BuddyTickerSetNames()
|
|
285 {
|
|
286 GList *p = tickerbuds;
|
|
287 while ( p ) {
|
|
288 TickerData *q = (TickerData *) p->data;
|
|
289 if (im_options & OPT_IM_ALIAS_TAB)
|
|
290 gtk_label_set_text(GTK_LABEL(q->label), q->alias);
|
|
291 else
|
|
292 gtk_label_set_text(GTK_LABEL(q->label), q->buddy);
|
|
293 p = p->next;
|
|
294 }
|
|
295 }
|
|
296
|
|
297 int
|
|
298 BuddyTickerMessageRemove( gpointer data )
|
|
299 {
|
|
300 if ( userclose == TRUE )
|
|
301 return FALSE;
|
|
302 if ( tickerwindow == NULL )
|
|
303 return FALSE;
|
|
304 gtk_ticker_remove( GTK_TICKER( ticker ), msgw );
|
|
305 return FALSE;
|
|
306 }
|
|
307
|
|
308 int
|
|
309 BuddyTickerLogonTimeout( gpointer data )
|
|
310 {
|
|
311 return FALSE;
|
|
312 }
|
|
313
|
|
314 int
|
|
315 BuddyTickerLogoutTimeout( gpointer data )
|
|
316 {
|
|
317 char *name = (char *) data;
|
|
318
|
|
319 if ( userclose == TRUE )
|
|
320 return FALSE;
|
|
321 BuddyTickerRemoveUser( name );
|
|
322
|
|
323 return FALSE;
|
|
324 }
|
|
325
|
|
326 void
|
|
327 BuddyTickerSignoff( void )
|
|
328 {
|
|
329 GList *p = tickerbuds;
|
|
330 TickerData *q;
|
|
331
|
|
332 while ( p ) {
|
|
333 q = (TickerData *) p->data;
|
|
334 if ( q )
|
|
335 BuddyTickerRemoveUser( q->buddy );
|
|
336 p = tickerbuds;
|
|
337 }
|
|
338 userclose = FALSE;
|
|
339 if ( tickerwindow )
|
|
340 gtk_widget_hide( tickerwindow );
|
|
341 }
|
|
342
|
|
343 void
|
|
344 BuddyTickerClearList( void )
|
|
345 {
|
|
346 GList *p = tickerbuds;
|
|
347
|
|
348 while ( p )
|
|
349 p = g_list_remove( p, p->data );
|
|
350 tickerbuds = (GList *) NULL;
|
|
351 }
|
|
352
|
|
353 void BuddyTickerShow()
|
|
354 {
|
4770
|
355 /* Someone should fix the ticker
|
3391
|
356 struct group *g;
|
|
357 struct buddy *b;
|
4349
|
358 GSList *grps, *buds;
|
4687
|
359 const char *xpm;
|
4349
|
360 for( grps = groups; grps; grps = grps->next ) {
|
|
361 g = (struct group *)grps->data;
|
|
362 for( buds = g->members; buds; buds = buds->next ) {
|
|
363 b = (struct buddy *)buds->data;
|
5068
|
364 if(GAIM_BUDDY_IS_ONLINE(b)) {
|
4349
|
365 xpm = NULL;
|
4491
|
366 if (b->account->gc->prpl->list_icon)
|
4687
|
367 xpm = b->account->gc->prpl->list_icon(b->account, b);
|
|
368 BuddyTickerAddUser( b->name, gaim_get_buddy_alias(b), xpm);
|
3391
|
369 }
|
|
370 }
|
|
371 }
|
4770
|
372 */
|
3391
|
373 }
|
|
374
|
|
375 void signon_cb(struct gaim_connection *gc, char *who) {
|
4850
|
376 struct buddy *b = gaim_find_buddy(gc->account, who);
|
4687
|
377 const char *xpm = NULL;
|
4850
|
378
|
3391
|
379 if (gc->prpl->list_icon)
|
4687
|
380 xpm = gc->prpl->list_icon(b->account, b);
|
|
381
|
|
382 BuddyTickerAddUser(who, gaim_get_buddy_alias(b), xpm);
|
3391
|
383 }
|
|
384
|
|
385 void signoff_cb(struct gaim_connection *gc) {
|
3630
|
386 if (connections && !connections->next) {
|
3391
|
387 gtk_widget_destroy(tickerwindow);
|
|
388 tickerwindow = NULL;
|
|
389 ticker = NULL;
|
|
390 }
|
|
391 }
|
|
392
|
|
393 void buddy_signoff_cb(struct gaim_connection *gc, char *who) {
|
|
394 BuddyTickerRemoveUser(who);
|
|
395 }
|
|
396
|
|
397 void away_cb(struct gaim_connection *gc, char *who) {
|
4850
|
398 struct buddy *b = gaim_find_buddy(gc->account, who);
|
4687
|
399 const char *xpm = NULL;
|
3391
|
400
|
|
401 if (gc->prpl->list_icon)
|
4687
|
402 xpm = gc->prpl->list_icon(b->account, b);
|
|
403 BuddyTickerSetPixmap(who, xpm);
|
3391
|
404 }
|
|
405
|
3630
|
406 /*
|
|
407 * EXPORTED FUNCTIONS
|
|
408 */
|
|
409
|
|
410 G_MODULE_EXPORT char *name() {
|
4585
|
411 return _("Buddy Ticker");
|
3630
|
412 }
|
|
413
|
|
414 G_MODULE_EXPORT char *description() {
|
4606
|
415 return _("A horizontal scrolling version of the buddy list.");
|
3630
|
416 }
|
|
417
|
|
418 G_MODULE_EXPORT char *gaim_plugin_init(GModule *h) {
|
3391
|
419 handle = h;
|
|
420
|
|
421 gaim_signal_connect(h, event_buddy_signon, signon_cb, NULL);
|
|
422 gaim_signal_connect(h, event_signoff, signoff_cb, NULL);
|
|
423 gaim_signal_connect(h, event_buddy_signoff, buddy_signoff_cb, NULL);
|
|
424 gaim_signal_connect(h, event_buddy_away, away_cb, NULL);
|
|
425
|
|
426 if (connections)
|
|
427 BuddyTickerShow();
|
|
428 return NULL;
|
|
429 }
|
|
430
|
3630
|
431 G_MODULE_EXPORT void gaim_plugin_remove() {
|
|
432 BuddyTickerDestroyWindow(tickerwindow);
|
3391
|
433 }
|
3551
|
434 struct gaim_plugin_description desc;
|
3630
|
435 G_MODULE_EXPORT struct gaim_plugin_description *gaim_plugin_desc() {
|
3551
|
436 desc.api_version = PLUGIN_API_VERSION;
|
4585
|
437 desc.name = g_strdup(_("Buddy Ticker"));
|
3551
|
438 desc.version = g_strdup(VERSION);
|
4585
|
439 desc.description = g_strdup(_("A horizontal scrolling version of the buddy list."));
|
3551
|
440 desc.authors = g_strdup("Syd Logan");
|
|
441 desc.url = g_strdup(WEBSITE);
|
|
442 return &desc;
|
|
443 }
|