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 );
|
|
162 TickerData *data = (TickerData *) p->data;
|
|
163
|
432
|
164 if ( userclose == TRUE )
|
|
165 return;
|
430
|
166 if ( data ) {
|
|
167 gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox );
|
|
168 tickerbuds = g_list_remove( tickerbuds, data );
|
|
169 free( data );
|
|
170 }
|
|
171 }
|
|
172
|
|
173 void
|
|
174 BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm )
|
|
175 {
|
432
|
176 GList *p;
|
|
177 TickerData *data;
|
430
|
178
|
432
|
179 if ( userclose == TRUE )
|
|
180 return;
|
|
181 p = (GList *) BuddyTickerFindUser( name );
|
436
|
182 if ( p )
|
|
183 data = (TickerData *) p->data;
|
|
184 else
|
|
185 return;
|
430
|
186 if ( data->pix == (GtkWidget *) NULL ) {
|
|
187 data->pix = gtk_pixmap_new( pm, bm );
|
|
188 gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix );
|
|
189 } else {
|
|
190 gtk_widget_hide( data->pix );
|
|
191 gtk_pixmap_set(GTK_PIXMAP(data->pix), pm, bm);
|
|
192 }
|
|
193 gtk_widget_show( data->pix );
|
|
194 }
|
|
195
|
|
196 GList *
|
|
197 BuddyTickerFindUser( char *name )
|
|
198 {
|
|
199 GList *p = tickerbuds;
|
|
200
|
|
201 while ( p ) {
|
|
202 TickerData *q = (TickerData *) p->data;
|
|
203 if ( !strcmp( name, q->buddy ) )
|
|
204 return( p );
|
|
205 p = p->next;
|
|
206 }
|
|
207 return (GList *) NULL;
|
|
208 }
|
|
209
|
|
210 int
|
433
|
211 BuddyTickerMessageRemove( gpointer data )
|
|
212 {
|
|
213 if ( userclose == TRUE )
|
|
214 return;
|
|
215 gtk_ticker_remove( GTK_TICKER( ticker ), msgw );
|
|
216 return FALSE;
|
|
217 }
|
|
218
|
|
219 int
|
430
|
220 BuddyTickerLogonTimeout( gpointer data )
|
|
221 {
|
|
222 return FALSE;
|
|
223 }
|
|
224
|
|
225 int
|
|
226 BuddyTickerLogoutTimeout( gpointer data )
|
|
227 {
|
|
228 char *name = (char *) data;
|
|
229
|
432
|
230 if ( userclose == TRUE )
|
|
231 return FALSE;
|
430
|
232 BuddyTickerRemoveUser( name );
|
|
233
|
|
234 return FALSE;
|
|
235 }
|
432
|
236
|
|
237 void
|
|
238 BuddyTickerSignoff( void )
|
|
239 {
|
|
240 GList *p = tickerbuds;
|
|
241 TickerData *q;
|
|
242
|
|
243 while ( p ) {
|
|
244 q = (TickerData *) p->data;
|
436
|
245 if ( q )
|
|
246 BuddyTickerRemoveUser( q->buddy );
|
432
|
247 p = tickerbuds;
|
|
248 }
|
|
249 userclose = FALSE;
|
434
|
250 gtk_widget_hide( tickerwindow );
|
432
|
251 }
|
|
252
|
|
253 void
|
|
254 BuddyTickerClearList( void )
|
|
255 {
|
|
256 GList *p = tickerbuds;
|
|
257
|
436
|
258 while ( p )
|
432
|
259 p = g_list_remove( p, p->data );
|
|
260 tickerbuds = (GList *) NULL;
|
|
261 }
|
|
262
|
|
263
|