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