Mercurial > pidgin
annotate plugins/ticker/ticker.c @ 4694:8f523dbb970e
[gaim-migrate @ 5005]
more blist goodness:
* all the buttons at the bottom work
* the away message menu is back
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Mon, 10 Mar 2003 16:39:46 +0000 |
parents | e19f91053ad0 |
children | c4c28874ecd3 |
rev | line source |
---|---|
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(); | |
76 gtk_ticker_stop_scroll( GTK_TICKER( ticker ) ); | |
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 | |
89 if ( tickerwindow != (GtkWidget *) NULL ) | |
90 return; | |
91 debug_printf("Making ticker\n"); | |
92 tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4074
diff
changeset
|
93 g_signal_connect (GTK_OBJECT(tickerwindow), "destroy", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4074
diff
changeset
|
94 G_CALLBACK (BuddyTickerDestroyWindow), "WM destroy"); |
4586 | 95 gtk_window_set_title (GTK_WINDOW(tickerwindow), _("Gaim - Buddy Ticker")); |
4074 | 96 gtk_window_set_role (GTK_WINDOW(tickerwindow), "ticker"); |
3391 | 97 gtk_widget_realize(tickerwindow); |
98 | |
99 ticker = gtk_ticker_new(); | |
100 if (!ticker) | |
101 return; | |
102 gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 ); | |
4635 | 103 gtk_widget_set_size_request( ticker, 500, -1 ); |
3391 | 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 ); | |
107 /* Damned egotists | |
108 msgw = gtk_label_new( msg ); | |
109 gtk_ticker_add( GTK_TICKER( ticker ), msgw ); | |
110 */ | |
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; | |
4476
62c1e5e656d0
[gaim-migrate @ 4751]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
123 gaim_conversation_new(GAIM_CONV_IM, NULL, p->buddy); |
3391 | 124 |
125 return TRUE; | |
126 } | |
127 | |
128 void | |
4687 | 129 BuddyTickerAddUser( char *name, char *alias, const char *pb) |
3391 | 130 { |
131 TickerData *p; | |
132 GList *q; | |
133 | |
134 if ( userclose == TRUE ) | |
135 return; | |
136 | |
137 debug_printf("Adding %s\n", name); | |
138 | |
139 BuddyTickerCreateWindow(); | |
140 if (!ticker) | |
141 return; | |
142 | |
143 q = (GList *) BuddyTickerFindUser( name ); | |
144 if ( q != (GList *) NULL ) | |
145 return; | |
146 | |
147 p = (TickerData *) malloc( sizeof( TickerData ) ); | |
148 p->hbox = (GtkWidget *) NULL; | |
149 p->label = (GtkWidget *) NULL; | |
150 p->pix = (GtkWidget *) NULL; | |
151 strcpy( p->buddy, name ); | |
152 strcpy( p->alias, alias); | |
153 tickerbuds = g_list_append( tickerbuds, p ); | |
154 | |
155 p->hbox = gtk_hbox_new( FALSE, 0 ); | |
156 gtk_ticker_add( GTK_TICKER( ticker ), p->hbox ); | |
157 gtk_widget_show_all( p->hbox ); | |
158 | |
4687 | 159 BuddyTickerSetPixmap(name, pb); |
3391 | 160 |
161 p->ebox = gtk_event_box_new(); | |
162 | |
163 /* click detection */ | |
164 | |
165 gtk_widget_set_events (p->ebox, GDK_BUTTON_PRESS_MASK); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4074
diff
changeset
|
166 g_signal_connect (GTK_OBJECT (p->ebox), "button_press_event", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4074
diff
changeset
|
167 G_CALLBACK(ButtonPressCallback), (gpointer) p); |
3391 | 168 |
169 gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->ebox ); | |
170 gtk_widget_show( p->ebox ); | |
171 | |
172 if (im_options & OPT_IM_ALIAS_TAB) | |
173 p->label = gtk_label_new( alias ); | |
174 else | |
175 p->label = gtk_label_new( name ); | |
176 gtk_container_add( GTK_CONTAINER(p->ebox), p->label ); | |
177 | |
178 gtk_widget_show( p->label ); | |
179 | |
180 gtk_widget_show( tickerwindow ); | |
181 } | |
182 | |
183 void | |
184 BuddyTickerRemoveUser( char *name ) | |
185 { | |
186 GList *p = (GList *) BuddyTickerFindUser( name ); | |
187 TickerData *data; | |
188 | |
189 if ( !p ) | |
190 return; | |
191 | |
192 data = (TickerData *) p->data; | |
193 | |
194 if ( userclose == TRUE ) | |
195 return; | |
196 if ( data ) { | |
197 gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox ); | |
198 tickerbuds = g_list_remove( tickerbuds, data ); | |
199 free( data ); | |
200 } | |
201 } | |
202 | |
203 void | |
4687 | 204 BuddyTickerSetPixmap( char *name, const char *pb) |
3391 | 205 { |
206 GList *p; | |
207 TickerData *data; | |
4687 | 208 char *file = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", pb, NULL); |
209 | |
3391 | 210 if ( userclose == TRUE ) |
211 return; | |
212 p = (GList *) BuddyTickerFindUser( name ); | |
213 if ( p ) | |
214 data = (TickerData *) p->data; | |
215 else | |
216 return; | |
217 if ( data->pix == (GtkWidget *) NULL ) { | |
4687 | 218 data->pix = gtk_image_new_from_file(file); |
3391 | 219 gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix ); |
220 } else { | |
221 gtk_widget_hide( data->pix ); | |
4687 | 222 gtk_image_set_from_file(GTK_IMAGE(data->pix), file); |
3391 | 223 } |
224 gtk_widget_show( data->pix ); | |
225 } | |
226 | |
227 void | |
228 BuddyTickerSetAlias( char *name, char *alias) { | |
229 GList *p; | |
230 TickerData *data; | |
231 | |
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 (alias) { | |
240 g_snprintf(data->alias, sizeof(data->alias), alias); | |
241 | |
242 if (im_options & OPT_IM_ALIAS_TAB) | |
243 gtk_label_set_text(GTK_LABEL(data->label), alias); | |
244 } | |
245 } | |
246 | |
247 GList * | |
248 BuddyTickerFindUser( char *name ) | |
249 { | |
250 GList *p = tickerbuds; | |
251 | |
252 while ( p ) { | |
253 TickerData *q = (TickerData *) p->data; | |
254 if ( !strcmp( name, q->buddy ) ) | |
255 return( p ); | |
256 p = p->next; | |
257 } | |
258 return (GList *) NULL; | |
259 } | |
260 | |
261 void | |
262 BuddyTickerSetNames() | |
263 { | |
264 GList *p = tickerbuds; | |
265 while ( p ) { | |
266 TickerData *q = (TickerData *) p->data; | |
267 if (im_options & OPT_IM_ALIAS_TAB) | |
268 gtk_label_set_text(GTK_LABEL(q->label), q->alias); | |
269 else | |
270 gtk_label_set_text(GTK_LABEL(q->label), q->buddy); | |
271 p = p->next; | |
272 } | |
273 } | |
274 | |
275 int | |
276 BuddyTickerMessageRemove( gpointer data ) | |
277 { | |
278 if ( userclose == TRUE ) | |
279 return FALSE; | |
280 if ( tickerwindow == NULL ) | |
281 return FALSE; | |
282 gtk_ticker_remove( GTK_TICKER( ticker ), msgw ); | |
283 return FALSE; | |
284 } | |
285 | |
286 int | |
287 BuddyTickerLogonTimeout( gpointer data ) | |
288 { | |
289 return FALSE; | |
290 } | |
291 | |
292 int | |
293 BuddyTickerLogoutTimeout( gpointer data ) | |
294 { | |
295 char *name = (char *) data; | |
296 | |
297 if ( userclose == TRUE ) | |
298 return FALSE; | |
299 BuddyTickerRemoveUser( name ); | |
300 | |
301 return FALSE; | |
302 } | |
303 | |
304 void | |
305 BuddyTickerSignoff( void ) | |
306 { | |
307 GList *p = tickerbuds; | |
308 TickerData *q; | |
309 | |
310 while ( p ) { | |
311 q = (TickerData *) p->data; | |
312 if ( q ) | |
313 BuddyTickerRemoveUser( q->buddy ); | |
314 p = tickerbuds; | |
315 } | |
316 userclose = FALSE; | |
317 if ( tickerwindow ) | |
318 gtk_widget_hide( tickerwindow ); | |
319 } | |
320 | |
321 void | |
322 BuddyTickerClearList( void ) | |
323 { | |
324 GList *p = tickerbuds; | |
325 | |
326 while ( p ) | |
327 p = g_list_remove( p, p->data ); | |
328 tickerbuds = (GList *) NULL; | |
329 } | |
330 | |
331 void BuddyTickerShow() | |
332 { | |
333 struct group *g; | |
334 struct buddy *b; | |
4349 | 335 GSList *grps, *buds; |
4687 | 336 const char *xpm; |
4349 | 337 |
338 for( grps = groups; grps; grps = grps->next ) { | |
339 g = (struct group *)grps->data; | |
340 for( buds = g->members; buds; buds = buds->next ) { | |
341 b = (struct buddy *)buds->data; | |
342 if( b->present ) { | |
343 xpm = NULL; | |
4491 | 344 if (b->account->gc->prpl->list_icon) |
4687 | 345 xpm = b->account->gc->prpl->list_icon(b->account, b); |
346 BuddyTickerAddUser( b->name, gaim_get_buddy_alias(b), xpm); | |
3391 | 347 } |
348 } | |
349 } | |
350 } | |
351 | |
352 void signon_cb(struct gaim_connection *gc, char *who) { | |
4687 | 353 struct buddy *b = gaim_find_buddy(gc->account, who); |
354 const char *xpm = NULL; | |
355 | |
3391 | 356 if (gc->prpl->list_icon) |
4687 | 357 xpm = gc->prpl->list_icon(b->account, b); |
358 | |
359 BuddyTickerAddUser(who, gaim_get_buddy_alias(b), xpm); | |
3391 | 360 } |
361 | |
362 void signoff_cb(struct gaim_connection *gc) { | |
3630 | 363 if (connections && !connections->next) { |
3391 | 364 gtk_widget_destroy(tickerwindow); |
365 tickerwindow = NULL; | |
366 ticker = NULL; | |
367 } | |
368 } | |
369 | |
370 void buddy_signoff_cb(struct gaim_connection *gc, char *who) { | |
371 BuddyTickerRemoveUser(who); | |
372 } | |
373 | |
374 void away_cb(struct gaim_connection *gc, char *who) { | |
4687 | 375 struct buddy *b = gaim_find_buddy(gc->account, who); |
376 const char *xpm = NULL; | |
3391 | 377 |
378 if (gc->prpl->list_icon) | |
4687 | 379 xpm = gc->prpl->list_icon(b->account, b); |
380 BuddyTickerSetPixmap(who, xpm); | |
3391 | 381 } |
382 | |
3630 | 383 /* |
384 * EXPORTED FUNCTIONS | |
385 */ | |
386 | |
387 G_MODULE_EXPORT char *name() { | |
4585 | 388 return _("Buddy Ticker"); |
3630 | 389 } |
390 | |
391 G_MODULE_EXPORT char *description() { | |
4606 | 392 return _("A horizontal scrolling version of the buddy list."); |
3630 | 393 } |
394 | |
395 G_MODULE_EXPORT char *gaim_plugin_init(GModule *h) { | |
3391 | 396 handle = h; |
397 | |
398 gaim_signal_connect(h, event_buddy_signon, signon_cb, NULL); | |
399 gaim_signal_connect(h, event_signoff, signoff_cb, NULL); | |
400 gaim_signal_connect(h, event_buddy_signoff, buddy_signoff_cb, NULL); | |
401 gaim_signal_connect(h, event_buddy_away, away_cb, NULL); | |
402 | |
403 if (connections) | |
404 BuddyTickerShow(); | |
405 return NULL; | |
406 } | |
407 | |
3630 | 408 G_MODULE_EXPORT void gaim_plugin_remove() { |
409 BuddyTickerDestroyWindow(tickerwindow); | |
3391 | 410 } |
3551 | 411 struct gaim_plugin_description desc; |
3630 | 412 G_MODULE_EXPORT struct gaim_plugin_description *gaim_plugin_desc() { |
3551 | 413 desc.api_version = PLUGIN_API_VERSION; |
4585 | 414 desc.name = g_strdup(_("Buddy Ticker")); |
3551 | 415 desc.version = g_strdup(VERSION); |
4585 | 416 desc.description = g_strdup(_("A horizontal scrolling version of the buddy list.")); |
3551 | 417 desc.authors = g_strdup("Syd Logan"); |
418 desc.url = g_strdup(WEBSITE); | |
419 return &desc; | |
420 } |