430
|
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 */
|
|
23
|
|
24 #include <gtk/gtk.h>
|
|
25 #include "gtkticker.h"
|
|
26
|
|
27 GtkWidget *tickerwindow = NULL;
|
|
28 GtkWidget *ticker;
|
|
29
|
|
30 typedef struct {
|
|
31 char buddy[ 128 ];
|
|
32 GtkWidget *hbox;
|
438
|
33 GtkWidget *ebox;
|
430
|
34 GtkWidget *label;
|
|
35 GtkWidget *pix;
|
|
36 } TickerData;
|
|
37
|
|
38 static GList *tickerbuds = (GList *) NULL;
|
432
|
39 static gboolean userclose = FALSE;
|
433
|
40 static GtkWidget *msgw;
|
430
|
41
|
|
42 void BuddyTickerDestroyWindow( GtkWidget *window );
|
|
43 void BuddyTickerCreateWindow( void );
|
|
44 void BuddyTickerAddUser( char *name, GdkPixmap *pm, GdkBitmap *bm );
|
|
45 void BuddyTickerRemoveUser( char *name );
|
|
46 void BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm );
|
432
|
47 void BuddyTickerClearList( void );
|
|
48 void BuddyTickerSignOff( void );
|
430
|
49 GList * BuddyTickerFindUser( char *name );
|
433
|
50 int BuddyTickerMessageRemove( gpointer data );
|
430
|
51
|
436
|
52 // this pref is startup only, so make a shadow here of settings at startup
|
|
53 // code uses this variable, not display_prefs
|
|
54
|
|
55 extern int display_options;
|
|
56 int ticker_prefs;
|
|
57
|
|
58 void
|
|
59 SetTickerPrefs( void )
|
|
60 {
|
|
61 ticker_prefs = display_options;
|
|
62 }
|
|
63
|
430
|
64 void
|
|
65 BuddyTickerDestroyWindow( GtkWidget *window )
|
|
66 {
|
432
|
67 BuddyTickerClearList();
|
430
|
68 gtk_ticker_stop_scroll( GTK_TICKER( ticker ) );
|
|
69 gtk_widget_destroy( window );
|
|
70 ticker = tickerwindow = (GtkWidget *) NULL;
|
432
|
71 userclose = TRUE;
|
430
|
72 }
|
|
73
|
433
|
74 static char *msg = "Welcome to GAIM 0.9.20, brought to you by Rob Flynn (maintainer), Eric Warmenhoven, Mark Spencer, Jeramey Crawford, Jim Duchek, and Syd Logan";
|
|
75
|
430
|
76 void
|
|
77 BuddyTickerCreateWindow()
|
|
78 {
|
|
79 if ( tickerwindow != (GtkWidget *) NULL )
|
|
80 return;
|
|
81 tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
82 gtk_signal_connect (GTK_OBJECT(tickerwindow), "destroy",
|
|
83 GTK_SIGNAL_FUNC (BuddyTickerDestroyWindow), "WM destroy");
|
433
|
84 gtk_window_set_title (GTK_WINDOW(tickerwindow), "GAIM - Buddy Ticker");
|
430
|
85
|
|
86 ticker = gtk_ticker_new();
|
433
|
87 gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 );
|
|
88 gtk_widget_set_usize( ticker, 500, -1 );
|
430
|
89 gtk_container_add( GTK_CONTAINER( tickerwindow ), ticker );
|
|
90 gtk_ticker_set_interval( GTK_TICKER( ticker ), 500 );
|
|
91 gtk_ticker_set_scootch( GTK_TICKER( ticker ), 10 );
|
433
|
92 msgw = gtk_label_new( msg );
|
|
93 gtk_ticker_add( GTK_TICKER( ticker ), msgw );
|
430
|
94 gtk_ticker_start_scroll( GTK_TICKER( ticker ) );
|
433
|
95
|
|
96 gtk_timeout_add( 60000, BuddyTickerMessageRemove, (gpointer) NULL );
|
|
97
|
|
98 gtk_widget_show_all (ticker);
|
|
99
|
430
|
100 }
|
|
101
|
438
|
102 gint
|
|
103 ButtonPressCallback( GtkWidget *widget, GdkEvent *event, gpointer callback_data )
|
|
104 {
|
|
105 TickerData *p = (TickerData *) callback_data;
|
|
106
|
|
107 pressed_ticker( p->buddy );
|
|
108 }
|
|
109
|
430
|
110 void
|
|
111 BuddyTickerAddUser( char *name, GdkPixmap *pm, GdkBitmap *bm )
|
|
112 {
|
|
113 GtkWidget *hbox, *label, *pmap;
|
|
114 TickerData *p;
|
432
|
115 GList *q;
|
|
116
|
|
117 if ( userclose == TRUE )
|
|
118 return;
|
436
|
119
|
|
120 BuddyTickerCreateWindow();
|
|
121
|
432
|
122 q = (GList *) BuddyTickerFindUser( name );
|
|
123 if ( q != (GList *) NULL )
|
|
124 return;
|
430
|
125
|
|
126 p = (TickerData *) malloc( sizeof( TickerData ) );
|
|
127 p->hbox = (GtkWidget *) NULL;
|
|
128 p->label = (GtkWidget *) NULL;
|
|
129 p->pix = (GtkWidget *) NULL;
|
|
130 strcpy( p->buddy, name );
|
|
131 tickerbuds = g_list_append( tickerbuds, p );
|
|
132
|
|
133 p->hbox = gtk_hbox_new( FALSE, 0 );
|
|
134 gtk_ticker_add( GTK_TICKER( ticker ), p->hbox );
|
|
135 gtk_widget_show_all( p->hbox );
|
|
136
|
|
137 BuddyTickerSetPixmap( name, pm, bm );
|
|
138
|
438
|
139 p->ebox = gtk_event_box_new();
|
|
140
|
|
141 // click detection
|
|
142
|
|
143 gtk_widget_set_events (p->ebox, GDK_BUTTON_PRESS_MASK);
|
|
144 gtk_signal_connect (GTK_OBJECT (p->ebox), "button_press_event",
|
|
145 GTK_SIGNAL_FUNC(ButtonPressCallback), (gpointer) p);
|
|
146
|
|
147 gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->ebox );
|
|
148 gtk_widget_show( p->ebox );
|
|
149
|
430
|
150 p->label = gtk_label_new( name );
|
438
|
151 gtk_container_add( GTK_CONTAINER(p->ebox), p->label );
|
|
152
|
430
|
153 gtk_widget_show( p->label );
|
|
154
|
|
155 gtk_widget_show( tickerwindow );
|
|
156 }
|
|
157
|
|
158 void
|
|
159 BuddyTickerRemoveUser( char *name )
|
|
160 {
|
|
161 GList *p = (GList *) BuddyTickerFindUser( name );
|
460
|
162 TickerData *data;
|
|
163
|
|
164 if ( !p )
|
|
165 return;
|
|
166
|
|
167 data = (TickerData *) p->data;
|
430
|
168
|
432
|
169 if ( userclose == TRUE )
|
|
170 return;
|
430
|
171 if ( data ) {
|
|
172 gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox );
|
|
173 tickerbuds = g_list_remove( tickerbuds, data );
|
|
174 free( data );
|
|
175 }
|
|
176 }
|
|
177
|
|
178 void
|
|
179 BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm )
|
|
180 {
|
432
|
181 GList *p;
|
|
182 TickerData *data;
|
430
|
183
|
432
|
184 if ( userclose == TRUE )
|
|
185 return;
|
|
186 p = (GList *) BuddyTickerFindUser( name );
|
436
|
187 if ( p )
|
|
188 data = (TickerData *) p->data;
|
|
189 else
|
|
190 return;
|
430
|
191 if ( data->pix == (GtkWidget *) NULL ) {
|
|
192 data->pix = gtk_pixmap_new( pm, bm );
|
|
193 gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix );
|
|
194 } else {
|
|
195 gtk_widget_hide( data->pix );
|
|
196 gtk_pixmap_set(GTK_PIXMAP(data->pix), pm, bm);
|
|
197 }
|
|
198 gtk_widget_show( data->pix );
|
|
199 }
|
|
200
|
|
201 GList *
|
|
202 BuddyTickerFindUser( char *name )
|
|
203 {
|
|
204 GList *p = tickerbuds;
|
|
205
|
|
206 while ( p ) {
|
|
207 TickerData *q = (TickerData *) p->data;
|
|
208 if ( !strcmp( name, q->buddy ) )
|
|
209 return( p );
|
|
210 p = p->next;
|
|
211 }
|
|
212 return (GList *) NULL;
|
|
213 }
|
|
214
|
|
215 int
|
433
|
216 BuddyTickerMessageRemove( gpointer data )
|
|
217 {
|
|
218 if ( userclose == TRUE )
|
|
219 return;
|
|
220 gtk_ticker_remove( GTK_TICKER( ticker ), msgw );
|
|
221 return FALSE;
|
|
222 }
|
|
223
|
|
224 int
|
430
|
225 BuddyTickerLogonTimeout( gpointer data )
|
|
226 {
|
|
227 return FALSE;
|
|
228 }
|
|
229
|
|
230 int
|
|
231 BuddyTickerLogoutTimeout( gpointer data )
|
|
232 {
|
|
233 char *name = (char *) data;
|
|
234
|
432
|
235 if ( userclose == TRUE )
|
|
236 return FALSE;
|
430
|
237 BuddyTickerRemoveUser( name );
|
|
238
|
|
239 return FALSE;
|
|
240 }
|
432
|
241
|
|
242 void
|
|
243 BuddyTickerSignoff( void )
|
|
244 {
|
|
245 GList *p = tickerbuds;
|
|
246 TickerData *q;
|
|
247
|
|
248 while ( p ) {
|
|
249 q = (TickerData *) p->data;
|
436
|
250 if ( q )
|
|
251 BuddyTickerRemoveUser( q->buddy );
|
432
|
252 p = tickerbuds;
|
|
253 }
|
|
254 userclose = FALSE;
|
434
|
255 gtk_widget_hide( tickerwindow );
|
432
|
256 }
|
|
257
|
|
258 void
|
|
259 BuddyTickerClearList( void )
|
|
260 {
|
|
261 GList *p = tickerbuds;
|
|
262
|
436
|
263 while ( p )
|
432
|
264 p = g_list_remove( p, p->data );
|
|
265 tickerbuds = (GList *) NULL;
|
|
266 }
|
|
267
|
|
268
|