Mercurial > pidgin
annotate plugins/ticker/ticker.c @ 4687:283fb289c510
[gaim-migrate @ 4998]
This is a new buddy list.
Lots of things about it just Don't Work. I probably already know about those
things, and you'd just be wasting my time in submitting a bug report about it.
I decided that instead of getting it to all work perfectly before committing,
that I'd get it in cvs, and slowly fix it with regular commits. That way, it's
easier to keep track of things, and other developers can help. Plus, I'm getting
pissed off at the buddy list and want it to die. It's kinda boring, and doing nothing
but the buddy list for such a long time has just gotten me very bitter.
After 0.60 is released later this week, Gaim will resume being fun. This week is
going to be very stressful, though, I'm sure.
Things you ought to know about this buddy list:
- It crashes
- It leaks
- There's no way to edit the buddy list, or access offline buddies
- Most of the menus and buttons and whatnot just plain ol' don't work.
- Status icons are only implemented for AIM.
That's mostly just because I'm lazy. As such, you may want to be wary of updating this.
If you do decide to update this, you may want to learn "cvs update -D yesterday" as well :)
All the art there is just placeholder art.
You probably won't really have as many problems as it sounds like you will from reading this.
This message is extra-negative to stress that I don't want to be bothered with complaints about
something not working about it :). I'll repeat: If something doesn't work, I probably already
know about it.
If you want to actually help with something, I'd be delighted to have it. IM me.
-s.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 10 Mar 2003 05:30:31 +0000 |
parents | 42d53c416bb9 |
children | e19f91053ad0 |
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" | |
32 #include "pixmaps/no_icon.xpm" | |
3630 | 33 #ifdef _WIN32 |
34 #include "win32dep.h" | |
35 #endif | |
3391 | 36 |
3867 | 37 #ifndef GAIM_PLUGINS |
38 #define GAIM_PLUGINS | |
39 #endif | |
40 | |
3391 | 41 static GtkWidget *tickerwindow = NULL; |
42 static GtkWidget *ticker; | |
43 static GModule *handle; | |
44 | |
45 typedef struct { | |
46 char buddy[ 128 ]; | |
47 char alias[ 388 ]; | |
48 GtkWidget *hbox; | |
49 GtkWidget *ebox; | |
50 GtkWidget *label; | |
51 GtkWidget *pix; | |
52 } TickerData; | |
53 | |
54 GList *tickerbuds = (GList *) NULL; | |
55 gboolean userclose = FALSE; | |
56 GtkWidget *msgw; | |
57 | |
3630 | 58 /* for win32 compatability */ |
59 G_MODULE_IMPORT GSList *connections; | |
60 G_MODULE_IMPORT GtkWidget *blist; | |
61 | |
3391 | 62 void BuddyTickerDestroyWindow( GtkWidget *window ); |
63 void BuddyTickerCreateWindow( void ); | |
4687 | 64 void BuddyTickerAddUser( char *name, char *alias, const char *pb); |
3391 | 65 void BuddyTickerRemoveUser( char *name ); |
4687 | 66 void BuddyTickerSetPixmap( char *name, const char *pb); |
3391 | 67 void BuddyTickerClearList( void ); |
68 void BuddyTickerSignOff( void ); | |
69 GList * BuddyTickerFindUser( char *name ); | |
70 int BuddyTickerMessageRemove( gpointer data ); | |
71 void BuddyTickerShow(); | |
72 | |
73 void | |
74 BuddyTickerDestroyWindow( GtkWidget *window ) | |
75 { | |
76 BuddyTickerClearList(); | |
77 gtk_ticker_stop_scroll( GTK_TICKER( ticker ) ); | |
78 gtk_widget_destroy( window ); | |
79 ticker = tickerwindow = (GtkWidget *) NULL; | |
80 userclose = TRUE; | |
81 } | |
82 | |
3466 | 83 /* 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"; |
84 */ | |
3391 | 85 |
86 void | |
87 BuddyTickerCreateWindow() | |
88 { | |
89 | |
90 if ( tickerwindow != (GtkWidget *) NULL ) | |
91 return; | |
92 debug_printf("Making ticker\n"); | |
93 tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4074
diff
changeset
|
94 g_signal_connect (GTK_OBJECT(tickerwindow), "destroy", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4074
diff
changeset
|
95 G_CALLBACK (BuddyTickerDestroyWindow), "WM destroy"); |
4586 | 96 gtk_window_set_title (GTK_WINDOW(tickerwindow), _("Gaim - Buddy Ticker")); |
4074 | 97 gtk_window_set_role (GTK_WINDOW(tickerwindow), "ticker"); |
3391 | 98 gtk_widget_realize(tickerwindow); |
99 | |
100 ticker = gtk_ticker_new(); | |
101 if (!ticker) | |
102 return; | |
103 gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 ); | |
4635 | 104 gtk_widget_set_size_request( ticker, 500, -1 ); |
3391 | 105 gtk_container_add( GTK_CONTAINER( tickerwindow ), ticker ); |
106 gtk_ticker_set_interval( GTK_TICKER( ticker ), 500 ); | |
107 gtk_ticker_set_scootch( GTK_TICKER( ticker ), 10 ); | |
108 /* Damned egotists | |
109 msgw = gtk_label_new( msg ); | |
110 gtk_ticker_add( GTK_TICKER( ticker ), msgw ); | |
111 */ | |
112 gtk_ticker_start_scroll( GTK_TICKER( ticker ) ); | |
113 | |
4168 | 114 g_timeout_add( 60000, BuddyTickerMessageRemove, NULL); |
3391 | 115 |
4168 | 116 gtk_widget_show_all (ticker); |
3391 | 117 |
118 } | |
119 | |
120 gint | |
121 ButtonPressCallback( GtkWidget *widget, GdkEvent *event, gpointer callback_data ) | |
122 { | |
123 TickerData *p = (TickerData *) callback_data; | |
4476
62c1e5e656d0
[gaim-migrate @ 4751]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
124 gaim_conversation_new(GAIM_CONV_IM, NULL, p->buddy); |
3391 | 125 |
126 return TRUE; | |
127 } | |
128 | |
129 void | |
4687 | 130 BuddyTickerAddUser( char *name, char *alias, const char *pb) |
3391 | 131 { |
132 TickerData *p; | |
133 GList *q; | |
134 | |
135 if ( userclose == TRUE ) | |
136 return; | |
137 | |
138 debug_printf("Adding %s\n", name); | |
139 | |
140 BuddyTickerCreateWindow(); | |
141 if (!ticker) | |
142 return; | |
143 | |
144 q = (GList *) BuddyTickerFindUser( name ); | |
145 if ( q != (GList *) NULL ) | |
146 return; | |
147 | |
148 p = (TickerData *) malloc( sizeof( TickerData ) ); | |
149 p->hbox = (GtkWidget *) NULL; | |
150 p->label = (GtkWidget *) NULL; | |
151 p->pix = (GtkWidget *) NULL; | |
152 strcpy( p->buddy, name ); | |
153 strcpy( p->alias, alias); | |
154 tickerbuds = g_list_append( tickerbuds, p ); | |
155 | |
156 p->hbox = gtk_hbox_new( FALSE, 0 ); | |
157 gtk_ticker_add( GTK_TICKER( ticker ), p->hbox ); | |
158 gtk_widget_show_all( p->hbox ); | |
159 | |
4687 | 160 BuddyTickerSetPixmap(name, pb); |
3391 | 161 |
162 p->ebox = gtk_event_box_new(); | |
163 | |
164 /* click detection */ | |
165 | |
166 gtk_widget_set_events (p->ebox, GDK_BUTTON_PRESS_MASK); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4074
diff
changeset
|
167 g_signal_connect (GTK_OBJECT (p->ebox), "button_press_event", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4074
diff
changeset
|
168 G_CALLBACK(ButtonPressCallback), (gpointer) p); |
3391 | 169 |
170 gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->ebox ); | |
171 gtk_widget_show( p->ebox ); | |
172 | |
173 if (im_options & OPT_IM_ALIAS_TAB) | |
174 p->label = gtk_label_new( alias ); | |
175 else | |
176 p->label = gtk_label_new( name ); | |
177 gtk_container_add( GTK_CONTAINER(p->ebox), p->label ); | |
178 | |
179 gtk_widget_show( p->label ); | |
180 | |
181 gtk_widget_show( tickerwindow ); | |
182 } | |
183 | |
184 void | |
185 BuddyTickerRemoveUser( char *name ) | |
186 { | |
187 GList *p = (GList *) BuddyTickerFindUser( name ); | |
188 TickerData *data; | |
189 | |
190 if ( !p ) | |
191 return; | |
192 | |
193 data = (TickerData *) p->data; | |
194 | |
195 if ( userclose == TRUE ) | |
196 return; | |
197 if ( data ) { | |
198 gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox ); | |
199 tickerbuds = g_list_remove( tickerbuds, data ); | |
200 free( data ); | |
201 } | |
202 } | |
203 | |
204 void | |
4687 | 205 BuddyTickerSetPixmap( char *name, const char *pb) |
3391 | 206 { |
207 GList *p; | |
208 TickerData *data; | |
4687 | 209 char *file = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", pb, NULL); |
210 | |
3391 | 211 if ( userclose == TRUE ) |
212 return; | |
213 p = (GList *) BuddyTickerFindUser( name ); | |
214 if ( p ) | |
215 data = (TickerData *) p->data; | |
216 else | |
217 return; | |
218 if ( data->pix == (GtkWidget *) NULL ) { | |
4687 | 219 data->pix = gtk_image_new_from_file(file); |
3391 | 220 gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix ); |
221 } else { | |
222 gtk_widget_hide( data->pix ); | |
4687 | 223 gtk_image_set_from_file(GTK_IMAGE(data->pix), file); |
3391 | 224 } |
225 gtk_widget_show( data->pix ); | |
226 } | |
227 | |
228 void | |
229 BuddyTickerSetAlias( char *name, char *alias) { | |
230 GList *p; | |
231 TickerData *data; | |
232 | |
233 if ( userclose == TRUE ) | |
234 return; | |
235 p = (GList *) BuddyTickerFindUser( name ); | |
236 if ( p ) | |
237 data = (TickerData *) p->data; | |
238 else | |
239 return; | |
240 if (alias) { | |
241 g_snprintf(data->alias, sizeof(data->alias), alias); | |
242 | |
243 if (im_options & OPT_IM_ALIAS_TAB) | |
244 gtk_label_set_text(GTK_LABEL(data->label), alias); | |
245 } | |
246 } | |
247 | |
248 GList * | |
249 BuddyTickerFindUser( char *name ) | |
250 { | |
251 GList *p = tickerbuds; | |
252 | |
253 while ( p ) { | |
254 TickerData *q = (TickerData *) p->data; | |
255 if ( !strcmp( name, q->buddy ) ) | |
256 return( p ); | |
257 p = p->next; | |
258 } | |
259 return (GList *) NULL; | |
260 } | |
261 | |
262 void | |
263 BuddyTickerSetNames() | |
264 { | |
265 GList *p = tickerbuds; | |
266 while ( p ) { | |
267 TickerData *q = (TickerData *) p->data; | |
268 if (im_options & OPT_IM_ALIAS_TAB) | |
269 gtk_label_set_text(GTK_LABEL(q->label), q->alias); | |
270 else | |
271 gtk_label_set_text(GTK_LABEL(q->label), q->buddy); | |
272 p = p->next; | |
273 } | |
274 } | |
275 | |
276 int | |
277 BuddyTickerMessageRemove( gpointer data ) | |
278 { | |
279 if ( userclose == TRUE ) | |
280 return FALSE; | |
281 if ( tickerwindow == NULL ) | |
282 return FALSE; | |
283 gtk_ticker_remove( GTK_TICKER( ticker ), msgw ); | |
284 return FALSE; | |
285 } | |
286 | |
287 int | |
288 BuddyTickerLogonTimeout( gpointer data ) | |
289 { | |
290 return FALSE; | |
291 } | |
292 | |
293 int | |
294 BuddyTickerLogoutTimeout( gpointer data ) | |
295 { | |
296 char *name = (char *) data; | |
297 | |
298 if ( userclose == TRUE ) | |
299 return FALSE; | |
300 BuddyTickerRemoveUser( name ); | |
301 | |
302 return FALSE; | |
303 } | |
304 | |
305 void | |
306 BuddyTickerSignoff( void ) | |
307 { | |
308 GList *p = tickerbuds; | |
309 TickerData *q; | |
310 | |
311 while ( p ) { | |
312 q = (TickerData *) p->data; | |
313 if ( q ) | |
314 BuddyTickerRemoveUser( q->buddy ); | |
315 p = tickerbuds; | |
316 } | |
317 userclose = FALSE; | |
318 if ( tickerwindow ) | |
319 gtk_widget_hide( tickerwindow ); | |
320 } | |
321 | |
322 void | |
323 BuddyTickerClearList( void ) | |
324 { | |
325 GList *p = tickerbuds; | |
326 | |
327 while ( p ) | |
328 p = g_list_remove( p, p->data ); | |
329 tickerbuds = (GList *) NULL; | |
330 } | |
331 | |
332 void BuddyTickerShow() | |
333 { | |
334 struct group *g; | |
335 struct buddy *b; | |
4349 | 336 GSList *grps, *buds; |
4687 | 337 const char *xpm; |
4349 | 338 |
339 for( grps = groups; grps; grps = grps->next ) { | |
340 g = (struct group *)grps->data; | |
341 for( buds = g->members; buds; buds = buds->next ) { | |
342 b = (struct buddy *)buds->data; | |
343 if( b->present ) { | |
344 xpm = NULL; | |
4491 | 345 if (b->account->gc->prpl->list_icon) |
4687 | 346 xpm = b->account->gc->prpl->list_icon(b->account, b); |
347 BuddyTickerAddUser( b->name, gaim_get_buddy_alias(b), xpm); | |
3391 | 348 } |
349 } | |
350 } | |
351 } | |
352 | |
353 void signon_cb(struct gaim_connection *gc, char *who) { | |
4687 | 354 struct buddy *b = gaim_find_buddy(gc->account, who); |
355 const char *xpm = NULL; | |
356 | |
3391 | 357 if (gc->prpl->list_icon) |
4687 | 358 xpm = gc->prpl->list_icon(b->account, b); |
359 | |
360 BuddyTickerAddUser(who, gaim_get_buddy_alias(b), xpm); | |
3391 | 361 } |
362 | |
363 void signoff_cb(struct gaim_connection *gc) { | |
3630 | 364 if (connections && !connections->next) { |
3391 | 365 gtk_widget_destroy(tickerwindow); |
366 tickerwindow = NULL; | |
367 ticker = NULL; | |
368 } | |
369 } | |
370 | |
371 void buddy_signoff_cb(struct gaim_connection *gc, char *who) { | |
372 BuddyTickerRemoveUser(who); | |
373 } | |
374 | |
375 void away_cb(struct gaim_connection *gc, char *who) { | |
4687 | 376 struct buddy *b = gaim_find_buddy(gc->account, who); |
377 const char *xpm = NULL; | |
3391 | 378 |
379 if (gc->prpl->list_icon) | |
4687 | 380 xpm = gc->prpl->list_icon(b->account, b); |
381 BuddyTickerSetPixmap(who, xpm); | |
3391 | 382 } |
383 | |
3630 | 384 /* |
385 * EXPORTED FUNCTIONS | |
386 */ | |
387 | |
388 G_MODULE_EXPORT char *name() { | |
4585 | 389 return _("Buddy Ticker"); |
3630 | 390 } |
391 | |
392 G_MODULE_EXPORT char *description() { | |
4606 | 393 return _("A horizontal scrolling version of the buddy list."); |
3630 | 394 } |
395 | |
396 G_MODULE_EXPORT char *gaim_plugin_init(GModule *h) { | |
3391 | 397 handle = h; |
398 | |
399 gaim_signal_connect(h, event_buddy_signon, signon_cb, NULL); | |
400 gaim_signal_connect(h, event_signoff, signoff_cb, NULL); | |
401 gaim_signal_connect(h, event_buddy_signoff, buddy_signoff_cb, NULL); | |
402 gaim_signal_connect(h, event_buddy_away, away_cb, NULL); | |
403 | |
404 if (connections) | |
405 BuddyTickerShow(); | |
406 return NULL; | |
407 } | |
408 | |
3630 | 409 G_MODULE_EXPORT void gaim_plugin_remove() { |
410 BuddyTickerDestroyWindow(tickerwindow); | |
3391 | 411 } |
3551 | 412 struct gaim_plugin_description desc; |
3630 | 413 G_MODULE_EXPORT struct gaim_plugin_description *gaim_plugin_desc() { |
3551 | 414 desc.api_version = PLUGIN_API_VERSION; |
4585 | 415 desc.name = g_strdup(_("Buddy Ticker")); |
3551 | 416 desc.version = g_strdup(VERSION); |
4585 | 417 desc.description = g_strdup(_("A horizontal scrolling version of the buddy list.")); |
3551 | 418 desc.authors = g_strdup("Syd Logan"); |
419 desc.url = g_strdup(WEBSITE); | |
420 return &desc; | |
421 } |