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