Mercurial > pidgin.yaz
annotate plugins/gtik.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 | ebfb80bbe1ed |
children | fefad67de2c7 |
rev | line source |
---|---|
426 | 1 /* |
2 * GNOME Stock Ticker | |
3 * (C) 2000 Jayson Lorenzen, Jim Garrison, Rached Blili | |
4 * | |
5 * based on: | |
6 * desire, and the old great slash applet. | |
7 * | |
8 * | |
9 * Authors: Jayson Lorenzen (jaysonl@pacbell.net) | |
10 * Jim Garrison (garrison@users.sourceforge.net) | |
11 * Rached Blili (striker@Dread.net) | |
12 * | |
13 * The Gnome Stock Ticker is a free, Internet based application. | |
14 * These quotes are not guaranteed to be timely or accurate. | |
15 * | |
16 * Do not use the Gnome Stock Ticker for making investment decisions, | |
17 * it is for informational purposes only. | |
18 * | |
2142
4bd8e3b65402
[gaim-migrate @ 2152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2130
diff
changeset
|
19 * Modified by EWarmenhoven to become a gaim plugin. There was little |
426 | 20 * enough that needed to be changed that I can't really claim any credit. |
21 * (you need to add -lghttp to the GTK_LIBS part of the Makefile) | |
22 * TODO: config, saving info | |
23 * | |
24 */ | |
25 | |
26 #define GAIM_PLUGINS | |
27 #include "gaim.h" | |
28 | |
29 #include <gtk/gtk.h> | |
30 #include <time.h> | |
31 #include <stdlib.h> | |
32 #include <stdio.h> | |
33 #include <string.h> | |
34 | |
35 #include "ghttp.h" | |
36 #include <sys/stat.h> | |
37 #include <unistd.h> | |
38 #include <dirent.h> | |
39 #include <gdk/gdkx.h> | |
40 | |
41 | |
42 GtkWidget *applet; /* this will become the main window */ | |
43 GtkWidget *label; | |
44 | |
45 | |
46 static GdkPixmap *pixmap = NULL; | |
47 GtkWidget * drawing_area; | |
48 | |
49 int location; | |
50 int MOVE; | |
51 | |
52 char output[64]; | |
53 | |
54 /** | |
55 * FOR COLOR | |
56 * LEN and the length of output, and colorNum must match | |
57 */ | |
58 const int LEN = 20; | |
59 char outputArray[20][64]; | |
60 char changeArray[20][64]; | |
61 int colorArray[20]; | |
62 | |
63 const int RED = 1; | |
64 const int GREEN = 2; | |
65 | |
66 static const int max_rgb_str_len = 7; | |
67 static const int max_rgb_str_size = 8; | |
68 | |
69 int setCounter, getCounter, setColorCounter,getColorCounter; | |
70 | |
71 GdkGC *gc; | |
72 GdkColor gdkUcolor,gdkDcolor; | |
73 | |
74 /* end of COLOR vars */ | |
75 | |
76 | |
77 char configFileName[256]; | |
78 | |
79 | |
80 /* properties vars */ | |
81 | |
82 GtkWidget *tik_syms_entry; | |
83 gchar tik_syms[256]; | |
84 | |
85 GtkWidget * pb = NULL; | |
86 | |
87 typedef struct | |
88 { | |
89 char *tik_syms; | |
90 char *output; | |
91 char *scroll; | |
92 gint timeout; | |
93 gchar dcolor[8]; | |
94 gchar ucolor[8]; | |
95 | |
96 } gtik_properties; | |
97 | |
98 gtik_properties props = {"cald+rhat+corl","default","right2left", | |
99 5,"#ff0000","#00ff00"}; | |
100 | |
101 /* end prop vars */ | |
102 | |
103 | |
104 gint timeout = 0; | |
105 gint drawTimeID, updateTimeID; | |
106 GdkFont * my_font; | |
107 GdkFont * extra_font; | |
108 GdkFont * small_font; | |
109 static gint symbolfont = 1; | |
110 static gint destroycb; | |
111 | |
112 | |
113 int configured(); | |
114 void timeout_cb( GtkWidget *widget, GtkWidget *spin ); | |
115 static int http_get_to_file(gchar *a_host, gint a_port, | |
116 gchar *a_resource, FILE *a_file); | |
117 int http_got(); | |
118 void properties_save( char *path) ; | |
119 void gaim_plugin_remove(); | |
120 | |
121 | |
122 /* FOR COLOR */ | |
123 | |
124 void updateOutput() ; | |
125 static void reSetOutputArray() ; | |
126 static void setOutputArray(char *param1) ; | |
127 static void setColorArray(int theColor) ; | |
128 void setup_colors(void); | |
129 int create_gc(void) ; | |
130 | |
131 /* end of color funcs */ | |
132 | |
133 | |
134 | |
135 /*-----------------------------------------------------------------*/ | |
136 void remove_self(GtkWidget *w, void *handle) | |
137 { | |
138 gtk_signal_disconnect(GTK_OBJECT(applet), destroycb); | |
4168 | 139 if (drawTimeID > 0) { g_source_remove(drawTimeID); } |
140 if (updateTimeID >0) { g_source_remove(updateTimeID); } | |
426 | 141 gtk_widget_destroy(applet); |
142 gaim_plugin_unload(handle); | |
143 } | |
144 | |
145 | |
146 /*-----------------------------------------------------------------*/ | |
147 void load_fonts() | |
148 { | |
149 my_font = gdk_font_load ("fixed"); | |
150 extra_font = gdk_font_load ("-urw-symbol-medium-r-normal-*-*-100-*-*-p-*-adobe-fontspecific"); | |
151 small_font = gdk_font_load ("-schumacher-clean-medium-r-normal-*-*-100-*-*-c-*-iso8859-1"); | |
152 | |
153 /* If fonts do not load */ | |
154 if (!my_font) | |
155 g_error("Could not load fonts!"); | |
156 if (!extra_font) { | |
157 extra_font = gdk_font_load("fixed"); | |
158 symbolfont = 0; | |
159 } | |
160 if (!small_font) | |
161 small_font = gdk_font_load("fixed"); | |
162 } | |
163 | |
164 /*-----------------------------------------------------------------*/ | |
165 /*void load_properties( char *path) { | |
166 | |
167 | |
168 gnome_config_push_prefix (path); | |
169 if( gnome_config_get_string ("gtik/tik_syms") != NULL ) | |
170 props.tik_syms = gnome_config_get_string("gtik/tik_syms"); | |
171 | |
172 | |
173 timeout = gnome_config_get_int("gtik/timeout") > 0 ? gnome_config_get_int ("gtik/timeout") : props.timeout; | |
174 | |
175 | |
176 if ( gnome_config_get_string ("gtik/output") != NULL ) | |
177 props.output = gnome_config_get_string("gtik/output"); | |
178 | |
179 if ( gnome_config_get_string ("gtik/scroll") != NULL ) | |
180 props.scroll = gnome_config_get_string("gtik/scroll"); | |
181 | |
182 if ( gnome_config_get_string ("gtik/ucolor") != NULL ) | |
183 strcpy(props.ucolor, gnome_config_get_string("gtik/ucolor")); | |
184 | |
185 if ( gnome_config_get_string ("gtik/dcolor") != NULL ) | |
186 strcpy(props.dcolor, gnome_config_get_string("gtik/dcolor")); | |
187 | |
188 gnome_config_pop_prefix (); | |
189 }*/ | |
190 | |
191 | |
192 | |
193 /*-----------------------------------------------------------------*/ | |
194 /*void properties_save( char *path) { | |
195 | |
196 gnome_config_push_prefix (path); | |
197 gnome_config_set_string( "gtik/tik_syms", props.tik_syms ); | |
198 gnome_config_set_string( "gtik/output", props.output ); | |
199 gnome_config_set_string( "gtik/scroll", props.scroll ); | |
200 gnome_config_set_string( "gtik/ucolor", props.ucolor ); | |
201 gnome_config_set_string( "gtik/dcolor", props.dcolor ); | |
202 | |
203 gnome_config_set_int("gtik/timeout",props.timeout); | |
204 | |
205 gnome_config_pop_prefix (); | |
206 gnome_config_sync(); | |
207 gnome_config_drop_all(); | |
208 }*/ | |
209 | |
210 | |
211 /*-----------------------------------------------------------------*/ | |
212 char * extractText(const char *line) { | |
213 | |
214 int i=0; | |
215 int j=0; | |
216 static char Text[256]=""; | |
217 | |
218 while (i < (strlen(line) -1)) { | |
219 if (line[i] != '>') | |
220 i++; | |
221 else { | |
222 i++; | |
223 while (line[i] != '<') { | |
224 Text[j] = line[i]; | |
225 i++;j++; | |
226 } | |
227 } | |
228 } | |
229 Text[j] = '\0'; | |
230 i = 0; | |
231 while (i < (strlen(Text)) ) { | |
232 if (Text[i] < 32) | |
233 Text[i] = '\0'; | |
234 i++; | |
235 } | |
236 return(Text); | |
237 | |
238 } | |
239 | |
240 /*-----------------------------------------------------------------*/ | |
241 char * parseQuote(FILE *CONFIG, char line[512]) { | |
242 | |
243 char symbol[512]; | |
244 char buff[512]; | |
245 char price[16]; | |
246 char change[16]; | |
247 char percent[16]; | |
248 static char result[512]=""; | |
249 int linenum=0; | |
250 int AllOneLine=0; | |
251 int flag=0; | |
252 char *section; | |
253 char *ptr; | |
254 | |
255 if (strlen(line) > 64) AllOneLine=1; | |
256 | |
257 if (AllOneLine) { | |
258 strcpy(buff,line); | |
259 while (!flag) { | |
260 if ((ptr=strstr(buff,"</td>"))!=NULL) { | |
261 ptr[0] = '|'; | |
262 } | |
263 else flag=1; | |
264 } | |
265 section = strtok(buff,"|"); | |
266 } | |
267 /* Get the stock symbol */ | |
268 if (!AllOneLine) strcpy(symbol,extractText(line)); | |
269 else strcpy(symbol,extractText(section)); | |
270 linenum++; | |
271 | |
272 /* Skip the time... */ | |
273 if (!AllOneLine) fgets(line,255,CONFIG); | |
274 else section = strtok(NULL,"|"); | |
275 linenum++; | |
276 | |
277 while (linenum < 8 ) { | |
278 if (!AllOneLine) { | |
279 fgets(line,255,CONFIG); | |
280 | |
281 if (strstr(line, | |
282 "<td align=center nowrap colspan=2>")) { | |
283 strcpy(change,""); | |
284 strcpy(percent,""); | |
285 linenum=100; | |
286 } | |
287 } | |
288 else { | |
289 section = strtok(NULL,"|"); | |
290 if (strstr(section, | |
291 "<td align=center nowrap colspan=2>")) { | |
292 strcpy(change,""); | |
293 strcpy(percent,""); | |
294 linenum=100; | |
295 } | |
296 } | |
297 | |
298 if (linenum == 2) { | |
299 if (!AllOneLine) | |
300 strcpy(price,extractText(line)); | |
301 else | |
302 strcpy(price,extractText(section)); | |
303 } | |
304 else if (linenum == 3) { | |
305 if (!AllOneLine) | |
306 strcpy(change,extractText(line)); | |
307 else | |
308 strcpy(change,extractText(section)); | |
309 | |
310 if (strstr(change,"-")) { | |
311 setColorArray(RED); | |
312 } | |
313 else if (strstr(change,"+")) { | |
314 setColorArray(GREEN); | |
315 } | |
316 else { | |
317 setColorArray(0); | |
318 } | |
319 | |
320 } | |
321 else if (linenum == 4) { | |
322 if (!AllOneLine) | |
323 strcpy(percent,extractText(line)); | |
324 else | |
325 strcpy(percent,extractText(section)); | |
326 } | |
327 linenum++; | |
328 } | |
329 sprintf(result,"%s:%s:%s:%s", | |
330 symbol,price,change,percent); | |
331 return(result); | |
332 | |
333 } | |
334 | |
335 | |
336 | |
337 /*-----------------------------------------------------------------*/ | |
338 int configured() { | |
339 int retVar; | |
340 | |
341 char buffer[512]; | |
342 static FILE *CONFIG; | |
343 | |
344 CONFIG = fopen((const char *)configFileName,"r"); | |
345 | |
346 retVar = 0; | |
347 | |
348 /* clear the output variable */ | |
349 reSetOutputArray(); | |
350 | |
351 if ( CONFIG ) { | |
352 while ( !feof(CONFIG) ) { | |
353 fgets(buffer,511,CONFIG); | |
354 | |
355 if (strstr(buffer, | |
356 "<td nowrap align=left><a href=\"/q\?s=")) { | |
357 | |
358 setOutputArray(parseQuote(CONFIG,buffer)); | |
359 retVar = 1; | |
360 } | |
361 else { | |
362 retVar = (retVar > 0) ? retVar : 0; | |
363 } | |
364 } | |
365 fclose(CONFIG); | |
366 | |
367 } | |
368 else { | |
369 retVar = 0; | |
370 } | |
371 | |
372 return retVar; | |
373 } | |
374 | |
375 | |
376 /*-----------------------------------------------------------------*/ | |
377 /* Shamelessly stolen from the Slashapp applet | |
378 */ | |
379 static int http_get_to_file(gchar *a_host, gint a_port, | |
380 gchar *a_resource, FILE *a_file) { | |
381 int length = -1; | |
382 ghttp_request *request = NULL; | |
383 gchar s_port[8]; | |
384 gchar *uri = NULL; | |
385 gchar *body; | |
386 gchar *proxy = g_getenv("http_proxy"); | |
387 | |
388 g_snprintf(s_port, 8, "%d", a_port); | |
389 uri = g_strconcat("http://", a_host, ":", s_port, | |
390 a_resource, NULL); | |
391 | |
392 fprintf(stderr,"Asking for %s\n", uri); | |
393 | |
394 request = ghttp_request_new(); | |
395 if (!request) | |
396 goto ec; | |
397 if (proxy && (ghttp_set_proxy(request,proxy) != 0)) | |
398 goto ec; | |
399 | |
400 if (ghttp_set_uri(request, uri) != 0) | |
401 goto ec; | |
402 ghttp_set_header(request, http_hdr_Connection, "close"); | |
403 if (ghttp_prepare(request) != 0) | |
404 goto ec; | |
405 if (ghttp_process(request) != ghttp_done) | |
406 goto ec; | |
407 length = ghttp_get_body_len(request); | |
408 body = ghttp_get_body(request); | |
409 if (body != NULL) | |
410 fwrite(body, length, 1, a_file); | |
411 | |
412 ec: | |
413 if (request) | |
414 ghttp_request_destroy(request); | |
415 if (uri) | |
416 | |
417 g_free(uri); | |
418 return length; | |
419 } | |
420 | |
421 | |
422 | |
423 | |
424 /*-----------------------------------------------------------------*/ | |
425 int http_got() { | |
426 | |
427 int retVar; | |
428 FILE *local_file; | |
429 | |
430 char tmpBuff[256]; | |
431 memset(tmpBuff,0,sizeof(tmpBuff)); | |
432 | |
433 strcat(tmpBuff,"/q?s="); | |
434 strcat(tmpBuff, props.tik_syms); | |
435 strcat(tmpBuff,"&d=v2"); | |
436 | |
437 retVar = 0; | |
438 | |
439 local_file = fopen(configFileName, "w"); | |
440 retVar = http_get_to_file("finance.yahoo.com", 80, | |
441 tmpBuff, local_file); | |
442 | |
443 fclose(local_file); | |
444 | |
445 return retVar; | |
446 } | |
447 | |
448 | |
449 | |
450 | |
451 | |
452 /*-----------------------------------------------------------------*/ | |
453 gint expose_event (GtkWidget *widget,GdkEventExpose *event) { | |
454 | |
455 gdk_draw_pixmap(widget->window, | |
456 widget->style->fg_gc[GTK_WIDGET_STATE(widget)], | |
457 pixmap, | |
458 event->area.x, event->area.y, | |
459 event->area.x, event->area.y, | |
460 event->area.width,event->area.height); | |
461 | |
462 return FALSE; | |
463 } | |
464 | |
465 | |
466 | |
467 /*-----------------------------------------------------------------*/ | |
468 static gint configure_event(GtkWidget *widget,GdkEventConfigure *event){ | |
469 | |
470 if(pixmap) { | |
471 gdk_pixmap_unref (pixmap); | |
472 } | |
473 | |
474 pixmap = gdk_pixmap_new(widget->window, | |
475 widget->allocation.width, | |
476 widget->allocation.height, | |
477 -1); | |
478 | |
479 return TRUE; | |
480 } | |
481 | |
482 | |
483 | |
484 | |
485 | |
486 | |
487 /*-----------------------------------------------------------------*/ | |
488 gint Repaint (gpointer data) { | |
489 GtkWidget* drawing_area = (GtkWidget *) data; | |
490 GdkRectangle update_rect; | |
491 int comp; | |
492 | |
493 /* FOR COLOR */ | |
494 char *tmpSym; | |
495 int totalLoc; | |
496 int totalLen; | |
497 int i; | |
498 | |
499 | |
500 totalLoc = 0; | |
501 totalLen = 0; | |
502 | |
503 /* clear the pixmap */ | |
504 gdk_draw_rectangle (pixmap, | |
505 drawing_area->style->black_gc, | |
506 TRUE, | |
507 0,0, | |
508 drawing_area->allocation.width, | |
509 drawing_area->allocation.height); | |
510 | |
511 | |
512 for(i=0;i<LEN;i++) { | |
513 totalLen += strlen(outputArray[i]); | |
514 } | |
515 if (!strcmp(props.output,"default")) { | |
516 for(i=0;i<LEN;i++) { | |
517 totalLen += strlen(changeArray[i]); | |
518 } | |
519 } | |
520 | |
521 comp = 1 - ( totalLen *8 ); | |
522 | |
523 if (MOVE == 1) { MOVE = 0; } else { MOVE = 1; } | |
524 | |
525 if (MOVE == 1) { | |
526 | |
527 | |
528 if (!strcmp(props.scroll,"right2left")) { | |
529 if (location > comp) { | |
530 location--; | |
531 } | |
532 else { | |
533 location = drawing_area->allocation.width; | |
534 } | |
535 | |
536 } | |
537 else { | |
538 if (location < drawing_area->allocation.width) { | |
539 location ++; | |
540 } | |
541 else { | |
542 location = comp; | |
543 } | |
544 } | |
545 | |
546 | |
547 | |
548 } | |
549 | |
550 for (i=0;i<LEN;i++) { | |
551 | |
552 /* COLOR */ | |
553 if (colorArray[i] == GREEN) { | |
554 gdk_gc_set_foreground( gc, &gdkUcolor ); | |
555 } | |
556 else if (colorArray[i] == RED) { | |
557 gdk_gc_set_foreground( gc, &gdkDcolor ); | |
558 } | |
559 else { | |
560 gdk_gc_copy( gc, drawing_area->style->white_gc ); | |
561 } | |
562 | |
563 tmpSym = outputArray[i]; | |
564 gdk_draw_string (pixmap,my_font, | |
565 gc, | |
566 location + (totalLoc * 6 ) ,12,outputArray[i]); | |
567 totalLoc += (strlen(tmpSym) + 1); | |
568 | |
569 | |
570 if (!strcmp(props.output,"default")) { | |
571 tmpSym = changeArray[i]; | |
572 if (*(changeArray[i])) | |
573 gdk_draw_text (pixmap,extra_font, | |
574 gc, location + (totalLoc * 6) , | |
575 12,changeArray[i],1); | |
576 gdk_draw_string (pixmap,small_font, | |
577 gc, location + ((totalLoc +2) * 6) , | |
578 12, &changeArray[i][1]); | |
579 totalLoc += (strlen(tmpSym) + 1); | |
580 } | |
581 | |
582 } | |
583 update_rect.x = 0; | |
584 update_rect.y = 0; | |
585 update_rect.width = drawing_area->allocation.width; | |
586 update_rect.height = drawing_area->allocation.height; | |
587 | |
588 gtk_widget_draw(drawing_area,&update_rect); | |
589 return 1; | |
590 } | |
591 | |
592 | |
593 | |
594 | |
595 /*-----------------------------------------------------------------*/ | |
3551 | 596 |
597 struct gaim_plugin_description desc; | |
598 struct gaim_plugin_description *gaim_plugin_desc() { | |
599 desc.api_version = PLUGIN_API_VERSION; | |
600 desc.name = g_strdup("Stock Ticker"); | |
601 desc.version = g_strdup(VERSION); | |
602 desc.description = g_strdup( | |
603 " This program uses ghttp to connect to " | |
604 "a popular stock quote site, then downloads " | |
605 "and parses the html returned from the " | |
606 "site to scroll delayed quotes" | |
607 "\n\n The Gnome Stock Ticker is a free, Internet based application. These quotes are not " | |
608 "guaranteed to be timely or accurate. " | |
609 "Do not use the Gnome Stock Ticker for making investment decisions; it is for " | |
610 "informational purposes only."); | |
611 desc.authors = g_strdup("Jayson Lorenzen, Jim Garrison, Rached Blili"); | |
612 desc.url = g_strdup(WEBSITE); | |
613 return &desc; | |
614 } | |
615 | |
616 char *description() { | |
426 | 617 return |
618 " This program uses ghttp to connect to " | |
619 "a popular stock quote site, then downloads " | |
620 "and parses the html returned from the " | |
621 "site to scroll delayed quotes" | |
622 "\n\n The Gnome Stock Ticker is a free, Internet based application. These quotes are not " | |
623 "guaranteed to be timely or accurate. " | |
624 "Do not use the Gnome Stock Ticker for making investment decisions; it is for " | |
625 "informational purposes only." | |
626 "\n\n (C) 2000 Jayson Lorenzen, Jim Garrison, Rached Blili"; | |
627 } | |
628 | |
629 char *name() { | |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2142
diff
changeset
|
630 return "The Gnome Stock Ticker for Gaim"; |
426 | 631 } |
632 | |
633 | |
634 | |
635 | |
636 | |
637 | |
638 /*-----------------------------------------------------------------*/ | |
639 void changed_cb(GtkWidget *pb, gpointer data) { | |
640 /* gnome_property_box_changed(GNOME_PROPERTY_BOX(pb)); */ | |
641 } | |
642 | |
643 | |
644 /*-----------------------------------------------------------------*/ | |
645 void toggle_output_cb(GtkWidget *widget, gpointer data) { | |
646 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) | |
647 props.output = g_strdup("nochange"); | |
648 else | |
649 props.output = g_strdup("default"); | |
650 | |
651 } | |
652 | |
653 /*-----------------------------------------------------------------*/ | |
654 void toggle_scroll_cb(GtkWidget *widget, gpointer data) { | |
655 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) | |
656 props.scroll = g_strdup("left2right"); | |
657 else | |
658 props.scroll = g_strdup("right2left"); | |
659 | |
660 } | |
661 | |
662 /*-----------------------------------------------------------------*/ | |
663 void timeout_cb( GtkWidget *widget, GtkWidget *spin ) { | |
664 timeout=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin)); | |
665 /* gnome_property_box_changed(GNOME_PROPERTY_BOX(pb)); */ | |
666 } | |
667 | |
668 | |
669 | |
670 | |
671 /*-----------------------------------------------------------------*/ | |
672 static void apply_cb( GtkWidget *widget, void *data ) { | |
673 char *tmpText; | |
674 | |
675 | |
676 tmpText = gtk_entry_get_text(GTK_ENTRY(tik_syms_entry)); | |
677 props.tik_syms = g_strdup(tmpText); | |
678 if (props.timeout) { | |
679 props.timeout = timeout > 0 ? timeout : props.timeout; | |
680 } | |
681 | |
682 /* properties_save(APPLET_WIDGET(applet)->privcfgpath); */ | |
683 | |
684 setup_colors(); | |
685 updateOutput(); | |
686 } | |
687 | |
688 | |
689 | |
690 | |
691 /*-----------------------------------------------------------------*/ | |
692 gint destroy_cb( GtkWidget *widget, void *data ) { | |
693 pb = NULL; | |
694 return FALSE; | |
695 } | |
696 | |
697 | |
698 | |
699 /*-----------------------------------------------------------------*/ | |
700 void gaim_plugin_config() { | |
701 GtkWidget * vbox; | |
702 GtkWidget *urlcheck, *launchcheck; | |
703 | |
704 GtkWidget *panela, *panel1 ,*panel2, *panel3, *panel4; | |
705 GtkWidget *label1,*label2,*label3 ; | |
706 | |
707 | |
708 GtkWidget *timeout_label,*timeout_c; | |
709 GtkObject *timeout_a; | |
710 | |
711 GtkWidget *upColor, *downColor, *upLabel, *downLabel; | |
712 GtkWidget *check,*check2; | |
713 | |
714 int ur,ug,ub, dr,dg,db; | |
715 | |
716 if (pb) return; | |
717 pb = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
718 | |
719 gtk_window_set_title(GTK_WINDOW(pb), _("Gnome Stock Ticker Properties")); | |
720 | |
721 vbox = gtk_vbox_new(FALSE, 8); | |
722 | |
723 panela = gtk_hbox_new(FALSE, 5); | |
724 panel1 = gtk_hbox_new(FALSE, 5); | |
725 panel2 = gtk_hbox_new(FALSE, 5); | |
726 panel3 = gtk_hbox_new(FALSE, 5); | |
727 panel4 = gtk_hbox_new(FALSE, 5); | |
728 | |
729 gtk_container_set_border_width(GTK_CONTAINER(vbox), 8); | |
730 | |
731 timeout_label = gtk_label_new(_("Update Frequency in min")); | |
732 timeout_a = gtk_adjustment_new( timeout, 0.5, 128, 1, 8, 8 ); | |
733 timeout_c = gtk_spin_button_new( GTK_ADJUSTMENT(timeout_a), 1, 0 ); | |
734 | |
735 gtk_box_pack_start_defaults( GTK_BOX(panel2), timeout_label ); | |
736 gtk_box_pack_start_defaults( GTK_BOX(panel2), timeout_c ); | |
737 | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
738 g_signal_connect_swapped(GTK_OBJECT(timeout_c), "changed",G_CALLBACK(changed_cb),GTK_OBJECT(pb)); |
426 | 739 |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
740 g_signal_connect( GTK_OBJECT(timeout_a),"value_changed", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
741 G_CALLBACK(timeout_cb), timeout_c ); |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
742 g_signal_connect( GTK_OBJECT(timeout_c),"changed", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
743 G_CALLBACK(timeout_cb), timeout_c ); |
426 | 744 gtk_spin_button_set_update_policy( GTK_SPIN_BUTTON(timeout_c), |
745 GTK_UPDATE_ALWAYS ); | |
746 | |
747 label1 = gtk_label_new(_("Enter symbols delimited with \"+\" in the box below.")); | |
748 | |
749 tik_syms_entry = gtk_entry_new_with_max_length(60); | |
750 | |
751 /* tik_syms var is her if want a default value */ | |
752 gtk_entry_set_text(GTK_ENTRY(tik_syms_entry), props.tik_syms ? props.tik_syms : tik_syms); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
753 g_signal_connect_swapped(GTK_OBJECT(tik_syms_entry), "changed",G_CALLBACK(changed_cb),GTK_OBJECT(pb)); |
426 | 754 |
755 /* OUTPUT FORMAT and SCROLL DIRECTION */ | |
756 | |
757 label2 = gtk_label_new(_("Check this box to display only symbols and price:")); | |
758 label3 = gtk_label_new(_("Check this box to scroll left to right:")); | |
759 check = gtk_check_button_new(); | |
760 check2 = gtk_check_button_new(); | |
761 gtk_box_pack_start_defaults(GTK_BOX(panel3),label2); | |
762 gtk_box_pack_start_defaults(GTK_BOX(panel3),check); | |
763 gtk_box_pack_start_defaults(GTK_BOX(panel4),label3); | |
764 gtk_box_pack_start_defaults(GTK_BOX(panel4),check2); | |
765 | |
766 /* Set the checkbox according to current prefs */ | |
767 if (strcmp(props.output,"default")!=0) | |
768 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), | |
769 TRUE); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
770 g_signal_connect_swapped(GTK_OBJECT(check),"toggled", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
771 G_CALLBACK(changed_cb),GTK_OBJECT(pb)); |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
772 g_signal_connect(GTK_OBJECT(check),"toggled", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
773 G_CALLBACK(toggle_output_cb),NULL); |
426 | 774 |
775 /* Set the checkbox according to current prefs */ | |
776 if (strcmp(props.scroll,"right2left")!=0) | |
777 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check2), | |
778 TRUE); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
779 g_signal_connect_swapped(GTK_OBJECT(check2),"toggled", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
780 G_CALLBACK(changed_cb),GTK_OBJECT(pb)); |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
781 g_signal_connect(GTK_OBJECT(check2),"toggled", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
782 G_CALLBACK(toggle_scroll_cb),NULL); |
426 | 783 |
784 /* COLOR */ | |
785 /* upLabel = gtk_label_new(_("+ Color")); | |
786 upColor = gnome_color_picker_new(); | |
787 | |
788 sscanf( props.ucolor, "#%02x%02x%02x", &ur,&ug,&ub ); | |
789 | |
790 gnome_color_picker_set_i8(GNOME_COLOR_PICKER (upColor), | |
791 ur, ug, ub, 255); | |
792 | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
793 g_signal_connect(GTK_OBJECT(upColor), "color_set", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
794 G_CALLBACK(ucolor_set_cb), NULL); |
426 | 795 |
796 gtk_box_pack_start_defaults( GTK_BOX(panela), upLabel ); | |
797 gtk_box_pack_start_defaults( GTK_BOX(panela), upColor ); | |
798 | |
799 downLabel = gtk_label_new(_("- Color")); | |
800 downColor = gnome_color_picker_new(); | |
801 | |
802 sscanf( props.dcolor, "#%02x%02x%02x", &dr,&dg,&db ); | |
803 | |
804 gnome_color_picker_set_i8(GNOME_COLOR_PICKER (downColor), | |
805 dr, dg, db, 255); | |
806 | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
807 g_signal_connect(GTK_OBJECT(downColor), "color_set", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
808 G_CALLBACK(dcolor_set_cb), NULL); |
426 | 809 |
810 gtk_box_pack_start_defaults( GTK_BOX(panela), downLabel ); | |
811 gtk_box_pack_start_defaults( GTK_BOX(panela), downColor ); | |
812 | |
813 */ | |
814 gtk_box_pack_start(GTK_BOX(panel1), label1, FALSE, | |
815 FALSE, 8); | |
816 | |
817 gtk_box_pack_start(GTK_BOX(vbox), panel2, FALSE, | |
818 FALSE, 8); | |
819 gtk_box_pack_start(GTK_BOX(vbox), panel3, FALSE, | |
820 FALSE, 8); | |
821 gtk_box_pack_start(GTK_BOX(vbox), panel4, FALSE, | |
822 FALSE, 8); | |
823 gtk_box_pack_start(GTK_BOX(vbox), panela, FALSE, | |
824 FALSE, 8); | |
825 gtk_box_pack_start(GTK_BOX(vbox), panel1, FALSE, | |
826 FALSE, 8); | |
827 | |
828 gtk_box_pack_start(GTK_BOX(vbox), tik_syms_entry, | |
829 FALSE, FALSE, 8); | |
830 | |
831 gtk_container_add(GTK_CONTAINER(pb), vbox); | |
832 | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
833 g_signal_connect_swapped(GTK_OBJECT(tik_syms_entry), |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
834 "changed",G_CALLBACK(changed_cb), |
426 | 835 GTK_OBJECT(pb)); |
836 | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
837 g_signal_connect(GTK_OBJECT(pb), "apply", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
838 G_CALLBACK(apply_cb), NULL); |
426 | 839 |
840 gtk_widget_show_all(pb); | |
841 } | |
842 | |
843 | |
844 | |
845 | |
846 | |
847 /*-----------------------------------------------------------------*/ | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
426
diff
changeset
|
848 char *gaim_plugin_init(GModule *handle) { /* used to be main() */ |
426 | 849 GtkWidget *label; |
850 | |
851 GtkWidget * vbox; | |
852 | |
853 memset(configFileName,0,sizeof(configFileName)); | |
854 strcat(configFileName, getenv("HOME")); | |
855 strcat(configFileName, "/.gtik.conf"); | |
856 | |
857 applet = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* or not */ | |
858 | |
859 vbox = gtk_hbox_new (FALSE,0); | |
860 | |
861 drawing_area = gtk_drawing_area_new(); | |
862 gtk_drawing_area_size(GTK_DRAWING_AREA (drawing_area),200,20); | |
863 | |
864 gtk_widget_show(drawing_area); | |
865 gtk_box_pack_start(GTK_BOX (vbox), drawing_area,TRUE,TRUE,0); | |
866 | |
867 gtk_widget_show(vbox); | |
868 | |
869 /* applet_widget_add (APPLET_WIDGET (applet), vbox); */ | |
870 gtk_container_add(GTK_CONTAINER(applet), vbox); | |
871 | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
872 g_signal_connect(GTK_OBJECT(drawing_area),"expose_event", |
426 | 873 (GtkSignalFunc) expose_event, NULL); |
874 | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
875 g_signal_connect(GTK_OBJECT(drawing_area),"configure_event", |
426 | 876 (GtkSignalFunc) configure_event, NULL); |
877 | |
878 | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
879 destroycb = g_signal_connect(GTK_OBJECT(applet), "destroy", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
880 G_CALLBACK(remove_self), handle); |
426 | 881 |
882 | |
883 | |
884 gtk_widget_show (applet); | |
885 create_gc(); | |
886 | |
887 /* load_properties(APPLET_WIDGET(applet)->privcfgpath); */ | |
888 | |
889 setup_colors(); | |
890 load_fonts(); | |
891 updateOutput(); | |
892 | |
893 | |
894 /* KEEPING TIMER ID FOR CLEANUP IN DESTROY */ | |
4168 | 895 drawTimeID = g_timeout_add(2,Repaint,drawing_area); |
896 updateTimeID = g_timeout_add(props.timeout * 60000, | |
897 updateOutput,"NULL"); | |
426 | 898 |
899 | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
426
diff
changeset
|
900 return NULL; |
426 | 901 } |
902 | |
903 | |
904 | |
905 /*-----------------------------------------------------------------*/ | |
906 void updateOutput() { | |
907 if ( http_got() == -1 || !(configured()) ) { | |
908 reSetOutputArray(); | |
909 printf("No data!\n"); | |
910 setOutputArray("No data available or properties not set"); | |
911 } | |
912 } | |
913 | |
914 | |
915 | |
916 | |
917 /* JHACK */ | |
918 /*-----------------------------------------------------------------*/ | |
919 void gaim_plugin_remove() { | |
920 gtk_signal_disconnect(GTK_OBJECT(applet), destroycb); | |
4168 | 921 if (drawTimeID > 0) { g_source_remove(drawTimeID); } |
922 if (updateTimeID >0) { g_source_remove(updateTimeID); } | |
426 | 923 gtk_widget_destroy(applet); |
924 } | |
925 | |
926 | |
927 | |
928 | |
929 | |
930 /*HERE*/ | |
931 /*-----------------------------------------------------------------*/ | |
932 static void reSetOutputArray() { | |
933 int i; | |
934 | |
935 for (i=0;i<LEN;i++) { | |
936 /* CLEAR EACH SYMBOL'S SPACE */ | |
937 memset(outputArray[i],0,sizeof(outputArray[i])); | |
938 | |
939 /* CLEAR ASSOC COLOR ARRAY */ | |
940 colorArray[i] = 0; | |
941 | |
942 /* CLEAR ADDITIONAL INFO */ | |
943 memset(changeArray[i],0,sizeof(changeArray[i])); | |
944 | |
945 } | |
946 | |
947 setCounter = 0; | |
948 getCounter = 0; | |
949 setColorCounter = 0; | |
950 getColorCounter = 0; | |
951 | |
952 } | |
953 | |
954 | |
955 /*-----------------------------------------------------------------*/ | |
956 char *splitPrice(char *data) { | |
957 char buff[128]=""; | |
958 static char buff2[128]=""; | |
959 char *var1, *var2; | |
960 int i; | |
961 | |
962 strcpy(buff,data); | |
963 var1 = strtok(buff,":"); | |
964 var2 = strtok(NULL,":"); | |
965 | |
966 sprintf(buff2," %s %s",var1,var2); | |
967 return(buff2); | |
968 } | |
969 | |
970 /*-----------------------------------------------------------------*/ | |
971 char *splitChange(char *data) { | |
972 char buff[128]=""; | |
973 static char buff2[128]=""; | |
974 char *var1, *var2, *var3, *var4; | |
975 int i; | |
976 | |
977 strcpy(buff,data); | |
978 var1 = strtok(buff,":"); | |
979 var2 = strtok(NULL,":"); | |
980 var3 = strtok(NULL,":"); | |
981 var4 = strtok(NULL,""); | |
982 | |
983 if (var3[0] == '+') { | |
984 if (symbolfont) | |
985 var3[0] = 221; | |
986 var4[0] = '('; | |
987 } | |
988 else if (var3[0] == '-') { | |
989 if (symbolfont) | |
990 var3[0] = 223; | |
991 var4[0] = '('; | |
992 } | |
993 else { | |
994 var3 = strdup(_("(No")); | |
995 var4 = strdup(_("Change")); | |
996 } | |
997 | |
998 sprintf(buff2,"%s %s)",var3,var4); | |
999 return(buff2); | |
1000 } | |
1001 | |
1002 /*-----------------------------------------------------------------*/ | |
1003 static void setOutputArray(char *param1) { | |
1004 char *price; | |
1005 char *change; | |
1006 | |
1007 price = splitPrice(param1); | |
1008 change = splitChange(param1); | |
1009 | |
1010 if (setCounter < LEN) { | |
1011 | |
1012 strcpy(outputArray[setCounter],price); | |
1013 strcpy(changeArray[setCounter],change); | |
1014 } | |
1015 setCounter++; | |
1016 } | |
1017 | |
1018 | |
1019 | |
1020 /*-----------------------------------------------------------------*/ | |
1021 static void setColorArray(int theColor) { | |
1022 if (setColorCounter < LEN) { | |
1023 colorArray[setColorCounter] = theColor; | |
1024 } | |
1025 setColorCounter++; | |
1026 } | |
1027 | |
1028 void setup_colors(void) { | |
1029 GdkColormap *colormap; | |
1030 | |
1031 colormap = gtk_widget_get_colormap(drawing_area); | |
1032 | |
1033 gdk_color_parse(props.ucolor, &gdkUcolor); | |
1034 gdk_color_alloc(colormap, &gdkUcolor); | |
1035 | |
1036 gdk_color_parse(props.dcolor, &gdkDcolor); | |
1037 gdk_color_alloc(colormap, &gdkDcolor); | |
1038 } | |
1039 | |
1040 | |
1041 int create_gc(void) { | |
1042 gc = gdk_gc_new( drawing_area->window ); | |
1043 gdk_gc_copy( gc, drawing_area->style->white_gc ); | |
1044 return 0; | |
1045 } |